travessuras initrd
Se você estiver usando initrd ou initramfs, lembre-se do seguinte:
rdinit= é usado em vez de init=
se rdinit=não é dado, os caminhos padrão tentativas são: /sbin/init, /etc/init, /bin/inite /bin/shnão, mas/init
Quando não /initestiver usando o initrd, é o primeiro caminho tentado, seguido pelos outros.
v4.15 RTFS: tudo está contido no arquivo https://github.com/torvalds/linux/blob/v4.15/init/main.c .
Primeiro aprendemos que:
execute_comand é o que for passado para: init=
ramdisk_execute_command é o que for passado para: rdinit=
como pode ser visto em:
static int __init init_setup(char *str)
{
unsigned int i;
execute_command = str;
/*
* In case LILO is going to boot us with default command line,
* it prepends "auto" before the whole cmdline which makes
* the shell think it should execute a script with such name.
* So we ignore all arguments entered _before_ init=... [MJ]
*/
for (i = 1; i < MAX_INIT_ARGS; i++)
argv_init[i] = NULL;
return 1;
}
__setup("init=", init_setup);
static int __init rdinit_setup(char *str)
{
unsigned int i;
ramdisk_execute_command = str;
/* See "auto" comment in init_setup */
for (i = 1; i < MAX_INIT_ARGS; i++)
argv_init[i] = NULL;
return 1;
}
__setup("rdinit=", rdinit_setup);
onde __setupé uma maneira mágica de lidar com os parâmetros da linha de comando.
start_kernel, o kernel "ponto de entrada", chama rest_init, que "chama" kernel_initem um thread:
pid = kernel_thread(kernel_init, NULL, CLONE_FS);
Então, kernel_initfaz:
static int __ref kernel_init(void *unused)
{
int ret;
kernel_init_freeable();
[...]
if (ramdisk_execute_command) {
ret = run_init_process(ramdisk_execute_command);
if (!ret)
return 0;
pr_err("Failed to execute %s (error %d)\n",
ramdisk_execute_command, ret);
}
[...]
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
e kernel_init_freeablefaz:
static noinline void __init kernel_init_freeable(void)
{
[...]
if (!ramdisk_execute_command)
ramdisk_execute_command = "/init";
if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
ramdisk_execute_command = NULL;
prepare_namespace();
}
TODO: entenda sys_access.
Observe também que existem outras diferenças entre inits ram e inits não ram, por exemplo, manipulação de console: Diferença na execução do init com initramfs incorporado e externo?
init? Eles podem simplesmente estar ignorando a linha de comando ... você pode examinar o initrd e ver o que os scripts estão realmente fazendo.