Table of Contents
Understanding Logical Volumes in Linux (LVM)
Logical volumes are the core abstraction provided by LVM (Logical Volume Manager). In the parent chapter you’ve seen LVM concepts in general; here we focus specifically on logical volumes (LVs): how they are structured, created, managed, and used.
This chapter assumes you already know the relationship:
- Physical Volume (PV) → Volume Group (VG) → Logical Volume (LV)
and focuses on the LV layer.
What Is a Logical Volume (in Practice)?
A logical volume is the “virtual disk” that you actually put filesystems on and mount. From the kernel’s point of view, a logical volume looks like a block device (similar to a normal partition).
Typical device paths:
/dev/<vg_name>/<lv_name>(e.g./dev/vgdata/lvhome)/dev/mapper/<vg_name>-<lv_name>(e.g./dev/mapper/vgdata-lvhome)
You can:
- Create filesystems on LVs (
mkfs.ext4 /dev/vgdata/lvhome) - Mount them (
mount /dev/vgdata/lvhome /home) - Resize them (grow or shrink, with care)
- Take snapshots (copy‑on‑write views of an LV)
The key advantage: LVs are flexible: sizes and layout can change without touching the underlying physical disks directly.
Types of Logical Volumes
LVM supports several kinds of logical volumes. The most common in everyday use:
1. Linear Logical Volumes
This is the default and simplest type:
- Data is stored sequentially across one or more PVs.
- If the LV spans multiple PVs, chunks are laid out one after another.
Use case: Most general-purpose filesystems, root filesystem, /home, etc.
You typically get a linear LV if you don’t specify otherwise when creating it.
2. Striped Logical Volumes
Striped LVs distribute data in stripes across multiple PVs:
- Similar to RAID 0 across PVs.
- Each stripe is a chunk of data written alternately to each PV.
Benefits:
- Higher sequential and parallel I/O throughput when using multiple disks.
- Good for workloads with heavy read/write requirements.
Drawbacks:
- Loss of any PV in the stripe set typically loses the whole LV.
- Good backups or higher redundancy layers are critical.
Creation example (conceptual):
lvcreate -i 2 -I 64 -L 100G -n lvfast vgdata-i 2→ 2 stripes (use 2 PVs)-I 64→ 64 KB stripe size
3. Mirrored Logical Volumes (Classic LVM Mirroring)
Mirrored LVs maintain multiple copies of data across PVs:
- Similar to RAID 1.
- LVM keeps two (or more) copies in sync.
Key points:
- Increased redundancy: one disk can fail without data loss (depending on configuration).
- Write performance may be slower (writes must go to all mirrors).
- Read performance can improve (reads may be balanced).
Note: Many setups now use hardware RAID or MD RAID for mirroring and let LVM sit on top. Mirrored LVs are still useful but not as common as they once were.
4. Thin and Thin-Pool Logical Volumes (Overview Only)
Thin provisioning is powerful and deserves its own deep dive, but from the LV perspective:
- A thin pool is a special LV that provides storage space “on demand”.
- Thin LVs are logical volumes carved out of a thin pool:
- They appear as full-size devices to the OS.
- Real disk space is allocated only as data is written.
Useful when:
- You want to overprovision storage (e.g. many VMs each with a “virtual” 500 GB disk) without physically allocating it all up front.
- You need fast, space-efficient snapshots.
Managing thin LVs uses lvcreate --type thin-pool and lvcreate --thin options; we’ll touch on generic LV operations here and leave advanced thin-provisioning behavior for a dedicated chapter or practice.
Creating Logical Volumes
Logical volumes live inside an existing volume group. You must have a VG ready first.
Basic Linear LV Creation
Common patterns:
- Create by size:
lvcreate -L 20G -n lvhome vgdata-L 20G→ size in gigabytes-n lvhome→ LV namevgdata→ volume group name
- Create by percentage of VG:
lvcreate -l 100%FREE -n lvbackup vgdata-luses extents (LVM’s internal unit of allocation)100%FREEmeans “use all remaining free extents in the VG”
- Create by percentage of total VG size:
lvcreate -l 50%VG -n lvdata vgdata- 50% of the VG total size is assigned to the LV.
Creating a Striped LV
You need at least as many PVs as stripes:
lvcreate -L 50G -i 2 -I 128 -n lvvideo vgfastKey options:
-i <num>: number of stripes (devices to spread across).-I <KB>: stripe size in kilobytes.
Choose stripe size according to workload (larger for big sequential I/O, smaller for many small I/Os).
Creating a Mirrored LV (Classic)
Example with two-way mirror:
lvcreate -L 20G -m 1 -n lvsafe vgdata-m 1→ one additional mirror (2 copies total).
Inspecting Logical Volumes
Several tools let you see LVs and how they are laid out.
The `lvs` Command (Summary View)
lvsTypical output:
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvroot vgroot -wi-ao---- 40.00g
lvhome vgroot -wi-ao---- 200.00gKey columns:
LV: logical volume nameVG: volume group nameAttr: attributes describing type, permissions, etc.LSize: logical size
You can customize columns, e.g.:
lvs -o lv_name,vg_name,lv_size,segtypeThe `lvdisplay` Command (Detailed View)
lvdisplay /dev/vgroot/lvhomeShows:
- LV path, UUID
- LV size
- LV segment type (linear, striped, mirrored, etc.)
- Number of stripes, mirror count, etc.
Using Logical Volumes as Filesystem Devices
The basic workflow:
- Create the LV.
- Put a filesystem on it.
- Mount it (manually or via
/etc/fstab).
Example: Creating and Mounting an LV for `/data`
- Create LV:
lvcreate -L 100G -n lvdata vgdata- Make filesystem:
mkfs.ext4 /dev/vgdata/lvdata- Create mount point:
mkdir /data- Mount:
mount /dev/vgdata/lvdata /data- Add to
/etc/fstab(persistent mount):
/dev/vgdata/lvdata /data ext4 defaults 0 2Resizing Logical Volumes
One of the biggest advantages of LVs is that you can change their size. You must always consider both:
- The LV size
- The filesystem size
They are separate layers, and each has its own tools and limits.
Growing (Extending) a Logical Volume
Common situation: partition runs out of space; you want to give it more.
General steps:
- Ensure the VG has free space (
vgsorvgdisplay). - Extend the LV.
- Grow the filesystem.
Example: Extend lvdata from 100G to 150G and grow an ext4 filesystem:
- Extend the LV:
lvextend -L 150G /dev/vgdata/lvdata
# or add +50G:
lvextend -L +50G /dev/vgdata/lvdata- Grow the filesystem (online for ext4 on a mounted LV):
resize2fs /dev/vgdata/lvdata
Some filesystems (like XFS) use different tools (e.g. xfs_growfs) and may require specific procedures, but the logic is always:
- Step 1: LV bigger
- Step 2: filesystem bigger
Shrinking (Reducing) a Logical Volume
Shrinking is riskier than growing because data may be truncated if mistakes are made. General rule:
Shrink the filesystem first, then shrink the LV.
Example with ext4:
- Unmount the filesystem (most filesystems require this to shrink):
umount /data- Check filesystem consistency:
e2fsck -f /dev/vgdata/lvdata- Shrink filesystem to target size (must be >= used space):
resize2fs /dev/vgdata/lvdata 80G- Now shrink the LV:
lvreduce -L 80G /dev/vgdata/lvdata
# or interactive:
lvreduce -r -L 80G /dev/vgdata/lvdata
The -r option (--resizefs) can automatically shrink the filesystem along with the LV for supported filesystems, but you should still have backups and understand what is happening.
- Mount again:
mount /dataAlways have verified backups before shrinking LVs. A mistake can lead to irreversible data loss.
Moving Logical Volumes Between Physical Volumes
You can relocate the data backing an LV from one PV to another without unmounting, using pvmove. The LV itself doesn’t change from the filesystem’s perspective; its underlying extents are just moved.
Example: Move all data from /dev/sdb1 to /dev/sdc1 within the same VG:
pvmove /dev/sdb1 /dev/sdc1Use cases:
- Replacing a failing disk (after adding a new PV to the VG).
- Migrating data to faster storage.
From the logical volume’s view, nothing about its device path or size changes, only the physical location of its extents.
Renaming Logical Volumes
You might need more descriptive LV names later. You can rename without losing data.
Example:
lvrename vgdata oldname lvappdataor specifying full paths:
lvrename /dev/vgdata/oldname /dev/vgdata/lvappdataAfter renaming, remember to update references in:
/etc/fstab- Any scripts or configuration files pointing to the old name.
Deleting Logical Volumes
To remove an LV:
- Ensure it is not in use or mounted.
- Optionally, wipe filesystem signatures if you want to reuse the space for something else (outside LVM).
- Remove the LV.
Example:
umount /data
lvremove /dev/vgdata/lvdata
LVM will ask for confirmation; you can bypass prompts with -y:
lvremove -y /dev/vgdata/lvdataWarning: LV deletion destroys all data on that logical volume. Recovering data afterward is extremely difficult.
Logical Volume Snapshots (Overview)
Snapshots are a special kind of LV that captures the state of another LV at a point in time using copy-on-write.
Key ideas (from the LV perspective):
- A snapshot is created against an origin LV.
- Only changed blocks are copied to the snapshot’s space.
- Snapshots can be:
- Used for backups (mount the snapshot and back it up).
- Used to quickly roll back changes (depending on type).
Example (classic snapshot):
lvcreate -L 10G -s -n lvsnap /dev/vgdata/lvdata-s→ snapshot of the origin LV-L 10G→ snapshot space (limits how many changes can be stored)
Modern setups typically use thin snapshots via thin pools, which handle space more efficiently. Regardless of type, when working with snapshots as an admin you treat them as additional LVs.
Practical Patterns and Use Cases
Separate LVs for Different Data Types
Common layout:
lvroot→/lvhome→/homelvvar→/varlvdata→ application data
Benefits:
- You can grow or shrink particular areas without affecting others.
- Easier backup and snapshot strategies per LV (e.g. frequent snapshots of
lvdata, fewer oflvroot).
Growing Storage Over Time
Scenario:
- Start with a 500 GB disk as a PV in
vgdata. - Create LVs for
/,/home, and/var. - Later, add another 1 TB disk as a PV to
vgdata. - Extend
lvhomeandlvdatainto the free space, grow their filesystems. - No repartitioning or OS reinstall needed, just logical volume operations and filesystem resizing.
This elasticity is exactly why logical volumes are central to modern Linux storage design.
Common Logical Volume Management Commands (Cheat Sheet)
Create LV:
lvcreate -L 20G -n lvname vgnameList LVs:
lvs # summary
lvdisplay # detailedExtend LV:
lvextend -L +10G /dev/vgname/lvname
resize2fs /dev/vgname/lvname # ext4 exampleReduce LV (with care):
umount /mountpoint
e2fsck -f /dev/vgname/lvname
resize2fs /dev/vgname/lvname 50G
lvreduce -L 50G /dev/vgname/lvname
mount /mountpointMove LV data from one PV to another:
pvmove /dev/sdX /dev/sdYRename LV:
lvrename vgname oldlv newlvRemove LV:
umount /mountpoint
lvremove /dev/vgname/lvnameBy mastering logical volumes—creating, resizing, moving, and snapshotting them—you gain fine-grained, flexible control over storage that traditional fixed partitions cannot offer. The next related topics naturally build on this layer: thin provisioning, snapshots and rollbacks, and integrating logical volumes with RAID and encryption.