Skip to content

Commit

Permalink
[draft] bootloader: Use lsblk
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Jul 12, 2024
1 parent 9103908 commit e762cf6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
51 changes: 23 additions & 28 deletions lib/src/bootloader.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,48 @@
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<Utf8PathBuf> {
#[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(
device: &Utf8Path,
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()
Expand Down
2 changes: 1 addition & 1 deletion lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e762cf6

Please sign in to comment.