From 2a24849be23ebba354a932857a4c48d886ebc5e9 Mon Sep 17 00:00:00 2001 From: Xianglai Li Date: Thu, 24 Jul 2025 15:45:58 +0800 Subject: [PATCH] fix virt-install location option issue fix virt-install location option can't boot kernel crorrectly on loongarch On the loongarch platform, the location option should be used in conjunction with -boot uefi=off to install the iso correctly Signed-off-by: Xianglai Li --- ...dd-stub-support-for-boot-uefi-on-off.patch | 71 +++++ virt-install-implement-boot-uefi-off.patch | 292 ++++++++++++++++++ virt-manager.spec | 8 +- virt-xml-implement-edit-boot-uefi-off.patch | 141 +++++++++ 4 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 cli-Add-stub-support-for-boot-uefi-on-off.patch create mode 100644 virt-install-implement-boot-uefi-off.patch create mode 100644 virt-xml-implement-edit-boot-uefi-off.patch diff --git a/cli-Add-stub-support-for-boot-uefi-on-off.patch b/cli-Add-stub-support-for-boot-uefi-on-off.patch new file mode 100644 index 0000000..3d516ff --- /dev/null +++ b/cli-Add-stub-support-for-boot-uefi-on-off.patch @@ -0,0 +1,71 @@ +From 37f3f63843b76841f17d84f94ed43c6a8d4de190 Mon Sep 17 00:00:00 2001 +From: Cole Robinson +Date: Wed, 13 Nov 2024 16:43:37 -0500 +Subject: [PATCH 1/3] cli: Add stub support for `--boot uefi=on|off` + +The way `--boot uefi` is implemented allows a value to be passed, +but the value is completely ignored. So `--boot uefi=off` or +`--boot uefi=FOOBAR` is treated the same as `--boot uefi` + +Lets fix this by making `--boot uefi` and `--boot uefi=on` the same, +`--boot uefi=off` will be implemented later, but any other value +throws an error. This is technically an CLI break but I don't +think it's anything to worry about + +Signed-off-by: Cole Robinson +Signed-off-by: Xianglai Li +--- + tests/test_cli.py | 3 ++- + virtinst/cli.py | 8 ++++++-- + 2 files changed, 8 insertions(+), 3 deletions(-) + +diff --git a/tests/test_cli.py b/tests/test_cli.py +index 08f1ae8..bc570c6 100644 +--- a/tests/test_cli.py ++++ b/tests/test_cli.py +@@ -1109,7 +1109,7 @@ c.add_compare("--connect " + utils.URIs.kvm_x86_remote + " --import --disk %(EXI + c.add_compare("--connect %(URI-KVM-X86)s --os-variant fedora26 --graphics spice --controller usb,model=none", "graphics-usb-disable") + c.add_compare("--osinfo generic --boot uefi --disk size=1", "boot-uefi") + c.add_compare("--osinfo generic --boot uefi --disk size=1 --tpm none --connect " + utils.URIs.kvm_x86_oldfirmware, "boot-uefi-oldcaps") +-c.add_compare("--osinfo linux2020 --boot uefi --launchSecurity sev --connect " + utils.URIs.kvm_amd_sev, "amd-sev", prerun_check=no_osinfo_linux2020_virtio) ++c.add_compare("--osinfo linux2020 --boot uefi=on --launchSecurity sev --connect " + utils.URIs.kvm_amd_sev, "amd-sev", prerun_check=no_osinfo_linux2020_virtio) + + c.add_invalid("--disk none --location nfs:example.com/fake --nonetworks", grep="NFS URL installs are no longer supported") + c.add_invalid("--disk none --boot network --machine foobar", grep="domain type None with machine 'foobar'") +@@ -1359,6 +1359,7 @@ c.add_compare("--confirm 1 --edit --cpu host-passthrough", "prompt-response", in + c.add_compare("--edit --print-diff --qemu-commandline clearxml=yes", "edit-clearxml-qemu-commandline", input_file=(_VIRTXMLDIR + "virtxml-qemu-commandline-clear.xml")) + c.add_compare("--print-diff --remove-device --serial 1", "remove-console-dup", input_file=(_VIRTXMLDIR + "virtxml-console-dup.xml")) + c.add_compare("--print-diff --define --connect %(URI-KVM-X86)s test --edit --boot uefi", "edit-boot-uefi") ++c.add_invalid("--print-diff --define --connect %(URI-KVM-X86)s test-alternate-devs --edit --boot uefi=off", grep="NotImplementedError") + c.add_compare("--print-diff --define --connect %(URI-KVM-X86)s test-many-devices --edit --cpu host-copy", "edit-cpu-host-copy") + c.add_compare("--connect %(URI-KVM-X86)s test-many-devices --build-xml --disk source.pool=pool-disk,source.volume=sdfg1", "build-pool-logical-disk") + c.add_compare("test --add-device --network default --update --confirm", "update-succeed", env={"VIRTXML_TESTSUITE_UPDATE_IGNORE_FAIL": "1", "VIRTINST_TEST_SUITE_INCREMENT_MACADDR": "1"}, input_text="yes\nyes\n") # test hotplug success +diff --git a/virtinst/cli.py b/virtinst/cli.py +index 8dbffeb..053d0a5 100644 +--- a/virtinst/cli.py ++++ b/virtinst/cli.py +@@ -2764,8 +2764,8 @@ class ParserBoot(VirtCLIParser): + self._convert_boot_order(inst) + + # Back compat to allow uefi to have no cli value specified +- if "uefi" in self.optdict: +- self.optdict["uefi"] = True ++ if self.optdict.get("uefi", -1) is None: ++ self.optdict["uefi"] = "on" + + return super()._parse(inst) + +@@ -2779,6 +2779,10 @@ class ParserBoot(VirtCLIParser): + self.guest.refresh_machine_type() + + def set_uefi_cb(self, inst, val, virtarg): ++ val = _on_off_convert("uefi", val) ++ if not val: ++ raise NotImplementedError() ++ + if not self.editing: + # From virt-install, we just set this flag, and set_defaults() + # will fill in everything for us, otherwise we have a circular +-- +2.43.0 + diff --git a/virt-install-implement-boot-uefi-off.patch b/virt-install-implement-boot-uefi-off.patch new file mode 100644 index 0000000..63c9c32 --- /dev/null +++ b/virt-install-implement-boot-uefi-off.patch @@ -0,0 +1,292 @@ +From 3cb84bd5c53ce85073855eab7a373ba45143bbf1 Mon Sep 17 00:00:00 2001 +From: Cole Robinson +Date: Wed, 13 Nov 2024 17:33:30 -0500 +Subject: [PATCH 2/3] virt-install: implement `--boot uefi=off` + +Tells virt-install to not use UEFI, if it would normally default +to it. + +This likely isn't too useful in practice, since all occasions we +default to UEFI require it. But it future proofs opt out in case +we ever start defaulting to UEFI in cases where BIOS still works. + +Resolves: https://github.com/virt-manager/virt-manager/issues/692 + +Signed-off-by: Cole Robinson +Signed-off-by: Xianglai Li +--- + man/virt-install.rst | 5 +- + .../compare/virt-install-win11-no-uefi.xml | 192 ++++++++++++++++++ + virtinst/cli.py | 6 +- + virtinst/guest.py | 5 +- + 4 files changed, 203 insertions(+), 5 deletions(-) + create mode 100644 tests/data/cli/compare/virt-install-win11-no-uefi.xml + +diff --git a/man/virt-install.rst b/man/virt-install.rst +index 3a6e8dc..a68eed8 100644 +--- a/man/virt-install.rst ++++ b/man/virt-install.rst +@@ -951,12 +951,15 @@ Some examples: + has been specified, virt-install will default to /sbin/init, otherwise + will default to /bin/sh. + +-``--boot uefi`` ++``--boot uefi``, ``--boot uefi=on`` + Configure the VM to boot from UEFI. In order for virt-install to know the + correct UEFI parameters, libvirt needs to be advertising known UEFI binaries + via domcapabilities XML, so this will likely only work if using properly + configured distro packages. + ++``--boot uefi=off`` ++ Do not use UEFI if the VM would normally default to it. ++ + ``--boot loader=/.../OVMF_CODE.fd,loader.readonly=yes,loader.type=pflash,nvram.template=/.../OVMF_VARS.fd,loader_secure=no`` + Specify that the virtual machine use the custom OVMF binary as boot firmware, + mapped as a virtual flash chip. In addition, request that libvirt instantiate +diff --git a/tests/data/cli/compare/virt-install-win11-no-uefi.xml b/tests/data/cli/compare/virt-install-win11-no-uefi.xml +new file mode 100644 +index 0000000..58f559f +--- /dev/null ++++ b/tests/data/cli/compare/virt-install-win11-no-uefi.xml +@@ -0,0 +1,192 @@ ++ ++ win11 ++ 00000000-1111-2222-3333-444444444444 ++ ++ ++ ++ ++ ++ 65536 ++ 65536 ++ 4 ++ ++ hvm ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ /usr/bin/qemu-system-x86_64 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ destroy ++ ++ ++ win11 ++ 00000000-1111-2222-3333-444444444444 ++ ++ ++ ++ ++ ++ 65536 ++ 65536 ++ 4 ++ ++ hvm ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ /usr/bin/qemu-system-x86_64 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +diff --git a/virtinst/cli.py b/virtinst/cli.py +index 053d0a5..a4f8c88 100644 +--- a/virtinst/cli.py ++++ b/virtinst/cli.py +@@ -2780,15 +2780,15 @@ class ParserBoot(VirtCLIParser): + + def set_uefi_cb(self, inst, val, virtarg): + val = _on_off_convert("uefi", val) +- if not val: +- raise NotImplementedError() + + if not self.editing: + # From virt-install, we just set this flag, and set_defaults() + # will fill in everything for us, otherwise we have a circular + # dep on determining arch/machine info +- self.guest.uefi_requested = True ++ self.guest.uefi_requested = val + else: ++ if not val: ++ raise NotImplementedError() + self.guest.enable_uefi() + + def set_initargs_cb(self, inst, val, virtarg): +diff --git a/virtinst/guest.py b/virtinst/guest.py +index 86f6e14..1c91d24 100644 +--- a/virtinst/guest.py ++++ b/virtinst/guest.py +@@ -219,7 +219,7 @@ class Guest(XMLBuilder): + self.num_pcie_root_ports = 14 + + self.skip_default_osinfo = False +- self.uefi_requested = False ++ self.uefi_requested = None + self.__osinfo = None + self._capsinfo = None + self._domcaps = None +@@ -861,6 +861,9 @@ class Guest(XMLBuilder): + return path + + def _set_default_uefi(self): ++ if self.uefi_requested is False: ++ return ++ + use_default_uefi = (self.prefers_uefi() and + not self.os.kernel and + not self.os.loader and +-- +2.43.0 + diff --git a/virt-manager.spec b/virt-manager.spec index 6a2167e..8a528ce 100644 --- a/virt-manager.spec +++ b/virt-manager.spec @@ -2,7 +2,7 @@ Name: virt-manager Version: 4.1.0 -Release: 8 +Release: 9 Summary: The manage virtual machines tool which via libvirt. License: GPLv2+ BuildArch: noarch @@ -29,6 +29,9 @@ Patch17: backport-virt-install-unattended-and-cloud-init-conflict.pa Patch18: backport-virt-install-Reuse-cli.fail_conflicting.patch Patch19: backport-cli-support-boot-loader.stateless.patch Patch20: backport-diskbackend-Drop-support-for-sheepdog.patch +Patch21: cli-Add-stub-support-for-boot-uefi-on-off.patch +Patch22: virt-install-implement-boot-uefi-off.patch +Patch23: virt-xml-implement-edit-boot-uefi-off.patch Requires: virt-manager-common = %{version}-%{release} python3-gobject gtk3 libvirt-glib >= 0.0.9 Requires: gtk-vnc2 dconf vte291 gtksourceview4 @@ -106,6 +109,9 @@ done %{_mandir}/man1/{virt-install.1*,virt-clone.1*,virt-xml.1*} %changelog +* Thu Jul 24 2025 Xianglai Li - 4.1.0-9 +- fix virt-install location option can't boot kernel crorrectly on loongarch + * Wed Aug 21 2024 yanjianqing - 4.1.0-8 - diskbackend: Drop support for sheepdog - cli: support --boot loader.stateless= diff --git a/virt-xml-implement-edit-boot-uefi-off.patch b/virt-xml-implement-edit-boot-uefi-off.patch new file mode 100644 index 0000000..4362990 --- /dev/null +++ b/virt-xml-implement-edit-boot-uefi-off.patch @@ -0,0 +1,141 @@ +From 57121e77fb81a04ee30e919cea04f6485aa5bc0d Mon Sep 17 00:00:00 2001 +From: Cole Robinson +Date: Wed, 13 Nov 2024 17:41:50 -0500 +Subject: [PATCH 3/3] virt-xml: implement `--edit --boot uefi=off` + +Disable all UEFI config bits for an existing VM + +Signed-off-by: Cole Robinson +Signed-off-by: Xianglai Li +--- + .../compare/virt-xml-edit-boot-uefi-off.xml | 20 +++++++++++++++++++ + tests/data/testdriver/testdriver.xml | 8 ++++++++ + tests/test_cli.py | 2 +- + virtManager/object/domain.py | 6 +----- + virtinst/cli.py | 5 +++-- + virtinst/guest.py | 16 +++++++++++++++ + 6 files changed, 49 insertions(+), 8 deletions(-) + create mode 100644 tests/data/cli/compare/virt-xml-edit-boot-uefi-off.xml + +diff --git a/tests/data/cli/compare/virt-xml-edit-boot-uefi-off.xml b/tests/data/cli/compare/virt-xml-edit-boot-uefi-off.xml +new file mode 100644 +index 0000000..d05e925 +--- /dev/null ++++ b/tests/data/cli/compare/virt-xml-edit-boot-uefi-off.xml +@@ -0,0 +1,20 @@ ++ 134217728 ++ 67108864 ++ 2 ++- +++ ++ hvm ++- ++- ++- ++- ++- /usr/share/edk2/ovmf/OVMF_CODE.secboot.fd.qcow2 ++- ++- ++- ++ ++ ++ ++ ++Domain 'test-alternate-devs' defined successfully. ++Changes will take effect after the domain is fully powered off. +diff --git a/tests/data/testdriver/testdriver.xml b/tests/data/testdriver/testdriver.xml +index 04476b2..cd123b7 100644 +--- a/tests/data/testdriver/testdriver.xml ++++ b/tests/data/testdriver/testdriver.xml +@@ -715,7 +715,15 @@ test-many-devices, like an alternate RNG, EOL OS ID, title field + 2 + + ++ ++ ++ ++ + hvm ++ /usr/share/edk2/ovmf/OVMF_CODE.secboot.fd.qcow2 ++ ++ ++ + + + +diff --git a/tests/test_cli.py b/tests/test_cli.py +index bc570c6..5b9e0a8 100644 +--- a/tests/test_cli.py ++++ b/tests/test_cli.py +@@ -1359,7 +1359,7 @@ c.add_compare("--confirm 1 --edit --cpu host-passthrough", "prompt-response", in + c.add_compare("--edit --print-diff --qemu-commandline clearxml=yes", "edit-clearxml-qemu-commandline", input_file=(_VIRTXMLDIR + "virtxml-qemu-commandline-clear.xml")) + c.add_compare("--print-diff --remove-device --serial 1", "remove-console-dup", input_file=(_VIRTXMLDIR + "virtxml-console-dup.xml")) + c.add_compare("--print-diff --define --connect %(URI-KVM-X86)s test --edit --boot uefi", "edit-boot-uefi") +-c.add_invalid("--print-diff --define --connect %(URI-KVM-X86)s test-alternate-devs --edit --boot uefi=off", grep="NotImplementedError") ++c.add_compare("--print-diff --define --connect %(URI-KVM-X86)s test-alternate-devs --edit --boot uefi=off", "edit-boot-uefi-off") + c.add_compare("--print-diff --define --connect %(URI-KVM-X86)s test-many-devices --edit --cpu host-copy", "edit-cpu-host-copy") + c.add_compare("--connect %(URI-KVM-X86)s test-many-devices --build-xml --disk source.pool=pool-disk,source.volume=sdfg1", "build-pool-logical-disk") + c.add_compare("test --add-device --network default --update --confirm", "update-succeed", env={"VIRTXML_TESTSUITE_UPDATE_IGNORE_FAIL": "1", "VIRTINST_TEST_SUITE_INCREMENT_MACADDR": "1"}, input_text="yes\nyes\n") # test hotplug success +diff --git a/virtManager/object/domain.py b/virtManager/object/domain.py +index 2d6f5bc..9aba059 100644 +--- a/virtManager/object/domain.py ++++ b/virtManager/object/domain.py +@@ -739,11 +739,7 @@ class vmmDomain(vmmLibvirtObject): + # preserve NVRAM paths, so skip clearing all the properties + # and let libvirt do it for us. + if firmware is None: +- # Implies 'default', so clear everything +- guest.os.loader_ro = None +- guest.os.loader_type = None +- guest.os.nvram = None +- guest.os.nvram_template = None ++ guest.disable_uefi() + else: + # Implies UEFI + guest.set_uefi_path(loader) +diff --git a/virtinst/cli.py b/virtinst/cli.py +index a4f8c88..59529d3 100644 +--- a/virtinst/cli.py ++++ b/virtinst/cli.py +@@ -2788,8 +2788,9 @@ class ParserBoot(VirtCLIParser): + self.guest.uefi_requested = val + else: + if not val: +- raise NotImplementedError() +- self.guest.enable_uefi() ++ self.guest.disable_uefi() ++ else: ++ self.guest.enable_uefi() + + def set_initargs_cb(self, inst, val, virtarg): + inst.set_initargs_string(val) +diff --git a/virtinst/guest.py b/virtinst/guest.py +index 1c91d24..38e7edd 100644 +--- a/virtinst/guest.py ++++ b/virtinst/guest.py +@@ -591,6 +591,22 @@ class Guest(XMLBuilder): + log.debug("Setting default UEFI path=%s", path) + self.set_uefi_path(path) + ++ def disable_uefi(self): ++ self.os.firmware = None ++ self.os.loader = None ++ self.os.loader_ro = None ++ self.os.loader_type = None ++ self.os.loader_secure = None ++ self.os.nvram = None ++ self.os.nvram_template = None ++ for feature in self.os.firmware_features: ++ self.os.remove_child(feature) ++ ++ # Force remove any properties we don't know about ++ self._xmlstate.xmlapi.node_force_remove("./os/firmware") ++ self._xmlstate.xmlapi.node_force_remove("./os/nvram") ++ self._xmlstate.xmlapi.node_force_remove("./os/loader") ++ + def has_spice(self): + for gfx in self.devices.graphics: + if gfx.type == gfx.TYPE_SPICE: +-- +2.43.0 + -- Gitee