Booting rootfs From RAM (x86_64)

Hello,
As a quick emergency OS option, can I get the official build of OpenWRT to accept a rootfs in cpio archive format as an initrd?

So, for example, download from 23.05.3 "generic-kernel.bin" and "rootfs.tar.gz", convert the rootfs to cpio format, place them in the /boot folder of the EFI system partition and then add to the system's grub.cfg:-

linux /boot/generic-kernel.bin
initrd /boot/rootfs.cpio.gz

I have tried this, but something goes wrong and it reboots instantly. Does the official kernel image have initramfs support?

(I wrote a short Python script to convert tar to cpio, seems to generate a valid archive but not extensively tested... :flushed: )

So this morning, I did a few things:-

  • Added "console=tty0" and "panic=30" to the kernel cmdline, this yielded output including:-
VFS: Cannot open root device "(null)" or unknown-block(1,0): error -6

So the kernel can't "see" the initrd.

  • If I add "initrd" to the kernel cmdline, it freezes whilst still showing GRUB.
  • Tested my generated cpio archives using 7-Zip, finding out that Python's tarfile module doesn't retain file type information in TarInfo.mode, so my archives had regular files where there should have been directories. Also fixed a padding issue at the end of the archive :face_with_open_eyes_and_hand_over_mouth:

So, I am thinking that without at least CONFIG_DEV_BLK_INITRD being enabled in the kernel config, this will never work.

Hi

Did you try the build-in option Target Images -> Initramfs?

Please try to enable it and you will get a kernel that I think it will fit with your needs.

I remember I did a try in the past. For testing you can use qemu to speed up the testing (Google will help you with something like qemu x86 initramfs example).

Good luck!

have you seen [x86/64] Request official release of the initramfs-kernel ?

Sorry, work took priority the last month or so.

I actually did quite a lot of testing and was able to determine that selecting the Initramfs target image on x86_64 does precisely two things, which is copy the file:-

target/linux/generic/other-files/init -> /init

And then create an archive of the new root filesystem using cpio instead of tar.
(I spent hours tracing the build process using strace and filtering on execve syscalls to learn this, as the makefiles aren't easy to follow) :sweat:

So you can actually take the pre-built rootfs tar archive, add the init script (you can download it individually from GitHub, don't even need the Image Builder) and then re-create the rootfs as a cpio archive and specify it in the "initrd" line of your bootloader alongside the generic kernel. :partying_face:

Testing also revealed that the generic kernel supports gzipped initramfs, but nothing more exotic (no xz or zstd).

Hi,

I'm not sure if that may help or not, but if I'm not wrong, inside the initramfs menu, you can change the compressed file type from gzip to others. But, of course, you need to build a customized image and change the configuration value before building it.

Regards