Skip to content

Commit 6ad2b9c

Browse files
committed
(wip) Add boot mode support
1 parent 6828311 commit 6ad2b9c

3 files changed

Lines changed: 56 additions & 5 deletions

File tree

qubes/vm/appvm.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ def template_changed_update_storage(self):
4040
self.storage.init_volume(volume_name, config)
4141

4242

43+
def template_changed_update_bootmode(self):
44+
"""Update boot mode configuration for TemplateVM changes"""
45+
if self.template.features.get("boot-mode.appvm-default", None) is None:
46+
self.template.features["boot-mode.appvm-default"] = "default"
47+
active_boot_mode = self.template.features["boot-mode.appvm-default"]
48+
try:
49+
_ = self.features.check_with_template(
50+
f"boot-mode.{active_boot_mode}.kernelopts"
51+
)
52+
self.features["boot-mode.active"] = active_boot_mode
53+
except KeyError:
54+
self.template.features["boot-mode.appvm-default"] = "default"
55+
self.features["boot-mode.active"] = "default"
56+
57+
4358
class AppVM(
4459
qubes.vm.mix.dvmtemplate.DVMTemplateMixin, qubes.vm.qubesvm.QubesVM
4560
):
@@ -149,8 +164,10 @@ def on_property_pre_set_template(
149164
@qubes.events.handler("property-set:template")
150165
def on_property_set_template(self, event, name, newvalue, oldvalue=None):
151166
"""Adjust root (and possibly other snap_on_start=True) volume
152-
on template change.
167+
on template change. Also switch active boot mode to match that set by
168+
the template.
153169
""" # pylint: disable=unused-argument
154170
template_changed_update_storage(self)
171+
template_changed_update_bootmode(self)
155172
for vm in self.dispvms:
156173
vm.on_property_set_template(event, name, newvalue, oldvalue)

qubes/vm/qubesvm.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,27 @@ def _setter_kbd_layout(self, prop, value):
216216
return value
217217

218218

219+
def _bootmode_kernelopts(self):
220+
"""
221+
Return the kernel options specified by the currently active boot mode,
222+
with a leading space. Force the VM's boot mode to 'default' if the active
223+
boot mode does not exist. If the active boot mode is (or ends up set to)
224+
'default', return an empty string.
225+
"""
226+
if self.features.get("boot-mode.active", None) is None:
227+
self.features["boot-mode.active"] = "default"
228+
if self.features["boot-mode.active"] == "default":
229+
return ""
230+
active_boot_mode = self.features["boot-mode.active"]
231+
try:
232+
return self.features.check_with_template(
233+
f"boot-mode.{active_boot_mode}.kernelopts"
234+
)
235+
except KeyError:
236+
self.features["boot-mode.active"] = "default"
237+
return ""
238+
239+
219240
def _default_virt_mode(self):
220241
if list(self.devices["pci"].get_assigned_devices()):
221242
return "hvm"
@@ -659,6 +680,15 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
659680
#
660681
# properties loaded from XML
661682
#
683+
bootmode_kernelopts = qubes.property(
684+
"bootmode_kernelopts",
685+
type=str,
686+
load_stage=4,
687+
default=_bootmode_kernelopts,
688+
doc="Additional kernel command line segment passed to domain, set by "
689+
"the domain's active boot mode."
690+
)
691+
662692
guivm = qubes.VMProperty(
663693
"guivm",
664694
load_stage=4,

templates/libvirt/xen.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@
6262
{% endif %}
6363
{% if vm.kernel %}
6464
{% if vm.features.check_with_template('no-default-kernelopts', False) -%}
65-
<cmdline>{{ vm.kernelopts }}</cmdline>
65+
<cmdline>{{ vm.kernelopts }}{{ vm.bootmode_kernelopts }}</cmdline>
6666
{% elif vm.features.check_with_template('apparmor', '0') == '1' -%}
67-
<cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }} apparmor=1 security=apparmor</cmdline>
67+
<cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }} apparmor=1 security=apparmor{{ vm.bootmode_kernelopts }}</cmdline>
6868
{% elif vm.features.check_with_template('selinux', '0') == '1' -%}
69-
<cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }} selinux=1 security=selinux</cmdline>
69+
<cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }} selinux=1 security=selinux{{ vm.bootmode_kernelopts }}</cmdline>
7070
{% else -%}
71-
<cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }}</cmdline>
71+
<cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }}{{ vm.bootmode_kernelopts }}</cmdline>
7272
{% endif -%}
7373
{% endif %}
74+
<!--
75+
Support for appending vm.bootmode_kernelopts to the kernel
76+
commandline for in-VM kernels should be added here.
77+
-->
7478
{% endblock %}
7579
</os>
7680

0 commit comments

Comments
 (0)