0

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

and:

-boot d

and:

-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.

Edit:

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 at 15:38
0

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 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 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 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 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. – Johan Myréen Jul 17 at 19:18
0

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
EDK II
UEFI v2.70 (EDK II, 0x00010000)
Mapping table
      FS0: Alias(s):HD1a65535a1:;BLK3:
          PciRoot(0x0)/Pci(0x4,0x0)/Sata(0x0,0xFFFF,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)
     BLK0: Alias(s):
          PciRoot(0x0)/Pci(0x1,0x0)/Floppy(0x0)
     BLK1: Alias(s):
          PciRoot(0x0)/Pci(0x1,0x0)/Floppy(0x1)
     BLK2: Alias(s):
          PciRoot(0x0)/Pci(0x4,0x0)/Sata(0x0,0xFFFF,0x0)

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

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"

Breakdown:

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.