]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
fix: kconsole fallback not activating when initrd is missing
authorTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 06:18:24 +0000 (03:18 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 06:18:24 +0000 (03:18 -0300)
Root cause: init_start() always called arch_platform_start_userspace()
even when fs_root was NULL. The userspace init thread was created
asynchronously and returned 0 (success) to kernel_main(), so the
'init_ret < 0' check never triggered kconsole_enter(). The init
thread would later discover fs_root==NULL, print '[ELF] fs_root
missing' and hang — but kconsole was never entered.

Fix: init_start() now checks fs_root before attempting to start
userspace. If no root filesystem exists (e.g. missing initrd module
in GRUB), it returns -1 immediately, triggering the kconsole
emergency console fallback in kernel_main().

Also added clear panic message before kconsole entry (similar to
Linux's 'Kernel panic - not syncing: VFS: Unable to mount root fs').

Tested: boot without initrd module now shows:
  [INIT] No root filesystem — cannot start userspace.
  [PANIC] Userspace init failed — dropping to emergency console.
  *** AdrOS Kernel Console (kconsole) ***
  kconsole>

Normal boot: 19/19 smoke pass, cppcheck clean

src/kernel/init.c
src/kernel/main.c

index d60d8d1c3cddcd0a835c04001d96f696ff0a7ef4..9a0578f8a14eaf31b343db36ab3d764c451dc2ec 100644 (file)
@@ -131,6 +131,11 @@ int init_start(const struct boot_info* bi) {
         }
     }
 
+    if (!fs_root) {
+        kprintf("[INIT] No root filesystem — cannot start userspace.\n");
+        return -1;
+    }
+
     int user_ret = arch_platform_start_userspace(bi);
 
     if (bi && cmdline_has_token(bi->cmdline, "ring3")) {
index cb61c7c83dbf785c06228769c6b970f777da9a81..df8545dc2c82be0cc114c790aa3188dfadf2b11f 100644 (file)
@@ -91,7 +91,8 @@ void kernel_main(const struct boot_info* bi) {
     int init_ret = init_start(bi);
     
     if (init_ret < 0) {
-        // VFS/init failed — enter kernel emergency console
+        kprintf("\n[PANIC] Userspace init failed — dropping to emergency console.\n");
+        kprintf("        (type 'help' for commands, 'reboot' to restart)\n\n");
         kconsole_enter();
     }