Skip to content

Commit c05588c

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs-backend: Implement bootc usr-overlay
Similar to ostree, mount a transient overlayfs on /usr Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent c503391 commit c05588c

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

crates/initramfs/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ fn overlay_state(base: impl AsFd, state: impl AsFd, source: &str) -> Result<()>
179179
mount_at_wrapper(fs, base, ".").context("Moving mount")
180180
}
181181

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

crates/lib/src/bootc_composefs/state.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ use std::os::unix::fs::symlink;
22
use std::{fs::create_dir_all, process::Command};
33

44
use anyhow::{Context, Result};
5+
use bootc_initramfs_setup::overlay_transient;
56
use bootc_kernel_cmdline::utf8::Cmdline;
67
use bootc_mount::tempmount::TempMount;
78
use bootc_utils::CommandRunExt;
89
use camino::Utf8PathBuf;
10+
use cap_std_ext::cap_std::ambient_authority;
11+
use cap_std_ext::cap_std::fs::Dir;
912
use cap_std_ext::{cap_std, dirext::CapStdExtDirExt};
1013
use composefs::fsverity::{FsVerityHashValue, Sha256HashValue};
1114
use fn_error_context::context;
@@ -163,3 +166,25 @@ pub(crate) fn write_composefs_state(
163166

164167
Ok(())
165168
}
169+
170+
pub(crate) fn composefs_usr_overlay() -> Result<()> {
171+
let usr = Dir::open_ambient_dir("/usr", ambient_authority()).context("Opening /usr")?;
172+
let is_usr_mounted = usr
173+
.is_mountpoint(".")
174+
.context("Failed to get mount details for /usr")?;
175+
176+
let is_usr_mounted =
177+
is_usr_mounted.ok_or_else(|| anyhow::anyhow!("Falied to get mountinfo"))?;
178+
179+
if is_usr_mounted {
180+
println!("A writeable overlayfs is already mounted on /usr");
181+
return Ok(());
182+
}
183+
184+
overlay_transient(usr)?;
185+
186+
println!("A writeable overlayfs is now mounted on /usr");
187+
println!("All changes there will be discarded on reboot.");
188+
189+
Ok(())
190+
}

crates/lib/src/cli.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use serde::{Deserialize, Serialize};
3333
use crate::bootc_composefs::{
3434
finalize::{composefs_native_finalize, get_etc_diff},
3535
rollback::composefs_rollback,
36+
state::composefs_usr_overlay,
3637
status::composefs_booted,
3738
switch::switch_composefs,
3839
update::upgrade_composefs,
@@ -1289,7 +1290,17 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
12891290
Ok(())
12901291
}
12911292
Opt::Edit(opts) => edit(opts).await,
1292-
Opt::UsrOverlay => usroverlay().await,
1293+
Opt::UsrOverlay => {
1294+
#[cfg(feature = "composefs-backend")]
1295+
if composefs_booted()?.is_some() {
1296+
composefs_usr_overlay()
1297+
} else {
1298+
usroverlay().await
1299+
}
1300+
1301+
#[cfg(not(feature = "composefs-backend"))]
1302+
usroverlay().await
1303+
}
12931304
Opt::Container(opts) => match opts {
12941305
ContainerOpts::Lint {
12951306
rootfs,

0 commit comments

Comments
 (0)