I'm setting up a read-only filesystem and some of the guides I have read say to add fastboot noswap ro
to /boot/cmdline.txt
, others don't. All of them mention adding ro
to /etc/fstab
though. Is there a difference? I haven't been able to find any documentation on the available options for cmdline.txt and what they all do but it seems to work as read-only without making any changes to cmdline.txt...
2 Answers
It has to do with how the kernel initially mounts the root filesystem. According to the Linux kernel user’s and administrator’s guide, there are both ro
and rw
parameters:
ro [KNL] Mount root device read-only on boot
...
rw [KNL] Mount root device read-write on boot
It turns out that read-only is the default (and has been for 17 years), so adding it to the command line has no effect.
Sometime later, the boot process ("systemd[1]: Started Remount Root and Kernel File Systems.") will remount /
according to the options in /etc/fstab
. The default is to remount it RW.
You might use rw
on the cmdline if your boot process fscks from the initrd (a.k.a. initramfs) before mounting the "real" root filesystem (see e.g. Arch documentation). The usual Raspberry Pi boot process does not use an initrd, so using rw
stops /
from being fscked during boot.
(If you specify rw
on the cmdline and ro
in fstab, then /
will be briefly mounted read-write, fsck will be skipped, and then /
will be remounted read-only. I can't think of a reason you would want to do this.)
Tangent: Another source of confusion is that not all kernel command line parameters are handled by the kernel: systemd appears to handle fsck.mode, fsck.repair, fastboot, and forcefsck. I'm not sure if anything else handles fastboot
, and a quick search hasn't uncovered what handles noswap
.
fsck is pretty fast in the normal case (fsck.ext4 runs ~instantly if the filesystem was unmounted cleanly, fsck.vfat is fast since /boot is small), so the benefit of fastboot
is pretty marginal (and means you risk potentially undetected corruption if you remount read-write and then the Pi loses power).
-
"I'm not sure if anything else handles..." -> The kernel only passes parameters to init, which is also the only process the kernel starts of its own accord (implicitly then it is the first process and all others can be traced back to it); systemd is the init implementation predominantly used on linux today. What the kernel passes is anything that isn't a kernel parameter, so, eg.,
noswap
is I think something that was applied by SysV init (preceded systemd), but wasn't at first by systemd: github.com/systemd/systemd/issues/6686– goldilocks ♦Commented Jul 20, 2021 at 16:27 -
My gist was that it's hard to tell if
fastboot
has other effects, since something else could parse it out of/proc/cmdline
(and parameters like fsck.mode=... must be parsed out of/proc/cmdline
since they are not passed to init).– tc.Commented Jul 20, 2021 at 17:14 -
Yes it is passed to init. You say it yourself: "systemd appears to handle fsck.mode" Systemd doesn't get that by parsing
cmdline.txt
, it gets it when it is instantiated as init by the kernel. I wasn't trying to contradict or correct you, BTW, just resolve your uncertainty: If it isn't a kernel parameter, it is passed to init (systemd). Of course there are probably some undocumented kernel params, and systemd may ignore some of the params it is passed, but if it does something, it's done via one or the other (the kernel or systemd/init).– goldilocks ♦Commented Jul 20, 2021 at 17:39 -
fsck.mode=... is not passed to init because the param name contains a '.', and you can easily confirm this by checking dmsg for "Run /sbin/init as init process". systemd-fsck/systemd-fsckd (not the init process!) presumably parses it out of
/proc/cmdline
in a function called parse_proc_cmdline_item.– tc.Commented Jul 21, 2021 at 18:26 -
Point taken -- I do not get schooled here very often, thank you! I did not think of
/proc/cmdline
and did not know the thing about dot args. Which is right at the top ofkernel-parameters.rst
: The kernel parses parameters from the kernel command line up to “–”; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after “–” is passed as an argument to init..– goldilocks ♦Commented Jul 22, 2021 at 14:05
The difference is mainly that cmdline is related to kernel command line (ie parameters to pass to kernel boot) as opposite to /etc/fstab which is related to your operating system.