Founding prices until 15 December: 30% off Pro, locked for life. See pricing

RHCSA storage practice: partitions, LVM, swap and fstab on a VM

Partition a spare disk, build and grow LVM volumes, add swap and mount everything by UUID or label so it survives a reboot. Commands in exam order.

LinuxUpdated 27 November 20262 min read

Storage tasks are where people lose the most points on the RHCSA, because a mistake shows up only at the reboot: the machine stops in emergency mode and every other task fails with it. Practise on a VM with two spare 5 GB disks (how to build one); BrokenCluster's lab machines have no disks to partition. Device names below are /dev/sdb and /dev/sdc (on KVM: /dev/vdb, /dev/vdc).

1. Partitions

lsblk
sudo gdisk /dev/sdb           # n (new), size +1G, type 8e00 (Linux LVM); w to write
sudo partprobe /dev/sdb       # if lsblk doesn't show the new partition yet
lsblk /dev/sdb

parted /dev/sdb mkpart does the same without the prompts, which is handy in scripts. Never create partitions on the disk that holds /.

2. LVM: create

sudo pvcreate /dev/sdb1
sudo vgcreate -s 8M vgdata /dev/sdb1         # 8 MiB extents
sudo lvcreate -n lvapp -l 50 vgdata          # 50 extents = 400 MiB
sudo mkfs.xfs /dev/vgdata/lvapp
sudo mkdir /app

Lower-case -l counts extents and upper-case -L takes a size (-L 400M). Exam tasks often state one or the other on purpose.

3. Mount it at boot

sudo blkid /dev/vgdata/lvapp
sudo vim /etc/fstab
UUID=<from blkid>   /app   xfs   defaults   0 0
sudo systemctl daemon-reload
sudo mount -a          # mounts what fstab lists; complains about a bad line now, not at boot
findmnt /app

For a label instead: sudo xfs_admin -L appdata /dev/vgdata/lvapp (unmounted), then LABEL=appdata /app xfs defaults 0 0.

4. Grow it

sudo pvcreate /dev/sdc
sudo vgextend vgdata /dev/sdc
sudo lvextend -r -L +1G /dev/vgdata/lvapp
df -h /app

-r grows the filesystem in the same step. Without it, run xfs_growfs /app (XFS) or resize2fs (ext4) afterwards, or df still shows the old size.

5. Swap

sudo gdisk /dev/sdb           # another partition, type 8200 (Linux swap)
sudo partprobe /dev/sdb
sudo mkswap /dev/sdb2
sudo vim /etc/fstab           # UUID=<from blkid>  none  swap  defaults  0 0
sudo swapon -a
swapon --show

A swap logical volume works the same way (lvcreate -n lvswap -L 512M vgdata, then mkswap).

6. Prove it survives

Reboot the VM. Everything must come back without you typing anything: findmnt /app, swapon --show. If the boot stops in emergency mode, see the FAQ below, then roll back to your snapshot and try again.

Drill

From the clean snapshot, in one go: a 512 MiB swap partition, a volume group with 16 MiB extents, a 30-extent ext4 volume mounted by label, then grow it by 200 MiB. Aim for 15 minutes. The storage quiz questions cover the "why".

Questions

Can I shrink an XFS filesystem?
No. XFS only grows. To make it smaller, back it up, recreate a smaller logical volume and filesystem, and restore. ext4 can shrink, but only unmounted and after e2fsck -f.
Why mount by UUID instead of /dev/sdb1?
Kernel device names follow detection order and can change when disks are added. A UUID or label belongs to the filesystem itself, so the fstab line keeps working.
My VM stopped in emergency mode after I edited fstab. What now?
Log in with the root password, run mount -o remount,rw /, fix or comment out the bad line in /etc/fstab, then systemctl daemon-reload and reboot. Next time, test with mount -a before rebooting.

Fix it yourself

A live machine in your browser, already broken. The grader checks the result.

Start the first lab

No account needed for your first tries.

More guides