From 2f9c3e4ee446d66e110973eb5bf9f4f00220f186 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. vfs_lstat() which was used previously would fail with certain configurations. This was likely due to the involved functions being marked __init at some point in the past. Signed-off-by: Richard Laroque Signed-off-by: Bruce Ashfield Signed-off-by: Bruce Ashfield Signed-off-by: Sven Schwermer --- init/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/init/main.c b/init/main.c index 649d9e4201a8..4e6af76ca199 100644 --- a/init/main.c +++ b/init/main.c @@ -1574,7 +1574,21 @@ static int __ref kernel_init(void *unused) /* Open /dev/console, for stdin/stdout/stderr, this should never fail */ void __init console_on_rootfs(void) { - struct file *file = filp_open("/dev/console", O_RDWR, 0); + struct file *file; + +#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 + */ + struct kstat stat; + if (init_stat("/dev/console", &stat, 0) || !S_ISCHR(stat.mode)) { + panic("/dev/console is missing or not a character device!\nPlease ensure your rootfs is properly configured\n"); + } +#endif + + file = filp_open("/dev/console", O_RDWR, 0); if (IS_ERR(file)) { pr_err("Warning: unable to open an initial console.\n"); -- 2.19.1