diff --git a/Cargo.lock b/Cargo.lock index d2fb0bf9..5dfa5d8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,9 +154,9 @@ dependencies = [ ] [[package]] -name = "blockdev" +name = "bootc-blockdev" version = "0.0.0" -source = "git+https://github.com/containers/bootc?rev=9a586935e3c88a3802ea4308b0ec364b6448c59e#9a586935e3c88a3802ea4308b0ec364b6448c59e" +source = "git+https://github.com/containers/bootc?rev=69264e0836c07d2203b29b780cdb8c6dcddfffbc#69264e0836c07d2203b29b780cdb8c6dcddfffbc" dependencies = [ "anyhow", "bootc-utils", @@ -171,7 +171,7 @@ dependencies = [ [[package]] name = "bootc-utils" version = "0.0.0" -source = "git+https://github.com/containers/bootc?rev=9a586935e3c88a3802ea4308b0ec364b6448c59e#9a586935e3c88a3802ea4308b0ec364b6448c59e" +source = "git+https://github.com/containers/bootc?rev=69264e0836c07d2203b29b780cdb8c6dcddfffbc#69264e0836c07d2203b29b780cdb8c6dcddfffbc" dependencies = [ "anyhow", "rustix", @@ -180,6 +180,7 @@ dependencies = [ "tempfile", "tokio", "tracing", + "tracing-subscriber", ] [[package]] @@ -188,7 +189,7 @@ version = "0.2.26" dependencies = [ "anyhow", "bincode", - "blockdev", + "bootc-blockdev", "bootc-utils", "camino", "cap-std-ext", @@ -660,6 +661,15 @@ version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "maybe-owned" version = "0.3.4" @@ -751,6 +761,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-traits" version = "0.2.17" @@ -843,6 +863,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "pin-project-lite" version = "0.2.16" @@ -917,8 +943,17 @@ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.8", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -929,9 +964,15 @@ checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.5", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.5" @@ -1017,6 +1058,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -1026,6 +1076,12 @@ dependencies = [ "libc", ] +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "strsim" version = "0.11.1" @@ -1082,6 +1138,16 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tokio" version = "1.43.0" @@ -1126,6 +1192,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -1156,6 +1252,12 @@ dependencies = [ "serde", ] +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 4c12716d..27c12cd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,8 @@ path = "src/main.rs" [dependencies] anyhow = "1.0" bincode = "1.3.2" -bootc-blockdev = { git = "https://github.com/containers/bootc", rev = "9a586935e3c88a3802ea4308b0ec364b6448c59e", package = "blockdev" } -bootc-utils = { git = "https://github.com/containers/bootc", rev = "9a586935e3c88a3802ea4308b0ec364b6448c59e" } +bootc-blockdev = { git = "https://github.com/containers/bootc", rev = "69264e0836c07d2203b29b780cdb8c6dcddfffbc" } +bootc-utils = { git = "https://github.com/containers/bootc", rev = "69264e0836c07d2203b29b780cdb8c6dcddfffbc" } cap-std-ext = "4.0.4" camino = "1.1.9" chrono = { version = "0.4.39", features = ["serde"] } diff --git a/src/bios.rs b/src/bios.rs index 2e85f01c..fa549c40 100644 --- a/src/bios.rs +++ b/src/bios.rs @@ -1,4 +1,6 @@ use anyhow::{bail, Result}; +#[cfg(target_arch = "powerpc64")] +use std::borrow::Cow; use std::io::prelude::*; use std::os::unix::io::AsRawFd; use std::path::Path; @@ -12,6 +14,31 @@ use crate::packagesystem; // grub2-install file path pub(crate) const GRUB_BIN: &str = "usr/sbin/grub2-install"; +#[cfg(target_arch = "powerpc64")] +fn target_device(device: &str) -> Result> { + const PREPBOOT_GUID: &str = "9E1A2D38-C612-4316-AA26-8B49521E5A8B"; + /// We make a best-effort to support MBR partitioning too. + const PREPBOOT_MBR_TYPE: &str = "41"; + + // Here we use lsblk to see if the device has any partitions at all + let dev = bootc_blockdev::list_dev(device.into())?; + if dev.children.is_some() { + return Ok(device.into()); + }; + drop(dev); + // If it does, directly call `sfdisk` and bypass lsblk because inside a container + // we may not have all the cached udev state (that I think is in /run). + let device = bootc_blockdev::partitions_of(device.into())?; + let prepdev = device + .partitions + .iter() + .find(|p| matches!(p.parttype.as_str(), PREPBOOT_GUID | PREPBOOT_MBR_TYPE)) + .ok_or_else(|| { + anyhow::anyhow!("Failed to find PReP partition with GUID {PREPBOOT_GUID}") + })?; + Ok(prepdev.path().as_str().to_owned().into()) +} + #[derive(Default)] pub(crate) struct Bios {} @@ -54,10 +81,13 @@ impl Bios { .arg(device); #[cfg(target_arch = "powerpc64")] - cmd.args(&["--target", "powerpc-ieee1275"]) - .args(&["--boot-directory", boot_dir.to_str().unwrap()]) - .arg("--no-nvram") - .arg(device); + { + let device = target_device(device)?; + cmd.args(&["--target", "powerpc-ieee1275"]) + .args(&["--boot-directory", boot_dir.to_str().unwrap()]) + .arg("--no-nvram") + .arg(&*device); + } let cmdout = cmd.output()?; if !cmdout.status.success() {