CentOS partition VG, PV, LV

Keywords: CentOS

CentOS expansion volume group

pv, vg, lv

Physical volume (PV): refers to the hard disk partition, or the entire hard disk or the created soft RAID. It is the basic storage device of LVM.

Volume group (VG): a storage pool composed of one or more physical volumes. One or more logical volumes can be created on the volume group.

Logical volume (LV): similar to the hard disk partition in non LVM system, it is built on the volume group and is a standard block device. A file system can be built on the logical volume.

1. First, check the size of our root partition

[root@localhost ~]# df -hT
 file system                type      Capacity used available used% Mount point
/dev/mapper/centos-root xfs        18G  1.1G   17G    6% /
devtmpfs                devtmpfs  479M     0  479M    0% /dev
tmpfs                   tmpfs     489M     0  489M    0% /dev/shm
tmpfs                   tmpfs     489M  6.7M  483M    2% /run
tmpfs                   tmpfs     489M     0  489M    0% /sys/fs/cgroup
/dev/sda1               xfs       497M  125M  373M   25% /boot
tmpfs                   tmpfs      98M     0   98M    0% /run/user/0<br>

You can see that our root partition size is 17G

2. Add a physical disk. Add in virtual machine

3. Check the disk number

ls /dev/sd*<br>/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb

You can see that sdb is the disk we just added
4. Create pv

[root@localhost ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created

5. Adding pv to vg is equivalent to expanding the size of vg

Use vgs to view the vg group first

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   2   0 wz--n- 19.51g 40.00m

You can see that there is a vg group with two lv volumes. If you are not sure, you can check whether it is the partition we need to expand through lvs

[root@localhost ~]# lvs
LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.47g                                                  swap centos -wi-ao----  2.00g  

You can see that this is the root partition we need to expand. I also have a swap partition here
To extend vg, use the vgextend command

[root@localhost ~]# vgextend centos /dev/sdb
  Volume group "centos" successfully extended

The vgextend name command is followed by the name of vg, followed by the location of the disk
6. We have successfully expanded the vg volume. Let's check it with vgs

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   2   2   0 wz--n- 39.50g 20.04g
[root@localhost ~]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 17.47g                                                   
  swap centos -wi-ao----  2.00g  

Although we have extended vg, lv has not been extended yet
7. Extend lv and use the lvextend command

[root@localhost ~]# lvextend -L +20G /dev/mapper/centos-root
  Size of logical volume centos/root changed from 17.47 GiB (4472 extents) to 37.47 GiB (9592 extents).
  Logical volume root successfully resized.-

Specify how much space to expand to lv. The following / dev / mapper / CentOS root is the file location of the specified extension, which can be seen in df -h
View lv size

[root@localhost ~]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 37.47g                                                
  swap centos -wi-ao----  2.00g  

Check if there is any change in DF - H

[root@localhost ~]# df -h
 file system                 Capacity used available used% Mount point
/dev/mapper/centos-root   18G  1.1G   17G    6% /
devtmpfs                 479M     0  479M    0% /dev
tmpfs                    489M     0  489M    0% /dev/shm
tmpfs                    489M  6.7M  483M    2% /run
tmpfs                    489M     0  489M    0% /sys/fs/cgroup
/dev/sda1                497M  125M  373M   25% /boot
tmpfs                     98M     0   98M    0% /run/user/0

No change.
So we're going to use[ root@localhost ~]# xfs_ The growfs / dev / mapper / CentOS root command causes the system to reread the size

[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=1144832 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=4579328, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 4579328 to 9822208

Then use DF - h to view

[root@localhost ~]# df -h
 file system                 Capacity used available used% Mount point
/dev/mapper/centos-root   38G  1.1G   37G    3% /
devtmpfs                 479M     0  479M    0% /dev
tmpfs                    489M     0  489M    0% /dev/shm
tmpfs                    489M  6.7M  483M    2% /run
tmpfs                    489M     0  489M    0% /sys/fs/cgroup
/dev/sda1                497M  125M  373M   25% /boot
tmpfs                     98M     0   98M    0% /run/user/0

Here we have successfully expanded.

Note: we can produce our own vg group and generate lv in the new vg

vgcreate creates a new vg group

lvcreate creates a new lv in a new vg, but specifies the name of the vg

vg result removes pv from vg. If there is only one pv in vg, vg move is used directly

Posted by tested_123 on Fri, 03 Dec 2021 22:24:53 -0800