This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
install-driver
executable file
·452 lines (388 loc) · 15.8 KB
/
install-driver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/usr/bin/env bash
# shellcheck disable=SC2045,SC2059,SC2143
# shellcheck source=/dev/null
[[ $(source "/etc/os-release" 2>/dev/null; echo "$ID") == "clear-linux-os" ]] || exit 1
# Driver installer script for NVIDIA graphics on Clear Linux OS.
# Usage: ./install-driver latest|550|555|vulkan|<pathname>
#
# NVIDIA Driver Archive
# https://download.nvidia.com/XFree86/Linux-x86_64/
# https://www.nvidia.com/en-us/drivers/unix/
#
# Vulkan Driver Support
# https://developer.nvidia.com/vulkan-driver
#
# CUDA Redistributable Driver Archive
# https://developer.download.nvidia.com/compute/cuda/redist/nvidia_driver/linux-x86_64/
kernel=$(uname -r)
osver=$(source "/etc/os-release"; echo "$VERSION_ID")
# Exit if the "fix-nvidia-libGL-trigger.service" file is missing.
if [[ ! -f "/etc/systemd/system/fix-nvidia-libGL-trigger.service" ]]; then
echo "Please run 'bash pre-install-driver' first."
exit 1
fi
# Exit if dkms or the kernel-source is not installed.
if [[ ! -x "/usr/bin/dkms" ]]; then
echo "The dkms package is not installed, exiting."
exit 1
elif [[ ! -f "/usr/lib/modules/${kernel}/build/Makefile" ]]; then
echo "The kernel source is not installed for ${kernel}, exiting."
exit 1
fi
# On first use after OS install, perform check in the event "nomodeset"
# is passed to the kernel and attempting shortcut by not rebooting.
# The installer requires a non-graphical environment to run.
contflag=1 state=$(systemctl is-active graphical.target 2>&1)
if [[ "$state" == "active" ]]; then
contflag=0
elif [[ -n $(pidof gnome-shell) || -n $(pidof xdg-desktop-portal) ]]; then
contflag=0
fi
if [[ $contflag -eq 0 ]]; then
echo "Run the pre-install-driver script with no arguments."
echo "Then, login into multi-user mode to install the driver."
exit 1
fi
###############################################################################
# Parse command-line arguments.
inst_file=""
path_regex1="NVIDIA-Linux-x86_64-.*\.run$"
path_regex2="nvidia_driver-linux-x86_64-.*-archive\.tar\.xz"
path_vulkan="vulkan-.*-linux$"
case "$1" in
latest) echo "Retrieving latest information from the web."
in=$(curl -sL "https://download.nvidia.com/XFree86/Linux-x86_64/latest.txt" | head -1);
inst_url="https://download.nvidia.com/XFree86/Linux-x86_64/${in##* }"
;;
550) inst_url="https://download.nvidia.com/XFree86/Linux-x86_64/550.107.02/NVIDIA-Linux-x86_64-550.107.02.run"
;;
555) inst_url="https://download.nvidia.com/XFree86/Linux-x86_64/555.58.02/NVIDIA-Linux-x86_64-555.58.02.run"
;;
vulkan) inst_url="https://developer.nvidia.com/downloads/vulkan-beta-5504065-linux"
;;
*) if [[ "$1" =~ $path_regex1 ]]; then
# Installation via a driver run file
if [[ ! -f "$1" ]]; then
echo "ERROR: Cannot open '$1' (No such file)"
exit 1
fi
if [[ "$1" == *"grid"* || "$1" == *"vgpu"* || "$1" == *"kvm"* ]]; then
echo "ERROR: Cannot install '$1' (Not supported)"
exit 1
fi
inst_file="$1"
elif [[ "$1" =~ $path_regex2 ]]; then
# Installation via a CUDA redistributable driver file
if [[ ! -f "$1" ]]; then
echo "ERROR: Cannot open '$1' (No such file)"
exit 1
fi
inst_file="$1"
elif [[ "$1" =~ $path_vulkan ]]; then
# Installation via a Vulkan driver file
if [[ ! -f "$1" ]]; then
echo "ERROR: Cannot open '$1' (No such file)"
exit 1
fi
inst_file="$1"
else
echo "Usage: ${0##*/} latest|550|555|vulkan|<pathname>"
exit 1
fi
esac
# Download the driver installer from the web.
[[ -z ${inst_file} ]] && inst_file="${inst_url##*/}"
[[ -n ${SUDO_USER} ]] && user=$SUDO_USER || user=$USER
if [[ ! -s "$inst_file" ]]; then
inst_file="Downloads/$inst_file"
if [[ ! -s "$inst_file" ]]; then
if [[ ! -d Downloads && ! -L Downloads ]]; then
echo "Creating symbolic link."
DownloadPath="/home/${user}/Downloads"
if [[ -e "/usr/bin/xdg-user-dir" ]]; then
DownloadPath="$(xdg-user-dir DOWNLOAD)"
fi
if [[ ! -d "$DownloadPath" ]]; then
mkdir -p "$DownloadPath"
chown "$user:$user" "$DownloadPath"
chmod 755 "$DownloadPath"
fi
ln -sfv "$DownloadPath" "Downloads"
fi
echo "Downloading ${inst_file##*/} from download.nvidia.com ..."
curl -LO --output-dir "Downloads" "$inst_url"
if [[ ! -f "$inst_file" || -n $(grep "404 - Not Found" "$inst_file") ]]; then
rm -f "$inst_file"
echo "ERROR: ${inst_file##*/} (No such file at download URL)"
echo "https://download.nvidia.com/XFree86/Linux-x86_64/"
echo "https://developer.download.nvidia.com/compute/cuda/redist/nvidia_driver/linux-x86_64/"
exit 1
fi
fi
fi
nvver1=$(echo "$inst_file" | cut -f4 -d- | cut -f1 -d.)
nvver2=$(echo "$inst_file" | cut -f4 -d- | cut -f2 -d.)
apply_gpl_pfn_valid_patch=0
apply_gcc14_update=0
if [[ "$inst_file" =~ $path_vulkan ]]; then
true # pass - The path vulkan regex is checked first.
elif [[ ${nvver1} -le 545 ]]; then
echo "ERROR: The ${nvver1} release is unsupported. Try 550 or later release."
exit 1
elif [[ ${nvver1} -eq 550 && ${nvver2} -le 40 ]]; then
apply_gpl_pfn_valid_patch=1
apply_gcc14_update=1
elif [[ ${nvver1} -eq 550 && ${nvver2} -le 54 ]]; then
apply_gcc14_update=1
fi
###############################################################################
# Test sudo and exit if wrong password or terminated via Ctrl-C.
sudo id >/dev/null || exit 2
# Create directories.
sudo mkdir -p /etc/X11
sudo mkdir -p /opt/nvidia/lib32
sudo mkdir -p /opt/nvidia/lib64
sudo mkdir -p /var/lib/dkms
# Allow save to /etc/X11/xorg.conf via NVIDIA settings as the normal user.
# E.g. Settings > X Server Display Configuration > Save to X Configuration File
[[ -f /etc/X11/xorg.conf ]] && sudo chown "$user" /etc/X11/xorg.conf
sudo chown "$user" /etc/X11
# Remove /etc/{egl,glvnd,nvidia}; created from prior repo revisions.
if [[ -L /usr/share/nvidia ]]; then
sudo rm -rf /etc/{egl,glvnd,nvidia} /usr/share/nvidia
fi
# Remove development libraries {EGL, GLESv1_CM, GLESv2, GL, OpenCL, OpenGL}.
# They are restored by the fix-nvidia-libGL-trigger service.
if [[ ${osver} -ge 38270 ]]; then
[[ -L /usr/lib64/libOpenCL.so ]] && sudo rm -f /usr/lib{32,64}/libOpenCL.so
else
[[ -L /usr/lib64/libEGL.so ]] && sudo rm -f /usr/lib{32,64}/libEGL.so
[[ -L /usr/lib64/libGLESv1_CM.so ]] && sudo rm -f /usr/lib{32,64}/libGLESv1_CM.so
[[ -L /usr/lib64/libGLESv2.so ]] && sudo rm -f /usr/lib{32,64}/libGLESv2.so
[[ -L /usr/lib64/libGL.so ]] && sudo rm -f /usr/lib{32,64}/libGL.so
[[ -L /usr/lib64/libOpenCL.so ]] && sudo rm -f /usr/lib{32,64}/libOpenCL.so
[[ -L /usr/lib64/libOpenGL.so ]] && sudo rm -f /usr/lib{32,64}/libOpenGL.so
fi
# Remove the vulkan producer libs, to be copied after installation.
sudo rm -f /usr/lib64/libnvidia-vulkan-producer.so.*
# Define arguments for the NVIDIA installer script.
args=""
args+=" --force-libglx-indirect"
args+=" --glvnd-egl-config-path=/usr/share/glvnd/egl_vendor.d"
args+=" --x-prefix=/opt/nvidia"
args+=" --x-library-path=/opt/nvidia/lib64"
args+=" --x-sysconfig-path=/etc/X11/xorg.conf.d"
args+=" --compat32-prefix=/opt/nvidia"
args+=" --compat32-libdir=lib32"
args+=" --opengl-prefix=/opt/nvidia"
args+=" --no-precompiled-interface"
args+=" --no-distro-scripts"
args+=" --no-cc-version-check"
args+=" --no-nouveau-check"
args+=" --silent"
args+=" --no-dkms"
sudo cp "check-kernel-dkms" /tmp/.
if [[ ${apply_gpl_pfn_valid_patch} -eq 1 ]]; then
sudo cp "patches/nvidia-gpl-pfn_valid.patch" /tmp/.
fi
if [[ ${apply_gcc14_update} -eq 1 ]]; then
sudo cp "patches/nvidia-drivers-gcc14.patch" /tmp/.
fi
# Remove all /usr/src/nvidia-* folders and /var/lib/dkms/nvidia/VERSION.
# This is necessary in case of prior gpl_pfn_valid patching.
sudo rm -fr /usr/src/nvidia-[0-9]*[0-9]
sudo rm -fr /var/lib/dkms/nvidia/[0-9]*[0-9]
# Install driver.
if [[ "$inst_file" =~ $path_regex1 || "$inst_file" =~ $path_vulkan ]]; then
# Installation via a driver run file
echo "Installing the NVIDIA proprietary driver..."
# shellcheck disable=SC2086
sudo CFLAGS="" CXXFLAGS="" IGNORE_PREEMPT_RT_PRESENCE=1 \
bash -c "export PATH=/tmp:\$PATH; bash '$inst_file' $args 2>/dev/null"
status=$?
else
# Installation via a CUDA redistributable driver file
inst_ver=$(echo "$inst_file" | cut -f4 -d-)
echo "Uncompressing CUDA Redistributable Driver for Linux-$(uname -m) ${inst_ver}"
mkdir -p "/tmp/nvidia-redist.$$"
tar xJf "$inst_file" -C "/tmp/nvidia-redist.$$"
echo "Installing the NVIDIA proprietary driver..."
# shellcheck disable=SC2164
cd /tmp/nvidia-redist.$$/*
# Relocate files to match a run file installation
mv CHANGELOG NVIDIA_Changelog
mv MANIFEST .manifest
mv README README.txt
mv bin/* .
mv docs html
mv etc/* .
mv lib/* .
mv lib32 32
mv man/man1/* .
mv sbin/* .
mv share/* .
mv tests/glvnd libglvnd_install_checker
mv tests/glvnd32 32/libglvnd_install_checker
mv wine/* .
rm -rf bin etc lib man sbin share tests wine
# Create nvidia-persistenced-init.tar.bz2
if [[ -d "src/nvidia-persistenced/init" ]]; then
mv src/nvidia-persistenced/init nvidia-persistenced-init
tar cjf nvidia-persistenced-init.tar.bz2 nvidia-persistenced-init
rm -rf nvidia-persistenced-init src
fi
# Check if exist nvidia/rim folder
if [[ -d "nvidia/rim" ]]; then
mv nvidia/rim/* .
rm -fr nvidia
fi
# Create pkg-history.txt
ver=$(./nvidia-installer --version | awk '/version/ { print $NF; exit }')
( printf "Package history for NVIDIA-Linux-x86_64-${ver}-internal:\n\n"
printf "NVIDIA-Linux-x86_64-${ver}-internal: Initial package\n\n"
printf "NVIDIA-Linux-x86_64-${ver}: Added 32 bit compatibility libraries\n\n"
printf "NVIDIA-Linux-x86_64-${ver}: Added Wine files\n\n"
) > pkg-history.txt; unset ver
# Run the installer
# shellcheck disable=SC2086
sudo CFLAGS="" CXXFLAGS="" IGNORE_PREEMPT_RT_PRESENCE=1 \
bash -c "export PATH=/tmp:\$PATH; ./nvidia-installer $args 2>/dev/null"
status=$?
# Clean up
cd "/tmp" || exit
sudo rm -rf "/tmp/nvidia-redist.$$"
fi
# Terminate here if the NVIDIA installation failed.
if [[ $status -ne 0 ]]; then
echo "ERROR: Failed to the install the NVIDIA proprietary driver."
echo "See /var/log/nvidia-installer.log for details."
exit $status
else
echo "The NVIDIA driver installation succeeded."
echo
fi
module_dir=$(cd /usr/src; ls -1dr nvidia-*[0-9] | head -1)
dkms_module=${module_dir//-/\/}
# Fix GPL-incompatible module nvidia.ko uses GPL-only symbol __rcu_read_[un]lock.
(
if [[ ${apply_gpl_pfn_valid_patch} -eq 1 && -f "/tmp/nvidia-gpl-pfn_valid.patch" ]]; then
echo "Applying nvidia-gpl-pfn_valid.patch to /usr/src/${module_dir}"
cd "/usr/src/${module_dir}"
sudo patch -Np2 --no-backup-if-mismatch -i "/tmp/nvidia-gpl-pfn_valid.patch"
sudo rm -f "/tmp/nvidia-gpl-pfn_valid.patch"
echo
fi
)
# Apply GCC14 support to conftest.sh.
(
if [[ ${apply_gcc14_update} -eq 1 && -f "/tmp/nvidia-drivers-gcc14.patch" ]]; then
echo "Applying nvidia-drivers-gcc14.patch to /usr/src/${module_dir}"
cd "/usr/src/${module_dir}"
sudo patch -Np2 --no-backup-if-mismatch -i "/tmp/nvidia-drivers-gcc14.patch"
sudo rm -f "/tmp/nvidia-drivers-gcc14.patch"
echo
fi
)
# Register DKMS module.
echo "Registering the NVIDIA kernel module sources with DKMS."
sudo dkms add ${dkms_module}
# Build kernel modules.
echo "Building the NVIDIA kernel modules."
sudo "/tmp/check-kernel-dkms" || exit $?
sudo rm -f "/tmp/check-kernel-dkms"
# Configure NVD_BACKEND, system-wide.
sudo mkdir -p "/etc/environment.d"
sudo tee "/etc/environment.d/10-nvidia-vaapi-driver.conf" >/dev/null <<'EOF'
# The EGL backend (which is still the default) was broken in the 525 driver
# series, so the direct backend is necessary for decoding to work.
NVD_BACKEND=direct
# Wayland fix for integrated AMD/Intel GPU with optimus.
# https://github.com/elFarto/nvidia-vaapi-driver/issues/247
NVD_GPU=0
EOF
# Default to "gnome-wayland" for the login session.
if [[ ${osver} -ge 38270 ]]; then
sudo mkdir -p "/var/lib/AccountsService/users"
sudo chown 0700 "/var/lib/AccountsService/users"
userconf="/var/lib/AccountsService/users/$user"
sudo touch "$userconf"
lncount=$(sudo wc -l "$userconf")
if [[ ${lncount% *} -eq 0 ]]; then
echo "Default to 'gnome-wayland' for the login session."
sudo tee "$userconf" >/dev/null <<"EOF"
[User]
Session=gnome-wayland
SystemAccount=false
EOF
fi
fi
# Disable the NVIDIA_PRESERVE_VIDEO_MEMORY_ALLOCATIONS check in 61-gdm.rules.
if [[ -e /usr/lib/udev/rules.d/61-gdm.rules ]]; then
sudo mkdir -p /etc/udev/rules.d
awk '
/NVIDIA_PRESERVE_VIDEO_MEMORY_ALLOCATIONS/ { printf "#%s\n", $0; next }
/^GOTO="gdm_disable_wayland"/ { printf "GOTO=\"gdm_end\"\n"; next }
{ print $0 }
' /usr/lib/udev/rules.d/61-gdm.rules \
| sudo tee /etc/udev/rules.d/61-gdm.rules >/dev/null
fi
if [[ ${nvver1} -ge 545 ]]; then
# Remove symbolic link left behind. The helper library was removed in 545.23.06,
# no longer needed by the Wayland WSI.
sudo rm -f /usr/lib64/libnvidia-vulkan-producer.so
else
# Fix missing NVIDIA libraries in /usr/lib64/.
sudo cp -a /opt/nvidia/lib64/libnvidia-vulkan-producer.so.* /usr/lib64/. 2>/dev/null
fi
if [[ -e /usr/lib64/libnvidia-allocator.so.1 ]]; then
if [[ ! -e /usr/lib64/gbm/nvidia-drm_gbm.so ]]; then
sudo mkdir -p /usr/lib64/gbm
sudo ln -sf /usr/lib64/libnvidia-allocator.so.1 /usr/lib64/gbm/nvidia-drm_gbm.so
fi
fi
sudo ldconfig
###############################################################################
# Update the X11 output class configuration file, making NVIDIA the primary GPU.
echo "Updating the X11 output class configuration file."
sudo tee "/etc/X11/xorg.conf.d/nvidia-drm-outputclass.conf" >/dev/null <<'EOF'
Section "OutputClass"
Identifier "nvidia"
MatchDriver "nvidia-drm"
Driver "nvidia"
Option "AllowEmptyInitialConfiguration"
Option "PrimaryGPU" "yes" # This can be commented if wanted Intel as primary GPU
Option "SLI" "Auto"
Option "BaseMosaic" "on"
EndSection
Section "OutputClass"
Identifier "intel"
MatchDriver "i915"
Driver "modesetting"
Option "AccelMethod" "none" # Comment when using Intel as primary
EndSection
EOF
# Reload systemd and run the trigger service.
echo "Running the fix-nvidia-libGL-trigger service."
sudo systemctl daemon-reload
sudo systemctl start fix-nvidia-libGL-trigger.service
###############################################################################
# Finish.
if [[ ${USER} != "root" ]]; then
# The $user variable is set to $SUDO_USER or $USER above.
gpucache_list1=$(find /home/${user}/.config -name GPUCache 2>/dev/null)
gpucache_list2=$(find /home/${user}/.local -name GPUCache 2>/dev/null)
if [[ -n "$gpucache_list1" || -n "$gpucache_list2" ]]; then
echo "Clearing GPUCache for Electron applications."
rm -fr $gpucache_list1 $gpucache_list2 2>/dev/null
fi
echo "Updating the flatpak user runtime."
flatpak update --user -y
fi
sync
echo ""
echo "On Optimus-based laptops, edit /etc/X11/xorg.conf.d/nvidia-drm-outputclass.conf"
echo "and comment two lines 'PrimaryGPU'/'AccelMethod' to use Intel as the primary GPU."
echo "Remove also /etc/X11/xorg.conf if the file exist."
echo ""
echo "Run 'sudo reboot' afterwards."
echo ""