Skip to content

Commit 68e2010

Browse files
committed
bwrap: Bind-mount host /dev instead of creating fresh devtmpfs
Replace `--dev /dev` with `--dev-bind /dev /dev` in the bwrap container setup so that lsblk inside the sandbox can properly enumerate partition children of block devices (e.g. loop devices). The previous approach created a minimal devtmpfs that lacked complete device information, causing ESP partition discovery to fail inside the bwrap sandbox. With a full bind-mount of host /dev, the per-device bind_device() mechanism is no longer needed and is removed. Additionally, bind-mount /run/udev into the sandbox when it exists so that lsblk and libblkid can read the udev database for partition type GUIDs and other device properties. Without this, tools that query device metadata (e.g. PARTTYPE) would get incomplete results even with /dev properly mounted. Assisted-by: Claude Code (Opus 4) Signed-off-by: ckyrouac <ckyrouac@redhat.com>
1 parent b5173fe commit 68e2010

2 files changed

Lines changed: 9 additions & 29 deletions

File tree

crates/lib/src/bootloader.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,10 @@ pub(crate) fn install_via_bootupd(
122122
let mut bwrap_args = vec!["bootupctl"];
123123
bwrap_args.extend(bootupd_args);
124124

125-
// Collect partition paths first so they live long enough
126-
let partition_paths: Vec<String> =
127-
device.children.iter().flatten().map(|p| p.path()).collect();
128-
129-
let mut cmd = BwrapCmd::new(&target_root)
125+
let cmd = BwrapCmd::new(&target_root)
130126
// Bind mount /boot from the physical target root so bootupctl can find
131127
// the boot partition and install the bootloader there
132-
.bind(&boot_path, &"/boot")
133-
// Bind the target block device inside the bwrap container so bootupctl can access it
134-
.bind_device(&device_path);
135-
136-
// Also bind all partitions of the target block device
137-
for part_path in &partition_paths {
138-
cmd = cmd.bind_device(part_path);
139-
}
128+
.bind(&boot_path, &"/boot");
140129

141130
// The $PATH in the bwrap env is not complete enough for some images
142131
// so we inject a reasonnable default.

crates/utils/src/bwrap.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pub struct BwrapCmd<'a> {
1717
chroot_path: Cow<'a, Utf8Path>,
1818
/// Bind mounts in format (source, target)
1919
bind_mounts: Vec<(&'a str, &'a str)>,
20-
/// Device nodes to bind into the container
21-
devices: Vec<&'a str>,
2220
/// Environment variables to set
2321
env_vars: Vec<(&'a str, &'a str)>,
2422
}
@@ -31,7 +29,6 @@ impl<'a> BwrapCmd<'a> {
3129
Self {
3230
chroot_path: Cow::Owned(Utf8PathBuf::from(&fd_path)),
3331
bind_mounts: Vec::new(),
34-
devices: Vec::new(),
3532
env_vars: Vec::new(),
3633
}
3734
}
@@ -41,7 +38,6 @@ impl<'a> BwrapCmd<'a> {
4138
Self {
4239
chroot_path: Cow::Borrowed(path),
4340
bind_mounts: Vec::new(),
44-
devices: Vec::new(),
4541
env_vars: Vec::new(),
4642
}
4743
}
@@ -57,12 +53,6 @@ impl<'a> BwrapCmd<'a> {
5753
self
5854
}
5955

60-
/// Bind a device node into the container.
61-
pub fn bind_device(mut self, device: &'a str) -> Self {
62-
self.devices.push(device);
63-
self
64-
}
65-
6656
/// Set an environment variable for the command.
6757
pub fn setenv(mut self, key: &'a str, value: &'a str) -> Self {
6858
self.env_vars.push((key, value));
@@ -79,19 +69,20 @@ impl<'a> BwrapCmd<'a> {
7969
// Setup API filesystems
8070
// See https://systemd.io/API_FILE_SYSTEMS/
8171
cmd.args(["--proc", "/proc"]);
82-
cmd.args(["--dev", "/dev"]);
72+
cmd.args(["--dev-bind", "/dev", "/dev"]);
8373
cmd.args(["--bind", "/sys", "/sys"]);
8474

75+
// Bind /run primarily for the udev database so that
76+
// lsblk/libblkid inside the sandbox can read
77+
// partition type GUIDs and other device properties.
78+
cmd.args(["--tmpfs", "/run"]);
79+
cmd.args(["--bind", "/run", "/run"]);
80+
8581
// Add bind mounts
8682
for (source, target) in &self.bind_mounts {
8783
cmd.args(["--bind", source, target]);
8884
}
8985

90-
// Add device bind mounts
91-
for device in self.devices {
92-
cmd.args(["--dev-bind", device, device]);
93-
}
94-
9586
// Add environment variables
9687
for (key, value) in &self.env_vars {
9788
cmd.args(["--setenv", key, value]);

0 commit comments

Comments
 (0)