1. Modify the hard disk size
Shut down the virtual machine→Settings→Hard Disk→Modify to the disk size you need
2. Check the current disk usage statistics of the root directory
df -h
Note: Although the new disk size has been set to 50G in step 1, it can be clearly seen that the total disk size is still the previous 20G, which involves partitioning issues.
3. Modify the partition and allocate disk space to the root directory
1. View the disk partition table
You can see that the actual disk size of the host is about 50G which was set before.
fdisk -l
2. Create a partition
3. Check the disk partition table again
4. Receive new partition table information
[root@test-1 ~]# partprobe
5. Format the partition into ext4 format
mkfs.ext4 /dev/sda3
5. View the volume group name
vgdisplay
6. Create a new physical volume
pvccreate /dev/sda3
7. Expand to volume group
vgextend centos /dev/sda3
8. View the root partition
lvdisplay
9. Expand to capacity logical partition
lvextend /dev/centos/root /dev/sda3
10. Refresh logical partitions
resize2fs /dev/centos/root
11. If an error is reported, check whether the file system is xfs.
Disk expansion report resize2fs: Bad magic number in super-block
# resize2fs -p -F /dev/mapper/mpatha
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block 当尝试打开 /dev/mapper/mpatha 时
找不到有效的文件系统超级块.
cat /etc/fstab
12. If yes, use this command
xfs_growfs /dev/centos/root
13. View the root directory
df -h
At this time, it has become 47G, and restarting the virtual machine will take effect.