Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

LVM: Flexible Disk Management on Linux

By Kokil Thapa | Last reviewed: September 2026

LVM: Flexible Disk Management on Linux solves a problem every server operator hits eventually: a partition runs out of space, but the disk layout is rigid. Standard MBR or GPT partitions lock size at creation time. Logical Volume Manager (LVM) adds a flexible layer between raw block devices and filesystems. You can grow a database volume at 2 a.m. without reinstalling the OS. I've used LVM on every Linux production server I maintain for Laravel apps, MySQL databases, and client hosting stacks. This guide walks through the architecture, setup commands, live resize workflows, and the mistakes that cause data loss.

What is LVM and how does flexible disk management work on Linux?

LVM sits between your disks and filesystems. Raw block devices become Physical Volumes (PVs). PVs join a Volume Group (VG), which acts as a storage pool. From that pool you carve Logical Volumes (LVs), format them, and mount them like any partition.

The naming convention matters in production. A typical path looks like /dev/mapper/vg0-lvol0 or the symlink /dev/vg0/lvol0. The mapper device is what you format and mount.

LVM Storage Hierarchy/dev/sdbPhysical Volume/dev/sdcPhysical Volume/dev/sddPhysical VolumeVolume Group: vg0Combined storage poolLV: mysql-data200 GB ext4LV: app-logs50 GB xfsLV: backups100 GB ext4
LVM flexible disk management on Linux: physical volumes feed a volume group, which supplies logical volumes to filesystems.

Three concepts drive every LVM operation:

  • Physical Extents (PEs): Fixed-size chunks (default 4 MB on Ubuntu) that LVM allocates from PVs into LVs.
  • Volume Group: The named pool. All free PEs live here until assigned.
  • Logical Volume: The virtual disk your filesystem sees. Resize it independently of other LVs in the same VG.

On Ubuntu 22.04 and 24.04 servers, LVM2 ships by default. Install it explicitly if missing:

sudo apt update
sudo apt install lvm2
sudo systemctl enable --now lvm2-monitor.service

The upstream reference is the Red Hat LVM administration guide. Red Hat maintains the canonical documentation because LVM2 is shared across RHEL, Fedora, Debian, and Ubuntu.

How do you create LVM volumes on a fresh Ubuntu Linux server?

Assume a new data disk at /dev/sdb on an Ubuntu 24.04 VPS. The workflow has four stages: partition (optional), create PV, create VG, create LV.

Step 1: Prepare the block device

You can use a whole disk or a partition. For dedicated data disks, the whole disk is common:

sudo wipefs -a /dev/sdb
sudo pvcreate /dev/sdb
sudo pvs
sudo pvdisplay /dev/sdb

pvcreate writes an LVM label to the device. Verify with pvs before proceeding. A typo here targets the wrong disk.

Step 2: Create the volume group

sudo vgcreate vg-data /dev/sdb
sudo vgs
sudo vgdisplay vg-data

Need to add a second disk later? Run sudo vgextend vg-data /dev/sdc. The VG grows without touching existing LVs.

Step 3: Create and activate logical volumes

sudo lvcreate -L 100G -n mysql-data vg-data
sudo lvcreate -L 50G -n app-logs vg-data
sudo lvs
sudo lvdisplay /dev/vg-data/mysql-data

Format and mount each LV:

sudo mkfs.ext4 /dev/vg-data/mysql-data
sudo mkdir -p /var/lib/mysql-lvm
echo '/dev/vg-data/mysql-data /var/lib/mysql-lvm ext4 defaults 0 2' | sudo tee -a /etc/fstab
sudo mount -a

Always use the LV path in /etc/fstab, not /dev/sdX. SD names can shift after reboot on cloud VMs. LVM device names stay stable.

LVM Setup WorkflowRaw Disk/dev/sdbpvcreatePhysical VolumevgcreateVolume GrouplvcreateLogical Volumemkfs.ext4Format FSmount/etc/fstabVerify at each steppvs → vgs → lvs → df -hlvdisplay for PE mappingAlways backup before pvcreateDouble-check device names
Step-by-step LVM flexible disk management setup: pvcreate, vgcreate, lvcreate, format, and mount on Linux.

On client projects where I deploy Laravel applications with separate MySQL data directories, I always isolate database storage on its own LV. A runaway log volume cannot fill the database partition.

How do you resize LVM logical volumes without downtime?

Live extension is the main reason operators adopt LVM. The filesystem must support online resize. ext4 and XFS both work on modern Ubuntu kernels.

Extending a logical volume (most common)

  1. Add capacity to the VG (new disk or free PEs on an existing PV).
  2. Extend the LV with lvextend.
  3. Grow the filesystem to fill the new space.
# Add a new disk to the pool
sudo pvcreate /dev/sdc
sudo vgextend vg-data /dev/sdc

# Extend LV by 50 GB
sudo lvextend -L +50G /dev/vg-data/mysql-data

# Grow ext4 online
sudo resize2fs /dev/vg-data/mysql-data

# Verify
df -h /var/lib/mysql-lvm
sudo lvs

For XFS, use sudo xfs_growfs /mount/point instead of resize2fs. XFS cannot shrink—plan capacity accordingly.

Shrinking a logical volume (risky—backup first)

Shrinking requires unmounting for ext4. The safe order is: shrink filesystem first, then shrink LV.

sudo umount /dev/vg-data/app-logs
sudo e2fsck -f /dev/vg-data/app-logs
sudo resize2fs /dev/vg-data/app-logs 30G
sudo lvreduce -L 30G /dev/vg-data/app-logs
sudo mount /dev/vg-data/app-logs /var/log/app

Never run lvreduce before shrinking the filesystem. You will truncate data and corrupt files. I've seen this on a production deployment where someone skipped the resize2fs step.

Pair LVM resize workflows with log rotation and disk space management so application logs do not mask underlying storage pressure.

How does LVM compare to standard disk partitions on Linux?

Plain partitions work fine on small VPS instances with fixed sizing. LVM earns its overhead once you manage databases, backups, or multi-tenant hosting.

CriteriaStandard PartitionsLVM
Resize onlineDifficult; often needs downtime or backup/restoreExtend LVs and filesystems online (ext4/XFS grow)
Span multiple disksOne partition per disk slice; no poolingVolume group pools PVs into one namespace
SnapshotsNot native; requires LVM or filesystem snapshotslvcreate --snapshot for point-in-time copies
Boot complexitySimpler; direct /dev/sdX pathsRequires LVM-aware initramfs (default on Ubuntu)
Recovery toolsStandard fsck, testdiskAdditional: vgcfgrestore, pvscan, metadata backups
Best fitSingle-disk VPS, fixed workloadsDatabase servers, growing storage, managed hosting stacks

Ubuntu Server installs often use LVM on the root disk by default. The installer creates ubuntu-vg with LVs for root and swap. You inherit flexible disk management without manual setup.

Partitions vs LVMStandard Partitions/ 40 GB fixed/var 20 GB fixed/home 100 GB fixedRep partition to growNo pooling across disksLVM Logical Volumes/ grow onlinemysql extend +50Gsnap-db snapshot LVlvextend + resize2fsvgextend adds disks
LVM: Flexible Disk Management on Linux versus fixed partitions—online growth and snapshots versus rigid sizing.

How do LVM snapshots work for database backups on Linux?

An LVM snapshot captures the state of an LV at a point in time. Writes after snapshot creation go to a separate COW (copy-on-write) area. The snapshot LV reads unchanged blocks from the original and changed blocks from the COW pool.

# Create 10 GB snapshot (COW space, not full copy)
sudo lvcreate -L 10G -s -n mysql-snap /dev/vg-data/mysql-data

# Mount snapshot read-only for backup
sudo mkdir -p /mnt/snap
sudo mount -o ro /dev/vg-data/mysql-snap /mnt/snap
sudo tar czf /backup/mysql-$(date +%F).tar.gz -C /mnt/snap .

# Remove snapshot when done
sudo umount /mnt/snap
sudo lvremove /dev/vg-data/mysql-snap

Snapshots are not a replacement for off-site backups. They live on the same VG. A disk failure takes both the source LV and its snapshots. Combine snapshots with automated database backups on Linux and off-server storage.

Size the COW pool generously. Heavy write activity during a long backup can fill the snapshot and invalidate it. Monitor with lvs -o+snap_percent.

For booking platforms like Adventure Third Pole Trek, I snapshot the MySQL LV before major Laravel migrations. If a migration corrupts data, I restore from the snapshot in minutes instead of replaying binlogs.

