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.
# df -h
檔案系統 容量 已用 可用 已用% 掛載點
/dev/mapper/centos-root 50G 9.1G 41G 19% /
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 9.8M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/sda2 1014M 239M 776M 24% /boot
/dev/mapper/centos-home 0.3T 147G 0.1T 2% /home
tmpfs 13G 0 13G 0% /run/user/0
stop services: apache, tomcat, mysql etc. on home
systemctl stop mysql
systemctl stop tomcat
systemctl status mysql
systemctl status tomcat
• backup the contents of /home
> tar -czvf /home/home.tgz -C /home .
• test the backup
> tar -tvf /home/home.tgz
copy /home/home.tgz to other PC
• unmount home
> umount /dev/mapper/centos-home
如果顯示/home正忙,且不在/home目錄下,說明/home下有程式正在使用,用
fuser -m -v -i -k /home
殺死/home下的程式,再解除掛載點。但是fuser在centos7裡面不是預設安裝的,需要
yum install psmisc
來安裝這個包。
• remove the home logical volume
> lvremove /dev/mapper/centos-home
- 擴充套件
/root
所在的lv,增加200G :lvextend -L +200G /dev/mapper/centos-root
- 擴充套件/root檔案系統 :
xfs_growfs /dev/mapper/centos-root
vgdisplay
重新建立home lv
分割槽的大小,根據 vgdisplay 中的free PE 的大小確定
lvcreate -L 300G -n home centos
- 建立檔案系統:
mkfs.xfs /dev/centos/home
- 掛載
home
:mount /dev/centos/home /home
• 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.
REF: