Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 812 of 93611. Introduction to Embedded LinuxFree lesson

Implementing Read-Only Root Filesystems

Configure the system to mount the root filesystem as read-only to improve reliability and prevent data corruption in flash-based storage devices.

In this lesson, you will learn how to configure your embedded Linux system to mount the root filesystem as read-only to significantly improve system stability and protect against data corruption on flash storage.

The Problem with Writable Flash

Flash-based storage media, such as SD cards, eMMC, or raw NAND, have a limited number of write cycles. Furthermore, if power is abruptly cut while the filesystem is writing data—especially during a system crash or power loss—the filesystem metadata can easily become inconsistent, leading to a "bricked" state where the kernel fails to mount the rootfs on the next boot.

Designing for Immutability

A read-only (RO) root filesystem assumes that your application data and logs should never reside on the same partition as the OS binaries. By mounting the root as read-only, you effectively make the system immune to accidental corruption of system files and configuration scripts.

To implement this, you first need to pass the ro parameter to your kernel command line. This is typically configured in your bootloader (like U-Boot) environment variables:

setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait ro

Handling Dynamic Data

Even with a read-only rootfs, the system still needs to write files (e.g., logs, system state, or runtime configuration). The standard approach is to use tmpfs or a separate dedicated data partition. You can mount these areas in your fstab to provide "writable windows":

# /etc/fstab
/dev/mmcblk0p2  /       ext4    ro,noatime      0 1
tmpfs           /var/log tmpfs   defaults,noatime 0 0
tmpfs           /tmp     tmpfs   defaults,noatime 0 0
/dev/mmcblk0p3  /data    ext4    rw,noatime      0 2

By mounting /var/log and /tmp as tmpfs, these volatile directories exist only in RAM, preventing unnecessary writes to your flash media. Meanwhile, any persistent data your application requires is directed to the /data partition, which is explicitly mounted as rw. This separation ensures that even if a process crashes while writing, it only affects the data partition, leaving your core operating system binaries untouched and verifiable.

Key Takeaway: Mounting your root filesystem as read-only, paired with RAM-based tmpfs for transient data, is the industry-standard approach for ensuring long-term reliability and filesystem integrity in flash-constrained embedded systems.