Linux

Linux LVM Guide: Creating Physical Volumes, Volume Groups, and Logical Volumes on Ubuntu and RHEL

The Back Room Tech Staff · Edited by Aseem Kishore
14 min read

The Back Room Tech is reader-supported. We may earn a commission when you buy through links on our site. Learn more.

This Linux LVM guide takes you from a blank disk to a mounted, reboot-proof logical volume on Ubuntu Server or RHEL 9/10. You’ll run five core steps: pvcreate, vgcreate, lvcreate, mkfs, and an /etc/fstab edit. Check the result after each one, because LVM mistakes are cheap to catch early and expensive to catch late.

The short answer: identify the disk with lsblk. Initialize it with sudo pvcreate /dev/sdX. Pool it with sudo vgcreate vgdata /dev/sdX. Carve out space with sudo lvcreate --name lvdata --size 5G vgdata. Format it with mkfs, then add a UUID-based line to /etc/fstab so the mount survives a reboot. The core commands are the same on Ubuntu and RHEL. The differences you’ll notice most in this workflow are package install, the usual filesystem, and whether you partition the disk first; defaults and boot integration can also vary by release.

Quick Reference: The LVM Workflow at a Glance

StepCommandVerify With
Find the disklsblksudo fdisk -l
Create physical volumesudo pvcreate /dev/sdb1sudo pvs / sudo pvdisplay
Create volume groupsudo vgcreate vgdata /dev/sdb1sudo vgs / sudo vgdisplay
Create logical volumesudo lvcreate --name lvdata --size 5G vgdatasudo lvs / sudo lvdisplay
Formatsudo mkfs.xfs /dev/vgdata/lvdatasudo blkid /dev/vgdata/lvdata
Persist mountEdit /etc/fstab with the UUIDsudo mount -a then findmnt /data

What Is LVM? PV vs VG vs LV

LVM (Logical Volume Manager) is a storage layer from the lvm2 package. It sits between your raw disks and the filesystems you mount. It has three layers:

  • Physical Volume (PV): a disk or partition that pvcreate has labeled with LVM metadata. This is the raw material.
  • Volume Group (VG): a named pool built from one or more PVs. Add three disks to one VG and they become one large pool of space.
  • Logical Volume (LV): a block device carved out of a VG’s free space. You format and mount it like a normal partition.

The payoff is flexibility. A plain partition has a fixed size. An LV can grow into free space in its VG, and a VG can grow when you add another disk.

The trade-off is one more layer to understand and troubleshoot. For a single disk that’ll never change size, plain partitioning is simpler. ZFS and Btrfs build similar pooling into the filesystem itself. They’re a different storage stack, though, and out of scope here.

Prerequisites

  • Ubuntu Server (current LTS) or RHEL 9 / RHEL 10
  • Terminal access with sudo or root privileges
  • The lvm2 package installed (present by default on most server installs)
  • An unused disk or partition holding no data you need. For example, a spare SSD, a second NAS hard drive in a homelab box, or an extra virtual disk attached to a VM
  • A current backup of anything important on the machine

Check that lvm2 is installed, and install it if it’s missing:

# Ubuntu / Debian
sudo apt update && sudo apt install lvm2

# RHEL 9 / RHEL 10
sudo dnf install lvm2

The examples below use /dev/sdb as the new disk. Your device name may differ. Expect /dev/vdb on KVM guests or /dev/nvme1n1 on NVMe drives. Swap in your own device name in every command.

Step-by-Step Guide

Step 1: Identify the Target Disk with lsblk and fdisk

Do this before you touch anything. Most LVM disasters start with the wrong device name.

lsblk

Example output (your devices will differ):

NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                         8:0    0   40G  0 disk
├─sda1                      8:1    0    1G  0 part /boot/efi
├─sda2                      8:2    0    2G  0 part /boot
└─sda3                      8:3    0   37G  0 part
  └─ubuntu--vg-ubuntu--lv 252:0    0   37G  0 lvm  /
sdb                         8:16   0   20G  0 disk

You’re looking for a disk with no children and no mountpoint. Here, that’s sdb. Note that sda already holds an LVM volume for the root filesystem. Leave it alone.

