OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:47 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: How to boot QEMU from a locally mounted drive on Windows?
PostPosted: Tue Sep 13, 2022 6:18 am 
Offline

Joined: Fri Mar 15, 2019 4:31 pm
Posts: 7
I'm trying to learn bare metal development with UEFI, I'm developing on Windows in Visual Studio, and I want to test my software in QEMU. The usual QEMU workflow that's described everywhere includes creating a FAT32 drive image file and specifying that file. But I don't know how to do this on Windows and I don't want to have to mess with it, I just want to use a local RAM disk, properly formatted and containing my EFI/BOOT/bootx64.efi file.

How to tell QEMU to use a local drive (e. g. Z:) for booting? What's the right command line incantation?


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 7:39 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Booting from a physical drive is always open to problems. Get something wrong and you may erase your system drive.

Why not use qemu-img (which comes with qemu) to create and manage a disk image? It's very straightforward.


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 10:20 am 
Offline

Joined: Fri Mar 15, 2019 4:31 pm
Posts: 7
Corruption of the partition is not a problem, it's a ramdisk. Thanks for pointing me to qemu-img, but is there really no way to tell qemu to just boot from the damn partition I prepared for it?


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 10:57 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
You can give QEMU the UNC path to your disk.

But do you need to create a RAM disk at all? QEMU has built-in support for creating a FAT-formatted disk out of a directory. This is what I use for UEFI development.


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 11:04 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
I’m not thinking of corrupting the partition you want to use. Get something wrong and you could end up using the wrong partition.

You can certainly do what you want to - it’s described in the documentation ( https://www.qemu.org/docs/master/system/images.html ) but I would still recommend that you don’t. If you really don’t want to use a disk image use a virtual FAT image from a directory.


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 11:17 am 
Offline

Joined: Fri Mar 15, 2019 4:31 pm
Posts: 7
Octocontrabass wrote:
But do you need to create a RAM disk at all? QEMU has built-in support for creating a FAT-formatted disk out of a directory. This is what I use for UEFI development.

Thank you, that does look like what I need! Could you please show your qemu invocation command line that works? I'm getting a "Block node is read-only" error (of course the boot partition should be read-only), and if I add "rw:" quemu does boot, but fails to see my bootloader, so I'm doing something wrong.

Does "fat" mean FAT32?


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 11:55 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
VioletGiraffe wrote:
Could you please show your qemu invocation command line that works?

Code:
.\qemu-system-x86_64.exe -drive file=.\edk2-x86_64-code.fd,if=pflash,format=raw,unit=0,readonly=on -drive file=fat:rw:\Users\me\Documents\uefi-test,format=raw

The EFI directory is inside the uefi-test directory.

VioletGiraffe wrote:
Does "fat" mean FAT32?

Maybe, but it doesn't matter for testing in QEMU. OVMF works just as well with FAT12 and FAT16.


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 12:38 pm 
Offline

Joined: Fri Mar 15, 2019 4:31 pm
Posts: 7
Any idea why it wouldn't work? Tried different options for the path - UNC/regular, absolute/relative, with/without the trailing slash, with/without quotes - it just boots into UEFI shell. Tried on a USB stick and a physical PC - boots fine.

Code:
"C:\Program Files\qemu\qemu-system-x86_64.exe" -cpu qemu64 -net none -drive if=pflash,format=raw,unit=0,file=E:\Development\Tools\UEFI\OVMF\OVMF_CODE.fd,readonly=on -drive if=pflash,format=raw,unit=1,file=E:\Development\Tools\UEFI\OVMF\OVMF_VARS.fd -drive file=fat:rw:E:\Development\Projects\Personal\UEFI-Bootloader\BOOT\,format=raw


The "BOOT" folder contains EFI\BOOT\bootx64.efi inside


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 12:56 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
VioletGiraffe wrote:
Code:
OVMF_VARS.fd

Your NVRAM might have the boot order set incorrectly. Press ESC during boot to open the OVMF configuration, then use the Boot Maintenance Manager menu to fix the boot order.


Top
 Profile  
 
 Post subject: Re: How to boot QEMU from a locally mounted drive on Windows
PostPosted: Tue Sep 13, 2022 12:59 pm 
Offline

Joined: Fri Mar 15, 2019 4:31 pm
Posts: 7
Octocontrabass wrote:
Your NVRAM might have the boot order set incorrectly. Press ESC during boot to open the OVMF configuration, then use the Boot Maintenance Manager menu to fix the boot order.

Spot on, thank you! Just removing the OVMF_VARS.fd drive from the command line did the trick.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 76 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group