Using qemu-system-x86_64, I want QEMU to start a virtual machine with a drive and a few virtual cdrom drives and floppy drives attached. I need it to automatically boot from the first virtual cdrom drive without me having to "press any key to boot from cd/dvd".

I have specified the cdrom drive like this:

-drive "file=${WINDOWS_INSTALL_ISO},index=1,media=cdrom"

But no matter what I do with the -boot parameter, it always displays this "Press any key to boot from cd/dvd now..." for about 5 seconds and then it doesn't boot from that cd. I have tried various things like:

-boot order=d -boot menu=on


-boot d


-boot "order=d,menu=on"

I also tried using the boot index:

-drive "file=${WINDOWS_INSTALL_ISO},index=1,media=cdrom,bootindex=1"

Which results in an error: Block format 'raw' does not support the option 'bootindex'

The cdrom drive that I want to boot from contains a Windows 10 installation image which I have configured to install itself automatically without user interaction. My goal is to have a bash script which automatically creates a Windows VM and automatically installs Windows without any user interaction. So I really just need QEMU to automatically boot into that Windows installation.


I managed to reproduce the the behavior like this:

sudo qemu-system-x86_64 \
    -smp 4 \
    -m 4G \
    -drive "file=/home/fedora/vm/windows10.iso,index=1,media=cdrom" \
    -boot order=d \
    -drive id=disk0,if=virtio,cache.direct=on,if=virtio,aio=native,format=raw,file=/home/fedora/Projects/misc/MobilePassThrough/vm-files/WindowsVM.img \
    -drive "if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd" \
    -drive "if=pflash,format=raw,file=/home/fedora/vm/WindowsVM_VARS.fd"

If I remove the last 2 lines (which are responsible for booting in UEFI (OVMF) mode instead of in BIOS (SeaBIOS) mode), then it actually respects the -boot parameter. But I have to boot the VM in UEFI mode, otherwise it would be useless to me.

Edit2: If I understood this correctly, in the UEFI world, the boot order is determined by a variable that is kept in a non-volitile storage (in my case "home/fedora/vm/WindowsVM_VARS.fd"). Now when the boot fails I think I drop into the "UEFI shell". And after doing some research, it appears that this shell is exposed via QEMU's serial port and in theory it would have to be possible to set the variable via 'setvar' and 'expect'. But neither do I have a clue what the name if that variable would be nor what the value would look like or how I would even specify my CD drive in it. I don't even know how 'setvar' and 'expect' work at all.

  • Providing the full command you are using to start qemu, will help others diagnose and scoop the problem.
    – user274160
    Jul 17, 2019 at 15:38

4 Answers 4


If you boot with these parameters to QEmu, using a fresh copy of /usr/share/OVMF/OVMF_VARS.fd, it should start the CD automatically:

-drive file=${WINDOWS_INSTALL_ISO},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on \
-device ahci,id=achi0 \
-device ide-cd,bus=achi0.0,drive=drive-cd1,id=cd1,bootindex=1

(these are taken from the script in qemu-ovmf-secureboot, which boots UefiShell.iso from a Python script and feeds it commands over a pipe). The first line adds a device, the second line adds an adapter, and the third line connects the device to the adapter.

However, the Windows installer itself displays the message "Press any key to boot from CD or DVD" and if it time-outs continue to boot (which will lead into the EFI Shell). This way originally done to prevent the installation running over again when the machine rebooted for the first time, and I believe that this therefore also happens even if you have an autounattend.xml file on the media.

In the question Windows boot iso file without press any key, it is mentioned that there exists a file efisys_noprompt.bin which can be used instead of efisys.bin in the EFI\Microsoft\Boot directory on the CD. You could do this as part of the configuration of the installation medium.

If you have a hard requirement on not modifying the ISO, you could try to create a small image containing just AutoUnattend.xml and the EFI partition, and then use bcdedit to modify the boot database in EFI\Microsoft\Boot\BCD to set a ramdisksdidevice boot loader option load the installer from the CD (I don't know if that would actually work; I haven't tried it).

Use the -no-reboot option to QEmu when installing; when the machine restarts it will return to your script; you can then start it again with a different bootindex the second time.

To use bootindex with a harddisk, you can add it to QEmu thus:

-drive file=${TARGET_IMAGE},format=raw,if=none,media=disk,id=drive-hd1,readonly=off \
-device virtio-scsi-pci,id=scsi0 \
-device scsi-hd,bus=scsi0.0,drive=drive-hd1,id=hd1,bootindex=2

(this adapter will of course need the VirtIO drivers from RedHat installed)

  • Wow, that's... quite a lot of command to unfold. But it works.
    – Xerz
    Sep 1, 2020 at 18:43
  • Separating drive and device and adding bootindex to the device is what I was missing (for a slightly different use case - a USB stick image virtualized as a hard drive image)
    – Reinderien
    Jul 24, 2021 at 20:58
  • Thank you very much for a solution for that extremely annoying problem, which has cost me several hours until I came across this page. No word about it in the qemu documentation ... +1
    – Binarus
    Jan 15, 2022 at 13:26
  • Should be marked as correct answer. Thank you so much Oct 28, 2023 at 5:47
  • I should note that in my situation (using qemu builder for packer), once I put on UEFI it started ignoring the "index=x" for the -drive in qemuargs. This is a problem because I had an unattended installation for Windows that specified the drives in specific order. I had to take each drive and redo them with the settings mentioned in this post and use the bootindex flag to set everything back in the right order. Oct 28, 2023 at 6:17

