centos7重新调整分区大小

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.

 

# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   50G  9.1G   41G   19% /
devtmpfs                  63G     0   63G    0% /dev
tmpfs                     63G     0   63G    0% /dev/shm
tmpfs                     63G  9.8M   63G    1% /run
tmpfs                     63G     0   63G    0% /sys/fs/cgroup
/dev/sda2               1014M  239M  776M   24% /boot
/dev/mapper/centos-home  0.3T  147G  0.1T    2% /home
tmpfs                     13G     0   13G    0% /run/user/0

 

stop services: apache, tomcat, mysql etc. on home

systemctl stop mysql

systemctl stop tomcat

 

systemctl status mysql

systemctl status tomcat

 

 

backup the contents of /home

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

• test the backup

> tar -tvf /home/home.tgz
copy /home/home.tgz to other PC

• unmount home

> umount /dev/mapper/centos-home

如果显示/home正忙,且不在/home目录下,说明/home下有进程正在使用,用
fuser -m -v -i -k /home
杀死/home下的进程,再解除挂载点。但是fuser在centos7里面不是默认安装的,需要
yum install psmisc
来安装这个包。

• remove the home logical volume

> lvremove /dev/mapper/centos-home

  • 扩展/root所在的lv,增加200G : lvextend -L +200G /dev/mapper/centos-root
  • 扩展/root文件系统 : xfs_growfs /dev/mapper/centos-root

vgdisplay

重新创建home lv 分区的大小,根据 vgdisplay 中的free PE 的大小确定

lvcreate -L 300G -n home centos

  • 创建文件系统: mkfs.xfs /dev/centos/home
  • 挂载 home: mount /dev/centos/home /home
 

• 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.

 

REF:

https://serverfault.com/questions/771921/how-to-shrink-home-and-add-more-space-on-centos7?newreg=7fb7d8d40ca441f0add4586f51f7bb8b

posted @ 2018-12-25 08:21  emanlee  阅读(4927)  评论(0编辑  收藏  举报