MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / prepare_sandbox_rootfs

Function prepare_sandbox_rootfs

crates/openshell-driver-vm/src/rootfs.rs:355–392  ·  view source on GitHub ↗
(rootfs: &Path, sandbox_uid: u32, sandbox_gid: u32)

Source from the content-addressed store, hash-verified

353
354#[allow(clippy::similar_names)]
355fn prepare_sandbox_rootfs(rootfs: &Path, sandbox_uid: u32, sandbox_gid: u32) -> Result<(), String> {
356 for relative in ["opt/openshell/.initialized", "opt/openshell/.rootfs-type"] {
357 remove_rootfs_path(rootfs, relative)?;
358 }
359
360 let init_path = rootfs.join("srv/openshell-vm-sandbox-init.sh");
361 if let Some(parent) = init_path.parent() {
362 fs::create_dir_all(parent).map_err(|e| format!("create {}: {e}", parent.display()))?;
363 }
364 fs::write(
365 &init_path,
366 include_str!("../scripts/openshell-vm-sandbox-init.sh"),
367 )
368 .map_err(|e| format!("write {}: {e}", init_path.display()))?;
369 #[cfg(unix)]
370 {
371 use std::os::unix::fs::PermissionsExt as _;
372
373 fs::set_permissions(&init_path, fs::Permissions::from_mode(0o755))
374 .map_err(|e| format!("chmod {}: {e}", init_path.display()))?;
375 }
376
377 ensure_supervisor_binary(rootfs)?;
378 ensure_umoci_binary(rootfs)?;
379
380 let opt_dir = rootfs.join("opt/openshell");
381 fs::create_dir_all(&opt_dir).map_err(|e| format!("create {}: {e}", opt_dir.display()))?;
382 fs::write(opt_dir.join(".rootfs-type"), "sandbox\n")
383 .map_err(|e| format!("write sandbox rootfs marker: {e}"))?;
384 ensure_sandbox_guest_user(rootfs, sandbox_uid, sandbox_gid)?;
385 create_sandbox_mountpoint(&rootfs.join("sandbox"))?;
386 create_sandbox_mountpoint(&rootfs.join("image-cache"))?;
387 create_sandbox_mountpoint(&rootfs.join("lower"))?;
388 create_sandbox_mountpoint(&rootfs.join("overlay"))?;
389 create_sandbox_mountpoint(&rootfs.join("newroot"))?;
390
391 Ok(())
392}
393
394pub fn validate_sandbox_rootfs(rootfs: &Path) -> Result<(), String> {
395 require_rootfs_path(rootfs, SANDBOX_GUEST_INIT_PATH)?;

Calls 5

remove_rootfs_pathFunction · 0.85
ensure_supervisor_binaryFunction · 0.85
ensure_umoci_binaryFunction · 0.85