2016-03-15 157 views
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 

回答

1

你的第一个例子

$ sudo的QEMU系统-x86_64的image.bin

使用image.bin“第一“磁盘。你的第二个例子

$ sudo的QEMU系统-x86_64的-hdb的/ dev/sdb的

使用的 “image.bin” 复制 “第二” 磁盘。

请问您可以尝试不使用“-hdb”或使用明确的“-hda”。

相关问题