为什么 qemu 不能启动我的 usb?
Why won't qemu boot my usb?
我使用 bootloader code 调用 C 代码,当我在 qemu 中启动映像时,它可以工作。但是,如果我将图像写入 USB 并尝试在 qemu 中加载 USB,则它不起作用。你能帮我知道哪里出了问题吗?如果我使用仅使用 16 位实模式和 qemu32 的更简单的 booloader 执行此过程,则可以从 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
你的第一个例子
$ sudo qemu-system-x86_64 image.bin
使用 image.bin 作为 "first" 磁盘。你的第二个例子
$ sudo qemu-system-x86_64 -hdb /dev/sdb
使用 "image.bin" 的副本作为 "second" 磁盘。
您可以尝试不使用“-hdb”或使用明确的“-hda”吗?
我使用 bootloader code 调用 C 代码,当我在 qemu 中启动映像时,它可以工作。但是,如果我将图像写入 USB 并尝试在 qemu 中加载 USB,则它不起作用。你能帮我知道哪里出了问题吗?如果我使用仅使用 16 位实模式和 qemu32 的更简单的 booloader 执行此过程,则可以从 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
你的第一个例子
$ sudo qemu-system-x86_64 image.bin
使用 image.bin 作为 "first" 磁盘。你的第二个例子
$ sudo qemu-system-x86_64 -hdb /dev/sdb
使用 "image.bin" 的副本作为 "second" 磁盘。
您可以尝试不使用“-hdb”或使用明确的“-hda”吗?