1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 15:45:53 +01:00

Merge pull request #1560 from Johan-Liebert1/bind-mnt-etc

composefs/install: Copy /etc contents to state
This commit is contained in:
Colin Walters
2025-08-29 13:20:30 -04:00
committed by GitHub
6 changed files with 55 additions and 2 deletions

1
Cargo.lock generated
View File

@@ -253,6 +253,7 @@ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
"anyhow", "anyhow",
"bootc-initramfs-setup",
"bootc-internal-blockdev", "bootc-internal-blockdev",
"bootc-internal-utils", "bootc-internal-utils",
"bootc-kernel-cmdline", "bootc-kernel-cmdline",

View File

@@ -22,6 +22,7 @@ bootc-sysusers = { path = "../sysusers" }
bootc-tmpfiles = { path = "../tmpfiles" } bootc-tmpfiles = { path = "../tmpfiles" }
bootc-utils = { package = "bootc-internal-utils", path = "../utils", version = "0.0.0" } bootc-utils = { package = "bootc-internal-utils", path = "../utils", version = "0.0.0" }
ostree-ext = { path = "../ostree-ext", features = ["bootc"] } ostree-ext = { path = "../ostree-ext", features = ["bootc"] }
bootc-initramfs-setup = { path = "../initramfs" }
# Workspace dependencies # Workspace dependencies
anstream = { workspace = true } anstream = { workspace = true }

View File

@@ -0,0 +1 @@
pub(crate) mod state;

View File

@@ -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
unmount(tempdir.path(), UnmountFlags::DETACH).context("Unmounting composefs")?;
cp_ret
}

View File

@@ -77,6 +77,7 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "install-to-disk")] #[cfg(feature = "install-to-disk")]
use self::baseline::InstallBlockDeviceOpts; use self::baseline::InstallBlockDeviceOpts;
use crate::bootc_composefs::state::copy_etc_to_state;
use crate::boundimage::{BoundImage, ResolvedBoundImage}; use crate::boundimage::{BoundImage, ResolvedBoundImage};
use crate::composefs_consts::{ use crate::composefs_consts::{
BOOT_LOADER_ENTRIES, COMPOSEFS_CMDLINE, COMPOSEFS_STAGED_DEPLOYMENT_FNAME, BOOT_LOADER_ENTRIES, COMPOSEFS_CMDLINE, COMPOSEFS_STAGED_DEPLOYMENT_FNAME,
@@ -2247,8 +2248,9 @@ pub(crate) fn write_composefs_state(
) -> Result<()> { ) -> Result<()> {
let state_path = root_path.join(format!("{STATE_DIR_RELATIVE}/{}", deployment_id.to_hex())); let state_path = root_path.join(format!("{STATE_DIR_RELATIVE}/{}", deployment_id.to_hex()));
create_dir_all(state_path.join("etc/upper"))?; create_dir_all(state_path.join("etc"))?;
create_dir_all(state_path.join("etc/work"))?;
copy_etc_to_state(&root_path, &deployment_id.to_hex(), &state_path)?;
let actual_var_path = root_path.join(SHARED_VAR_PATH); let actual_var_path = root_path.join(SHARED_VAR_PATH);
create_dir_all(&actual_var_path)?; create_dir_all(&actual_var_path)?;

View File

@@ -4,6 +4,7 @@
//! to provide a fully "container native" tool for using //! to provide a fully "container native" tool for using
//! bootable container images. //! bootable container images.
mod bootc_composefs;
pub(crate) mod bootc_kargs; pub(crate) mod bootc_kargs;
mod bootloader; mod bootloader;
mod boundimage; mod boundimage;