Page 1 of 1

QEMU cant find a bootable disk when trying to boot my kernel

Posted: Fri Jan 09, 2026 9:52 am
by Nima0908
Hello,
when Iam trying to boot my kernel with

Code: Select all

run: $(KERNEL)
	@echo "Booting kernel in QEMU..."
	qemu-system-x86_64 \
		-m 256 \
		-drive format=raw,file=$(KERNEL) \
		-serial stdio \
		-display sdl
qemu starts succesfully but it cant find a bootable disk. My kernel includes a multiboot2 header and is packaged as a .bin file called kernel.bin.

Here are some informations about my kernel:

Code: Select all

~/Dokumente/Projects/Nexus> make info
Kernel ELF Header:
readelf -h build/kernel.bin
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x100040
  Start of program headers:          64 (bytes into file)
  Start of section headers:          4592 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         3
  Size of section headers:           64 (bytes)
  Number of section headers:         6
  Section header string table index: 4

Kernel Sections:
readelf -S build/kernel.bin
There are 6 section headers, starting at offset 0x11f0:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .multiboot_header PROGBITS         0000000000100000  00001000
       0000000000000018  0000000000000000   A       0     0     8
  [ 2] .text             PROGBITS         0000000000100020  00001020
       0000000000000062  0000000000000000  AX       0     0     16
  [ 3] .symtab           SYMTAB           0000000000000000  00001088
       00000000000000f0  0000000000000018           5     5     8
  [ 4] .shstrtab         STRTAB           0000000000000000  00001178
       0000000000000033  0000000000000000           0     0     1
  [ 5] .strtab           STRTAB           0000000000000000  000011ab
       0000000000000044  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), l (large), p (processor specific)

Kernel Symbols:
readelf -s build/kernel.bin | grep -E "_start|kernel_main"
     2: 0000000000100000     0 NOTYPE  LOCAL  DEFAULT    1 header_start
     6: 0000000000100040     0 NOTYPE  GLOBAL DEFAULT    2 _start
multiboot2_header.S:

Code: Select all

.section .multiboot_header, "a"
.align 8
header_start:
    .long 0xE85250D6
    .long 4
    .long header_end - header_start
    .long 0x100000 - header_start
    .short 0
    .short 0
    .long 8
header_end:
I already tried multiple different ways to fix this, like packaging it into a .iso together with grub but i couldnt get it to work because the error persisted. I sqw some different posts online, but none provided me with the required information to notch me in the correct way of fixing it. Does anyone know what iam doing wrong? Thank you for your answers :)

Re: QEMU cant find a bootable disk when trying to boot my kernel

Posted: Fri Jan 09, 2026 10:51 am
by iansjack
Is the file $(KERNEL) a disk image with a boot loader on it?

Re: QEMU cant find a bootable disk when trying to boot my kernel

Posted: Fri Jan 09, 2026 11:38 am
by Octocontrabass
Nima0908 wrote: Fri Jan 09, 2026 9:52 amI already tried multiple different ways to fix this, like packaging it into a .iso together with grub
You're trying to boot your OS on QEMU's legacy BIOS. Did your copy of GRUB include legacy BIOS support? If you're using Linux on a modern PC, the package providing GRUB's legacy BIOS support may not be installed by default, since modern PCs don't need it.

Re: QEMU cant find a bootable disk when trying to boot my kernel

Posted: Sat Jan 10, 2026 12:34 am
by iansjack
I use Arm64 Fedora Linux in a VM running on a Mac. It has no problem creating an ISO image with a x86_64 kernel that uses grub with default bios to run on qemu. (Although I’ve now switched to Limine - again using the legacy bios.)

Re: QEMU cant find a bootable disk when trying to boot my kernel

Posted: Sat Jan 10, 2026 7:56 am
by Nima0908
Thank you very much for all your answers. The problem was indeed that i had grub installed without BIOS support on my gentoo machine. After switching QEMU to UEFI it boots succesfully :).