Managing Logical Storage
Theory Questions
1. Identify standard components in an LVM setup.
- Command(s):
pvs # Physical Volumes
vgs # Volume Groups
lvs # Logical Volumes
-
Why: Logical Volume Manager (LVM) abstracts physical storage into three core layers:
-
Physical Volume (PV): A raw block device or partition (e.g.,
/dev/sdb1) initialized for LVM. -
Volume Group (VG): A storage pool constructed by combining one or more PVs, allocated in fixed-size chunks called Physical Extents (PEs, default 4 MiB).
-
Logical Volume (LV): A block device created out of PEs from a VG, formatted with a file system and mounted for use.
-
Gotchas: Confusing PVs with VGs during creation. You must create the PV first (
pvcreate), add it to a VG (vgcreate), and then allocate an LV (lvcreate). -
Verify:
pvdisplay && vgdisplay && lvdisplay
2. Identify features that are and are not part of LVM.
- Command(s):
lvcreate --help
-
Why:
-
Part of LVM: Dynamic online volume resizing (extending/shrinking), volume snapshotting, thin provisioning, RAID/mirroring, and spanning across multiple physical disks.
-
NOT Part of LVM: File system creation (handled separately by
mkfs), direct physical hardware RAID controller configuration, or network file sharing (NFS/Samba). -
Gotchas: Assuming
lvextendautomatically resizes your file system. Without the-r(--resizefs) flag, only the underlying block device is grown, not the file system. -
Verify:
lvs -o name,attr,size
3. Mark a GPT partition with the LVM partition type.
- Command(s):
# Using fdisk interactively:
fdisk /dev/sdb
# Enter 't', select partition number, set type to 'Linux LVM' (Type code 31 or 8E00/8E)
# Enter 'w' to save.
# Using parted non-interactively:
parted -s /dev/sdb set 1 lvm on
- Why: Flagging a partition as
Linux LVMsets the partition type GUID on GPT disks (E6D66786-700A-45DB-B34B-4739E273C0D7), allowing system utilities and udev to recognize the partition’s intended purpose. - Gotchas:
pvcreatecan format a partition regardless of partition type, but failing to set the LVM flag on an exam partition may lose marks during automated grading scripts. - Verify:
fdisk -l /dev/sdb | grep -i "LVM"
4. Create a logical volume using a percentage of available space.
- Command(s):
# Use 50% of the remaining free space in the VG:
lvcreate -l 50%FREE -n lv_data vg_name
# Use 100% of the total capacity of the VG:
lvcreate -l 100%VG -n lv_full vg_name
- Why: Lowercase
-lspecifies Extents (either absolute count or relative percentage strings like100%FREE), whereas uppercase-Laccepts explicit size values (e.g.,-L 500M). - Gotchas: Mixing up
-l(extents/percentage) and-L(bytes/megabytes). Executinglvcreate -L 100%FREEwill throw a syntax error. - Verify:
lvs vg_name/lv_data
5. Show an overview of available physical volumes.
- Command(s):
pvs
# Or for detailed output:
pvscan
- Why:
pvsprovides a concise table showing physical device names, associated volume group names, total format size, and unallocated free space. - Gotchas: Forgetting to run
partprobeorudevadm settleafter creating a new partition before runningpvcreateorpvs. - Verify:
pvs -o pv_name,vg_name,pv_size,pv_free
6. Evaluate statements about resizing LVM logical volumes.
- Command(s):
lvextend -r -L +250M /dev/vg_name/lv_name
-
Statements Evaluation:
-
True: Logical volumes formatted with Ext4 can be extended and shrunk.
-
True: Logical volumes formatted with XFS can be extended online.
-
False: XFS file systems can be shrunk. (Correction: XFS does not support shrinking under any circumstances.)
-
Why: XFS architecture only supports online growth (
xfs_growfs). Attempting to shrink an XFS logical volume will corrupt the file system. -
Gotchas: Trying to shrink an XFS LV on the RHCSA exam. If a task asks for volume reduction, the file system will always be Ext4.
-
Verify:
df -hT /dev/vg_name/lv_name
7. Remove a physical volume from a volume group.
- Command(s):
# Step 1: Evacuate data from the PV to other PVs in the VG
pvmove /dev/sdb1
# Step 2: Remove the PV from the VG
vgreduce vg_name /dev/sdb1
# Step 3: Clear the LVM metadata from the disk (Optional cleanup)
pvremove /dev/sdb1
- Why:
pvmoveensures allocated extents are migrated to remaining devices beforevgreducedetaches the drive, preventing data loss. - Gotchas: Running
vgreduceorpvremovewhile active extents are still assigned to/dev/sdb1will destroy volume data. - Verify:
vgs vg_name
pvs /dev/sdb1
8. Fix a mismatch between an extended logical volume and its XFS file system.
- Command(s):
xfs_growfs /mountpoint
- Why: If an LV was extended using
lvextend -L +500M /dev/vg_name/lv_namewithout the-rflag, the underlying block device expanded, but the XFS file system table remains at its original size. - Gotchas:
xfs_growfsrequires the mount point path (e.g.,/groups), NOT the device path/dev/vg_name/lv_name. Passing the device node path will result in an error. (In contrast, Ext4’sresize2fsrequires the device path). - Verify:
df -h /mountpoint
9. Identify storage used by Stratis for metadata.
- Command(s):
stratis pool list
- Why: Stratis allocates an internal thin-provisioning layer managed by
devicemapper. It reserves a small portion of the block devices added to a pool (typically ~1 GiB per pool) for metadata layout, headers, and thin-pool management structures. - Gotchas: Expecting 100% of a raw block device size to be available for Stratis file system allocation.
- Verify:
stratis pool list
(Compare Total Physical vs Total Allocated / Free)
10. Mount a Stratis file system through /etc/fstab.
- Command(s) / Entry:
UUID=abcd1234-5678-90ab-cdef-1234567890ab /stratis-mount xfs defaults,x-systemd.requires=stratisd.service 0 0
- Why: Stratis management relies on the
stratisddaemon. The mount optionx-systemd.requires=stratisd.serviceforces systemd to defer mounting the file system at boot until thestratisddaemon has fully initialized and activated the underlying pools. - Gotchas: Omitting
x-systemd.requires=stratisd.servicein/etc/fstab. Without this option, the system will attempt to mount the device beforestratisdstarts, causing system boot to hang or drop into emergency shell. - Verify:
umount /stratis-mount 2>/dev/null
mount -a
11. Identify the GPT partition type for LVM usage.
- Command(s):
# Partition type code in fdisk: 31 (Linux LVM)
# Partition type code in gdisk: 8E00
# GUID: E6D66786-700A-45DB-B34B-4739E273C0D7
- Why: Standardizes the block device identification for LVM tools across Linux installations.
- Gotchas: Using standard
Linux filesystem(Type 20 / 8300) instead ofLinux LVM. - Verify:
fdisk -l /dev/sdb
12. Create a volume group with a specific physical extent size.
- Command(s):
vgcreate -s 16M vg_custom /dev/sdb1
- Why: The
-soption specifies the Physical Extent (PE) size (e.g.,8M,16M,32M). Default PE size is 4 MiB. - Gotchas: Specifying PE sizes that are not powers of 2, or changing PE size after the VG is already created with active volumes.
- Verify:
vgdisplay vg_custom | grep "PE Size"
13. Show a summary of physical volumes and their volume groups.
- Command(s):
pvs -o pv_name,vg_name,pv_size,pv_free
- Why: Custom column ordering with
pvs -odisplays precise layout details without clutter. - Gotchas: Forgetting that
pvswithout flags provides a concise default summary. - Verify:
pvs
14. Add an entire hard disk to an existing volume group.
- Command(s):
pvcreate /dev/sdc
vgextend vg_name /dev/sdc
- Why: LVM accepts raw unpartitioned block devices (e.g.,
/dev/sdc) directly as Physical Volumes, expanding the total pool size ofvg_name. - Gotchas: Running
vgcreateinstead ofvgextend.vgcreatewill fail if the VG already exists. - Verify:
vgs vg_name
15. Create a logical volume of a specific size.
- Command(s):
lvcreate -L 500M -n lv_group vg_name
- Why:
-L 500Mexplicitly defines a 500 Megabyte volume size, and-nsets the LV unit name. - Gotchas: Using lower case
-lwith explicit unit suffixes (e.g.,-l 500Mfails). Use-Lfor unit sizes (M, G, T). - Verify:
lvs /dev/vg_name/lv_group
16. Extend a logical volume by a specific amount.
- Command(s):
lvextend -r -L +250M /dev/vg_name/lv_group
- Why: The
+sign indicates an incremental addition of 250 MB (rather than setting total size to 250 MB).-rresizes the underlying file system automatically in a single command. - Gotchas: Omitting the
+sign. Runninglvextend -L 250Mon a 500M volume will fail or attempt to set absolute size to 250M. - Verify:
lvs /dev/vg_name/lv_group
df -h /groups
17. Remove a physical volume from a volume group (two-command procedure).
- Command(s):
pvmove /dev/sdb1
vgreduce vg_name /dev/sdb1
- Why: First moves physical extents off
/dev/sdb1, then safely removes the empty PV from the VG. - Gotchas: Executing
vgreducebeforepvmovefinishes when space on other PVs is constrained. - Verify:
vgs vg_name
18. Mount a Stratis volume via /etc/fstab.
- Command(s) / Entry:
UUID=12345678-1234-1234-1234-123456789abc /stratis xfs defaults,x-systemd.requires=stratisd.service 0 0
- Why: Leverages UUID lookup and systemd service ordering dependencies to ensure mount points activate after system boot completes daemon initialization.
- Gotchas: Attempting to format Stratis volumes with Ext4 or using
/dev/stratis/...device paths instead of persistentUUID=. - Verify:
findmnt --verify
19. Create a Stratis pool from a block device.
- Command(s):
systemctl enable --now stratisd
stratis pool create pool_name /dev/sdb
- Why: Initializes a Stratis management pool named
pool_nameusing block storage on/dev/sdb. - Gotchas: Running
stratisCLI commands whenstratisd.serviceis not running. Always ensurestratisdis active first. - Verify:
stratis pool list
20. Format a Stratis volume with Ext4.
- Command(s): Not Possible. Stratis volumes automatically format as XFS upon creation using:
stratis filesystem create pool_name fs_name
- Why: Stratis is an opinionated storage engine built specifically around XFS and thin-provisioning devicemapper architecture. It does not support Ext4.
- Gotchas: Trying to run
mkfs.ext4 /dev/stratis/...manually will destroy Stratis thin-provisioning headers and corrupt the pool. - Verify:
stratis filesystem list
Lab Tasks
LVM Practice
Task: Create a 500 MB logical volume named lvgroup. Format it with XFS and mount it persistently on /groups. Reboot and verify. Then add 250 MB to lvgroup and verify automatic file system resizing.
- Command(s):
# Step 1: Create physical volume and volume group (assuming /dev/sdb1 is available)
pvcreate /dev/sdb1
vgcreate vg_data /dev/sdb1
# Step 2: Create 500 MB Logical Volume named lvgroup
lvcreate -L 500M -n lvgroup vg_data
# Step 3: Format with XFS
mkfs.xfs /dev/vg_data/lvgroup
# Step 4: Create mount point and configure persistent entry in /etc/fstab
mkdir -p /groups
LV_UUID=$(blkid -s UUID -o value /dev/vg_data/lvgroup)
echo "UUID=${LV_UUID} /groups xfs defaults 0 0" >> /etc/fstab
# Step 5: Test mount and verify pre-reboot state
mount -a
df -h /groups
# Step 6: Reboot to verify persistence
reboot
# Step 7: (Post-Reboot) Extend the LV by 250 MB and resize file system automatically
lvextend -r -L +250M /dev/vg_data/lvgroup
-
Why:
-
lvcreate -L 500M -n lvgroup: Creates exact 500 MB block device. -
mkfs.xfs: Builds XFS file system structures. -
UUID=: Guarantees persistent mounting post-reboot regardless of block node identifier changes. -
lvextend -r -L +250M: Increases LV capacity by +250 MB (total 750 MB) and executesxfs_growfsautomatically via-r. -
Gotchas:
-
Forgetting the
-roption duringlvextend. If omitted,lvswill show 750 MB, butdf -h /groupswill still display 500 MB untilxfs_growfs /groupsis manually executed. -
Specifying
-L 250Minstead of-L +250Mwill attempt to set absolute size to 250M (which fails because LV is already 500M). -
Verify:
# Check persistent mount after reboot:
findmnt /groups
# Check total extended capacity post-resize:
df -h /groups
lvs /dev/vg_data/lvgroup
(Output of df -h /groups should show approximately ~750 MB capacity)
Stratis Practice
Task: Create a Stratis pool of 5 GiB. Create two Stratis file systems within it and ensure they are automatically mounted. Add an additional block device to the Stratis pool and verify pool size extension. Ensure the new Stratis device is automatically mounted on /stratis after reboot.
- Command(s):
# Step 1: Install and start Stratis service components
dnf install -y stratisd stratis-cli
systemctl enable --now stratisd
# Step 2: Create a 5 GiB Stratis pool (using /dev/sdc, assuming 5 GiB device)
stratis pool create stratis-pool /dev/sdc
# Step 3: Create two Stratis file systems
stratis filesystem create stratis-pool fs1
stratis filesystem create stratis-pool fs2
# Step 4: Create mount points and gather UUIDs
mkdir -p /stratis /stratis-fs2
FS1_UUID=$(stratis filesystem list | grep fs1 | awk '{print $2}')
FS2_UUID=$(stratis filesystem list | grep fs2 | awk '{print $2}')
# Step 5: Add persistent fstab entries with systemd dependency flag
echo "UUID=${FS1_UUID} /stratis xfs defaults,x-systemd.requires=stratisd.service 0 0" >> /etc/fstab
echo "UUID=${FS2_UUID} /stratis-fs2 xfs defaults,x-systemd.requires=stratisd.service 0 0" >> /etc/fstab
# Step 6: Test mount
mount -a
# Step 7: Add additional block device (/dev/sdd) to extend the pool size
stratis pool add-data stratis-pool /dev/sdd
# Step 8: Reboot and verify persistent mounts
reboot
-
Why:
-
stratisd: Daemon required to manage pools, thin provisioning, and file system devices. -
stratis pool add-data: Dynamically expands pool capacity by adding secondary block devices. -
x-systemd.requires=stratisd.service: Mandatory mount option in/etc/fstabensuring systemd waits forstratisdto initialize before attempting to mount Stratis volumes at boot time. -
Gotchas:
-
Omitting
x-systemd.requires=stratisd.servicein/etc/fstab. The system will hang during boot or drop to emergency mode becausestratisdstarts after early boot mount targets. -
Using standard device paths (
/dev/stratis/...) instead ofUUID=in/etc/fstab. -
Verify:
# Verify pool extension:
stratis pool list
# Verify persistent mounts post-reboot:
findmnt /stratis
findmnt /stratis-fs2
(Output should show stratis-pool with total combined capacity of /dev/sdc + /dev/sdd, and both /stratis and /stratis-fs2 mounted persistently)