Linux LVM: Resizing and Extending for Amazon EC2

One of the things I need to do with some regularity is to resize and extend disk volumes on Amazon EC2. Since I don't deal with LVM on a daily basis I also tend to forget the steps to do it, and for whatever reason Googling around tends to produce incomplete instructions. So here is my general process for this - your mileage may vary. I assume XFS here, if you use ext2/3/4 you would use resizefs at the end instead of xfs_growfs. Without further ado, here goes:

1) Take a snapshot of the EBS volume to extend.

2) Once the snapshot completes, create a new volume from the snapshot with the full size you want to extend it to. For example, your original snapshot and volume is 50GB, you may want the new volume to be 100GB.

3) Unmount the old volume from the instance.

4) Attach the new volume to the instance.

5) vgdisplay (look for the VG name - in my example it's vol_grp1)

6) vgchange -an vol_grp1 (to disable the volume group)

7) pvdisplay (look for the PV name - in this example it's /dev/xvdl)

8) pvchange -u /dev/xvdf (to change the UUID)

9) pvresize /dev/xvdf

10) pvdisplay (should show new larger size)

11) vgdisplay (should now show the volume group reflecting the new 100GB size)

12) lvdisplay (look for the LV name - in this example it's /dev/vol_grp1/lvol0)

13) lvextend -l +100%FREE /dev/vol_grp1/lvol0

14) vgchange -u vol_grp1 (to change the UUID)

15) vgchange -ay (to activate the volume group)

16) mount /dev/vol_grp1/lvol0 /mnt/foo (mount the filesystem to a mount point, in this example /mnt/foo)

17) xfs_growfs /mnt/foo

18) xfs_admin -U generate /dev/vol_grp1/lvol0

19) umount /mnt/foo

20) lvrename /dev/vol_grp1/lvol0 /dev/vol_grp1/logvol0

21) vgrename /dev/vol_grp1 /dev/vol_grp2

...and boom goes the dynamite. The partition has now been expanded to the full size of the new volume. You may also need to vgrename and lvrename depending on whether or not the original volume is still in use.

Add new comment