Denny Lim
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:
sudo fdisk -l sudo lvmdiskscan sudo lsblk
sudo pvcreate /dev/<disk-name> # Example sudo pvcreate /dev/sdX
# Display volume groups sudo vgdisplay # Show free and used space sudo vgs
sudo vgcreate <volume-group-name> <physical-volume-1> [<physical-volume-2> ...] # Example sudo vgcreate my_volume_group /dev/sdX /dev/sdY
sudo vgextend <volume-group-name> <new-physical-volume> # Example sudo vgextend my_volume_group /dev/sdZ
sudo vgreduce <volume-group-name> <physical-volume-to-remove> # Example sudo vgreduce my_volume_group /dev/sdZ
sudo vgremove <volume-group-name> # Example sudo vgremove my_volume_group
A logical volume is a flexible "partition" created from a volume group. These are typically mounted to paths like /mnt
.
# Display logical volumes sudo lvdisplay # Show free and used space sudo lvs
sudo lvcreate --name <lv-name> --size 5G <volume-group-name> # Example sudo lvcreate --name docker-lv --size 5G ubuntu-vg
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
sudo mkfs -t ext4 /dev/<volume-group-name>/<logical-volume-name> # Example sudo mkfs -t ext4 /dev/ubuntu-vg/docker-lv
# 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
defaults 0 2
:defaults
: Standard mount options (rw,suid,dev,exec,auto,nouser,async
)0
: Do not check this filesystem on boot2
: If checked, do so after the root filesystem (which has 1
)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.