Repository navigation
Expand file tree
/
Copy pathnvidia_module_install.zsh
More file actions
executable file
·124 lines (104 loc) · 3.65 KB
/
Copy pathnvidia_module_install.zsh
File metadata and controls
executable file
·124 lines (104 loc) · 3.65 KB
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
#!/usr/bin/env zsh
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright (c) 2023-2026 Maulik Mistry
#
# nvidia_moduole_install.zsh - Install NVIDIA kernel modules and configure Wayland compatibility on Ubuntu.
#
# Author: Maulik Mistry
# Please share support: https://www.paypal.com/paypalme/m1st0
# https://venmo.com/code?user_id=3319592654995456106&created=1753283702
SCRIPT_DIR="${0:A:h}"
source "$SCRIPT_DIR/vendor/tput_shell_colorize/tput_shell_colorize.sh"
# NVIDIA driver version.
# Update this value when intentionally moving driver generations.
#
# If upgrading this value (for example 580 -> 585), previous apt-mark holds
# will remain on the old NVIDIA package names. Check existing holds with:
#
# apt-mark showhold | grep 'nvidia-'
#
# Remove old holds before migrating if needed:
#
# sudo apt-mark unhold <package-name>
driver_version=580
# Build NVIDIA kernel package list for every installed kernel.
# This allows a kernel upgrade to require only one reboot.
packages=()
kernel_packages=()
for kernel in /lib/modules/*; do
kernel=${kernel##*/}
kernel_packages+=(
"linux-modules-nvidia-${driver_version}-${kernel}"
"linux-objects-nvidia-${driver_version}-${kernel}"
"linux-signatures-nvidia-${kernel}"
)
done
packages+=("${kernel_packages[@]}")
packages+=(
"nvidia-utils-${driver_version}"
"libnvidia-gl-${driver_version}"
)
is_installed() {
dpkg-query -W -f='${Status}\n' "$1" 2>/dev/null | \
grep -q '^install ok installed$'
}
missing_packages=()
for package in "${packages[@]}"; do
if is_installed "$package"; then
messenger_std "✓ $package is installed."
else
messenger_end "✗ $package is missing."
missing_packages+=("$package")
fi
done
if (( ${#missing_packages[@]} > 0 )); then
linefeed
messenger_std "Installing missing NVIDIA packages..."
if sudo apt install -y "${missing_packages[@]}"; then
linefeed
messenger_std "Holding NVIDIA kernel packages..."
sudo apt-mark hold "${kernel_packages[@]}"
else
messenger_end "NVIDIA package installation failed."
exit 1
fi
else
linefeed
messenger_end "All NVIDIA packages are already installed."
linefeed
messenger_std "Holding NVIDIA kernel packages..."
sudo apt-mark hold "${kernel_packages[@]}"
fi
if ! sudo apt install -y "nvidia-vaapi-driver"; then
messenger_end "Verify you have \`nvidia-vaapi-driver\` available in your APT sources."
fi
# Prevent NVIDIA modules from automatically loading.
# This avoids SDDM failures on some Optimus laptops under Wayland.
sudo tee /etc/modprobe.d/blacklist-nvidia.conf > /dev/null << 'EOF'
blacklist nvidia
blacklist nvidia-drm
blacklist nvidia-modeset
blacklist nvidia-uvm
EOF
# Disable NVIDIA services that interfere with manual Optimus activation.
sudo ln -sf /dev/null \
/etc/systemd/system/systemd-hibernate.service.requires/nvidia-hibernate.service
sudo systemctl mask \
nvidia-hibernate.service \
nvidia-suspend.service \
sys-bus-pci-drivers-nvidia.device \
nvidia-resume.service \
nvidia-fabricmanager.service \
nvidia-persistenced.service \
nvidia-suspend-then-hibernate.service
sudo systemctl daemon-reload
linefeed
messenger_std "✓ NVIDIA ${driver_version} modules installed and configured.
Use nvidia_wake.zsh to run programs on the discrete GPU.
Run it without parameters to turn the discrete GPU off."
linefeed
messenger_std "If changing NVIDIA driver versions in the future, review existing holds:
apt-mark showhold | grep 'nvidia-'"
linefeed
messenger_std "Remove outdated holds with:
sudo apt-mark unhold <package-name>"