Skip to content
systemcoding.dev
Embedded Linux

Mount the root filesystem read-only with ro in fstab

List the root device with the ro option in /etc/fstab so an embedded board's root filesystem is mounted read-only, and a power cut cannot corrupt it.

1 min read
Summarize in AI

A filesystem that is never written cannot be left half-written by a power loss, which is the reason many products ship with a read-only root. The fstab line is the one place that states it for the running system.

Text
/dev/mmcblk0p2  /      ext4   ro,noatime  0  1
/dev/mmcblk0p3  /data  ext4   rw,noatime,sync  0  2
Shell
mount | grep ' on / '
Text
/dev/mmcblk0p2 on / type ext4 (ro,noatime)

The kernel mounts the root device before it reads fstab, using the command line, so add ro there too (root=/dev/mmcblk0p2 ro rootwait). A rw on the command line, which many boards set by default, gets the root mounted read-write first, and the fstab line is applied later by a remount, if your init does one. Check the output of mount, not the file. Services that write to /var or /etc will now fail with "Read-only file system", so give them a tmpfs or the writable data partition. Also note an ext4 journal needs a recovery pass after a power cut, and replaying it writes, so the first boot after a crash may mount read-write briefly. See the mount(8) option list.

Also inSecurity
Share

More snippets

Kernels

Get a GPIO descriptor with devm_gpiod_get

devm_gpiod_get() looks up a named GPIO from the device tree, sets its direction and initial level, and releases it on unbind; use it instead of gpio numbers.

1 min read
Embedded Linux

Choose the hardware target with MIX_TARGET

Set MIX_TARGET to a Nerves target such as rpi4 before running mix commands, so dependencies and the firmware are built for the board and not the host.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.