How do I extend an EBS volume with LVM partitions?

6 minute read
0

I want to extend my Amazon Elastic Block Store (Amazon EBS) volume that has LVM partitions.

Short description

There are two options for extending logical volumes:

  1. Increase the size of the existing EBS volume.
  2. Add additional EBS volumes to your volume group and extend the VG-LV.

Resolution

Option 1: Increase the size of the existing EBS volume

Note: Size changes to existing volumes usually take effect within seconds after the volume enters the optimizing state. The volume's performance is affected while in the optimizing state, but doesn't fall below the source configuration specification. Depending on your volume type, changes might take from a few minutes to a few hours. For more information, see Monitor the progress of volume modifications.

1.    Modify the size of the existing EBS volume.

2.    Run the following command to install the growpart utility:

$ sudo yum install cloud-utils-growpart

Note: Run the following command to install the growpart utility on Debian or Ubuntu-based systems:

$ sudo apt install -y cloud-guest-utils

3.    Run the growpart command to extend the partition.

$ sudo growpart /dev/xvdh 1
 CHANGED: disk=/dev/xvdh partition=1: start=2048 old: size=20971519,end=16777182 new: size=41940958,end=41943006

4.    Run the pvresize command to resize the PV. In the following example, partition /dev/xvdh1 is extended:

$ sudo pvresize /dev/xvdh1
Physical volume "/dev/xvdh1" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

Use the pvs or pvdisplay to view the physical volume details:

$ sudo pvs
PV         VG            Fmt  Attr PSize   PFree
 /dev/xvdh1 examplegroup1 lvm2 a--  <20.00g <13.00g

Use the vgs or vgdisplay to view the volume group details:

$ sudo vgs
 VG            #PV #LV #SN Attr   VSize   VFree
examplegroup1   1   1   0 wz--n- <20.00g <13.00g

5.    Run the lvextend command to extend the logical volume:

$ sudo lvextend -L 19G /dev/examplegroup1/lvexample1

Note: In the preceding example, 19G is the new, increased size of the LV. 19G isn't the size by which the LV has to be increased.

Use the lvs or lvdisplay command to view the logical volume details:

$ sudo lvs  LV        VG            Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
lvexample1 examplegroup1 -wi-a----- 19.00g

6.    Run the following command to extend the file system:

Ext2, Ext3, and Ext4 file systems:

$ sudo resize2fs /dev/examplegroup1/lvexample1

XFS file systems:

$ sudo xfs_growfs /dev/examplegroup1/lvexample1

Option 2: Add additional EBS volumes to your volume group and extend the VG-LV

1.    Create another EBS volume of 10 GB, and then attach the volume to the instance. Create a partition on the device /dev/xvdi following step 3 of Create physical volumes on the partition of your EBS volume. Then, run the pvcreate command. In the following example, the volume's block device name is /dev/xvdi1.

$ sudo pvcreate /dev/xvdi1
Physical volume "/dev/xvdi1" successfully created

2.    Use the vgextend command to extend the volume group and add the new volume. The following example extends the volume group examplegroup1 to include the volume /dev/xvdi1:

$ sudo vgextend examplegroup1 /dev/xvdi1
Volume group "examplegroup2" successfully extended

To confirm the extension, run the vgs or vgdisplay command. The following example shows that there are now two PVs in the examplegroup1 volume group:

$ sudo vgs
  VG                       #PV #LV #SN Attr   VSize   VFree
examplegroup1            2   1   0 wz--n-  29.99g   20.99g

3.    Run the lvextend command to extend the logical volume:

$ sudo lvextend -L 29G /dev/examplegroup1/lvexample1

Note: In the preceding example, 29G is the new increased size of the LV. 29G isn't the size by which the LV has to be increased.

4.    Resize the file system:

Ext2, Ext3, and Ext4 file systems:

$ sudo resize2fs /dev/examplegroup1/lvexample1

XFS file systems:

$ sudo xfs_growfs /dev/examplegroup1/lvexample1

Extend a striped volume

Striping is a technique to spread data across multiple disks. You might receive a message similar to the following when extending a logical volume:

$ pvcreate /dev/xvdd
Physical volume "/dev/xvdd" successfully created.

$ vgextend vg01 /dev/xvdd
Volume group "vg01" successfully extended

$ vgs
VG   #PV #LV #SN Attr   VSize   VFree
vg01   3   1   0 wz--n- <23.99g <13.99g

$ lvextend /dev/vg01/lv01 -L +10G
Using stripesize of last segment 128.00 KiB
Insufficient suitable allocatable extents for logical volume lv01: 1026 more required

The preceding error or similar errors occur when extending a "striped" logical volume without adding sufficient number of devices to stripe the data.

To avoid these errors when extending a striped volume, complete the following steps:

1.    Run the following command to identify the number of devices that the LV stripes the data across.

$ lvs -o+lv_layout,stripes
LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Layout     #Str
lv01 vg01 -wi-a----- 10.00g                                                     striped       2

2.    The #Str, or stripes, column represents the number of devices the data is being striped across. In the preceding example, the data is striped across 2 devices. So, you require at least 2 devices (or devices in multiples of 2) added to the vg to extend the LV. Since you added one device (in the preceding steps), you add the second device and attempt to extend again:

$ pvcreate /dev/xvde
Physical volume "/dev/xvde" successfully created.

$ vgextend vg01 /dev/xvde
Volume group "vg01" successfully extended

$ vgs
VG   #PV #LV #SN Attr   VSize  VFree
  vg01   4   1   0 wz--n- 31.98g 21.98g

$ lvextend /dev/vg01/lv01 -L +10G
Using stripesize of last segment 128.00 KiB
Size of logical volume vg01/lv01 changed from 10.00 GiB (2560 extents) to 20.00 GiB (5120 extents).
Logical volume vg01/lv01 successfully resized.

$ lvs -o+lv_layout,stripes
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Layout     #Str
lv01 vg01 -wi-a----- 20.00g                                                     striped       2
lv01 vg01 -wi-a----- 20.00g                                                     striped       2

The preceding example output shows that the lvextend command completed successfully when the second device was added.

3.    Run the following command to resize the file system:

Ext2, Ext3, and Ext4 file systems:

$ sudo resize2fs /dev/vg01/lv01

XFS file systems:

$ sudo xfs_growfs /dev/vg01/lv01
AWS OFFICIAL
AWS OFFICIALUpdated 10 months ago