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
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...
- preinit launching mount_root
- fstools package providing mount_root
- fstools sources:
- inside fstools, pay attention to overlay stuff
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,
but is since May 2015 in the upstream Linux
That is part of the process (although later than the initial preinit stuff).
The init scripts take precautions, so that
- "boot" (s10boot) triggers
mount_rootonce 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
But not the actual calls of those functions.
adding from that wiki article, the crucial part about "firstboot":
Executed with parameter 'switch2jffs'
- Determine (and set variable for) MTD rootfs_data partition
- Determine (and set variable for) rom partition
- Determine (and set variable for) jffs2 partition
- Determine if mini overlay is supported. If not run hook no_fo
- Otherwise, if mounted, skip the rest, otherwise mount under squashfs (
- Copy ramdisk to jffs2
/(root) and move