Linux Centos 7 adjust partition size

Foreword: When installing a new system, sometimes it is impossible to predict or divide the size of the partition incorrectly, which often leads to great inconvenience in our subsequent operations. For example, a partition is too small, resulting in software installation Sometimes it will be reported that the installation space is not enough, which is very troublesome. Here I will record the whole process of resizing the home and root partition storage space after the wrong partition.

1. First use df -h to check the partition size. It is found that the /home space is too large, but the root space is too small

2. Use mount |grep root to check the file partition system type. Linux partition formats are mainly ext2/ext3/ext4 and xfs 
      ------------------ It should be noted that the root partition It must be the same as the home partition type to perform compression and expansion adjustments:

 3. Format specification:

-------The adjustment command of ext2/ext3/ext4 file system is resize2fs (both increase and decrease are supported)
lvextend -L 120G /dev/mapper/centos-home //Increase to 120G
lvextend -L +20G /dev/mapper/centos-home //Increase 20G
lvreduce -L 50G /dev/mapper/centos-home //Reduce to 50G
lvreduce -L -8G /dev/mapper/centos-home //Reduce 8G
resize2fs / dev/mapper/centos-home //Execute adjustment
-------The adjustment command of the xfs file system is xfs_growfs (only supports increase)
lvextend -L 120G /dev/mapper/centos-home //Increase to 120G
lvextend -L +20G /dev/mapper/centos-home //Add 20G
xfs_growfs /dev/mapper/centos-home //Perform adjustment

4. After checking the file type is xfs, but xfs_frowfs only supports enlargement, so other methods can be used here.
If it is ext2/ext3/ext4 type, then use the above commands.

4.1 Use umount /home/ to unmount the home partition,
      if it prompts that home is busy, first execute fuser -km /home/    
      and then execute umount /home/

[root@localhost ~]# umount /home/
​​​​​​​[root@localhost ~]# lvreduce -L -400G /dev/mapper/centos-home 


4.2. Format the home partition

[root@localhost ~]# mkfs.xfs /dev/mapper/centos-home -f

4.3, mount it to home again

[root@localhost ~]# mount /dev/mapper/centos-home /home/

 5. Query the partition size df -h again and find that the home partition size has been reduced

 5.1 Check the free space after vgdisplay compression,

 5.2 Adjust Free idle 300G to root   

5.3 Expand 300 G for root

[root@localhost ~]# lvextend -L +400G /dev/mapper/centos-root

5.4 Executing operations

[root@localhost ~]# xfs_growfs /dev/mapper/centos-root

 5.5 Waiting for data blocks changed from 13107200 to 91750400 means the expansion is successful

verify:::::

 PS: Refer to  Adjust partition size under LINUX7_Linux adjust partition size_Tyler Tang's blog-CSDN blog   to complete the post

Guess you like

Origin blog.csdn.net/shanxun1012/article/details/130520949