Getting started with LVM

I recently had to extend a normal disk partition. It wasn't fun. That's why I recommend using LVM, it's a lot easier to manage, extend, shrink and remove partitions on a single or multiple disks.

Common Terms

Physical Volumes (PVs) are your physical disks attached to a server. These can be different sizes. That's why LVM is so flexible.

Volume Groups (VGs) are groups of PVs. For example you could have vg00 which includes PVs a, b and c.

Logical Volumes (LVs) are smaller “partitions” of VGs. You can mount these at different mount points and are easily manageable.


Your server configuration:

You can either split those into multiple VGs or combine them into one. I recommend combining them, because you can only assign a PV to single VG.

Currently your total allocatable storage for vg00 would be 4445GB. Now you can split that into one or more LVs and mount them to your system. I usually have different /, /var, /home and swap partitions.


Creating a PV

sudo pvcreate <disk>

Example <disk> values:

List PVs

sudo pvs

Creating a VG

sudo vgcreate <VG name> <PVs>


List VGs

sudo vgs

Creating a LV

sudo lvcreate -n <name> -L <size> <VG name>



You can choose any filesystem you want. I usually select ext4.

sudo mkfs.ext4 /dev/<VG name>/<LV name>


Final Steps

Now you can mount them and store files. Remember to add them to /etc/fstab in order to automatically have them mounted.

sudo mount /dev/<VG name>/<LV name> /mnt

List LVs

sudo lvs

Extend a LV

sudo lvextend -L +2G /dev/<VG name>/<LV name> -r

The -r flag automatically resizes the filesystem. If it's not provided, you need to manually run the resize2fs <volume> command.


Verify Changes

You can run df -h and it should show the new amount. If it still shows the old one, you can try running resize2fs /dev/<VG name>/<LV name> command.