ext4文件系统可以经行扩缩容操作,但xfs的文件系统只能扩容,无法缩容
所以如果需要进行xfs的缩容,可以先使用xfsdump备份文件系统,然后对逻辑卷(/分区)进行缩容操作(此时原xfs文件系统会损坏),然后再重新格式化该逻辑卷(/分区),最后xfsrestore将备份还原到该逻辑卷(/分区)
当然,这需要先下载xfsdump工具
[root@localhost ~]# df -Th #查看文件系统磁盘使用情况 Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 7.9G 0 7.9G 0% /dev tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm tmpfs tmpfs 7.9G 8.9M 7.9G 1% /run tmpfs tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 50G 3.0G 47G 6% / /dev/sda2 xfs 1014M 131M 884M 13% /boot /dev/sda1 vfat 200M 12M 189M 6% /boot/efi /dev/mapper/centos-home xfs 64G 33M 64G 1% /home tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0 [root@localhost ~]# xfsdump -f ~/home.xfs_dump /home #备份文件系统 xfsdump: using file dump (drive_simple) strategy xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control ============================= dump label dialog ============================== please enter label for this dump session (timeout in 300 sec) -> #自定义备份会话标签,可直接回车 session label entered: "" --------------------------------- end dialog --------------------------------- xfsdump: WARNING: no session label specified xfsdump: level 0 dump of localhost.localdomain:/home xfsdump: dump date: Wed Oct 26 22:48:12 2022 xfsdump: session id: e3f11041-db93-41db-954f-b1101edb7b42 xfsdump: session label: "" xfsdump: ino map phase 1: constructing initial dump list xfsdump: ino map phase 2: skipping (no pruning necessary) xfsdump: ino map phase 3: skipping (only one dump stream) xfsdump: ino map construction complete xfsdump: estimated dump size: 20800 bytes ============================= media label dialog ============================= please enter label for media in drive 0 (timeout in 300 sec) -> #自定义备份媒体标签,可直接回车 media label entered: "" --------------------------------- end dialog --------------------------------- xfsdump: WARNING: no media label specified xfsdump: creating dump session media file 0 (media 0, file 0) xfsdump: dumping ino map xfsdump: dumping directories xfsdump: dumping non-directory files xfsdump: ending media file xfsdump: media file size 21352 bytes xfsdump: dump size (non-dir files) : 0 bytes xfsdump: dump complete: 1 seconds elapsed xfsdump: Dump Summary: xfsdump: stream 0 /root/home.xfs_dump OK (success) xfsdump: Dump Status: SUCCESS [root@localhost ~]# umount /home #卸载home分区,(业内习惯性叫home分区,其实就是home逻辑卷) [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-a----- 64.00g root centos -wi-ao---- 50.00g swap centos -wi-ao---- 12.80g [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 3 0 wz--n- 126.80g 0 [root@localhost ~]# lvreduce -L 24G /dev/mapper/centos-home #home分区缩容 WARNING: Reducing active logical volume to 24.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce centos/home? [y/n]: y Size of logical volume centos/home changed from 64.00 GiB (16384 extents) to 24.00 GiB (6144 extents). Logical volume centos/home successfully resized. [root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root #将空余空间全部给root分区 Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 90.00 GiB (23040 extents). Logical volume centos/root successfully resized. [root@localhost ~]# xfs_growfs /dev/mapper/centos-root #逻辑卷扩容后,需要刷新文件系统 meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=13107200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 13107200 to 23592960 [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 7.9G 0 7.9G 0% /dev tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm tmpfs tmpfs 7.9G 8.9M 7.9G 1% /run tmpfs tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 90G 3.0G 87G 4% / /dev/sda2 xfs 1014M 131M 884M 13% /boot /dev/sda1 vfat 200M 12M 189M 6% /boot/efi tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0 [root@localhost ~]# mkfs.xfs /dev/mapper/centos-home -f #格式化home分区 meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=1572864 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=6291456, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=3072, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]# mount /dev/mapper/centos-home /home/ #重新挂载home分区 [root@localhost ~]# xfsrestore -f ~/home.xfs_dump /home #home文件系统还原 xfsrestore: using file dump (drive_simple) strategy xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control xfsrestore: searching media for dump xfsrestore: examining media file 0 xfsrestore: dump description: xfsrestore: hostname: localhost.localdomain xfsrestore: mount point: /home xfsrestore: volume: /dev/mapper/centos-home xfsrestore: session time: Wed Oct 26 22:48:12 2022 xfsrestore: level: 0 xfsrestore: session label: "" xfsrestore: media label: "" xfsrestore: file system id: e59981eb-07f9-44e4-9c6f-9ecd8afc8b81 xfsrestore: session id: e3f11041-db93-41db-954f-b1101edb7b42 xfsrestore: media id: fd63d3e5-9bee-49f8-9872-9d17e82f80fc xfsrestore: using online session inventory xfsrestore: searching media for directory dump xfsrestore: reading directories xfsrestore: 1 directories and 0 entries processed xfsrestore: directory post-processing xfsrestore: restore complete: 0 seconds elapsed xfsrestore: Restore Summary: xfsrestore: stream 0 /root/home.xfs_dump OK (success) xfsrestore: Restore Status: SUCCESS [root@localhost ~]# df -Th #核对现在逻辑卷文件系统的情况 Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 7.9G 0 7.9G 0% /dev tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm tmpfs tmpfs 7.9G 8.9M 7.9G 1% /run tmpfs tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 90G 3.0G 87G 4% / /dev/sda2 xfs 1014M 131M 884M 13% /boot /dev/sda1 vfat 200M 12M 189M 6% /boot/efi tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0 /dev/mapper/centos-home xfs 24G 33M 24G 1% /home [root@localhost ~]#
#若有必要,使用uuid挂载
[root@localhost ~]# grep home /etc/fstab /dev/mapper/centos-home /home xfs defaults 0 0 [root@localhost ~]# blkid|grep home /dev/mapper/centos-home: UUID="39916644-f3eb-42c1-a940-8749395b88f9" TYPE="xfs"
xfsdump也可以面交互执行
-L :xfsdump 记录每次备份的 session 标头,这里可以填写针对此文件系统的简易说明
-M :xfsdump 可以记录存储媒体的标头,这里可以填写此媒体的简易说明
[root@localhost ~]# xfsdump -f ~/home.xfs_dump01 /home -L home_dump -M root_dir xfsdump: using file dump (drive_simple) strategy xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control xfsdump: level 0 dump of localhost.localdomain:/home xfsdump: dump date: Wed Oct 26 23:39:40 2022 xfsdump: session id: fa67f2be-0efe-4d23-b096-0fb0e3d12558 xfsdump: session label: "home_dump" xfsdump: ino map phase 1: constructing initial dump list xfsdump: ino map phase 2: skipping (no pruning necessary) xfsdump: ino map phase 3: skipping (only one dump stream) xfsdump: ino map construction complete xfsdump: estimated dump size: 20800 bytes xfsdump: creating dump session media file 0 (media 0, file 0) xfsdump: dumping ino map xfsdump: dumping directories xfsdump: dumping non-directory files xfsdump: ending media file xfsdump: media file size 21352 bytes xfsdump: dump size (non-dir files) : 0 bytes xfsdump: dump complete: 0 seconds elapsed xfsdump: Dump Summary: xfsdump: stream 0 /root/home.xfs_dump01 OK (success) xfsdump: Dump Status: SUCCESS [root@localhost ~]#
指定只备份分区中某个目录
参数:-s 文件路径 只对指定的文件进行备份,-s指定时,路径写的是相对路径(-s 可以是文件或目录)
[root@localhost sdb1]# xfsdump -f /opt/dump_grub2 -s grub2/grub.cfg /boot -L dump_grub2 -M boot-sda1
备份成功后,我们可以在/var/lib/xfsdump/inventory 目录下看到生成的档案信息
[root@localhost sdb1]# ls /
var
/lib/xfsdump/inventory/
0180aae6-80c6-472f-a031-c79f271f8177.InvIndex
a5398b8f-e1ae-49a4-9d70-5f1fc5a68194.StObj
a5c5b8d4-6656-4023-b576-96593b9440b8.StObj
ba6ae155-c50d-440d-802f-7111a5cd3d03.InvIndex
fstab
[root@localhost sdb1]# xfsdump -I # 查看备份信息
当然如果遇到挂载点繁忙,可以使用fuser或lsof去查看,或者直接umount -lf 挂载点
fuser 可以显示出当前哪个程序在使用磁盘上的:
标签:xfsrestore,dump,扩缩容,dev,xfsdump,lvm,home,xfs,root From: https://www.cnblogs.com/santia-god/p/16830616.html某个文件
挂载点
甚至网络端口