From 4ad8c12c9b21426166d55ef6e9e5aaad03df8c57 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 18f8f0140fa0..5b904bc78fa4 100644 --- a/init/main.c +++ b/init/main.c @@ -1112,6 +1112,9 @@ static int __ref kernel_init(void *unused) 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. */ @@ -1143,6 +1146,18 @@ static noinline void __init kernel_init_freeable(void) do_basic_setup(); +#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 + /* Open the /dev/console on the rootfs, this should never fail */ if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) pr_err("Warning: unable to open an initial console.\n"); -- 2.19.1