How to Extend Volume Group (VG) in Linux Using vgextend

In the realm of Linux system administration, the ability to manage storage effectively is a crucial skill. One of the most valuable tools at your disposal is the Logical Volume Manager (LVM) which allows you to manage disk space efficiently.

In this blog post, we will show you how to extend volume group (VG) size in Linux using vgextend step-by-step.

When to Extend Volume Group?

Sometimes, we may encounter situations where we need to increase the size of an LVM partition. However, if there is no available free space within the Volume Group, we must first extend the volume group itself. This can be achieved by adding new disks to the volume group using the vgextend command.

Scenario: Suppose We want to extend the size of /home, but there is no free in the volume group .

Use the df command to verify the space of /home partition and use vgdisplay or vgs command to view the available space in the volume group

[root@cloud ~]# df -h /home/
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/mapper/vg_cloud-LogVol00
                       16G   16G   41M 100% /home
[root@cloud ~]# vgdisplay vg_cloud
   --- Volume group ---
 VG Name                           vg_cloud
 System ID
 Format                            lvm2
 Metadata Areas                    1
 Metadata Sequence No              8
 VG Access                         read/write
 VG Status                         resizable
 MAX LV                            0
 Cur LV                            3
 Open LV                           3
 Max PV                            0
 Cur PV                            1
 Act PV                            1
 VG Size                           27.01 GiB
 PE Size                           4.00 MiB
 Total PE                          6915
 Alloc PE / Size                   6915 / 27.01 GiB
  Free  PE / Size                  0 / 0   
 VG UUID                           1R89GB-mIP2-7Hgu-zEVR-5H02-7GdB-Ufj7R4

Refer the below steps to extend the size of volume group (vg_cloud).

1) Prepare Physical Volumes

Let’s suppose a new disk is attached to our linux system. Check the new disk using ‘ fdisk -l ‘ command and create the physical volume

# pvcreate /dev/sdX

Replace /dev/sdX with the appropriate device name for each physical volume. In my case new disk is detected as ‘/dev/sdb’

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

2) Extend the Volume Group

Add the newly created physical volumes to the existing volume group using the following command:

# vgextend <existing_volume_group_name> /dev/sdX

Replace <existing_volume_group_name> with the name of the volume group you want to extend, and /dev/sdX with the device name of the new physical volume.

[root@cloud ~]# vgextend vg_cloud /dev/sdb
    Volume group "vg_cloud" successfully extended
[root@cloud ~]#

3) Verify the size of Volume Group

To ensure that the volume group has been extended successfully, run the following command to verify,

# vgdisplay <existing_volume_group_name>

This command will display information about the volume group, including the new total size, reflecting the extension.

[root@cloud ~]# vgdisplay vg_cloud
   --- Volume group ---
 VG Name                           vg_cloud
 System ID
 Format                            lvm2
 Metadata Areas                    2
 Metadata Sequence No              9
 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                           37.04 GiB
 PE Size                           4.00 MiB
 Total PE                          9481
 Alloc PE / Size                   6915 / 27.01 GiB
 Free  PE / Size                   2566 / 10.02 GiB
 VG UUID                           1R89GB-mIP2-7Hgu-zEVR-5H02-7GdB-Ufj7R4
[root@cloud ~]#

Output above confirms that we have Free PE (physical extend) / size of 10.02 GB

4) Expand Logical Volume using lvextend

After extending the volume group, you can proceed to expand the logical volumes within it. Use the lvextend command to increase the size of the logical volume.

# lvextend -L +100G /dev/<existing_volume_group_name>/<logical_volume_name>

Replace <existing_volume_group_name> with the name of the volume group and <logical_volume_name> with the name of the logical volume you want to expand. Adjust the size (+100G) according to your requirements.

[root@cloud ~]# lvextend -L +5G /dev/mapper/vg_cloud-LogVol00
     Extending logical volume LogVol00 to 21.25 GiB
 Logical volume LogVol00 successfully resized
[root@cloud ~]#

5) Resize the filesystem using resize2fs command

 [root@cloud ~]# resize2fs /dev/mapper/vg_cloud-LogVol00
 resize2fs 1.41.12 (17-May-2010)
 Filesystem at /dev/mapper/vg_cloud-LogVol00 is mounted on /home; on-line resizing required
 old desc_blocks = 2, new_desc_blocks = 2
 Performing an on-line resize of /dev/mapper/vg_cloud-LogVol00 to 5569536 (4k) blocks.
 The filesystem on /dev/mapper/vg_cloud-LogVol00 is now 5569536 blocks long.
[root@cloud ~]#

6) Validate the file system size

Now run df command to validate the file system size

[root@cloud ~]# df -h /home/
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/mapper/vg_cloud-LogVol00
                        21G   16G  4.8G  77% /home
[root@cloud ~]#

Great, output above shows that /home file system has been resized successfully.

Conclusion:

That’s all from post!, By following these steps, you should be able to successfully extend a volume group in Linux, expanding both the volume group and its logical volumes while resizing the filesystems to utilize the additional space. Remember to exercise caution and double-check your commands to avoid any unintended consequences.

1 thought on “How to Extend Volume Group (VG) in Linux Using vgextend”

Leave a Comment