I've followed your tip on Edit2 and here is what i discovered.

In fact, -boot [order=drives][,once=drives] ... option refers only to BIOS/Legacy bootstraping. If you check QEMU's docs on this option you'll see it makes no remarks on EFI.

To alter EFI boot behavior on QEMU you'll have to edit the VM_VARS.fd that if I understood correctly, equates to a flash SPI memory that contains boot parameters specified on the EFI standard. You could probably edit VM_VARS.fd directly but I honestly did not look into this method; I used the UEFI Shell instead. Here are the steps I took:

1) Make a copy of the default config.

`$ cp /usr/share/OVMF/OVMF_VARS.fd ~/my_vars.fd`

2) Run QEMU and access the UEFI Shell.

In my case, I wanted to boot from a SATA device so -drive id=disk ... onward is particular to my setup and you should change to what ever you need.

sudo qemu-system-x86_64 \
          -cpu host --enable-kvm \
          -drive "if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd" \
          -drive "if=pflash,format=raw,file=~/my_vars.fd" \ 
          -drive id=disk,file=fat:rw:rootfs,if=none \
          -device ich9-ahci,id=ahci \
          -device ide-drive,drive=disk,bus=ahci.0 \
          -nographic \
          -no-reboot \

Wait until it fallbacks to the UEFI Shell. It can take some minutes if it initially tries to boot over the network. You'll end up here:

UEFI Interactive Shell v2.2
UEFI v2.70 (EDK II, 0x00010000)
Mapping table
      FS0: Alias(s):HD1a65535a1:;BLK3:
     BLK0: Alias(s):
     BLK1: Alias(s):
     BLK2: Alias(s):

Press ESC in 1 seconds to skip startup.nsh or any other key to continue.

You can refer to this extensive list of EFI Shell commands or any other UEFI documentation really. I found this article on Arch to be very helpful; it shows how to add, delete and move boot entries.

3) Modify the boot entries. You'll probably run something like:

Shell> bcfg boot add 0 FS0:\EFI\boot\BOOT_X64.efi "my_boot"


bcfg boot add - add a new boot entry.

0 - where to insert (0 is the first).

FS0:\EFI\boot\BOOT_X64.efi - [device_mapping]:[path/to/efi/payload/in/device]. Use the map command to list mappings. Notice that FS0 is my SATA device.

"my_boot" - an alias to your entry.

That's it. Your modifications will be saved in my_vars.fd. Don't forget to add it in all subsequent QEMU invocation.


Maybe it helps to boot manually once from CD-ROM / DVD-ROM in guest:

  • Wait until the TianoCore splash screen shows up
  • Press ESC
  • Use Boot Manager option to boot from DVD-ROM

According to fedoraproject.org/wiki you need "UefiShell.iso" to be able to boot into UEFI shell.

Since OVMF doesn't ship with any SecureBoot keys installed, we need to install some to mimic what an MS certified UEFI machine will ship with. OVMF now ships with the binaries required to set up a default set of keys. The easiest way is to use UefiShell.iso which is available at /usr/share/edk2/ovmf/UefiShell.iso. Boot your VM with this as the CD-ROM image and it should boot into the UEFI shell. At the prompt.

  • Okay and how would this solve my problem? It's not that I can't boot the windows installation image or even install it. My problem is that it doesn't automatically boot from the "cd".
    – Forivin
    Jul 17, 2019 at 17:05
  • Well, it does not boot from the cd when trying to boot in UEFI but it boots in bios as you pointed "If I remove the last 2 lines (which are responsible for booting in UEFI (OVMF) mode instead of in BIOS (SeaBIOS) mode), then it actually respects the -boot parameter." that mean the issue is not with qemu but with the uefi shell that it does not boot. One more question, is the last edit you did have all the options you are passing to qemu? if no please paste all the script or the command you are using to boot followed with error you getting.
    – user274160
    Jul 17, 2019 at 17:39
  • You don't understand. The difference between booting in UEFI vs BIOS is that it doesn't AUTOMATICALLY boot from the CD in UEFI mode, even though I specified "-boot order=d", which should cause the CD to be booted automatically. But instead I just get a message "Press any key to boot from CD/DVD..." (If I press any key at that point, it boots just fine) but it doesn't boot automatically and that is my problem.
    – Forivin
    Jul 17, 2019 at 17:52
  • If that what you need so you question is not related to "unix" world at all its "Microsoft windows" ... its in bootfix.bin google how to edit/remove that file in your windows iso and rebuild the iso, there is plenty of tutorial on MS.windows support sites .
    – user274160
    Jul 17, 2019 at 18:10
  • How well is the UEFI firmware emulated on QEMU? On a real UEFI machine, the boot order is determined by the boot variables stored in non-volatile storage. Jul 17, 2019 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .