]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
1.0.13 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_pause {
20 if [ -n "${vtdebug_flag}" ]; then
21 echo "press Enter to continue ......"
22 read vtTmpPause
23 fi
24 }
25
26 function ventoy_debug_pause {
27 if [ -n "${vtdebug_flag}" ]; then
28 echo "press Enter to continue ......"
29 read vtTmpPause
30 fi
31 }
32
33
34 function ventoy_power {
35 configfile $prefix/power.cfg
36 }
37
38 function ventoy_diagnosis {
39 configfile $prefix/debug.cfg
40 }
41
42 function ventoy_localboot {
43 configfile $prefix/localboot.cfg
44 }
45
46 function get_os_type {
47 set vtoy_os=Linux
48
49 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
50 if vt_file_exist_nocase (loop)/$file; then
51 set vtoy_os=Windows
52 break
53 fi
54 done
55
56 if [ -n "${vtdebug_flag}" ]; then
57 echo ISO is $vtoy_os
58 fi
59 }
60
61 function vt_check_compatible_pe {
62 #Check for PE without external tools
63 if [ -f $1/HBCD_PE.ini ]; then
64 set ventoy_compatible=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 ventoy_debug_pause
74 fi
75 }
76
77 function locate_wim {
78 vt_windows_locate_wim_patch (loop)
79
80 if [ -n "${vtdebug_flag}" ]; then
81 echo '###############################################'
82 vt_dump_wim_patch
83 echo '###############################################'
84 ventoy_debug_pause
85 fi
86 }
87
88 function distro_specify_wim_patch {
89 if [ -d (loop)/h3pe ]; then
90 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
91 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
92 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
93 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
94 fi
95 }
96
97 function distro_specify_wim_patch_phase2 {
98 if [ -f (loop)/boot/boot.wim ]; then
99 vt_windows_collect_wim_patch wim /boot/boot.wim
100 fi
101 }
102
103
104 function distro_specify_initrd_file {
105 if [ -e (loop)/boot/all.rdz ]; then
106 vt_linux_specify_initrd_file /boot/all.rdz
107 elif [ -e (loop)/boot/xen.gz ]; then
108 if [ -e (loop)/install.img ]; then
109 vt_linux_specify_initrd_file /install.img
110 fi
111 elif [ -d (loop)/casper ]; then
112 if [ -e (loop)/casper/initrd ]; then
113 vt_linux_specify_initrd_file /casper/initrd
114 fi
115 if [ -e (loop)/casper/initrd-oem ]; then
116 vt_linux_specify_initrd_file /casper/initrd-oem
117 fi
118 elif [ -e (loop)/boot/grub/initrd.xz ]; then
119 vt_linux_specify_initrd_file /boot/grub/initrd.xz
120 elif [ -e (loop)/initrd.gz ]; then
121 vt_linux_specify_initrd_file /initrd.gz
122 elif [ -e (loop)/slax/boot/initrfs.img ]; then
123 vt_linux_specify_initrd_file /slax/boot/initrfs.img
124 elif [ -e (loop)/pmagic/initrd.img ]; then
125 vt_linux_specify_initrd_file /pmagic/initrd.img
126 elif [ -e (loop)/boot/initrd.xz ]; then
127 vt_linux_specify_initrd_file /boot/initrd.xz
128 elif [ -f (loop)/boot/initrd ]; then
129 vt_linux_specify_initrd_file /boot/initrd
130 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
131 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
132 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
133 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
134
135
136 fi
137 }
138
139
140 function distro_specify_initrd_file_phase2 {
141 if [ -f (loop)/boot/initrd.img ]; then
142 vt_linux_specify_initrd_file /boot/initrd.img
143 elif [ -f (loop)/Setup/initrd.gz ]; then
144 vt_linux_specify_initrd_file /Setup/initrd.gz
145 elif [ -f (loop)/isolinux/initramfs ]; then
146 vt_linux_specify_initrd_file /isolinux/initramfs
147 elif [ -f (loop)/boot/iniramfs.igz ]; then
148 vt_linux_specify_initrd_file /boot/iniramfs.igz
149 elif [ -f (loop)/initrd-x86_64 ]; then
150 vt_linux_specify_initrd_file /initrd-x86_64
151 elif [ -f (loop)/live/initrd.img ]; then
152 vt_linux_specify_initrd_file /live/initrd.img
153 elif [ -f (loop)/initrd.img ]; then
154 vt_linux_specify_initrd_file /initrd.img
155
156 fi
157 }
158
159 function uefi_windows_menu_func {
160 vt_windows_reset
161
162 if [ "$ventoy_compatible" = "NO" ]; then
163
164 if [ "$ventoy_fs_probe" = "iso9660" ]; then
165 loopback -d loop
166 vt_iso9660_nojoliet 1
167 loopback loop $1$2
168 fi
169
170 for file in "efi/microsoft/boot/bcd"; do
171 vt_windows_collect_wim_patch bcd (loop)/$file
172 done
173
174 vt_windows_count_wim_patch vt_wim_cnt
175 if [ $vt_wim_cnt -eq 0 ]; then
176 distro_specify_wim_patch_phase2
177 fi
178
179 ventoy_debug_pause
180 locate_wim
181 fi
182
183 vt_windows_chain_data ${1}${chosen_path}
184 ventoy_debug_pause
185
186 if [ -n "$vtoy_chain_mem_addr" ]; then
187 terminal_output console
188 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
189 boot
190 else
191 echo "chain empty failed"
192 ventoy_pause
193 fi
194 }
195
196 function uefi_linux_menu_func {
197 if [ "$ventoy_compatible" = "NO" ]; then
198
199 if [ "$ventoy_fs_probe" = "udf" ]; then
200 loopback -d loop
201 set ventoy_fs_probe=iso9660
202 loopback loop $1$2
203 fi
204
205 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1
206
207 vt_linux_clear_initrd
208
209 if [ -d (loop)/pmagic ]; then
210 vt_linux_specify_initrd_file /pmagic/initrd.img
211 else
212 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
213 if [ -e (loop)/$file ]; then
214 vt_linux_parse_initrd_grub file (loop)/$file
215 fi
216 done
217 fi
218
219 # special process for special distros
220 if [ -d (loop)/loader/entries ]; then
221 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
222 elif [ -d (loop)/boot/grub ]; then
223 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
224 fi
225
226 distro_specify_initrd_file
227
228 vt_linux_initrd_count vtcount
229 if [ $vtcount -eq 0 ]; then
230 distro_specify_initrd_file_phase2
231
232 if [ "$vt_efi_dir" = "NO" ]; then
233 if [ -f (loop)/efi.img ]; then
234 vt_add_replace_file 0 "initrd"
235 fi
236 fi
237 fi
238
239 locate_initrd
240
241 if [ -d (loop)/loader/entries ]; then
242 vt_linux_get_main_initrd_index vtindex
243
244 if [ -d (loop)/arch ]; then
245 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
246 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
247 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
248 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
249 fi
250 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
251 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
252 fi
253 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
254 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
255 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
256 fi
257
258 fi
259
260 vt_linux_chain_data ${1}${chosen_path}
261
262 if [ -n "$vtoy_chain_mem_addr" ]; then
263 terminal_output console
264 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}
265 boot
266 else
267 echo "chain empty failed"
268 ventoy_pause
269 fi
270 }
271
272
273 function uefi_iso_menu_func {
274
275 if [ -d (loop)/ ]; then
276 loopback -d loop
277 fi
278
279 if [ -n "$vtisouefi" ]; then
280 set LoadIsoEfiDriver=on
281 unset vtisouefi
282 elif vt_check_mode 2; then
283 set LoadIsoEfiDriver=on
284 else
285 unset LoadIsoEfiDriver
286 fi
287
288 vt_chosen_img_path chosen_path
289 vt_select_auto_install ${chosen_path}
290 vt_select_persistence ${chosen_path}
291
292 if vt_is_udf ${1}${chosen_path}; then
293 set ventoy_fs_probe=udf
294 else
295 set ventoy_fs_probe=iso9660
296 vt_iso9660_nojoliet 0
297 fi
298
299 loopback loop ${1}${chosen_path}
300 get_os_type (loop)
301
302 if [ -d (loop)/EFI ]; then
303 set vt_efi_dir=YES
304 elif [ -d (loop)/efi ]; then
305 set vt_efi_dir=YES
306 else
307 set vt_efi_dir=NO
308 fi
309
310 if [ -n "$vtcompat" ]; then
311 set ventoy_compatible=YES
312 unset vtcompat
313 elif vt_check_mode 1; then
314 set ventoy_compatible=YES
315 else
316 vt_check_compatible (loop)
317 fi
318
319 vt_img_sector ${1}${chosen_path}
320
321 if [ "$vtoy_os" = "Windows" ]; then
322 vt_check_compatible_pe (loop)
323 uefi_windows_menu_func $1 ${chosen_path}
324 else
325 uefi_linux_menu_func $1 ${chosen_path}
326 fi
327
328 terminal_output gfxterm
329 }
330
331 function uefi_iso_memdisk {
332 vt_chosen_img_path chosen_path
333
334 echo 'Loading ISO file to memory ...'
335 vt_load_iso_to_mem ${1}${chosen_path} vtoy_iso_buf
336
337 terminal_output console
338 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}
339 boot
340 }
341
342
343 function legacy_windows_menu_func {
344 vt_windows_reset
345
346 if [ "$ventoy_compatible" = "NO" ]; then
347
348 if [ "$ventoy_fs_probe" = "iso9660" ]; then
349 loopback -d loop
350 vt_iso9660_nojoliet 1
351 loopback loop $1$2
352 fi
353
354 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
355 vt_windows_collect_wim_patch bcd (loop)/$file
356 done
357
358 distro_specify_wim_patch
359
360 vt_windows_count_wim_patch vt_wim_cnt
361 if [ $vt_wim_cnt -eq 0 ]; then
362 distro_specify_wim_patch_phase2
363 fi
364
365 ventoy_debug_pause
366 locate_wim
367 fi
368
369 vt_windows_chain_data ${1}${chosen_path}
370 ventoy_debug_pause
371
372 if [ -n "$vtoy_chain_mem_addr" ]; then
373 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
374 boot
375 else
376 echo "chain empty failed"
377 ventoy_pause
378 fi
379 }
380
381 function legacy_linux_menu_func {
382 if [ "$ventoy_compatible" = "NO" ]; then
383
384 if [ "$ventoy_fs_probe" = "udf" ]; then
385 loopback -d loop
386 set ventoy_fs_probe=iso9660
387 loopback loop $1$2
388 fi
389
390 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
391
392 vt_linux_clear_initrd
393
394 if [ -d (loop)/pmagic ]; then
395 vt_linux_specify_initrd_file /pmagic/initrd.img
396 else
397 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
398 if [ -d (loop)/$dir ]; then
399 vt_linux_parse_initrd_isolinux (loop)/$dir/
400 fi
401 done
402 fi
403
404 # special process for special distros
405 #archlinux
406 if [ -d (loop)/arch/boot/syslinux ]; then
407 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
408 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
409
410 #manjaro
411 elif [ -d (loop)/manjaro ]; then
412 if [ -e (loop)/boot/grub/kernels.cfg ]; then
413 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
414 fi
415 elif [ -e (loop)/boot/grub/grub.cfg ]; then
416 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
417 fi
418
419 distro_specify_initrd_file
420
421 vt_linux_initrd_count vtcount
422 if [ $vtcount -eq 0 ]; then
423 distro_specify_initrd_file_phase2
424 fi
425
426 locate_initrd
427 fi
428
429 vt_linux_chain_data ${1}${chosen_path}
430 ventoy_debug_pause
431
432 if [ -n "$vtoy_chain_mem_addr" ]; then
433 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
434 boot
435 else
436 echo "chain empty failed"
437 ventoy_pause
438 fi
439 }
440
441 function legacy_iso_menu_func {
442
443 if [ -d (loop)/ ]; then
444 loopback -d loop
445 fi
446
447 vt_chosen_img_path chosen_path
448 vt_select_auto_install ${chosen_path}
449 vt_select_persistence ${chosen_path}
450
451 if vt_is_udf ${1}${chosen_path}; then
452 set ventoy_fs_probe=udf
453 else
454 set ventoy_fs_probe=iso9660
455 vt_iso9660_nojoliet 0
456 fi
457
458 loopback loop ${1}${chosen_path}
459 get_os_type (loop)
460
461 if [ -n "$vtcompat" ]; then
462 set ventoy_compatible=YES
463 unset vtcompat
464 elif vt_check_mode 1; then
465 set ventoy_compatible=YES
466 else
467 vt_check_compatible (loop)
468 fi
469
470 vt_img_sector ${1}${chosen_path}
471
472 if [ "$vtoy_os" = "Windows" ]; then
473 vt_check_compatible_pe (loop)
474 legacy_windows_menu_func $1 ${chosen_path}
475 else
476 legacy_linux_menu_func $1 ${chosen_path}
477 fi
478 }
479
480 function legacy_iso_memdisk {
481 vt_chosen_img_path chosen_path
482
483 linux16 $vtoy_path/memdisk iso raw
484 echo "Loading ISO file to memory ..."
485 initrd16 ${1}${chosen_path}
486 boot
487 }
488
489 function iso_common_menuentry {
490 if [ "$grub_platform" = "pc" ]; then
491 if vt_check_mode 0; then
492 legacy_iso_memdisk $iso_path
493 else
494 legacy_iso_menu_func $iso_path
495 fi
496 else
497 if vt_check_mode 0; then
498 uefi_iso_memdisk $iso_path
499 else
500 uefi_iso_menu_func $iso_path
501 fi
502 fi
503 }
504
505 function iso_unsupport_menuentry {
506 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
507 echo -e "\n Will return to main menu after 10 seconds ...\n"
508 sleep 10
509 }
510
511
512 function wim_common_menuentry {
513 vt_chosen_img_path chosen_path
514 vt_wim_chain_data ${iso_path}${chosen_path}
515
516 ventoy_debug_pause
517
518 if [ -n "$vtoy_chain_mem_addr" ]; then
519 if [ "$grub_platform" = "pc" ]; then
520 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
521 else
522 terminal_output console
523 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
524 fi
525 boot
526 else
527 echo "chain empty failed"
528 ventoy_pause
529 fi
530 }
531
532 function wim_unsupport_menuentry {
533 echo -e "\n The name of the wim file could NOT contain space or non-ascii characters. \n"
534 echo -e "\n Will return to main menu after 10 seconds ...\n"
535 sleep 10
536 }
537
538 #############################################################
539 #############################################################
540 #############################################################
541 ####### Main Process ###########
542 #############################################################
543 #############################################################
544 #############################################################
545
546 set VENTOY_VERSION="1.0.13"
547
548 # Default menu display mode, you can change it as you want.
549 # 0: List mode
550 # 1: TreeView mode
551 set VTOY_DEFAULT_MENU_MODE=0
552
553 #disable timeout
554 unset timeout
555
556 set VTOY_MEM_DISK_STR="[Memdisk]"
557 set VTOY_ISO_RAW_STR="Compatible Mode"
558 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
559
560 set VTOY_F2_CMD="ventoy_power"
561 set VTOY_F4_CMD="ventoy_localboot"
562 set VTOY_F5_CMD="ventoy_diagnosis"
563
564 if [ "$grub_platform" = "pc" ]; then
565 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
566 else
567 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
568 fi
569
570 vt_device $root vtoy_dev
571
572 if [ "$vtoy_dev" = "tftp" ]; then
573 set vtoy_path=($root)
574 for vtid in 0 1 2 3; do
575 if [ -d (hd$vtid,2)/ventoy ]; then
576 set iso_path=(hd$vtid,1)
577 set vtoy_efi_part=(hd$vtid,2)
578 break
579 fi
580 done
581 loadfont ascii
582 else
583 if [ "$prefix" = "(ventoydisk)/grub" ]; then
584 set vtoy_path=(ventoydisk)/ventoy
585 else
586 set vtoy_path=($root)/ventoy
587 fi
588
589 set iso_path=($vtoy_dev,1)
590 set vtoy_efi_part=($vtoy_dev,2)
591 loadfont unicode
592 fi
593
594
595 #Load Plugin
596 if [ -f $iso_path/ventoy/ventoy.json ]; then
597 vt_load_plugin $iso_path
598 fi
599
600 if [ -f $iso_path/ventoy/ventoy_wimboot.img ]; then
601 vt_load_wimboot $iso_path/ventoy/ventoy_wimboot.img
602 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
603 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
604 fi
605
606
607 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
608 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
609 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug"
610 else
611 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
612 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug"
613 fi
614
615
616 if [ -n "$vtoy_gfxmode" ]; then
617 set gfxmode=$vtoy_gfxmode
618 else
619 set gfxmode=1920x1080,1366x768,1024x768
620 fi
621
622 if [ -n "$vtoy_theme" ]; then
623 set theme=$vtoy_theme
624 else
625 set theme=$prefix/themes/ventoy/theme.txt
626 fi
627
628 if [ "$vtoy_display_mode" = "CLI" ]; then
629 terminal_output console
630 else
631 terminal_output gfxterm
632 fi
633
634 #vtdebug on
635
636 #colect all image files (iso files)
637 set ventoy_img_count=0
638 vt_list_img $iso_path ventoy_img_count
639
640 #Main menu
641 if [ $ventoy_img_count -gt 0 ]; then
642 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
643 vt_dynamic_menu 0 0
644 else
645 vt_dynamic_menu 0 1
646 fi
647 else
648 if [ -n "$VTOY_NO_ISO_TIP" ]; then
649 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
650 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
651 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
652 else
653 NO_ISO_MENU="No ISO files found"
654 fi
655 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
656 echo -e "\n Rebooting ... "
657 reboot
658 }
659 fi