lanzaboote/rust/lanzatool/src/install.rs

55 lines
1.4 KiB
Rust
Raw Normal View History

2022-11-23 09:26:26 -05:00
use std::fs;
use std::path::Path;
use anyhow::Result;
use crate::bootspec::Bootspec;
use crate::esp::EspPaths;
2022-11-23 14:40:01 -05:00
use crate::pe;
pub fn install(
_: &Path,
bootspec: &Path,
lanzaboote_stub: &Path,
initrd_stub: &Path,
) -> Result<()> {
2022-11-23 09:26:26 -05:00
let bootspec_doc: Bootspec = serde_json::from_slice(&fs::read(bootspec)?)?;
let esp_paths = EspPaths::new(&bootspec_doc.v1.extension.esp);
2022-11-23 14:40:01 -05:00
let lanzaboote_image = pe::assemble_image(
lanzaboote_stub,
2022-11-23 09:26:26 -05:00
&bootspec_doc.v1.extension.os_release,
&bootspec_doc.v1.kernel_params,
&esp_paths.kernel,
&esp_paths.initrd,
)
2022-11-23 11:16:08 -05:00
.expect("Failed to assemble stub");
2022-11-23 09:26:26 -05:00
2022-11-23 14:40:01 -05:00
let wrapped_initrd =
pe::wrap_initrd(initrd_stub, &bootspec_doc.v1.initrd).expect("Failed to assemble stub");
2022-11-23 09:26:26 -05:00
// Copy the files to the ESP
fs::create_dir_all(&esp_paths.nixos)?;
fs::copy(bootspec_doc.v1.kernel, esp_paths.kernel)?;
2022-11-23 14:40:01 -05:00
fs::copy(wrapped_initrd, esp_paths.initrd)?;
fs::create_dir_all(&esp_paths.linux)?;
fs::copy(lanzaboote_image, esp_paths.lanzaboote_image)?;
2022-11-23 09:26:26 -05:00
let systemd_boot = bootspec_doc
.v1
.extension
.systemd
.join("lib/systemd/boot/efi/systemd-bootx64.efi");
fs::create_dir_all(esp_paths.efi_fallback_dir)?;
fs::copy(&systemd_boot, esp_paths.efi_fallback)?;
fs::create_dir_all(&esp_paths.systemd)?;
fs::copy(&systemd_boot, esp_paths.systemd_boot)?;
2022-11-23 09:26:26 -05:00
Ok(())
}