What are common LVM mistakes on production Linux servers?

LVM is reliable when you respect ordering and metadata. These errors recur across client servers I troubleshoot.

Wrong device names in scripts

Cloud providers reassign /dev/sdX after attach/detach cycles. Use /dev/disk/by-id/ or /dev/disk/by-uuid/ in automation and /etc/fstab. LVM PV paths in /etc/lvm/backup/ reference UUIDs, which is safer.

Skipping metadata backups

LVM stores VG layout in on-disk metadata. Corruption or accidental pvremove can orphan LVs. Back up metadata regularly:

sudo vgcfgbackup vg-data
sudo ls -la /etc/lvm/backup/vg-data
sudo vgcfgrestore -l vg-data

Store copies off-server alongside your cron-scheduled backup jobs.

100% full volume groups

Leave 5–10% free PEs in every VG. Snapshots need COW space. Emergency extends need headroom. A full VG blocks lvextend at the worst moment.

Shrinking without filesystem prep

Already covered, but it bears repeating. lvreduce before resize2fs destroys data. Always unmount, run e2fsck -f, shrink the FS, then shrink the LV.

LVM Production Gotchaslvreduce before resize2fsData truncation — unrecoverableVG at 100% capacitySnapshots fail mid-backup/dev/sdb name driftUse /dev/disk/by-id pathsNo vgcfgbackupMetadata loss orphans LVsPrevention checklistBackup metadata · Leave VG headroom · Test resize on staging
Avoid these LVM flexible disk management failures on production Linux servers running databases and web applications.

Monitor disk usage with Netdata alerts and investigate spikes using CPU and memory diagnostics when runaway processes fill storage.

How do you integrate LVM with RAID and cloud block storage?

LVM and RAID solve different problems. RAID protects against disk failure. LVM manages capacity flexibly. The usual stack is RAID1 or RAID10 underneath, with LVM on top.

# Software RAID1 + LVM example
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
sudo pvcreate /dev/md0
sudo vgcreate vg-raid /dev/md0
sudo lvcreate -L 500G -n production vg-raid

On AWS EC2, attach a new EBS volume, create a PV, and run vgextend. No reboot required. The same pattern works on DigitalOcean volumes and Hetzner cloud disks.

For ongoing server maintenance, document your VG layout in runbooks. Include PV UUIDs, LV sizes, mount points, and filesystem types. The next engineer (or future you) should not need to reverse-engineer the server at 3 a.m.

Thin provisioning (lvcreate -V) lets you overcommit storage. Useful in lab environments. Risky in production unless you monitor actual usage closely. Most client servers I run use thick LVs for predictability.

Encrypted LVs use LUKS on top of or below LVM. Ubuntu full-disk encryption during install places LUKS below LVM. Either order works; pick one and document it. Key recovery matters more than the stacking choice.

Refer to the lvm(8) man page for the full command reference. The Ubuntu community wiki also covers LVM on Ubuntu with distribution-specific installer notes.

Proper file permissions and ACLs on mounted LVs matter as much as the storage layer. A world-writable backup mount undermines every hardening step above it.

When planning capacity, a quick storage budget helps. If you are sizing monthly hosting costs in NPR, the Nepal EMI calculator can model hardware lease payments alongside cloud volume pricing (~Rs 8–15/GB/month on local providers, ~USD 0.10/GB on AWS).

For WordPress and WooCommerce stacks on shared VPS hosts, separate LVs for /var/www, MySQL, and backups simplify performance testing and optimization. You can snapshot the database LV before plugin updates without touching uploaded media.

Legal-tech portals such as Court Marriage In Nepal store uploaded documents on dedicated LVs. Document storage grows independently of application code. Extending the LV takes five commands instead of a full migration.

If you inherit a server with cryptic VG names, rename safely:

sudo vgrename old-vg-name new-vg-name
sudo lvrename new-vg-name old-lv-name new-lv-name
sudo vi /etc/fstab
sudo update-initramfs -u

Update every reference: fstab, application configs, backup scripts, and systemd unit files that point at mount paths.

On sister sites sharing a Deployer 7 pipeline, I keep identical VG naming (vg-app, vg-data) across servers. Automation scripts stay portable. Consistency beats clever naming.

