[gnome-boxes/add-opt-in-efi-support: 2/3] assistant, installer-media: Restore EFI support (opt-in)
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/add-opt-in-efi-support: 2/3] assistant, installer-media: Restore EFI support (opt-in)
- Date: Thu, 23 Dec 2021 12:03:20 +0000 (UTC)
commit 56355d63aa0a83d4428438c85abc247c2230179c
Author: Felipe Borges <felipeborges gnome org>
Date: Thu Dec 23 12:31:46 2021 +0100
assistant, installer-media: Restore EFI support (opt-in)
When EFI is supported by the hypervisor AND by the operating system
detected in the source InstallerMedia, we will show a toggle to
Enable it at the VM creation Assistant.
This option is opt-in, since we prefer most users continue using
the legacy BIOS firmware because of its support for Snapshots.
Fixes #620
src/assistant/review-page.vala | 27 +++++++++++++++++++++++++--
src/installer-media.vala | 17 +++++++++++++----
src/vm-configurator.vala | 31 ++++---------------------------
3 files changed, 42 insertions(+), 33 deletions(-)
---
diff --git a/src/assistant/review-page.vala b/src/assistant/review-page.vala
index 42e6a21a..0353ba5f 100644
--- a/src/assistant/review-page.vala
+++ b/src/assistant/review-page.vala
@@ -21,6 +21,10 @@
private unowned Hdy.ActionRow unattended_password_row;
[GtkChild]
private unowned Gtk.Label password_label;
+ [GtkChild]
+ private unowned Hdy.ActionRow uefi_row;
+ [GtkChild]
+ private unowned Gtk.Switch uefi_switch;
private GLib.Cancellable? cancellable;
@@ -47,9 +51,10 @@ public async void populate (LibvirtMachine machine) {
ram_row.setup (machine);
storage_row.setup (machine);
+ var install_media = machine.vm_creator.install_media;
bool show_unattended_rows = false;
- if (machine.vm_creator.install_media is Boxes.UnattendedInstaller) {
- var installer = machine.vm_creator.install_media as Boxes.UnattendedInstaller;
+ if (install_media is Boxes.UnattendedInstaller) {
+ var installer = install_media as Boxes.UnattendedInstaller;
show_unattended_rows = installer.setup_box.express_toggle.active;
if (!show_unattended_rows)
@@ -59,6 +64,24 @@ public async void populate (LibvirtMachine machine) {
password_label.label = installer.setup_box.hidden_password;
}
unattended_username_row.visible = unattended_password_row.visible = show_unattended_rows;
+
+ uefi_row.visible = install_media.supports_efi;
+ }
+
+ [GtkCallback]
+ private void on_uefi_switch_toggled () {
+ LibvirtMachine machine = artifact as LibvirtMachine;
+ bool use_uefi = uefi_switch.get_active ();
+
+ try {
+ InstallerMedia install_media = machine.vm_creator.install_media;
+ install_media.set_uefi_firmware (machine.domain_config, use_uefi);
+
+ machine.domain.set_config (machine.domain_config);
+ debug ("Setting firmware to %s", use_uefi ? "EFI" : "BIOS");
+ } catch (GLib.Error error) {
+ warning ("Failed to toggle UEFI support: %s", error.message);
+ }
}
public override void cleanup () {
diff --git a/src/installer-media.vala b/src/installer-media.vala
index b14d0c06..4829c587 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -62,14 +62,13 @@
if (os == null)
return false;
- return (os.get_id ().has_prefix("http://gnome.org/gnome/"));
-
- /*foreach (var iter in os.get_firmware_list (null) .get_elements ()) {
+ foreach (var iter in os.get_firmware_list (null).get_elements ()) {
var firmware = iter as Firmware;
if (firmware.get_firmware_type () == "efi")
return true;
}
- return false;*/
+
+ return false;
}
}
@@ -353,4 +352,14 @@ private void eject_cdrom_media (Domain domain) {
domain.set_devices (devices);
}
+ public void set_uefi_firmware (Domain domain, bool use_uefi) {
+ try {
+ var os = new DomainOs.from_xml (domain.get_os ().to_xml ());
+ os.set_firmware (use_uefi ? DomainOsFirmware.EFI : DomainOsFirmware.BIOS);
+ domain.set_os (os);
+ } catch (GLib.Error error) {
+ warning ("Failed to set %s firmware: %s", use_uefi ? "EFI" : "BIOS",
+ error.message);
+ }
+ }
}
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 75008cc1..e48a7506 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -407,31 +407,13 @@ private static void set_post_install_os_config (Domain domain) {
os.set_arch (old_os.get_arch ());
os.set_machine (old_os.get_machine ());
-#if USE_UEFI
- if (old_os.get_firmware () == GVirConfig.DomainOsFirmware.EFI)
- os.set_firmware (GVirConfig.DomainOsFirmware.EFI);
-#endif
-
- domain.set_os (os);
- }
- private static bool domain_caps_supports_efi (DomainCapabilities domain_caps) {
- foreach (var firmware in domain_caps.get_os ().get_firmwares()) {
- if (firmware == GVirConfig.DomainOsFirmware.EFI)
- return true;
+ if (old_os.get_firmware () == GVirConfig.DomainOsFirmware.EFI) {
+ if (App.app.supports_uefi_installs ())
+ os.set_firmware (GVirConfig.DomainOsFirmware.EFI);
}
- return false;
- }
-
- private static bool supports_efi (InstallerMedia install_media, DomainCapabilities domain_caps) {
- if (install_media == null || !install_media.supports_efi)
- return false;
-
- if (domain_caps == null || !domain_caps_supports_efi (domain_caps))
- return false;
-
- return true;
+ domain.set_os (os);
}
private static void set_os_config (Domain domain, InstallerMedia install_media, CapabilitiesGuest
guest_caps, DomainCapabilities domain_caps) {
@@ -441,11 +423,6 @@ private static void set_os_config (Domain domain, InstallerMedia install_media,
if (install_media.prefers_q35)
os.set_machine ("q35");
-#if USE_UEFI
- if (supports_efi (install_media, domain_caps))
- os.set_firmware (GVirConfig.DomainOsFirmware.EFI);
-#endif
-
var boot_devices = new GLib.List<DomainOsBootDevice> ();
install_media.set_direct_boot_params (os);
boot_devices.append (DomainOsBootDevice.CDROM);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]