lsblk output showing the system disk sda with partitions and an existing root LV, plus an empty 20G disk sdb with no partitions or mountpoints, highlighted as the target

Confirm the disk is empty with fdisk:

sudo fdisk -l /dev/sdb

No partition table entries means the disk is a clean target. If you see partitions you don’t recognize, stop. Find out what they are before you continue.

Step 2: Decide Between a Whole Disk and a Partition

This is the main place where the two vendors’ docs disagree:

Both approaches work. A partition makes the disk’s purpose obvious to other tools and other admins. A whole disk is simpler and skips partition-alignment questions. Pick one and use it consistently.

If you’re using the whole disk, skip to Step 3.

To partition the disk, open it in fdisk:

sudo fdisk /dev/sdb

Inside fdisk, press these keys in order:

  • n: create a new partition. Accept the defaults to use the full disk.
  • t: change the partition type.
  • 8e: Linux LVM. This is the MBR (DOS) type code that Ubuntu documents, and it only applies to an MBR partition table.
  • p: print the table to verify it.
  • w: write the changes and exit.

Ubuntu’s docs only cover the MBR code. On a GPT disk, 8e isn’t a valid type. At the type prompt, press L to list the GPT types, find the Linux LVM entry, and enter the number shown next to it. That number can differ between fdisk versions, so read it from the list rather than copying it from a guide.

fdisk session on /dev/sdb showing the partition table after setting type 8e, with the Type column reading Linux LVM highlighted

The p output should list /dev/sdb1 with type Linux LVM. The rest of this guide uses /dev/sdb1. If you used the whole disk, use /dev/sdb instead.

Warning: Pressing w in fdisk overwrites the partition table on that disk. Double-check the device name at the top of the fdisk session before you write.

Step 3: Create the Physical Volume with pvcreate

Warning: pvcreate writes LVM metadata to the target and can destroy existing data on it. Run lsblk one more time right before this command.

sudo pvcreate /dev/sdb1

Expected output:

  Physical volume "/dev/sdb1" successfully created.

Verify:

sudo pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda3  ubuntu-vg lvm2 a--  <37.00g      0
  /dev/sdb1            lvm2 ---  <20.00g <20.00g

The VG column is empty because the new PV doesn’t belong to a group yet. PFree equals PSize because none of its space is in use. For full details, including the PV UUID, run sudo pvdisplay /dev/sdb1.

pvcreate success message followed by pvs table showing /dev/sdb1 with lvm2 format, empty VG column, and PSize/PFree columns highlighted

Step 4: Create the Volume Group with vgcreate

sudo vgcreate vgdata /dev/sdb1
# vgdata is the VG name, used in paths like /dev/vgdata/...
# List multiple PVs to pool them: sudo vgcreate vgdata /dev/sdb1 /dev/sdc1

Expected output:

  Volume group "vgdata" successfully created

Optional: you can set the physical extent size at creation time with -s. Extents are the allocation units in a VG, and LVM sets a default automatically if you don’t specify one (Red Hat: Managing LVM volume groups).

Check your distribution’s current documentation before relying on a specific default value or assuming the extent size can’t be adjusted later. Most setups never need to touch it.

# Alternative: create the VG with 8 MiB extents instead of the default
sudo vgcreate -s 8M vgdata /dev/sdb1

Verify:

sudo vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  ubuntu-vg   1   1   0 wz--n- <37.00g      0
  vgdata      1   0   0 wz--n- <20.00g <20.00g

This is how you check free space before creating an LV. The VFree column shows exactly how much you can allocate. sudo vgdisplay vgdata shows the same data in more detail, including PE Size and Free PE / Size.

vgcreate success message followed by vgs table with the vgdata row highlighted, showing #PV 1, #LV 0, and VSize/VFree columns

Step 5: Create the Logical Volume with lvcreate

You’ve got two options. Use a fixed size:

sudo lvcreate --name lvdata --size 5G vgdata
# --name sets the LV name; --size takes units like M, G, T

Or use the --extents 100%FREE option, which is designed to allocate the VG’s remaining free space to the LV:

sudo lvcreate --name lvdata --extents 100%FREE vgdata
# --extents (-l) sets the LV size by extent count or percentage instead of a fixed size

