Is it possible to mount overlay on initramfs?

Hi all,

At OpenWrt 22.03.x, is it possible to mount overlay on initramfs?
I asked the question with chatGPT, I try the script and it is not working.
I try to use procd to auto mount overlay, but the log show

[   12.249624] block: attempting to load /tmp/ubifs_cfg/upper/etc/config/fstab
[   12.256895] block: unable to load configuration (fstab: Entry not found)
[   12.263911] block: attempting to load /tmp/ubifs_cfg/etc/config/fstab
[   12.270756] block: unable to load configuration (fstab: Entry not found)
[   12.277655] block: attempting to load /etc/config/fstab
[   12.283856] block: extroot: not configured
[   12.290334] mount_root: switching to ubifs overlay
[   12.301604] mount_root: pivot_root failed /mnt /mnt/rom: Invalid argument
[   12.308738] mount_root: switching to ubifs failed - fallback to ramoverlay
[   12.316213] mount_root: opening /proc/filesystems failed: No such file or directory
[   12.324139] mount_root: BUG: no suitable fs found

Anyone can help? Thanks.

3 Likes

Something from Google, still not working.

mount -n -t ubifs ubi0_0 /overlay 
mount -n -t overlay overlayfs:/overlay -o rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work /mnt 
mount -n /proc -o noatime,--move /mnt/proc 
pivot_root /mnt /mnt/rom  
mount -n /rom/dev -o noatime,--move /dev 
mount -n /rom/tmp -o noatime,--move /tmp 
mount -n /rom/sys -o noatime,--move /sys 
mount -n /rom/overlay -o noatime,--move /overlay 

The error is

root@53a6:~# pivot_root /mnt /mnt/rom  
pivot_root: (null): Invalid argument

From man pivot_root:

The rootfs (initial ramfs) cannot be pivot_root()ed. The recommended method of changing the root filesystem in this case is to delete everything in rootfs, overmount rootfs with the new root, attach stdin/stdout/stderr to the new /dev/console, and exec the new init(1). Helper programs for this process exist; see switch_root(8).

So AFAICS your only option is to copy the content of the initramfs to a newly mounted tmpfs, and use that to create a layered filesystem. Then you can pivot_root or chroot into it. But the old initramfs keeps in memory. The alternative is to do from init, in process 1, then you can switch_root to the new filesystem, destroying the old one.

Thanks @Mijzelf , looks like I need to change my way to create rootfs.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.