uEFI on QEMU on Ubuntu with virtual NVMe drive (1 of 3)

This post is useful for setting up of uEFI development environment on Ubuntu with virtual NVMe drive.

We will install QEMU, Git clone the edk2 source and write few automation scripts.


Install QEMU by typing “sudo apt-get install qemu”:


Make one virtual hda and one virtual NVMe drive 1GB each.
Use dd, mkfs.vfat and fdisk for the job and also create two empty directories for mounting the drives to put some data for fun.
Make DOS partition table and format the two drives with fat filesystem:


You can create partitions and filesystems as per your wish but for uEFI based experimentation FAT is more suitable. For fdisk options just press return to use all the default values.


Similar steps are required for both hda(ATA) disk and NVMe disk.


Navigate to the edk directory. We need to build three uEFI efi packages for setting up the development environment.

1.    MdeModulePkg.dsc
2.    OvmfPkgX64.dsc
3.    ShellPkg.dsc

Check your gcc version and input it as mentioned in the below link.

Follow the below link and build the packages:

If you make a mistake, close the terminal, reopen it and source the “edksetup.sh” once again. -> . edksetup.sh

I faced 3 errors in the build, fixed them by initializing the variables to NULL. The build went smooth after that.


You can refer the below link which gives you detailed steps of running uEFI under QEMU with debug setup:


After completion of the above builds place the OVMF.fd in the QEMU directory and rename it as bios.bin

Run the below command to launch QEMU with Tianocore bios:

qemu-system-x86_64 -L . -bios bios.bin -hda hda.disk -drive file=nvme.disk,if=none,id=drv0 -device nvme,drive=drv0,serial=foo –enable-kvm -smp 2 -m 1024

Short descriptions:

-L = Look in current directory.

-bios <file name>= bios file name.

-m = RAM allocated.

-smp = no. of cpus.

–enable-kvm = Enable virtualization in you Laptop/PC bios, install kvm, check with “kvm-ok” and use this option.



Short description of uEFI commands:

To go into any filesystem as given in the above screenshot (FS0 and FS1): fs0: ↵

To see the list of commands in the shell:

help -b ↵

-b: this “break” option is like the “more” command in Linux.

You can use the long QEMU launch command in a script and automate the launch.

In the next post I am going to talk about how to modify the current uEFI shell and  to use the compiled shell in a pen drive to test it on a live PC with uEFI and recompile the ovmf bios.


Leave A Reply

Your email address will not be published. Required fields are marked *