Why does Linux allow ‘init=/bin/bash’?
I read this, answers are saying it's KERNEL running this init program.
Then I started to wonder, Linux usually comes with a initramfs, which will eventually mount and pivot_root to real root filesystem. So what does this init
argument mean? The path in the initramfs? Or like I guessed, it's not read by the kernel but by init of initramfs to exec the real init.
Also, the root=UUID=xxxx
argument, is that really read by kernel or just by init of initramfs to find the real root filesystem?
It seems like I can pass any argument I want as kernel arguments, so are they all read by the kernel or at least some of them are only meaningful to userspace programs?
Best Answer
Parameters passed on the kernel command line don’t have to be meaningful for the kernel: the kernel parameters documentation says
This doesn’t apply to
init
androot
which really are kernel parameters, and are handled by the kernel. They can also be acted upon by user-space, since they appear in/proc/cmdline
. (Thus for example systemd takes thequiet
kernel parameter into account to reduce its output.)When the kernel is booted with an initramfs, the
root
parameter isn’t used by the kernel directly, and theinit
parameter is only used ifrdinit
fails.init
startup is handled inkernel_init
, which works as follows:rdinit
on the kernel command line, or/init
) which is accessible, the kernel attempts to run that;init
on the kernel command line), the kernel attempts to run that, and panics if it can’t;/sbin/init
,/etc/init
,/bin/init
, and/bin/sh
; if none of those can be run, it panics.When there’s an initramfs, all of this happens there, and the target volume isn’t mounted by the kernel. What happens after the kernel runs the first
init
program (typically, the/init
script in the initramfs) is up to the program, not the kernel. Arguments which aren’t passed toinit
are still available in/proc/cmdline
if the/proc
file system is mounted.