diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index f2b8b7c9..8b611fea 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -2028,7 +2028,19 @@ class QemuVM(BaseNode): raise QemuError("bios image '{}' is not accessible".format(self._bios_image)) options.extend(["-bios", self._bios_image.replace(",", ",,")]) elif self._uefi: - options.extend(["-bios", "OVMF.fd"]) # the OVMF bios image should be in the image directory + # get the OVMF firmware from the images directory + ovmf_firmware_path = self.manager.get_abs_image_path("OVMF_CODE.fd") + log.info("Configuring UEFI boot mode using OVMF file: '{}'".format(ovmf_firmware_path)) + options.extend(["-drive", "if=pflash,format=raw,readonly,file={}".format(ovmf_firmware_path)]) + + # the node should have its own copy of OVMF_VARS.fd (the UEFI variables store) + ovmf_vars_node_path = os.path.join(self.working_dir, "OVMF_VARS.fd") + if not os.path.exists(ovmf_vars_node_path): + try: + shutil.copyfile(self.manager.get_abs_image_path("OVMF_VARS.fd"), ovmf_vars_node_path) + except OSError as e: + raise QemuError("Cannot copy OVMF_VARS.fd file to the node working directory: {}".format(e)) + options.extend(["-drive", "if=pflash,format=raw,file={}".format(ovmf_vars_node_path)]) return options def _linux_boot_options(self): diff --git a/gns3server/disks/OVMF.fd b/gns3server/disks/OVMF.fd deleted file mode 100644 index d05e10cb..00000000 Binary files a/gns3server/disks/OVMF.fd and /dev/null differ diff --git a/gns3server/disks/OVMF_CODE.fd b/gns3server/disks/OVMF_CODE.fd new file mode 100644 index 00000000..7df46b8b Binary files /dev/null and b/gns3server/disks/OVMF_CODE.fd differ diff --git a/gns3server/disks/OVMF_VARS.fd b/gns3server/disks/OVMF_VARS.fd new file mode 100644 index 00000000..efb4f46c Binary files /dev/null and b/gns3server/disks/OVMF_VARS.fd differ diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 2d504732..7b3ea6e3 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -387,12 +387,22 @@ async def test_bios_option(vm, tmpdir, fake_qemu_img_binary): assert ' '.join(['-bios', str(tmpdir / "test.img")]) in ' '.join(options) -async def test_uefi_boot_mode_option(vm, tmpdir, fake_qemu_img_binary): +async def test_uefi_boot_mode_option(vm, tmpdir, images_dir, fake_qemu_img_binary): vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0") vm._uefi = True + + # create fake OVMF files + ovmf_code_path = os.path.join(images_dir, "OVMF_CODE.fd") + with open(ovmf_code_path, "w+") as f: + f.write('1') + ovmf_vars_path = os.path.join(images_dir, "OVMF_VARS.fd") + with open(ovmf_vars_path, "w+") as f: + f.write('1') + options = await vm._build_command() - assert ' '.join(['-bios', 'OVMF.fd']) in ' '.join(options) + assert ' '.join(["-drive", "if=pflash,format=raw,readonly,file={}".format(ovmf_code_path)]) in ' '.join(options) + assert ' '.join(["-drive", "if=pflash,format=raw,file={}".format(os.path.join(vm.working_dir, "OVMF_VARS.fd"))]) in ' '.join(options) async def test_uefi_with_bios_image_already_configured(vm, tmpdir, fake_qemu_img_binary):