Skip to content

Commit 5ff7bcc

Browse files
committed
libvirt: Fix custom secure boot logic
- The nvram path needs to be absolute (would be nice if we could pass this as a file descriptor instead, but hard to do AFAIK with libvirt today) - When a custom nvram is specified, we need to avoid using firmware="efi" as it's mutually exclusive with explicit <loader> paths - Also need to explicitly specify `raw` format for nvram No tests yet, but I did test this locally as part of updating bootc's composefs+UKI integration test suite. Signed-off-by: Colin Walters <[email protected]>
1 parent 92cc086 commit 5ff7bcc

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

crates/kit/src/libvirt/domain.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,12 @@ impl DomainBuilder {
209209
&& (self.firmware == Some(FirmwareType::UefiSecure) || self.ovmf_code_path.is_some());
210210
let insecure_boot = self.firmware == Some(FirmwareType::UefiInsecure);
211211

212-
if use_uefi {
213-
writer.start_element("os", &[("firmware", "efi")])?;
214-
} else {
215-
writer.start_element("os", &[])?;
216-
}
212+
// Don't use firmware="efi" when we have custom OVMF paths (secure boot with custom keys)
213+
// because firmware="efi" and explicit <loader> paths are mutually exclusive
214+
let os_attributes = (use_uefi && self.ovmf_code_path.is_none())
215+
.then_some([("firmware", "efi")].as_slice())
216+
.unwrap_or_default();
217+
writer.start_element("os", os_attributes)?;
217218

218219
// For secure boot on x86_64, we may need a specific machine type with SMM
219220
let machine_type = if secure_boot && arch_config.arch == "x86_64" {
@@ -231,7 +232,8 @@ impl DomainBuilder {
231232
if use_uefi {
232233
if let Some(ref ovmf_code) = self.ovmf_code_path {
233234
// Use custom OVMF_CODE path for secure boot
234-
let mut loader_attrs = vec![("readonly", "yes"), ("type", "pflash")];
235+
let mut loader_attrs =
236+
vec![("readonly", "yes"), ("type", "pflash"), ("format", "raw")];
235237
if secure_boot {
236238
loader_attrs.push(("secure", "yes"));
237239
}
@@ -242,7 +244,11 @@ impl DomainBuilder {
242244
writer.write_text_element_with_attrs(
243245
"nvram",
244246
"", // Empty content, template attr provides the source
245-
&[("template", nvram_template)],
247+
&[
248+
("template", nvram_template),
249+
("templateFormat", "raw"),
250+
("format", "raw"),
251+
],
246252
)?;
247253
}
248254
} else if secure_boot {

crates/kit/src/libvirt/run.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,13 @@ fn create_libvirt_domain_from_disk(
11311131
if let Some(ref sb_config) = secure_boot_config {
11321132
let ovmf_code = crate::libvirt::secureboot::find_ovmf_code_secboot()
11331133
.context("Failed to find OVMF_CODE.secboot.fd")?;
1134+
let sb_vars_path = sb_config
1135+
.vars_template
1136+
.canonicalize_utf8()
1137+
.context("Canonicalizing secureboot vars path")?;
11341138
domain_builder = domain_builder
11351139
.with_ovmf_code_path(ovmf_code.as_str())
1136-
.with_nvram_template(sb_config.vars_template.as_str());
1140+
.with_nvram_template(sb_vars_path.as_str());
11371141

11381142
// Add secure boot keys path to metadata for reference
11391143
domain_builder =

0 commit comments

Comments
 (0)