Programster's Blog

Tutorials focusing on Linux, programming, and open-source

LVM Cheatsheet

As with all my cheatsheets, they are works in progress and will be continuously added to whenever I find a command that I need that it does not list. If there is something that you are looking for that is not listed, please visit the references. If you find a good reference that is not listed, please add it to the comments and I will merge it in.

Listing Items

  • sudo pvdisplay - List physical devices.
  • sudo vgdisplay - List volume groups.
  • sudo lvdisplay - List logical volumes.

Extend Logical Volume By Amount

sudo lvextend -L+[Number of GB to add]G -n /dev/[volume group name]/[logicial volume name]  

Extend Logical Volume By Percentage Free

sudo lvextend -l 100%FREE /dev/$VG_NAME/$LV_NAME

Extend Logical Volume To Specified Size

sudo lvextend -L [New Size In GB]G -n /dev/[volume group name]/[logicial volume name]  

Resize Filesystem

If you extend your LVM then you need to resize the filesystem in order to utilize it.

resize2fs /dev/[volume group name]/[logical volume name]  

Create Logical Volume

Create an LVM by adding it to a Volume Group that already exists.

lvcreate -L [Size in GB]G [Volume Group Name]  

... or to just use the entire space:

lvcreate -l 100%FREE [Volume Group Name]  

Create Filesystem on New LVM

This creates an ext4 filesystem on the newly created LVM

sudo mkfs -t ext4 /dev/[volume group]/[Logical volume name]  

Create Physical Volume

Create a physical volume on a drive. This is required before you can add it to a volume group or create a volume group from it.

pvcreate /dev/sd[x]  

Create Volume Group

Volume groups are collections of physical volumes. To create one, you need to specify which volumes it should group/manage.

vgcreate [new volume group name] /dev/sd[x] /dev/sd[x] ...  

Note: The ... signifies that you can specify any number of physical volumes. The [x] signifies different drive letters such as a or a1.

Add Physical Volume To Volume Group

vgextend [volume group name] /dev/sd[x]  

Extend Volume Group

See "Add Physical Volume To Volume Group"

Destroy Volume Group

vgremove [volume group name]  


Last updated: 23rd December 2018
First published: 16th August 2018