Linux磁盘分区与扩容——具体操作实例

Linux下的扩容,分为:1.增加物理磁盘;2.新建分区;3.建立ext4文件系统并格式化;4.将分区加入虚拟卷组;5.将分区加到文件存储的主要部分;6.刷新文件存储的主要部分

给分区扩容的原理:每个分区都有一个逻辑卷组,这是一个虚拟卷组,这个卷组可以动态扩展,通过向这个卷组中添加物理卷(分区)来增加卷组,即实现分区扩容。

添加磁盘

# 若在虚拟机下,则关闭虚拟机实例,在虚拟机设置里增加磁盘容量

新建分区

#列出所有分区信息 [root@oralinux66 ~]# fdisk -l

# 这部分可以看做是一块物理磁盘 Disk /dev/sda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00003748 # 表示该物理磁盘的分区,两个分区,不言而喻 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 4178 33041408 8e Linux LVM

# 下面两部分的物理介质实质上都是上述的物理磁盘 # 这部分可以看做是当前系统占用了上述物理磁盘的主要部分(文件存储) # 扩容,扩的就是文件存储的主要部分 Disk /dev/mapper/vg_oralinux66-lv_root: 30.4 GB, 30396121088 bytes 255 heads, 63 sectors/track, 3695 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000

# 这部分可以看做是当前系统占用了上述物理磁盘的部分(交换空间) Disk /dev/mapper/vg_oralinux66-lv_swap: 3435 MB, 3435134976 bytes 255 heads, 63 sectors/track, 417 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000

[root@oralinux66 ~]# fdisk /dev/ Display all 207 possibilities? (y or n) # 操作该物理磁盘 [root@oralinux66 ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').

Command (m for help): m
Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)

# 显示该物理磁盘分区情况 Command (m for help): p

Disk /dev/sda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00003748

Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 4178 33041408 8e Linux LVM

# 显然,n-添加一个分区 Command (m for help): n Command action e extended p primary partition (1-4) # 创建主分区 p # 上述有两个分区了,选择3,表示创建第三分区 Partition number (1-4): 3 First cylinder (4178-7832, default 4178): Using default value 4178 Last cylinder, +cylinders or +size{K,M,G} (4178-7832, default 7832): Using default value 7832 # 写表并退出 Command (m for help): w The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@oralinux66 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00003748 # 多了分区3 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 4178 33041408 8e Linux LVM /dev/sda3 4178 7832 29356108 83 Linux

Disk /dev/mapper/vg_oralinux66-lv_root: 30.4 GB, 30396121088 bytes 255 heads, 63 sectors/track, 3695 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000

Disk /dev/mapper/vg_oralinux66-lv_swap: 3435 MB, 3435134976 bytes 255 heads, 63 sectors/track, 417 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000

# 重启虚拟器实例 # 重启虚拟器实例 # 重启虚拟器实例

建立ext4文件系统并格式化

创建完分区后,就需要在各个分区上建立文件系统

# 查看文件系统类型

[root@oralinux66 ~]# df -T /dev/sda3

Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1009616 200 1009416 1% /dev [root@oralinux66 ~]# df -T /dev/sda2

Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1009616 200 1009416 1% /dev [root@oralinux66 ~]# mkfs

mkfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.ext4dev mkfs.msdos mkfs.vfat

# 在/dev/sda3下建立ext4文件系统,将格式化/dev/sda3

[root@oralinux66 ~]# mkfs -t ext4 /dev/sda3

mke2fs 1.43-WIP (20-Jun-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1835008 inodes, 7339027 blocks 366951 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 224 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done

# 检查文件系统

root@oralinux66 ~]# fsck -f /dev/sda3

将分区加入虚拟卷组

[root@oralinux66 ~]# lvm # 用于将物理硬盘分区初始化为物理卷,以便LVM使用 lvm> pvcreate /dev/sda3

Physical volume "/dev/sda3" successfully created # 获取VG Name lvm> pvdisplay

--- Physical volume --- PV Name /dev/sda2 VG Name vg_oralinux66 PV Size 31.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 8066 Free PE 0 Allocated PE 8066 PV UUID bjNDod-d1vx-7xdi-iamU-CnSH-IbnJ-KKeqnE

"/dev/sda3" is a new physical volume of "28.00 GiB" --- NEW Physical volume --- PV Name /dev/sda3 VG Name
PV Size 28.00 GiB Allocatable NO PE Size 0
Total PE 0 Free PE 0 Allocated PE 0 PV UUID lr9eYq-b1Ko-9PD3-g0eb-WM9K-xduy-HCDRDf

lvm> ^C [root@oralinux66 ~]# lvm # 用于动态扩展LVM卷组,它通过向卷组vg_oralinux66中添加物理卷来增加卷组的容量 lvm> vgextend vg_oralinux66 /dev/sda3

Volume group "vg_oralinux66" successfully extended lvm> ^Z [1]+ Stopped lvm [root@oralinux66 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00003748

Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 4178 33041408 8e Linux LVM /dev/sda3 4178 7832 29356108 83 Linux

Disk /dev/mapper/vg_oralinux66-lv_root: 30.4 GB, 30396121088 bytes 255 heads, 63 sectors/track, 3695 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000

Disk /dev/mapper/vg_oralinux66-lv_swap: 3435 MB, 3435134976 bytes 255 heads, 63 sectors/track, 417 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000

将分区加到文件存储的主要部分

[root@oralinux66 ~]# lvm

lvm> lvextend -L +28G /dev/mapper/vg_oralinux66-lv_root

Insufficient free space: 7168 extents needed, but only 7166 available

# 容量加入到文件存储部分,真正实现扩容 lvm> lvextend -L +27G /dev/mapper/vg_oralinux66-lv_root

Size of logical volume vg_oralinux66/lv_root changed from 28.31 GiB (7247 extents) to 55.31 GiB (14159 extents). Logical volume lv_root successfully resized lvm> ^Z [2]+ Stopped lvm

刷新文件存储的主要部分

# 重新加载逻辑卷的大小才能生效 [root@oralinux66 ~]# resize2fs /dev/mapper/vg_oralinux66-lv_root

resize2fs 1.43-WIP (20-Jun-2013) Filesystem at /dev/mapper/vg_oralinux66-lv_root is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 4 The filesystem on /dev/mapper/vg_oralinux66-lv_root is now 14498816 blocks long.

[root@oralinux66 ~]# df -h

Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_oralinux66-lv_root 55G 27G 26G 51% / tmpfs 998M 247M 752M 25% /dev/shm /dev/sda1 477M 65M 384M 15% /boot [root@oralinux66 ~]#

root可用容量为26G

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值