Adjust the space size of the root directory under Linux

Goal: Reduce VolGroup-lv_home to 20G and add the remaining space to VolGroup-lv_root

1. First check the disk usage
[root@localhost ~]# df -h
file system capacity used and available 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

2. Uninstall /home
[root@localhost ~]# umount /home
umount /home If it prompts that it cannot be uninstalled, there is a process occupying /home. Use the following command to terminate the occupying process:
[ root@localhost ~]# fuser -m /home 

3. Resize partition
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
If prompted to run "e2fsck -f /dev/mapper/VolGroup-lv_home", execute the relevant command:
[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_home Then execute the command again:
[root@localhost ~ ]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
Note: resize2fs is to re-set the disk size, just re-specify the size, it will not affect the result, it needs the cooperation of lvreduce below

4. Mount /home and check Disk usage
[root@localhost ~]# mount /home
[root@localhost ~]# df -h

5. Set free space
Use the lvreduce command to reduce the space occupied by LVM logical volumes. Existing data on the logical volume may be deleted, so confirmation must be made before operation. Remember to enter "y"
[root@localhost ~]# lvreduce -L 20G /dev/mapper/VolGroup-lv_home
Note: lvreduce -L 20G means to set the current file system to 20G, if lvreduce -l 20G means to start from the current file Reduce the size of the logical volume by 20G
using lvreduce on the system. Note: The reduced size cannot be smaller than the file size, otherwise data will be lost.

You can use the vgdisplay command, etc. to check the size that can be manipulated. You can also use the fdisk -l command to view detailed information.
[root@localhost ~]# vgdisplay
Note: vgdisplay is to display the metadata information of the LVM volume group

6. Hang the free space in the root directory
[root@localhost ~]# lvextend -L +283G /dev/mapper/VolGroup-lv_root
Note: lvextend -L +283G To add 283G to the file system
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_root

7. Check the adjustment result
[root@localhost ~]# df -h

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326673038&siteId=291194637
Recommended