From 87ce0f648bf6b468d779c911bec902e21f2bbc6b Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Tue, 13 Jan 2026 09:58:16 +0100 Subject: [PATCH] deb: create special device nodes inside chroot --- src/deb/ephemeral.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/deb/ephemeral.rs b/src/deb/ephemeral.rs index a307fd0..f4f3c5d 100644 --- a/src/deb/ephemeral.rs +++ b/src/deb/ephemeral.rs @@ -102,6 +102,10 @@ impl EphemeralContextGuard { log::debug!("Extracting chroot tarball to {}...", chroot_path.display()); Self::extract_tarball(&tarball_path, chroot_path)?; + // Create device nodes in the chroot + log::debug!("Creating device nodes in chroot..."); + Self::create_device_nodes(chroot_path)?; + Ok(()) } @@ -167,6 +171,57 @@ impl EphemeralContextGuard { Ok(()) } + + fn create_device_nodes(chroot_path: &Path) -> Result<(), Box> { + let ctx = context::current(); + let dev_null_path = chroot_path.join("dev/null"); + let dev_zero_path = chroot_path.join("dev/zero"); + + // Ensure /dev directory exists + fs::create_dir_all(chroot_path.join("dev"))?; + + // Remove existing device nodes if they exist + let _ = ctx + .command("rm") + .arg("-f") + .arg(dev_null_path.to_string_lossy().to_string()) + .status(); + + let _ = ctx + .command("rm") + .arg("-f") + .arg(dev_zero_path.to_string_lossy().to_string()) + .status(); + + // Create new device nodes using fakeroot and mknod + let status_null = ctx + .command("sudo") + .arg("mknod") + .arg("-m") + .arg("666") + .arg(dev_null_path.to_string_lossy().to_string()) + .arg("c") + .arg("1") + .arg("3") + .status()?; + + let status_zero = ctx + .command("sudo") + .arg("mknod") + .arg("-m") + .arg("666") + .arg(dev_zero_path.to_string_lossy().to_string()) + .arg("c") + .arg("1") + .arg("5") + .status()?; + + if !status_null.success() || !status_zero.success() { + return Err("Failed to create device nodes".into()); + } + + Ok(()) + } } impl Drop for EphemeralContextGuard {