Computing: Computer Administration

Using LVM disk storage layout on Ubuntu Server.


Beside the classic disk storage layout using partitions, Linux operating systems include the possibility to use the logical volume manager (LVM), that allows to create logical volumes out of one or multiple physical fixed disks. LVM volumes can be created on both software RAID partitions and standard partitions. Such volumes can be extended, giving greater flexibility to systems as requirements change. This tutorial shows, how to choose LVM disk storage layout at installation time of Ubuntu Server 20.04 LTS and how to add a second fixed disk to the LVM system, later.

When installing Ubuntu Server, you can choose to use LVM by selecting the Set up this disk as an LVM group checkbox of the Use an entire disk option on the Guided storage configuration page.

Ubuntu Server installation: Setting up a disk as an LVM group [1]

In an LVM context:

Ubuntu Server installation: Setting up a disk as an LVM group [2]

There are some useful utilities to view information about LVM: pvdisplay shows information about physical volumes; vgdisplay shows information about volume groups and lvdisplay shows information about logical volumes. On the screenshots below (taken after the installation of Ubuntu Server was completed), we can see

Ubuntu server LVM utilities: Display of PV and VG information
Ubuntu server LVM utilities: Display of LV information

Extending an LVM group.

My Ubuntu Server VMware virtual machine actually has 2 fixed disks and the following part of the tutorial shows how to do to add the second disk to the volume group ubuntu-vg in order to get a logical disk made of two areas: the third partition of the first disk (/dev/sda3) and the whole second disk (/dev/sdb). This operation is done in 4 steps:

  1. Create a physical volume.
  2. Extend the volume group (add the physical volume to the volume group).
  3. Extend the logical volume.
  4. Extend the logical volume's filesystem.

The creation of the physical volume is done by the command
    sudo pvcreate /dev/sdb
You should be careful when doing this with /dev/sdb containing data; it could result in data loss!

The extension of the volume group ubuntu-vg, adding the newly created volume, is done by the command
    sudo vgextend ubuntu-vg /dev/sdb

The following screenshot shows the volume group information after the volume group extension has been done. You can see that the VG now has two areas: 4735 allocated physical extends (corresponding to the 18.50 GB /dev/sda3) and 5119 free physical extends (corresponding to the 20.00 GB /dev/sdb). This is similar to a disk with an 18.50 GB partition and 20 GB of free (unallocated) space.

Ubuntu server LVM volume group extension: VG with one allocated and one free area

A logical volume is similar to a partition in a non-LVM system, we said. Thus, after having extended the volume group, we'll have to extend the logical volume ubuntu-lv:
    sudo lvextend /dev/ubuntu-vg/ubuntu-lv −l +5119

When using the lvextend command, we have to specify, beside the name of the logical volume, the size by which the LV has to be extended. This is done here by using the -l option, that needs a physical extend (PE) value as argument (another possibility is to use the -L option, that needs a size value in MB, GB...) The PE value used here (5119) corresponds to the size of the entire free PE available (what actually corresponds to the entire disk /dev/sdb).

The following screenshots show the LVM information after the logical volume extension has been done: (1) the two physical volumes /dev/sda3 and /dev/sdb; (2) the volume group ubuntu-vg, that is made of two areas, that now, from a logical point of view, form one big area of 4735 + 5119 = 9854 PE, or 18.50 + 20.00 = 38.50 GB (in fact 38.49 GB because of some not usable MB); (3) the logical volume ubuntu-lv, that may be seen as a partition of 9854 extends (38.49 GB).

Ubuntu server LVM volume group extension: LVM with two physical volumes
Ubuntu server LVM volume group extension: VG with two areas forming one big extend
Ubuntu server LVM volume group extension: LV with one big 'partition' corresponding to 2 two different PV

So far done, the space added to the logical volume isn't usable because it hasn't yet been formatted. This may be done by extending the EXT4 filesystem using the command:
    sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

Note, that there is a certain risk when doing this without unmounting the logical volume. However, with the EXT4 filesystem, it normally succeeds without any problems.

To terminate the tutorial, here a screenshot of how all this looks in the display of the partitioning tool fdisk. The screenshot shows, among others, the two (physical) fixed disks /dev/sda and /dev/sdb, the first one being subdivided into 3 partitions, as well as the 38.50 GB logical LVM volume.

Ubuntu server LVM disk storage layout viewed in fdisk

If you find this text helpful, please, support me and this website by signing my guestbook.