]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
add support to freebsd
[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 function ventoy_cli_console {
34 if [ "$grub_platform" = "pc" ]; then
35 #terminal_output vga_text
36 terminal_output console
37 else
38 if [ "$vtoy_display_mode" != "CLI" ]; then
39 terminal_output console
40 fi
41 fi
42 }
43
44 function ventoy_gui_console {
45 if [ "$grub_platform" = "pc" ]; then
46 if [ "$vtoy_display_mode" = "CLI" ]; then
47 terminal_output console
48 else
49 terminal_output gfxterm
50 fi
51 else
52 if [ "$vtoy_display_mode" != "CLI" ]; then
53 terminal_output gfxterm
54 fi
55 fi
56 }
57
58 function ventoy_power {
59 configfile $prefix/power.cfg
60 }
61
62 function ventoy_diagnosis {
63 configfile $prefix/debug.cfg
64 }
65
66 function ventoy_localboot {
67 configfile $prefix/localboot.cfg
68 }
69
70 function ventoy_ext_menu {
71 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
72 set ventoy_new_context=1
73 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
74 unset ventoy_new_context
75 else
76 echo "ventoy_grub.cfg NOT exist."
77 echo -e "\npress ENTER to exit ..."
78 read vtInputKey
79 fi
80 }
81
82 function get_os_type {
83 set vtoy_os=Linux
84
85 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
86 if vt_file_exist_nocase (loop)/$file; then
87 set vtoy_os=Windows
88 break
89 fi
90 done
91
92 if [ "$vtoy_os" = "Linux" ]; then
93 if vt_strstr "$vt_system_id" "FreeBSD"; then
94 set vtoy_os=Unix
95 elif [ -e (loop)/bin/freebsd-version ]; then
96 set vtoy_os=Unix
97 fi
98 fi
99
100 if [ -n "${vtdebug_flag}" ]; then
101 echo ISO is $vtoy_os
102 fi
103 }
104
105 function vt_check_compatible_pe {
106 #Check for PE without external tools
107 if [ -f $1/HBCD_PE.ini ]; then
108 set ventoy_compatible=YES
109 fi
110 }
111
112 function locate_initrd {
113 vt_linux_locate_initrd
114
115 if [ -n "${vtdebug_flag}" ]; then
116 vt_linux_dump_initrd
117 ventoy_debug_pause
118 fi
119 }
120
121 function locate_wim {
122 vt_windows_locate_wim_patch (loop)
123
124 if [ -n "${vtdebug_flag}" ]; then
125 echo '###############################################'
126 vt_dump_wim_patch
127 echo '###############################################'
128 ventoy_debug_pause
129 fi
130 }
131
132 function distro_specify_wim_patch {
133 if [ -d (loop)/h3pe ]; then
134 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
135 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
136 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
137 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
138 fi
139 }
140
141 function distro_specify_wim_patch_phase2 {
142 if [ -f (loop)/boot/boot.wim ]; then
143 vt_windows_collect_wim_patch wim /boot/boot.wim
144 fi
145 }
146
147
148 function distro_specify_initrd_file {
149 if [ -e (loop)/boot/all.rdz ]; then
150 vt_linux_specify_initrd_file /boot/all.rdz
151 elif [ -e (loop)/boot/xen.gz ]; then
152 if [ -e (loop)/install.img ]; then
153 vt_linux_specify_initrd_file /install.img
154 fi
155 elif [ -d (loop)/casper ]; then
156 if [ -e (loop)/casper/initrd ]; then
157 vt_linux_specify_initrd_file /casper/initrd
158 fi
159 if [ -e (loop)/casper/initrd-oem ]; then
160 vt_linux_specify_initrd_file /casper/initrd-oem
161 fi
162 elif [ -e (loop)/boot/grub/initrd.xz ]; then
163 vt_linux_specify_initrd_file /boot/grub/initrd.xz
164 elif [ -e (loop)/initrd.gz ]; then
165 vt_linux_specify_initrd_file /initrd.gz
166 elif [ -e (loop)/slax/boot/initrfs.img ]; then
167 vt_linux_specify_initrd_file /slax/boot/initrfs.img
168 elif [ -e (loop)/pmagic/initrd.img ]; then
169 vt_linux_specify_initrd_file /pmagic/initrd.img
170 elif [ -e (loop)/boot/initrd.xz ]; then
171 vt_linux_specify_initrd_file /boot/initrd.xz
172 elif [ -f (loop)/boot/initrd ]; then
173 vt_linux_specify_initrd_file /boot/initrd
174 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
175 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
176 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
177 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
178
179
180 fi
181 }
182
183
184 function distro_specify_initrd_file_phase2 {
185 if [ -f (loop)/boot/initrd.img ]; then
186 vt_linux_specify_initrd_file /boot/initrd.img
187 elif [ -f (loop)/Setup/initrd.gz ]; then
188 vt_linux_specify_initrd_file /Setup/initrd.gz
189 elif [ -f (loop)/isolinux/initramfs ]; then
190 vt_linux_specify_initrd_file /isolinux/initramfs
191 elif [ -f (loop)/boot/iniramfs.igz ]; then
192 vt_linux_specify_initrd_file /boot/iniramfs.igz
193 elif [ -f (loop)/initrd-x86_64 ]; then
194 vt_linux_specify_initrd_file /initrd-x86_64
195 elif [ -f (loop)/live/initrd.img ]; then
196 vt_linux_specify_initrd_file /live/initrd.img
197 elif [ -f (loop)/initrd.img ]; then
198 vt_linux_specify_initrd_file /initrd.img
199 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
200 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
201 elif [ -f (loop)/CDlinux/initrd ]; then
202 vt_linux_specify_initrd_file /CDlinux/initrd
203 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
204 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
205 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
206 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
207 fi
208 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
209 #Qubes
210 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
211 if [ "$grub_platform" != "pc" ]; then
212 vt_add_replace_file 0 "initrd.img"
213 fi
214 elif [ -f (loop)/initrd ]; then
215 vt_linux_specify_initrd_file /initrd
216 elif [ -f (loop)/live/initrd1 ]; then
217 vt_linux_specify_initrd_file /live/initrd1
218
219 fi
220 }
221
222 function ventoy_freebsd_proc {
223 if regexp "^12_[0-9]" $vt_volume_id; then
224 set vt_freebsd_ver=12.x
225 elif regexp "^11_[0-9]" $vt_volume_id; then
226 set vt_freebsd_ver=11.x
227 elif regexp "^10_[0-9]" $vt_volume_id; then
228 set vt_freebsd_ver=10.x
229 elif [ -e (loop)/bin/freebsd-version ]; then
230 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
231 if regexp "\"12\.[0-9]-" $vt_userland_ver; then
232 set vt_freebsd_ver=12.x
233 elif regexp "\"11\.[0-9]-" $vt_userland_ver; then
234 set vt_freebsd_ver=11.x
235 elif regexp "\"10\.[0-9]-" $vt_userland_ver; then
236 set vt_freebsd_ver=10.x
237 fi
238 else
239 set vt_freebsd_ver=12.x
240 fi
241
242 if file --is-i386-kfreebsd (loop)/boot/kernel/kernel; then
243 set vt_freebsd_bit=32
244 else
245 set vt_freebsd_bit=64
246 fi
247
248 if [ -n "${vtdebug_flag}" ]; then
249 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
250 fi
251
252 for file in "geom_nop" "ipmi"; do
253 if [ -e (loop)/boot/kernel/${file}.ko ]; then
254 set vt_unix_ko=$file
255 break
256 fi
257 done
258
259 vt_unix_replace_ko $vt_unix_ko (vtunix)/ventoy_unix/FreeBSD/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
260 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
261 }
262
263 function ventoy_unix_comm_proc {
264 vt_unix_reset
265
266 if [ "$ventoy_compatible" = "NO" ]; then
267 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
268
269 set vt_unix_type=unknown
270 if vt_strstr "$vt_system_id" "FreeBSD"; then
271 ventoy_freebsd_proc $1 ${chosen_path}
272 elif [ -e (loop)/bin/freebsd-version ]; then
273 ventoy_freebsd_proc $1 ${chosen_path}
274 else
275 if [ -n "${vtdebug_flag}" ]; then
276 echo "Unknown unix type"
277 fi
278 fi
279 fi
280
281 vt_unix_chain_data ${1}${chosen_path}
282 ventoy_debug_pause
283 }
284
285
286 function uefi_windows_menu_func {
287 vt_windows_reset
288
289 if [ "$ventoy_compatible" = "NO" ]; then
290
291 if [ "$ventoy_fs_probe" = "iso9660" ]; then
292 loopback -d loop
293 vt_iso9660_nojoliet 1
294 loopback loop $1$2
295 fi
296
297 for file in "efi/microsoft/boot/bcd"; do
298 vt_windows_collect_wim_patch bcd (loop)/$file
299 done
300
301 vt_windows_count_wim_patch vt_wim_cnt
302 if [ $vt_wim_cnt -eq 0 ]; then
303 distro_specify_wim_patch_phase2
304 fi
305
306 ventoy_debug_pause
307 locate_wim
308 fi
309
310 vt_windows_chain_data ${1}${chosen_path}
311 ventoy_debug_pause
312
313 if [ -n "$vtoy_chain_mem_addr" ]; then
314 ventoy_cli_console
315 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
316 boot
317 else
318 echo "chain empty failed"
319 ventoy_pause
320 fi
321 }
322
323 function uefi_linux_menu_func {
324 if [ "$ventoy_compatible" = "NO" ]; then
325
326 if [ "$ventoy_fs_probe" = "udf" ]; then
327 loopback -d loop
328 set ventoy_fs_probe=iso9660
329 loopback loop $1$2
330 fi
331
332 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1
333
334 vt_linux_clear_initrd
335
336 if [ -d (loop)/pmagic ]; then
337 vt_linux_specify_initrd_file /pmagic/initrd.img
338 else
339 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
340 if [ -e (loop)/$file ]; then
341 vt_linux_parse_initrd_grub file (loop)/$file
342 fi
343 done
344 fi
345
346 # special process for special distros
347 if [ -d (loop)/loader/entries ]; then
348 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
349 elif [ -d (loop)/boot/grub ]; then
350 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
351 fi
352
353 distro_specify_initrd_file
354
355 vt_linux_initrd_count vtcount
356 if [ $vtcount -eq 0 ]; then
357 distro_specify_initrd_file_phase2
358
359 if [ "$vt_efi_dir" = "NO" ]; then
360 if [ -f (loop)/efi.img ]; then
361 vt_add_replace_file 0 "initrd"
362 fi
363 fi
364 fi
365
366 locate_initrd
367
368 if [ -d (loop)/loader/entries ]; then
369 vt_linux_get_main_initrd_index vtindex
370
371 if [ -d (loop)/arch ]; then
372 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
373 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
374 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
375 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
376 fi
377 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
378 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
379 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
380 vt_add_replace_file $vtindex "boot\\initrd"
381 fi
382 elif [ -d (loop)/EFI/boot/entries ]; then
383 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
384 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
385 fi
386 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
387 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
388 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
389 fi
390
391 fi
392
393 vt_linux_chain_data ${1}${chosen_path}
394
395 if [ -n "$vtoy_chain_mem_addr" ]; then
396 ventoy_cli_console
397 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}
398 boot
399 else
400 echo "chain empty failed"
401 ventoy_pause
402 fi
403 }
404
405 function uefi_unix_menu_func {
406 ventoy_unix_comm_proc $1 ${chosen_path}
407
408 if [ -n "$vtoy_chain_mem_addr" ]; then
409 ventoy_cli_console
410 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}
411 boot
412 else
413 echo "chain empty failed"
414 ventoy_pause
415 fi
416 }
417
418 function uefi_iso_menu_func {
419
420 if [ -d (loop)/ ]; then
421 loopback -d loop
422 fi
423
424 if [ -n "$vtisouefi" ]; then
425 set LoadIsoEfiDriver=on
426 unset vtisouefi
427 elif vt_check_mode 2; then
428 set LoadIsoEfiDriver=on
429 else
430 unset LoadIsoEfiDriver
431 fi
432
433 vt_chosen_img_path chosen_path
434 vt_select_auto_install ${chosen_path}
435 vt_select_persistence ${chosen_path}
436
437 if vt_is_udf ${1}${chosen_path}; then
438 set ventoy_fs_probe=udf
439 else
440 set ventoy_fs_probe=iso9660
441 vt_iso9660_nojoliet 0
442 fi
443
444 loopback loop ${1}${chosen_path}
445 vt_parse_iso_volume ${1}${chosen_path} vt_system_id vt_volume_id
446 get_os_type (loop)
447
448 if [ -d (loop)/EFI ]; then
449 set vt_efi_dir=YES
450 elif [ -d (loop)/efi ]; then
451 set vt_efi_dir=YES
452 else
453 set vt_efi_dir=NO
454 fi
455
456 if [ -n "$vtcompat" ]; then
457 set ventoy_compatible=YES
458 unset vtcompat
459 elif vt_check_mode 1; then
460 set ventoy_compatible=YES
461 else
462 vt_check_compatible (loop)
463 fi
464
465 vt_img_sector ${1}${chosen_path}
466
467 if [ "$vtoy_os" = "Windows" ]; then
468 vt_check_compatible_pe (loop)
469 uefi_windows_menu_func $1 ${chosen_path}
470 elif [ "$vtoy_os" = "Unix" ]; then
471 uefi_unix_menu_func $1 ${chosen_path}
472 else
473 uefi_linux_menu_func $1 ${chosen_path}
474 fi
475
476 ventoy_gui_console
477 }
478
479 function uefi_iso_memdisk {
480 vt_chosen_img_path chosen_path
481
482 echo 'Loading ISO file to memory ...'
483 vt_load_iso_to_mem ${1}${chosen_path} vtoy_iso_buf
484
485 ventoy_cli_console
486 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}
487 boot
488
489 ventoy_gui_console
490 }
491
492
493 function legacy_windows_menu_func {
494 vt_windows_reset
495
496 if [ "$ventoy_compatible" = "NO" ]; then
497
498 if [ "$ventoy_fs_probe" = "iso9660" ]; then
499 loopback -d loop
500 vt_iso9660_nojoliet 1
501 loopback loop $1$2
502 fi
503
504 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
505 vt_windows_collect_wim_patch bcd (loop)/$file
506 done
507
508 distro_specify_wim_patch
509
510 vt_windows_count_wim_patch vt_wim_cnt
511 if [ $vt_wim_cnt -eq 0 ]; then
512 distro_specify_wim_patch_phase2
513 fi
514
515 ventoy_debug_pause
516 locate_wim
517 fi
518
519 vt_windows_chain_data ${1}${chosen_path}
520 ventoy_debug_pause
521
522 if [ -n "$vtoy_chain_mem_addr" ]; then
523 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
524 boot
525 else
526 echo "chain empty failed"
527 ventoy_pause
528 fi
529 }
530
531 function legacy_linux_menu_func {
532 if [ "$ventoy_compatible" = "NO" ]; then
533
534 if [ "$ventoy_fs_probe" = "udf" ]; then
535 loopback -d loop
536 set ventoy_fs_probe=iso9660
537 loopback loop $1$2
538 fi
539
540 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
541
542 vt_linux_clear_initrd
543
544 if [ -d (loop)/pmagic ]; then
545 vt_linux_specify_initrd_file /pmagic/initrd.img
546 else
547 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
548 if [ -d (loop)/$dir ]; then
549 vt_linux_parse_initrd_isolinux (loop)/$dir/
550 fi
551 done
552 fi
553
554 # special process for special distros
555 #archlinux
556 if [ -d (loop)/arch/boot/syslinux ]; then
557 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
558 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
559
560 #manjaro
561 elif [ -d (loop)/manjaro ]; then
562 if [ -e (loop)/boot/grub/kernels.cfg ]; then
563 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
564 fi
565 elif [ -e (loop)/boot/grub/grub.cfg ]; then
566 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
567 fi
568
569 distro_specify_initrd_file
570
571 vt_linux_initrd_count vtcount
572 if [ $vtcount -eq 0 ]; then
573 distro_specify_initrd_file_phase2
574 fi
575
576 locate_initrd
577 fi
578
579 vt_linux_chain_data ${1}${chosen_path}
580 ventoy_debug_pause
581
582 if [ -n "$vtoy_chain_mem_addr" ]; then
583 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
584 boot
585 else
586 echo "chain empty failed"
587 ventoy_pause
588 fi
589 }
590
591
592 function legacy_unix_menu_func {
593 ventoy_unix_comm_proc $1 ${chosen_path}
594
595 if [ -n "$vtoy_chain_mem_addr" ]; then
596 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
597 boot
598 else
599 echo "chain empty failed"
600 ventoy_pause
601 fi
602 }
603
604
605 function legacy_iso_menu_func {
606
607 if [ -d (loop)/ ]; then
608 loopback -d loop
609 fi
610
611 vt_chosen_img_path chosen_path
612 vt_select_auto_install ${chosen_path}
613 vt_select_persistence ${chosen_path}
614
615 if vt_is_udf ${1}${chosen_path}; then
616 set ventoy_fs_probe=udf
617 else
618 set ventoy_fs_probe=iso9660
619 vt_iso9660_nojoliet 0
620 fi
621
622 loopback loop ${1}${chosen_path}
623 vt_parse_iso_volume ${1}${chosen_path} vt_system_id vt_volume_id
624 get_os_type (loop)
625
626 if [ -n "$vtcompat" ]; then
627 set ventoy_compatible=YES
628 unset vtcompat
629 elif vt_check_mode 1; then
630 set ventoy_compatible=YES
631 else
632 vt_check_compatible (loop)
633 fi
634
635 vt_img_sector ${1}${chosen_path}
636
637 if [ "$vtoy_os" = "Windows" ]; then
638 vt_check_compatible_pe (loop)
639 legacy_windows_menu_func $1 ${chosen_path}
640 elif [ "$vtoy_os" = "Unix" ]; then
641 legacy_unix_menu_func $1 ${chosen_path}
642 else
643 legacy_linux_menu_func $1 ${chosen_path}
644 fi
645 }
646
647 function legacy_iso_memdisk {
648 vt_chosen_img_path chosen_path
649
650 linux16 $vtoy_path/memdisk iso raw
651 echo "Loading ISO file to memory ..."
652 initrd16 ${1}${chosen_path}
653 boot
654 }
655
656 function iso_common_menuentry {
657 unset vt_system_id
658 unset vt_volume_id
659
660 if [ "$grub_platform" = "pc" ]; then
661 if vt_check_mode 0; then
662 legacy_iso_memdisk $vtoy_iso_part
663 else
664 legacy_iso_menu_func $vtoy_iso_part
665 fi
666 else
667 if vt_check_mode 0; then
668 uefi_iso_memdisk $vtoy_iso_part
669 else
670 uefi_iso_menu_func $vtoy_iso_part
671 fi
672 fi
673 }
674
675 function common_unsupport_menuentry {
676 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
677 echo -e " 文件名中不能有中文或空格 \n"
678 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
679 read vtInputKey
680 }
681
682 function iso_unsupport_menuentry {
683 common_unsupport_menuentry
684 }
685
686 function wim_common_menuentry {
687 vt_chosen_img_path chosen_path
688 vt_wim_chain_data ${vtoy_iso_part}${chosen_path}
689
690 ventoy_debug_pause
691
692 if [ -n "$vtoy_chain_mem_addr" ]; then
693 if [ "$grub_platform" = "pc" ]; then
694 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
695 else
696 ventoy_cli_console
697 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
698 ventoy_gui_console
699 fi
700 boot
701 else
702 echo "chain empty failed"
703 ventoy_pause
704 fi
705 }
706
707 function wim_unsupport_menuentry {
708 common_unsupport_menuentry
709 }
710
711 function efi_common_menuentry {
712 vt_chosen_img_path chosen_path
713
714 ventoy_cli_console
715 chainloader ${vtoy_iso_part}${chosen_path}
716 boot
717 ventoy_gui_console
718 }
719
720 function efi_unsupport_menuentry {
721 common_unsupport_menuentry
722 }
723
724
725
726 #############################################################
727 #############################################################
728 #############################################################
729 ####### Main Process ###########
730 #############################################################
731 #############################################################
732 #############################################################
733
734 set VENTOY_VERSION="1.0.17"
735
736 # Default menu display mode, you can change it as you want.
737 # 0: List mode
738 # 1: TreeView mode
739 set VTOY_DEFAULT_MENU_MODE=0
740
741 set VTOY_MEM_DISK_STR="[Memdisk]"
742 set VTOY_ISO_RAW_STR="Compatible Mode"
743 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
744
745 set VTOY_F2_CMD="ventoy_power"
746 set VTOY_F4_CMD="ventoy_localboot"
747 set VTOY_F5_CMD="ventoy_diagnosis"
748 set VTOY_F6_CMD="ventoy_ext_menu"
749
750 if [ "$grub_platform" = "pc" ]; then
751 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
752 else
753 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
754 fi
755
756 vt_device $root vtoy_dev
757
758 if [ "$vtoy_dev" = "tftp" ]; then
759 set vtoy_path=($root)
760 for vtid in 0 1 2 3; do
761 if [ -d (hd$vtid,2)/ventoy ]; then
762 set vtoy_iso_part=(hd$vtid,1)
763 set vtoy_efi_part=(hd$vtid,2)
764 break
765 fi
766 done
767 loadfont ascii
768
769 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
770 set vt_plugin_path=$vtoy_iso_part
771 else
772 set vt_plugin_path=$prefix
773 vt_load_plugin $vt_plugin_path
774 fi
775 else
776 if [ "$prefix" = "(ventoydisk)/grub" ]; then
777 set vtoy_path=(ventoydisk)/ventoy
778 else
779 set vtoy_path=($root)/ventoy
780 fi
781
782 set vtoy_iso_part=($vtoy_dev,1)
783 set vtoy_efi_part=($vtoy_dev,2)
784 loadfont unicode
785 set vt_plugin_path=$vtoy_iso_part
786 fi
787
788
789 #Load Plugin
790 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
791 vt_load_plugin $vtoy_iso_part
792 fi
793
794 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
795 set timeout=$VTOY_MENU_TIMEOUT
796 else
797 unset timeout
798 fi
799
800 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
801 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
802 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
803 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
804 fi
805
806
807 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
808 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
809 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
810 else
811 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
812 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
813 fi
814
815
816 if [ -n "$vtoy_gfxmode" ]; then
817 set gfxmode=$vtoy_gfxmode
818 else
819 set gfxmode=1920x1080,1366x768,1024x768
820 fi
821
822 if [ "$vtoy_display_mode" = "CLI" ]; then
823 terminal_output console
824 else
825 if [ -n "$vtoy_theme" ]; then
826 set theme=$vtoy_theme
827 else
828 set theme=$prefix/themes/ventoy/theme.txt
829 fi
830 terminal_output gfxterm
831 fi
832
833 #export necessary variable
834 export theme
835 export gfxmode
836 export vtoy_dev
837 export vtoy_iso_part
838 export vtoy_efi_part
839 export VENTOY_VERSION
840
841
842
843
844 #colect all image files (iso files)
845 set ventoy_img_count=0
846 vt_list_img $vtoy_iso_part ventoy_img_count
847
848 #Main menu
849 if [ $ventoy_img_count -gt 0 ]; then
850 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
851 vt_dynamic_menu 0 0
852 else
853 vt_dynamic_menu 0 1
854 fi
855 else
856 if [ -n "$VTOY_NO_ISO_TIP" ]; then
857 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
858 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
859 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
860 else
861 NO_ISO_MENU="No ISO files found"
862 fi
863 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
864 echo -e "\n Rebooting ... "
865 reboot
866 }
867 fi