Looking at Linux kernel source, I see that if the file /init exists, the kernel will always attempt to run it on the assumption that it's doing a ramdisk boot. Check your system to see if /init exists, if it does, then that's probably your problem.
init is not "spawned" (as a child process), but rather exec
'd like this:
# Boot the real thing.
exec switch_root /mnt/root /sbin/init
exec
replaces the entire process in place. The final init is still the first process (pid 1), even though it was preceded with those in the Initramfs.
The Initramfs /init
, which is a Busybox shell script with pid 1, exec
s to Busybox switch_root
(so now switch_root
is pid 1); this program changes your mount points so /mnt/root
will be the new /
.
switch_root
then again exec
s to /sbin/init
of your real root filesystem; thereby it makes your real init system the first process with pid 1, which in turn may spawn any number of child processes.
Certainly it could just as well be done with a Python script, if you somehow managed to bake Python into your Initramfs. Although if you don't plan to include busybox anyway, you would have to painstakingly reimplement some of its functionality (like switch_root
, and everything else you would usually do with a simple command).
However, it does not work on kernels that do not allow script binaries (CONFIG_BINFMT_SCRIPT=y
), or rather in such a case you'd have to start the interpreter directly and make it load your script somehow.
Best Answer
By default, no, that's not allowed. Under Linux (from
man 2 kill
):Pid 1 (init) can decide to allow itself to be killed, in which case the "kill" is basically a request for it to shut itself down. This is one possible way to implement the
halt
command, though I'm not aware of anyinit
that does that.On a Mac, killing
launchd
(its init analogue) with signal 15 (SIGTERM) will immediately reboot the system, without bothering to shut down running programs cleanly. Killing it with the uncatchable signal 9 (SIGKILL) does nothing, showing that Mac'skill()
semantics are the same as Linux's in this respect.At the moment, I don't have a Linux box handy that I'm willing to experiment with, so the question of what Linux'sAnd withinit
does with a SIGTERM will have to wait.init
replacement projects like Upstart and Systemd being popular these days, the answer could be variable.UPDATE: On Linux,
init
explicitly ignores SIGTERM, so it does nothing. @jsbillings has information on what Upstart and Systemd do.