Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,17 @@ todo = "deny"
needless_borrow = "allow"
needless_borrows_for_generic_args = "allow"


# Image platform selection for --target-arch is not yet in released
# composefs-rs or ocidir. All composefs crates come from the same branch
# so their types stay compatible.
[patch.crates-io]
composefs = { git = "https://github.com/mattmoor/composefs-rs", branch = "pull-platform" }
Comment on lines +139 to +140
composefs-boot = { git = "https://github.com/mattmoor/composefs-rs", branch = "pull-platform" }
composefs-ctl = { git = "https://github.com/mattmoor/composefs-rs", branch = "pull-platform" }
composefs-fuse = { git = "https://github.com/mattmoor/composefs-rs", branch = "pull-platform" }
composefs-ioctls = { git = "https://github.com/mattmoor/composefs-rs", branch = "pull-platform" }
composefs-oci = { git = "https://github.com/mattmoor/composefs-rs", branch = "pull-platform" }
composefs-splitdirfdstream = { git = "https://github.com/mattmoor/composefs-rs", branch = "pull-platform" }
composefs-storage = { git = "https://github.com/mattmoor/composefs-rs", branch = "pull-platform" }
ocidir = { git = "https://github.com/mattmoor/ocidir-rs", branch = "platform-selection" }
8 changes: 8 additions & 0 deletions crates/lib/src/bootc_composefs/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,14 @@ fn install_composefs_bootloader(
if bootloader == Bootloader::None {
return Ok(());
}
// Only systemd-boot installs from the image's own binaries; the other
// paths name or run the host's.
let target_arch = state.config_opts.target_arch();
ensure!(
target_arch.is_host() || (bootloader == Bootloader::Systemd && target_arch.uses_efi()),
"Installing for {target_arch} from {} requires systemd-boot, not {bootloader:?}",
crate::install::target_arch::TargetArch::host()
);
let mounted_root = MountedImageRoot::new(composefs_mnt_fd, &root_setup.device_info)?;

if bootloader == Bootloader::Ukiboot {
Expand Down
19 changes: 17 additions & 2 deletions crates/lib/src/bootc_composefs/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ pub(crate) async fn pull_install_composefs_repository(
// ostree/bootc/storage depend on this link.
crate::store::ensure_composefs_bootc_link(rootfs_dir)?;

// Select the target's manifest only when it differs from the host's, so
// a native install resolves exactly as it always has.
let platform = if state.config_opts.is_cross_arch() {
anyhow::ensure!(
!use_unified,
"Installing for {} does not support unified storage",
state.config_opts.target_arch()
);
Some(state.config_opts.target_arch().oci_platform()?)
} else {
None
};

let pull_result = if use_unified {
// Unified path: first into containers-storage on the target
// rootfs, then cstor zero-copy into composefs. This ensures the image
Expand Down Expand Up @@ -297,7 +310,7 @@ pub(crate) async fn pull_install_composefs_repository(
} else {
// Direct path: pull directly into composefs via skopeo, without
// containers-storage as intermediary.
pull_composefs_direct(&repo, &imgref, false, ProgressWriter::default()).await?
pull_composefs_direct(&repo, &imgref, false, ProgressWriter::default(), platform).await?
};

Ok(pull_result)
Expand Down Expand Up @@ -406,6 +419,7 @@ async fn pull_composefs_direct(
imgref: &containers_image_proxy::ImageReference,
quiet: bool,
prog: ProgressWriter,
platform: Option<ocidir::oci_spec::image::Platform>,
) -> Result<PullResult<Sha512HashValue>> {
let imgref_str = imgref.to_string();
tracing::info!("Direct pull: fetching {imgref_str} into composefs repository");
Expand All @@ -422,6 +436,7 @@ async fn pull_composefs_direct(
PullOptions {
img_proxy_config: Some(config),
progress: Some(reporter),
platform,
..Default::default()
},
)
Expand Down Expand Up @@ -594,7 +609,7 @@ pub(crate) async fn pull_composefs_repo(

pull_composefs_unified(&imgstore, &storage_path, &repo, &imgref, quiet, prog).await?
} else {
pull_composefs_direct(&repo, &imgref, quiet, prog).await?
pull_composefs_direct(&repo, &imgref, quiet, prog, None).await?
};

// Tag the manifest as a bootc-owned GC root.
Expand Down
19 changes: 19 additions & 0 deletions crates/lib/src/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const KERNEL_INSTALL_CONF_ROOT: &str = "/tmp";
/// See: <https://www.freedesktop.org/software/systemd/man/latest/bootctl.html>
const BOOTCTL_RANDOM_SEED_MIN_VERSION: u32 = 257;

/// First systemd release whose `bootctl install` accepts `--all-architectures`
/// and `--install-source`.
const BOOTCTL_CROSS_ARCH_MIN_VERSION: u32 = 252;

/// Mount the first ESP found among backing devices at /boot/efi.
///
/// This is used by the install-alongside path to clean stale bootloader
Expand Down Expand Up @@ -308,6 +312,21 @@ pub(crate) fn install_systemd_boot(
}
}

if configopts.is_cross_arch() {
// bootctl installs only binaries named for its own EFI architecture,
// so on another architecture's root it finds none and installs
// nothing. Take every architecture the image ships (a single-arch
// image ships only its own), and only from the image, never the
// host's.
let systemd_version = systemd_version()?;
anyhow::ensure!(
systemd_version >= BOOTCTL_CROSS_ARCH_MIN_VERSION,
"Installing systemd-boot for {} requires systemd >= {BOOTCTL_CROSS_ARCH_MIN_VERSION}, found {systemd_version}",
configopts.target_arch()
);
bootctl_args.extend(["--all-architectures", "--install-source=image"]);
}

Command::new("bootctl")
.args(bootctl_args)
// Skip partition-type GUID validation because e.g. osbuild
Expand Down
24 changes: 24 additions & 0 deletions crates/lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ pub(crate) mod completion;
pub(crate) mod config;
mod osbuild;
pub(crate) mod osconfig;
pub(crate) mod target_arch;

use target_arch::TargetArch;

use std::collections::HashMap;
use std::io::Write;
Expand Down Expand Up @@ -393,6 +396,27 @@ pub(crate) struct InstallConfigOpts {
#[clap(long)]
#[serde(default)]
pub(crate) bootloader: Option<Bootloader>,

/// The architecture of the image being installed. Defaults to the
/// architecture bootc runs on. Installing for another architecture is
/// supported for `install to-disk` with the composefs backend and
/// systemd-boot, and needs a systemd whose `bootctl install` supports
/// `--install-source`.
#[clap(long)]
#[serde(default)]
pub(crate) target_arch: Option<TargetArch>,
Comment on lines +405 to +407
}

impl InstallConfigOpts {
/// The architecture this install targets.
pub(crate) fn target_arch(&self) -> TargetArch {
self.target_arch.unwrap_or_else(TargetArch::host)
Comment on lines +412 to +413
}

/// Whether this install targets an architecture other than the host's.
pub(crate) fn is_cross_arch(&self) -> bool {
!self.target_arch().is_host()
}
}

#[derive(Debug, Default, Clone, clap::Parser, Serialize, Deserialize, PartialEq, Eq)]
Expand Down
56 changes: 34 additions & 22 deletions crates/lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use super::RW_KARG;
use super::RootSetup;
use super::State;
use super::config::Filesystem;
use super::target_arch::FirmwareBootPartition;
use crate::bootloader::systemd_version;
use crate::task::Task;
use bootc_blockdev::dps::BIOS_BOOT;
Expand Down Expand Up @@ -895,35 +896,37 @@ fn sfdisk(
root_size: Option<u64>,
composefs_backend: bool,
requires_bootpart: bool,
target_arch: super::TargetArch,
) -> Result<PartitionLayout> {
// Generate partitioning spec as input to sfdisk
let mut partno = 0;
let mut partitioning_buf = String::new();
writeln!(partitioning_buf, "label: gpt")?;
let random_label = uuid::Uuid::new_v4();
writeln!(&mut partitioning_buf, "label-id: {random_label}")?;
if cfg!(target_arch = "x86_64") {
partno += 1;
writeln!(
&mut partitioning_buf,
r#"size=1MiB, bootable, type=21686148-6449-6E6F-744E-656564454649, name="BIOS-BOOT""#
)?;
} else if cfg!(target_arch = "powerpc64") {
// PowerPC-PReP-boot
partno += 1;
let label = PREPBOOT_LABEL;
let uuid = PREPBOOT_GUID;
writeln!(
&mut partitioning_buf,
r#"size=4MiB, bootable, type={uuid}, name="{label}""#
)?;
} else if cfg!(any(target_arch = "aarch64", target_arch = "s390x")) {
match target_arch.firmware_boot_partition()? {
Some(FirmwareBootPartition::BiosBoot) => {
partno += 1;
writeln!(
&mut partitioning_buf,
r#"size=1MiB, bootable, type=21686148-6449-6E6F-744E-656564454649, name="BIOS-BOOT""#
)?;
}
Some(FirmwareBootPartition::PrepBoot) => {
// PowerPC-PReP-boot
partno += 1;
let label = PREPBOOT_LABEL;
let uuid = PREPBOOT_GUID;
writeln!(
&mut partitioning_buf,
r#"size=4MiB, bootable, type={uuid}, name="{label}""#
)?;
}
// No bootloader partition is necessary
} else {
anyhow::bail!("Unsupported architecture: {}", std::env::consts::ARCH);
None => {}
}

let esp_partno = if super::ARCH_USES_EFI {
let esp_partno = if target_arch.uses_efi() {
let esp_guid = bootc_blockdev::dps::ESP;
partno += 1;

Expand Down Expand Up @@ -959,7 +962,7 @@ fn sfdisk(
let root_size = root_size
.map(|v| Cow::Owned(format!("size={v}MiB, ")))
.unwrap_or_else(|| Cow::Borrowed(""));
let rootpart_uuid = uuid::Uuid::parse_str(bootc_blockdev::dps::this_arch_root())?;
let rootpart_uuid = uuid::Uuid::parse_str(target_arch.root_partition_type())?;
writeln!(
&mut partitioning_buf,
r#"{root_size}type={rootpart_uuid}, name="root""#
Expand Down Expand Up @@ -1050,13 +1053,21 @@ pub(crate) fn install_create_rootfs(
let serial = device.serial.as_deref().unwrap_or("<unknown>");
let model = device.model.as_deref().unwrap_or("<unknown>");
let discoverable = state.aboot_disk_layout.is_none() && use_discoverable_partitions(state);
let target_arch = state.config_opts.target_arch();
// systemd-repart lays out partitions for the architecture it runs on, so
// only the sfdisk path can lay a disk out for another one.
anyhow::ensure!(
target_arch.is_host() || (state.aboot_disk_layout.is_none() && !use_systemd_repart),
"Installing for {target_arch} from {} is not supported with systemd-repart partitioning",
super::TargetArch::host()
);
Comment on lines +1059 to +1063
if let Some(layout) = state.aboot_disk_layout {
anyhow::ensure!(
block_setup == BlockSetup::Direct,
"{layout:?} aboot layout requires --block-setup direct"
);
anyhow::ensure!(
layout != AbootDiskLayout::Ukiboot || super::ARCH_USES_EFI,
layout != AbootDiskLayout::Ukiboot || target_arch.uses_efi(),
"ukiboot disk layout requires x86_64 or aarch64"
);
anyhow::ensure!(
Expand Down Expand Up @@ -1125,6 +1136,7 @@ pub(crate) fn install_create_rootfs(
root_size,
state.composefs_options.composefs_backend,
block_setup.requires_bootpart(),
target_arch,
)?
};

Expand Down Expand Up @@ -1168,7 +1180,7 @@ pub(crate) fn install_create_rootfs(
let root_device = device.find_device_by_partno(layout.rootpn)?;

// Verify the partition type matches the DPS root partition type for this architecture
let expected_parttype = bootc_blockdev::dps::this_arch_root();
let expected_parttype = target_arch.root_partition_type();
if !root_device
.parttype
.as_ref()
Expand Down
Loading
Loading