CentoS 7 系统 扩容根分区

博客作者:联系请点击,搬运不易,希望请作者喝咖啡,可以点击联系博客作者

需求场景:

需要将客户物理机磁盘剩余的空闲空间分区,合并到逻辑卷,扩展根分区

当前环境:

[root@master ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   10T  9.5T  549G   95% /
devtmpfs                  16G     0   16G    0% /dev
tmpfs                     16G     0   16G    0% /dev/shm
tmpfs                     16G  9.7M   16G    1% /run
tmpfs                     16G     0   16G    0% /sys/fs/cgroup
/dev/vda2                2.0G  166M  1.9G    9% /boot
tmpfs                    3.2G     0  3.2G    0% /run/user/0

可以看到vda 磁盘有20T 还有10T空闲空间没有分配

[root@master ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0              11:0    1 1024M  0 rom  
vda             252:0    0 19.8T  0 disk 
├─vda1          252:1    0    1M  0 part 
├─vda2          252:2    0    2G  0 part /boot
└─vda3          252:3    0   10T  0 part 
   └─centos-root 253:0   0   10T  0 lvm  /

操作步骤:

第一步:将剩余空间分区

说明:parted 分区退出自动保存,不像fdisk需要保存

第二步:格式化分区

[root@master ~]# mkfs.xfs /dev/vda4

查看当前逻辑卷

[root@master ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               10 TiB
  PE Size               4.00 MiB
  Total PE              5180926
  Alloc PE / Size       5180926 / 10 TiB
  Free  PE / Size       0 / 0   
  VG UUID               jw3yqY-Ssfb-NNu3-iwDN-4CV2-d4Nq-uFL0So

第三步:逻辑化分区/dev/vda4,准备给centos逻辑卷扩容

[root@master ~]# pvcreate /dev/vda4
WARNING: xfs signature detected on /dev/vda4 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/vda4.
  Physical volume "/dev/vda4" successfully created.

第四步:开始扩容

[root@master ~]# vgextend centos /dev/vda4
  Volume group "centos" successfully extended
[root@master ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               19.76 TiB
  PE Size               4.00 MiB
  Total PE              5180926
  Alloc PE / Size       5180926 / 19.76 TiB
  Free  PE / Size       0 / 0   
  VG UUID               jw3yqY-Ssfb-NNu3-iwDN-4CV2-d4Nq-uFL0So

说明:磁盘空闲空间增长到19.76T,说明扩容成功

第五步:扩容/dev/mapper/centos-root逻辑卷分区

[root@master ~]# lvextend -l +100%FREE  /dev/mapper/centos-root 
  Size of logical volume centos/root changed from <10.00 TiB (2620927 extents) to 19.76 TiB (5180926 extents).
  Logical volume centos/root successfully resized.

第六步:更新逻辑卷分区的大小

[root@master ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=10, agsize=268435455 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2683829248, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=521728, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 2683829248 to 5305268224

第七步:检查是否扩容更新成功

[root@master ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   20T  9.5T   11T   48% /
devtmpfs                  16G     0   16G    0% /dev
tmpfs                     16G     0   16G    0% /dev/shm
tmpfs                     16G  9.7M   16G    1% /run
tmpfs                     16G     0   16G    0% /sys/fs/cgroup
/dev/vda2                2.0G  166M  1.9G    9% /boot
tmpfs                    3.2G     0  3.2G    0% /run/user/0

最后更新于