3

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 2

4

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).

6
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.