Skip to content

Commit d55be0e

Browse files
evan-goodecgwalters
authored andcommitted
initramfs: Allow mounting overlay with flags
Signed-off-by: Evan Goode <mail@evangoo.de>
1 parent 6c0ec0c commit d55be0e

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

crates/initramfs/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ fn overlay_state(
219219
state: impl AsFd,
220220
source: &str,
221221
mode: Option<rustix::fs::Mode>,
222+
mount_attr_flags: Option<MountAttrFlags>,
222223
) -> Result<()> {
223224
let upper = ensure_dir(state.as_fd(), "upper", mode)?;
224225
let work = ensure_dir(state.as_fd(), "work", mode)?;
@@ -232,16 +233,26 @@ fn overlay_state(
232233
let fs = fsmount(
233234
overlayfs.as_fd(),
234235
FsMountFlags::FSMOUNT_CLOEXEC,
235-
MountAttrFlags::empty(),
236+
mount_attr_flags.unwrap_or(MountAttrFlags::empty()),
236237
)?;
237238

238239
mount_at_wrapper(fs, base, ".").context("Moving mount")
239240
}
240241

241242
/// Mounts a transient overlayfs with passed in fd as the lowerdir
242243
#[context("Mounting transient overlayfs")]
243-
pub fn overlay_transient(base: impl AsFd, mode: Option<rustix::fs::Mode>) -> Result<()> {
244-
overlay_state(base, prepare_mount(mount_tmpfs()?)?, "transient", mode)
244+
pub fn overlay_transient(
245+
base: impl AsFd,
246+
mode: Option<rustix::fs::Mode>,
247+
mount_attr_flags: Option<MountAttrFlags>,
248+
) -> Result<()> {
249+
overlay_state(
250+
base,
251+
prepare_mount(mount_tmpfs()?)?,
252+
"transient",
253+
mode,
254+
mount_attr_flags,
255+
)
245256
}
246257

247258
#[context("Opening rootfs")]
@@ -309,8 +320,9 @@ pub fn mount_subdir(
309320
open_dir(&state, subdir)?,
310321
"overlay",
311322
None,
323+
None,
312324
),
313-
MountType::Transient => overlay_transient(open_dir(&new_root, subdir)?, None),
325+
MountType::Transient => overlay_transient(open_dir(&new_root, subdir)?, None, None),
314326
}
315327
}
316328

@@ -373,7 +385,7 @@ pub fn setup_root(args: Args) -> Result<()> {
373385
}
374386

375387
if config.root.transient {
376-
overlay_transient(&new_root, None)?;
388+
overlay_transient(&new_root, None, None)?;
377389
}
378390

379391
match composefs::mount::mount_at(&sysroot_clone, &new_root, "sysroot") {

0 commit comments

Comments
 (0)