首页 > 其他分享 >lvm+xfs的扩缩容

lvm+xfs的扩缩容

时间:2022-10-26 23:55:34浏览次数:46  
标签:xfsrestore dump 扩缩容 dev xfsdump lvm home xfs root

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

相关文章

  • lvm卷 扩容
    lvdisplay#查看已经存在的LV信息,以存在LV:LogVol01为例创建:lvcreate-L90G-nLogVol01VolGroup00扩展:lvextend–L+1G/dev/VolGroup00/LogVol01#扩展LVresize2fs......
  • LVM扩容大容量磁盘
    今天帮客户扩容一个虚拟机的LVM卷,记录一下方法怎么给虚拟机添加磁盘就不描述了,直接从添加磁盘以后开始1.使用命令 lsblk查看新添加的磁盘2.使用 parted 给大容量磁......
  • LVM添加硬盘并扩容至已有分区
    转载自:https://www.dogfei.cnLVM添加硬盘新增一块硬盘,大小为200G,如下:#lsblkNAMEMAJ:MINRMSIZEROTYPEMOUNTPOINTfd02:014......
  • 这个项目是一个学习 LLVM 的教程
    https://github.com/P2Tree/LLVM_for_cpu0介绍这个项目是一个学习LLVM的教程,我实现了一个LLVM框架下的后端,用来编译能够在Cpu0上执行的可执行代码,Cpu0是一个简单......
  • Oracle Linux 7u2 启动错误 XFS_WANT_CORRUPTED_GOTO
    OracleLinux7u2 (OracleLinux-R7-U2-Server-x86_64-dvd.iso) 安装海锋五笔(ibus-table-chinese-wubi-haifeng-1.4.6-3.el7.noarch.rpm)后,启动系统失败。 XFS: In......
  • Btrfs vs. EXT4 vs. F2FS vs. XFS vs. reiserFS 性能比对
    ext4、ntfs、xfs、btrfs、zfs、f2fs和reiserFS性能测试对比https://blog.csdn.net/linkyy5/article/details/125955196Linux5.14SSDBenchmarksWithBtrfsvs.EXT4vs......
  • 修改 Proxmox VE 6.0 LVM Thin 为存储分区
    PVE安装后默认将60G的SSD分为了14G和26G的两个分区,其中25G为LVMThin,用于ISO镜像存储的分区为14G,明显不够用,传一个WInServer2016的镜像就会占用5G+。虽说......
  • CentOS 7 下 LVM 创建流程
    1.简介1.1.逻辑卷概念PP(PhysicalPartition)-物理分区如硬盘的分区,或RAID分区。PV(PhysicalVolume)-物理卷是PP的LVM抽象,它维护了PP的结构信息,是组成VG的基本......
  • ext4和xfs文件系统的扩容和收缩
    1.LVM逻辑卷管理2.ext4文件系统2.1扩容CentOS6的根文件系统(ext4)根文件系统在/dev/VolGroup/lv_root逻辑卷上,文件系统类型为ext4,大小为10G,现在要将其扩容成20G。1......
  • LVM与磁盘配额
    分区的缺点:1、一旦建立无法修改想修改得重新格式化数据丢失2、不够灵活空间只能来自一块硬盘,且必须是连续的空间3、没有备份冗余功能需要工程师手动备份 如果没......