Logical Volume Manager vs Partitions

LVM = Logical Volume Management

Why would you use LVM over partitions with gparted?

LVM does this better, and has additional functionality on top of partitions and gparted.

LVM has these key terms:

Physical Volumes – This is your hardware, i.e. your hard disk.

Volume Groups – This is a collection of physical and logical volumes.

Logical Volumes – These are the partitions that hold the file systems. Unlike partitions, these get names rather than numbers. They can span across multiple disks and don’t have to be physically next to one another.

One big advantage of logical volumes is that any operations that are carried out on them can be done on the fly and while the volume is in use. The same cannot be said about partitions and gparted, as usually they will require that the partitions aren’t in use. Gparted also only allows 4 primary partitions, and all logical partitions must be contained within one contiguous (along side one another) extended partition.

Resizing of partitions with gparted, you can only do it when the disk isn’t in operation, as well as the fact that you can only extend the free space to what’s left on the disk. Whereas with LVM, you can use the hard disk space on any of the physical volumes that are within the volume group, as well as being able to resize on the fly provided that the file system within the logical volume allows for it, i.e. ext4.

There are no partition limitations with LVM unlike partitions which are left with 4. If you want to allocate more space, you easily can with LVM through the use of one command.

Snapshots are a feature that are exclusive to LVM, this will allow you to take an image in time of the state of your filesystem. This will also let you mount this image back in and change the image without affecting the original system in use.

The above code will create a physical volume on one of your partitions, then it will create a volume group called testing which will include the physical volume you just created. Then you will create a new logical volume named ‘partition’ and it will have a size of 0.5 g which will come from the volume group’s allocated space.

As of right now, you only have one phyiscal disk, however, if you would like to add more physical disks to the volume group so that you can share more of the memory out, you can do so with the following commands:

That should be it.

So, if in your /dev/nvme1n1 partition, if the total amount of free space was 2GB, and you allocated 0.5G, therefore you have 1.5G left. However, now that we have two physical disks in the same volume group, if we create a new logical volume (partition):

Now, we just specified that the partition should have a size of 2G, however, we only have 1.5 left on /dev/nvme1n1 however, seeing that we have the second disk added, it can allocate it’s space (2GB) to help create the partition, this would mean that after all, if we run sudo pvscan, it would show that /dev/nvme1n1 should have 0G disk space left and /dev/nvme1n2 should have 1.5G left.

if you have more than one physical volume in your setup, you can move a logical volume from one of the physical volumes to another one of the physical volumes. For instance, if you have the phyiscal volumes:

/dev/nvme1n1 and /dev/nvme1n2

on /dev/nvme1n1 you have a logcal volume called ‘partition’ and it has 1GB space, and /dev/nvme1n2 has 1.5GB free, so you want to move it over to this physical volume, they you can do the following command:

Something to mention is that you specify the physical volume that you’re taking the logical volume off of.

If you want to create a snapshot of a logical volume, you can do so as follows:

This will create an image and it will not have any size. Since the snapshot volume only stores the areas of the disk that have changed since it was created, it can be musch smaller than the original volume.

you can also mount the snapshot and modify it without affecting the original.

If you want to revert back to the original snapshot, you can do so with the following:

Thanks for reading!



Learning, and posting my findings!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store