Read Ubuntu user management alongside storage work when provisioning new team accounts. Disk quotas and LVM are complementary—LVM controls the pool, quotas limit per-user consumption within a mount.

Enterprise deployments sometimes use multi-tier application architectures with dedicated database servers. LVM on DB hosts is non-negotiable. Query logs and binlogs grow continuously.

Before any destructive LVM command, run sudo lvdisplay and confirm the LV path twice. Pipe destructive commands through pv for a visual pause:

echo 'yes' | sudo lvremove /dev/vg-data/old-lv

The -f flag on lvremove skips confirmation. Never alias it in production shells.

Key Takeaways

  • LVM maps PVs into VGs and LVs, giving you online resize and snapshot capability that plain partitions lack.
  • Always extend the filesystem after lvextend; always shrink the filesystem before lvreduce.
  • Back up VG metadata with vgcfgbackup and keep 5–10% free PEs in every volume group.
  • Use stable device paths (/dev/vg-name/lv-name or /dev/disk/by-id) in fstab and automation.
  • Combine LVM snapshots with off-server backups—snapshots alone do not survive disk failure.
  • Document your VG layout in runbooks so the next maintenance window does not start with guesswork.

People Also Ask

Does Ubuntu Server use LVM by default?

Yes. The Ubuntu Server installer offers guided LVM setup on the entire disk. It creates a volume group (usually ubuntu-vg) with logical volumes for root and swap. You get flexible disk management from day one without manual pvcreate steps.

Can you convert existing partitions to LVM without reinstalling?

Yes, but it requires backup, shrink, and migration. Back up data, shrink the partition and filesystem, create PV/VG/LV structures, copy data, and update fstab. Tools like gparted help with partition shrinking. Test on a staging clone first.

Is LVM slower than direct partitions?

The overhead is negligible on modern hardware—typically 1–3% for most workloads. The flexibility benefits outweigh the tiny I/O cost on database and web servers. RAID and SSD/NVMe performance dominate latency, not the LVM indirection layer.

How do you remove LVM from a disk completely?

Deactivate in reverse order: unmount filesystems, run lvremove on each LV, then vgremove on the VG, then pvremove on each PV. Finally, wipefs -a /dev/sdX clears LVM signatures. Confirm no production data remains before pvremove.

Put flexible storage to work on your next deployment

LVM: Flexible Disk Management on Linux is not optional on servers that outgrow their initial disk layout. The commands are straightforward. The discipline—metadata backups, resize ordering, headroom planning—is what separates smooth 2 a.m. extends from corrupted databases. Start with separate LVs for database, application, and backup data on your next VPS. Your future self will thank you when MySQL needs another 50 GB and the site stays online.

Need help sizing storage, migrating to LVM, or hardening a production Ubuntu stack? See the Linux system administration service or contact us to discuss your server layout. For background on the author, visit about me or browse the project portfolio.

Frequently Asked Questions

LVM sits between raw block devices and filesystems. Disks become Physical Volumes, which join a Volume Group that acts as a storage pool. From that pool you carve Logical Volumes, format them, and mount them like any partition. Physical Extents are fixed chunks, defaulting to 4 MB on Ubuntu. Paths such as /dev/vg-data/mysql-data stay stable across reboots, unlike /dev/sdX names that cloud providers can reassign after attach cycles.

LVM2 ships by default on Ubuntu Server, but verify it is present before building volumes. Run sudo apt update followed by sudo apt install lvm2, then enable the monitor service with sudo systemctl enable --now lvm2-monitor.service. The Red Hat LVM administration guide is the upstream reference because LVM2 is shared across RHEL, Fedora, Debian, and Ubuntu. Check pvs after installation to confirm the tools respond before touching production disks.

Assume a dedicated data disk at /dev/sdb. Run wipefs -a only after confirming the device, then pvcreate, vgcreate vg-data, and lvcreate for each logical volume such as mysql-data and app-logs. Format with mkfs.ext4, create mount points, and add entries to /etc/fstab using the LV path, never /dev/sdX. Run pvs, vgs, and lvs at every stage. On Laravel deployments I isolate MySQL on its own LV so a runaway log volume cannot fill the database partition.

