最近在VMware虚拟机上使用Centos,用着用着,发现虚拟机的磁盘空间不够了。通过以下步骤成功扩展了根目录的磁盘空间
1、Centos 关机,选择编辑虚拟机设置,硬盘,在实用工具那里选择“扩展”
填写扩展的磁盘容量
点击扩展后,VMware会提示磁盘已成功扩展。您必须从客户机操作系统内部对磁盘重新进行分区和扩展文件系统。也就是说,这里扩展的磁盘空间,在操作系统里面还不可用,还没生效,需要在操作系统里面进行设置后才能使用。
2、启动客户机操作系统Centos,查看磁盘情况
输入指令
显示结果如下
Disk /dev/loop0: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/loop1: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sda: 37.6 GB, 37580963840 bytes255 heads, 63 sectors/track, 4568 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000c8278 Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 1306 9972736 8e Linux LVMDisk /dev/mapper/vg_test001-lv_root: 9135 MB, 9135194112 bytes255 heads, 63 sectors/track, 1110 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_test001-lv_swap: 1073 MB, 1073741824 bytes255 heads, 63 sectors/track, 130 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/docker-253:0-264224-pool: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 65536 bytesDisk identifier: 0x00000000
其中,可以看到现在的分区情况如下
Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 1306 9972736 8e Linux LVM
3、创建分区 sda3
输入指令
然后根据命令提示创建分区,具体见以下 # 后面的注释
再次查看分区情况
这时可以看到
Disk /dev/loop0: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/loop1: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sda: 37.6 GB, 37580963840 bytes255 heads, 63 sectors/track, 4568 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000c8278 Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 1306 9972736 8e Linux LVM/dev/sda3 1306 4568 26206700 83 LinuxDisk /dev/mapper/vg_test001-lv_root: 9135 MB, 9135194112 bytes255 heads, 63 sectors/track, 1110 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_test001-lv_swap: 1073 MB, 1073741824 bytes255 heads, 63 sectors/track, 130 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/docker-253:0-264224-pool: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 65536 bytesDisk identifier: 0x00000000
其中,分区已变为3个了,但这时还没挂载,还不能用
Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 1306 9972736 8e Linux LVM/dev/sda3 1306 4568 26206700 83 Linux
4、重启操作系统
5、格式化新分区为ext3
输入指令
结果为
mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks1638400 inodes, 6551675 blocks327583 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296200 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000Writing inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 33 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
6、将物理硬盘分区初始化为物理卷,以便被LVM使用,输入指令
7、向卷组中添加物理卷来增加卷组的容量
查看lvm组名,输入指令 df -h
其中,vg_test001 就是 根 所在的组名
输入指令,增加卷组的容量
8、查看可扩展的空间大小
输入指令,显示LNM卷组的元数据信息
结果为
--- Volume group --- VG Name vg_test001 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 34.50 GiB PE Size 4.00 MiB Total PE 8831 Alloc PE / Size 2434 / 9.51 GiB Free PE / Size 6397 / 24.99 GiB # 可分配空间,1G=256 VG UUID JuPKc8-Ydps-1bsN-0Wld-fbYS-0Hd2-NgvX1q
其中 Free PE / Size 就是可供分配的自由空间,最多有 24.99G,在扩展时输入小于该值
9、扩充磁盘空间
10、使用e2fsck指令检查文件系统错误
11、使用resize2fs指令来增大或者收缩未加载的“ext2/ext3”文件系统的大小
12、查看扩展空间后的结果
可以看出,在根目录下磁盘空间已经扩容了,大功告成!