-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnvidia-boot-update
executable file
·186 lines (141 loc) · 4.94 KB
/
nvidia-boot-update
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
#!/bin/sh
# EL8 (grub2 with BootLoaderSpec patches)
#
# kernel options: grub.cfg + grubenv + /etc/kernel/cmdline
# kernel options in /boot/loader/entries/*.conf use kernelopts from /boot/grub2/grubenv
# grubby
# - updates kernelopts in /boot/grub2/grubenv
# - does not update /etc/default/grub
# - does not update kernelopts in grub.cfg
# grub.cfg:
# - UEFI: /etc/grub2-efi.cfg -> /boot/efi/EFI/<os>/grub.cfg
# - BIOS: /etc/grub2.cfg -> /boot/grub2/grub.cfg
# EL9 (grub2 with BootLoaderSpec patches)
#
# kernel options: grub.cfg + /etc/kernel/cmdline + /boot/loader/entries/*.conf
# manually update: /etc/default/grub + /etc/kernel/cmdline
# grub2-mkconfig does not update /boot/loader/entries/*.conf
# grub.cfg:
# - UEFI: /etc/grub2-efi.cfg -> /boot/efi/EFI/<os>/grub.cfg
# - BIOS: /etc/grub2.cfg -> /boot/grub2/grub.cfg
# Fedora (grub2 with BootLoaderSpec patches)
#
# kernel options: grub.cfg + /etc/kernel/cmdline + /boot/loader/entries/*.conf
# manually update: /etc/default/grub + /etc/kernel/cmdline
# grub2-mkconfig does not update /boot/loader/entries/*.conf
# grub.cfg:
# - UEFI/BIOS: /boot/grub2/grub.cfg
# Fedora (systemd-boot)
#
# kernel options: grub.cfg + /boot/efi/loader/entries/*.conf (UEFI only)
# grubby as an updateloaderentries alias:
# - updates all entries in /boot/efi/loader/entries/*.conf
# - does not work with multiple parameters at once
# - does not update /etc/kernel/cmdline
# Complete use case coverage, regardless of boot loaders:
#
# - update options in /etc/default/grub
# - regenerate grub.cfg/grubenv
# - update options in /boot/{efi/}loader/entries/*.conf entries
# - update options in /etc/kernel/cmdline
# - cover both UEFI and BIOS case
CMDLINE_ARGS_ADD="_dracutopts_in"
CMDLINE_ARGS_REMOVE="_dracutopts_rm"
print_usage() {
cat <<EOF
Tool to add or remove kernel command line options required for proper operation of the Nvidia driver.
Its main use is to be called from the %post/%preun scripts of the Nvidia driver packages, but it can also be used in other contexts, for example in a kickstart file after the drivers have been already installed.
Boot loaders supported:
- grub 2 with BootLoaderSpec patches (el8, el9, fedora)
- systemd-boot (fedora)
Usage: nvidia-update-boot post|preun
post Adjust necessary kernel command line options
preun Remove all kernel command line options
EOF
}
check() {
if [ ! -f /run/ostree-booted ]; then
if [ -f /etc/default/grub ]; then
# Grub 2 is installed
if [ -d /sys/firmware/efi ]; then
GRUB_CFG=/etc/grub2-efi.cfg
else
GRUB_CFG=/etc/grub2.cfg
fi
if [ -d /etc/kernel/cmdline ]; then
# Grub 2 with BootLoaderSpec patches, different path than systemd-boot
BLS_ENTRIES=/boot/loader/entries
fi
. /etc/default/grub
elif [ ! -f /etc/default/grub ] && [ -f /etc/kernel/cmdline ]; then
# systemd-boot is installed
BLS_ENTRIES=/boot/efi/loader/entries
else
echo "Nvidia driver setup: no bootloader configured. Please run 'nvidia-boot-update post' manually."
fi
fi
}
post() {
if [ -v GRUB_CFG ]; then
if [ -z "${GRUB_CMDLINE_LINUX}" ]; then
echo GRUB_CMDLINE_LINUX=\""$CMDLINE_ARGS_ADD"\" >> /etc/default/grub
else
for param in $CMDLINE_ARGS_ADD; do
echo ${GRUB_CMDLINE_LINUX} | grep -q $param
[ $? -eq 1 ] && GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} ${param}"
done
for param in $CMDLINE_ARGS_REMOVE; do
echo ${GRUB_CMDLINE_LINUX} | grep -q $param
[ $? -eq 0 ] && GRUB_CMDLINE_LINUX="$(echo ${GRUB_CMDLINE_LINUX} | sed -e "s/ $param//g")"
done
sed -i -e "s|^GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE_LINUX}\"|g" /etc/default/grub
fi
grub2-mkconfig -o $GRUB_CFG &>/dev/null
fi
if [ -v BLS_ENTRIES ]; then
for config_file in $BLS_ENTRIES/*.conf; do
for param in $CMDLINE_ARGS_ADD; do
grep -q $param $config_file
[ $? -eq 1 ] && sed -i -e "s|^options.*|& $param|" $config_file
done
for param in $CMDLINE_ARGS_REMOVE; do
grep -q $param $config_file
[ $? -eq 0 ] && sed -i -e "s| $param||" $config_file
done
done
fi
}
preun() {
if [ -v GRUB_CFG ]; then
for param in $CMDLINE_ARGS_ADD; do
echo ${GRUB_CMDLINE_LINUX} | grep -q $param
[ $? -eq 0 ] && GRUB_CMDLINE_LINUX="$(echo ${GRUB_CMDLINE_LINUX} | sed -e "s/ $param//g")"
done
sed -i -e "s|^GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE_LINUX}\"|g" /etc/default/grub
grub2-mkconfig -o $GRUB_CFG &>/dev/null
fi
if [ -v BLS_ENTRIES ]; then
for config_file in $BLS_ENTRIES/*.conf; do
for param in $CMDLINE_ARGS_ADD; do
grep -q $param $config_file
[ $? -eq 0 ] && sed -i -e "s| $param||" $config_file
done
done
fi
}
case "$1" in
post)
check
post
exit 0
;;
preun)
check
preun
exit 0
;;
*)
print_usage
exit 0
;;
esac