以下文章摘自http://jamyy.us.to/blog/2015/09/7673.html
調整 XFS 格式的 Logical Volume 大小
by Jamyy on 九月.04, 2015, under Linux
由於 XFS 只能擴大不能縮小, 利用 xfsdump / xfsrestore 工具, 在必須縮小 Logical Volume 的情況下, 得以備份、還原資料。
操作環境: CentOS 7, 安裝時採用 Automatically configure partitioning (XFS + LVM)
處理前環境
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- 99.51g 64.00m# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- 99.51g 64.00m# lvs
將 /home 縮減為 5GB, 剩下都給 / (root)
安裝 xfsdump 套件
# yum -y install xfsdump備份 /home
# xfsdump -f /home.xfsdump /homeplease enter label for this dump session (timeout in 300 sec)
-> home
please enter label for media in drive 0 (timeout in 300 sec)
-> home卸載 /home
# umount /home將 /home 的 Logical Volume 縮減為 5GB
# lvreduce -L 5G /dev/mapper/centos-homeDo you really want to reduce home? [y/n]: y將騰出的空間都給 / (root)
# lvextend -l +100%FREE /dev/centos/root延展 xfs 空間
# xfs_growfs /dev/centos/root
恢復 /home 內容
格式化 /home 的 Logical Volume
# mkfs.xfs -f /dev/mapper/centos-home掛載 /home
# mount /home將備份資料寫回 /home
# xfsrestore -f /home.xfsdump /home
處理後環境
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- 99.51g 0# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- 99.51g 0# lvs