mikaku / Fiwix

A UNIX-like kernel for the i386 architecture
https://www.fiwix.org
Other
407 stars 32 forks source link

Boot with ram drive not working #7

Closed rick-masters closed 1 year ago

rick-masters commented 1 year ago

Booting with the initrd.img ram drive from media_setup does not work. The screen output after the startup messages is:

PANIC: in init_init()
can't find /sbin/init

Fiwix version: current git code a542c566979bc03ac93d1b3e5eece29b75a8653b

How to reproduce:

qemu-system-x86_64 \
    -kernel fiwix \
    -initrd initrd.img \
    -append "root=/dev/ram0 ramdisksize=1024 initrd=initrd.img"

Qemu places the initrd image right after the kernel, as a multiboot module. The problem is that get_last_boot_addr is not accounting for the initrd module. Well it is, but then some newer code from April 29th can move the last address back down to right after the kernel, just below the initrd module. Then, kernel stack and data structures will overwrite the initrd image.

If I move that code above the multiboot module adjustments, the kernel boots ok:

--- a/kernel/multiboot.c
+++ b/kernel/multiboot.c
@@ -177,6 +177,11 @@ unsigned int get_last_boot_addr(unsigned int info)

        addr = strtab->sh_addr + strtab->sh_size;

+       /* no ELF header tables */
+       if(!(mbi->flags & MULTIBOOT_INFO_ELF_SHDR)) {
+               addr = (unsigned int)_end + PAGE_SIZE;
+       }
+
        /*
         * https://www.gnu.org/software/grub/manual/multiboot/multiboot.html
         *
@@ -190,11 +195,6 @@ unsigned int get_last_boot_addr(unsigned int info)
                }
        }

-       /* no ELF header tables */
-       if(!(mbi->flags & MULTIBOOT_INFO_ELF_SHDR)) {
-               addr = (unsigned int)_end + PAGE_SIZE;
-       }
-
        return P2V(addr);
 }
mikaku commented 1 year ago

Thank you.