提交 ba24762b 编写于 作者: M Michael Opdenacker 提交者: Linus Torvalds

init: make init failures more explicit

This patch proposes to make init failures more explicit.

Before this, the "No init found" message didn't help much.  It could
sometimes be misleading and actually mean "No *working* init found".

This message could hide many different issues:
 - no init program candidates found at all
 - some init program candidates exist but can't be executed (missing
   execute permissions, failed to load shared libraries, executable
   compiled for an unknown architecture...)

This patch notifies the kernel user when a candidate init program is found
but can't be executed.  In each failure situation, the error code is
displayed, to quickly find the root cause.  "No init found" is also
replaced by "No working init found", which is more correct.

This will help embedded Linux developers (especially the newcomers),
regularly making and debugging new root filesystems.

Credits to Geert Uytterhoeven and Janne Karhunen for their improvement
suggestions.
Signed-off-by: NMichael Opdenacker <michael.opdenacker@free-electrons.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: NJanne Karhunen <Janne.Karhunen@gmail.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 df3ef3af
...@@ -810,10 +810,26 @@ static int run_init_process(const char *init_filename) ...@@ -810,10 +810,26 @@ static int run_init_process(const char *init_filename)
(const char __user *const __user *)envp_init); (const char __user *const __user *)envp_init);
} }
static int try_to_run_init_process(const char *init_filename)
{
int ret;
ret = run_init_process(init_filename);
if (ret && ret != -ENOENT) {
pr_err("Starting init: %s exists but couldn't execute it (error %d)\n",
init_filename, ret);
}
return ret;
}
static noinline void __init kernel_init_freeable(void); static noinline void __init kernel_init_freeable(void);
static int __ref kernel_init(void *unused) static int __ref kernel_init(void *unused)
{ {
int ret;
kernel_init_freeable(); kernel_init_freeable();
/* need to finish all async __init code before freeing the memory */ /* need to finish all async __init code before freeing the memory */
async_synchronize_full(); async_synchronize_full();
...@@ -825,9 +841,11 @@ static int __ref kernel_init(void *unused) ...@@ -825,9 +841,11 @@ static int __ref kernel_init(void *unused)
flush_delayed_fput(); flush_delayed_fput();
if (ramdisk_execute_command) { if (ramdisk_execute_command) {
if (!run_init_process(ramdisk_execute_command)) ret = run_init_process(ramdisk_execute_command);
if (!ret)
return 0; return 0;
pr_err("Failed to execute %s\n", ramdisk_execute_command); pr_err("Failed to execute %s (error %d)\n",
ramdisk_execute_command, ret);
} }
/* /*
...@@ -837,18 +855,19 @@ static int __ref kernel_init(void *unused) ...@@ -837,18 +855,19 @@ static int __ref kernel_init(void *unused)
* trying to recover a really broken machine. * trying to recover a really broken machine.
*/ */
if (execute_command) { if (execute_command) {
if (!run_init_process(execute_command)) ret = run_init_process(execute_command);
if (!ret)
return 0; return 0;
pr_err("Failed to execute %s. Attempting defaults...\n", pr_err("Failed to execute %s (error %d). Attempting defaults...\n",
execute_command); execute_command, ret);
} }
if (!run_init_process("/sbin/init") || if (!try_to_run_init_process("/sbin/init") ||
!run_init_process("/etc/init") || !try_to_run_init_process("/etc/init") ||
!run_init_process("/bin/init") || !try_to_run_init_process("/bin/init") ||
!run_init_process("/bin/sh")) !try_to_run_init_process("/bin/sh"))
return 0; return 0;
panic("No init found. Try passing init= option to kernel. " panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/init.txt for guidance."); "See Linux Documentation/init.txt for guidance.");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册