Skip to content

Commit ad158a0

Browse files
committed
[Ubuntu24.04] Install the driver in a single step
Signed-off-by: Tariq Ibrahim <[email protected]>
1 parent eea136d commit ad158a0

File tree

3 files changed

+37
-201
lines changed

3 files changed

+37
-201
lines changed

ubuntu24.04/Dockerfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ ADD install.sh /tmp
6767
RUN apt-key del 7fa2af80 && OS_ARCH=${TARGETARCH/amd64/x86_64} && OS_ARCH=${OS_ARCH/arm64/sbsa} && \
6868
apt-key adv --fetch-keys "https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/${OS_ARCH}/3bf863cc.pub"
6969

70-
RUN /tmp/install.sh reposetup && /tmp/install.sh depinstall && \
71-
curl -fsSL -o /usr/local/bin/donkey https://github.com/3XX0/donkey/releases/download/v1.1.0/donkey && \
72-
chmod +x /usr/local/bin/donkey
70+
RUN /tmp/install.sh depinstall
7371

7472
COPY nvidia-driver /usr/local/bin
7573

@@ -90,9 +88,6 @@ RUN if [ "$DRIVER_TYPE" != "vgpu" ] && [ "$TARGETARCH" != "arm64" ]; then \
9088

9189
WORKDIR /drivers
9290

93-
ARG PUBLIC_KEY=empty
94-
COPY ${PUBLIC_KEY} kernel/pubkey.x509
95-
9691
# Install / upgrade packages here that are required to resolve CVEs
9792
ARG CVE_UPDATES
9893
RUN if [ -n "${CVE_UPDATES}" ]; then \

ubuntu24.04/install.sh

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,11 @@ dep_install () {
3535
fi
3636
}
3737

38-
repo_setup () {
39-
if [ "$TARGETARCH" = "amd64" ]; then
40-
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ noble main universe" > /etc/apt/sources.list && \
41-
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ noble-updates main universe" >> /etc/apt/sources.list && \
42-
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ noble-security main universe" >> /etc/apt/sources.list && \
43-
usermod -o -u 0 -g 0 _apt
44-
elif [ "$TARGETARCH" = "arm64" ]; then
45-
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports noble main universe" > /etc/apt/sources.list && \
46-
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports noble-updates main universe" >> /etc/apt/sources.list && \
47-
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports noble-security main universe" >> /etc/apt/sources.list && \
48-
usermod -o -u 0 -g 0 _apt
49-
else
50-
echo "TARGETARCH doesn't match a known arch target"
51-
exit 1
52-
fi
53-
}
54-
55-
if [ "$1" = "reposetup" ]; then
56-
repo_setup
57-
elif [ "$1" = "depinstall" ]; then
38+
if [ "$1" = "depinstall" ]; then
5839
dep_install
5940
elif [ "$1" = "download_installer" ]; then
6041
download_installer
6142
else
6243
echo "Unknown function: $1"
6344
exit 1
6445
fi
65-

ubuntu24.04/nvidia-driver

Lines changed: 35 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -100,91 +100,22 @@ _remove_prerequisites() {
100100
fi
101101
}
102102

