Skip to content
Merged
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
4 changes: 1 addition & 3 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ similar-asserts = { workspace = true }
static_assertions = { workspace = true }

[features]
default = ["install-to-disk", "composefs-backend"]
default = ["install-to-disk"]
# This feature enables `bootc install to-disk`, which is considered just a "demo"
# or reference installer; we expect most nontrivial use cases to be using
# `bootc install to-filesystem`.
install-to-disk = []
# Enable support for the composefs native backend
composefs-backend = []
# This featuares enables `bootc internals publish-rhsm-facts` to integrate with
# Red Hat Subscription Manager
rhsm = []
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/bootc_composefs/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ fn delete_type1_entry(depl: &DeploymentEntry, boot_dir: &Dir, deleting_staged: b
// We reuse kernel + initrd if they're the same for two deployments
// We don't want to delete the (being deleted) deployment's kernel + initrd
// if it's in use by any other deployment
let should_del_kernel = match &depl.deployment.boot_digest {
Some(digest) => find_vmlinuz_initrd_duplicates(&digest)?
let should_del_kernel = match depl.deployment.boot_digest.as_ref() {
Some(digest) => find_vmlinuz_initrd_duplicates(digest)?
.is_some_and(|vec| vec.iter().any(|digest| *digest != depl.deployment.verity)),
None => false,
};
Expand Down
2 changes: 0 additions & 2 deletions crates/lib/src/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use fn_error_context::context;
use bootc_blockdev::{Partition, PartitionTable};
use bootc_mount as mount;

#[cfg(any(feature = "composefs-backend", feature = "install-to-disk"))]
use crate::bootc_composefs::boot::mount_esp;
use crate::{discoverable_partition_specification, utils};

Expand Down Expand Up @@ -72,7 +71,6 @@ pub(crate) fn install_via_bootupd(
}

#[context("Installing bootloader")]
#[cfg(any(feature = "composefs-backend", feature = "install-to-disk"))]
pub(crate) fn install_systemd_boot(
device: &PartitionTable,
_rootfs: &Utf8Path,
Expand Down
28 changes: 3 additions & 25 deletions crates/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ use schemars::schema_for;
use serde::{Deserialize, Serialize};
use tempfile::tempdir_in;

#[cfg(feature = "composefs-backend")]
use crate::bootc_composefs::delete::delete_composefs_deployment;
#[cfg(feature = "composefs-backend")]
use crate::bootc_composefs::{
finalize::{composefs_backend_finalize, get_etc_diff},
rollback::composefs_rollback,
Expand Down Expand Up @@ -669,13 +667,12 @@ pub(crate) enum Opt {
#[clap(subcommand)]
#[clap(hide = true)]
Internals(InternalsOpts),
#[cfg(feature = "composefs-backend")]
ComposefsFinalizeStaged,
#[cfg(feature = "composefs-backend")]
/// Diff current /etc configuration versus default
ConfigDiff,
#[cfg(feature = "composefs-backend")]
DeleteDeployment { depl_id: String },
DeleteDeployment {
depl_id: String,
},
}

/// Ensure we've entered a mount namespace, so that we can remount
Expand Down Expand Up @@ -1267,38 +1264,26 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
let root = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
match opt {
Opt::Upgrade(opts) => {
#[cfg(feature = "composefs-backend")]
if composefs_booted()?.is_some() {
upgrade_composefs(opts).await
} else {
upgrade(opts).await
}

#[cfg(not(feature = "composefs-backend"))]
upgrade(opts).await
}
Opt::Switch(opts) => {
#[cfg(feature = "composefs-backend")]
if composefs_booted()?.is_some() {
switch_composefs(opts).await
} else {
switch(opts).await
}

#[cfg(not(feature = "composefs-backend"))]
switch(opts).await
}
Opt::Rollback(opts) => {
#[cfg(feature = "composefs-backend")]
if composefs_booted()?.is_some() {
composefs_rollback().await?
} else {
rollback(&opts).await?
}

#[cfg(not(feature = "composefs-backend"))]
rollback(&opts).await?;

if opts.apply {
crate::reboot::reboot()?;
}
Expand All @@ -1307,15 +1292,11 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
}
Opt::Edit(opts) => edit(opts).await,
Opt::UsrOverlay => {
#[cfg(feature = "composefs-backend")]
if composefs_booted()?.is_some() {
composefs_usr_overlay()
} else {
usroverlay().await
}

#[cfg(not(feature = "composefs-backend"))]
usroverlay().await
}
Opt::Container(opts) => match opts {
ContainerOpts::Lint {
Expand Down Expand Up @@ -1608,13 +1589,10 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
}
},

#[cfg(feature = "composefs-backend")]
Opt::ComposefsFinalizeStaged => composefs_backend_finalize().await,

#[cfg(feature = "composefs-backend")]
Opt::ConfigDiff => get_etc_diff().await,

#[cfg(feature = "composefs-backend")]
Opt::DeleteDeployment { depl_id } => delete_composefs_deployment(&depl_id).await,
}
}
Expand Down
30 changes: 3 additions & 27 deletions crates/lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use serde::{Deserialize, Serialize};

#[cfg(feature = "install-to-disk")]
use self::baseline::InstallBlockDeviceOpts;
#[cfg(feature = "composefs-backend")]
use crate::bootc_composefs::{boot::setup_composefs_boot, repo::initialize_composefs_repository};
use crate::boundimage::{BoundImage, ResolvedBoundImage};
use crate::containerenv::ContainerExecutionInfo;
Expand All @@ -66,7 +65,6 @@ use crate::task::Task;
use crate::utils::sigpolicy_from_opt;
use bootc_kernel_cmdline::{bytes, utf8, INITRD_ARG_PREFIX, ROOTFLAGS};
use bootc_mount::Filesystem;
#[cfg(feature = "composefs-backend")]
use composefs::fsverity::FsVerityHashValue;

/// The toplevel boot directory
Expand All @@ -88,7 +86,6 @@ const SELINUXFS: &str = "/sys/fs/selinux";
pub(crate) const EFIVARFS: &str = "/sys/firmware/efi/efivars";
pub(crate) const ARCH_USES_EFI: bool = cfg!(any(target_arch = "x86_64", target_arch = "aarch64"));

#[cfg(feature = "composefs-backend")]
pub(crate) const EFI_LOADER_INFO: &str = "LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f";

const DEFAULT_REPO_CONFIG: &[(&str, &str)] = &[
Expand Down Expand Up @@ -278,7 +275,6 @@ pub(crate) struct InstallToDiskOpts {

#[clap(flatten)]
#[serde(flatten)]
#[cfg(feature = "composefs-backend")]
pub(crate) composefs_opts: InstallComposefsOpts,
}

Expand Down Expand Up @@ -356,7 +352,6 @@ pub(crate) struct InstallToFilesystemOpts {
#[clap(flatten)]
pub(crate) config_opts: InstallConfigOpts,

#[cfg(feature = "composefs-backend")]
#[clap(flatten)]
pub(crate) composefs_opts: InstallComposefsOpts,
}
Expand Down Expand Up @@ -391,7 +386,6 @@ pub(crate) struct InstallToExistingRootOpts {
#[clap(default_value = ALONGSIDE_ROOT_MOUNT)]
pub(crate) root_path: Utf8PathBuf,

#[cfg(feature = "composefs-backend")]
#[clap(flatten)]
pub(crate) composefs_opts: InstallComposefsOpts,
}
Expand Down Expand Up @@ -434,7 +428,6 @@ pub(crate) struct State {
pub(crate) composefs_required: bool,

// If Some, then --composefs_native is passed
#[cfg(feature = "composefs-backend")]
pub(crate) composefs_options: InstallComposefsOpts,

/// Detected bootloader type for the target system
Expand Down Expand Up @@ -565,7 +558,7 @@ impl FromStr for MountSpec {
}
}

#[cfg(all(feature = "install-to-disk", feature = "composefs-backend"))]
#[cfg(feature = "install-to-disk")]
impl InstallToDiskOpts {
pub(crate) fn validate(&self) -> Result<()> {
if !self.composefs_opts.composefs_backend {
Expand Down Expand Up @@ -1221,19 +1214,15 @@ async fn verify_target_fetch(
}

fn root_has_uki(root: &Dir) -> Result<bool> {
#[cfg(feature = "composefs-backend")]
return crate::bootc_composefs::boot::container_root_has_uki(root);

#[cfg(not(feature = "composefs-backend"))]
Ok(false)
crate::bootc_composefs::boot::container_root_has_uki(root)
}

/// Preparation for an install; validates and prepares some (thereafter immutable) global state.
async fn prepare_install(
config_opts: InstallConfigOpts,
source_opts: InstallSourceOpts,
target_opts: InstallTargetOpts,
#[cfg(feature = "composefs-backend")] mut composefs_options: InstallComposefsOpts,
mut composefs_options: InstallComposefsOpts,
) -> Result<Arc<State>> {
tracing::trace!("Preparing install");
let rootfs = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())
Expand Down Expand Up @@ -1308,7 +1297,6 @@ async fn prepare_install(

tracing::debug!("Composefs required: {composefs_required}");

#[cfg(feature = "composefs-backend")]
if composefs_required {
composefs_options.composefs_backend = true;
}
Expand Down Expand Up @@ -1381,7 +1369,6 @@ async fn prepare_install(

// Determine bootloader type for the target system
// Priority: user-specified > bootupd availability > systemd-boot fallback
#[cfg(feature = "composefs-backend")]
let detected_bootloader = {
if let Some(bootloader) = composefs_options.bootloader.clone() {
bootloader
Expand All @@ -1393,8 +1380,6 @@ async fn prepare_install(
}
}
};
#[cfg(not(feature = "composefs-backend"))]
let detected_bootloader = crate::spec::Bootloader::Grub;
println!("Bootloader: {detected_bootloader}");

// Create our global (read-only) state which gets wrapped in an Arc
Expand All @@ -1413,7 +1398,6 @@ async fn prepare_install(
host_is_container,
composefs_required,
detected_bootloader,
#[cfg(feature = "composefs-backend")]
composefs_options,
});

Expand Down Expand Up @@ -1585,7 +1569,6 @@ async fn install_to_filesystem_impl(
}
}

#[cfg(feature = "composefs-backend")]
if state.composefs_options.composefs_backend {
// Load a fd for the mounted target physical root

Expand All @@ -1596,9 +1579,6 @@ async fn install_to_filesystem_impl(
ostree_install(state, rootfs, cleanup).await?;
}

#[cfg(not(feature = "composefs-backend"))]
ostree_install(state, rootfs, cleanup).await?;

// Finalize mounted filesystems
if !rootfs.skip_finalize {
let bootfs = rootfs.boot.as_ref().map(|_| ("boot", "boot"));
Expand All @@ -1618,7 +1598,6 @@ fn installation_complete() {
#[context("Installing to disk")]
#[cfg(feature = "install-to-disk")]
pub(crate) async fn install_to_disk(mut opts: InstallToDiskOpts) -> Result<()> {
#[cfg(feature = "composefs-backend")]
opts.validate()?;

// Log the disk installation operation to systemd journal
Expand Down Expand Up @@ -1667,7 +1646,6 @@ pub(crate) async fn install_to_disk(mut opts: InstallToDiskOpts) -> Result<()> {
opts.config_opts,
opts.source_opts,
opts.target_opts,
#[cfg(feature = "composefs-backend")]
opts.composefs_opts,
)
.await?;
Expand Down Expand Up @@ -1905,7 +1883,6 @@ pub(crate) async fn install_to_filesystem(
opts.config_opts,
opts.source_opts,
opts.target_opts,
#[cfg(feature = "composefs-backend")]
opts.composefs_opts,
)
.await?;
Expand Down Expand Up @@ -2177,7 +2154,6 @@ pub(crate) async fn install_to_existing_root(opts: InstallToExistingRootOpts) ->
source_opts: opts.source_opts,
target_opts: opts.target_opts,
config_opts: opts.config_opts,
#[cfg(feature = "composefs-backend")]
composefs_opts: opts.composefs_opts,
};

Expand Down
1 change: 0 additions & 1 deletion crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! to provide a fully "container native" tool for using
//! bootable container images.

#[cfg(feature = "composefs-backend")]
mod bootc_composefs;
pub(crate) mod bootc_kargs;
mod bootloader;
Expand Down
2 changes: 0 additions & 2 deletions crates/lib/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use linkme::distributed_slice;
use ostree_ext::ostree_prepareroot;
use serde::Serialize;

#[cfg(feature = "composefs-backend")]
use crate::bootc_composefs::boot::EFI_LINUX;

/// Reference to embedded default baseimage content that should exist.
Expand Down Expand Up @@ -770,7 +769,6 @@ fn check_boot(root: &Dir, config: &LintExecutionConfig) -> LintResult {
})
.collect();
let mut entries = entries?;
#[cfg(feature = "composefs-backend")]
{
// Work around https://github.com/containers/composefs-rs/issues/131
let efidir = Utf8Path::new(EFI_LINUX)
Expand Down
7 changes: 0 additions & 7 deletions crates/lib/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use ostree_ext::{container::OstreeImageReference, oci_spec};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[cfg(feature = "composefs-backend")]
use crate::bootc_composefs::boot::BootType;
use crate::{k8sapitypes, status::Slot};

Expand Down Expand Up @@ -201,7 +200,6 @@ impl FromStr for Bootloader {
/// A bootable entry
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "composefs-backend")]
pub struct BootEntryComposefs {
/// The erofs verity
pub verity: String,
Expand Down Expand Up @@ -235,7 +233,6 @@ pub struct BootEntry {
/// If this boot entry is ostree based, the corresponding state
pub ostree: Option<BootEntryOstree>,
/// If this boot entry is composefs based, the corresponding state
#[cfg(feature = "composefs-backend")]
pub composefs: Option<BootEntryComposefs>,
}

Expand Down Expand Up @@ -272,7 +269,6 @@ pub struct HostStatus {
pub ty: Option<HostType>,
}

#[cfg(feature = "composefs-backend")]
pub(crate) struct DeploymentEntry<'a> {
pub(crate) ty: Option<Slot>,
pub(crate) deployment: &'a BootEntryComposefs,
Expand Down Expand Up @@ -315,7 +311,6 @@ impl Host {
}
}

#[cfg(feature = "composefs-backend")]
pub(crate) fn require_composefs_booted(&self) -> anyhow::Result<&BootEntryComposefs> {
let cfs = self
.status
Expand All @@ -328,7 +323,6 @@ impl Host {
}

/// Returns all composefs deployments in a list
#[cfg(feature = "composefs-backend")]
#[fn_error_context::context("Getting all composefs deployments")]
pub(crate) fn all_composefs_deployments<'a>(&'a self) -> Result<Vec<DeploymentEntry<'a>>> {
let mut all_deps = vec![];
Expand Down Expand Up @@ -636,7 +630,6 @@ mod tests {
pinned: false,
store: None,
ostree: None,
#[cfg(feature = "composefs-backend")]
composefs: None,
}
}
Expand Down
Loading