[Virtual machine] centos7 distributes the disk space of /dev/sda to the root directory

1. Modify the size of the hard disk

Close the virtual machine→Settings→Hard Disk→Modify to the disk size you need

2. View 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 here 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 real disk size of the host is about 50G set before

fdisk -l

2. Create a partition

3. View the disk partition table again

4. Receive new partition table information

[root@test-1 ~]# partprobe 

5. Format the partition as ext4

mkfs.ext4 /dev/sda3

5. View volume group name

vgdisplay

6. Create a new physical volume

pvcreate /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 the logical partition

resize2fs /dev/centos/root

11. If an error is reported, check whether the file system is xfs

cat /etc/fstab

12. If so, use this command

xfs_growfs /dev/centos/root

13. View the root directory

df -h

At this time, it has become 47G, restart the virtual machine to take effect.

Guess you like

Origin blog.csdn.net/weixin_46156489/article/details/129475144