大网数据广告活动
服务器运维问答

How to shrink /home and add more space on CentOS7

· 52CE 我爱测

CentOS 7 file system is XFS , And resize2fs doesn't work. I need to shrink /home to 400G and add 100G space to / . What should I do? # df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 50G 50G 341M 100% / d…

问题原文

原帖链接 · GoingMyWay · CC BY-SA 3.0

CentOS 7 file system is XFS, And resize2fs doesn't work. I need to shrink /home to 400G and add 100G space to /. What should I do?

# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   50G   50G  341M 100% /
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G   84K  7.8G   1% /dev/shm
tmpfs                    7.8G  778M  7.0G  10% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1                497M  241M  257M  49% /boot
tmpfs                    1.6G   16K  1.6G   1% /run/user/42
tmpfs                    1.6G     0  1.6G   0% /run/user/0
/dev/mapper/centos-home  500G   20G  480G   4% /home

The output of lvs, vgs and pvs are:

[root@localhost]~# lvs -v
    Using logical volume(s) on command line.
  LV   VG     #Seg Attr       LSize   Maj Min KMaj KMin Pool Origin Data%  Meta%  Move Cpy%Sync Log Convert LV UUID                                LProfile
  home centos    1 -wi-ao---- 499.38g  -1  -1  253    2                                                     4I53D9-7VSm-HN9H-QsSp-FvFU-5R9D-y5VwsN         
  root centos    1 -wi-ao----  50.00g  -1  -1  253    0                                                     LGRoEL-0EHz-G135-p6vx-Lt2s-RvI5-qdT9Sm         
  swap centos    1 -wi-ao----   7.81g  -1  -1  253    1                                                     UYB5xP-cEyV-lWvn-blIq-8s13-9kVB-ykjIWI         
[root@localhost]~# vgs -v
    Using volume group(s) on command line.
  VG     Attr   Ext   #PV #LV #SN VSize   VFree  VG UUID                                VProfile
  centos wz--n- 4.00m   1   3   0 557.26g 64.00m Gd5c08-ujdQ-fsix-o7z6-Wfsv-C0uW-XzDois         
[root@localhost]~# pvs -v
    Using physical volume(s) on command line.
    Found same device /dev/sda2 with same pvid TCmreQr93apETNoTl8bMc54l57FZ5hut
  PV         VG     Fmt  Attr PSize   PFree  DevSize PV UUID                               
  /dev/sda2  centos lvm2 a--  557.26g 64.00m 557.26g TCmreQ-r93a-pETN-oTl8-bMc5-4l57-FZ5hut
[root@localhost]~# 

已采纳解答

原帖链接 · Ari · CC BY-SA 4.0

As others have pointed out, XFS filesystem cannot be shrunk.

So your best bet is to backup /home, remove and recreate its volume in a smaller size and give the rest to your /root volume just as Koen van der Rijt outlined in his post.

• backup the contents of /home

tar -czvf /root/home.tgz -C /home .

• test the backup

tar -tvf /root/home.tgz

• unmount home

umount /dev/mapper/centos-home

• remove the home logical volume

lvremove /dev/mapper/centos-home

• recreate a new 400GB logical volume for /home, format and mount it

lvcreate -L 400GB -n home centos
mkfs.xfs /dev/centos/home
mount /dev/mapper/centos-home

• extend your /root volume with ALL of the remaining space and resize (-r) the file system while doing so

lvextend -r -l +100%FREE /dev/mapper/centos-root

• restore your backup

tar -xzvf /root/home.tgz -C /home

• check /etc/fstab for any mapping of /home volume. IF it is using UUID you should update the UUID portion. (Since we created a new volume, UUID has changed)

That's it.

Hope this helps.

Kindly add this to sync the changes:

dracut --regenerate-all --force

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。