Expected output:

  Logical volume "lvdata" created.

The fixed-size option leaves some VG space free. That gives you room to grow the LV later or to take snapshots. Using all remaining free space makes sense if the disk has one job.

Verify:

sudo lvs
  LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- <37.00g
  lvdata    vgdata    -wi-a-----   5.00g

The a in Attr means the LV is active. There’s no o (open) flag yet because nothing is using the device, and here nothing has mounted it. sudo lvdisplay /dev/vgdata/lvdata shows the full path, the UUID, and the size.

lvcreate success message followed by lvs table with the lvdata row in vgdata highlighted, showing the LSize column at 5.00g

Step 6: Format the Logical Volume with mkfs

A new LV is only a block device. Red Hat’s docs note that it must be formatted and mounted before you can use it (Red Hat: Basic logical volume management). Pick one filesystem:

# XFS — the conventional choice on RHEL
sudo mkfs.xfs /dev/vgdata/lvdata

# ext4 — the conventional choice on Ubuntu
sudo mkfs.ext4 /dev/vgdata/lvdata

The mkfs.ext4 output ends with a line like this:

Writing superblocks and filesystem accounting information: done

mkfs.xfs prints a block of geometry details (meta-data=, data=, log=, and so on). No error message means it worked.

Warning: mkfs creates a new, empty filesystem and destroys whatever was on the target device. Run it only on the LV you just created, and double-check the device path. Never point it at an existing volume that holds data.

Note on resizing: Filesystem resize capabilities (growing versus shrinking) differ by filesystem and can change between OS versions, so don’t assume a specific behavior.

Check your distribution’s current xfs_growfs and resize2fs documentation before planning a resize, especially a shrink, and pick whichever filesystem that documentation supports for your needs.

mkfs.xfs or mkfs.ext4 output formatting /dev/vgdata/lvdata, with the device path and filesystem type highlighted

Step 7: Mount the Volume and Get Its UUID

Create a mountpoint and mount the volume once by hand:

sudo mkdir -p /data
sudo mount /dev/vgdata/lvdata /data
df -h /data

Next, grab the filesystem UUID:

sudo blkid /dev/vgdata/lvdata
/dev/vgdata/lvdata: UUID="3f8c2a1e-xxxx-xxxx-xxxx-xxxxxxxxxxxx" BLOCK_SIZE="512" TYPE="xfs"
blkid output for /dev/vgdata/lvdata with the UUID value and TYPE field highlighted

Why use a UUID instead of /dev/sdb1? The kernel assigns device names in detection order. Add a disk, move a cable, or change controllers, and /dev/sdb can become /dev/sdc on the next boot. An /dev/sdX entry in fstab will then mount the wrong thing or fail outright.

The UUID belongs to the filesystem itself, so it stays the same when device naming changes. It isn’t permanent, though: reformatting the volume creates a new UUID, so update fstab after any mkfs.

The /dev/mapper/vgdata-lvdata path is also generally considered stable, since it’s derived from the VG and LV names rather than detection order. Either option is commonly recommended over a raw /dev/sdX path.

Step 8: Make the Mount Persistent in /etc/fstab

Back up fstab first. A broken entry can drop the system into emergency mode at boot, and that’s a bad way to spend an evening.

sudo cp /etc/fstab /etc/fstab.bak
sudo nano /etc/fstab

Add one line. Use your own UUID and filesystem type:

# /etc/fstab
UUID=3f8c2a1e-xxxx-xxxx-xxxx-xxxxxxxxxxxx  /data  xfs  defaults,nofail  0 0
# Alternative using the stable mapper path:
# /dev/mapper/vgdata-lvdata  /data  xfs  defaults,nofail  0 0

The nofail option is intended to let the system continue booting even if this volume is missing. Without it, a failed entry for this mount can stop the boot and drop you into emergency mode, which is why the backup above matters.

That behavior comes from systemd’s handling of fstab entries, and exact specifics can vary by distribution and systemd version. It’s commonly useful on secondary data disks that aren’t required for the system to start. For ext4, change xfs to ext4. You can also set the last field to 2 if you want periodic fsck checks.

