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

  1. Create logical volumes — Use lvcreate to allocate extents from a volume group into a named logical volume, specifying size by absolute value or percentage
  2. Format and mount logical volumes — Create a filesystem on the LV device, mount it, and add a persistent mount entry to /etc/fstab
  3. Inspect logical volumes — Use lvs and lvdisplay to list and examine logical volume attributes and usage
  4. Extend and remove logical volumes — Grow an LV and its filesystem online with lvextend, and safely decommission an LV with lvremove

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/LVNAME or /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
Two equivalent device paths

/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
Two size flags: -L (absolute) and -l (extents/%)

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
LVM device paths are stable

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
LVLogical volume name
VGVolume group the LV belongs to
AttrLV attributes: w=writeable, i=inherited, a=active, o=open
LSizeCurrent 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 = number of logical extents

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
+SIZE adds; SIZE sets total

-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?
XFSxfs_growfsMount pointMust be mounted
ext4resize2fsDevice pathCan 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
Swap LV = lvcreate + mkswap + swapon

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
lvremove is permanent — data is not recoverable

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
Snapshot size = capacity for changes

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 sizesudo lvcreate -L 8G -n LVNAME VGNAME
Create LV using all VG free spacesudo lvcreate -l 100%FREE -n LVNAME VGNAME
Format LV with XFSsudo mkfs.xfs /dev/VGNAME/LVNAME
Format LV with ext4sudo mkfs.ext4 /dev/VGNAME/LVNAME
Format LV for swapsudo mkswap /dev/VGNAME/LVNAME
Mount LVsudo mount /dev/VGNAME/LVNAME /mountpoint
List all LVs (summary)sudo lvs
Detailed LV informationsudo lvdisplay /dev/VGNAME/LVNAME
Extend LV (add to size)sudo lvextend -L +5G /dev/VGNAME/LVNAME
Extend LV and grow filesystemsudo lvextend -L +5G -r /dev/VGNAME/LVNAME
Grow XFS filesystemsudo xfs_growfs /mountpoint
Grow ext4 filesystemsudo resize2fs /dev/VGNAME/LVNAME
Remove an LV (after unmounting)sudo lvremove /dev/VGNAME/LVNAME
Create a snapshotsudo 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.

  1. Write the command to create an 8 GiB logical volume named webdata in the volume group appvg.
  2. 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?
  3. Write the /etc/fstab entry to mount /dev/appvg/webdata at /webdata with XFS and default options.
  4. The /webdata filesystem is full. You want to add 4 GiB to the LV and grow the XFS filesystem in one step. Write the command.
  5. What is the difference between xfs_growfs and resize2fs and what argument does each take?
  6. You need to remove the webdata LV. Write the commands in the correct order.

Knowledge Check — Answers

  1. sudo lvcreate -L 8G -n webdata appvg
    1. sudo mkfs.xfs /dev/appvg/webdata — format with XFS
    2. sudo mkdir -p /webdata — create the mount point directory
    3. sudo mount /dev/appvg/webdata /webdata — mount immediately
  2. /dev/appvg/webdata /webdata xfs defaults 0 0
    The five fields are: device, mount point, filesystem type, options, dump, fsck order.
  3. sudo lvextend -L +4G -r /dev/appvg/webdata
    The -r flag runs xfs_growfs automatically after extending the LV.
  4. xfs_growfs grows an XFS filesystem and takes the mount point as its argument (xfs_growfs /webdata). The filesystem must be mounted. resize2fs grows an ext4 filesystem and takes the device path as its argument (resize2fs /dev/appvg/webdata). It can be run mounted or unmounted.
    1. sudo umount /webdata — unmount the filesystem
    2. Remove the fstab entry for /webdata from /etc/fstab
    3. sudo lvremove /dev/appvg/webdata — confirm with y

Key Takeaways

  1. Create an LV with lvcreate -L SIZE -n NAME VGNAME. Capital -L for human-readable sizes (8G); lowercase -l for extents or percentages (100%FREE). The LV device appears at /dev/VGNAME/LVNAME.
  2. 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/fstab with format /dev/VG/LV /mnt xfs defaults 0 0.
  3. Extend with lvextend -L +SIZE -r /dev/VG/LV. The -r flag grows the filesystem automatically. Without -r: XFS needs xfs_growfs /mountpoint; ext4 needs resize2fs /dev/VG/LV.
  4. 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 named labdata. Verify with sudo lvs and sudo lvdisplay /dev/labvg/labdata.
  • Format /dev/labvg/labdata with XFS. Create the directory /labdata and mount the LV. Confirm with df -h /labdata.
  • Add the persistent fstab entry for /labdata. Test it with sudo umount /labdata && sudo mount -a && df -h /labdata to 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 with df -h /labdata.
  • Create a second LV named labswap with 1 GiB. Format it as swap with mkswap, activate it with swapon, and confirm with swapon --show.
  • Clean up: deactivate the swap (swapoff /dev/labvg/labswap), unmount /labdata, remove the fstab entries, and remove both LVs with lvremove. Confirm with sudo lvs that both are gone.
RHCSA Objective

"Create and delete logical volumes." The exam tests the complete workflow: lvcreatemkfsmountfstab → verify. And removal: umount → edit fstab → lvremove.