Add/Remove PV on VG on the Fly

Describes what is a VG (Volume Group) - a virtual storage device made up by one or more PVs (Physical Volumes). Tutorial examples are given on how to create a new VG, add PV to a VG and remove a PV from a VG.

What Is VG (Volume Group)? VG represents a virtual storage device made up by one or more PVs (Physical Volumes). Once created, a VG can be divided into one or more LVs (Logical Volumes) to hold different file systems.

There are a number commands provided on CentOS 8 systems for you to create and manage PVs.

1. List all VGs that are currently managed by LVM using the "pvs" command, which is a also sub-command of the "lvm" command. The output shows that I have 1 VG named as "cl" supported by 2 PVs and holding 3 LVs with 831.69g free space.

herong$ sudo vgs
  VG #PV #LV #SN Attr   VSize VFree
  cl   2   3   0 wz--n- 1.00t 831.69g

2. Display details of each VG using the "vgdisplay" command, which is also a sub-command of the "lvm" command. The output shows the VG's format is "lvm2".

herong$ sudo vgdisplay

  --- Volume group ---
  VG Name               cl
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               1.00 TiB
  PE Size               4.00 MiB
  Total PE              263256
  Alloc PE / Size       50343 / 196.65 GiB
  Free  PE / Size       212913 / 831.69 GiB
  VG UUID               C48qEx-RPFb-Xf5D-exff-0aVo-...

3. Display PVs and LVs that are related to the "cl" VG.

herong$ sudo pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sda7  cl lvm2 a--   96.65g      0
  /dev/sdb2  cl lvm2 a--  931.69g 831.69g
  /dev/sdb3     lvm2 ---   93.13g  93.13g

herong$ sudo lvs
  LV   VG Attr       LSize   Pool Origin Data%  Meta%  ...
  home cl -wi-ao---- 138.94g
  root cl -wi-ao----  50.00g
  swap cl -wi-ao----   7.71g

How To Add PV to a VG? If an existing VG is running out of space, you can follow steps below to add a new PV to the VG.

1. Check available PVs using "pvs" command. I see /dev/sdb3 is a new PV with 93.13g of space.

herong$ sudo pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sda7  cl lvm2 a--   96.65g      0
  /dev/sdb2  cl lvm2 a--  931.69g 831.69g
  /dev/sdb3     lvm2 ---   93.13g  93.13g

2. Check existing VGs using "vgs" command. I see "cl" is an existing VG with 2 PVs and 1.00t of space.

herong$ sudo vgs
  VG #PV #LV #SN Attr   VSize VFree
  cl   2   3   0 wz--n- 1.00t 831.69g

3. Add /dev/sdb3 to "cl" using "vgextend" command. The output shows "cl" is extended to 1.10t of space.

herong$ sudo vgextend cl /dev/sdb3
 Volume group "cl" successfully extended

herong$ sudo vgs
   VG #PV #LV #SN Attr   VSize  VFree
   cl   3   3   0 wz--n- 1.10t 924.82g

How To Remove PV from a VG? If a PV in a VG is not used at all, you can remove it from the VG.

1. Check to see if the PV is used or not. I see /dev/sdb3 with entire space marked as free. So it is not used.

herong$ sudo pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sda7  cl lvm2 a--   96.65g      0
  /dev/sdb2  cl lvm2 a--  931.69g 831.69g
  /dev/sdb3  cl lvm2 a--   93.13g  93.13g

2. Remove /dev/sdb3 from "cl" using the "vgreduce" command.

herong$ sudo vgreduce cl /dev/sdb3
  Removed "/dev/sdb3" from volume group "cl"

herong$ sudo pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sda7  cl lvm2 a--   96.65g      0
  /dev/sdb2  cl lvm2 a--  931.69g 831.69g
  /dev/sdb3     lvm2 ---   93.13g  93.13g

As you can see, managing PVs in a VG is easy. You can add a PV to a VG and remove it at any time, while the VG is still in use.

How To Create a New VG VG? If don't want to use the existing VG, you can create a new one.

1. Make sure that there is free PV available to used as the first PV for the new VG.

herong$ sudo pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sda7  cl lvm2 a--   96.65g      0
  /dev/sdb2  cl lvm2 a--  931.69g 831.69g
  /dev/sdb3     lvm2 ---   93.13g  93.13g

2. Create a new VG with a free PV using "vgcreate" command.

herong$ sudo vgcreate data /dev/sdb3
  Volume group "data" successfully created

herong$ sudo pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda7  cl   lvm2 a--   96.65g      0
  /dev/sdb2  cl   lvm2 a--  931.69g 831.69g
  /dev/sdb3  data lvm2 a--   93.13g  93.13g

herong$ sudo vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  cl     2   3   0 wz--n-   1.00t 831.69g
  data   1   0   0 wz--n-  93.13g  93.13g

See next tutorials on what is LV (Logical Volume) and how to create LVs.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

 Process Management

 Memory Management

 Files and Directories

 Users and Groups

 File Systems

 Block Devices and Partitions

LVM (Logical Volume Manager)

 What Is LVM (Logical Volume Manager)

 Create New PV (Physical Volume)

Add/Remove PV on VG on the Fly

 Create LV on VG on the Fly

 Extend /home LV with a New Partition

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Internet Networking Tools

 SSH Protocol and ssh/scp Commands

 Software Package Manager on CentOS - DNF and YUM

 vsftpd - Very Secure FTP Daemon

 LDAP (Lightweight Directory Access Protocol)

 Administrative Tasks

 References

 Full Version in PDF/EPUB