Skip to content

Commit

Permalink
Mount overlay with nvidia libraries
Browse files Browse the repository at this point in the history
Nvidia libraries must match the kernel module version. To avoid
the need to rebuild app containers frequently, mount nvidia libraries
as an overlay over base image.
  • Loading branch information
marmarek committed Oct 3, 2023
1 parent c0f534b commit 5324492
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions runtime/init-container/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1996,8 +1996,15 @@ int main(int argc, char **argv) {
CHECK(mkdir("/mnt/overlay/work", S_IRWXU));

CHECK(mount("/dev/vda", "/mnt/image", "squashfs", MS_RDONLY, ""));
CHECK(mount("overlay", SYSROOT, "overlay", 0,
"lowerdir=/mnt/image,upperdir=/mnt/overlay/upper,workdir=/mnt/overlay/work"));
if (access("/dev/vdb", R_OK) == 0) {
CHECK(mkdir("/mnt/gpu-files", S_IRWXU));
CHECK(mount("/dev/vdb", "/mnt/gpu-files", "squashfs", MS_RDONLY, ""));
CHECK(mount("overlay", SYSROOT, "overlay", 0,
"lowerdir=/mnt/image:/mnt/gpu-files,upperdir=/mnt/overlay/upper,workdir=/mnt/overlay/work"));
} else {
CHECK(mount("overlay", SYSROOT, "overlay", 0,
"lowerdir=/mnt/image,upperdir=/mnt/overlay/upper,workdir=/mnt/overlay/work"));
}

g_sysroot_fd = CHECK(open(SYSROOT, O_RDONLY | O_DIRECTORY | O_CLOEXEC));
assert(g_sysroot_fd >= 3);
Expand Down
8 changes: 8 additions & 0 deletions runtime/src/vmrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const DIR_RUNTIME: &str = "runtime";
const FILE_RUNTIME: &str = "vmrt";
const FILE_VMLINUZ: &str = "vmlinuz-virt";
const FILE_INITRAMFS: &str = "initramfs.cpio.gz";
const FILE_NVIDIA_FILES: &str = "nvidia-files.squashfs";

#[derive(Default)]
pub struct RuntimeData {
Expand Down Expand Up @@ -115,6 +116,13 @@ pub async fn start_vmrt(
cmd.arg("none");
}

if Path::new(FILE_NVIDIA_FILES).exists() {
cmd.arg("-drive");
cmd.arg(format!(
"file={},cache=unsafe,readonly=on,format=raw,if=virtio",
FILE_NVIDIA_FILES).as_str());
}

let (vpn, inet) =
// backward-compatibility mode
if vpn_remote.is_none() && inet_remote.is_none() {
Expand Down

0 comments on commit 5324492

Please sign in to comment.