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
- preinit launching mount_root
https://github.com/openwrt/openwrt/blob/master/package/base-files/files/lib/preinit/80_mount_root - fstools package providing mount_root
https://github.com/openwrt/openwrt/blob/master/package/system/fstools/Makefile#L99 - fstools sources:
https://git.openwrt.org/?p=project/fstools.git;a=blob;f=mount_root.c;h=d343909a9e0ccb6e898f57e1dd20500d7a400051;hb=HEAD - inside fstools, pay attention to overlay stuff
https://git.openwrt.org/?p=project/fstools.git;a=blob;f=libfstools/overlay.c;h=7a7a95fd268aadf78067c26f1c794a24a15eaa66;hb=HEAD
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
-
https://github.com/openwrt/openwrt/blob/master/package/base-files/files/lib/functions/preinit.sh
But not the actual calls of those functions.
EDIT:
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 (
/rom/jffs
)- Copy ramdisk to jffs2
- Move
/jffs
to/
(root) and move/
(root) to/rom
- Cleanup