You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This method is not very flexible however, as it is hard to reliably pass multiple commands and command line arguments to the init with it, as explained at: xref:init-environment[xrefstyle=full].
3260
3266
3261
3267
For this reason, we have created a more robust helper method with the `--eval` option:
@@ -3435,55 +3441,66 @@ at the very end of the boot logs.
3435
3441
3436
3442
=== Init environment
3437
3443
3438
-
Documented at https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html[]:
3444
+
Documented at https://www.kernel.org/doc/html/v5.9/admin-guide/kernel-parameters.html[]:
3439
3445
3440
3446
____
3441
3447
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.
3442
3448
____
3443
3449
3444
-
And you can try it out with:
3450
+
And you can try it out with our link:userland/linux/init_env_poweroff.c[] program:
From the <<dry-run,generated QEMU command>>, we see that the kernel CLI at LKMC 69f5745d3df11d5c741551009df86ea6c61a09cf now contains:
3457
+
From the <<dry-run,generated QEMU command>>, we see that the kernel CLI at LKMC 69f5745d3df11d5c741551009df86ea6c61a09cf now contains (or at least would if it weren't for https://github.com/cirosantilli/linux-kernel-module-cheat/issues/110 oh God), manually indented for readability:
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:
3480
+
Tested as of the Linux kernel v5.7 and possibly earlier, boot also shows the init arguments and environment very clearly when using <<printk>> at `loglevel=8`, which is a great addition:
3473
3481
3474
3482
....
3475
-
<6>[ 0.309984] Run /sbin/init as init process
3476
-
<7>[ 0.309991] with arguments:
3477
-
<7>[ 0.309997] /sbin/init
3478
-
<7>[ 0.310004] nokaslr
3479
-
<7>[ 0.310010] -
3480
-
<7>[ 0.310016] with environment:
3481
-
<7>[ 0.310022] HOME=/
3482
-
<7>[ 0.310028] TERM=linux
3483
-
<7>[ 0.310035] earlyprintk=pl011,0x1c090000
3484
-
<7>[ 0.310041] lkmc_home=/lkmc
3483
+
<6>[ 2.777265] Run /lkmc/linux/init_env_poweroff.out as init process
3484
+
<7>[ 2.777729] with arguments:
3485
+
<7>[ 2.777953] /lkmc/linux/init_env_poweroff.out
3486
+
<7>[ 2.778212] lkmc_home=/lkmc
3487
+
<7>[ 2.778391] go_in_arg=val2
3488
+
<7>[ 2.778554] zxcv
3489
+
<7>[ 2.778705] with environment:
3490
+
<7>[ 2.778901] HOME=/
3491
+
<7>[ 2.779065] TERM=linux
3492
+
<7>[ 2.779223] go_in_env=val1
3485
3493
....
3486
3494
3495
+
As we can see, the passing of environment variables to init is a bit wonky:
3496
+
3497
+
* `init` and `loglevel` didn't go because they were recognized
3498
+
* `go_in_env` went because it wasn't
3499
+
3500
+
so things can always break in future kernel releases... The only way to guard from this a bit is to use some unique prefix and hope the kernel never decides to use it. We of course use `lkmc_*` for our variables.
3501
+
3502
+
And it is also impossible to pass environment variables that contain dots in them: our `with_dot.before` is simply gone. Not a common use case, but still, quite insane.
3503
+
3487
3504
==== init arguments
3488
3505
3489
3506
The annoying dash `-` gets passed as a parameter to `init`, which makes it impossible to use this method for most non custom executables.
0 commit comments