103-
# Check if the kernel version requires a new precompiled driver packages.
104-
_kernel_requires_package() {
105-
local proc_mount_arg=""
106-
107-
echo "Checking NVIDIA driver packages..."
108-
cd /usr/src/nvidia-${DRIVER_VERSION}/${KERNEL_TYPE}
109-
110-
# proc_mount_arg needs to be set, to do the module match check below
111-
if [ -f /lib/modules/${KERNEL_VERSION}/proc/version ]; then
112-
proc_mount_arg="--proc-mount-point /lib/modules/${KERNEL_VERSION}/proc"
113-
fi
114-
for pkg_name in $(ls -d -1 precompiled/** 2> /dev/null); do
115-
if ! ../mkprecompiled --match ${pkg_name} ${proc_mount_arg} > /dev/null; then
116-
echo "Found NVIDIA driver package ${pkg_name##*/}"
117-
return 1
118-
fi
119-
done
120-
return 0
121-
}
122-
123-
# Compile the kernel modules, optionally sign them, and generate a precompiled package for use by the nvidia-installer.
124-
_create_driver_package() (
125-
local pkg_name="nvidia-modules-${KERNEL_VERSION%-*}${PACKAGE_TAG:+-${PACKAGE_TAG}}"
126-
local nvidia_sign_args=""
127-
local nvidia_modeset_sign_args=""
128-
local nvidia_uvm_sign_args=""
129-
130-
trap "make -s -j ${MAX_THREADS} SYSSRC=/lib/modules/${KERNEL_VERSION}/build clean > /dev/null" EXIT
131-
132-
echo "Compiling NVIDIA driver kernel modules..."
133-
cd /usr/src/nvidia-${DRIVER_VERSION}/${KERNEL_TYPE}
134-
103+
# This is required as currently GPU driver installer doesn't expect headers in x86_64 folder, but only in either default
104+
# or kernel-version folder.
105+
_link_ofa_kernel() (
135106
if _gpu_direct_rdma_enabled; then
136107
ln -s /run/mellanox/drivers/usr/src/ofa_kernel /usr/src/
137108
# if arch directory exists(MOFED >=5.5) then create a symlink as expected by GPU driver installer
138-
# This is required as currently GPU driver installer doesn't expect headers in x86_64 folder, but only in either default or kernel-version folder.
139109
# ls -ltr /usr/src/ofa_kernel/
140110
# lrwxrwxrwx 1 root root 36 Dec 8 20:10 default -> /etc/alternatives/ofa_kernel_headers
141111
# drwxr-xr-x 4 root root 4096 Dec 8 20:14 x86_64
142112
# lrwxrwxrwx 1 root root 44 Dec 9 19:05 5.4.0-90-generic -> /usr/src/ofa_kernel/x86_64/5.4.0-90-generic/
143-
if [[ -d /run/mellanox/drivers/usr/src/ofa_kernel/$DRIVER_ARCH/`uname -r` ]]; then
144-
if [[ ! -e /usr/src/ofa_kernel/`uname -r` ]]; then
145-
ln -s /run/mellanox/drivers/usr/src/ofa_kernel/$DRIVER_ARCH/`uname -r` /usr/src/ofa_kernel/
113+
if [[ -d /run/mellanox/drivers/usr/src/ofa_kernel/$DRIVER_ARCH/$(uname -r) ]]; then
114+
if [[ ! -e /usr/src/ofa_kernel/$(uname -r) ]]; then
115+
ln -s /run/mellanox/drivers/usr/src/ofa_kernel/$DRIVER_ARCH/$(uname -r) /usr/src/ofa_kernel/
146116
fi
147117
fi
148118
fi
149-
150-
export IGNORE_CC_MISMATCH=1
151-
make -s -j ${MAX_THREADS} SYSSRC=/lib/modules/${KERNEL_VERSION}/build nv-linux.o nv-modeset-linux.o > /dev/null
152-
153-
echo "Relinking NVIDIA driver kernel modules..."
154-
rm -f nvidia.ko nvidia-modeset.ko
155-
ld -d -r -o nvidia.ko ./nv-linux.o ./nvidia/nv-kernel.o_binary
156-
ld -d -r -o nvidia-modeset.ko ./nv-modeset-linux.o ./nvidia-modeset/nv-modeset-kernel.o_binary
157-
158-
if [ -n "${PRIVATE_KEY}" ]; then
159-
echo "Signing NVIDIA driver kernel modules..."
160-
donkey get ${PRIVATE_KEY} sh -c "PATH=${PATH}:/usr/src/linux-headers-${KERNEL_VERSION}/scripts && \
161-
sign-file sha512 \$DONKEY_FILE pubkey.x509 nvidia.ko nvidia.ko.sign && \
162-
sign-file sha512 \$DONKEY_FILE pubkey.x509 nvidia-modeset.ko nvidia-modeset.ko.sign && \
163-
sign-file sha512 \$DONKEY_FILE pubkey.x509 nvidia-uvm.ko"
164-
nvidia_sign_args="--linked-module nvidia.ko --signed-module nvidia.ko.sign"
165-
nvidia_modeset_sign_args="--linked-module nvidia-modeset.ko --signed-module nvidia-modeset.ko.sign"
166-
nvidia_uvm_sign_args="--signed"
167-
fi
168-
169-
echo "Building NVIDIA driver package ${pkg_name}..."
170-
../mkprecompiled --pack ${pkg_name} --description ${KERNEL_VERSION} \
171-
--proc-mount-point /lib/modules/${KERNEL_VERSION}/proc \
172-
--driver-version ${DRIVER_VERSION} \
173-
--kernel-interface nv-linux.o \
174-
--linked-module-name nvidia.ko \
175-
--core-object-name nvidia/nv-kernel.o_binary \
176-
${nvidia_sign_args} \
177-
--target-directory . \
178-
--kernel-interface nv-modeset-linux.o \
179-
--linked-module-name nvidia-modeset.ko \
180-
--core-object-name nvidia-modeset/nv-modeset-kernel.o_binary \
181-
${nvidia_modeset_sign_args} \
182-
--target-directory . \
183-
--kernel-module nvidia-uvm.ko \
184-
${nvidia_uvm_sign_args} \
185-
--target-directory .
186-
mkdir -p precompiled
187-
mv ${pkg_name} precompiled
188119
)
189120

190121
_assert_nvswitch_system() {
@@ -420,18 +351,31 @@ _unload_driver() {
420351
_install_driver() {
421352
local install_args=()
422353

423-
echo "Installing NVIDIA driver kernel modules..."
424-
cd /usr/src/nvidia-${DRIVER_VERSION}
425-
if [ -d /lib/modules/${KERNEL_VERSION}/kernel/drivers/video ]; then
426-
rm -rf /lib/modules/${KERNEL_VERSION}/kernel/drivers/video
427-
else
428-
rm -rf /lib/modules/${KERNEL_VERSION}/video
429-
fi
430-
431354
if [ "${ACCEPT_LICENSE}" = "yes" ]; then
432355
install_args+=("--accept-license")
433356
fi
434-
nvidia-installer --kernel-module-only --no-drm --ui=none --no-nouveau-check -m=${KERNEL_TYPE} ${install_args[@]+"${install_args[@]}"}
357+
358+
if [ -n "${MAX_THREADS}" ]; then
359+
install_args+=("--concurrency-level=${MAX_THREADS}")
360+
fi
361+
362+
# Install the NVIDIA driver in one step
363+
sh NVIDIA-Linux-$DRIVER_ARCH-$DRIVER_VERSION.run --silent \
364+
--ui=none \
365+
--no-drm \
366+
--no-nouveau-check \
367+
--no-nvidia-modprobe \
368+
--no-rpms \
369+
--no-backup \
370+
--no-check-for-alternate-installs \
371+
--no-libglx-indirect \
372+
--no-install-libglvnd \
373+
--x-prefix=/tmp/null \
374+
--x-module-path=/tmp/null \
375+
--x-library-path=/tmp/null \
376+
--x-sysconfig-path=/tmp/null \
377+
-m="${KERNEL_TYPE}" \
378+
${install_args[@]+"${install_args[@]}"}
435379
}
436380

437381
# Mount the driver rootfs into the run directory with the exception of sysfs.
@@ -524,26 +468,6 @@ init() {
524468
_find_vgpu_driver_version || exit 1
525469
fi
526470

527-
# Install the userspace components and copy the kernel module sources.
528-
sh NVIDIA-Linux-$DRIVER_ARCH-$DRIVER_VERSION.run -x && \
529-
cd NVIDIA-Linux-$DRIVER_ARCH-$DRIVER_VERSION && \
530-
./nvidia-installer --silent \
531-
--no-kernel-module \
532-
--no-nouveau-check \
533-
--no-nvidia-modprobe \
534-
--no-rpms \
535-
--no-backup \
536-
--no-check-for-alternate-installs \
537-
--no-libglx-indirect \
538-
--no-install-libglvnd \
539-
--x-prefix=/tmp/null \
540-
--x-module-path=/tmp/null \
541-
--x-library-path=/tmp/null \
542-
--x-sysconfig-path=/tmp/null && \
543-
mkdir -p /usr/src/nvidia-${DRIVER_VERSION} && \
544-
mv LICENSE mkprecompiled ${KERNEL_TYPE} /usr/src/nvidia-${DRIVER_VERSION} && \
545-
sed '9,${/^\(kernel\|LICENSE\)/!d}' .manifest > /usr/src/nvidia-${DRIVER_VERSION}/.manifest
546-
547471
echo -e "\n========== NVIDIA Software Installer ==========\n"
548472
echo -e "Starting installation of NVIDIA driver version ${DRIVER_VERSION} for Linux kernel version ${KERNEL_VERSION}\n"
549473

@@ -560,15 +484,13 @@ init() {
560484
_unload_driver || exit 1
561485
_unmount_rootfs
562486

563-
if _kernel_requires_package; then
564-
_update_ca_certificates
565-
_update_package_cache
566-
_resolve_kernel_version || exit 1
567-
_install_prerequisites
568-
_create_driver_package
569-
#_remove_prerequisites
570-
#_cleanup_package_cache
571-
fi
487+
_update_ca_certificates
488+
_update_package_cache
489+
_resolve_kernel_version || exit 1
490+
_install_prerequisites
491+
_link_ofa_kernel
492+
#_remove_prerequisites
493+
#_cleanup_package_cache
572494

573495
_install_driver
574496
_load_driver || exit 1
@@ -583,63 +505,6 @@ init() {
583505
exit 0
584506
}
585507

586-
update() {
587-
exec 3>&2
588-
if exec 2> /dev/null 4< ${PID_FILE}; then
589-
if ! flock -n 4 && read pid <&4 && kill -0 "${pid}"; then
590-
exec > >(tee -a "/proc/${pid}/fd/1")
591-
exec 2> >(tee -a "/proc/${pid}/fd/2" >&3)
592-
else
593-
exec 2>&3
594-
fi
595-
exec 4>&-
596-
fi
597-
exec 3>&-
598-
599-
# vgpu driver version is choosen dynamically during runtime, so pre-compile modules for
600-
# only non-vgpu driver types
601-
if [ "${DRIVER_TYPE}" != "vgpu" ]; then
602-
# Install the userspace components and copy the kernel module sources.
603-
if [ ! -e /usr/src/nvidia-${DRIVER_VERSION}/mkprecompiled ]; then
604-
sh NVIDIA-Linux-$DRIVER_ARCH-$DRIVER_VERSION.run -x && \
605-
cd NVIDIA-Linux-$DRIVER_ARCH-$DRIVER_VERSION && \
606-
./nvidia-installer --silent \
607-
--no-kernel-module \
608-
--no-nouveau-check \
609-
--no-nvidia-modprobe \
610-
--no-rpms \
611-
--no-backup \
612-
--no-check-for-alternate-installs \
613-
--no-libglx-indirect \
614-
--no-install-libglvnd \
615-
--x-prefix=/tmp/null \
616-
--x-module-path=/tmp/null \
617-
--x-library-path=/tmp/null \
618-
--x-sysconfig-path=/tmp/null && \
619-
mkdir -p /usr/src/nvidia-${DRIVER_VERSION} && \
620-
mv LICENSE mkprecompiled ${KERNEL_TYPE} /usr/src/nvidia-${DRIVER_VERSION} && \
621-
sed '9,${/^\(kernel\|LICENSE\)/!d}' .manifest > /usr/src/nvidia-${DRIVER_VERSION}/.manifest
622-
fi
623-
fi
624-
625-
echo -e "\n========== NVIDIA Software Updater ==========\n"
626-
echo -e "Starting update of NVIDIA driver version ${DRIVER_VERSION} for Linux kernel version ${KERNEL_VERSION}\n"
627-
628-
trap "echo 'Caught signal'; exit 1" HUP INT QUIT PIPE TERM
629-
630-
_update_package_cache
631-
_resolve_kernel_version || exit 1
632-
_install_prerequisites
633-
if _kernel_requires_package; then
634-
_create_driver_package
635-
fi
636-
_remove_prerequisites
637-
_cleanup_package_cache
638-
639-
echo "Done"
640-
exit 0
641-
}
642-
643508
# Wait for MOFED drivers to be loaded and load nvidia-peermem whenever it gets unloaded during MOFED driver updates
644509
reload_nvidia_peermem() {
645510
if [ "$USE_HOST_MOFED" = "true" ]; then
@@ -688,7 +553,6 @@ Usage: $0 COMMAND [ARG...]
688553
689554
Commands:
690555
init [-a | --accept-license] [-m | --max-threads MAX_THREADS]
691-
update [-k | --kernel VERSION] [-s | --sign KEYID] [-t | --tag TAG] [-m | --max-threads MAX_THREADS]
692556
EOF
693557
exit 1
694558
}
@@ -699,7 +563,6 @@ fi
699563
command=$1; shift
700564
case "${command}" in
701565
init) options=$(getopt -l accept-license,max-threads: -o am: -- "$@") ;;
702-
update) options=$(getopt -l kernel:,sign:,tag:,max-threads: -o k:s:t:m: -- "$@") ;;
703566
reload_nvidia_peermem) options="" ;;
704567
probe_nvidia_peermem) options="" ;;
705568
*) usage ;;
@@ -712,15 +575,13 @@ eval set -- "${options}"
712575
ACCEPT_LICENSE=""
713576
MAX_THREADS=""
714577
KERNEL_VERSION=$(uname -r)
715-
PRIVATE_KEY=""
716578
PACKAGE_TAG=""
717579

718580
for opt in ${options}; do
719581
case "$opt" in
720582
-a | --accept-license) ACCEPT_LICENSE="yes"; shift 1 ;;
721583
-k | --kernel) KERNEL_VERSION=$2; shift 2 ;;
722584
-m | --max-threads) MAX_THREADS=$2; shift 2 ;;
723-
-s | --sign) PRIVATE_KEY=$2; shift 2 ;;
724585
-t | --tag) PACKAGE_TAG=$2; shift 2 ;;
725586
--) shift; break ;;
726587
esac

0 commit comments

Comments
 (0)