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