将/home目录压缩一部分空间到/
ref: https://serverfault.com/a/811124/434124
https://stackoverflow.com/a/19969471/8025086
https://ask.fedoraproject.org/en/question/10427/lvm-issue-with-lvremove-logical-volume-contains-a-filesystem-in-use/
由于xfs文件系统不能缩小空间,所以只能将/home先卸载,调整大小,再挂载,将剩余空间分配给/
As others have pointed out, XFS filesystem cannot be shrunk.
So your best bet is to backup /home, remove and recreate its volume in a smaller size and give the rest to your /root volume just as Koen van der Rijt outlined in his post.
• backup the contents of /home
> tar -czvf /root/home.tgz -C /home .
• test the backup
> tar -tvf /root/home.tgz
• unmount home
> umount /dev/mapper/centos-home # 有可能有target is busy错误,使用umount -l /dev/mapper/centos-home, l表示lazy
• remove the home logical volume
> lvremove /dev/mapper/centos-home # 有可能有Logical volume centos/home contains a filesystem in use. 使用lvremove -f /dev/mapper/centos-home,如果还不可以,使用lvremove -f /dev/mapper/centos-home 然后再lvremove -f /dev/mapper/centos-home
• recreate a new 400GB logical volume for /home, format and mount it
> lvcreate -L 400GB -n home centos
> mkfs.xfs /dev/centos/home
> mount /dev/mapper/centos-home
• extend your /root volume with ALL of the remaining space and resize (-r) the file system while doing so
> lvextend -r -l +100%FREE /dev/mapper/centos-root # 测试,用-t
• restore your backup
> tar -xzvf /root/home.tgz -C /home
• check /etc/fstab for any mapping of /home volume. IF it is using UUID you should update the UUID portion. (Since we created a new volume, UUID has changed)
That's it.
Hope this helps.