How to adjust the size of home and root partition in CentOS of Linux system

Time:2021-6-10

After the XXX / data / path of owncloud was modified, there was no write permission for the web server, so the capacity of the redundant home partition was adjusted to the root folder, and the related problems were solved. The next problem is to solve the problem of external hard disk.

Objective:The volgroup LV_ Reduce home to 20g and add the remaining space to volgroup Lv_ root

1. First check disk usage
[[email protected]~]# df -h
File system capacity used% free used mount point
Filesystem            Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  154G 7.9G 139G  6% /
tmpfs               1.9G 100K 1.9G  1% /dev/shm
/dev/sda1             485M 69M 391M  15% /boot
/dev/mapper/VolGroup-lv_ Home 299G 984m 283g 1% / home goal: volgroup LV_ Reduce home to 20g and add the remaining space to volgroup Lv_ root

2. Uninstall / home
[[email protected]~]# umount /home
Umount / homeIf the prompt cannot be unloaded, there is a process occupying / home. Use the following command to terminate the occupying process:
[[email protected]~]# fuser -m /home

3. Resizing partitions
[[email protected]~]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
If prompted to run “e2fsck – F / dev / mapper / volgroup Lv”_ Then execute the related commands:
[ [email protected] ~]# e2fsck -f /dev/mapper/VolGroup-lv_ Home and re execute the command:
[ [email protected] ~]# resize2fs -p /dev/mapper/VolGroup-lv_ Note: to reset the disk size, resize2fs only needs to re specify the size, which will not affect the result. It needs the cooperation of lvreduce below
  4. Mount / home to check disk usage
[[email protected]~]# mount /home
[[email protected]~]# df -h

5. Set free space
The lvreduce instruction is used to reduce the space occupied by LVM logical volume. Existing data on the logical volume may be deleted, so you must confirm before you operate. Remember to enter “Y”
[ [email protected] ~]# lvreduce -L 20G /dev/mapper/VolGroup-lv_ Note: lvreduce – L 20g means to set the current file system to 20g. If lvreduce – L 20g means to reduce 20g from the current file system
Use lvreduce to reduce the size of the logical volume.

Note: the reduced size cannot be smaller than the size of the file, otherwise the data will be lost.
 
You can use the vgdisplay command to check the size of the operation. You can also use the fdisk – L command to view the details.
[ [email protected] ~]#Vgdisplay note: vgdisplay displays the metadata information of LVM volume group
 
6. Hang the free space in the root directory
[[email protected]~]# lvextend -L +283G /dev/mapper/VolGroup-lv_root
Note: lvextend – L + 283g is to add 283g to the file system
[ [email protected] ~]# resize2fs -p /dev/mapper/VolGroup-lv_ Finally, check the adjustment result
[[email protected]~]# df -h

The above is sometimes due to improper partition when installing the system, some partition space is insufficient, need to adjust the size of home and root partition, thank you for reading, hope to help you, please continue to pay attention to developer, we will try to share more excellent articles.