-
Notifications
You must be signed in to change notification settings - Fork 131
composefs/install: Copy /etc contents to state #1560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cgwalters
merged 1 commit into
bootc-dev:composefs-backend
from
Johan-Liebert1:bind-mnt-etc
Aug 29, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod state; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::process::Command; | ||
|
||
use anyhow::{Context, Result}; | ||
use bootc_utils::CommandRunExt; | ||
use camino::Utf8PathBuf; | ||
use fn_error_context::context; | ||
|
||
use rustix::{ | ||
fs::{open, Mode, OFlags, CWD}, | ||
mount::{unmount, UnmountFlags}, | ||
path::Arg, | ||
}; | ||
|
||
/// Mounts an EROFS image and copies the pristine /etc to the deployment's /etc | ||
#[context("Copying etc")] | ||
pub(crate) fn copy_etc_to_state( | ||
sysroot_path: &Utf8PathBuf, | ||
erofs_id: &String, | ||
state_path: &Utf8PathBuf, | ||
) -> Result<()> { | ||
let sysroot_fd = open( | ||
sysroot_path.as_std_path(), | ||
OFlags::PATH | OFlags::DIRECTORY | OFlags::CLOEXEC, | ||
Mode::empty(), | ||
) | ||
.context("Opening sysroot")?; | ||
|
||
let composefs_fd = bootc_initramfs_setup::mount_composefs_image(&sysroot_fd, &erofs_id, false)?; | ||
|
||
let tempdir = tempfile::tempdir().context("Creating tempdir")?; | ||
|
||
bootc_initramfs_setup::mount_at_wrapper(composefs_fd, CWD, tempdir.path())?; | ||
|
||
// TODO: Replace this with a function to cap_std_ext | ||
let cp_ret = Command::new("cp") | ||
.args([ | ||
"-a", | ||
&format!("{}/etc/.", tempdir.path().as_str()?), | ||
&format!("{state_path}/etc/."), | ||
]) | ||
.run_capture_stderr(); | ||
|
||
// Unmount regardless of copy succeeding | ||
cgwalters marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unmount(tempdir.path(), UnmountFlags::DETACH).context("Unmounting composefs")?; | ||
|
||
cp_ret | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think what we want is a wrapper for tempdir that handles unmount-on-drop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Composefs has a struct for exactly this, but again is only visible at crate level. We could make that public. https://github.com/containers/composefs-rs/blob/main/crates/composefs/src/mountcompat.rs#L129
The composefs-rs crate has a lot of helper functions which are private