400. Filesystems and fstab
This page is for anyone adding a disk to a KDOS machine, or checking, labelling or trimming one.
It covers the filesystems a KDOS machine can make, mount and check, and /etc/fstab, the table of what the boot mounts. It shows which port provides each filesystem’s tools, what the image’s own fstab holds and what the installer adds to it, how the boot checks and mounts the table, and the tasks of an installed system: adding a disk, checking a filesystem by hand, labelling one and trimming an SSD.
When the root itself is checked, and why only ext4 gets a check at boot, is explained in the KDOS book’s Checking the root. Swap lines are on zram and swap.
Installation
util-linux provides mount, umount, findmnt, blkid, lsblk, fsck, fstrim, wipefs, cfdisk and sfdisk. Its fsck is the one the boot runs: a front end that runs the checker of each filesystem type, fsck.<type>. e2fsprogs is built with --disable-fsck, so util-linux’s is the only fsck on the system.
Each filesystem’s own tools come from its port:
| Filesystem | Port | Kernel driver |
|---|---|---|
| ext2, ext3, ext4 | e2fsprogs | built in |
| btrfs | btrfs-progs | built in |
| xfs | xfsprogs | built in |
| f2fs | f2fs-tools | module |
| FAT (vfat) | dosfstools, mtools | built in |
| exFAT | exfatprogs | built in |
| NTFS | ntfs-3g | ntfs and ntfs3, modules; ntfs-3g itself mounts through FUSE |
| ISO 9660, UDF | udftools for UDF | built in |
| squashfs | squashfs-tools | built in |
| EROFS | erofs-utils | module |
| HFS+, JFS, NILFS2 | hfsprogs, jfsutils, nilfs-utils | modules |
Every port in the table is on the installation image except hfsprogs, which sudo kdos update install hfsprogs adds (see Installing software).
The kernel column is read from the kernel’s configuration, ports/core/boot/linux/kdos.config, where each driver is =y (built in) or =m (a module).
fuse provides fusermount3, setuid root, through which the FUSE filesystems (filesystems run as ordinary programs) are mounted: e2fsprogs’ fuse2fs, sshfs and gocryptfs. ntfs-3g is built --with-fuse=internal, with its own copy of the FUSE library, so it does not use fusermount3 and mounts as root.
The four filesystems the installer offers for the root, ext4, btrfs, xfs and f2fs, are the ones the initramfs can mount; see The root filesystem.
Nothing is started for a filesystem except at boot, and all of these are enabled on the image:
rcSchecks and mounts/etc/fstab;03_lvmdoes the same again for entries on the volume groups it activates (see LVM and RAID);53_xfs_healerwatches each XFS filesystem mounted at boot (see Disk health);- a timer runs
fstrim -adaily.
Configuration
/etc/fstab, from the base filesystem. The image’s own table mounts only the kernel’s pseudo-filesystems (such as /proc and /sys) and the two temporary ones. Four of the pseudo-filesystems are ones the kernel does not mount by itself: tracefs, debugfs, securityfs (where /sys/kernel/security/lsm and lockdown are read) and bpffs:
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
devtmpfs /dev devtmpfs defaults 0 0
# mode=1777 is NOT optional: a tmpfs mounted with `defaults` comes up 0755
# root, hiding the 1777 /tmp baked into the image, and then no non-root user
# can write to /tmp at all — which breaks Wayland/GTK apps, GIMP, LibreOffice,
# podman's temp files and fontconfig's cache writes.
tmpfs /tmp tmpfs mode=1777,nosuid,nodev 0 0
tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0
cgroup2 /sys/fs/cgroup cgroup2 nsdelegate 0 0
# The kernel mounts none of these four: without tracefs every tracepoint
# probe (bpftrace, perf trace, trace-cmd) finds an empty /sys/kernel/tracing,
# without debugfs the kernel's debug files (/sys/kernel/debug/dri/,
# wakeup_sources, powertop's readings) are absent, without securityfs the
# active LSM list and the lockdown state under /sys/kernel/security cannot be
# read, and without bpffs no pinned BPF object survives the process that made it.
tracefs /sys/kernel/tracing tracefs nosuid,nodev,noexec 0 0
debugfs /sys/kernel/debug debugfs nosuid,nodev,noexec 0 0
securityfs /sys/kernel/security securityfs nosuid,nodev,noexec 0 0
bpf /sys/fs/bpf bpf nosuid,nodev,noexec,mode=0700 0 0
The live medium uses this table unchanged. Its root is the overlay the initramfs built, which no line of the table names. Every key and line is described in /etc/fstab.
The installer’s lines. On an installed system the installer puts its own lines in front of the image’s, keeping every shipped one, from src/system/kinstall-core/install.c:
emit('N', "fstab");
const Filesystem *rfs = ki_fs(cfg.fstype);
char fst[8192] = "";
snprintf(fst, sizeof(fst),
"# Written by the KDOS installer.\n"
"UUID=%s\t/\t%s\t%s\t0 %d\n",
root_uuid, rfs->name, rfs->opts, rfs->passno);
if (esp_uuid[0]) {
char l[256];
snprintf(l, sizeof(l),
"UUID=%s\t/boot/efi\tvfat\tdefaults,umask=0077\t0 2\n",
esp_uuid);
cat(fst, sizeof(fst), l);
}
if (home_uuid[0]) {
char l[256];
snprintf(l, sizeof(l), "UUID=%s\t/home\t%s\t%s\t0 %d\n",
home_uuid, rfs->name, rfs->opts, rfs->passno ? 2 : 0);
cat(fst, sizeof(fst), l);
cat(fst, sizeof(fst), KI_SHARED_PACKS "\t/var/lib/kdos/packs\t"
"none\tbind\t0 0\n");
}
if (swap_uuid[0]) {
char l[256];
snprintf(l, sizeof(l), "UUID=%s\tnone\tswap\tdefaults\t0 0\n",
swap_uuid);
cat(fst, sizeof(fst), l);
}
if (cfg.swap == SWAP_FILE && cfg.swap_mb > 0 && !ki_ab() &&
make_swapfile())
cat(fst, sizeof(fst), "/swapfile\tnone\tswap\tdefaults\t0 0\n");
cat(fst, sizeof(fst), "\n");
if (slurp(TARGET "/etc/fstab", buf, sizeof(buf)) > 0)
cat(fst, sizeof(fst), buf);
src/system/kinstall-core/install.c, lines 2939–2973
So an installed fstab holds, in order:
- the root, by its filesystem UUID;
- the EFI system partition at
/boot/efi, withumask=0077and pass 2; - on the A/B layout (which an erased disk under LVM gets when it has room for two root slots), the
homevolume at/home, and a bind mount of/home/.kdos/packson/var/lib/kdos/packs, so the packs and boxes live on the volume both slots share (see A/B slots and rollback); - any swap partition, volume or file.
A swap file is offered only on a single-root layout, because a file inside one slot’s root would not be there after a switch. The swap file is made before the table is written, and its /swapfile line is written only when the file was made whole: a file that could not be made is deleted, the install warns that the machine has no swap, and the table names none.
The root’s type, options and pass number come from one table, in src/system/kinstall-core/conf.c:
const Filesystem ki_filesystems[] = {
{ "ext4", "mkfs.ext4", "-F", "defaults,noatime", 1,
KI_SWAPFILE_FALLOCATE,
"the default: journalled, boring, and what the kernel has built in" },
{ "btrfs", "mkfs.btrfs", "-f", "defaults,noatime,compress=zstd:3", 0,
KI_SWAPFILE_BTRFS,
"snapshots and transparent zstd compression" },
{ "xfs", "mkfs.xfs", "-f", "defaults,noatime", 0,
KI_SWAPFILE_DD,
"large files and parallel IO; it cannot be shrunk" },
/* fs_passno 0: there is no fsck.f2fs worth running at boot — f2fs.fsck
* exists but is a repair tool, not a boot-time check. The swapfile is
* dd'd for the same reason xfs's is: a file written out in full has no
* unwritten extent for any kernel's `swapon -a` to refuse at the NEXT
* boot, where a refusal leaves no swap and nothing saying why. */
{ "f2fs", "mkfs.f2fs", "-f", "defaults,noatime", 0,
KI_SWAPFILE_DD,
"log-structured, for flash: a stick, an SD card or a cheap eMMC" },
};
src/system/kinstall-core/conf.c, lines 45–63
Only ext4 has pass 1; btrfs, xfs and f2fs have 0. See The filesystem table.
The boot’s check and mount, from /etc/init.d/rcS, in three steps:
fsck -A -R -T -achecks every entry with a non-zero pass except the root;mount -amounts every entry;- a remount gives the root the options its line names, such as
noatime, which the initramfs’s bare mount andmount -aboth leave out. The live medium’s overlay root has no line and is left as it is.
splash step "MOUNTING FILESYSTEMS"
# Check every fstab filesystem with a pass number before anything mounts it.
# The root is left out (-R): the initramfs checked it before mounting it, and
# a check of a mounted root would ask for a reboot. The ESP is the one the
# installer marks, and it is FAT with no journal, holding the A/B boot state.
# An entry on a logical volume the initramfs activated is checked here like any
# other. One on a group it did not activate — any group on a live boot, or on a
# disk that appeared after it ran — has no device yet, so fsck reports it with
# bit 8, which is not shown here, and 03_lvm checks it once its group is active.
# A filesystem with errors left uncorrected is still mounted — the machine
# boots and says so, rather than stopping behind the splash. The report is held
# until /run is mounted: written now, it would land on the root filesystem's
# /run and be hidden under the tmpfs.
_fsck_rc=0
_fsck_out=""
if command -v fsck >/dev/null 2>&1; then
_fsck_out=$(fsck -A -R -T -a </dev/null 2>&1)
_fsck_rc=$?
fi
mount -a
# The initramfs mounts the root with no options, and `mount -a` skips a
# filesystem that is already mounted, so the root's fstab options (noatime,
# a btrfs compress=) apply only through this remount, which takes them from
# fstab. A root with no fstab line — the live medium's overlay — is left alone.
if findmnt -s -n / >/dev/null 2>&1; then
mount -o remount /
fi
[ -n "$_fsck_out" ] && printf '%s\n' "$_fsck_out" > /run/kdos-fsck.log
if [ $((_fsck_rc & 4)) -ne 0 ]; then
splash detail "fsck: errors left uncorrected, see /run/kdos-fsck.log"
printf '%s\n' "$_fsck_out"
fi
fs/etc/init.d/rcS, lines 98–129
The daily trim, /etc/kdos/timers.d/20-fstrim.timer, which tells an SSD which blocks are free:
# Tells every mounted SSD which blocks are free. The installer mounts ext4 and
# xfs without `discard`, so without this a freed block is never reported and
# the drive's write speed and wear degrade as it fills with blocks it believes
# are still in use. btrfs and f2fs already discard as they free blocks, so on
# them this is a cheap second pass. A filesystem whose device cannot discard
# is skipped by fstrim itself.
#
# Daily, and at midday rather than overnight: fstrim cannot touch a timefile,
# so there is no `-t` and a slot the machine was OFF for is simply missed. A
# desktop switched off every night would never reach a 03:00 slot. ext4 skips
# a block group it has trimmed and freed nothing in since, so on a mounted ext4
# the runs after the first cost little.
#
# -s 20h: a machine ASLEEP at the slot runs it once when it wakes, within the
# day.
fstrim -H 12 -M 47 -s 20h -- fstrim -a
fs/etc/kdos/timers.d/20-fstrim.timer
How a timer line is read is on Timers.
Usage
Seeing what is mounted
findmnt # the mount tree, with each filesystem's source, type and options
df -h # space used and free on each
sudo blkid # every filesystem's type, label and UUID
lsblk -f needs root to report a filesystem’s type, label and UUID; run as a user its columns are empty. blkid run as a user cannot read a device (blkid -p /dev/sdb1 answers Permission denied) and prints only what root’s last blkid left in its cache, which may be out of date, so ask it as root. See Known gaps.
Adding a disk to fstab
Find the partition and its filesystem’s UUID:
sudo lsblk -f sudo blkid -s UUID -o value /dev/sdb1For a new partition, make the filesystem first, for example
sudo mkfs.ext4 -L data /dev/sdb1.Make the mount point; the image ships no
/srv, so-pmakes it too:sudo mkdir -p /srv/dataAdd a line with
sudoedit /etc/fstab, naming the filesystem by its UUID:UUID=<uuid> /srv/data ext4 defaults,noatime 0 2Use pass
2for ext2, ext3, ext4 and FAT, so that the boot checks it, and0for btrfs, xfs and f2fs, as the installer does for the root. Addnofailto the options of a disk that is not always connected.Check the table, then mount everything it names that is not mounted yet:
sudo findmnt --verify sudo mount -a findmnt /srv/dataA table with no fault gives
Success, no errors or warnings detected, andfindmntthen shows the line mounted,/srv/data /dev/sdb1 ext4 rw,noatime.
mount is not setuid on KDOS (util-linux is built --disable-makeinstall-setuid), so a user or users option does not let an ordinary account mount the line; see setuid binaries. An NFS share is the exception, because nfs-utils’ mount.nfs is setuid; see Mounting an NFS export. A removable disk an ordinary account should mount is left to udisks2 instead; see Storage and removable media.
On the live medium the edit lands in the session’s overlay and lasts only as long as the session, or as long as a persistence store holds it; see Live persistence.
Checking a filesystem by hand
A filesystem is checked unmounted, except where its tool says otherwise. Unmount it first:
sudo umount /srv/data
Then run its checker:
| Filesystem | Check | Notes |
|---|---|---|
| ext2, ext3, ext4 | sudo e2fsck -f /dev/sdb1 |
-f checks a filesystem marked clean. It asks before each repair, so it needs a terminal; -n only reports, and -p repairs what is safe without asking |
| xfs | sudo xfs_repair /dev/sdb1 |
xfs_repair -n only reports. sudo xfs_scrub /srv/data checks while mounted |
| btrfs | sudo btrfs scrub start -B /srv/data |
Runs mounted, reading every block against its checksum. btrfs check is the unmounted, offline check |
| f2fs | sudo fsck.f2fs /dev/sdb1 |
|
| FAT | sudo fsck.vfat -a /dev/sdb1 |
|
| exFAT | sudo fsck.exfat /dev/sdb1 |
|
| NTFS | sudo ntfsfix /dev/sdb1 |
Repairs a few common faults and marks the volume for Windows to check (Volume is scheduled for check). The kernel’s ntfs3 then refuses to mount it until Windows has checked it (volume is dirty and "force" flag is not set! in dmesg); ntfs-3g still mounts it |
The root cannot be unmounted on the running system. An ext2, ext3 or ext4 root is checked by the initramfs at every boot; to check any root by hand, boot the live medium and check it there, as Encrypted root does for an encrypted one.
Labelling a filesystem
A label names a filesystem in fstab (LABEL=data) and becomes the mount point’s name under /run/media/<user>/ when udisks2 mounts it.
| Filesystem | Command |
|---|---|
| ext2, ext3, ext4 | sudo e2label /dev/sdb1 data |
| btrfs | sudo btrfs filesystem label /srv/data data |
| xfs | sudo xfs_admin -L data /dev/sdb1 (unmounted) |
| FAT | sudo fatlabel /dev/sdb1 DATA |
| exFAT | sudo exfatlabel /dev/sdb1 data |
| NTFS | sudo ntfslabel /dev/sdb1 data |
Trimming an SSD by hand
The daily job runs fstrim -a. To run it at once and see what it did:
sudo fstrim -av
It prints one line for each filesystem it trimmed, such as /srv/data: 487.1 MiB (510717952 bytes) trimmed on /dev/sdb1. The job itself runs as the supervised service kdos-timer-fstrim, which service status timers lists.
Changing a mount’s options
Edit the line in /etc/fstab, then apply it to the mounted filesystem without unmounting:
sudo mount -o remount /srv/data
Tips
- Name filesystems by
UUID=orLABEL=, never by/dev/sdX: device names follow the order in which disks are found, and that order can change from one boot to the next. - A removable device that
/etc/fstabnames is mounted at that line’s mount point and with its options when udisks2 mounts it. - e2fsprogs is built without its cron directory (
--without-crond-dir) and xfsprogs withoutxfs_scrub_all, so no periodic online check runs. A btrfs scrub or anxfs_scrubcan be made a job of the system’s timer table; see Timers. - Clear a partition with
sudo wipefs -a /dev/sdb1before making a new filesystem over an old one.mkfs.btrfs -fover an XFS filesystem leaves the XFS superblock at offset 0 beside the new btrfs one at 64 KiB;sudo wipefs /dev/sdb1lists both, and amountthat is not told-t btrfstries XFS and fails withfsconfig() failed: Data consistency error. - The installer mounts ext4 and xfs without
discard; the dailyfstrimcovers them. btrfs and f2fs discard on their own. kdos why /etc/fstabprints the reason recorded against the file: why/tmpmust be mounted mode 1777.
Troubleshooting
The splash says fsck: errors left uncorrected, see /run/kdos-fsck.log. A filesystem with a pass number had errors fsck -a would not repair alone. It is mounted anyway. Read the report, then unmount that filesystem and check it by hand as in Checking a filesystem by hand:
cat /run/kdos-fsck.log
The log is in /run and is gone at the next boot; a boot whose fsck printed nothing, as on the live medium, writes none. An entry on a volume group activated by 03_lvm is checked there, and its report is appended to the same file.
The splash says ROOT FILESYSTEM HAS ERRORS - RUN e2fsck. The initramfs’s e2fsck -p left errors on an ext root and the boot went on. Boot the live medium and run sudo e2fsck -f on the root’s device.
A filesystem in fstab is not mounted after boot. Mount it by hand to see the error the boot printed:
sudo findmnt --verify
sudo mount -a
findmnt --verify reports a line whose source does not exist, a type the kernel does not know and a mount point that is missing, and exits 1. A line naming a disk that is not there reads:
/nonexist
[E] unreachable on boot required target: No such file or directory
[W] unreachable source: /dev/vdz9: No such file or directory
[W] cannot detect on-disk filesystem type (No such file or directory)
0 parse errors, 1 error, 2 warnings
and mount -a says mount: /nonexist: fsconfig() failed: /dev/vdz9: Can't lookup blockdev. For an entry on a logical volume, see LVM and RAID.
mount: unknown filesystem type 'f2fs', or 'ntfs', 'ntfs3', 'erofs', 'hfsplus', 'jfs', 'nilfs2'. These drivers are modules, and mount has the kernel load the one it needs, so this message means the module could not be loaded. sudo modprobe f2fs (or the type named) prints why, such as modprobe: FATAL: Module f2fs not found in directory /lib/modules/<version> when the modules of the running kernel are not installed.
lsblk -f shows empty columns. Run it as root; see Known gaps.
Known gaps
lsblkshows a filesystem’s type, label and UUID to root only- An NFSv3 mount needs
-o nolock - A root filesystem on LVM has been booted in one shape only
- Features whose library has no port: ntfs-3g reads no boot geometry from
libhd, and btrfs-progs cannot convert a ReiserFS volume
See also
- Storage: the boot’s checks, swap, zram and removable media
- Checking the root: the initramfs’s check and the two boot passes
- Mount points that must be right: the pseudo-filesystems and why each is mounted
/etc/fstab: the file, in the configuration reference- The filesystem table: the installer’s four root filesystems
- Mount options:
nosuid,nodevandnoexecacross the system - zram and swap, LVM and RAID, Encrypted root, Storage and removable media, Disk health, Timers