]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
vhd boot
[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 echo "press Enter to continue ......"
21 read vtTmpPause
22 }
23
24 function ventoy_debug_pause {
25 if [ -n "${vtdebug_flag}" ]; then
26 echo "press Enter to continue ......"
27 read vtTmpPause
28 fi
29 }
30
31 function ventoy_cli_console {
32 if [ -z "$vtoy_display_mode" ]; then
33 terminal_output console
34 elif [ "$vtoy_display_mode" = "GUI" ]; then
35 terminal_output console
36 fi
37 }
38
39 function ventoy_gui_console {
40 if [ -z "$vtoy_display_mode" ]; then
41 terminal_output gfxterm
42 elif [ "$vtoy_display_mode" = "GUI" ]; then
43 terminal_output gfxterm
44 fi
45 }
46
47 function ventoy_power {
48 configfile $prefix/power.cfg
49 }
50
51 function ventoy_diagnosis {
52 configfile $prefix/debug.cfg
53 }
54
55 function ventoy_localboot {
56 configfile $prefix/localboot.cfg
57 }
58
59 function ventoy_ext_menu {
60 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
61 set ventoy_new_context=1
62 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
63 unset ventoy_new_context
64 else
65 echo "ventoy_grub.cfg NOT exist."
66 echo -e "\npress ENTER to exit ..."
67 read vtInputKey
68 fi
69 }
70
71 function get_os_type {
72 set vtoy_os=Linux
73
74 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
75 if vt_file_exist_nocase (loop)/$file; then
76 set vtoy_os=Windows
77 break
78 fi
79 done
80
81 if [ "$vtoy_os" = "Linux" ]; then
82 if vt_strstr "$vt_system_id" "FreeBSD"; then
83 set vtoy_os=Unix
84 set vt_unix_type=FreeBSD
85 elif [ -e (loop)/bin/freebsd-version ]; then
86 set vtoy_os=Unix
87 set vt_unix_type=FreeBSD
88
89
90 elif [ -e (loop)/boot/kernel/kernel ]; then
91 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
92 set vtoy_os=Unix
93 set vt_unix_type=FreeBSD
94 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
95 set vtoy_os=Unix
96 set vt_unix_type=NetBSD
97 fi
98 fi
99 fi
100
101 if [ -n "${vtdebug_flag}" ]; then
102 echo ISO is $vtoy_os
103 fi
104 }
105
106 function vt_check_compatible_pe {
107 #Check for PE without external tools
108 if [ -f $1/HBCD_PE.ini ]; then
109 set ventoy_compatible=YES
110 fi
111 }
112
113 function locate_initrd {
114 vt_linux_locate_initrd
115
116 if [ -n "${vtdebug_flag}" ]; then
117 vt_linux_dump_initrd
118 ventoy_debug_pause
119 fi
120 }
121
122 function locate_wim {
123 vt_windows_locate_wim_patch (loop)
124
125 if [ -n "${vtdebug_flag}" ]; then
126 echo '###############################################'
127 vt_dump_wim_patch
128 echo '###############################################'
129 ventoy_debug_pause
130 fi
131 }
132
133 function distro_specify_wim_patch {
134 if [ -d (loop)/h3pe ]; then
135 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
136 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
137 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
138 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
139 fi
140 }
141
142 function distro_specify_wim_patch_phase2 {
143 if [ -f (loop)/boot/boot.wim ]; then
144 vt_windows_collect_wim_patch wim /boot/boot.wim
145 fi
146 }
147
148
149 function distro_specify_initrd_file {
150 if [ -e (loop)/boot/all.rdz ]; then
151 vt_linux_specify_initrd_file /boot/all.rdz
152 elif [ -e (loop)/boot/xen.gz ]; then
153 if [ -e (loop)/install.img ]; then
154 vt_linux_specify_initrd_file /install.img
155 fi
156 elif [ -d (loop)/casper ]; then
157 if [ -e (loop)/casper/initrd ]; then
158 vt_linux_specify_initrd_file /casper/initrd
159 fi
160 if [ -e (loop)/casper/initrd.gz ]; then
161 vt_linux_specify_initrd_file /casper/initrd.gz
162 fi
163 if [ -e (loop)/casper/initrd-oem ]; then
164 vt_linux_specify_initrd_file /casper/initrd-oem
165 fi
166 elif [ -e (loop)/boot/grub/initrd.xz ]; then
167 vt_linux_specify_initrd_file /boot/grub/initrd.xz
168 elif [ -e (loop)/initrd.gz ]; then
169 vt_linux_specify_initrd_file /initrd.gz
170 elif [ -e (loop)/slax/boot/initrfs.img ]; then
171 vt_linux_specify_initrd_file /slax/boot/initrfs.img
172 elif [ -e (loop)/pmagic/initrd.img ]; then
173 vt_linux_specify_initrd_file /pmagic/initrd.img
174 elif [ -e (loop)/boot/initrd.xz ]; then
175 vt_linux_specify_initrd_file /boot/initrd.xz
176 elif [ -e (loop)/boot/initrd.gz ]; then
177 vt_linux_specify_initrd_file /boot/initrd.gz
178 elif [ -f (loop)/boot/initrd ]; then
179 vt_linux_specify_initrd_file /boot/initrd
180 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
181 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
182 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
183 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
184 elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
185 vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
186
187
188 fi
189
190 if [ -f (loop)/isolinux/initrd.gz ]; then
191 vt_linux_specify_initrd_file /isolinux/initrd.gz
192 fi
193
194 if [ "$vt_chosen_size" = "1133375488" ]; then
195 if [ -d (loop)/boot/grub/x86_64-efi ]; then
196 vt_cpio_busybox64
197 fi
198 fi
199 }
200
201
202 function distro_specify_initrd_file_phase2 {
203 if [ -f (loop)/boot/initrd.img ]; then
204 vt_linux_specify_initrd_file /boot/initrd.img
205 elif [ -f (loop)/Setup/initrd.gz ]; then
206 vt_linux_specify_initrd_file /Setup/initrd.gz
207 elif [ -f (loop)/isolinux/initramfs ]; then
208 vt_linux_specify_initrd_file /isolinux/initramfs
209 elif [ -f (loop)/boot/iniramfs.igz ]; then
210 vt_linux_specify_initrd_file /boot/iniramfs.igz
211 elif [ -f (loop)/initrd-x86_64 ]; then
212 vt_linux_specify_initrd_file /initrd-x86_64
213 elif [ -f (loop)/live/initrd.img ]; then
214 vt_linux_specify_initrd_file /live/initrd.img
215 elif [ -f (loop)/initrd.img ]; then
216 vt_linux_specify_initrd_file /initrd.img
217 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
218 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
219 elif [ -f (loop)/CDlinux/initrd ]; then
220 vt_linux_specify_initrd_file /CDlinux/initrd
221 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
222 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
223 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
224 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
225 fi
226 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
227 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
228 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
229 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
230 fi
231 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
232 #Qubes
233 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
234 if [ "$grub_platform" != "pc" ]; then
235 vt_add_replace_file 0 "initrd.img"
236 fi
237 elif [ -f (loop)/initrd ]; then
238 vt_linux_specify_initrd_file /initrd
239 elif [ -f (loop)/live/initrd1 ]; then
240 vt_linux_specify_initrd_file /live/initrd1
241 elif [ -f (loop)/isolinux/initrd.img ]; then
242 vt_linux_specify_initrd_file /isolinux/initrd.img
243 elif [ -f (loop)/isolinux/initrd.gz ]; then
244 vt_linux_specify_initrd_file /isolinux/initrd.gz
245 elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
246 vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
247 elif vt_strstr $vt_volume_id "Daphile"; then
248 vt_linux_parse_initrd_isolinux (loop)/isolinux/
249 elif [ -f (loop)/boot/rootfs.xz ]; then
250 vt_linux_specify_initrd_file /boot/rootfs.xz
251 if [ "$grub_platform" != "pc" ]; then
252 vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
253 fi
254
255 fi
256 }
257
258 function ventoy_get_ghostbsd_ver {
259
260 # vt_parse_iso_create_date $1/${chosen_path} vt_create_date
261 # if regexp "^202005" "$vt_create_date"; then
262 # set vt_freebsd_ver=12.x
263 # fi
264
265 set vt_freebsd_ver=12.x
266 }
267
268 function ventoy_get_furybsd_ver {
269 if regexp "13\.[0-9]" "$2"; then
270 set vt_freebsd_ver=13.x
271 else
272 set vt_freebsd_ver=12.x
273 fi
274 }
275
276 function ventoy_get_freenas_ver {
277 set vt_freebsd_ver=11.x
278
279 if [ -e (loop)/FreeNAS-MANIFEST ]; then
280 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
281 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
282 set vt_freebsd_ver=13.x
283 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
284 set vt_freebsd_ver=12.x
285 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
286 set vt_freebsd_ver=11.x
287 fi
288 fi
289 }
290
291 function ventoy_get_midnightbsd_ver {
292 set vt_freebsd_ver=11.x
293 }
294
295 function ventoy_freebsd_proc {
296 set vtFreeBsdDistro=FreeBSD
297
298 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
299 ventoy_get_ghostbsd_ver $1 ${chosen_path}
300 elif vt_strstr "$vt_volume_id" "FREENAS"; then
301 ventoy_get_freenas_ver $1 ${chosen_path}
302 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
303 ventoy_get_furybsd_ver $1 ${chosen_path}
304 elif regexp "^13_[0-9]" "$vt_volume_id"; then
305 set vt_freebsd_ver=13.x
306 elif regexp "^12_[0-9]" "$vt_volume_id"; then
307 set vt_freebsd_ver=12.x
308 elif regexp "^11_[0-9]" "$vt_volume_id"; then
309 set vt_freebsd_ver=11.x
310 elif regexp "^10_[0-9]" "$vt_volume_id"; then
311 set vt_freebsd_ver=10.x
312 elif regexp "^9_[0-9]" "$vt_volume_id"; then
313 set vt_freebsd_ver=9.x
314 elif [ -d (loop)/usr/midnightbsd-dist ]; then
315 ventoy_get_midnightbsd_ver $1 ${chosen_path}
316 set vtFreeBsdDistro=MidnightBSD
317 elif [ -e (loop)/bin/freebsd-version ]; then
318 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
319 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
320 set vt_freebsd_ver=13.x
321 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
322 set vt_freebsd_ver=12.x
323 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
324 set vt_freebsd_ver=11.x
325 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
326 set vt_freebsd_ver=10.x
327 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
328 set vt_freebsd_ver=9.x
329 fi
330 elif [ -e (loop)/README.TXT ]; then
331 vt_1st_line (loop)/README.TXT vt_freebsd_line1
332 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
333 set vt_freebsd_ver=13.x
334 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
335 set vt_freebsd_ver=12.x
336 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
337 set vt_freebsd_ver=11.x
338 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
339 set vt_freebsd_ver=10.x
340 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
341 set vt_freebsd_ver=9.x
342 fi
343 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
344 set vt_freebsd_ver=9.x
345 else
346 set vt_freebsd_ver=12.x
347 fi
348
349 set vt_freebsd_bit=64
350 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
351 if [ -e (loop)/$file ]; then
352 if file --is-i386-kfreebsd (loop)/$file; then
353 set vt_freebsd_bit=32
354 fi
355 break
356 fi
357 done
358
359 if [ -n "${vtdebug_flag}" ]; then
360 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
361 fi
362
363 unset vt_unix_mod_path
364 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version" "/etc/fstab"; do
365 if [ -e (loop)${file} ]; then
366 set vt_unix_mod_path=${file}
367 break
368 fi
369 done
370
371 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
372 set vtFreeBsdDistro=ClonOS
373 fi
374
375 vt_unix_replace_ko $vt_unix_mod_path (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
376 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
377 }
378
379 function ventoy_unix_comm_proc {
380 vt_unix_reset
381
382 if [ "$ventoy_compatible" = "NO" ]; then
383 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
384
385 if [ "$vt_unix_type" = "FreeBSD" ]; then
386 ventoy_freebsd_proc $1 ${chosen_path}
387 elif [ "$vt_unix_type" = "NetBSD" ]; then
388 echo "NetBSD not supported"
389
390
391
392 else
393 if [ -n "${vtdebug_flag}" ]; then
394 echo "Unknown unix type"
395 fi
396 fi
397 fi
398
399 vt_unix_chain_data ${1}${chosen_path}
400 ventoy_debug_pause
401 }
402
403
404 function uefi_windows_menu_func {
405 vt_windows_reset
406
407 if [ "$ventoy_compatible" = "NO" ]; then
408
409 if [ "$ventoy_fs_probe" = "iso9660" ]; then
410 loopback -d loop
411 vt_iso9660_nojoliet 1
412 loopback loop $1$2
413 fi
414
415 for file in "efi/microsoft/boot/bcd"; do
416 vt_windows_collect_wim_patch bcd (loop)/$file
417 done
418
419 vt_windows_count_wim_patch vt_wim_cnt
420 if [ $vt_wim_cnt -eq 0 ]; then
421 distro_specify_wim_patch_phase2
422 fi
423
424 ventoy_debug_pause
425 locate_wim
426 fi
427
428 vt_windows_chain_data ${1}${chosen_path}
429 ventoy_debug_pause
430
431 if [ -n "$vtoy_chain_mem_addr" ]; then
432 ventoy_cli_console
433 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${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 uefi_linux_menu_func {
442 if [ "$ventoy_compatible" = "NO" ]; then
443
444 if [ "$ventoy_fs_probe" = "udf" ]; then
445 loopback -d loop
446 set ventoy_fs_probe=iso9660
447 loopback loop $1$2
448 fi
449
450 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
451
452 vt_linux_clear_initrd
453
454 if [ -d (loop)/pmagic ]; then
455 vt_linux_specify_initrd_file /pmagic/initrd.img
456 else
457 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
458 if [ -e (loop)/$file ]; then
459 vt_linux_parse_initrd_grub file (loop)/$file
460 fi
461 done
462 fi
463
464 # special process for special distros
465 if [ -d (loop)/loader/entries ]; then
466 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
467 elif [ -d (loop)/boot/grub ]; then
468 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
469 fi
470
471 distro_specify_initrd_file
472
473 vt_linux_initrd_count vtcount
474 if [ $vtcount -eq 0 ]; then
475 distro_specify_initrd_file_phase2
476
477 if [ "$vt_efi_dir" = "NO" ]; then
478 if [ -f (loop)/efi.img ]; then
479 vt_add_replace_file 0 "initrd"
480 fi
481 fi
482 fi
483
484 locate_initrd
485
486 if [ -d (loop)/loader/entries ]; then
487 vt_linux_get_main_initrd_index vtindex
488
489 if [ -d (loop)/arch ]; then
490 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
491 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
492 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
493 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
494 fi
495 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
496 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
497 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
498 vt_add_replace_file $vtindex "boot\\initrd"
499 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
500 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
501 fi
502 elif [ -d (loop)/EFI/boot/entries ]; then
503 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
504 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
505 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
506 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
507 fi
508 elif [ -d (loop)/EFI/BOOT/entries ]; then
509 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
510 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
511 fi
512 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
513 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
514 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
515
516
517 fi
518
519 fi
520
521 vt_linux_chain_data ${1}${chosen_path}
522
523 if [ -n "$vtoy_chain_mem_addr" ]; then
524 ventoy_cli_console
525 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}
526 boot
527 else
528 echo "chain empty failed"
529 ventoy_pause
530 fi
531 }
532
533 function uefi_unix_menu_func {
534 ventoy_unix_comm_proc $1 ${chosen_path}
535
536 if [ -n "$vtoy_chain_mem_addr" ]; then
537 ventoy_cli_console
538 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}
539 boot
540 else
541 echo "chain empty failed"
542 ventoy_pause
543 fi
544 }
545
546 function uefi_iso_menu_func {
547
548 if [ -d (loop)/ ]; then
549 loopback -d loop
550 fi
551
552 if [ -n "$vtisouefi" ]; then
553 set LoadIsoEfiDriver=on
554 unset vtisouefi
555 elif vt_check_mode 2; then
556 set LoadIsoEfiDriver=on
557 else
558 unset LoadIsoEfiDriver
559 fi
560
561 set chosen_path=$2
562 vt_select_auto_install ${chosen_path}
563 vt_select_persistence ${chosen_path}
564
565 if vt_is_udf ${1}${chosen_path}; then
566 set ventoy_fs_probe=udf
567 else
568 set ventoy_fs_probe=iso9660
569 vt_iso9660_nojoliet 0
570 fi
571
572 loopback loop ${1}${chosen_path}
573 get_os_type (loop)
574
575 if [ -d (loop)/EFI ]; then
576 set vt_efi_dir=YES
577 elif [ -d (loop)/efi ]; then
578 set vt_efi_dir=YES
579 else
580 set vt_efi_dir=NO
581 fi
582
583 if [ -n "$vtcompat" ]; then
584 set ventoy_compatible=YES
585 unset vtcompat
586 elif vt_check_mode 1; then
587 set ventoy_compatible=YES
588 else
589 vt_check_compatible (loop)
590 fi
591
592 vt_img_sector ${1}${chosen_path}
593
594 if [ "$vtoy_os" = "Windows" ]; then
595 vt_check_compatible_pe (loop)
596 uefi_windows_menu_func $1 ${chosen_path}
597 elif [ "$vtoy_os" = "Unix" ]; then
598 uefi_unix_menu_func $1 ${chosen_path}
599 else
600 uefi_linux_menu_func $1 ${chosen_path}
601 fi
602
603 ventoy_gui_console
604 }
605
606 function uefi_iso_memdisk {
607 echo 'Loading ISO file to memory ...'
608 vt_load_img_memdisk ${1}${2} vtoy_iso_buf
609
610 ventoy_cli_console
611 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}
612 boot
613
614 ventoy_gui_console
615 }
616
617
618 function legacy_windows_menu_func {
619 vt_windows_reset
620
621 if [ "$ventoy_compatible" = "NO" ]; then
622
623 if [ "$ventoy_fs_probe" = "iso9660" ]; then
624 loopback -d loop
625 vt_iso9660_nojoliet 1
626 loopback loop $1$2
627 fi
628
629 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
630 vt_windows_collect_wim_patch bcd (loop)/$file
631 done
632
633 distro_specify_wim_patch
634
635 vt_windows_count_wim_patch vt_wim_cnt
636 if [ $vt_wim_cnt -eq 0 ]; then
637 distro_specify_wim_patch_phase2
638 fi
639
640 ventoy_debug_pause
641 locate_wim
642 fi
643
644 vt_windows_chain_data ${1}${chosen_path}
645 ventoy_debug_pause
646
647 if [ -n "$vtoy_chain_mem_addr" ]; then
648 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
649 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
650 terminal_output gfxterm
651 boot
652 else
653 echo "chain empty failed"
654 ventoy_pause
655 fi
656 }
657
658 function legacy_linux_menu_func {
659 if [ "$ventoy_compatible" = "NO" ]; then
660
661 if [ "$ventoy_fs_probe" = "udf" ]; then
662 loopback -d loop
663 set ventoy_fs_probe=iso9660
664 loopback loop $1$2
665 fi
666
667 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
668
669 vt_linux_clear_initrd
670
671 if [ -d (loop)/pmagic ]; then
672 vt_linux_specify_initrd_file /pmagic/initrd.img
673 else
674 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
675 if [ -d (loop)/$dir ]; then
676 vt_linux_parse_initrd_isolinux (loop)/$dir/
677 fi
678 done
679 fi
680
681 # special process for special distros
682 #archlinux
683 if [ -d (loop)/arch/boot/syslinux ]; then
684 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
685 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
686
687 #manjaro
688 elif [ -d (loop)/manjaro ]; then
689 if [ -e (loop)/boot/grub/kernels.cfg ]; then
690 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
691 fi
692 elif [ -e (loop)/boot/grub/grub.cfg ]; then
693 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
694 fi
695
696 distro_specify_initrd_file
697
698 vt_linux_initrd_count vtcount
699 if [ $vtcount -eq 0 ]; then
700 if [ -d (loop)/rancheros ]; then
701 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
702 fi
703
704 distro_specify_initrd_file_phase2
705 fi
706
707 locate_initrd
708 fi
709
710 vt_linux_chain_data ${1}${chosen_path}
711 ventoy_debug_pause
712
713 if [ -n "$vtoy_chain_mem_addr" ]; then
714 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
715 boot
716 else
717 echo "chain empty failed"
718 ventoy_pause
719 fi
720 }
721
722
723 function legacy_unix_menu_func {
724 ventoy_unix_comm_proc $1 ${chosen_path}
725
726 if [ -n "$vtoy_chain_mem_addr" ]; then
727 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
728 boot
729 else
730 echo "chain empty failed"
731 ventoy_pause
732 fi
733 }
734
735
736 function legacy_iso_menu_func {
737
738 if [ -d (loop)/ ]; then
739 loopback -d loop
740 fi
741
742 set chosen_path=$2
743 vt_select_auto_install ${chosen_path}
744 vt_select_persistence ${chosen_path}
745
746 if vt_is_udf ${1}${chosen_path}; then
747 set ventoy_fs_probe=udf
748 else
749 set ventoy_fs_probe=iso9660
750 vt_iso9660_nojoliet 0
751 fi
752
753 loopback loop ${1}${chosen_path}
754
755 get_os_type (loop)
756
757 if [ -n "$vtcompat" ]; then
758 set ventoy_compatible=YES
759 unset vtcompat
760 elif vt_check_mode 1; then
761 set ventoy_compatible=YES
762 else
763 vt_check_compatible (loop)
764 fi
765
766 vt_img_sector ${1}${chosen_path}
767
768 if [ "$vtoy_os" = "Windows" ]; then
769 vt_check_compatible_pe (loop)
770 legacy_windows_menu_func $1 ${chosen_path}
771 elif [ "$vtoy_os" = "Unix" ]; then
772 legacy_unix_menu_func $1 ${chosen_path}
773 else
774 legacy_linux_menu_func $1 ${chosen_path}
775 fi
776 }
777
778 function legacy_iso_memdisk {
779
780 linux16 $vtoy_path/memdisk iso raw
781 echo "Loading ISO file to memory ..."
782 initrd16 ${1}${2}
783 boot
784 }
785
786
787 function iso_endless_os_proc {
788 if [ -d (loop)/ ]; then
789 loopback -d loop
790 fi
791
792 loopback loop ${1}${2}
793 vt_img_sector ${1}${2}
794
795 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
796 vt_trailer_cpio $1 $2 noinit
797
798 ventoy_debug_pause
799
800 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
801
802 set eosimage=loop
803 set ventoy_bls_bootdev=/boot
804 set ventoy_loading_tip="Loading files ......"
805
806 export eosimage
807 configfile (loop)/endless/grub/grub.cfg
808
809 unset eosimage
810 unset ventoy_bls_bootdev
811 unset ventoy_loading_tip
812
813 vt_unset_boot_opt
814 }
815
816
817 function ventoy_iso_busybox_ver {
818 set ventoy_busybox_ver=32
819
820 #special process for deepin-live iso
821 if [ "$vt_chosen_size" = "403701760" ]; then
822 if vt_str_str $vt_chosen_path "/deepin-live"; then
823 set ventoy_busybox_ver=64
824 fi
825 elif vt_str_begin $vt_volume_id "PHOTON_"; then
826 set ventoy_busybox_ver=64
827 elif vt_str_begin $vt_volume_id "smgl-test-quinq-x86_64"; then
828 set ventoy_busybox_ver=64
829
830 fi
831 }
832
833 function iso_common_menuentry {
834 unset vt_system_id
835 unset vt_volume_id
836
837 vt_chosen_img_path vt_chosen_path vt_chosen_size
838 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
839
840 ventoy_iso_busybox_ver
841
842 #special process for Endless OS
843 if vt_str_begin $vt_volume_id "Endless-OS"; then
844 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
845 elif vt_str_begin $vt_volume_id "TENS-Public"; then
846 set vtcompat=1
847 fi
848
849 if [ "$grub_platform" = "pc" ]; then
850 if vt_check_mode 0; then
851 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
852 else
853 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
854 fi
855 else
856 if vt_check_mode 0; then
857 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
858 else
859 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
860 fi
861 fi
862 }
863
864 function miso_common_menuentry {
865 vt_chosen_img_path vt_chosen_path vt_chosen_size
866
867 if [ "$grub_platform" = "pc" ]; then
868 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
869 else
870 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
871 fi
872 }
873
874
875 function common_unsupport_menuentry {
876 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
877 echo -e " 文件名中不能有中文或空格 \n"
878 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
879 read vtInputKey
880 }
881
882 function miso_unsupport_menuentry {
883 common_unsupport_menuentry
884 }
885
886 function iso_unsupport_menuentry {
887 common_unsupport_menuentry
888 }
889
890 function wim_common_menuentry {
891 vt_chosen_img_path vt_chosen_path vt_chosen_size
892 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
893
894 ventoy_debug_pause
895
896 if [ -n "$vtoy_chain_mem_addr" ]; then
897 if [ "$grub_platform" = "pc" ]; then
898 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
899 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
900 terminal_output gfxterm
901 else
902 ventoy_cli_console
903 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
904 ventoy_gui_console
905 fi
906 boot
907 else
908 echo "chain empty failed"
909 ventoy_pause
910 fi
911 }
912
913 function wim_unsupport_menuentry {
914 common_unsupport_menuentry
915 }
916
917 function efi_common_menuentry {
918 vt_chosen_img_path vt_chosen_path vt_chosen_size
919
920 vt_concat_efi_iso ${vtoy_iso_part}${vt_chosen_path} vtoy_iso_buf
921
922 ventoy_debug_pause
923
924 ventoy_cli_console
925
926 unset vtoy_dotefi_retry
927 chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} dotefi isoefi=on ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
928 boot
929
930 if [ -n "$vtoy_dotefi_retry" ]; then
931 unset vtoy_dotefi_retry
932 chainloader ${vtoy_iso_part}${vt_chosen_path}
933 boot
934 fi
935
936 ventoy_gui_console
937 }
938
939 function efi_unsupport_menuentry {
940 common_unsupport_menuentry
941 }
942
943
944 function vhd_common_menuentry {
945
946 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
947 if [ "$vtoy_iso_fs" != "ntfs" ]; then
948 echo -e "!!! WARNING !!!\n"
949 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
950 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
951 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
952 read vtInputKey
953 fi
954 fi
955
956 vt_chosen_img_path vt_chosen_path vt_chosen_size
957 vt_patch_vhdboot ${vtoy_iso_part} ${vt_chosen_path}
958
959 ventoy_debug_pause
960
961 if [ -n "$vtoy_vhd_buf_addr" ]; then
962 if [ "$grub_platform" = "pc" ]; then
963 linux16 $vtoy_path/memdisk iso raw
964 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
965
966 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
967 terminal_output gfxterm
968 boot
969 else
970 ventoy_cli_console
971 chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
972 boot
973 ventoy_gui_console
974 fi
975 else
976 echo "Failed to boot vhd file"
977 ventoy_pause
978 fi
979 }
980
981 function vhd_unsupport_menuentry {
982 common_unsupport_menuentry
983 }
984
985 #
986 #============================================================#
987 # IMG file boot process #
988 #============================================================#
989 #
990
991
992 function ventoy_img_easyos {
993 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
994 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
995
996 loopback easysfs (vtimghd,1)/easy.sfs
997 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
998
999 if [ -n "$vt_module_ver" ]; then
1000 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1001 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1002 done
1003 fi
1004
1005 ventoy_debug_pause
1006
1007 #boot image file
1008 vt_set_boot_opt rdinit=/vtoy/vtoy
1009 vt_img_hook_root
1010
1011 syslinux_configfile (vtimghd,1)/syslinux.cfg
1012
1013 vt_img_unhook_root
1014 vt_unset_boot_opt
1015 loopback -d easysfs
1016 }
1017
1018 function ventoy_img_volumio {
1019 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1020 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1021
1022 ventoy_debug_pause
1023
1024 #boot image file
1025 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1026 vt_img_hook_root
1027
1028 syslinux_configfile (vtimghd,1)/syslinux.cfg
1029
1030 vt_img_unhook_root
1031 vt_unset_boot_opt
1032 }
1033
1034 function ventoy_img_openelec {
1035 elec_ver=$1
1036
1037 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1038 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1039
1040 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1041 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1042
1043 ventoy_debug_pause
1044
1045 #boot image file
1046 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1047 vt_img_hook_root
1048
1049 set root=(vtimghd,1)
1050 syslinux_configfile (vtimghd,1)/syslinux.cfg
1051
1052 vt_img_unhook_root
1053 vt_unset_boot_opt
1054 loopback -d vtloopex
1055 }
1056
1057
1058 function ventoy_img_freedombox {
1059 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1060 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1061
1062 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1063 if [ -n "$vt_module_ver" ]; then
1064 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1065 fi
1066
1067 ventoy_debug_pause
1068
1069 #boot image file
1070 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1071 vt_img_hook_root
1072
1073 configfile (vtimghd,1)/boot/grub/grub.cfg
1074
1075 vt_img_unhook_root
1076 vt_unset_boot_opt
1077 }
1078
1079 function ventoy_img_paldo {
1080 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1081 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1082
1083 ventoy_debug_pause
1084
1085 #boot image file
1086 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1087 vt_img_hook_root
1088
1089 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1090 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1091
1092 echo loading file...
1093 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1094 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1095 boot
1096
1097 vt_img_unhook_root
1098 vt_unset_boot_opt
1099 }
1100
1101 function ventoy_img_ubos {
1102 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1103 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1104
1105 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1106 if [ -n "$vt_module_ver" ]; then
1107 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1108 fi
1109
1110 ventoy_debug_pause
1111
1112 #boot image file
1113 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1114 vt_img_hook_root
1115
1116 echo loading file...
1117 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1118 initrd (vtimghd,2)/initramfs-linux.img
1119 boot
1120
1121 vt_img_unhook_root
1122 vt_unset_boot_opt
1123 }
1124
1125 function ventoy_img_recalbox {
1126 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1127 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1128
1129 ventoy_debug_pause
1130
1131 #boot image file
1132 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1133 vt_img_hook_root
1134
1135 set root=(vtimghd,1)
1136 configfile (vtimghd,1)/boot/grub/grub.cfg
1137
1138 vt_img_unhook_root
1139 vt_unset_boot_opt
1140 }
1141
1142 function ventoy_img_batocera {
1143 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1144 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1145
1146 ventoy_debug_pause
1147
1148 #boot image file
1149 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1150 vt_img_hook_root
1151
1152 set root=(vtimghd,1)
1153 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1154
1155 vt_img_unhook_root
1156 vt_unset_boot_opt
1157 }
1158
1159 function ventoy_img_memtest86 {
1160 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
1161 boot
1162 }
1163
1164 function img_unsupport_tip {
1165 echo -e "\n This IMG file is NOT supported now. \n"
1166 echo -e " 当前不支持启动此 IMG 文件 \n"
1167 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1168 read vtInputKey
1169 }
1170
1171 function img_common_menuentry {
1172 set ventoy_compatible=YES
1173 set ventoy_busybox_ver=32
1174
1175 vt_chosen_img_path vt_chosen_path vt_chosen_size
1176
1177 if [ -d (vtimghd)/ ]; then
1178 loopback -d vtimghd
1179 fi
1180
1181 loopback vtimghd ${vtoy_iso_part}${vt_chosen_path}
1182 vt_img_sector ${vtoy_iso_part}${vt_chosen_path}
1183
1184 vt_img_part_info (vtimghd)
1185
1186 set vtback_root=$root
1187 ventoy_cli_console
1188 vt_push_last_entry
1189
1190 vt_img_extra_initrd_reset
1191
1192 vt_get_fs_label (vtimghd,1) vtImgHd1Label
1193 if [ -d (vtimghd,2)/lib ]; then
1194 vt_get_fs_label (vtimghd,2) vtImgHd2Label
1195 fi
1196
1197 if [ -e (vtimghd,1)/etc/hostname ]; then
1198 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
1199 fi
1200
1201 if [ -e (vtimghd,1)/easy.sfs ]; then
1202 ventoy_img_easyos
1203 elif [ -e (vtimghd,1)/volumio.initrd ]; then
1204 ventoy_img_volumio
1205 elif vt_str_begin $vtImgHd1Label "LAKKA"; then
1206 ventoy_img_openelec lakka
1207 elif vt_str_begin $vtImgHd1Label "LIBREELEC"; then
1208 ventoy_img_openelec LibreELEC
1209 elif vt_str_begin $vtImgHd1Label "paldo-live"; then
1210 ventoy_img_paldo
1211 elif vt_str_begin $vtImgHostname "freedombox"; then
1212 ventoy_img_freedombox
1213 elif vt_str_begin $vtImgHd1Label "BATOCERA"; then
1214 ventoy_img_batocera
1215 elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
1216 ventoy_img_recalbox
1217 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
1218 ventoy_img_ubos
1219 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
1220 if [ "$grub_platform" = "pc" ]; then
1221 img_unsupport_tip
1222 else
1223 ventoy_img_memtest86
1224 fi
1225 else
1226 if [ "$grub_platform" = "pc" ]; then
1227 img_unsupport_tip
1228 else
1229 vt_linux_chain_data ${vtoy_iso_part}${vt_chosen_path}
1230 chainloader ${vtoy_path}/ventoy_x64.efi sector512 env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1231 boot
1232 fi
1233 fi
1234
1235 set root=$vtback_root
1236 vt_pop_last_entry
1237 ventoy_gui_console
1238 set ventoy_compatible=NO
1239 }
1240
1241 function img_unsupport_menuentry {
1242 common_unsupport_menuentry
1243 }
1244
1245 #############################################################
1246 #############################################################
1247 #############################################################
1248 ####### Main Process ###########
1249 #############################################################
1250 #############################################################
1251 #############################################################
1252
1253 set VENTOY_VERSION="1.0.20"
1254
1255 # Default menu display mode, you can change it as you want.
1256 # 0: List mode
1257 # 1: TreeView mode
1258 set VTOY_DEFAULT_MENU_MODE=0
1259
1260 set VTOY_MEM_DISK_STR="[Memdisk]"
1261 set VTOY_ISO_RAW_STR="Compatible Mode"
1262 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
1263
1264 set VTOY_F2_CMD="ventoy_power"
1265 set VTOY_F4_CMD="ventoy_localboot"
1266 set VTOY_F5_CMD="ventoy_diagnosis"
1267 set VTOY_F6_CMD="ventoy_ext_menu"
1268
1269 if [ "$grub_platform" = "pc" ]; then
1270 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1271 else
1272 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1273 fi
1274
1275 vt_device $root vtoy_dev
1276
1277 if [ "$vtoy_dev" = "tftp" ]; then
1278 set vtoy_path=($root)
1279 for vtid in 0 1 2 3; do
1280 if [ -d (hd$vtid,2)/ventoy ]; then
1281 set vtoy_iso_part=(hd$vtid,1)
1282 set vtoy_efi_part=(hd$vtid,2)
1283 break
1284 fi
1285 done
1286 loadfont ascii
1287
1288 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1289 set vt_plugin_path=$vtoy_iso_part
1290 else
1291 set vt_plugin_path=$prefix
1292 vt_load_plugin $vt_plugin_path
1293 fi
1294 else
1295 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1296 set vtoy_path=(ventoydisk)/ventoy
1297 else
1298 set vtoy_path=($root)/ventoy
1299 fi
1300
1301 set vtoy_iso_part=($vtoy_dev,1)
1302 set vtoy_efi_part=($vtoy_dev,2)
1303 loadfont unicode
1304 set vt_plugin_path=$vtoy_iso_part
1305 fi
1306
1307
1308 #Load Plugin
1309 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1310 vt_load_plugin $vtoy_iso_part
1311 fi
1312
1313 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1314 set timeout=$VTOY_MENU_TIMEOUT
1315 else
1316 unset timeout
1317 fi
1318
1319 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1320 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1321 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1322 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1323 fi
1324
1325 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
1326 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
1327 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
1328 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
1329 fi
1330
1331
1332 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1333 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1334 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
1335 else
1336 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1337 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
1338 fi
1339
1340
1341 if [ -n "$vtoy_gfxmode" ]; then
1342 set gfxmode=$vtoy_gfxmode
1343 else
1344 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
1345 fi
1346
1347 if [ "$vtoy_display_mode" = "CLI" ]; then
1348 terminal_output console
1349 elif [ "$vtoy_display_mode" = "serial" ]; then
1350 if [ -n "$vtoy_serial_param" ]; then
1351 serial $vtoy_serial_param
1352 fi
1353 terminal_input serial
1354 terminal_output serial
1355 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1356 if [ -n "$vtoy_serial_param" ]; then
1357 serial $vtoy_serial_param
1358 fi
1359 terminal_input serial console
1360 terminal_output serial console
1361 else
1362 if [ -n "$vtoy_theme" ]; then
1363 set theme=$vtoy_theme
1364 else
1365 set theme=$prefix/themes/ventoy/theme.txt
1366 fi
1367 terminal_output gfxterm
1368 fi
1369
1370 #export necessary variable
1371 export theme
1372 export gfxmode
1373 export vtoy_dev
1374 export vtoy_iso_part
1375 export vtoy_efi_part
1376 export VENTOY_VERSION
1377
1378
1379
1380
1381 #colect all image files (iso files)
1382 set ventoy_img_count=0
1383 vt_list_img $vtoy_iso_part ventoy_img_count
1384
1385 #Main menu
1386 if [ $ventoy_img_count -gt 0 ]; then
1387 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1388 vt_dynamic_menu 0 0
1389 else
1390 vt_dynamic_menu 0 1
1391 fi
1392 else
1393 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1394 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1395 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1396 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1397 else
1398 NO_ISO_MENU="No ISO files found"
1399 fi
1400 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1401 echo -e "\n Rebooting ... "
1402 reboot
1403 }
1404 fi