LFCS — Linux Foundation System Administrator
From LVM to autofs — Build Storage by Hand
Goal
You build LVM on top of two loop devices, register ext4 in fstab by UUID, extend it online, turn on a swap file, set up an NFS server and an autofs client inside the same VM, and then leave metrics with iostat and vmstat. Everything really attaches.
Why it matters
The LFCS Storage domain (20%) could not be done at all in a Pod — pvcreate and mount are blocked because there is no capability. This lab runs as root on an Ubuntu 24.04 VM. In exchange, there is no empty disk. The scratch disk was already formatted as ext4 and attached by the platform, so you start with a loop device (losetup), which makes a file look like a block device. It is exactly the method used in practice when testing LVM or RAID without a disk.
Three things are the skeleton of this lab. First, LVM has three layers, PV → VG → LV, and extending happens separately in two layers (resize2fs after lvextend). Second, in fstab you write the UUID, not the device name — the device order can change on every boot. Third, editing a configuration file and the daemon knowing about it are different things (exportfs -ra, systemctl restart autofs).
A session starts at 60 minutes and can be extended up to 180 minutes, and the VM disappears when the session ends.
Steps
- Create
/var/lib/lfcs/disk1.imgand/var/lib/lfcs/disk2.img, each 1GiB in size (sparse files are fine), and attach both as loop devices. After attaching, save the output oflosetup -ato/root/lfcs/storage/loop.txt. - Initialize the two loop devices as LVM physical volumes (PVs), and combine them into a volume group
vg_lfcs. - From
vg_lfcs, create a 600MiB logical volumelv_dataand format it as ext4. - Mount
lv_dataat/srv/data, and add a line starting with UUID= (typeext4, optionsdefaults, dump 0, pass 2) to/etc/fstabso that it attaches after a reboot.findmnt --verifymust show no errors in fstab. - Extend
lv_databy 300MiB more (900MiB or more in total), and make the ext4 filesystem grow along with it without unmounting. The size of/srv/dataas seen bydfmust grow. - Create
/var/swap/lfcs.swapas a 256MiB swap file and turn it on. The permissions must be600, and add a line (typeswap) to/etc/fstabso that it is turned on after a reboot. - Export
/srv/shareover NFS, but allow only 127.0.0.1 (optionsrw,sync,no_subtree_check). Write any content to/srv/share/hello.txt, and mount that share at/mnt/shareover NFS so that the same file is visible. - Make autofs attach the same share at the moment of access. In the master map
/etc/auto.master.d/lfcs.autofs, connect/nfsto the map/etc/auto.lfcs, and in that map write the keysharepointing to127.0.0.1:/srv/shareas nfs4. After restarting autofs,ls /nfs/sharemust show hello.txt. (If the server is itself, autofs attaches with bind instead of NFS — it is normal for the SOURCE offindmnt /nfs/shareto show[/srv/share].) - Save the output of
iostat -dxk 1 3to/root/lfcs/storage/iostat.txtand the output ofvmstat 1 3to/root/lfcs/storage/vmstat.txt. Then make/root/lfcs/storage/summary.txtwith four lines:VG=vg_lfcs,PVS=<vg_lfcs 의 PV 개수>,LV_MB=<lv_data 의 크기(MiB, 정수)>, andSWAP=<켜져 있는 스왑 파일 경로>(PVS= followed by the number of PVs in vg_lfcs, LV_MB= followed by the size of lv_data in MiB as an integer, and SWAP= followed by the path of the swap file that is on).
Notes
- Loop device:
truncate -s 1G 파일→losetup -f --show 파일(the placeholder is the file). To see which device it attached to, uselosetup -j 파일. - LVM:
pvcreate,vgcreate vg_lfcs 장치1 장치2(the placeholders are device 1 and device 2),lvcreate -L 600M -n lv_data vg_lfcs,lvextend -L +300M -r. - UUID:
blkid -o value -s UUID /dev/vg_lfcs/lv_data. After editing fstab, runsystemctl daemon-reloadandmount -a. - NFS:
/etc/exports→exportfs -ra→exportfs -v. autofs: map file →systemctl restart autofs. - Common mistake 1: running only
lvextendand leaving outresize2fs, sodfis unchanged. - Common mistake 2: putting a space between the client and the opening parenthesis in
/etc/exports, so it is opened to the whole world. - Common mistake 3: writing
/dev/loopNin fstab — the number can change on every boot.
Create two loop devices
Create /var/lib/lfcs/disk1.img and /var/lib/lfcs/disk2.img, each 1GiB in size (sparse files are fine), and attach both as loop devices. After attaching, save the output of losetup -a to /root/lfcs/storage/loop.txt.
You can make a sparse file with truncate -s. snap is already using a few loop numbers, so do not hard-code one; get a free one (losetup -f --show).
Make a VG from two PVs
Initialize the two loop devices as LVM physical volumes (PVs), and combine them into a volume group vg_lfcs.
pvcreate takes one device at a time, and for vgcreate you list the devices after the VG name. You can find which loop device it is again with losetup -j .
Cut an LV and format it as ext4
From vg_lfcs, create a 600MiB logical volume lv_data and format it as ext4.
Give the size with lvcreate -L and the name with -n. The device path appears in two forms, /dev// or /dev/mapper/-.
Mount it and write it in fstab by UUID
Mount lv_data at /srv/data, and add a line starting with UUID= (type ext4, options defaults, dump 0, pass 2) to /etc/fstab so that it attaches after a reboot. findmnt --verify must show no errors in fstab.
You see the UUID with blkid. The device path (/dev/loopN) can change on every boot, so you must not write it in fstab. After writing, use systemctl daemon-reload and mount -a to confirm that the fstab line itself works.
Grow the LV and the filesystem online
Extend lv_data by 300MiB more (900MiB or more in total), and make the ext4 filesystem grow along with it without unmounting. The size of /srv/data as seen by df must grow.
Even if you extend the LV with lvextend -L +300M, the filesystem does not know. You have to run resize2fs separately or add -r to lvextend for df to change.
Create a swap file and turn it on
Create /var/swap/lfcs.swap as a 256MiB swap file and turn it on. The permissions must be 600, and add a line (type swap) to /etc/fstab so that it is turned on after a reboot.
The order is to create the file with fallocate or dd, then chmod 600 → mkswap → swapon. Check that it is on with swapon --show. The fstab line has six fields, the mount point position is none, and the type is swap (example: /var/swap/sample.swap none swap sw 0 0).
Export it from a local NFS server and mount it
Export /srv/share over NFS, but allow only 127.0.0.1 (options rw,sync,no_subtree_check). Write any content to /srv/share/hello.txt, and mount that share at /mnt/share over NFS so that the same file is visible.
The order is one line in /etc/exports → exportfs -ra → mount -t nfs4 127.0.0.1:/srv/share /mnt/share. Confirm with exportfs -v that it was actually exported — if you only edit the file, the server does not know.
Attach on access with autofs
Make autofs attach the same share at the moment of access. In the master map /etc/auto.master.d/lfcs.autofs, connect /nfs to the map /etc/auto.lfcs, and in that map write the key share pointing to 127.0.0.1:/srv/share as nfs4. After restarting autofs, ls /nfs/share must show hello.txt. (If the server is itself, autofs attaches with bind instead of NFS — it is normal for the SOURCE of findmnt /nfs/share to show [/srv/share].)
A master map line is 'mount-point map-file', and a map line is 'key -fstype=nfs4 server:/path'. If you forget systemctl restart autofs after editing the map, /nfs is just an empty directory.
Leave performance metrics with iostat and vmstat
Save the output of iostat -dxk 1 3 to /root/lfcs/storage/iostat.txt and the output of vmstat 1 3 to /root/lfcs/storage/vmstat.txt. Then make /root/lfcs/storage/summary.txt with four lines: VG=vg_lfcs, PVS=<vg_lfcs 의 PV 개수>, LV_MB=<lv_data 의 크기(MiB, 정수)>, and SWAP=<켜져 있는 스왑 파일 경로> (PVS= followed by the number of PVs in vg_lfcs, LV_MB= followed by the size of lv_data in MiB as an integer, and SWAP= followed by the path of the swap file that is on).
iostat is in the sysstat package. The first sample is a cumulative value since boot, so take three. Do not write the values by hand; pull them from vgs, lvs --units m --nosuffix, and swapon --show.