11.4 Create and Delete Logical Volumes
Key Takeaways
- Create LVs with lvcreate -n NAME -L Size VGNAME (or -l extents/%FREE); list with lvs and lvdisplay; remove with lvremove after closing use.
- Device access paths are /dev/VG/LV and /dev/mapper/VG-LV (hyphen escaping rules); these are the block devices you format and mount.
- Deleting an LV is destructive to its data—unmount, swapoff, or stop services first; confirm the exact LV name before lvremove.
- lvcreate allocates from VG free space (VFree); insufficient free extents is the most common create failure.
- LV existence persists across reboot when the VG activates; mounting still requires filesystem creation and fstab/systemd configuration in related objectives.
11.4 Create and Delete Logical Volumes
Quick Answer: From free space in a VG, create an LV with
lvcreate -n data -L 2G research. Verify withlvs. The block device appears as/dev/research/dataand/dev/mapper/research-data. Delete withlvremove research/dataonly after unmounting or otherwise releasing the device. EX200 grades correct name, size, and VG, then later objectives may add filesystems and mounts.
Official skill and stack position
Under Configure local storage, you must create and delete logical volumes. The LV is the allocatable chunk that usually becomes:
- an XFS/ext4/VFAT filesystem, or
- swap, or
- occasionally a raw device for an application.
Layers again:
Disk → GPT partition → PV → VG → LV → mkfs/mkswap → mount/swapon → fstab
This section owns lvcreate / lvremove / lvs. Do not skip verification of the device node under /dev/mapper.
Create logical volumes: lvcreate
Size in absolute units
sudo lvcreate -n data -L 2G research
sudo lvcreate -n logs -L 512M research
sudo lvcreate --name shared --size 10G research
| Flag | Purpose |
|---|---|
-n / --name | LV name |
-L / --size | Human size (G, M, T) |
| final arg | Volume group name |
Size in extents or free percentage
sudo lvcreate -n bulk -l 100%FREE research
sudo lvcreate -n half -l 50%FREE research
sudo lvcreate -n pevol -l 256 research # 256 extents
100%FREE is popular when the task says “use all remaining space in the VG.”
Verify
sudo lvs
sudo lvs research/data
sudo lvdisplay research/data
ls -l /dev/research/data /dev/mapper/research-data
lsblk
Example lvs:
LV VG Attr LSize
data research -wi-a----- 2.00g
Attr includes open flags when mounted (o appears when LV is in use). Size should match the request within extent rounding.
Device naming: /dev/mapper and /dev/VG/LV
After activation (normal default):
| Path | Notes |
|---|---|
/dev/research/data | Friendly symlink path |
/dev/mapper/research-data | Device-mapper node (VG and LV joined by -) |
If VG or LV names contain hyphens, LVM doubles them in the mapper name. Example: VG my-vg + LV my-lv → /dev/mapper/my--vg-my--lv. Prefer simple names on EX200.
Use these paths for mkfs, mount, mkswap, and blkid—not the underlying /dev/sdb1 PV (unless you intentionally bypass LVM).
sudo mkfs.xfs /dev/research/data
# or
sudo mkfs.xfs /dev/mapper/research-data
(Filesystem creation is the next chapter’s deep focus; shown here so you know which device to format.)
Delete logical volumes: lvremove
sudo umount /dev/research/data # if mounted
sudo swapoff /dev/research/swaplv # if swap
sudo lvremove research/data
# confirm prompt: y
sudo lvremove -y research/old # non-interactive when you are sure
Syntax accepts vgname/lvname:
sudo lvremove research/data
Destructive: all filesystem data on that LV is gone when removed (absent advanced recovery). Triple-check name with lvs before -y.
If lvremove says the LV is open:
findmnt /dev/research/data
sudo lsof /dev/research/data
sudo umount -R /mount/point
sudo lvremove research/data
Free space failures and partial sizes
sudo vgs research
# VFree 1.00g
sudo lvcreate -n big -L 50G research
# Insufficient free space
Remedies:
- Smaller
-L/ use-l 100%FREE vgextendwith another PV firstlvremoveunused LVs to free space
sudo vgextend research /dev/sdc1
sudo lvcreate -n big -L 50G research
Root VG caution (non-destructive mindset)
Production-like exam systems already have LVs such as root and swap on VG rhel/rl:
sudo lvs
lsblk /
- Do not
lvremoveroot or swap LVs. - Creating an additional LV on the system VG is OK when free space exists and the task says so.
- Prefer a dedicated VG when the task gives a spare disk and a new VG name—keeps mistakes off
/.
Thin pools, stripes, mirrors (awareness only)
# Advanced forms exist:
# lvcreate --type raid1 ...
# lvcreate -T ... thin pool
EX200 study points emphasize standard linear LVs. Master -n, -L/-l, lvremove, and lvs before exploring RAID/thin options. Only use advanced types if a task explicitly requires them.
End-to-end exam scenarios
Scenario A — Create named LV with fixed size
Task: In VG research, create LV data of size 2G.
sudo vgs research
sudo lvcreate -n data -L 2G research
sudo lvs research/data
ls -l /dev/mapper/research-data
Scenario B — Consume remaining free space
Task: Create LV bulk using all free space in research.
sudo lvcreate -n bulk -l 100%FREE research
sudo lvs
sudo vgs # VFree should be ~0
Scenario C — Delete an LV
Task: Remove LV olddata from VG research.
findmnt | grep olddata || true
sudo umount /dev/research/olddata 2>/dev/null || true
sudo lvremove -y research/olddata
sudo lvs research
Scenario D — Full stack preview (know where LV skill ends)
Many multi-step items chain:
sudo parted /dev/sdb --script mklabel gpt mkpart primary 1MiB 100%
sudo parted /dev/sdb set 1 lvm on
sudo pvcreate /dev/sdb1
sudo vgcreate research /dev/sdb1
sudo lvcreate -n data -L 2G research
# later objectives:
# mkfs.xfs /dev/research/data
# mount + /etc/fstab by UUID
If the item only says create the LV, stop after lvs succeeds. If it says create and mount XFS, continue—but still use the LV device, not the PV.
Persistence, activation, and reboot
- LV metadata lives in the VG on the PVs → survives reboot.
- On boot, LVM activates VGs/LVs;
/dev/mapper/*nodes reappear. - Mounts do not automatically return without
fstabor mount units—separate objective (mount by UUID/label). - After reboot in practice:
sudo lvs,ls /dev/mapper, then check mounts if configured.
sudo lvs -a
sudo dmsetup ls
Verification checklist for graders (and you)
- Name exact:
lvsshows LV and VG. - Size correct (extent rounding within reason).
- Device node exists:
/dev/VG/LVor/dev/mapper/VG-LV. - After delete: LV absent from
lvs; space returned tovgsVFree. - Did not remove or shrink critical system LVs unless tasked.
Common traps
lvcreatewith PV path as last argument — last argument is VG name, not/dev/sdb1.- Formatting the PV (
mkfs /dev/sdb1) instead of the LV — destroys LVM structure. - Wrong mapper spelling — remember
vg-lvpattern. lvremovewhile mounted — unmount first.- Assuming create mounts the volume — it only creates a block device.
- Using
rm /dev/mapper/...— never; uselvremove. - 100%FREE twice — second LV fails; free is already gone.
- Ignoring exact case/spelling of LV names in the exam text.
How this links to “add storage non-destructively”
Later objectives emphasize adding space without destroying existing data: vgextend + lvextend + grow filesystem. This section’s lvcreate builds new volumes; lvremove destroys them. Do not use lvremove as a shortcut to “fix” a filesystem problem on a volume that should have been grown or remounted.
Section checkpoint
You should allocate LVs with lvcreate using -L or -l (including %FREE), verify with lvs and /dev/mapper paths, remove LVs safely with lvremove after releasing mounts/swap, respect free space and system LVs, and leave persistent LVM metadata ready for reboot and for filesystem objectives that follow. Together with GPT partitions, PVs, and VGs, this completes the core LVM construction path for EX200 local storage.
Which command creates a 2 GiB logical volume named data in volume group research?
After creating LV data in VG research, which path is a correct device-mapper style block device for mkfs?
lvcreate fails with insufficient free space. Which action directly addresses the LVM free-space problem?
Before lvremove research/olddata, what must you ensure?