LinuxXV · /etc/fstab and Mount ManagementNon-device entries
fstab entries that are not disks - bind mounts, tmpfs, and swap
What you'll learn
- Write a bind mount in fstab, including the two-line idiom for a read-only bind
- Explain why bind does not carry submounts and when rbind is required
- Size a tmpfs entry deliberately instead of inheriting the 50% default
- Write a swap entry that survives a mkswap and does not stop the boot
- Order a bind mount after the filesystem it binds from
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-11
Three kinds of fstab entry have no block device behind them. A
bind mount re-attaches a directory that is already mounted. A
tmpfs mount is memory pretending to be a filesystem. A swap
entry is not a mount at all - swapon reads it, not mount.
None of them can fail with “device not found”, which is why they tend to be written casually. Each has a failure the disk-backed entries do not.
Bind mounts
A bind mount attaches an existing directory at a second path.
The kernel keeps no record that it was a bind - man 8 mount is
explicit that “bind” is just another way to attach a filesystem,
with no second-class node created. Two paths, one filesystem,
one set of inodes.
$ grep -n bind /etc/fstab/srv/data/exports /export/data none bind 0 0The common uses are all about presenting the same data under a
path something else insists on: an NFS export root, a chroot or
container root, a service that hard-codes /var/lib/<name> when
the data lives on a separate volume.
A read-only bind takes two lines
This is the detail that catches people. The bind flag and the
read-only flag are set by different mechanisms, and the classic
mount(2) call cannot do both at once.
/srv/data/exports /export/data none bind 0 0
/srv/data/exports /export/data none remount,bind,ro 0 0
Two entries for the same mount point: the first creates the
bind, the second remounts it read-only. man 8 mount documents
this as the classic way, and notes that the remount,bind form
is still honoured when it comes from /etc/fstab.
Since util-linux 2.27 a single -o bind,ro also works from the
command line, but it is implemented in userspace as an extra
remount syscall - the man page states plainly that the solution
is not atomic. Since util-linux 2.39 with the new kernel mount
API the single-step form behaves properly. Check what you have
before relying on the short form:
$ mount --versionmount from util-linux 2.41.3 (libmount 2.41.3: selinux, smack, btrfs, verity, namespaces, idmapping, statmount, statx, assert, debug)bind stops at the mount boundary
A bind mount attaches one filesystem. If the source directory has other filesystems mounted underneath it, they do not come along.
$ findmnt -o TARGET,SOURCE,FSTYPE /var /var/log /export/varTARGET SOURCE FSTYPE
/var /dev/mapper/vg0-var ext4
/var/log /dev/mapper/vg0-varlog ext4
/export/var /dev/mapper/vg0-var[/] ext4Illustrative output
The failure is silent and it is usually discovered during a
restore. Use rbind when the source has submounts, and check
with findmnt rather than ls - an empty directory and a
missing filesystem look identical to ls.
Ordering a bind mount
A bind mount cannot succeed before its source is mounted. Say so explicitly rather than hoping the path nesting works out:
/srv/data/exports /export/data none bind,x-systemd.requires-mounts-for=/srv/data 0 0
x-systemd.requires-mounts-for= adds a RequiresMountsFor= to
the generated unit, which makes systemd order this mount after
whatever filesystem provides /srv/data and fail it cleanly if
that filesystem is absent. Without it, the failure mode is worse
than a failed mount: the bind can succeed against the empty
directory that exists at /srv/data before its real filesystem
is mounted, and you get an export of nothing.
tmpfs
tmpfs is memory presented as a filesystem. Pages are freed when files are deleted, and they can be pushed to swap under pressure. Its contents do not survive a reboot, which is the point, and also the thing somebody eventually forgets.
$ grep tmpfs /etc/fstab; findmnt -t tmpfs -o TARGET,SIZE,USED,AVAIL,OPTIONStmpfs /var/cache/app tmpfs rw,nosuid,nodev,noexec,size=2G,nr_inodes=200k,mode=1777 0 0
TARGET SIZE USED AVAIL OPTIONS
/dev/shm 15.6G 0 15.6G rw,nosuid,nodev,inode64
/run 3.2G 2.1M 3.2G rw,nosuid,nodev,mode=755,inode64
/var/cache/app 2G 418M 1.6G rw,nosuid,nodev,noexec,size=2G,nr_inodes=200k,mode=1777Illustrative output
Note that /tmp, /run and /dev/shm are usually mounted by
systemd or the initramfs, not by your fstab. Adding your own
/tmp entry overrides systemd’s tmp.mount, which is a
legitimate thing to do and also a change worth making
deliberately:
systemctl cat tmp.mount
systemctl is-enabled tmp.mount
Swap
A swap entry is read by swapon -a, not by mount. The mount
point column is none (or swap, which is equally ignored),
and the options column carries swap options rather than mount
options.
$ swapon --show; grep swap /etc/fstabNAME TYPE SIZE USED PRIO
/dev/dm-1 partition 8G 512M -2
/swapfile file 4G 0B 10
UUID=b4f0e2a1-8c3d-4e5f-9a01-2b3c4d5e6f70 none swap sw,nofail 0 0
/swapfile none swap sw,pri=10,nofail 0 0Illustrative output
The options recognised here come from man 8 swapon:
| Option | Effect |
|---|---|
sw | Legacy no-op kept for compatibility; harmless and conventional |
pri=N | Priority 0-32767; higher is used first |
discard, discard=once, discard=pages | Issue TRIM to the backing device |
nofail | Do not fail the boot if this swap area is missing |
noauto | Do not activate with swapon -a |
Knowledge check
Knowledge check · 4 questions
Q1. You bind-mount /var to /export/var for a backup job. /var/log is a separate filesystem. What does the backup contain?
Q2. Which statements about a read-only bind mount are correct? Select all that apply.
Q3. A tmpfs entry with no size= option defaults to half of physical RAM, and the space it consumes is charged against memory.
Q4. After running mkswap on an existing swap partition, the host fails to boot. What happened, and what would have prevented it?
Passing score: 75%. Answers are checked in this browser.