背景知识:
目前想缩小home分区到10GB:
[root@LinuxVm ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cs-root xfs 70G 3.8G 67G 6% / /dev/mapper/cs-home xfs 160G 1.2G 158G 1% /home /dev/sdb2 xfs 1014M 215M 800M 22% /boot /dev/sdb1 vfat 599M 7.3M 592M 2% /boot/efi [root@LinuxVm ~]# yum -y install xfsdump [root@LinuxVm ~]# xfsdump -f /home.xfsdump /home # 期间会有两次确认信息 [root@LinuxVm ~]# ll -h /home.xfsdump -rw-r--r--. 1 root root 29K Apr 13 21:55 /home.xfsdump [root@LinuxVm ~]# fuser -km /home /home: 5728c 5760c [root@LinuxVm ~]# umount /home [root@LinuxVm ~]# lvreduce -L 10G /dev/cs/home WARNING: Reducing active logical volume to 10.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce cs/home? [y/n]: y Size of logical volume cs/home changed from 159.10 GiB (40730 extents) to 10.00 GiB (2560 extents). Logical volume cs/home successfully resized. [root@LinuxVm ~]# lvextend -l +100%FREE /dev/cs/root Size of logical volume cs/root changed from 70.00 GiB (17920 extents) to 219.10 GiB (56090 extents). Logical volume cs/root successfully resized. [root@LinuxVm ~]# xfs_growfs /dev/cs/root [root@LinuxVm ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cs-root xfs 220G 4.8G 215G 3% / #剩余空间已经全部给到了根分区 /dev/sdb2 xfs 1014M 215M 800M 22% /boot /dev/sdb1 vfat 599M 7.3M 592M 2% /boot/efi [root@LinuxVm ~]# mkfs.xfs /dev/cs/home -f [root@LinuxVm ~]# mount /dev/cs/home /home [root@LinuxVm ~]# xfsrestore -f /home.xfsdump /home [root@LinuxVm ~]# grep home /etc/fstab /dev/mapper/cs-home /home xfs defaults 0 0 [root@LinuxVm ~]# blkid | grep home #确认一下,万一是UUID挂载,需要更新一下fastab /dev/mapper/cs-home: UUID="62ffb186-26e2-4fe9-abb1-8dff33975da7" BLOCK_SIZE="512" TYPE="xfs" [root@LinuxVm ~]# df -Th | egrep 'home|root' /dev/mapper/cs-root xfs 220G 4.8G 215G 3% / /dev/mapper/cs-home xfs 10G 104M 9.9G 2% /home
至此完成。