centos7针对xfs文件系统删除home目录并动态扩容根目录

操作背景:
运维同事安装操作系统按照参数来划分磁盘,不满足现在项目的需求,需要重新划分调整磁盘分区的大小来满足项目需要

删除home目录并动态扩容根目录的思路如下:
针对xfs文件系统对新安装好的服务器删除home文件系统所在的逻辑卷,增大根目录的逻辑卷,从而达到增大根目录大小

  1. 通过lsblk命令将新安装操作系统的机器列出块设备信息
[root@40-186 yum.repos.d]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  2.7T  0 disk 
├─sda1            8:1    0    1M  0 part 
├─sda2            8:2    0    1G  0 part /boot
└─sda3            8:3    0  2.7T  0 part 
  ├─centos-root 253:0    0  2.6T  0 lvm  /
  ├─centos-swap 253:1    0 31.4G  0 lvm  [SWAP]
  └─centos-home 253:2    0  100G  0 lvm  /home

  1. 卸载已经改在的/home目录,并删除/home目录挂载的逻辑卷
[root@40-186 yum.repos.d]# umount /home
[root@40-186 yum.repos.d]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y  
  Logical volume "home" successfully removed

  1. 使用lvextend命令把剩余的磁盘空间全部在线扩展根目录所在的逻辑卷的空间,并执行 xfs_growfs同步文件系统(这样df -Th就可以显示了)
[root@40-186 yum.repos.d]#  lvextend -l +100%FREE /dev/mapper/centos-root
  Size of logical volume centos/root changed from <2.60 TiB (681358 extents) to <2.70 TiB (706959 extents).
  Logical volume centos/root successfully resized.
[root@40-186 yum.repos.d]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=174427648 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=697710592, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=340679, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 697710592 to 723926016
  1. 通过lsblk命令将修改后的块设备信息展示,同时df -Th也要同步更新显示
[root@40-186 yum.repos.d]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  2.7T  0 disk 
├─sda1            8:1    0    1M  0 part 
├─sda2            8:2    0    1G  0 part /boot
└─sda3            8:3    0  2.7T  0 part 
  ├─centos-root 253:0    0  2.7T  0 lvm  /
  └─centos-swap 253:1    0 31.4G  0 lvm  [SWAP]
[root@40-186 yum.repos.d]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  2.7T  1.2G  2.7T   1% /
devtmpfs                  32G     0   32G   0% /dev
tmpfs                     32G     0   32G   0% /dev/shm
tmpfs                     32G  9.2M   32G   1% /run
tmpfs                     32G     0   32G   0% /sys/fs/cgroup
/dev/sda2               1014M  145M  870M  15% /boot
tmpfs                    6.3G     0  6.3G   0% /run/user/0
[root@40-186 yum.repos.d]# 

你可能感兴趣的:(centos)