Expand the root directory under centos

General situation:

The BCLinux image of the mobile cloud is installed on the VM virtual machine, and the disk is set to 8G, but after a period of time, the disk in the root directory is full, and operations such as creating folders cannot be performed, so the disk is expanded on the VM. After the expansion It needs to be mounted on the system by itself. Using mount /dev/sda3/ cannot be mounted to the root directory. After consulting various blogs, the root directory was finally expanded successfully.

The following are detailed steps:

This step has expanded the hard disk configuration on the virtual machine. If it has not been modified, close the virtual machine, click Edit Virtual Machine Settings, and expand the hard disk, then refer to the following steps.

1. First list all partition tables and check the partitions in the virtual machine

fdisk –l

It can be seen that the newly added 7G is not displayed in the partition table, because we have not partitioned the newly added 7G space

2. Use fdisk to partition the newly expanded disk space

fdisk /dev/sda

Enter m to view various commands, n is to add a new partition, so enter n

After the partition type, enter P for the primary partition

Partition number, I already had sda1 and sda2 before, enter 3 here,

For the first sector, just enter and press Enter

For the last sector, also enter Enter

See that a new partition is created 3

Finally, enter w to save and exit.

4. At this time, re-enter fdisk -l to view the partition status of the virtual machine, and you can see the newly created sda3 partition

fdisk -l

5. Use df -T -h to view the type and size of the current file system, you can see that the disk under my root directory is 100% used, and its file type is ext4

6. Use the lsblk command to view the current disk and partition panorama information

7. Use the vgdisplay -v command to view volume groups

vgdisplay -v

 

Pay attention to VG Name, you can see that my VG Name is /dev/bigcloud-enterprise-linux-for-euler

8. Use the pvcreate /dev/sda3 command to create a physical volume in the system, where /dev/sda3 is the device path specifying the physical volume to be created

Then use pvdisplay to view the current physical volume and see /dev/sda3

pvcreate /dev/sda3
pvdisplay

9. Add the created physical volume to the volume group

vgextend bigcloud-enterprise-linux-for-euler /dev/sda3, where /dev/sda3 is the physical volume created in the previous step, and bigcloud-enterprise-linux-for-euler is the physical volume to be added

Then use vgdisplay to view the volume group information again

vgextend bigcloud-enterprise-linux-for-euler /dev/sda3 
lvdisplay

10. Extend the logical volume size: lvextend -l +100%FREE /dev/bigcloud-enterprise-linux-for-euler/root

Extend all the newly created physical volumes to the /dev/bigcloud-enterprise-linux-for-euler/root volume group. Note that the name of the volume group should be changed to the name of your own volume group. If you don’t know it, just Use the df -h command to view the volume group name of your root directory

lvextend -l +100%FREE /dev/bigcloud-enterprise-linux-for-euler/root

11. To expand the logical volume, my file system is in ext4 format, so use the resize2fs command (ext2 3 4 can use this command)

resize2fs /dev/mapper/bigcloud--enterprise--linux--for--euler-root

If the file system is in xfs format, use the xfs_growfs command

xfs_growfs /dev/mapper/bigcloud--enterprise--linux--for--euler-root

 If not, you can try

xfs_growfs /

 

12. Finally, use df -h to check whether the expansion is successful

df -h

You can see that the /dev/mapper/bigcloud--enterprise--linux--for--euler-root volume group has changed from 6.1G to 13G, and the expansion is successful, so it can continue to be used.

Guess you like

Origin blog.csdn.net/guaizaiguaizai/article/details/132467323