I was going through a tutorial on setting up a custom initramfs where it states:
The only thing that is missing is /init, the executable in the root of the initramfs that is executed by the kernel once it is loaded. Because sys-apps/busybox includes a fully functional shell, this means you can write your /init binary as a simple shell script (instead of making it a complicated application written in Assembler or C that you have to compile).
and gives an example of init as a shell script that starts with #!/bin/busybox sh
So far, I was under the impression that init is the main process that is launched and that all the other user space process are eventually children of init. However, in the given example, the first process is actually bin/busybox/ sh
from which later init is spawned.
Is this a correct interpertation? If I were, for example, have a available interpreter available at that point, I could write init as a Python script etc.?
/
doesn't vanish into thin air - it is mounted over (though usually its contents are all deleted before it is to save memory). It is still there.switch_root
does the syscallswitchroot
- which is what the kernel devs provided when they changed the boot process in kernel 2.6.something to require initramfs. It is the kernel that does the magic. – mikeserv Dec 13 '14 at 19:12switchroot
syscall would indeed be news to me. Do you have a source for that? If you look at the switch_root.c source code, it seems to be quite a manual process, and the same as is described in Documentation/filesystems/ramfs-rootfs-initramfs.txt. Also if you delete everything and mount it over, it's pretty much vanished at this point, don't you think? – frostschutz Dec 13 '14 at 21:21pivot_root
, on the other hand, is a syscall. It's not used forswitch_root
though and can't be used without jumping through some hoops, and either way it matters none whatsoever for this answer, so I just removed it altogether. Too bad, I thought that magic and vanish into thin air worked really well... :-P – frostschutz Dec 13 '14 at 21:51switch_root
- for which I'm sorry, and I thank you for showing me - but it doesn't vanish anything anyway. initramfs root persists and is always there for everybody - it is root. – mikeserv Dec 13 '14 at 21:54find -xdev / -exec rm '{}' ';'
), overmount rootfs with the new root (cd /newmount; mount --move . /; chroot .
), attach stdin/stdout/stderr to the new /dev/console, and exec the new init. – mikeserv Dec 13 '14 at 21:56