7.4. Init environment
The kernel parses parameters from the kernel command line up to "-"; if it doesn’t recognize a parameter and it doesn’t contain a '.', the parameter gets passed to init: parameters with '=' go into init’s environment, others are passed as command line arguments to init. Everything after "-" is passed as an argument to init.
And you can try it out with:
./run --kernel-cli 'init=/lkmc/linux/init_env_poweroff.out' --kernel-cli-after-dash 'asdf=qwer zxcv'
From the generated QEMU command, we see that the kernel CLI at LKMC 69f5745d3df11d5c741551009df86ea6c61a09cf now contains:
init=/lkmc/linux/init_env_poweroff.out console=ttyS0 - lkmc_home=/lkmc asdf=qwer zxcv
and the init program outputs:
args: /lkmc/linux/init_env_poweroff.out - zxcv env: HOME=/ TERM=linux lkmc_home=/lkmc asdf=qwer
Source: userland/linux/init_env_poweroff.c.
As of the Linux kernel v5.7 (possibly earlier, I’ve skipped a few releases), boot also shows the init arguments and environment very clearly, which is a great addition:
<6>[ 0.309984] Run /sbin/init as init process <7>[ 0.309991] with arguments: <7>[ 0.309997] /sbin/init <7>[ 0.310004] nokaslr <7>[ 0.310010] - <7>[ 0.310016] with environment: <7>[ 0.310022] HOME=/ <7>[ 0.310028] TERM=linux <7>[ 0.310035] earlyprintk=pl011,0x1c090000 <7>[ 0.310041] lkmc_home=/lkmc