RED HAT ENTERPRISE LINUX
Logical Volumes:
Create and Delete
Create and delete logical volumes
CIS126RH | RHEL System Administration 1
Mesa Community College
A logical volume (LV) is the end product of the LVM stack — the device on which
filesystems, swap, and databases actually live. Unlike a fixed-size partition,
an LV can be created at any size up to the volume group's free space, extended
online, and moved between physical volumes without downtime. This module covers
lvcreate, the LV device path, formatting and mounting, lvs
and lvdisplay for inspection, extending LVs, and safe removal with
lvremove. These skills are tested on the RHCSA exam.
Learning Objectives
-
Create logical volumes —
Use
lvcreateto allocate extents from a volume group into a named logical volume, specifying size by absolute value or percentage -
Format and mount logical volumes —
Create a filesystem on the LV device, mount it, and add a persistent
mount entry to
/etc/fstab -
Inspect logical volumes —
Use
lvsandlvdisplayto list and examine logical volume attributes and usage -
Extend and remove logical volumes —
Grow an LV and its filesystem online with
lvextend, and safely decommission an LV withlvremove
What is a Logical Volume?
A logical volume is a virtual block device carved from the free physical extents of a volume group. It is exposed to the OS as a block device and can be used exactly like a partition.
- An LV has a name and belongs to one volume group
- Its size is specified in megabytes, gigabytes, or as a percentage of VG free space
- Device paths:
/dev/VGNAME/LVNAMEor/dev/mapper/VGNAME-LVNAME - Filesystems are created on the LV device:
mkfs.xfs /dev/datavg/data - An LV can be extended online — the filesystem can grow while mounted
- LVs can span multiple physical volumes in the same VG
/dev/datavg/data and /dev/mapper/datavg-data refer to
the same device. The /dev/VGNAME/LVNAME path is a symlink to the
device mapper node. Both work identically in mkfs, mount,
and fstab. Hyphens in VG or LV names become double-hyphens in the
mapper path.
Creating a Logical Volume: lvcreate
lvcreate allocates extents from a volume group and creates a
named logical volume device.
# Create an 8 GiB LV named "data" in volume group "datavg"
$ sudo lvcreate -L 8G -n data datavg
Logical volume "data" created.
# Create a 2 GiB LV named "swap" in datavg
$ sudo lvcreate -L 2G -n swap datavg
# Create an LV using all remaining free space in the VG
$ sudo lvcreate -l 100%FREE -n logs datavg
# Create an LV using 50% of VG free space
$ sudo lvcreate -l 50%FREE -n archive datavg
# Verify the LV was created
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta%
data datavg -wi-a----- 8.00g
Capital -L specifies size in MB, GB, or TB: -L 8G.
Lowercase -l specifies extents or percentage: -l 100%FREE.
-n names the LV. The VG name is the last argument.
Formatting and Mounting the Logical Volume
After creating an LV, it is an empty block device. It must be formatted with a filesystem and mounted before it can store data.
# Format with XFS (the RHEL 9 default filesystem)
$ sudo mkfs.xfs /dev/datavg/data
meta-data=/dev/datavg/data isize=512 agcount=4, agsize=524288 blks
...
log =internal log bsize=4096 blocks=2560, version=2
# Format with ext4
$ sudo mkfs.ext4 /dev/datavg/data
# Create the mount point directory
$ sudo mkdir -p /data
# Mount immediately
$ sudo mount /dev/datavg/data /data
# Add to /etc/fstab for persistent mounting at boot
$ sudo vim /etc/fstab
# Add this line:
/dev/datavg/data /data xfs defaults 0 0
# Test the fstab entry
$ sudo mount -a # mount all entries in fstab not yet mounted
$ df -h /data # confirm it is mounted
Using UUID in fstab
While the /dev/VGNAME/LVNAME path is stable for LVM volumes, some
administrators prefer to use the filesystem UUID for consistency.
# Get the UUID of the filesystem on the LV
$ sudo blkid /dev/datavg/data
/dev/datavg/data: UUID="abc123-de45-fg67..." TYPE="xfs"
# Alternative: lsblk -f shows UUIDs in tree format
$ lsblk -f /dev/datavg/data
NAME FSTYPE UUID MOUNTPOINTS
datavg-data xfs abc123-de45-fg67...
# fstab entry using UUID
UUID=abc123-de45-fg67... /data xfs defaults 0 0
# fstab entry using device path (simpler, equally valid for LVM)
/dev/datavg/data /data xfs defaults 0 0
Unlike physical disk device names (/dev/sda1 can change between reboots
if disks are added or removed), LVM device paths (/dev/datavg/data) are
stable because LVM identifies PVs by UUID internally. Using the LVM path in fstab
is safe and more readable than a UUID string.
Inspecting Logical Volumes: lvs
lvs provides a concise one-line-per-LV listing —
the standard command to check LV names, sizes, and status.
# Summary listing of all logical volumes
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- <17.00g
swap rhel -wi-ao---- 2.00g
data datavg -wi-a----- 8.00g
logs datavg -wi-a----- 9.99g
# Show a specific LV
$ sudo lvs datavg/data
# Add the device path column
$ sudo lvs -o +lv_path
| Column | Meaning |
|---|---|
LV | Logical volume name |
VG | Volume group the LV belongs to |
Attr | LV attributes: w=writeable, i=inherited, a=active, o=open |
LSize | Current size of the logical volume |
Detailed LV Inspection: lvdisplay
lvdisplay shows the complete details of a logical volume —
the verbose counterpart to lvs.
$ sudo lvdisplay /dev/datavg/data
--- Logical volume ---
LV Path /dev/datavg/data
LV Name data
VG Name datavg
LV UUID Abc123-DE45-fg67-HI89-jk01-LM23-NO45pq
LV Write Access read/write
LV Creation host, time servera, 2026-05-25 10:00:00 -0700
LV Status available
# open 1
LV Size 8.00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
Current LE is the count of logical extents allocated to this LV.
Multiplied by the PE size: 2048 × 4 MiB = 8 GiB. This confirms the LV size
in terms of the underlying extent structure.
Extending a Logical Volume: lvextend
lvextend grows an LV by allocating additional extents from the VG.
The filesystem must be separately grown to use the new space.
# Extend by adding 5 GiB to the current size
$ sudo lvextend -L +5G /dev/datavg/data
Size of logical volume datavg/data changed from 8.00 GiB to 13.00 GiB.
Logical volume datavg/data successfully resized.
# Extend to a specific total size
$ sudo lvextend -L 20G /dev/datavg/data
# Extend to use all remaining free space in the VG
$ sudo lvextend -l +100%FREE /dev/datavg/data
# Extend AND grow the XFS filesystem in one command
$ sudo lvextend -L +5G -r /dev/datavg/data
# -r resizes the filesystem automatically after extending the LV
fsadm: Trying to resize xfs filesystem on /dev/datavg/data...
xfs_growfs: /data is not a mount point
-L +5G adds 5 GiB to the current size.
-L 20G sets the total size to 20 GiB (fails if current size > 20G).
-l +100%FREE uses all remaining VG free space.
Growing the Filesystem After lvextend
When lvextend -r is not used, the filesystem must be manually
grown to occupy the new LV space. The command depends on the filesystem type.
# Grow an XFS filesystem (must be mounted)
$ sudo xfs_growfs /data # use the MOUNT POINT, not device path
meta-data=/dev/mapper/datavg-data isize=512 agcount=4 ...
data = bsize=4096 blocks=2097152, ...
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal bsize=4096 blocks=2560, version=2
realtime =none
data blocks changed from 2097152 to 3407872
# Grow an ext4 filesystem (can be mounted or unmounted)
$ sudo resize2fs /dev/datavg/data # use the device path
# The -r flag on lvextend does both steps automatically
$ sudo lvextend -L +5G -r /dev/datavg/data
| Filesystem | Grow command | Target argument | Mounted? |
|---|---|---|---|
| XFS | xfs_growfs | Mount point | Must be mounted |
| ext4 | resize2fs | Device path | Can be mounted or unmounted |
Creating a Swap Logical Volume
Swap space can be created as a logical volume — making it easy to resize swap without rebooting.
# Create a 2 GiB swap LV
$ sudo lvcreate -L 2G -n swap datavg
Logical volume "swap" created.
# Format as swap space
$ sudo mkswap /dev/datavg/swap
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
# Activate the swap immediately
$ sudo swapon /dev/datavg/swap
# Confirm swap is active
$ swapon --show
NAME TYPE SIZE USED PRIO
/dev/datavg/swap partition 2G 0B -2
# Add to /etc/fstab for persistence
/dev/datavg/swap swap swap defaults 0 0
The three-command sequence for swap is identical to the three-command sequence for a filesystem volume (lvcreate + mkfs + mount), just with swap-specific commands.
Removing a Logical Volume: lvremove
lvremove permanently deletes a logical volume and returns its
extents to the volume group's free pool. Data is not recoverable.
# Step 1: Unmount the filesystem
$ sudo umount /data
# Step 2: Remove the fstab entry (if present)
$ sudo vim /etc/fstab
# Delete or comment out the /data entry
# Step 3: Remove the logical volume
$ sudo lvremove /dev/datavg/data
Do you really want to remove active logical volume datavg/data? [y/n]: y
Logical volume "data" successfully removed
# Alternatively, skip the confirmation
$ sudo lvremove -f /dev/datavg/data
# Verify the LV is gone and space is returned to the VG
$ sudo lvs
$ sudo vgs datavg # VFree should increase
Once confirmed, the LV and all its data are permanently gone. The extents are returned to the VG free pool and can be reused. Always unmount and remove the fstab entry before running lvremove.
LVM Snapshots
An LVM snapshot creates an instant point-in-time copy of a logical volume. Snapshots are used for consistent backups of live filesystems.
# Create a 1 GiB snapshot of the data LV
$ sudo lvcreate -L 1G -s -n data-snap /dev/datavg/data
Logical volume "data-snap" created.
# Mount the snapshot read-only for backup
$ sudo mount -o ro /dev/datavg/data-snap /mnt/snap
# Back up from the snapshot
$ sudo tar -czvf /backup/data.tar.gz /mnt/snap
# Remove the snapshot when done
$ sudo umount /mnt/snap
$ sudo lvremove -f /dev/datavg/data-snap
The snapshot LV stores only the original blocks that have been changed since the snapshot was created. If the source LV changes rapidly, a small snapshot can fill up and become invalid. For backups, size the snapshot at 15–20% of the source LV size or larger.
Logical Volume Commands Quick Reference
| Task | Command |
|---|---|
| Create an LV of specific size | sudo lvcreate -L 8G -n LVNAME VGNAME |
| Create LV using all VG free space | sudo lvcreate -l 100%FREE -n LVNAME VGNAME |
| Format LV with XFS | sudo mkfs.xfs /dev/VGNAME/LVNAME |
| Format LV with ext4 | sudo mkfs.ext4 /dev/VGNAME/LVNAME |
| Format LV for swap | sudo mkswap /dev/VGNAME/LVNAME |
| Mount LV | sudo mount /dev/VGNAME/LVNAME /mountpoint |
| List all LVs (summary) | sudo lvs |
| Detailed LV information | sudo lvdisplay /dev/VGNAME/LVNAME |
| Extend LV (add to size) | sudo lvextend -L +5G /dev/VGNAME/LVNAME |
| Extend LV and grow filesystem | sudo lvextend -L +5G -r /dev/VGNAME/LVNAME |
| Grow XFS filesystem | sudo xfs_growfs /mountpoint |
| Grow ext4 filesystem | sudo resize2fs /dev/VGNAME/LVNAME |
| Remove an LV (after unmounting) | sudo lvremove /dev/VGNAME/LVNAME |
| Create a snapshot | sudo lvcreate -L 1G -s -n SNAPNAME /dev/VGNAME/LVNAME |
Complete LVM Stack: End-to-End
The full sequence from unpartitioned disk to persistently mounted filesystem.
# 1. Partition and initialise physical volume
$ sudo parted --script /dev/sdb mklabel gpt mkpart primary 1MiB 100%
$ sudo partprobe /dev/sdb
$ sudo pvcreate /dev/sdb1
# 2. Create volume group
$ sudo vgcreate datavg /dev/sdb1
# 3. Create logical volume
$ sudo lvcreate -L 8G -n data datavg
# 4. Create filesystem
$ sudo mkfs.xfs /dev/datavg/data
# 5. Mount and add to fstab
$ sudo mkdir -p /data
$ sudo mount /dev/datavg/data /data
$ echo "/dev/datavg/data /data xfs defaults 0 0" | sudo tee -a /etc/fstab
# 6. Verify
$ df -h /data
$ sudo lvs
$ sudo vgs
Common Mistakes
| Mistake | What goes wrong | Correct approach |
|---|---|---|
Confusing -L (size) and -l (extents/%) |
lvcreate -l 8G fails — lowercase -l expects an integer or percentage |
Capital -L 8G for human-readable sizes; lowercase -l 100%FREE for extents/percent |
| Extending LV but forgetting to grow the filesystem | The LV is larger but the filesystem still shows the old size in df |
Use lvextend -r or manually run xfs_growfs or resize2fs |
| Using device path for xfs_growfs instead of mount point | xfs_growfs /dev/datavg/data — fails with "not a mount point" |
xfs_growfs /data — xfs_growfs requires the mount point |
| Not removing fstab entry before lvremove | Next reboot fails trying to mount a device that no longer exists | Always edit fstab to remove the mount entry before running lvremove |
| Running lvcreate requesting more space than the VG has free | lvcreate fails: "Volume group datavg has insufficient free space" | Check available space with vgs first; use -l 100%FREE or a smaller size |
Forgetting -n to name the LV |
LV is created with an automatic name like lvol0 — hard to identify |
Always use -n LVNAME with a meaningful name |
Knowledge Check
Answer these before moving to the next slide.
- Write the command to create an 8 GiB logical volume named
webdatain the volume groupappvg. - After creating the LV, what are the next three commands needed to format it
with XFS, create a mount point at
/webdata, and mount it? - Write the
/etc/fstabentry to mount/dev/appvg/webdataat/webdatawith XFS and default options. - The
/webdatafilesystem is full. You want to add 4 GiB to the LV and grow the XFS filesystem in one step. Write the command. - What is the difference between
xfs_growfsandresize2fsand what argument does each take? - You need to remove the
webdataLV. Write the commands in the correct order.
Knowledge Check — Answers
sudo lvcreate -L 8G -n webdata appvg-
sudo mkfs.xfs /dev/appvg/webdata— format with XFSsudo mkdir -p /webdata— create the mount point directorysudo mount /dev/appvg/webdata /webdata— mount immediately
/dev/appvg/webdata /webdata xfs defaults 0 0
The five fields are: device, mount point, filesystem type, options, dump, fsck order.sudo lvextend -L +4G -r /dev/appvg/webdata
The-rflag runsxfs_growfsautomatically after extending the LV.xfs_growfsgrows an XFS filesystem and takes the mount point as its argument (xfs_growfs /webdata). The filesystem must be mounted.resize2fsgrows an ext4 filesystem and takes the device path as its argument (resize2fs /dev/appvg/webdata). It can be run mounted or unmounted.-
sudo umount /webdata— unmount the filesystem- Remove the fstab entry for
/webdatafrom/etc/fstab sudo lvremove /dev/appvg/webdata— confirm with y
Key Takeaways
-
Create an LV with
lvcreate -L SIZE -n NAME VGNAME. Capital-Lfor human-readable sizes (8G); lowercase-lfor extents or percentages (100%FREE). The LV device appears at/dev/VGNAME/LVNAME. -
Format → mount → fstab: three steps to a usable filesystem.
mkfs.xfs /dev/VG/LV,mkdir /mountpoint,mount /dev/VG/LV /mountpoint, then add to/etc/fstabwith format/dev/VG/LV /mnt xfs defaults 0 0. -
Extend with
lvextend -L +SIZE -r /dev/VG/LV. The-rflag grows the filesystem automatically. Without-r: XFS needsxfs_growfs /mountpoint; ext4 needsresize2fs /dev/VG/LV. - Remove safely: umount → edit fstab → lvremove. Skipping the fstab edit causes a boot failure when the removed LV's mount entry is processed. The extents are returned to the VG's free pool.
Graded Lab
- Using the volume group created in the previous lab (
labvg), create a 3 GiB logical volume namedlabdata. Verify withsudo lvsandsudo lvdisplay /dev/labvg/labdata. - Format
/dev/labvg/labdatawith XFS. Create the directory/labdataand mount the LV. Confirm withdf -h /labdata. - Add the persistent fstab entry for
/labdata. Test it withsudo umount /labdata && sudo mount -a && df -h /labdatato confirm the fstab entry is correct. - Write a 100 MB test file:
dd if=/dev/zero of=/labdata/testfile bs=1M count=100. Then extend the LV by 2 GiB and grow the filesystem in one command:sudo lvextend -L +2G -r /dev/labvg/labdata. Confirm the new size withdf -h /labdata. - Create a second LV named
labswapwith 1 GiB. Format it as swap withmkswap, activate it withswapon, and confirm withswapon --show. - Clean up: deactivate the swap (
swapoff /dev/labvg/labswap), unmount/labdata, remove the fstab entries, and remove both LVs withlvremove. Confirm withsudo lvsthat both are gone.
"Create and delete logical volumes."
The exam tests the complete workflow: lvcreate → mkfs
→ mount → fstab → verify. And removal:
umount → edit fstab → lvremove.