Reputation: 26647
I use bootloader code that calls C code which works when I boot the image in qemu. But if I write the image to a USB and try to load the USB in qemu then it doesn't work. Can you help me know what is wrong? If I do the procedure with a more simple booloader that only uses 16 bit real mode and qemu32 then reading from the USB works.
$ sudo qemu-system-x86_64 image.bin
WARNING: Image format was not specified for 'image.bin' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
$ sudo dd if=image.bin of=/dev/sdb
6145+1 records in
6145+1 records out
3146683 bytes (3,1 MB) copied, 1,17287 s, 2,7 MB/s
$ sudo qemu-system-x86_64 -hdb /dev/sdb
WARNING: Image format was not specified for '/dev/sdb' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
The build script is
#!/bin/bash
nasm -f bin boot.asm -o boot.bin
nasm -f elf64 loader.asm -o loader.o
#cc -m64 -ffreestanding -fno-builtin -nostdlib -c main.c
cc -m64 -masm=intel -c main.c
ld -lc -Ttext 0x100000 -o kernel.elf loader.o main.o
objcopy -R .note -R .comment -S -O binary kernel.elf kernel.bin
dd if=/dev/zero of=image.bin bs=512 count=2880
dd if=boot.bin of=image.bin conv=notrunc
dd if=kernel.bin of=image.bin conv=notrunc bs=512 seek=1
rm ./boot.bin ./kernel.bin ./main.o ./loader.o ./kernel.elf
qemu-system-x86_64 image.bin
# write to bootable usb: dd if=image.bin of=/dev/sdb
Upvotes: 0
Views: 1737
Reputation: 314
Your first example
$ sudo qemu-system-x86_64 image.bin
uses image.bin as "first" disk. Your second example
$ sudo qemu-system-x86_64 -hdb /dev/sdb
uses the copy of "image.bin" as "second" disk.
Could you please try without "-hdb" or with explicit "-hda".
Upvotes: 1