Mount rootfs to /rom

How does openwrt mount the root file system to /rom? Where is the code? Recently, we did not find the code to mount read-only rootfs. Please guide us

/etc/init.d/S10boot ?

Not quite sure which part of the process you are looking for (or if you are using overlayfs at all), but there are several actors in the normal rom+overlayfs combination...

Combination of

The "read-only when overlayfs is full" comes from the upstream Linux since May 2015.
Originally it was as a added as patch in OpenWrt,


That is part of the process (although later than the initial preinit stuff).

The init scripts take precautions, so that

  • "boot" (s10boot) triggers mount_root once more, and
  • finally "done" (s95done) does copying/cleanup in case a ram tmpfs was temporarily used as r/w rootfs while the new jffs2/ubi overlay was initialized during the boot process.

The actual workflow will partially depend on the boot begin the first boot after a flash (without a r/w fs already existing), or a later boot with r/w rootfs already existing. As there are alternative fs schemes to the default rom+overlayfs, the boot process needs flexibility.

Thanks in wonder

Just look for rootfs_data partition is mounted to /overlay, and then moved to upper layer. It is not seen that the rootfs is moved from / to /rom.

I have never really looked into the detail specifics original mount of the rootfs as "/" (or "/rom").
That might be handled by the kernel itself?

An overview of the process can be found in

I think that also busybox pivot functionality plays role there, as it is used to swap mount points. The relevant references on the OpenWrt side are in

adding from that wiki article, the crucial part about "firstboot":

Executed with parameter 'switch2jffs'

  1. Determine (and set variable for) MTD rootfs_data partition
  2. Determine (and set variable for) rom partition
  3. Determine (and set variable for) jffs2 partition
  4. Determine if mini overlay is supported. If not run hook no_fo
  5. Otherwise, if mounted, skip the rest, otherwise mount under squashfs (/rom/jffs)
  6. Copy ramdisk to jffs2
  7. Move /jffs to / (root) and move / (root) to /rom
  8. Cleanup
1 Like