在 QEMU 中启动原始磁盘映像

cat*_*cat 33 virtual-machine qemu disk-image

我有一个来自这里的磁盘映像文件;该页面说我可以使用 QEMU 和以下命令启动此映像:

$ qemu-system-x86_64  -m 4096  -ctrl-grab  -no-reboot  x86-64.img
Run Code Online (Sandbox Code Playgroud)

这给出了一个信息:

WARNING: Image format was not specified for 'x86-64.img' 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.
Run Code Online (Sandbox Code Playgroud)

模拟器加载,但 PilOS 崩溃,这意味着我做错了什么:

(可能是因为 PilOS 想写入块 0 但不能)

raw命令行参数,据我所知,这意味着这样传递:

$ qemu-system-x86_64 -drive format=raw file=x86-64.img 
qemu-system-x86_64: -drive format=raw: drive with bus=0, unit=0 (index=0) exists
Run Code Online (Sandbox Code Playgroud)

这失败了(我认为),因为我的引导设备在/dev/sda总线 0 上,所以根据 QEMU 的手册页,以下之一应该可以工作(但不是):

$ qemu-system-x86_64 -drive bus=9 format=raw file=x86-64.img 
qemu-system-x86_64: -drive bus=9: Could not open 'format=raw': No such file or directory
$ qemu-system-x86_64 -drive format=raw file=x86-64.img bus=9
qemu-system-x86_64: -drive format=raw: drive with bus=0, unit=0 (index=0) exists
Run Code Online (Sandbox Code Playgroud)

应该接受的bus=9参数-drive要么被解释为文件名,要么被完全忽略。

如何在 QEMU 中正确引导这样的原始映像?


这是 Ubuntu 15.10,运行:

QEMU emulator version 2.3.0 (Debian 1:2.3+dfsg-5ubuntu9.3), Copyright (c) 2003-2008 Fabrice Bellard
Run Code Online (Sandbox Code Playgroud)

图片的相关资料:

$ file x86-64.img 
x86-64.img: DOS/MBR boot sector; partition 1 : ID=0x83, active, start-CHS (0x0,1,1), end-CHS (0x82,246,62), startsector 62, 2006072 sectors; partition 2 : ID=0x82, start-CHS (0x83,0,1), end-CHS (0x15,246,62), startsector 2006134, 2006134 sectors

$ fdisk -lu x86-64.img 
Disk x86-64.img: 670 KiB, 686080 bytes, 1340 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device      Boot   Start     End Sectors   Size Id Type
x86-64.img1 *         62 2006133 2006072 979.5M 83 Linux
x86-64.img2      2006134 4012267 2006134 979.6M 82 Linux swap / Solaris
Run Code Online (Sandbox Code Playgroud)

der*_*ert 49

-drive选项采用如下所示的参数:

qemu-system-x86_64 -drive format=raw,file=x86-64.img 
Run Code Online (Sandbox Code Playgroud)

...您需要在其“子”选项之间使用逗号,而不是空格。

例如,这是我测试启动 Debian 安装程序 CD 的一个:

qemu-system-x86_64 -drive format=raw,media=cdrom,readonly,file=debian-8.2.0-amd64-DVD-1.iso 
Run Code Online (Sandbox Code Playgroud)

  • @Mr.Hyde 考虑到它对我和 OP 都有效,这很奇怪!完整的命令行是什么?也许最好提出一个新问题,您可以在问题中引用这个问题。 (3认同)