Test the entry without rebooting:

sudo umount /data
sudo systemctl daemon-reload   # tells systemd to re-read fstab
sudo mount -a                   # intended to mount all fstab entries; errors typically appear here rather than at boot
findmnt /data
TARGET SOURCE                    FSTYPE OPTIONS
/data  /dev/mapper/vgdata-lvdata xfs    rw,relatime,...

If findmnt shows the mount, your entry works. Run cat /etc/fstab to confirm the line was saved.

cat /etc/fstab output with the new UUID=... /data xfs defaults,nofail 0 0 line highlighted

Step 9: Final Verification

Run all three summary commands together:

sudo pvs && sudo vgs && sudo lvs

lvs should now show -wi-ao---- for lvdata. The o means the device is open; in this case that’s because it’s mounted on /data. If you can, reboot and run findmnt /data again to confirm the mount survives.

Configuration: Ubuntu vs RHEL Differences

ItemUbuntu ServerRHEL 9 / 10
Install lvm2sudo apt install lvm2sudo dnf install lvm2
Documented PV targetPartition (type 8e / lvm flag)Whole disk
Typical filesystemext4XFS
Grow LV + filesystemlvextend --resizefs documentedlvextend + xfs_growfs, or --resizefs
Default extent sizeNot stated in Ubuntu docsNot confirmed in current docs
LVM config file/etc/lvm/lvm.conf/etc/lvm/lvm.conf

The pvcreate, vgcreate, lvcreate, pvs, vgs, and lvs commands work the same way on both distributions. RHEL 10 also has a Cockpit web console that can create VGs and LVs. This guide sticks to the CLI. You can script it, and it behaves the same everywhere.

Tips and Troubleshooting

pvcreate ran on the wrong disk

Why it happens: the device name was misread from the lsblk output. Fix: prevention is the only reliable fix. Run lsblk right before pvcreate and match the device by size and by the lack of a mountpoint. If you did hit the wrong disk, stop writing to it right away and restore from backup.

“Can’t open /dev/sdb1 exclusively. Mounted filesystem?”

Why it happens: the device is mounted or in use by another process. Fix: check with findmnt /dev/sdb1 or lsblk. Unmount the device with sudo umount, stop any service using it, and then run pvcreate again.

lvcreate fails with “Insufficient free extents”

Why it happens: you asked for more space than the VG has. Fix: check VFree with sudo vgs. Then request a smaller size, use --extents 100%FREE, or add a disk with sudo pvcreate /dev/sdc followed by sudo vgextend vgdata /dev/sdc.

The LV exists but you can’t store anything on it

Why it happens: the LV was never formatted, or it was formatted but never mounted. Fix: run mkfs (Step 6), then mount the volume (Step 7). Check that lvs shows the o flag.

The mount disappears after a reboot

Why it happens: the volume was only mounted by hand, or fstab uses an /dev/sdX path that changed. Fix: replace the entry with a UUID= or /dev/mapper/ path and test it with sudo mount -a before rebooting.

You extended the LV but df shows the old size

Why it happens: lvextend grows the block device. The filesystem on it keeps its old size until you resize it. Fix: use sudo lvextend --resizefs --size +5G vgdata/lvdata, or run xfs_growfs /data (XFS) or resize2fs (ext4) after lvextend.

One more tip: sudden power loss during metadata writes can cause problems. A small UPS on a homelab storage box is cheap insurance.

Wrapping Up

You now have an LVM volume that mounts by UUID and comes back after every reboot. You can check each layer with pvs, vgs, and lvs. Growing it later takes an lvextend with --resizefs (plus a vgextend first if you add a disk), with no repartitioning.

In my view, LVM is the right default for any Linux server whose storage needs might change. I’d still leave some free space in the VG instead of using 100%FREE everywhere. That headroom is what makes resizes and pre-change snapshots painless.

StepActionApplies To
1–2Identify disk, optionally partition (8e)Ubuntu (partition), RHEL (whole disk)
3–5pvcreate → vgcreate → lvcreateBoth
6mkfs.ext4 or mkfs.xfsUbuntu / RHEL convention
7–9blkid, fstab, mount -a, verifyBoth

Resources