I'm making some Busybox/Linux operating system. It works with static busybox version, initramfs and sysroot have the same stuff except the init script. The one from initramfs sets PATH and mount /sys, /proc and /dev and new_root and then switches to it. It works but I wanted to make the main sysroot use shared version of busybox so external executables could use the same libc as busybox, so there is no wasted disk space. There are steps my Makefile does:
- Fetch sources of linux, busybox, musl and binary i686-linux-musl toolchain.
- Configure and compile linux, musl and busybox (install initramfs' static one to _initramfs_sysroot and the shared one to _sysroot) with the toolchain.
- Copy data from busybox/_initramfs_sysroot to initramfs/ and make a working cpio.gz archive from it.
- Copy data from busybox/_sysroot and copy that to sysroot/. Install musl to sysroot/usr and move sysroot/usr/lib to sysroot/usr/lib32 (because for some reason busybox wants libc to be in here).
- Make the raw disk image with extlinux on it.
- It doesn't work.
What I can see: Linux gives me a kernel panic when trying to run switch_root /new_root /etc/rc.d/rc
from the initramfs saying it's not present but all I have changed was that busybox is shared now so I mount the filesystem on my host OS and execute ldd /mnt/etc/rc.d/rc
and it says that there is no such file `/usr/lib32/libc.so and then I decided to move /usr/lib to /usr/lib32 as I said before. But I got the same error anyways, even if I set LD_LIBRARY_PATH to /usr/lib (libbusybox) and /usr/lib32 (libc) just like PATH - in the initramfs' init script, right before switching root to /new_root.
I discovered that the musl's libc.so is also an executable which can run programs that require it. For example, I succeeded to run /bin/sh (from busybox) as a shared executable through /usr/lib32/libc.so /bin/sh
and it works but only for the sh program. I can't run any other program even through the shell, but I can use the libc.so's "Dynamic Program Loader" again (that is the name of the libc's embedded executable or anything, it says that as help instructions).