Extend LVM by adding new disk

Submitted on Thu, 06/10/2021 - 22:09

Tags

Steps:

1. Locate new physical disk.

2. Create new LVM physical volume in the newly added disk.

3.  Extend the existing volume group by adding the new LVM physical volume.

4.  Extend the concerned logical volume.

5. Resize the filesystem of the logical volume.

1. Locate new physical disk

After adding new disk, reboot the system and run following command:

fdisk -l

Output:

Disk /dev/sdb: .....  

The new physical disk is available at /dev/sdb

The new disk can also be found with following command:

lvmdiskscan

2. Create new LVM physical volume in the newly added disk

pvcreate /dev/sdb

Confirm this with following commands:

  • pvs
  • pvdisplay
  • lvmdiskscan -l

3.  Extend the existing volume group by adding the new LVM physical volume

vgextend <volume-group-name> /dev/sdb

 

Example:

vgextend ubuntu-vg /dev/sdb

Note: Find out the name of the existing volume group with following command vgs or vgdisplay

4.  Extend the logical volume as required

lvextend -l +100%FREE /dev/<volume group name>/<logical volume name>

example: 

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv 

5. Resize the filesystem of the logical volume

For ext file system:

resize2fs -p <file system>


 

Example:

resize2fs -p /dev/mapper/ubuntu--vg-ubuntu--lv

For xfs file system

xfs_growfs <file system>

The filesystem details can be found from df -h

In this case, the partition was /dev/mapper/ubuntu--vg-ubuntu--lv