As others have pointed out, XFS filesystem cannot be shrunk.mysql
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.sql
# 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
apache
stop services: apache, tomcat, mysql etc. on homecentos
systemctl stop mysqltomcat
systemctl stop tomcatapp
systemctl status mysqlpost
systemctl status tomcatthis
• backup the contents of /homecentos7
> tar -czvf /home/home.tgz -C /home .
• test the backupspa
> tar -tvf/home/home.tgz
copy /home/home.tgz to other PC/home/home.tgz
• 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: