11.3. Creating and Mounting Filesystems
A partition is a container; a filesystem is the structure inside it that
files live in. Creating one is a single command, but it is the single
most destructive command in this chapter, so this section starts by
choosing both the filesystem and the target device deliberately, then
mounts the result temporarily, and finally makes the mount persistent
through /etc/fstab and checks how it behaves at boot.
11.3.1. Choosing a Filesystem and Creating It on the Correct Device
Debian 13 ships creation tools for the three filesystems this book administers in depth, plus the interchange formats removable media use. The choice matters mostly once, at creation, because features - checksums, snapshots, shrink support - cannot be added to a filesystem that lacks them. Chapter 12 treats each option in detail; the comparison below summarizes the selection criteria as documented by the respective tools on Debian 13 (e2fsprogs 1.47.2, xfsprogs 6.13.0, btrfs-progs 6.14):
| Filesystem | Grow / shrink | Checksums and scrub | Snapshots | Repair model | Typical fit |
|---|---|---|---|---|---|
| ext4 | Grow online, shrink offline only | Metadata journal only; no data checksums | No | e2fsck, offline, mature |
General-purpose default; small and mid-size volumes |
| XFS | Grow online; planned shrink requires migration (an experimental -D shrink path exists) |
Metadata checksums | No | xfs_repair, offline; refuses on a dirty log until it is cleared |
Large volumes, parallel throughput, many files |
| Btrfs | Grow and shrink online, per-device | Data and metadata checksums, scrub | Yes (copy-on-write) | btrfs check, integrated scrub |
Data safety, snapshots, multi-device volumes |
| FAT32 | External tools only | None | No | fsck.fat |
USB sticks and camera/SD interoperability |
| exFAT | External tools only | None | No | fsck.exfat |
Large removable media across OSes |
The versions cited are the installed ones, verifiable in one sequence
(each tool reports its own version; mkfs.ext4 -V writes to standard
error, the others to standard output):
# mkfs.ext4 -V; mkfs.xfs -V; mkfs.btrfs --version
mke2fs 1.47.2 (1-Jan-2025)
Using EXT2FS Library version 1.47.2
mkfs.xfs version 6.13.0
mkfs.btrfs, part of btrfs-progs v6.14
-EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=builtin
This chapter creates ext4, the general-purpose default, on all three
practice partitions; XFS and Btrfs creation differ only in the command
name and options, and Chapter 12 walks their
administration. FAT32 (mkfs.vfat from dosfstools) and exFAT
(mkfs.exfat from exfatprogs) serve the removable-media case of
Section 11.4.
Choosing the device is the step that deserves more care than it usually
gets. The target must be the partition (/dev/vdb1), not the whole disk
(/dev/vdb), unless a partitionless layout is a deliberate choice
(Chapter 9 made that choice for its I/O
lab). Confirm the target with the signature reader from
Section 11.1.2, in the root shell:
# wipefs -n /dev/vdb1
No output: the partition is blank, carrying no filesystem signature, so
mkfs will not be overwriting anything. (The check is worth making a
habit even on supposedly new disks - a signature here means the range was
part of some earlier filesystem, and you should know whose.) Then the
creation itself:
# mkfs.ext4 -q -L handbook-data /dev/vdb1
Silent - the -q flag suppresses mke2fs's progress report, which
without it prints a dozen lines of creation statistics like the one
Chapter 9 showed on /dev/vdb. The
filesystem is written at once: superblock, inode tables, journal. Do the
same for the other two partitions with their labels:
# mkfs.ext4 -q -L handbook-opt /dev/vdb2
# mkfs.ext4 -q -L handbook-scratch /dev/vdb3
Both silent.
mkfs.ext4 option |
Description |
|---|---|
-L LABEL |
Set the volume label, visible in lsblk -f and /dev/disk/by-label. |
-q |
Quiet: suppress the progress report. |
-N NUMBER |
Override the number of inodes (Section 11.5.2 uses this deliberately). |
-F |
Force past the "existing signature" confirmation. Does not override the mounted-device refusal. |
The last row's caveat is demonstrated in Section 11.3.2. Now read back what was created - the signature check first, exactly the command that was silent on the blank partition:
# wipefs -n /dev/vdb1
DEVICE OFFSET TYPE UUID LABEL
vdb1 0x438 ext4 67848521-8140-424f-a998-97fbaf0dcbf6 handbook-data
The new ext4 signature sits at offset 0x438 - 1080 bytes into the
partition, which is the ext4 superblock (starting at byte 1024) plus the
56 bytes to its magic number. lsblk -f shows all three creations at
once:
# lsblk -f /dev/vdb
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
vdb
├─vdb1 ext4 1.0 handbook-data 67848521-8140-424f-a998-97fbaf0dcbf6
├─vdb2 ext4 1.0 handbook-opt bcd65ade-67cd-4438-9b2c-3f4319d69194
└─vdb3 ext4 1.0 handbook-scratch 94db6eea-71bb-4d0c-a3a9-994f0defe923
Each partition now has an FSTYPE, a LABEL chosen at creation, and a
UUID generated by mkfs.ext4. blkid adds the partition-level
identifiers from Section 11.1.3's table:
# blkid /dev/vdb1 /dev/vdb2 /dev/vdb3
/dev/vdb1: LABEL="handbook-data" UUID="67848521-8140-424f-a998-97fbaf0dcbf6" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="data" PARTUUID="c6bd965a-c144-4b60-9329-8d08a068e879"
/dev/vdb2: LABEL="handbook-opt" UUID="bcd65ade-67cd-4438-9b2c-3f4319d69194" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="optional" PARTUUID="31ea70f4-3964-4c43-bbb6-76aa7b5562ca"
/dev/vdb3: LABEL="handbook-scratch" UUID="94db6eea-71bb-4d0c-a3a9-994f0defe923" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="scratch" PARTUUID="ef852be8-470a-4af7-b5b3-44c66c83bdbb"
The PARTLABEL and PARTUUID values are the GPT partition name and GUID
from Section 11.2.3; UUID and LABEL are the filesystem's own. And the
content-keyed stable names from Section 11.1.3 now exist, because the
content does:
# ls -l /dev/disk/by-uuid/ | grep vdb
lrwxrwxrwx 1 root root 10 Nov 20 02:27 67848521-8140-424f-a998-97fbaf0dcbf6 -> ../../vdb1
lrwxrwxrwx 1 root root 10 Nov 20 02:27 94db6eea-71bb-4d0c-a3a9-994f0defe923 -> ../../vdb3
lrwxrwxrwx 1 root root 10 Nov 20 02:27 bcd65ade-67cd-4438-9b2c-3f4319d69194 -> ../../vdb2
# ls -l /dev/disk/by-label/ | grep handbook
lrwxrwxrwx 1 root root 10 Nov 20 02:27 handbook-data -> ../../vdb1
lrwxrwxrwx 1 root root 10 Nov 20 02:27 handbook-opt -> ../../vdb2
lrwxrwxrwx 1 root root 10 Nov 20 02:27 handbook-scratch -> ../../vdb3
The filesystem UUIDs and labels are now usable as mount sources, which is how the rest of the chapter refers to them. Given only a label, the device it names is one lookup:
# blkid -L handbook-data
/dev/vdb1
The remaining question - what to do when the target device is not blank or not disused - is exactly what the mounted-filesystem checks demonstrate in the next section.
11.3.2. Temporary Mounts and Mount Options
A filesystem is usable once it is mounted: attached to a directory - the mount point - so that path operations read and write the filesystem. Mounting by hand is temporary: it lasts until unmounted or until reboot, and nothing remembers it. That is the right mode for testing a filesystem, and it is how this section starts. Create the mount points first, in the root shell (a mount point is just a directory):
# mkdir -p /srv/handbook/data /srv/handbook/optional /srv/handbook/scratch /srv/handbook/inodes
Silent. Then mount the data partition by device name:
# mount /dev/vdb1 /srv/handbook/data
Silent. Confirm the result:
# findmnt /srv/handbook/data
TARGET SOURCE FSTYPE OPTIONS
/srv/handbook/data /dev/vdb1 ext4 rw,relatime
findmnt invocation |
Description |
|---|---|
findmnt TARGET |
Show the filesystem mounted at TARGET; print nothing and exit 1 if none. |
findmnt -n TARGET |
Omit the header line. |
findmnt -o LIST TARGET |
Print selected columns only, as in -no OPTIONS. |
findmnt --verify --verbose |
Check /etc/fstab and the current mount table for errors (Section 11.3.3). |
findmnt is the read side of the mount table, and its OPTIONS column
deserves a look even in this minimal mount: rw is the read-write mode,
and relatime is the kernel's default atime policy (access timestamps
are updated only if the file was modified since the last update, or if
the existing timestamp is more than a day old - few writes, most tools
satisfied).
A freshly created ext4 filesystem is owned by root, like every other unconfigured system resource. Give the mount point to john so the examples can run as an ordinary user:
# chown john:john /srv/handbook/data
Silent. As john, in an ordinary shell, write a file onto the new filesystem and read it back:
$ printf "%s\n" "stored on the data disk" > /srv/handbook/data/note.txt; cat /srv/handbook/data/note.txt
stored on the data disk
The redirect creates and writes the file silently - output went to the
file, not the terminal - and cat prints it back. The data disk is now
doing the one job a storage layer has: holding john's data.
Mount options change how the kernel serves that filesystem. They are set
at mount time and can be changed on a live mount with
mount -o remount,…, which rewrites the option set without detaching
anything. A useful hardening set for a data-only filesystem:
# mount -o remount,noatime,nodev,nosuid /srv/handbook/data
Silent. Read the new options:
# findmnt -no OPTIONS /srv/handbook/data
rw,nosuid,nodev,noatime
| Mount option | Effect |
|---|---|
rw / ro |
Read-write (the default) or read-only. |
relatime / noatime / strictatime |
Access-timestamp policy: conditional updates (kernel default), never update, always update. |
nodev |
Ignore device files (block/character specials) on this filesystem - nothing there should be a device. |
nosuid |
Ignore setuid and setgid bits on executables here. |
noexec |
Refuse to execute any program from this filesystem. |
remount,… |
Not an option for a new mount: apply the listed options to an already-mounted filesystem. |
(The kernel stores the option set canonically, which is why findmnt
prints them sorted - rw,nosuid,nodev,noatime - rather than in the order
typed.) noatime goes one step past relatime and never writes
timestamps on read at all, which is the common choice for data volumes;
the tools that genuinely need accurate atime are rare and documented when
they do. nodev and nosuid close off privilege-escalation paths that a
data disk should not offer: with them, a device file or a setuid binary
planted on this filesystem is inert.
noexec completes the set and is worth seeing fail once. Remount with
it:
# mount -o remount,noexec /srv/handbook/data
Silent. As john, put a runnable script on the filesystem and try to execute it:
$ printf "#!/bin/sh\necho ran\n" > /srv/handbook/data/run.sh; chmod +x /srv/handbook/data/run.sh; /srv/handbook/data/run.sh
bash: line 2: /srv/handbook/data/run.sh: Permission denied
The script exists, is executable by permission, and still will not run:
noexec blocks the kernel's exec path from this filesystem, and the
shell reports the refusal (exit status 126, "command found but not
executable"). One boundary to understand: noexec stops direct
execution, not interpretation - sh /srv/handbook/data/run.sh would
still run, because then the executed program is /bin/sh, on the root
filesystem. noexec is a fence, not a wall.
Restore the working option set for the rest of the chapter:
# mount -o remount,exec,noatime,nodev,nosuid /srv/handbook/data
Silent.
A mounted filesystem is also busy, in the sense of Section 11.2.4, and the two refusals described there can now be captured for real. First, the partition-table re-read on the whole disk:
# blockdev --rereadpt /dev/vdb
blockdev: ioctl error on BLKRRPART: Device or resource busy
The kernel refuses the wholesale table replacement because vdb1 - a
partition of this disk - is mounted. Second, the formatting refusal,
with -F to show that forcing past the signature question is not forcing
past this:
# mkfs.ext4 -F /dev/vdb1
mke2fs 1.47.2 (1-Jan-2025)
/dev/vdb1 is mounted; will not make a filesystem here!
mke2fs names the condition and stops: no mkfs option creates a
filesystem on a mounted device. Both refusals clear the same way -
unmount:
# umount /srv/handbook/data
Silent. The data filesystem is detached again, its contents intact
(note.txt and run.sh are still on /dev/vdb1), and the next section
mounts it the permanent way.
11.3.3. Persistent Mounts in /etc/fstab
A mount that must exist after every reboot is declared in
/etc/fstab - one line per filesystem, owned by root, applied by systemd
at boot. The file has six fields:
| Field | Meaning | Example from this chapter |
|---|---|---|
| source | Device path, UUID=, LABEL=, or other spec |
UUID=67848521-8140-424f-a998-97fbaf0dcbf6 |
| mount point | Directory the filesystem attaches to | /srv/handbook/data |
| filesystem type | As mount expects it |
ext4 |
| options | Comma-separated mount options | defaults,noatime |
| dump | Obsolete dump(8) flag; always 0 on Debian |
0 |
| pass | fsck order at boot: 0 skip, 1 root, 2 after root |
2 |
Back up the file before editing it - a broken fstab can block the next boot (Section 11.3.4 shows the failure mode; Chapter 7 Section 7.6.2 walked the emergency-mode consequence):
# cp /etc/fstab /etc/fstab.ch11-test-backup
Silent. The new entry for the data filesystem, with the UUID from Section 11.3.1:
UUID=67848521-8140-424f-a998-97fbaf0dcbf6 /srv/handbook/data ext4 defaults,noatime 0 2
defaults is the standard option set (read-write, executable, suid and
device files honored, mounted at boot, not mountable by ordinary users);
noatime replaces the kernel's relatime as in Section 11.3.2. The pass
value is 2: the root filesystem is checked first (1), everything
else after (2), and 0 skips the check entirely. Append the line:
# printf '%s\n' 'UUID=67848521-8140-424f-a998-97fbaf0dcbf6 /srv/handbook/data ext4 defaults,noatime 0 2' >> /etc/fstab
Silent - the line was appended to the file, not printed; the next two
commands read the file's effects back. First, tell systemd to regenerate
the units it derives from /etc/fstab:
# systemctl daemon-reload
Silent. Then run the fstab validator, which translates every source spec, checks targets and types, and cross-checks the current mount table:
# findmnt --verify --verbose
/
[ ] target exists
[ ] VFS options: rw
[ ] FS options: discard,errors=remount-ro
[ ] UUID=be225267-eaf4-410c-9ffa-5cd32b221ce0 translated to /dev/vda1
[ ] source /dev/vda1 exists
[ ] FS type is ext4
/srv/handbook/data
[ ] target exists
[ ] VFS options: noatime
[ ] UUID=67848521-8140-424f-a998-97fbaf0dcbf6 translated to /dev/vdb1
[ ] source /dev/vdb1 exists
[ ] FS type is ext4
Success, no errors or warnings detected
The verifier walked both entries: the installed system's root entry
(UUID=be225267… translating to /dev/vda1, carrying the
discard,errors=remount-ro options the installer recorded -
Section 11.5.1 returns to discard) and the new data entry translating
to /dev/vdb1. mount -a mounts everything in the file that is not yet
mounted:
# mount -a
Silent. Confirm:
# findmnt /srv/handbook/data
TARGET SOURCE FSTYPE OPTIONS
/srv/handbook/data /dev/vdb1 ext4 rw,noatime
The filesystem is mounted again, this time with the fstab's noatime
applied. What makes this mount different from Section 11.3.2's is who owns
it: systemd, through a unit generated from the fstab line. The unit's
name is the mount path with slashes mapped to dashes,
srv-handbook-data.mount:
# systemctl status srv-handbook-data.mount --no-pager
● srv-handbook-data.mount - /srv/handbook/data
Loaded: loaded (/etc/fstab; generated)
Active: active (mounted) since Fri 2026-11-20 02:28:43 UTC; 4s ago
Invocation: e2ca43f544ef47a08f075062b354da62
Where: /srv/handbook/data
What: /dev/vdb1
Docs: man:fstab(5)
man:systemd-fstab-generator(8)
Loaded: loaded (/etc/fstab; generated) names the source of truth: the
unit is not a file on disk to edit, it is derived from /etc/fstab by
systemd-fstab-generator at boot and at every daemon-reload. The unit
can be started and stopped like any other:
# umount /srv/handbook/data; systemctl start srv-handbook-data.mount; systemctl is-active srv-handbook-data.mount; findmnt /srv/handbook/data
active
TARGET SOURCE FSTYPE OPTIONS
/srv/handbook/data /dev/vdb1 ext4 rw,noatime
One bounded sequence: umount detaches the filesystem (silent),
systemctl start mounts it again through the generated unit,
is-active confirms (active), and findmnt shows the same kernel
state as before. Both mounting paths - mount -a from the shell and
systemctl start on the unit - reach the same mount; the unit form is
what boot uses.
What depends on this mount - the question to answer before deciding whether a filesystem is truly optional - is a reverse-dependency query:
# systemctl list-dependencies --reverse srv-handbook-data.mount
srv-handbook-data.mount
○ └─local-fs.target
● └─sysinit.target
○ ├─apt-daily-upgrade.service
● ├─apt-daily-upgrade.timer
...
Selected output; the full listing continues with every unit that pulls in
sysinit.target - timers, ssh, udisks2, and the rest of the system's
startup graph.
The first two lines are the finding: local-fs.target - the target that
all required local filesystems must reach before the boot proceeds -
pulls in this mount unit. That is exactly the dependency
Chapter 7 Section 7.6.2 demonstrated from the
failure side, and it is why an fstab entry without nofail can hold a
boot: if the device never appears, local-fs.target waits, times out,
and fails. The next section shows both behaviors and the option that
distinguishes them.
11.3.4. Checking Mount Dependencies and Boot Behavior
The fstab currently holds one data entry. This section adds a second, deliberately broken entry for a device that does not exist, and uses it to observe the two boot-behavior classes - required and optional - before rebooting for real to confirm the persistent mount survives.
The fstab options that govern boot behavior:
| fstab option | Effect at boot |
|---|---|
| (none) | The mount is required: ordered before local-fs.target; failure blocks and can drop the boot to emergency mode. |
nofail |
The mount is optional: attempted, but its failure does not block or fail the boot. |
x-systemd.device-timeout=T |
How long systemd waits for the source device to appear (default 90 seconds). |
x-systemd.automount |
Defer the mount until first access (Section 11.4.2). |
x-systemd.idle-timeout=T |
With an automount, unmount again after T idle (documented in systemd.mount(5)). |
Add the broken entry, with nofail, to /etc/fstab - all zeros is not
a UUID any mkfs produced:
# printf '%s\n' 'UUID=00000000-0000-0000-0000-000000000000 /srv/handbook/missing ext4 defaults,nofail 0 2' >> /etc/fstab
Silent. Apply the file:
# mount -a
Also silent - and the silence is the point: mount -a reads /etc/fstab
directly (the daemon-reload step that keeps systemd's units in step comes
with the removal below), and it exited 0 even though UUID=00000000-…
matches no device on the system. nofail did exactly its job: the missing
filesystem was skipped, and nothing else was disturbed.
Remove the word - one sed edit - and the same command tells a
different story:
# sed -i "/handbook\/missing/s/,nofail//" /etc/fstab
Silent. Apply the file again:
# mount -a
mount: /srv/handbook/missing: can't find UUID=00000000-0000-0000-0000-000000000000.
Now mount -a fails (exit status 32, mount's generic failure code) and
says which source it could not find. The two runs differ only in
nofail; that one fstab word is the whole contract between "this
filesystem had better be there" and "this filesystem is best-effort".
At boot the difference is starker, as Section 7.6.2 of
Chapter 7 showed: a required mount that cannot be
satisfied blocks local-fs.target and lands the system in emergency
mode. Reserve required entries for filesystems the system cannot run
without (/var, /home on a server); use nofail - with a short
x-systemd.device-timeout if the device is expected to be absent - for
data volumes whose absence is survivable.
Remove the broken entry before it outlives its purpose:
# sed -i "/\/srv\/handbook\/missing/d" /etc/fstab; systemctl daemon-reload
Both steps silent: the sed deletes the line, the daemon-reload
regenerates units so the missing-device unit disappears too.
Now the real test. As john, leave a marker on the data filesystem (a write with redirection, so no output):
$ printf "%s\n" "persisted across reboot" > /srv/handbook/data/marker.txt
Then put the broken entry back with nofail - the boot test needs both
a required entry that works and an optional one that cannot:
# printf '%s\n' 'UUID=00000000-0000-0000-0000-000000000000 /srv/handbook/missing ext4 defaults,nofail 0 2' >> /etc/fstab; systemctl daemon-reload
Silent. Reboot the machine - sudo systemctl reboot from john's shell,
or the equivalent from the console - and log back in. Three checks
answer the three questions a persistent-mount change should always be
verified with.
First: is the data filesystem mounted, without anyone having run
mount?
# findmnt /srv/handbook/data
TARGET SOURCE FSTYPE OPTIONS
/srv/handbook/data /dev/vdb1 ext4 rw,noatime
It is, with the fstab's options applied at boot. Second: did the data survive? As john:
$ cat /srv/handbook/data/marker.txt
persisted across reboot
Third: what did the missing optional device cost? Check failed units and the missing mount's own unit:
# systemctl --failed --no-pager
UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed.
# systemctl status srv-handbook-missing.mount --no-pager
Warning: The unit file, source configuration file or drop-ins of srv-handbook-missing.mount changed on disk. Run 'systemctl daemon-reload' to reload units.
○ srv-handbook-missing.mount - /srv/handbook/missing
Loaded: loaded (/etc/fstab; generated)
Active: inactive (dead)
Job: 66
Where: /srv/handbook/missing
What: /dev/disk/by-uuid/00000000-0000-0000-0000-000000000000
Docs: man:fstab(5)
man:systemd-fstab-generator(8)
No failed units - the boot completed cleanly. The missing mount's unit
is inactive (dead), with Job: 66 recording the start job the boot
queued for it: the device named in What: never appeared, the job came
to nothing, and the unit itself never activated - Chapter 7's
job-versus-unit distinction from Section 7.6.2, seen from the nofail
side, where an unsatisfied optional mount leaves no failed unit to show
for it. The warning line - printed to standard error ahead of the status
block - is systemd noticing that the fstab-derived definition changed
after the units were loaded; the cleanup below runs the suggested
daemon-reload anyway.
Remove the practice entry and restore a clean fstab:
# sed -i "/\/srv\/handbook\/missing/d" /etc/fstab; systemctl daemon-reload
Silent. What the reboot established, in one sentence each: a fstab entry
mounts its filesystem at boot with no operator involvement; the data
written before the reboot is the data found after it; and a nofail
entry that cannot be satisfied costs nothing but an inactive unit. The
remaining question - which mounts deserve to exist at all, and which
should appear on demand - is the next section's subject.