From e762cf6634e4402c4db78438e9afe56eb53e5321 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 12 Jul 2024 14:08:12 -0400 Subject: [PATCH] [draft] bootloader: Use lsblk Signed-off-by: Colin Walters --- lib/src/bootloader.rs | 51 +++++++++++++++++-------------------- lib/src/install/baseline.rs | 2 +- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/lib/src/bootloader.rs b/lib/src/bootloader.rs index b8b1b557..80d203ad 100644 --- a/lib/src/bootloader.rs +++ b/lib/src/bootloader.rs @@ -1,13 +1,31 @@ -use std::process::Command; -use std::str; use anyhow::Result; -use camino::Utf8Path; +use camino::{Utf8Path, Utf8PathBuf}; use fn_error_context::context; use crate::task::Task; /// The name of the mountpoint for efi (as a subdirectory of /boot, or at the toplevel) pub(crate) const EFI_DIR: &str = "efi"; +pub(crate) const PREPBOOT_LABEL: &str = "PowerPC-PReP-boot"; + +/// Find the device to pass to bootupd. Only on powerpc64 right now +/// we explicitly find one with a specific label. +/// +/// This should get fixed once we execute on https://github.com/coreos/bootupd/issues/432 +fn get_bootupd_device(device: &Utf8Path) -> Result { + #[cfg(target_arch = "powerpc64")] + { + return crate::blockdev::list_dev(device)? + .children + .unwrap_or_default() + .into_iter() + .find(|dev| dev.label.as_deref() == Some(PREPBOOT_LABEL)) + .ok_or_else(|| anyhow::anyhow!("Failed to find partition with label {PREPBOOT_LABEL}")) + .map(|dev| dev.path().into()); + } + #[cfg(not(target_arch = "powerpc64"))] + return Ok(device.to_owned()); +} #[context("Installing bootloader")] pub(crate) fn install_via_bootupd( @@ -15,39 +33,16 @@ pub(crate) fn install_via_bootupd( rootfs: &Utf8Path, configopts: &crate::install::InstallConfigOpts, ) -> Result<()> { - let device_str: &str; - let prepboot_dir; let verbose = std::env::var_os("BOOTC_BOOTLOADER_DEBUG").map(|_| "-vvvv"); // bootc defaults to only targeting the platform boot method. let bootupd_opts = (!configopts.generic_image).then_some(["--update-firmware", "--auto"]); - if cfg!(target_arch = "powerpc64") { - // get PowerPC-PReP-boot device information - let result = Command::new("lsblk") - .args([ - "--noheadings", - "--paths", - "--filter", - &(format!(r#"'PARTLABEL=="PowerPC-PReP-boot"'"#)), - "--output", - &(format!("NAME")), - ]) - .arg(device) - .output()?; - if !result.status.success() { - println!("{}", String::from_utf8_lossy(&result.stderr)); - anyhow::bail!("lsblkh failed with {}", result.status); - } - prepboot_dir = String::from_utf8(result.stdout)?; - device_str = prepboot_dir.trim(); - } else { - device_str = device.as_str() - } + let target_device = get_bootupd_device(device)?; let args = ["backend", "install", "--write-uuid"] .into_iter() .chain(verbose) .chain(bootupd_opts.iter().copied().flatten()) - .chain(["--device", device_str, rootfs.as_str()]); + .chain(["--device", target_device.as_str(), rootfs.as_str()]); Task::new("Running bootupctl to install bootloader", "bootupctl") .args(args) .verbose() diff --git a/lib/src/install/baseline.rs b/lib/src/install/baseline.rs index f60c6bc6..09661ecd 100644 --- a/lib/src/install/baseline.rs +++ b/lib/src/install/baseline.rs @@ -265,7 +265,7 @@ pub(crate) fn install_create_rootfs( &mut sgdisk.cmd, partno, "0:+4M", - "PowerPC-PReP-boot", + crate::bootloader::PREPBOOT_LABEL, Some("9E1A2D38-C612-4316-AA26-8B49521E5A8B"), ); } else {