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: 3 additions & 1 deletion crates/initramfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ fn overlay_state(base: impl AsFd, state: impl AsFd, source: &str) -> Result<()>
mount_at_wrapper(fs, base, ".").context("Moving mount")
}

fn overlay_transient(base: impl AsFd) -> Result<()> {
/// Mounts a transient overlayfs with passed in fd as the lowerdir
#[context("Mounting transient overlayfs")]
pub fn overlay_transient(base: impl AsFd) -> Result<()> {
overlay_state(base, prepare_mount(mount_tmpfs()?)?, "transient")
}

Expand Down
25 changes: 25 additions & 0 deletions crates/lib/src/bootc_composefs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ use std::os::unix::fs::symlink;
use std::{fs::create_dir_all, process::Command};

use anyhow::{Context, Result};
use bootc_initramfs_setup::overlay_transient;
use bootc_kernel_cmdline::utf8::Cmdline;
use bootc_mount::tempmount::TempMount;
use bootc_utils::CommandRunExt;
use camino::Utf8PathBuf;
use cap_std_ext::cap_std::ambient_authority;
use cap_std_ext::cap_std::fs::Dir;
use cap_std_ext::{cap_std, dirext::CapStdExtDirExt};
use composefs::fsverity::{FsVerityHashValue, Sha256HashValue};
use fn_error_context::context;
Expand Down Expand Up @@ -163,3 +166,25 @@ pub(crate) fn write_composefs_state(

Ok(())
}

pub(crate) fn composefs_usr_overlay() -> Result<()> {
let usr = Dir::open_ambient_dir("/usr", ambient_authority()).context("Opening /usr")?;
let is_usr_mounted = usr
.is_mountpoint(".")
.context("Failed to get mount details for /usr")?;

let is_usr_mounted =
is_usr_mounted.ok_or_else(|| anyhow::anyhow!("Falied to get mountinfo"))?;

if is_usr_mounted {
println!("A writeable overlayfs is already mounted on /usr");
return Ok(());
}

overlay_transient(usr)?;

println!("A writeable overlayfs is now mounted on /usr");
println!("All changes there will be discarded on reboot.");

Ok(())
}
13 changes: 12 additions & 1 deletion crates/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use serde::{Deserialize, Serialize};
use crate::bootc_composefs::{
finalize::{composefs_native_finalize, get_etc_diff},
rollback::composefs_rollback,
state::composefs_usr_overlay,
status::composefs_booted,
switch::switch_composefs,
update::upgrade_composefs,
Expand Down Expand Up @@ -1289,7 +1290,17 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
Ok(())
}
Opt::Edit(opts) => edit(opts).await,
Opt::UsrOverlay => usroverlay().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
}
Comment on lines +1293 to +1303
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The conditional compilation logic here is a bit redundant. The else branch for when composefs-backend is enabled is identical to the case where it's disabled. You can simplify this to improve readability and reduce duplication.

        Opt::UsrOverlay => {
            #[cfg(feature = "composefs-backend")]
            if composefs_booted()?.is_some() {
                return composefs_usr_overlay();
            }
            usroverlay().await
        }

Opt::Container(opts) => match opts {
ContainerOpts::Lint {
rootfs,
Expand Down