First add capacity to the volume group by running pvcreate on a new disk and vgextend on the existing group. Then lvextend -L +50G on the target logical volume. Grow the filesystem afterward: resize2fs for ext4 or xfs_growfs for the mount point on XFS. Both filesystems support online growth on modern Ubuntu kernels. Verify with df -h and lvs. Skipping the filesystem step leaves space inside the LV that applications cannot use.

Shrinking is risky and requires a backup first. Unmount the filesystem, run e2fsck -f on the LV, shrink the filesystem with resize2fs to the target size, then run lvreduce to match. Never run lvreduce before shrinking the filesystem—that truncates blocks and corrupts data. I have seen this on a production deployment where someone skipped resize2fs. XFS cannot shrink at all, so choose ext4 or plan capacity upfront if you might need to reduce size later.

Yes. The installer offers guided LVM on the entire disk and creates ubuntu-vg with logical volumes for root and swap.

Overhead is typically one to three percent on modern hardware. RAID level and SSD or NVMe performance dominate latency, not the LVM indirection layer.

Local Nepali providers charge roughly Rs 8–15 per GB (~USD 0.06–0.11). AWS EBS runs about USD 0.10 per GB.

Plain partitions work on small VPS instances with fixed sizing. LVM adds online resize for ext4 and XFS, pools multiple disks into one volume group, and supports snapshots through lvcreate --snapshot. Standard partitions boot more simply and recover with ordinary fsck. LVM needs an LVM-aware initramfs, which Ubuntu provides by default. For MySQL databases, backup workflows, and multi-tenant hosting stacks I maintain, the flexibility outweighs the small operational overhead once storage needs to grow.

A snapshot captures LV state at a point in time using copy-on-write, not a full duplicate. Create one with lvcreate -L 10G -s -n mysql-snap, mount it read-only, tar the contents, then lvremove when finished. Unchanged blocks read from the source; writes during the snapshot fill the COW pool. Monitor snap_percent with lvs and size the COW pool generously. Snapshots are not off-site backups—a disk failure takes both source and snapshot. On booking platforms I snapshot the MySQL LV before major Laravel migrations.

Yes, but it requires backup, shrink, and migration rather than an in-place magic conversion. Back up all data, shrink the partition and filesystem to free space, create PV, VG, and LV structures on the freed or new disk, copy data across, and update /etc/fstab plus any application configs pointing at old paths. Tools like gparted help with partition shrinking. Test the full workflow on a staging clone before touching production. Plan a maintenance window because shrinking usually requires unmounting.

Work in reverse order of creation. Unmount every filesystem on the logical volumes, run lvremove on each LV, vgremove on the volume group, then pvremove on each physical volume. Finally run wipefs -a on the block device to clear LVM signatures. Confirm twice with lvdisplay that you are targeting the correct paths. Pipe destructive commands through pv for a visual pause in production shells, and never alias lvremove -f to skip confirmation.

The recurring failures I troubleshoot are wrong /dev/sdX device names in fstab and scripts, skipped vgcfgbackup metadata backups, volume groups filled to 100 percent, and lvreduce run before filesystem shrink. Use /dev/vg-name/lv-name or /dev/disk/by-id paths instead. Back up metadata with vgcfgbackup and store copies off-server. Leave five to ten percent free physical extents in every volume group for snapshots and emergency extends. A full VG blocks lvextend at the worst possible moment.

RAID and LVM solve different problems. Create RAID1 or RAID10 with mdadm on mirrored disks, pvcreate on /dev/md0, then vgcreate and lvcreate on top. On AWS EC2, attach a new EBS volume, pvcreate it, and vgextend the existing group with no reboot. The same pattern works on DigitalOcean and Hetzner cloud disks. Document PV UUIDs, LV sizes, mount points, and filesystem types in runbooks. On sister sites sharing a Deployer 7 pipeline, I keep identical VG naming such as vg-app and vg-data so automation scripts stay portable.

Thin provisioning via lvcreate -V lets you overcommit storage and suits lab environments, but it is risky in production unless you monitor actual usage closely. Most client servers I run use thick logical volumes for predictability. Encrypted volumes use LUKS above or below LVM; Ubuntu full-disk encryption places LUKS below LVM during install. Either stacking order works—document the choice and prioritize key recovery. Proper file permissions on mounted LVs matter as much as the storage layer; a world-writable backup mount undermines hardening.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: