From 4a8d1cb76c2a95efbc75659a43ac643f22e8a155 Mon Sep 17 00:00:00 2001 From: Bruce Ashfield Date: Thu, 8 Apr 2010 23:44:21 -0700 Subject: [PATCH] check console device file on fs when booting If a root filesystem is generated as non-root, one of the tell tale signs is /dev/console not being a character file. To save a whole class of questions, let's just test for the condition and let the user know. Signed-off-by: Richard Laroque Signed-off-by: Bruce Ashfield --- init/main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/init/main.c b/init/main.c index ae78fb68d231..69bc15d35dd0 100644 --- a/init/main.c +++ b/init/main.c @@ -1463,6 +1463,18 @@ static int __ref kernel_init(void *unused) /* Open /dev/console, for stdin/stdout/stderr, this should never fail */ void __init console_on_rootfs(void) { +#ifndef CONFIG_BLK_DEV_INITRD + /* + * Use /dev/console to infer if the rootfs is setup properly. + * In case of initrd or initramfs /dev/console might be instantiated + * later by /init so don't do this check for CONFIG_BLK_DEV_INITRD + */ + if (vfs_lstat((char __user *) "/dev/console", (struct kstat __user *) &console_stat) + || !S_ISCHR(console_stat.mode)) { + panic("/dev/console is missing or not a character device!\nPlease ensure your rootfs is properly configured\n"); + } +#endif + struct file *file = filp_open("/dev/console", O_RDWR, 0); if (IS_ERR(file)) { @@ -1477,6 +1489,9 @@ void __init console_on_rootfs(void) static noinline void __init kernel_init_freeable(void) { +#ifndef CONFIG_BLK_DEV_INITRD + struct kstat console_stat; +#endif /* * Wait until kthreadd is all set-up. */ -- 2.19.1