How to Set Up and Manage LVM (logical Volume Manager) on Ubuntu Server for Flexible Disk Partitioning

Learning how to set up and manage LVM (Logical Volume Manager) on Ubuntu Server for flexible disk partitioning is one of the most valuable skills a Linux administrator can have. Traditional disk partitioning is rigid. Once you set a partition size, changing it later is painful and risky. LVM changes that completely. It lets you resize volumes on the fly, add new disks without downtime, and create snapshots for backups. In this tutorial, you’ll learn how to install LVM, create physical volumes, volume groups, and logical volumes, and then resize them as your storage needs grow. By the end, you’ll have a fully working LVM setup ready for production use.

Prerequisites for Setting Up LVM on Ubuntu Server

Before you start, make sure you have the following in place.

System requirements:

  • Ubuntu Server 20.04 or 22.04 (this guide works on both)
  • Root or sudo access to the server
  • At least one unformatted disk or partition available (e.g., /dev/sdb)
  • Basic familiarity with the Linux terminal
  • SSH access if working on a remote server

Estimated time: 30–45 minutes

You should know basic Linux commands like ls, cd, and sudo. You don’t need prior LVM experience. This guide starts from scratch.

Check your available disks before proceeding. Run this command to list all block devices:

lsblk

Look for a disk with no mount point. That’s your target disk for LVM. In this tutorial, we’ll use /dev/sdb as the example. Replace it with your actual disk name throughout.

For background reading on storage concepts, the Ubuntu Server storage documentation is a great starting point.

Step-by-Step Guide to Configure LVM for Flexible Disk Partitioning

For a related walkthrough, see: Setup Pivpn Server on Ubuntu and Connect on Windows

Follow these steps carefully. Each one builds on the last.

Step 1: Install LVM2

Ubuntu Server sometimes includes LVM2 by default. Install it to be sure.

sudo apt update
sudo apt install lvm2 -y

Verify the installation worked:

sudo lvmdiskscan

This command scans for all available storage devices. You’ll see your disks listed.

Step 2: Create a Physical Volume (PV)

A physical volume is the foundation of LVM. You initialize a raw disk or partition as a PV.

sudo pvcreate /dev/sdb

Confirm it was created:

sudo pvdisplay

You’ll see details about the physical volume, including its size and UUID.

Step 3: Create a Volume Group (VG)

A volume group pools one or more physical volumes together. Think of it as a big storage container.

sudo vgcreate my_volume_group /dev/sdb

Replace my_volume_group with any name you prefer. Check the result:

sudo vgdisplay

You’ll see the total available space in the volume group.

Step 4: Create a Logical Volume (LV)

A logical volume is what you actually format and mount. Create one using part of the volume group’s space.

sudo lvcreate -L 10G -n my_logical_volume my_volume_group

This creates a 10GB logical volume named my_logical_volume. Adjust the size to match your needs. Verify it:

sudo lvdisplay

Step 5: Format the Logical Volume

Now format it with the ext4 filesystem. Other filesystems like XFS work too.

sudo mkfs.ext4 /dev/my_volume_group/my_logical_volume

This prepares the volume to store files.

Step 6: Mount the Logical Volume

Create a mount point and mount the volume.

sudo mkdir -p /mnt/my_storage
sudo mount /dev/my_volume_group/my_logical_volume /mnt/my_storage

Check that it’s mounted:

df -h /mnt/my_storage

You should see your 10GB volume listed and ready to use.

Step 7: Make the Mount Permanent

Mounts don’t survive a reboot unless you add them to /etc/fstab. Open the file:

sudo nano /etc/fstab

Add this line at the bottom:

/dev/my_volume_group/my_logical_volume /mnt/my_storage ext4 defaults 0 2

Save and close the file. Test the fstab entry without rebooting:

sudo mount -a

If no errors appear, you’re good.

Step 8: Extend a Logical Volume

This is where LVM truly shines. You can grow a volume without unmounting it.

First, extend the logical volume by 5GB:

sudo lvextend -L +5G /dev/my_volume_group/my_logical_volume

Then resize the filesystem to use the new space:

sudo resize2fs /dev/my_volume_group/my_logical_volume

Confirm the new size:

df -h /mnt/my_storage

Your volume now shows 15GB. No downtime required. That’s the power of how to set up and manage LVM (Logical Volume Manager) on Ubuntu Server for flexible disk partitioning in a real-world scenario.

Troubleshooting Common LVM Issues

Even experienced admins run into problems. Here are the most common ones and how to fix them.

Problem: “Device /dev/sdb not found”

This usually means the disk name is wrong. Run lsblk again to confirm the correct device name. Disk names can change after a reboot.

Problem: “Insufficient free space” when extending

Your volume group doesn’t have enough room. Check available space with:

sudo vgdisplay | grep "Free"

If space is low, add another physical volume to the group:

sudo pvcreate /dev/sdc
sudo vgextend my_volume_group /dev/sdc

Now you have more space to work with.

Problem: Filesystem doesn’t reflect new size after extending

You extended the logical volume but forgot to resize the filesystem. Always run resize2fs after lvextend. For XFS volumes, use xfs_growfs /mnt/my_storage instead.

Problem: Changes lost after reboot

You likely forgot to update /etc/fstab. Go back to Step 7 and add the mount entry. Double-check with sudo mount -a.

Warning: Never run pvcreate on a disk that already has data. It will wipe everything. Always double-check your disk name with lsblk before running any LVM commands.

For deeper reference on LVM commands and options, the official LVM man page covers every available flag and use case.

Conclusion: Managing LVM on Ubuntu for Long-Term Storage Flexibility

You now know how to set up and manage LVM (Logical Volume Manager) on Ubuntu Server for flexible disk partitioning from start to finish. You created physical volumes, built a volume group, carved out logical volumes, and extended them without any downtime. That’s a workflow you’ll use again and again in production environments.

LVM is a standard tool in any serious Linux setup. Once you’re comfortable with the basics, explore LVM snapshots for point-in-time backups. You can also look into thin provisioning for more efficient storage allocation.

Keep your volume group names descriptive. Document your LVM layout so future admins understand the setup. Good storage management saves you from headaches down the road. This foundation gives you full control over your Ubuntu server’s disk space for years to come.

Similar Posts