]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
1.0.11 release
[Ventoy.git] / INSTALL / grub / grub.cfg
1 #************************************************************************************
2 # Copyright (c) 2020, longpanda <admin@ventoy.net>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, see <http://www.gnu.org/licenses/>.
16 #
17 #************************************************************************************
18
19 function ventoy_power {
20 echo '<1> Reboot'
21 echo '<2> Halt'
22 echo '<0> Return to menu'
23 echo -e '\nPlease enter your choice:'
24
25 unset vtOpt
26 read vtOpt
27
28 if [ "$vtOpt" = "1" ]; then
29 echo -e '\n\nSystem is rebooting ... \n'
30 sleep 1
31 reboot
32 elif [ "$vtOpt" = "2" ]; then
33 echo -e '\n\nSystem is halting ... \n'
34 sleep 1
35 halt
36 fi
37 }
38
39 function get_os_type {
40 set vtoy_os=Linux
41 for file in "efi/microsoft" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" "BOOT/etfsboot.com"; do
42 if [ -e $1/$file ]; then
43 set vtoy_os=Windows
44 break
45 fi
46 done
47
48 if [ -n "${vtdebug_flag}" ]; then
49 echo ISO is $vtoy_os
50 fi
51 }
52
53 function vt_check_pe {
54 unset VT_PE_SUPPORT
55
56 if [ -f $1/HBCD_PE.ini ]; then
57 set ventoy_compatible=YES
58 set VT_PE_SUPPORT=YES
59 elif [ -f $1/easyu.flg ]; then
60 set VT_PE_SUPPORT=YES
61 elif [ -f $1/USM.ICO ]; then
62 set VT_PE_SUPPORT=YES
63 elif [ -d $1/USM_TOOL ]; then
64 set VT_PE_SUPPORT=YES
65 fi
66 }
67
68 function locate_initrd {
69 vt_linux_locate_initrd
70
71 if [ -n "${vtdebug_flag}" ]; then
72 vt_linux_dump_initrd
73 sleep 5
74 fi
75 }
76
77 function find_wim_file {
78 unset ventoy_wim_file
79
80 for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" \
81 "winpe_x64.wim" "boot/10pex64.wim" "BOOT/USM1PE6L.WIM" "BOOT/USM1PE6F.WIM"; do
82 if [ -e $1/$file ]; then
83 set ventoy_wim_file=$1/$file
84 break
85 fi
86 done
87 }
88
89 function distro_specify_initrd_file {
90 if [ -e (loop)/boot/all.rdz ]; then
91 vt_linux_specify_initrd_file /boot/all.rdz
92 elif [ -e (loop)/boot/xen.gz ]; then
93 if [ -e (loop)/install.img ]; then
94 vt_linux_specify_initrd_file /install.img
95 fi
96 elif [ -d (loop)/casper ]; then
97 if [ -e (loop)/casper/initrd ]; then
98 vt_linux_specify_initrd_file /casper/initrd
99 fi
100 if [ -e (loop)/casper/initrd-oem ]; then
101 vt_linux_specify_initrd_file /casper/initrd-oem
102 fi
103 elif [ -e (loop)/boot/grub/initrd.xz ]; then
104 vt_linux_specify_initrd_file /boot/grub/initrd.xz
105 elif [ -e (loop)/initrd.gz ]; then
106 vt_linux_specify_initrd_file /initrd.gz
107 elif [ -e (loop)/slax/boot/initrfs.img ]; then
108 vt_linux_specify_initrd_file /slax/boot/initrfs.img
109 elif [ -e (loop)/pmagic/initrd.img ]; then
110 vt_linux_specify_initrd_file /pmagic/initrd.img
111 elif [ -e (loop)/boot/initrd.xz ]; then
112 vt_linux_specify_initrd_file /boot/initrd.xz
113 elif [ -f (loop)/boot/initrd ]; then
114 vt_linux_specify_initrd_file /boot/initrd
115 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
116 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
117 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
118 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
119
120
121 fi
122 }
123
124
125 function distro_specify_initrd_file_phase2 {
126 if [ -f (loop)/boot/initrd.img ]; then
127 vt_linux_specify_initrd_file /boot/initrd.img
128 elif [ -f (loop)/Setup/initrd.gz ]; then
129 vt_linux_specify_initrd_file /Setup/initrd.gz
130 elif [ -f (loop)/isolinux/initramfs ]; then
131 vt_linux_specify_initrd_file /isolinux/initramfs
132 elif [ -f (loop)/boot/iniramfs.igz ]; then
133 vt_linux_specify_initrd_file /boot/iniramfs.igz
134 elif [ -f (loop)/initrd-x86_64 ]; then
135 vt_linux_specify_initrd_file /initrd-x86_64
136 elif [ -f (loop)/live/initrd.img ]; then
137 vt_linux_specify_initrd_file /live/initrd.img
138
139 fi
140 }
141
142 function uefi_windows_menu_func {
143 vt_windows_reset
144
145 if [ "$ventoy_compatible" = "NO" ]; then
146 find_wim_file (loop)
147 if [ -n "$ventoy_wim_file" ]; then
148 vt_windows_locate_wim $ventoy_wim_file
149 fi
150 fi
151
152 vt_windows_chain_data ${1}${chosen_path}
153
154 if [ -n "${vtdebug_flag}" ]; then
155 sleep 5
156 fi
157
158 if [ -n "$vtoy_chain_mem_addr" ]; then
159 terminal_output console
160 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
161 boot
162 else
163 echo "chain empty failed"
164 sleep 5
165 fi
166 }
167
168 function uefi_linux_menu_func {
169 if [ "$ventoy_compatible" = "NO" ]; then
170 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1
171
172 vt_linux_clear_initrd
173
174 if [ -d (loop)/pmagic ]; then
175 vt_linux_specify_initrd_file /pmagic/initrd.img
176 else
177 for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf" "/grub/grub.cfg"; do
178 if [ -e (loop)/$file ]; then
179 vt_linux_parse_initrd_grub file (loop)/$file
180 fi
181 done
182 fi
183
184 # special process for special distros
185 if [ -d (loop)/loader/entries ]; then
186 set LoadIsoEfiDriver=on
187 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
188 elif [ -d (loop)/boot/grub ]; then
189 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
190 fi
191
192 if [ -e (loop)/syslinux/alt0/full.cz ]; then
193 set LoadIsoEfiDriver=on
194 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
195 fi
196
197 distro_specify_initrd_file
198
199 vt_linux_initrd_count vtcount
200 if [ $vtcount -eq 0 ]; then
201 distro_specify_initrd_file_phase2
202
203 if [ "$vt_efi_dir" = "NO" ]; then
204 if [ -f (loop)/efi.img ]; then
205 vt_add_replace_file 0 "initrd"
206 fi
207 fi
208 fi
209
210 locate_initrd
211 fi
212
213 vt_linux_chain_data ${1}${chosen_path}
214
215 if [ -n "$vtoy_chain_mem_addr" ]; then
216 terminal_output console
217 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
218 boot
219 else
220 echo "chain empty failed"
221 sleep 5
222 fi
223 }
224
225
226 function uefi_iso_menu_func {
227
228 if [ -d (loop)/ ]; then
229 loopback -d loop
230 fi
231
232 if [ -n "$vtisouefi" ]; then
233 set LoadIsoEfiDriver=on
234 unset vtisouefi
235 elif vt_check_mode 2; then
236 set LoadIsoEfiDriver=on
237 else
238 unset LoadIsoEfiDriver
239 fi
240
241 vt_chosen_img_path chosen_path
242
243 if vt_is_udf ${1}${chosen_path}; then
244 set ventoy_fs_probe=udf
245 else
246 set ventoy_fs_probe=iso9660
247 fi
248
249 loopback loop ${1}${chosen_path}
250 get_os_type (loop)
251
252 if [ -d (loop)/EFI ]; then
253 set vt_efi_dir=YES
254 elif [ -d (loop)/efi ]; then
255 set vt_efi_dir=YES
256 else
257 set vt_efi_dir=NO
258 fi
259
260 if [ -n "$vtcompat" ]; then
261 set ventoy_compatible=YES
262 unset vtcompat
263 elif vt_check_mode 1; then
264 set ventoy_compatible=YES
265 else
266 vt_check_compatible (loop)
267 fi
268
269 vt_img_sector ${1}${chosen_path}
270
271 if [ "$vtoy_os" = "Windows" ]; then
272 vt_check_pe (loop)
273 if [ "$VT_PE_SUPPORT" != "YES" ]; then
274 if [ "$ventoy_fs_probe" = "iso9660" ]; then
275 set ventoy_compatible=YES
276 fi
277 fi
278
279 uefi_windows_menu_func $1 ${chosen_path}
280 else
281 uefi_linux_menu_func $1 ${chosen_path}
282 fi
283
284 terminal_output gfxterm
285 }
286
287 function uefi_iso_memdisk {
288 vt_chosen_img_path chosen_path
289
290 echo 'Loading ISO file to memory ...'
291 vt_load_iso_to_mem ${1}${chosen_path} vtoy_iso_buf
292
293 terminal_output console
294 chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
295 boot
296 }
297
298
299 function legacy_windows_menu_func {
300 vt_windows_reset
301
302 if [ "$ventoy_compatible" = "NO" ]; then
303 find_wim_file (loop)
304 if [ -n "$ventoy_wim_file" ]; then
305 vt_windows_locate_wim $ventoy_wim_file
306 elif [ -n "${vtdebug_flag}" ]; then
307 echo No wim file found
308 fi
309 fi
310
311 vt_windows_chain_data ${1}${chosen_path}
312
313 if [ -n "${vtdebug_flag}" ]; then
314 sleep 5
315 fi
316
317 if [ -n "$vtoy_chain_mem_addr" ]; then
318 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
319 boot
320 else
321 echo "chain empty failed"
322 sleep 5
323 fi
324 }
325
326 function legacy_linux_menu_func {
327 if [ "$ventoy_compatible" = "NO" ]; then
328 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
329
330 vt_linux_clear_initrd
331
332 if [ -d (loop)/pmagic ]; then
333 vt_linux_specify_initrd_file /pmagic/initrd.img
334 else
335 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
336 if [ -d (loop)/$dir ]; then
337 vt_linux_parse_initrd_isolinux (loop)/$dir/
338 fi
339 done
340 fi
341
342 # special process for special distros
343 #archlinux
344 if [ -d (loop)/arch/boot/syslinux ]; then
345 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
346 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
347
348 #manjaro
349 elif [ -d (loop)/manjaro ]; then
350 if [ -e (loop)/boot/grub/kernels.cfg ]; then
351 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
352 fi
353 elif [ -e (loop)/boot/grub/grub.cfg ]; then
354 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
355 fi
356
357 distro_specify_initrd_file
358
359 vt_linux_initrd_count vtcount
360 if [ $vtcount -eq 0 ]; then
361 distro_specify_initrd_file_phase2
362 fi
363
364 locate_initrd
365 fi
366
367 vt_linux_chain_data ${1}${chosen_path}
368
369 if [ -n "${vtdebug_flag}" ]; then
370 sleep 5
371 fi
372
373 if [ -n "$vtoy_chain_mem_addr" ]; then
374 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
375 boot
376 else
377 echo "chain empty failed"
378 sleep 5
379 fi
380 }
381
382 function legacy_iso_menu_func {
383
384 if [ -d (loop)/ ]; then
385 loopback -d loop
386 fi
387
388 vt_chosen_img_path chosen_path
389
390 if vt_is_udf ${1}${chosen_path}; then
391 set ventoy_fs_probe=udf
392 else
393 set ventoy_fs_probe=iso9660
394 fi
395
396 loopback loop ${1}${chosen_path}
397
398 get_os_type (loop)
399
400 if [ -n "$vtcompat" ]; then
401 set ventoy_compatible=YES
402 unset vtcompat
403 elif vt_check_mode 1; then
404 set ventoy_compatible=YES
405 else
406 vt_check_compatible (loop)
407 fi
408
409 vt_img_sector ${1}${chosen_path}
410
411 if [ "$vtoy_os" = "Windows" ]; then
412 vt_check_pe (loop)
413 if [ "$VT_PE_SUPPORT" != "YES" ]; then
414 if [ "$ventoy_fs_probe" = "iso9660" ]; then
415 set ventoy_compatible=YES
416 fi
417 fi
418
419 legacy_windows_menu_func $1 ${chosen_path}
420 else
421 legacy_linux_menu_func $1 ${chosen_path}
422 fi
423 }
424
425 function legacy_iso_memdisk {
426 vt_chosen_img_path chosen_path
427
428 linux16 $vtoy_path/memdisk iso raw
429 echo "Loading ISO file to memory ..."
430 initrd16 ${1}${chosen_path}
431 boot
432 }
433
434 function common_menuentry {
435 if [ "$grub_platform" = "pc" ]; then
436 if vt_check_mode 0; then
437 legacy_iso_memdisk $iso_path
438 else
439 legacy_iso_menu_func $iso_path
440 fi
441 else
442 if vt_check_mode 0; then
443 uefi_iso_memdisk $iso_path
444 else
445 uefi_iso_menu_func $iso_path
446 fi
447 fi
448 }
449
450
451 #############################################################
452 #############################################################
453 #############################################################
454 ####### Main Process ###########
455 #############################################################
456 #############################################################
457 #############################################################
458
459 set VENTOY_VERSION="1.0.11"
460
461 # Default menu display mode, you can change it as you want.
462 # 0: List mode
463 # 1: TreeView mode
464 set VTOY_DEFAULT_MENU_MODE=0
465
466 #disable timeout
467 unset timeout
468
469 set VTOY_MEM_DISK_STR="MEMDISK"
470 set VTOY_ISO_RAW_STR="ISO RAW"
471 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
472
473 set VTOY_F2_CMD="ventoy_power"
474
475 if [ "$grub_platform" = "pc" ]; then
476 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
477 else
478 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
479 fi
480
481 vt_device $root vtoy_dev
482
483 if [ "$vtoy_dev" = "tftp" ]; then
484 set vtoy_path=($root)
485 for vtid in 0 1 2 3; do
486 if [ -d (hd$vtid,2)/ventoy ]; then
487 set iso_path=(hd$vtid,1)
488 break
489 fi
490 done
491 else
492 set vtoy_path=($root)/ventoy
493 set iso_path=($vtoy_dev,1)
494 fi
495
496 loadfont ascii
497
498 #Load Plugin
499 if [ -f $iso_path/ventoy/ventoy.json ]; then
500 vt_load_plugin $iso_path
501 fi
502
503
504 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
505 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
506 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView"
507 else
508 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
509 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView"
510 fi
511
512
513 if [ -n "$vtoy_gfxmode" ]; then
514 set gfxmode=$vtoy_gfxmode
515 else
516 set gfxmode=1920x1080,1366x768,1024x768
517 fi
518
519 if [ -n "$vtoy_theme" ]; then
520 set theme=$vtoy_theme
521 else
522 set theme=$prefix/themes/ventoy/theme.txt
523 fi
524
525 terminal_output gfxterm
526
527 #colect all image files (iso files)
528 set ventoy_img_count=0
529 vt_list_img $iso_path ventoy_img_count
530
531 #Main menu
532 if [ $ventoy_img_count -gt 0 ]; then
533 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
534 vt_dynamic_menu 0 0
535 else
536 vt_dynamic_menu 0 1
537 fi
538 else
539 menuentry "No ISO files found (Press enter to reboot ...)" {
540 echo -e "\n Rebooting ... "
541 reboot
542 }
543 fi