lanzatool: implement copying sdboot to esp

This commit is contained in:
nikstur 2022-11-24 11:10:19 +01:00
parent 73b1f7e2b5
commit 3e7f5fa625
4 changed files with 24 additions and 21 deletions

View File

@ -17,6 +17,7 @@
"toplevel": "/run/current-system", "toplevel": "/run/current-system",
"extension": { "extension": {
"esp": "esp", "esp": "esp",
"systemd": "/run/current-system/systemd",
"bootctl": "/run/current-system/sw/bin/bootctl", "bootctl": "/run/current-system/sw/bin/bootctl",
"osRelease": "/etc/os-release" "osRelease": "/etc/os-release"
} }

View File

@ -33,4 +33,5 @@ pub struct Extension {
pub esp: String, pub esp: String,
pub bootctl: PathBuf, pub bootctl: PathBuf,
pub os_release: PathBuf, pub os_release: PathBuf,
pub systemd: PathBuf,
} }

View File

@ -7,6 +7,10 @@ pub struct EspPaths {
pub initrd: PathBuf, pub initrd: PathBuf,
pub linux: PathBuf, pub linux: PathBuf,
pub lanzaboote_image: PathBuf, pub lanzaboote_image: PathBuf,
pub efi_fallback_dir: PathBuf,
pub efi_fallback: PathBuf,
pub systemd: PathBuf,
pub systemd_boot: PathBuf,
} }
impl EspPaths { impl EspPaths {
@ -14,6 +18,8 @@ impl EspPaths {
let esp = Path::new(esp); let esp = Path::new(esp);
let esp_nixos = esp.join("EFI/nixos"); let esp_nixos = esp.join("EFI/nixos");
let esp_linux = esp.join("EFI/Linux"); let esp_linux = esp.join("EFI/Linux");
let esp_systemd = esp.join("EFI/systemd");
let esp_efi_fallback_dir = esp.join("EFI/BOOT");
Self { Self {
esp: esp.to_owned(), esp: esp.to_owned(),
@ -22,6 +28,10 @@ impl EspPaths {
initrd: esp_nixos.join("initrd"), initrd: esp_nixos.join("initrd"),
linux: esp_linux.clone(), linux: esp_linux.clone(),
lanzaboote_image: esp_linux.join("lanzaboote-image.efi"), lanzaboote_image: esp_linux.join("lanzaboote-image.efi"),
efi_fallback_dir: esp_efi_fallback_dir.clone(),
efi_fallback: esp_efi_fallback_dir.join("BOOTX64.EFI"),
systemd: esp_systemd.clone(),
systemd_boot: esp_systemd.join("systemd-bootx64.efi"),
} }
} }
} }

View File

@ -1,7 +1,6 @@
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::process::Command;
use anyhow::Result; use anyhow::Result;
@ -38,26 +37,18 @@ pub fn install(
fs::create_dir_all(&esp_paths.linux)?; fs::create_dir_all(&esp_paths.linux)?;
fs::copy(lanzaboote_image, esp_paths.lanzaboote_image)?; fs::copy(lanzaboote_image, esp_paths.lanzaboote_image)?;
// install_systemd_boot(bootctl, &esp)?;
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)?;
Ok(()) Ok(())
} }
fn _install_systemd_boot(bootctl: &Path, esp: &Path) -> Result<()> {
let args = vec![
String::from("install"),
String::from("--path"),
esp.display().to_string(),
];
let status = Command::new(&bootctl).args(&args).status()?;
if !status.success() {
return Err(anyhow::anyhow!(
"Failed success run `{}` with args `{:?}`",
&bootctl.display(),
&args
)
.into());
}
Ok(())
}