2016年12月19日 星期一

調整 XFS 格式的 Logical Volume 大小

以下文章摘自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
LV   VG     Attr       LSize  Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- 45.57g
root centos -wi-ao---- 50.00g
swap centos -wi-ao----  3.88g
將 /home 縮減為 5GB, 剩下都給 / (root)
安裝 xfsdump 套件
yum -y install xfsdump
備份 /home
xfsdump -f /home.xfsdump /home
please 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-home
Do 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
LV   VG     Attr       LSize  Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao----  5.00g
root centos -wi-ao---- 90.63g
swap centos -wi-ao----  3.88g