Need overlay script to run before /sbin/init

I guess the overlay module is not loaded, so I get the following error message, when the script does a modprobe on it:

modprobe: FATAL: Module overlay not found in directory /lib/modules/5.4.0-BPI-R64-Kernel

i guess you need to rebuild kernel for this (add overlay-module)…it looks like you use not my debian image, as kernel seems to be official one…

you can use my 5.4-main tree and change board in build.conf to bpi-r64

Thank you for being helpful, I will try it. I appreciate a lot your help.

i guess it’s the option

 CONFIG_OVERLAY_FS

which is already set in my 5.10 tree, maybe on 5.4 too

You are right, I guess I am using this image: Image link

I’ve been using this image since 2020, but tomorrow I will try this one from your post: Other image link

you can also try this (new ATF):

but you can also replace kernel in your existing image

Thanks! Do you think it will work on the EMMC? Or you did not test it yet? The one I am using now (from the official website) (link) is working on the EMMC and it would be nice to still run the OS from the EMMC if it is possible. Anyway I will try these images and also if I fail I will try to replace the kernel in the existing image which is running on the EMMC.

basicly emmc is same, except boot-headers, maybe you need reflashing bl2 and header_emmc/fip

and you need to change boot device in uboot (uenv.txt mmc 0 instead of 1 and root for kernel) and system (fstab)

Thank, I will try it in the morning and I will let you know :slight_smile:

Again, thank you for being this helpful.

Here is my current uEnv.txt file. This version of uEnv.txt allows the user to disable the overlay through the uEnv.txt, as opposed to having to manipulate the bootopts line. It also needs no compilation changes to the u-boot binary. Hope this helps somebody…

bootmenu_default=2

bootmenu_2=3. Boot from SD/EMMC with overlay.=run boot1
boot1=run selectmmc; setenv bootopts init=/sbin/overlayRoot.sh; run newboot;

bootmenu_3=4. Boot from SD/EMMC without overlay.=run boot2
boot2=run selectmmc; run newboot;

Now if only I could figure out how to copy the SD card to the EMMC correctly within the uEnv.txt file so it can boot from EMMC without the SD card in…

1 Like

You use r2 or r64? Basicly you can copy image to both devices, both need preloader (r64 bl2) in boot0 and partconfig set to 0x48. R64 needs bl31+fip for emmc to boot correctly. If you have system booting you can replace uenv.txt with the one from sdcard

Btw. You overwrite bootopts…maybe this is not right. Imho better should be extend existing content,like this

setenv bootopts "$bootopts ..."

I’m using my R2. I’ve made that change to my repo. Updated uEnv.txt:

bootmenu_default=2

bootmenu_2=3. Boot from SD/EMMC with overlay.=run boot1
boot1=run selectmmc; run loadbootenv; run importenv; setenv bootopts "$bootopts init=/sbin/overlayRoot.sh"; run newboot;

bootmenu_3=4. Boot from SD/EMMC without overlay.=run boot2
boot2=boot1=run selectmmc; run loadbootenv; run importenv; run newboot;
1 Like

Can i use a file (image with ext4) as overlayfs?

How to mount in running system? Just run the script (but i guess real init is called then which is already running)?

Can i use a file (image with ext4) as overlayfs?

If I’m understanding you correctly, you want to mount a ext4 image file as the readonly part of an overlayfs? I’m not sure that you can use a ext4 image file as part of a overlayfs… Would probably take modification of the script in order to make that happen, but it’s clearly not impossible…

If you are asking how to add it to an existing image, just add the uEnv.txt to the boot partition of the image and the overlayRoot.sh file to the /sbin directory. That should be all that if required to make this work…

Obviously, in order to make the read/write area persistent, you need a partition with the correct label (defaults to ROOT-RW, I believe)… Otherwise, it uses RAM to create the read/write area, and rebooting loses all changes to the system.

How to mount in running system? Just run the script (but i guess real init is called then which is already running)?

The answer is simple: You can’t. The script, which handles the partition finding and the entire overlayfs setup, MUST be called before /sbin/init (which handles the system initialization). I know of no other way to create a persistent formatable storage partition that doesn’t also destroy the root partition when formatted… (Doesn’t mean there isn’t another way, but I don’t know of any other way…)

Calling the script on a running system once the system is initialized is NOT advisable, but I can’t tell you if it would screw anything up by doing so… (Kinda doubt it, but wouldn’t try anyway!)

No as the rw overlay…having my image as base overlayed by an filesystem in an image.

Lemme see if I’m understanding correctly:

  1. Readonly is the operating system on the SD card or EMMC.
  2. Read/Write “partition” is the image file.

I don’t see why not. You would have to change the script to mount the image file instead of searching for the R/W partition and mounting what it finds. Very doable…

Yes,i guess image needs to be on external partition (to be writable as root is ro)

Yeah, I didn’t think of that, either…

Yeah, I created a 10mb image on the ro partition, formatted and mounted it, and tried to set the partition ro. No go…

Could you try to put image on other partition with rw access and guide me to configure/add script?