Centos ext4 format / directory space is insufficient and you need to allocate home space to the / directory

Centos ext4 format / directory space is insufficient and you need to allocate home space to the / directory

Note: You must log in as the root user at first. It will not work if you switch to root later.

1. View the file system

df  -hT

Insert image description here

lsblk

Insert image description here

2. Back up data

cp  -r  /home  homebak

Insert image description here

3. Unmount the partition to be operated

Before uninstalling /home, you must first terminate all processes using the /home file system.
You can use fuser -m /home to check which process information, then kill -9 pid and then uninstall: umount /home. If you accidentally run fuser in the home directory -km /home, then use the forced uninstall command umount -l /home to uninstall.

4. Compress the volume home and compress the space to 1G

resize2fs -p /dev/mapper/VolGroup-lv_host 1G

If you encounter a prompt that you need to execute another command first, follow the prompts.

e2fsck -f /dev/mapper/VolGroup-lv_host

Insert image description here

5. Remount and check the compression situation. You can see that the space in the home directory has been compressed.

Mount /dev/VolGroup/lv_host  /home
Df -h

6. Reduce the logical partition of /dev/mapper/VolGroup-lv_host to the specified size. Here we reduce it to 2G.

lvreduce  -L 2G /dev/mapper/VolGroup-lv_hose

Insert image description here

7. Check the size of the physical volume. Free PE/Size is the available space.

vgdisplay

Insert image description here

8. Increase the size of /dev/mapper'/VolGroup-lv_root (the increased value cannot be equal to the value of Free PE/Size in the above figure, Free PE/Size needs to leave some space)

lvextend -L +11G  /dev/mapper/VolGroup-lv_root

Insert image description here

9. Check if completed

Insert image description here

10. Recover data

cp  -r  homebak/*  /home/

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_46010834/article/details/130196248