0
我使用bootloader code調用C代碼,它在qemu中啓動映像時起作用。但是,如果我將圖像寫入USB並嘗試在qemu中加載USB,那麼它不起作用。你能幫我知道什麼是錯的嗎?如果我用一個更簡單的booloader來做這個程序,它只使用16位實模式和qemu32,那麼從USB讀取就可以工作。qemu爲什麼不啓動我的USB?
$ 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.
構建腳本是
#!/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