-
Notifications
You must be signed in to change notification settings - Fork 141
/
grub.cfg
333 lines (274 loc) · 7.76 KB
/
grub.cfg
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
# GLIM USB GRUB2 Configuration
insmod regexp
# Required for GUI and to prevent "No video mode set" error
insmod all_video
# Keep the same graphic mode for kernel booting (passed as vga=)
# other values are "text" or any gfxmode value
set gfxpayload=keep
# Enable GUI
terminal_output gfxterm
loadfont unicode
insmod png
set theme=${prefix}/themes/invader/theme.txt
set isopath=/boot/iso
probe --set rootuuid --fs-uuid $root
# Required to have these available in other configfile files
export isopath
export rootuuid
export theme
function use {
echo "Using $1 ..."
}
# Save the original value of $root and set it to $1
function change_root {
root_saved="$root"
root="$1"
}
# Restore $root value saved by change_root
function restore_root {
root="$root_saved"
}
# Like 'loopback loop A', but check if (loop) already exists
function loop {
if [ -e (loop) ]; then loopback -d loop; fi
loopback loop "$1"
}
# Order by mtime DESC, literal value ASC
function cmp_mtime_literal {
if [ "$1" -nt "$2" ]; then
true
elif [ "$1" -ot "$2" ]; then
false
else
[ "$1" '<' "$2" ]
fi
}
# Feed a list of isos (by one) to a callback in a sorted manner. The order is
# set by cmp_mtime_literal function. Args: callback iso1 iso2 ..
function for_each_sorted {
# We expect the list of isos to come from a pattern expansion. In case the
# pattern did not expand to anything existing, do nothing.
if [ ! -e "$2" ]; then return; fi
set my_callback="$1"
shift
# Below we loop over the set of iso files, pick the "best" one (in terms of
# cmp_mtime_literal) in the current set and exclude it from the set before
# starting the next iteration. When the "best" iso in the current set is
# found, we feed it to the callback.
# In a generic shell "$@" expands to nothing when there are no args. In
# grubscript it expands to an empty arg. Because of that the loop below can
# only reduce the list down to two elements. With just two elements left it
# would run infinitely if allowed.
while [ $# -gt 2 ]; do
set my_best="$1"
shift
for _ in "$@"; do
set my_next="$1"
shift
if cmp_mtime_literal "$my_next" "$my_best"; then
# next is better
setparams "$@" "$my_best"
set my_best="$my_next"
else
# next is nothing special
setparams "$@" "$my_next"
fi
done
"$my_callback" "$my_best"
done
if [ $# -eq 2 ]; then
if cmp_mtime_literal "$2" "$1"; then
setparams "$2" "$1"
fi
"$my_callback" "$1"
shift
fi
"$my_callback" "$1"
}
# Check if any of its args is an existing path
function any_exists {
if [ $# -gt 0 ]; then
for isofile in "$@"; do
if [ -e "$isofile" ]; then
return 0
fi
done
fi
return 1
}
# Menu!
# We (ab)use 'for' to check for at least one ISO file to show the menu entry
if any_exists ${isopath}/almalinux/AlmaLinux-*-Live-*.iso; then
menuentry "AlmaLinux >" --class almalinux {
configfile "${prefix}/inc-almalinux.cfg"
}
fi
if any_exists ${isopath}/antix/antiX-*-full.iso; then
menuentry "antiX >" --class antix {
configfile "${prefix}/inc-antix.cfg"
}
fi
if any_exists ${isopath}/arch/archlinux-*.iso; then
menuentry "Arch Linux >" --class arch {
configfile "${prefix}/inc-arch.cfg"
}
fi
if any_exists ${isopath}/artix/artix-*.iso; then
menuentry "Artix >" --class artix {
configfile "${prefix}/inc-artix.cfg"
}
fi
if any_exists ${isopath}/bodhi/bodhi-*.iso; then
menuentry "Bodhi Linux >" --class bodhi {
configfile "${prefix}/inc-bodhi.cfg"
}
fi
if any_exists ${isopath}/centos/CentOS-*-Live*.iso; then
menuentry "CentOS >" --class centos {
configfile "${prefix}/inc-centos.cfg"
}
fi
if any_exists ${isopath}/clonezilla/clonezilla-live-*.iso; then
menuentry "Clonezilla >" --class clonezilla {
configfile "${prefix}/inc-clonezilla.cfg"
}
fi
if any_exists ${isopath}/debian/debian-live-*.iso ${isopath}/debian/mini.iso; then
menuentry "Debian >" --class debian {
configfile "${prefix}/inc-debian.cfg"
}
fi
if any_exists ${isopath}/elementary/elementaryos-*.iso; then
menuentry "elementary OS >" --class elementary {
configfile "${prefix}/inc-elementary.cfg"
}
fi
if any_exists ${isopath}/fedora/Fedora-*.iso; then
menuentry "Fedora >" --class fedora {
configfile "${prefix}/inc-fedora.cfg"
}
fi
if any_exists ${isopath}/gentoo/*.iso; then
menuentry "Gentoo >" --class gentoo {
configfile "${prefix}/inc-gentoo.cfg"
}
fi
if any_exists ${isopath}/gparted/gparted-live-*.iso; then
menuentry "GParted >" --class gparted {
configfile "${prefix}/inc-gparted.cfg"
}
fi
if any_exists ${isopath}/grml/grml*.iso; then
menuentry "Grml >" --class grml {
configfile "${prefix}/inc-grml.cfg"
}
fi
if any_exists ${isopath}/ipxe/ipxe*.iso ${isopath}/ipxe/ipxe*.efi; then
menuentry "iPXE >" --class net {
configfile "${prefix}/inc-ipxe.cfg"
}
fi
if any_exists ${isopath}/kali/kali-*.iso; then
menuentry "Kali >" --class kali {
configfile "${prefix}/inc-kali.cfg"
}
fi
if any_exists ${isopath}/kubuntu/kubuntu-*.iso; then
menuentry "Kubuntu >" --class kubuntu {
configfile "${prefix}/inc-kubuntu.cfg"
}
fi
if [ -e "/KERNEL" -a -e "/SYSTEM" ]; then
menuentry "LibreELEC >" --class libreelec {
configfile "${prefix}/inc-libreelec.cfg"
}
fi
if any_exists ${isopath}/linuxmint/linuxmint-*.iso ${isopath}/linuxmint/lmde-*.iso; then
menuentry "Linux Mint >" --class linuxmint {
configfile "${prefix}/inc-linuxmint.cfg"
}
fi
if any_exists ${isopath}/manjaro/manjaro-*.iso; then
menuentry "Manjaro >" --class manjaro {
configfile "${prefix}/inc-manjaro.cfg"
}
fi
if any_exists ${isopath}/memtest/memtest*.bin ${isopath}/memtest/memtest*.efi; then
menuentry "Memtest >" --class memtest {
configfile "${prefix}/inc-memtest.cfg"
}
fi
if any_exists ${isopath}/netrunner/netrunner-*.iso; then
menuentry "Netrunner >" --class netrunner {
configfile "${prefix}/inc-netrunner.cfg"
}
fi
if any_exists ${isopath}/openbsd/*.iso; then
menuentry "OpenBSD >" --class openbsd {
configfile "${prefix}/inc-openbsd.cfg"
}
fi
if any_exists ${isopath}/peppermint/Peppermint-*.iso; then
menuentry "Peppermint >" --class peppermint {
configfile "${prefix}/inc-peppermint.cfg"
}
fi
if any_exists ${isopath}/porteus/Porteus-*.iso; then
menuentry "Porteus >" --class porteus {
configfile "${prefix}/inc-porteus.cfg"
}
fi
if any_exists ${isopath}/rhel/rhel-*.iso; then
menuentry "Red Hat Enterprise Linux >" --class redhat {
configfile "${prefix}/inc-rhel.cfg"
}
fi
if any_exists ${isopath}/rockylinux/Rocky-*.iso; then
menuentry "Rocky Linux >" --class rockylinux {
configfile "${prefix}/inc-rockylinux.cfg"
}
fi
if any_exists ${isopath}/super_grub2_disk_*.iso; then
menuentry "Super Grub2 Disk >" --class disk {
configfile "${prefix}/inc-supergrub2disk.cfg"
}
fi
if any_exists ${isopath}/systemrescue/systemrescue-*.iso; then
menuentry "SystemRescue >" --class systemrescue {
configfile "${prefix}/inc-systemrescue.cfg"
}
fi
if any_exists ${isopath}/tails/tails-*.iso; then
menuentry "Tails >" --class tails {
configfile "${prefix}/inc-tails.cfg"
}
fi
if any_exists ${isopath}/ubuntu/ubuntu-*.iso; then
menuentry "Ubuntu >" --class ubuntu {
configfile "${prefix}/inc-ubuntu.cfg"
}
fi
if any_exists ${isopath}/void/void-live-*.iso; then
menuentry "Void >" --class void {
configfile "${prefix}/inc-void.cfg"
}
fi
if any_exists ${isopath}/xubuntu/xubuntu-*.iso; then
menuentry "Xubuntu >" --class xubuntu {
configfile "${prefix}/inc-xubuntu.cfg"
}
fi
menuentry ' ' { # Empty line
true
}
if [ "${grub_platform}" = "efi" ]; then
menuentry "UEFI Firmware Settings" --class uefi {
fwsetup
}
fi
menuentry "Reboot" --class shutdown {
reboot
}
menuentry "Shutdown" --class shutdown {
halt
}