Managing Ubuntu Logical Volumes


Denny Lim

Denny Lim

·June 24, 2025·
LinuxSystem AdministrationUbuntu 24.04

Ubuntu uses Logical Volume Manager (LVM) to provide flexible disk management. This guide walks through the steps to create, manage, and utilise logical volumes, helping system administrators make the most of available disk space.

Prerequisites:

  • Shell access with superuser rights (sudo)

Understanding PV, VG, and LV

  • Physical Volumes (PVs):
    Physical disks or disk partitions initialized for use with LVM.
    In cloud environments, when you attach a new unformatted disk to an instance, it appears as a potential physical volume.
  • Volume Groups (VGs):
    A pool of storage created by combining one or more physical volumes.
  • Logical Volumes (LVs):
    Flexible partitions created from volume groups. LVs are easier to resize and manage than traditional partitions.

Physical Volumes (PVs)

Commands

sudo fdisk -l sudo lvmdiskscan sudo lsblk

Create a Physical Volume

sudo pvcreate /dev/<disk-name> # Example sudo pvcreate /dev/sdX

Volume Groups (VGs)

Commands

# Display volume groups sudo vgdisplay # Show free and used space sudo vgs

Create a Volume Group

sudo vgcreate <volume-group-name> <physical-volume-1> [<physical-volume-2> ...] # Example sudo vgcreate my_volume_group /dev/sdX /dev/sdY

Add a Physical Volume to an Existing Volume Group

sudo vgextend <volume-group-name> <new-physical-volume> # Example sudo vgextend my_volume_group /dev/sdZ

Remove a Physical Volume from a Volume Group

sudo vgreduce <volume-group-name> <physical-volume-to-remove> # Example sudo vgreduce my_volume_group /dev/sdZ

Remove a Volume Group

sudo vgremove <volume-group-name> # Example sudo vgremove my_volume_group

Logical Volumes (LVs)

A logical volume is a flexible "partition" created from a volume group. These are typically mounted to paths like /mnt.

Commands

# Display logical volumes sudo lvdisplay # Show free and used space sudo lvs

Create a Logical Volume

sudo lvcreate --name <lv-name> --size 5G <volume-group-name> # Example sudo lvcreate --name docker-lv --size 5G ubuntu-vg

Resize a Logical Volume

sudo lvextend --resizefs --size +5G <volume-group-name>/<logical-volume-name> # Example resize logical volume docker-lv under group ubuntu-vg with additional 5G disk space sudo lvextend --resizefs --size +5G ubuntu-vg/docker-lv

If the volume is mounted, it will be resized online. If not, resize it manually:

sudo resize2fs /dev/mapper/ubuntu--vg-docker--lv

Format the Logical Volume

sudo mkfs -t ext4 /dev/<volume-group-name>/<logical-volume-name> # Example sudo mkfs -t ext4 /dev/ubuntu-vg/docker-lv

Mount Logical Volume to /mnt

# Prepare mount point sudo mkdir -p /mnt/docker # Mount the volume sudo mount /dev/ubuntu-vg/docker-lv /mnt/docker # Make mount persistent sudo blkid

Sample output:

/dev/mapper/ubuntu--vg-docker--lv: UUID="a582dfd6-bbd3-4c60-9853-9d74427b9f26" BLOCK_SIZE="4096" TYPE="ext4"

Add the following line to /etc/fstab:

UUID=a582dfd6-bbd3-4c60-9853-9d74427b9f26 /mnt/docker ext4 defaults 0 2

Breakdown of defaults 0 2:

  • defaults: Standard mount options (rw,suid,dev,exec,auto,nouser,async)
  • 0: Do not check this filesystem on boot
  • 2: If checked, do so after the root filesystem (which has 1)

Example Use Case

You have two disks: /dev/sda and /dev/sdb. You want to pool and use them via LVM:

# Step 1: Initialize disks sudo pvcreate /dev/sda /dev/sdb # Step 2: Create volume group sudo vgcreate my_vg /dev/sda /dev/sdb # Step 3: Create logical volume sudo lvcreate -L 100G -n my_lv my_vg # Step 4: Format and mount sudo mkfs.ext4 /dev/my_vg/my_lv sudo mkdir -p /mnt/my_data sudo mount /dev/my_vg/my_lv /mnt/my_data # Step 5: Make persistent sudo blkid # Sample output /dev/my_vg/my_lv: UUID="f2211d0f-d894-47a7-8125-38ab6495c18f" BLOCK_SIZE="4096" TYPE="ext4" # Add to /etc/fstab echo "UUID=f2211d0f-d894-47a7-8125-38ab6495c18f /mnt/my_data ext4 defaults 0 2" | sudo tee -a /etc/fstab

This makes storage management on Ubuntu highly flexible, scalable, and cloud-friendly.