首页 > Unix > Centos7 缩小/home文件系统,空间加给根

Centos7 缩小/home文件系统,空间加给根

1 目标
如下文件系统,/home缩小至150g,余下空间都给根(/)

[root@dorisbe5 etc]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 126G     0  126G   0% /dev
tmpfs                    126G     0  126G   0% /dev/shm
tmpfs                    126G   44M  126G   1% /run
tmpfs                    126G     0  126G   0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  2.2G   48G   5% /
/dev/sda2               1014M  130M  885M  13% /boot
/dev/sda1                200M   12M  189M   6% /boot/efi
/dev/mapper/centos-home  2.2T   34M  2.2T   1% /home
tmpfs                     26G     0   26G   0% /run/user/0

2 准备工作
(1) 安装xfsdump
yum install -y xfsdump
(2)备份/home
临时备份到/tmp下,随便取个文件名

[root@dorisbe5 etc]# xfsdump -l 0 -L home -M home -f /tmp/home.xfsdump /home
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 dorisbe5:/home
xfsdump: dump date: Sun Mar  5 14:22:44 2023
xfsdump: session id: 08d43fe5-e7ed-4654-9e1b-aa4e7dfdb172
xfsdump: session label: "home"
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: /var/lib/xfsdump/inventory created
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 /tmp/home.xfsdump OK (success)
xfsdump: Dump Status: SUCCESS

3 缩小/home,空间加到根
(1) umount /home并缩小

[root@dorisbe5 etc]# lvreduce -L 150G /dev/mapper/centos-home
  WARNING: Reducing active logical volume to 150.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 <2.13 TiB (558053 extents) to 150.00 GiB (38400 extents).
  Logical volume centos/home successfully resized.

(2) 空间加到根

[root@dorisbe5 etc]# lvextend -l +100%FREE /dev/mapper/centos-root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 2.03 TiB (532453 extents).
  Logical volume centos/root successfully resized.
[root@dorisbe5 etc]# 
[root@dorisbe5 etc]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=16, agsize=819200 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=64     swidth=64 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 545231872

(3)恢复/home

[root@dorisbe5 etc]# mkfs.xfs -f /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512    agcount=16, agsize=2457600 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=39321600, imaxpct=25
         =                       sunit=64     swidth=64 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=19200, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@dorisbe5 etc]# 
[root@dorisbe5 etc]# mount /home
[root@dorisbe5 etc]# 
[root@dorisbe5 etc]# xfsrestore -f /tmp/home.xfsdump /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: dorisbe5
xfsrestore: mount point: /home
xfsrestore: volume: /dev/mapper/centos-home
xfsrestore: session time: Sun Mar  5 14:22:44 2023
xfsrestore: level: 0
xfsrestore: session label: "home"
xfsrestore: media label: "home"
xfsrestore: file system id: 3bb9514b-0721-4ca0-9a77-8bccc169df88
xfsrestore: session id: 08d43fe5-e7ed-4654-9e1b-aa4e7dfdb172
xfsrestore: media id: fe2f48f6-e24e-4105-886d-723c1fcdccba
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 /tmp/home.xfsdump OK (success)
xfsrestore: Restore Status: SUCCESS

4 验证
再查看一下文件系统,会发现已经调整完成

[root@dorisbe5 etc]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 126G     0  126G   0% /dev
tmpfs                    126G     0  126G   0% /dev/shm
tmpfs                    126G   44M  126G   1% /run
tmpfs                    126G     0  126G   0% /sys/fs/cgroup
/dev/mapper/centos-root  2.1T  2.3G  2.1T   1% /
/dev/sda2               1014M  130M  885M  13% /boot
/dev/sda1                200M   12M  189M   6% /boot/efi
tmpfs                     26G     0   26G   0% /run/user/0
/dev/mapper/centos-home  150G   33M  150G   1% /home
[root@dorisbe5 etc]# 
分类: Unix 标签: , ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.