-
Notifications
You must be signed in to change notification settings - Fork 1
/
nvidianew.sh
305 lines (238 loc) · 9.3 KB
/
nvidianew.sh
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
#!/bin/bash
# nvidianew.sh
# Michael McMahon
# This script installs proprietary NVIDIA drivers 384.98 and CUDA toolkit
# for GPU video output.
## Instructions:
# Run this script with:
# sudo bash nvidianew.sh
# OR
# su
# bash nvidianew.sh
# OR
# sudo chmod 755 nvidianew.sh
# sudo ./nvidianew.sh
# OR
# su
# chmod 755 nvidianew.sh
# ./nvidianew.sh
# Prerequisites for this script:
#
# 1. Run this script as root.
# bash nvidianew.sh
# OR
# sudo bash nvidianew.sh
#
# 2. Reboot and verify that all cards are working by running:
# nvidia-smi
#
# Initialization checks
# Check for /bin/bash.
if [ "$BASH_VERSION" = '' ]; then
echo "You are not using bash."
echo "Use this syntax instead:"
echo "bash nvidia.sh"
exit 1
fi
# Check for root.
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Check networking
# https://unix.stackexchange.com/questions/190513/shell-scripting-proper-way-to-check-for-internet-connectivity
echo Checking network...
if ping -q -c 1 -W 1 google.com >/dev/null; then
echo "The network is up."
else
echo "The network is down."
echo "Check connection and restart script!"
exit 1
fi
if [[ $(runlevel | awk '{ print $2 }') -gt 3 ]]; then
echo "Runlevel is greater than 3."
echo "Starting the machine will need to reboot after initial work."
echo "Creating boot hook..."
# cat << EOF > /etc/systemd/system/nvidiainstall.service
#[Unit]
#Description=Temporary script to install proprietary NVIDIA drivers
#After=network.target
#[Service]
#ExecStart=/usr/local/bin/disk-space-check.sh
#ExecStart=/etc/init.d/nvidiagpuinstall_once
#[Install]
#WantedBy=default.target
#EOF
cat << EOF > /etc/init.d/nvidiagpuinstall_once
#!/bin/bash
# NVIDIA install hook
# Located at /etc/init.d/nvidiagpuinstall_once
# Symlinked from /etc/rc3.d/S01nvidiagpuinstall
### BEGIN INIT INFO
# Provides: nvidiagpuinstall_once
# Required-Start:
# Required-Stop:
# Default-Start: 3
# Default-Stop:
# Short-Description: Install proprietary NVIDIA drivers during runlevel 3
# Description:
### END INIT INFO
# Log all stdout to logfile with date.
logfile=/tmp/$(date +%Y%m%d-%H%M).log
exec &> >(tee -a "$logfile")
echo Starting logfile as $logfile...
echo \
echo "Temporarily removing nouvea..."
modprobe -r nouveau
# DEBUG # nouveau continues to run with Scientific Linux 7
echo "Changing into the /tmp directory..."
cd /tmp
echo "This script currently works with GPU video output for"
echo "RPM or DEB workflows after you have properly booted."
# Downloading
echo "Downloading proprietary NVIDIA drivers..."
#wget -q http://us.download.nvidia.com/XFree86/Linux-x86_64/384.98/NVIDIA-Linux-x86_64-384.98.run
wget -q ftp://10.12.17.15/pub/software/drivers/nvidia/NVIDIA-Linux-x86_64-384.98.run
#wget -q http://us.download.nvidia.com/XFree86/Linux-x86_64/384.90/NVIDIA-Linux-x86_64-384.90.run
#wget -q ftp://10.12.17.15/pub/software/drivers/nvidia/NVIDIA-Linux-x86_64-384.90.run
#wget -q http://us.download.nvidia.com/XFree86/Linux-x86_64/384.69/NVIDIA-Linux-x86_64-384.69.run
#wget -q ftp://10.12.17.15/pub/software/drivers/nvidia/NVIDIA-Linux-x86_64-384.69.run
# Experimental automatically download latest stable driver
#wget http://www.nvidia.com/object/unix.html
#cat unix.html | grep "Latest Long Lived Branch version" | head -n 1 | cut -d '"' -f2 | xargs wget
#cat en-us | grep "confirmation.php" | cut -d '"' -f2 | awk '{print "http://www.nvidia.com" $1}' | xargs wget
#cat confirmatio* | grep .run | head -n 1 | cut -d '"' -f2 | xargs wget
# Works!
echo "Downloading proprietary CUDA toolkit..."
date
#wget -q http://developer2.download.nvidia.com/compute/cuda/9.0/secure/Prod/local_installers/cuda_9.0.176_384.81_linux.run
wget -q ftp://10.12.17.15/pub/software/drivers/nvidia/cuda_9.0.176_384.81_linux.run
#wget -q https://developer.nvidia.com/compute/cuda/8.0/prod2/local_installers/cuda_8.0.61_375.26_linux-run
#wget -q https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
#wget -q ftp://10.12.17.15/pub/software/drivers/nvidia/cuda_8.0.61_375.26_linux-run
#wget -q https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda_8.0.61.2_linux-run
#wget -q ftp://10.12.17.15/pub/software/drivers/nvidia/cuda_8.0.61.2_linux-run
date
# Installing NVIDIA
# To learn more about the available switches, see http://www.manpages.spotlynx.com/gnu_linux/man/nvidia-installer.1 or run:
# sh NVIDIA-Linux-x86_64-XXX.XX.run --help
echo "Installing proprietary NVIDIA drivers..."
#sh NVIDIA-Linux-x86_64-384.98.run --accept-license -q -X -Z
sh NVIDIA-Linux-x86_64-384.98.run --accept-license -q -X -Z --ui=none -s
#sh NVIDIA-Linux-x86_64-384.90.run --accept-license -q -X -Z
#sh NVIDIA-Linux-x86_64-384.90.run --accept-license -q -X -Z --ui=none -s
# If RPM based distro 6.x, the NVIDIA installer will fail. Use CTRL+C to close the installer. Let the cuda install finish. Manually run the NVIDIA installer.
# sh NVIDIA-Linux-x86_64-384.69.run --accept-license -q -X
# To update NVIDIA drivers on a system that already has proprietary NVIDIA drivers, use:
# nvidia-installer --update
# Installing CUDA
# To learn more about the available switches, run:
# sh cuda_* --help
echo "Installing proprietary CUDA toolkit..."
sh cuda_9.0.176_384.81_linux.run --toolkit -silent --override
echo "Adding CUDA to the PATH..."
if [[ $(cat /etc/bashrc | grep cuda | wc -l) -eq 0 ]]; then
echo export 'PATH=/usr/local/cuda/bin:$PATH' >> /etc/bashrc
fi
echo "Adding CUDA libs to the ld.so.conf..."
if [[ $(cat /etc/default/grub | grep cuda | wc -l) -eq 0 ]]; then
echo /usr/local/cuda/lib64 >> /etc/ld.so.conf
echo /usr/local/cuda/lib >> /etc/ld.so.conf
fi
echo "Blacklisting nouveau driver..."
if [[ $(cat /etc/modprobe.d/blacklist.conf | grep nouveau | wc -l) -eq 0 ]]; then
echo blacklist nouveau >> /etc/modprobe.d/blacklist.conf
fi
echo "(Red Hat) Executing dracut..."
dracut -f 2>/dev/null
echo "(OpenSUSE) Executing mkinitrd..."
mkinitrd 2>/dev/null
echo "Executing ldconfig..."
ldconfig
# Log details
echo "All temporary installers, scripts, and logs can be found in the /tmp/ folder."
uptime
echo "Log saved to $logfile"
echo \
# Remove hooks
rm -f /etc/init.d/nvidiagpuinstall_once
rm -f /etc/rc3.d/S01nvidiagpuinstall
#rm -f /etc/systemd/system/nvidiainstall.service
crontab -u root -l | grep -v 'nvidiagpuinstall' | crontab -u root -
# Remove files
#rm -f /tmp/NVIDIA-Linux-*
#rm -f /tmp/nvidia*.sh
#rm -f /tmp/cuda_*
# SBGrid 3D Workstation orders
echo "Systems with NVIDIA 3D Vision Glasses must also run:"
echo " nvidia-xconfig --stereo=11"
echo \
if [[ $(ls /etc/sysconfig/grub 2>/dev/null | wc -l) -gt 0 ]]; then
sed -i 's/.*CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="rhgb quiet"/' /etc/sysconfig/grub
sed -i 's/.*CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="rhgb quiet"/' /etc/default/grub
# This is from minimal. Default CentOS and rhel may vary.
## BIOS ##
grub2-mkconfig -o /boot/grub2/grub.cfg
## UEFI ##
#grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
#systemctl set-default graphical.target
/sbin/reboot
exit 1
fi
if [[ $(ls /etc/default/grub 2>/dev/null | wc -l) -gt 0 ]]; then
sed -i 's/.*LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/' /etc/default/grub
update-grub
#systemctl set-default graphical.target
/sbin/reboot
exit 1
fi
EOF
echo "Making the script executable..."
chmod 744 /etc/init.d/nvidiagpuinstall_once
echo -e "$(sudo crontab -u root -l)\n@reboot /etc/init.d/nvidiagpuinstall_once" | crontab -u root -
#chmod 664 /etc/systemd/system/nvidiainstall.service
#systemctl daemon-reload
#systemctl enable nvidiainstall.service
# Hook does not work on CentOS 7. Seems to work on Scientific Linux.
echo "Creating symlink..."
ln -s /etc/init.d/nvidiagpuinstall_once /etc/rc3.d/S01nvidiagpuinstall
# OpenSUSE
zypper install -t pattern devel_C_C++ devel_kernel 2>/dev/null
echo "Blacklisting nouveau driver..."
if [[ $(cat /etc/modprobe.d/blacklist.conf | grep nouveau | wc -l) -eq 0 ]]; then
echo blacklist nouveau >> /etc/modprobe.d/blacklist.conf
fi
if [[ $(ls /etc/sysconfig/grub 2>/dev/null | wc -l) -gt 0 ]]; then
echo "Updating system..."
yum update -y 2>/dev/null
yum groupinstall -y Development\ Tools 2>/dev/null
yum groupinstall -y Compatibility\ Libraries 2>/dev/null
yum groups install -y Development\ Tools 2>/dev/null
yum groups install -y Compatibility\ Libraries 2>/dev/null
dnf -y update 2>/dev/null
echo "Modifying grub for NVIDIA install..."
sed -i 's/.*CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="rhgb rdblacklist nouveau nomodeset 2"/' /etc/sysconfig/grub
sed -i 's/.*CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="rhgb rdblacklist nouveau nomodeset 2"/' /etc/default/grub
## BIOS ##
grub2-mkconfig -o /boot/grub2/grub.cfg
## UEFI ##
#grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
#systemctl set-default multi-user.target
reboot
exit 1
fi
if [[ $(ls /etc/default/grub 2>/dev/null | wc -l) -gt 0 ]]; then
echo "Updating system..."
apt update 2>/dev/null
apt upgrade -y 2>/dev/null
apt-get dist-upgrade -y 2>/dev/null
apt install -y ledmon 2>/dev/null
apt install -y build-essential 2>/dev/null
echo "Modifying grub for NVIDIA install..."
sed -i 's/.*LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="rdblacklist nouveau nomodeset text 2"/' /etc/default/grub
update-grub
#systemctl set-default multi-user.target
reboot
exit 1
fi
fi