LFCS 3.1: LVM
Building a volume group, growing a logical volume while it's in use, snapshots, swapping out a disk, and shrinking ext4.
Before you start
The lab adds three empty 2 GiB spare disks: /dev/loop40, /dev/loop41
and /dev/loop42. They come back at every boot, before filesystems are
mounted, so /etc/fstab lines and volume groups on them keep working.
Tasks
- Create volume group
vg_labfrom/dev/loop40and/dev/loop41, and a 1 GiB logical volumelv_datain it with an XFS filesystem, mounted at/dataat every boot. - Grow
lv_dataand its filesystem by 500 MiB while it's mounted. - Write
version 1to/data/notes.txt. Snapshotlv_dataaslv_data_snap(200 MiB is plenty), then change/data/notes.txttoversion 2and read the old version from the snapshot (mount it read-only at/mnt/snap). Keep the snapshot. - Add the third disk,
/dev/loop42, tovg_lab, then remove the first disk,/dev/loop40, from it without losing data. - Create a 1 GiB logical volume
lv_filesinvg_labwith an ext4 filesystem, mounted at/filesat every boot. Copy/etc/servicesinto it, then shrink the volume and its filesystem to 600 MiB.
Hints
pvcreate,vgcreate,lvcreate -n -L,mkfs.xfs, a line in/etc/fstab, thensystemctl daemon-reloadandmount -a.lvextend -r;df -h /databefore and after.lvcreate -s; an XFS snapshot needsmount -o ro,nouuid.vgextend,pvmove,vgreduce,pvremove;pvsandlvs -o +devices.- ext4 shrinks only unmounted:
umount, thenlvreduce -r.