Linux 逻辑卷扩容

Linux 逻辑卷扩容

 关键词:pv(物理卷)、vg(卷组) 、lv(逻辑卷)

今天在用linux过程中,根分区容量不够了,突然想起来好久没更新博客,就来说说逻辑卷扩容的问题吧。

1、扩容前的检查

记住/dev/mapper/rhel-root 我们等会给它扩容,记好root的分区类型为xfs

[root@hsun ~]# df -hT
文件系统                类型      容量   已用  可用   已用% 挂载点
/dev/mapper/rhel-root xfs      10G   6.7G  3.4G   67% /
devtmpfs              devtmpfs  1.9G     0  1.9G    0% /dev
tmpfs                 tmpfs     1.9G  4.0K  1.9G    1% /dev/shm
tmpfs                 tmpfs     1.9G  9.2M  1.9G    1% /run
tmpfs                 tmpfs     1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mapper/rhel-usr  xfs        35G   24G   12G   68% /usr
/dev/sda1             xfs      1014M  145M  870M   15% /boot
/dev/mapper/rhel-var  xfs       8.0G  5.5G  2.6G   69% /var
/dev/mapper/rhel-opt  xfs       4.0G  1.3G  2.8G   32% /opt
/dev/mapper/rhel-tmp  xfs       4.0G   34M  4.0G    1% /tmp
tmpfs                 tmpfs     378M     0  378M    0% /run/user/1002
tmpfs                 tmpfs     378M     0  378M    0% /run/user/20001116
tmpfs                 tmpfs     378M     0  378M    0% /run/user/0

可以看见root的VG(卷组)是rhel

[root@hsun ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
opt rhel -wi-ao---- 4.00g 
root rhel -wi-ao---- 13.90g 
swap rhel -wi-ao---- 8.00g 
tmp rhel -wi-ao---- 4.00g 
usr rhel -wi-ao---- <35.00g 
var rhel -wi-ao---- 8.00g

而vg(卷组)和pv(物理卷)的剩余空间都为0,所以我们要增加一块新的磁盘

[root@hsun ~]# vgs
VG #PV #LV #SN Attr VSize VFree 
rhel 1 6 0 wz--n- <69.00g 0 
[root@hsun ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- <69.00g 0

我们先将机器关机

[root@hsun ~]# poweroff -f
Powering off.

 2、增加新磁盘(给机器插入一块新的硬盘)

在VMware中增加一块硬盘,大小为4G。增加完了之后开机

 

3、扩容磁盘

3.1 开机之后检查新的硬盘

可以看见,刚刚插入的磁盘已经读出来了,在我的机器上为/dev/sdb大小为4G

[root@hsun ~]# fdisk -l | grep /dev/sd
磁盘 /dev/sdb:4294 MB, 4294967296 字节,8388608 个扇区
磁盘 /dev/sda:75.2 GB, 75161927680 字节,146800640 个扇区
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 146800639 72350720 8e Linux LVM

3.2 创建PV

[root@hsun ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda2  rhel lvm2 a--  <69.00g    0 
[root@hsun ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@hsun ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda2  rhel lvm2 a--  <69.00g    0 
  /dev/sdb        lvm2 ---    4.00g 4.00g

3.3 将PV的空间划入名为rhel的VG

[root@hsun ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree 
  rhel      1   6   0 wz--n- <69.00g     0 
[root@hsun ~]# vgextend rhel /dev/sdb
  Volume group "rhel" successfully extended
[root@hsun ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree 
  rhel   2   6   0 wz--n- 72.99g <4.00g
可以看到卷组vg已经成功的有69G扩容到73G,剩余4G未使用的空间

3.4 对root逻辑卷进行扩容操作

[root@hsun ~]# lvextend -L +3.9G /dev/rhel/root 
或者使用 lvextend -l +100%FREE /dev/rhel/root 将所有剩余空间划给/dev/rhel/root

Rounding size to boundary between physical extents:
3.90 GiB. Size of logical volume rhel/root changed from 10.00 GiB (2560 extents) to 13.90 GiB (3559 extents). Logical volume rhel/root successfully resized.

3.5 刷新容量

紧接着刷新一下容量,因为分区类型为xfs,所以使用命令xfs_growfs刷新容量

如果分区类型为ext类型的,则用resize2fs命令进行刷新

[root@hsun ~]# xfs_growfs /dev/rhel/root 

meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2621440 to 3644416

此时可以看见root已经扩容完成,大小为14G

[root@hsun ~]# df -hT
文件系统              类型      容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root xfs        14G  6.7G  7.3G   49% /
devtmpfs              devtmpfs  1.9G     0  1.9G    0% /dev
tmpfs                 tmpfs     1.9G  4.0K  1.9G    1% /dev/shm
tmpfs                 tmpfs     1.9G  9.2M  1.9G    1% /run
tmpfs                 tmpfs     1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mapper/rhel-usr  xfs        35G   24G   12G   68% /usr
/dev/sda1             xfs      1014M  145M  870M   15% /boot
/dev/mapper/rhel-var  xfs       8.0G  5.5G  2.6G   69% /var
/dev/mapper/rhel-opt  xfs       4.0G  1.3G  2.8G   32% /opt
/dev/mapper/rhel-tmp  xfs       4.0G   34M  4.0G    1% /tmp
tmpfs                 tmpfs     378M     0  378M    0% /run/user/1002
tmpfs                 tmpfs     378M     0  378M    0% /run/user/20001116
tmpfs                 tmpfs     378M     0  378M    0% /run/user/0

逻辑卷扩容到此结束。

 

如果有什么不懂的地方或者意见,请私信我或者在评论区进行留言,看到之后第一时间回复。

本人linux新手,希望各位linux大佬多多指教。

 

posted on 2019-05-28 12:07  状元兜里有糖  阅读(476)  评论(0编辑  收藏  举报

导航