Skip to content

Commit af5f8f5

Browse files
committed
fix: Create NVIDIA control device nodes in nvidia-cdi-refresh.service
Signed-off-by: Seungmin Kim <8457324+ehfd@users.noreply.github.com>
1 parent 2d26818 commit af5f8f5

12 files changed

Lines changed: 81 additions & 1 deletion

deployments/systemd/nvidia-cdi-refresh.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@
1818
# For example, to change the for the generated CDI specification update and
1919
# uncomment the following line:
2020
# NVIDIA_CTK_CDI_OUTPUT_FILE_PATH=/var/run/cdi/nvidia.yaml
21+
22+
# The service also runs
23+
# nvidia-ctk system create-device-nodes --control-devices --load-kernel-modules
24+
# before generating the CDI specification. Its driver and device roots can be
25+
# overridden by uncommenting the following lines (nvidia-ctk cdi generate uses
26+
# the separate NVIDIA_CTK_DRIVER_ROOT and NVIDIA_CTK_DEV_ROOT variables):
27+
#
28+
# NVIDIA_DRIVER_ROOT=/
29+
# NVIDIA_DEV_ROOT=/

deployments/systemd/nvidia-cdi-refresh.service

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ ConditionPathExists=|/usr/bin/nvidia-smi
1818
ConditionPathExists=|/usr/sbin/nvidia-smi
1919
ConditionPathExists=|/usr/lib/wsl/lib/nvidia-smi
2020
ConditionPathExists=/usr/bin/nvidia-ctk
21+
# Order container engines after this service so that the first container
22+
# started at boot does not race the device node creation and CDI refresh.
23+
Before=docker.service containerd.service crio.service
2124
# Limit the number of successive restarts to 5 in 10 seconds.
2225
StartLimitBurst=5
2326
StartLimitIntervalSec=10s
@@ -29,6 +32,11 @@ Environment=NVIDIA_CTK_CDI_OUTPUT_FILE_PATH=/var/run/cdi/nvidia.yaml
2932
EnvironmentFile=-/etc/nvidia-container-toolkit/nvidia-cdi-refresh.env
3033
ExecCondition=/bin/sh -c '/usr/bin/grep -qE "/(nvidia|nvidia-current)[.]ko" /lib/modules/%v/modules.dep || [ -e /dev/dxg ]'
3134
ExecStart=/bin/sh -c '/usr/bin/nvidia-smi -L || /usr/sbin/nvidia-smi -L || /usr/lib/wsl/lib/nvidia-smi -L'
35+
# Create any missing NVIDIA control device nodes (loading the kernel modules
36+
# they require) before generating the CDI specification; nothing else is
37+
# guaranteed to create them. Best-effort, and skipped on WSL where /dev/dxg is
38+
# used instead.
39+
ExecStart=-/bin/sh -c '[ -e /dev/dxg ] || /usr/bin/nvidia-ctk system create-device-nodes --control-devices --load-kernel-modules'
3240
ExecStart=/usr/bin/nvidia-ctk cdi generate
3341
CapabilityBoundingSet=CAP_SYS_MODULE CAP_SYS_ADMIN CAP_MKNOD
3442
# We set the service to restart on failure to ensure that a CDI spec is
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# The NVIDIA control device nodes (/dev/nvidiactl, /dev/nvidia-modeset, and
16+
# /dev/nvidia-uvm*) are created on demand by userspace and are not provided by
17+
# devtmpfs, so loading the NVIDIA kernel module does not guarantee that they
18+
# exist. Trigger nvidia-cdi-refresh.service on module load to create the
19+
# missing nodes and refresh the CDI specification.
20+
ACTION=="add", SUBSYSTEM=="module", KERNEL=="nvidia", TAG+="systemd", ENV{SYSTEMD_WANTS}+="nvidia-cdi-refresh.service"

docker/Dockerfile.debian

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ RUN make PREFIX=${DIST_DIR} cmds
5656
WORKDIR $DIST_DIR
5757
COPY packaging/debian ./debian
5858
COPY deployments/systemd/ .
59+
COPY deployments/udev/ .
5960

6061
RUN dch --create --package="${PKG_NAME}" \
6162
--newversion "${REVISION}" \

docker/Dockerfile.opensuse-leap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ RUN make PREFIX=${DIST_DIR} cmds
4848
WORKDIR $DIST_DIR/..
4949
COPY packaging/rpm .
5050
COPY deployments/systemd/ ${DIST_DIR}/
51+
COPY deployments/udev/ ${DIST_DIR}/
5152

5253
CMD arch=$(uname -m) && \
5354
rpmbuild --clean --target=$arch -bb \

docker/Dockerfile.rpm-yum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ RUN make PREFIX=${DIST_DIR} cmds
7676
WORKDIR $DIST_DIR/..
7777
COPY packaging/rpm .
7878
COPY deployments/systemd/ ${DIST_DIR}/
79+
COPY deployments/udev/ ${DIST_DIR}/
7980

8081
CMD arch=$(uname -m) && \
8182
rpmbuild --clean --target=$arch -bb \

docker/Dockerfile.ubuntu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ RUN make PREFIX=${DIST_DIR} cmds
5454
WORKDIR $DIST_DIR
5555
COPY packaging/debian ./debian
5656
COPY deployments/systemd/ .
57+
COPY deployments/udev/ .
5758

5859
RUN dch --create --package="${PKG_NAME}" \
5960
--newversion "${REVISION}" \

packaging/debian/nvidia-container-toolkit-base.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ nvidia-cdi-hook /usr/bin
44
nvidia-cdi-refresh.service /lib/systemd/system/
55
nvidia-cdi-refresh.path /lib/systemd/system/
66
nvidia-cdi-refresh.env /etc/nvidia-container-toolkit/
7+
99-nvidia-cdi-refresh.rules /lib/udev/rules.d/

packaging/debian/nvidia-container-toolkit-base.postinst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ set -e
55
case "$1" in
66
configure)
77
/usr/bin/nvidia-ctk --quiet config --config-file=/etc/nvidia-container-runtime/config.toml --in-place
8+
9+
# Reload udev rules so that the nvidia-cdi-refresh rules take effect
10+
# without a reboot.
11+
if command -v udevadm >/dev/null 2>&1; then
12+
udevadm control --reload-rules >/dev/null 2>&1 || true
13+
fi
814
;;
915

1016
abort-upgrade|abort-remove|abort-deconfigure)

packaging/debian/rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ override_dh_fixperms:
1616
chmod 755 debian/$(shell dh_listpackages)/usr/bin/nvidia-cdi-hook || true
1717
chmod 644 debian/$(shell dh_listpackages)/lib/systemd/system/nvidia-cdi-refresh.service || true
1818
chmod 644 debian/$(shell dh_listpackages)/lib/systemd/system/nvidia-cdi-refresh.path || true
19+
chmod 644 debian/$(shell dh_listpackages)/lib/udev/rules.d/99-nvidia-cdi-refresh.rules || true

0 commit comments

Comments
 (0)