OverlayFS: Read-Only Base + Writable Overlay
OpenWrt uses OverlayFS to combine two layers into a single coherent filesystem:Read-only base (/rom)
A squashfs partition containing the base system — the kernel, core binaries, default configuration, and baked-in packages. This layer is compressed and cannot be modified at runtime. It survives a factory reset.
Writable overlay (/overlay)
A jffs2 (on NOR flash) or ext4 (on NAND/eMMC/USB) partition that stores all changes made after boot: installed packages, modified config files, new files. This is what opkg writes to.
- A factory reset simply wipes the overlay, restoring the pristine base system
- The base system takes up minimal flash space due to squashfs compression
- Write operations are absorbed by the overlay without touching the compressed base
Directory Layout
Key Directories
/etc/config/
UCI configuration files. One file per subsystem. Edit these via
uci or directly. See UCI System./tmp/
tmpfs — lives in RAM, not flash. Used for runtime state (
/tmp/resolv.conf, /tmp/.uci/, lock files). Lost on reboot./overlay/
The raw writable overlay. Do not write here directly — access it through the merged
/ view./rom/
The read-only squashfs base. You can read default config files from here (e.g.,
/rom/etc/config/network) to compare against your current settings.Flash Storage Constraints
Key implications:/tmp(RAM-backed tmpfs) is the correct place for large temporary files- Avoid storing logs on flash — use a remote syslog server or log to
/tmp - Consider extroot (booting from a USB drive or SD card) to expand available space on flash-constrained devices
Firmware Upgrades with sysupgrade
sysupgrade is the standard tool for updating OpenWrt firmware. It replaces the base squashfs image while selectively preserving your configuration from the overlay.
Basic Usage
Always transfer the firmware image to
/tmp/ first — sysupgrade will wipe all mounted filesystems including the overlay during the upgrade process.What Gets Preserved
By default, sysupgrade preserves:/etc/— all configuration files (including UCI configs)- Files explicitly listed in
/etc/sysupgrade.conf
Customizing Preserved Files
Edit/etc/sysupgrade.conf to add files or directories you want to keep across upgrades: