[gnome-boxes/allow-booting-from-cdrom: 4/4] libvirt-machine: Enable boot menu for VMs with a CD/DVD assigned
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/allow-booting-from-cdrom: 4/4] libvirt-machine: Enable boot menu for VMs with a CD/DVD assigned
- Date: Mon, 5 Aug 2019 08:57:27 +0000 (UTC)
commit 315bf5b525c9dfdaf90e10e08ab3639411a2509e
Author: Felipe Borges <felipeborges gnome org>
Date: Thu Aug 1 10:54:08 2019 +0200
libvirt-machine: Enable boot menu for VMs with a CD/DVD assigned
Whenever a VM has a CD/DVD assigned to it (Properties -> Devices & Shares),
we show the boot menu during boot. This way users can press Escape
and pick the boot device they want.
This is very useful for users wanting to rescue broken VMs or users
that want to reproduce a dual-boot setup in a single virtual disk.
Fixes #34
src/libvirt-machine-properties.vala | 4 ++++
src/vm-configurator.vala | 24 ++++++++++++++++++++++++
2 files changed, 28 insertions(+)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 59673d23..16af2237 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -237,6 +237,10 @@ private void add_cdrom_property (GVirConfig.DomainDisk disk_config, ref List<Box
debug ("Error ejecting CD from '%s': %s", machine.name, e.message);
}
}
+
+ /* Enable/disable boot menu */
+ VMConfigurator.enable_boot_menu (machine.domain_config, !empty);
+ machine.domain.set_config (machine.domain_config);
});
var property = add_property (ref list, _("CD/DVD"), grid);
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 798e9dd2..2bf08934 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -265,6 +265,7 @@ public static async void update_existing_domain (Domain domain,
DomainInterface iface = null;
DomainGraphicsSpice graphics = null;
DomainChannel channel_webdav = null;
+ bool supports_alternative_boot_device = false;
foreach (var device in domain.get_devices ()) {
if (device is DomainInterface)
iface = device as DomainInterface;
@@ -276,6 +277,16 @@ else if (device is DomainChannel) {
channel_webdav = device_channel;
devices.prepend (device);
}
+ else if (device is DomainDisk) {
+ var domain_disk = device as DomainDisk;
+ var device_type = domain_disk.get_guest_device_type ();
+ if (device_type == DomainDiskGuestDeviceType.CDROM) {
+ if (domain_disk.get_source () != null)
+ supports_alternative_boot_device = true;
+ }
+
+ devices.prepend (device);
+ }
else
devices.prepend (device);
}
@@ -292,6 +303,8 @@ else if (device is DomainChannel) {
}
}
+ enable_boot_menu (domain, supports_alternative_boot_device);
+
if (graphics != null)
devices.prepend (create_graphics_device ());
if (channel_webdav == null)
@@ -301,6 +314,17 @@ else if (device is DomainChannel) {
domain.set_devices (devices);
}
+ public static void enable_boot_menu (Domain domain, bool enable) {
+ try {
+ var os = new DomainOs.from_xml (domain.get_os ().to_xml ());
+ os.enable_boot_menu (enable);
+
+ domain.set_os (os);
+ } catch (GLib.Error error) {
+ warning ("Failed to enable boot menu\n");
+ }
+ }
+
public static void set_target_media_config (Domain domain,
string target_path,
InstallerMedia install_media,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]