Skip to content

Commit ba24762

Browse files
Michael Opdenackertorvalds
authored andcommitted
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: Michael Opdenacker <michael.opdenacker@free-electrons.com> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Tested-by: Janne Karhunen <Janne.Karhunen@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent df3ef3a commit ba24762

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

init/main.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,26 @@ static int run_init_process(const char *init_filename)
810810
(const char __user *const __user *)envp_init);
811811
}
812812

813+
static int try_to_run_init_process(const char *init_filename)
814+
{
815+
int ret;
816+
817+
ret = run_init_process(init_filename);
818+
819+
if (ret && ret != -ENOENT) {
820+
pr_err("Starting init: %s exists but couldn't execute it (error %d)\n",
821+
init_filename, ret);
822+
}
823+
824+
return ret;
825+
}
826+
813827
static noinline void __init kernel_init_freeable(void);
814828

815829
static int __ref kernel_init(void *unused)
816830
{
831+
int ret;
832+
817833
kernel_init_freeable();
818834
/* need to finish all async __init code before freeing the memory */
819835
async_synchronize_full();
@@ -825,9 +841,11 @@ static int __ref kernel_init(void *unused)
825841
flush_delayed_fput();
826842

827843
if (ramdisk_execute_command) {
828-
if (!run_init_process(ramdisk_execute_command))
844+
ret = run_init_process(ramdisk_execute_command);
845+
if (!ret)
829846
return 0;
830-
pr_err("Failed to execute %s\n", ramdisk_execute_command);
847+
pr_err("Failed to execute %s (error %d)\n",
848+
ramdisk_execute_command, ret);
831849
}
832850

833851
/*
@@ -837,18 +855,19 @@ static int __ref kernel_init(void *unused)
837855
* trying to recover a really broken machine.
838856
*/
839857
if (execute_command) {
840-
if (!run_init_process(execute_command))
858+
ret = run_init_process(execute_command);
859+
if (!ret)
841860
return 0;
842-
pr_err("Failed to execute %s. Attempting defaults...\n",
843-
execute_command);
861+
pr_err("Failed to execute %s (error %d). Attempting defaults...\n",
862+
execute_command, ret);
844863
}
845-
if (!run_init_process("/sbin/init") ||
846-
!run_init_process("/etc/init") ||
847-
!run_init_process("/bin/init") ||
848-
!run_init_process("/bin/sh"))
864+
if (!try_to_run_init_process("/sbin/init") ||
865+
!try_to_run_init_process("/etc/init") ||
866+
!try_to_run_init_process("/bin/init") ||
867+
!try_to_run_init_process("/bin/sh"))
849868
return 0;
850869

851-
panic("No init found. Try passing init= option to kernel. "
870+
panic("No working init found. Try passing init= option to kernel. "
852871
"See Linux Documentation/init.txt for guidance.");
853872
}
854873

0 commit comments

Comments
 (0)