4

I am learning the basic of OS making. I have made a multi boot header compliant .asm file and a .c file. The code in the .asm file calls the main function of .c file.

The problem is that QEMU is unable to boot from the file produced after the compilation and linking of the .asm and the .c file .

It simply says that it can't find a bootable device.

Although, I am able to boot from a simple .asm file like :-

  mov ax, 0x0e
  mov al, 'H' 
  int 10h 
  times 510 - ($ - $$) db 0 
  jmp $ 
  dw 0xaa55 

Is there something more which I have to do?

Pratik Singhal
  • 6,283
  • 10
  • 55
  • 97
  • 1
    How did you create the boot image? Also, post the .asm file. – tgiphil Aug 24 '14 at 07:20
  • 1
    Also, how are you running the emulator (i.e. command line options). – Drew McGowen Aug 24 '14 at 14:38
  • 1
    Well you aren't using multiboot headers in this code. But one glaring problem is that `jmp $` is in the wrong place. It should be before the `times` statement. As it is the JMP pushed the boot signature of 0xaa55 outside the first 512 bytes which will cause QEMU to not identify it as a boot sector. – Michael Petch Sep 21 '18 at 02:23
  • `mov ax, 0x0e` is wrong, it should mov to ah. – ecm Feb 10 '20 at 17:26

3 Answers3

11

QEMU 2.0.0 does support multiboot

man qemu says:

-kernel bzImage

Use bzImage as kernel image. The kernel can be either a Linux kernel or in multiboot format.

I have uploaded a minimal hello world example at: https://github.com/cirosantilli/x86-bare-metal-examples/tree/dbbed23e4753320aff59bed7d252fb98ef57832f/multiboot

It generates a GAS + C multiboot file, and uses QEMU to run it.

grub-mkrescue can also convert a multiboot binary to a bootable .iso image which is another good approach.

Barry mentions that multiboot2 is not supported. How to generate a multiboot2 image in case you want to test it: How to compile the simple kernel in multiboot2 Spec corrently?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • 2
    QEMU currently can boot only to a multiboot1 header. multiboot2 is not yet supported. –  Aug 24 '17 at 01:58
  • @Barry thanks for the info. If you have a link to a feature request or source comment, also post it in. – Ciro Santilli OurBigBook.com Aug 24 '17 at 06:59
  • 1
    There's no link. READ the QEMU mailing-lists, source and try it for yourself. Multiboot2 and elf64 support have been consistently rejected for many years because the QEMU maintainers are recalcitrant to get with this millennium and actually LISTEN to users because "reasons." If you absolutely need mutliboot2 or elf64 support, use grub on an iso under QEMU. Or if you really want those features, create patches that add them. –  Sep 22 '17 at 05:32
-1

QEMU doesn't have native support for multiboot. Instead, you'll need to create a virtual hard drive image and install some sort of multiboot boot loader (such as grub), then put your multiboot image somewhere on the drive (i.e. in a file on a partition).

As far as actually installing grub onto a virtual HDD, there's multiple ways to do it, but here's the process I always use:

  1. Use qemu-img or dd if=/dev/zero to create your HDD image.
  2. Download a Linux installer ISO (I typically use Arch Linux).
  3. Boot qemu with the blank HDD image and ISO using -hda <HDD-image-filename> -cdrom <ISO-file-name> -boot once=d. The last bit ensures qemu will try to boot from CD first.
  4. Use fdisk/parted/etc to format the disk.
  5. Mount your boot partition (the one you want to install grub to) and use grub-install.
  6. Unmount and shut down the emulator.

Then, you'll be able to boot off the HDD image and use grub or whatever loader you choose to boot your multiboot image.


The reason your simple ASM example works is because you're effectively emulating the MBR, the first sector of a typical hard drive, so QEMU's BIOS will boot from it (specifically, it sees that 0xaa55 signature).

Drew McGowen
  • 11,471
  • 1
  • 31
  • 57
  • 7
    QEMU does have support for multiboot. The `-kernel` option allows you to specify an ELF executable that is multiboot compliant and it will boot from it. It doesn't support multiboot2 – Michael Petch Aug 24 '17 at 12:09
  • 1
    qemu also only supports elf32 binaries, not elf64. Many versions of binutils' ld will crash while attempting to create hybrid elf32 executables containing x86_64 code. Also, I've not had much luck using objcopy (maybe I'm holding it wrong) to transplant an elf64 to elf32 as the resulting executable is corrupt. Modern grub, elf64 and multiboot2 work fine, albeit slower development cycle than using `qemu -kernel` with multiboot1 and elf32. –  Sep 22 '17 at 05:54
-1

No, QEMU does have native support for the old multiboot spec, although it does not support VBE, ex.. Just compile from a freestanding compiler with the correct legacy multiboot header into an ELF executable and run with the -kernel option

n00ax
  • 307
  • 3
  • 7