Skip to content

Commit 953ed77

Browse files
authored
Merge pull request #153 from flatcar/remove-nvidia-runtime-symlink
nvidia-runtime: create symlinks dynamically
2 parents d11fc99 + 0fa0765 commit 953ed77

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

nvidia-runtime.sysext/create.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ function populate_sysext_root() {
5353
cp -aR out/usr/lib/*-linux-gnu/* "${sysextroot}/usr/lib/"
5454

5555
ln -s /opt/nvidia "${sysextroot}/usr/local/nvidia"
56-
ln -s /opt/bin/nvidia-smi "${sysextroot}/usr/bin/nvidia-smi"
5756
}
5857
# --
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
[Service]
2-
ExecStartPre=-/bin/sh -c "rm /run/extensions/nvidia-driver && systemctl restart systemd-sysext"
3-
ExecStartPost=-/opt/bin/nvidia-persistenced
4-
ExecStartPost=-/bin/sh -c "chcon -R -t container_file_t /dev/nvidia*"
5-
ExecStartPost=mkdir -p /run/extensions
6-
ExecStartPost=ln -sf /opt/nvidia/current /run/extensions/nvidia-driver
7-
ExecStartPost=systemctl restart systemd-sysext
2+
ExecStartPre=/usr/local/bin/_nvidia-runtime-helper pre
3+
ExecStartPost=/usr/local/bin/_nvidia-runtime-helper post
84
ExecStopPost=rmmod nvidia_uvm nvidia_modeset nvidia
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SYSEXT_MODE=0
5+
if systemd-sysext list 2>&1 | grep -q flatcar-nvidia-drivers; then
6+
SYSEXT_MODE=1
7+
fi
8+
9+
_pre() {
10+
if [ "$SYSEXT_MODE" -eq 0 ]; then
11+
rm /run/extensions/nvidia-driver && systemctl restart systemd-sysext || true
12+
fi
13+
}
14+
15+
_post() {
16+
chcon -R -t container_file_t /dev/nvidia* || true
17+
18+
if [ "$SYSEXT_MODE" -eq 0 ]; then
19+
mkdir -p /run/extensions
20+
# /opt/nvidia/current gets mounted as an overlay on root filesystem
21+
mkdir -p /opt/nvidia/current/usr/bin && ln -sf /opt/bin/nvidia-smi /opt/nvidia/current/usr/bin/nvidia-smi
22+
ln -sf /opt/nvidia/current /run/extensions/nvidia-driver
23+
systemctl restart systemd-sysext
24+
fi
25+
}
26+
27+
if [ ! "$#" -eq 1 ]; then
28+
echo "You need to specify action"
29+
exit 1
30+
fi
31+
32+
case "$1" in
33+
pre)
34+
_pre
35+
;;
36+
post)
37+
_post
38+
;;
39+
*)
40+
echo "Wrong action"
41+
exit 1
42+
;;
43+
esac

0 commit comments

Comments
 (0)