Skip to content

Commit 6f94015

Browse files
committed
bootloader: bind-mount target root on itself
This make it a mountpoint so the chrooted `bootupd` process will be able to find the underlying filesystem when `/boot` is not on a separate partition
1 parent 271bf75 commit 6f94015

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

crates/lib/src/bootloader.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ pub(crate) fn install_via_bootupd(
114114
let bind_mount_dirs = ["/dev", "/run", "/proc", "/sys"];
115115
let chroot_args = if let Some(target_root) = abs_deployment_path.as_deref() {
116116
tracing::debug!("Setting up bind-mounts before chrooting to the target deployment");
117+
// First off, we bind-mount target on itself, so it becomes a mount point and the chrooted
118+
// `findmnt` calls are able to resolve the mount in the chroot
119+
// See https://github.com/coreos/bootupd/issues/1051#issuecomment-3768271509 and following comments
120+
tracing::debug!("bind mounting the target deployement on itslelf");
121+
rustix::mount::mount_bind(target_root.as_std_path(), target_root.as_std_path())?;
122+
117123
for src in bind_mount_dirs {
118124
let dest = target_root
119125
// joining an absolute path
@@ -185,6 +191,11 @@ pub(crate) fn install_via_bootupd(
185191
tracing::warn!("Error unmounting {}: {e}", mount.display());
186192
}
187193
}
194+
if let Err(e) =
195+
rustix::mount::unmount(&target_root.into_std_path_buf(), UnmountFlags::DETACH)
196+
{
197+
tracing::warn!("Error unmounting target root bind mount: {e}");
198+
}
188199
}
189200
install_result
190201
}

0 commit comments

Comments
 (0)