1 #************************************************************************************
2 # Copyright (c) 2020, longpanda <admin@ventoy.net>
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.
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.
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/>.
17 #************************************************************************************
19 function ventoy_pause {
20 echo "press Enter to continue ......"
24 function ventoy_debug_pause {
25 if [ -n "${vtdebug_flag}" ]; then
26 echo "press Enter to continue ......"
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
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
47 function ventoy_acpi_param {
48 if [ "$VTOY_PARAM_NO_ACPI" != "1" ]; then
49 vt_acpi_param "$1" "$2"
53 function ventoy_power {
54 configfile $prefix/power.cfg
57 function ventoy_diagnosis {
59 configfile $prefix/debug.cfg
62 function ventoy_localboot {
63 configfile $prefix/localboot.cfg
66 function ventoy_ext_menu {
67 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
68 set ventoy_new_context=1
69 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
70 unset ventoy_new_context
72 echo "ventoy_grub.cfg NOT exist."
73 echo -e "\npress ENTER to exit ..."
78 function get_os_type {
81 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
82 if vt_file_exist_nocase (loop)/$file; then
88 if [ "$vtoy_os" = "Linux" ]; then
89 if vt_strstr "$vt_system_id" "FreeBSD"; then
91 set vt_unix_type=FreeBSD
92 elif [ -e (loop)/bin/freebsd-version ]; then
94 set vt_unix_type=FreeBSD
97 elif [ -e (loop)/boot/kernel/kernel ]; then
98 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
100 set vt_unix_type=FreeBSD
101 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
103 set vt_unix_type=NetBSD
108 if [ -n "${vtdebug_flag}" ]; then
109 echo ISO is "$vtoy_os"
113 function vt_check_compatible_pe {
114 #Check for PE without external tools
115 if [ -f "$1/HBCD_PE.ini" ]; then
116 set ventoy_compatible=YES
120 function locate_initrd {
121 vt_linux_locate_initrd
123 if [ -n "${vtdebug_flag}" ]; then
129 function locate_wim {
130 vt_windows_locate_wim_patch (loop)
132 if [ -n "${vtdebug_flag}" ]; then
133 echo '###############################################'
135 echo '###############################################'
140 function distro_specify_wim_patch {
141 if [ -d (loop)/h3pe ]; then
142 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
143 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
144 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
145 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
149 function distro_specify_wim_patch_phase2 {
150 if [ -f (loop)/boot/boot.wim ]; then
151 vt_windows_collect_wim_patch wim /boot/boot.wim
156 function distro_specify_initrd_file {
157 if [ -e (loop)/boot/all.rdz ]; then
158 vt_linux_specify_initrd_file /boot/all.rdz
159 elif [ -e (loop)/boot/xen.gz ]; then
160 if [ -e (loop)/install.img ]; then
161 vt_linux_specify_initrd_file /install.img
163 elif [ -d (loop)/casper ]; then
164 if [ -e (loop)/casper/initrd ]; then
165 vt_linux_specify_initrd_file /casper/initrd
167 if [ -e (loop)/casper/initrd.gz ]; then
168 vt_linux_specify_initrd_file /casper/initrd.gz
170 if [ -e (loop)/casper/initrd-oem ]; then
171 vt_linux_specify_initrd_file /casper/initrd-oem
173 elif [ -e (loop)/boot/grub/initrd.xz ]; then
174 vt_linux_specify_initrd_file /boot/grub/initrd.xz
175 elif [ -e (loop)/initrd.gz ]; then
176 vt_linux_specify_initrd_file /initrd.gz
177 elif [ -e (loop)/slax/boot/initrfs.img ]; then
178 vt_linux_specify_initrd_file /slax/boot/initrfs.img
179 elif [ -e (loop)/pmagic/initrd.img ]; then
180 vt_linux_specify_initrd_file /pmagic/initrd.img
181 elif [ -e (loop)/boot/initrd.xz ]; then
182 vt_linux_specify_initrd_file /boot/initrd.xz
183 elif [ -e (loop)/boot/initrd.gz ]; then
184 vt_linux_specify_initrd_file /boot/initrd.gz
185 elif [ -f (loop)/boot/initrd ]; then
186 vt_linux_specify_initrd_file /boot/initrd
187 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
188 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
189 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
190 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
191 elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
192 vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
197 if [ -f (loop)/isolinux/initrd.gz ]; then
198 vt_linux_specify_initrd_file /isolinux/initrd.gz
201 if [ "$vt_chosen_size" = "1133375488" ]; then
202 if [ -d (loop)/boot/grub/x86_64-efi ]; then
203 vt_cpio_busybox64 "64h"
209 function distro_specify_initrd_file_phase2 {
210 if [ -f (loop)/boot/initrd.img ]; then
211 vt_linux_specify_initrd_file /boot/initrd.img
212 elif [ -f (loop)/Setup/initrd.gz ]; then
213 vt_linux_specify_initrd_file /Setup/initrd.gz
214 elif [ -f (loop)/isolinux/initramfs ]; then
215 vt_linux_specify_initrd_file /isolinux/initramfs
216 elif [ -f (loop)/boot/iniramfs.igz ]; then
217 vt_linux_specify_initrd_file /boot/iniramfs.igz
218 elif [ -f (loop)/initrd-x86_64 ]; then
219 vt_linux_specify_initrd_file /initrd-x86_64
220 elif [ -f (loop)/live/initrd.img ]; then
221 vt_linux_specify_initrd_file /live/initrd.img
222 elif [ -f (loop)/initrd.img ]; then
223 vt_linux_specify_initrd_file /initrd.img
224 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
225 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
226 elif [ -f (loop)/CDlinux/initrd ]; then
227 vt_linux_specify_initrd_file /CDlinux/initrd
228 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
229 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
230 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
231 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
233 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
234 vt_linux_specify_initrd_file /parabola/boot/x86_64/initramfs-linux-libre.img
235 if [ -f (loop)/parabola/boot/i686/initramfs-linux-libre.img ]; then
236 vt_linux_specify_initrd_file /parabola/boot/i686/initramfs-linux-libre.img
238 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
239 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
240 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
241 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
243 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
245 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
246 if [ "$grub_platform" != "pc" ]; then
247 vt_add_replace_file 0 "initrd.img"
249 elif [ -f (loop)/initrd ]; then
250 vt_linux_specify_initrd_file /initrd
251 elif [ -f (loop)/live/initrd1 ]; then
252 vt_linux_specify_initrd_file /live/initrd1
253 elif [ -f (loop)/isolinux/initrd.img ]; then
254 vt_linux_specify_initrd_file /isolinux/initrd.img
255 elif [ -f (loop)/isolinux/initrd.gz ]; then
256 vt_linux_specify_initrd_file /isolinux/initrd.gz
257 elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
258 vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
259 elif vt_strstr "$vt_volume_id" "Daphile"; then
260 vt_linux_parse_initrd_isolinux (loop)/isolinux/
261 elif [ -f (loop)/boot/rootfs.xz ]; then
262 vt_linux_specify_initrd_file /boot/rootfs.xz
263 if [ "$grub_platform" != "pc" ]; then
264 vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
266 elif [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
267 vt_linux_specify_initrd_file /arch/boot/x86_64/archiso.img
268 if [ "$grub_platform" != "pc" ]; then
269 vt_add_replace_file 0 "EFI\\archiso\\archiso.img"
271 elif [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
272 vt_linux_specify_initrd_file /blackarch/boot/x86_64/archiso.img
274 elif [ -f (loop)/install.amd/initrd.gz ]; then
275 vt_linux_specify_initrd_file /live/initrd2.img
276 vt_linux_specify_initrd_file /install.amd/initrd.gz
277 vt_linux_specify_initrd_file /install.amd/gtk/initrd.gz
278 elif [ -f (loop)/boot/grub/kernels.cfg ]; then
279 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
284 function ventoy_get_ghostbsd_ver {
286 # vt_parse_iso_create_date "$1/${chosen_path}" vt_create_date
287 # if regexp "^202005" "$vt_create_date"; then
288 # set vt_freebsd_ver=12.x
291 set vt_freebsd_ver=12.x
294 function ventoy_get_furybsd_ver {
295 if regexp "13\.[0-9]" "$2"; then
296 set vt_freebsd_ver=13.x
298 set vt_freebsd_ver=12.x
302 function ventoy_get_freenas_ver {
303 set vt_freebsd_ver=11.x
305 if [ -e (loop)/FreeNAS-MANIFEST ]; then
306 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
307 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
308 set vt_freebsd_ver=13.x
309 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
310 set vt_freebsd_ver=12.x
311 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
312 set vt_freebsd_ver=11.x
317 function ventoy_get_truenas_ver {
318 set vt_freebsd_ver=12.x
320 if [ -e (loop)/TrueNAS-MANIFEST ]; then
321 vt_parse_freenas_ver (loop)/TrueNAS-MANIFEST vt_truenas_ver
322 if regexp "^13\.[0-9]" "$vt_truenas_ver"; then
323 set vt_freebsd_ver=13.x
324 elif regexp "^12\.[0-9]" "$vt_truenas_ver"; then
325 set vt_freebsd_ver=12.x
326 elif regexp "^11\.[0-9]" "$vt_truenas_ver"; then
327 set vt_freebsd_ver=11.x
332 function ventoy_get_midnightbsd_ver {
333 set vt_freebsd_ver=11.x
336 function ventoy_freebsd_proc {
337 set vtFreeBsdDistro=FreeBSD
339 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
340 ventoy_get_ghostbsd_ver "$1" "${chosen_path}"
341 elif vt_strstr "$vt_volume_id" "FREENAS"; then
342 ventoy_get_freenas_ver "$1" "${chosen_path}"
343 elif vt_strstr "$vt_volume_id" "TRUENAS"; then
344 ventoy_get_truenas_ver "$1" "${chosen_path}"
345 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
346 ventoy_get_furybsd_ver "$1" "${chosen_path}"
347 elif regexp "^13_[0-9]" "$vt_volume_id"; then
348 set vt_freebsd_ver=13.x
349 elif regexp "^12_[0-9]" "$vt_volume_id"; then
350 set vt_freebsd_ver=12.x
351 elif regexp "^11_[0-9]" "$vt_volume_id"; then
352 set vt_freebsd_ver=11.x
353 elif regexp "^10_[0-9]" "$vt_volume_id"; then
354 set vt_freebsd_ver=10.x
355 elif regexp "^9_[0-9]" "$vt_volume_id"; then
356 set vt_freebsd_ver=9.x
357 elif [ -d (loop)/usr/midnightbsd-dist ]; then
358 ventoy_get_midnightbsd_ver "$1" "${chosen_path}"
359 set vtFreeBsdDistro=MidnightBSD
360 elif [ -e (loop)/bin/freebsd-version ]; then
361 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
362 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
363 set vt_freebsd_ver=13.x
364 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
365 set vt_freebsd_ver=12.x
366 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
367 set vt_freebsd_ver=11.x
368 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
369 set vt_freebsd_ver=10.x
370 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
371 set vt_freebsd_ver=9.x
373 elif [ -e (loop)/README.TXT ]; then
374 vt_1st_line (loop)/README.TXT vt_freebsd_line1
375 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
376 set vt_freebsd_ver=13.x
377 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
378 set vt_freebsd_ver=12.x
379 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
380 set vt_freebsd_ver=11.x
381 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
382 set vt_freebsd_ver=10.x
383 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
384 set vt_freebsd_ver=9.x
386 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
387 set vt_freebsd_ver=9.x
389 set vt_freebsd_ver=12.x
392 set vt_freebsd_bit=64
393 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
394 if [ -e (loop)/$file ]; then
395 if file --is-i386-kfreebsd (loop)/$file; then
396 set vt_freebsd_bit=32
402 if [ -n "${vtdebug_flag}" ]; then
403 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
406 unset vt_unix_mod_path
407 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/TrueNAS-MANIFEST" "/version" "/etc/fstab"; do
408 if [ -e (loop)${file} ]; then
409 set vt_unix_mod_path=${file}
414 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
415 set vtFreeBsdDistro=ClonOS
418 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
419 vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
422 function ventoy_unix_comm_proc {
425 if [ "$ventoy_compatible" = "NO" ]; then
426 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
428 if [ "$vt_unix_type" = "FreeBSD" ]; then
429 ventoy_freebsd_proc "$1" "${chosen_path}"
430 elif [ "$vt_unix_type" = "NetBSD" ]; then
431 echo "NetBSD not supported"
436 if [ -n "${vtdebug_flag}" ]; then
437 echo "Unknown unix type"
442 vt_unix_chain_data "${1}${chosen_path}"
447 function uefi_windows_menu_func {
450 if [ "$ventoy_compatible" = "NO" ]; then
452 if [ "$ventoy_fs_probe" = "iso9660" ]; then
454 vt_iso9660_nojoliet 1
458 for file in "efi/microsoft/boot/bcd"; do
459 vt_windows_collect_wim_patch bcd (loop)/$file
462 vt_windows_count_wim_patch vt_wim_cnt
463 if [ $vt_wim_cnt -eq 0 ]; then
464 distro_specify_wim_patch_phase2
471 vt_windows_chain_data "${1}${chosen_path}"
474 if [ -n "$vtoy_chain_mem_addr" ]; then
475 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
477 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} iso_${ventoy_fs_probe} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
480 echo "chain empty failed"
485 function uefi_linux_menu_func {
487 if [ "$ventoy_compatible" = "NO" ]; then
489 if [ "$ventoy_fs_probe" = "udf" ]; then
491 set ventoy_fs_probe=iso9660
495 vt_load_cpio ${vtoy_path}/ventoy.cpio "$2" "$1" "busybox=$ventoy_busybox_ver"
497 vt_linux_clear_initrd
499 if [ -d (loop)/pmagic ]; then
500 vt_linux_specify_initrd_file /pmagic/initrd.img
502 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
503 if [ -e (loop)/$file ]; then
504 vt_linux_parse_initrd_grub file (loop)/$file
509 # special process for special distros
510 if [ -d (loop)/loader/entries ]; then
511 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
512 elif [ -d (loop)/boot/grub ]; then
513 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
516 distro_specify_initrd_file
518 vt_linux_initrd_count vtcount
520 if [ $vtcount -eq 0 ]; then
521 distro_specify_initrd_file_phase2
523 if [ "$vt_efi_dir" = "NO" ]; then
524 if [ -f (loop)/efi.img ]; then
525 vt_add_replace_file 0 "initrd"
532 if [ -d (loop)/loader/entries ]; then
533 vt_linux_get_main_initrd_index vtindex
535 if [ -d (loop)/arch ]; then
536 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
537 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
538 elif [ -f (loop)/arch/boot/x86_64/initramfs-linux.img ]; then
539 vt_add_replace_file $vtindex "arch\\boot\\x86_64\\initramfs-linux.img"
540 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
541 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
543 elif [ -d (loop)/blackarch ]; then
544 if [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
545 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
547 elif [ -d (loop)/anarchy ]; then
548 if [ -f (loop)/anarchy/boot/x86_64/initramfs-linux.img ]; then
549 vt_add_replace_file $vtindex "anarchy\\boot\\x86_64\\initramfs-linux.img"
551 elif [ -d (loop)/parabola ]; then
552 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
553 vt_add_replace_file $vtindex "EFI\\parabolaiso\\parabolaiso.img"
554 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
555 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
557 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
558 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
559 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
560 vt_add_replace_file $vtindex "boot\\initrd"
561 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
562 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
564 elif [ -d (loop)/EFI/boot/entries ]; then
565 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
566 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
567 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
568 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
570 elif [ -d (loop)/EFI/BOOT/entries ]; then
571 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
572 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
573 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
574 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
576 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
577 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
578 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
585 vt_linux_chain_data "${1}${chosen_path}"
587 if [ -n "$vtoy_chain_mem_addr" ]; then
588 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
590 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
593 echo "chain empty failed"
598 function uefi_unix_menu_func {
599 ventoy_unix_comm_proc $1 "${chosen_path}"
601 if [ -n "$vtoy_chain_mem_addr" ]; then
602 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
604 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
607 echo "chain empty failed"
612 function uefi_iso_menu_func {
614 if [ -d (loop)/ ]; then
618 if [ -n "$vtisouefi" ]; then
619 set LoadIsoEfiDriver=on
621 elif vt_check_mode 2; then
622 set LoadIsoEfiDriver=on
624 unset LoadIsoEfiDriver
628 vt_select_auto_install "${chosen_path}"
629 vt_select_persistence "${chosen_path}"
631 if vt_is_udf "${1}${chosen_path}"; then
632 set ventoy_fs_probe=udf
634 set ventoy_fs_probe=iso9660
635 vt_iso9660_nojoliet 0
638 loopback loop "${1}${chosen_path}"
641 if [ -d (loop)/EFI ]; then
643 elif [ -d (loop)/efi ]; then
649 if [ -n "$vtcompat" ]; then
650 set ventoy_compatible=YES
652 elif vt_check_mode 1; then
653 set ventoy_compatible=YES
655 vt_check_compatible (loop)
658 vt_img_sector "${1}${chosen_path}"
660 if [ "$ventoy_fs_probe" = "iso9660" ]; then
661 vt_select_conf_replace "${1}" "${chosen_path}"
664 if [ "$vtoy_os" = "Windows" ]; then
665 vt_check_compatible_pe (loop)
666 uefi_windows_menu_func "$1" "${chosen_path}"
667 elif [ "$vtoy_os" = "Unix" ]; then
668 uefi_unix_menu_func "$1" "${chosen_path}"
670 uefi_linux_menu_func "$1" "${chosen_path}"
676 function uefi_iso_memdisk {
677 echo 'Loading ISO file to memory ...'
678 vt_load_img_memdisk "${1}${2}" vtoy_iso_buf
681 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
688 function legacy_windows_menu_func {
691 if [ "$ventoy_compatible" = "NO" ]; then
693 if [ "$ventoy_fs_probe" = "iso9660" ]; then
695 vt_iso9660_nojoliet 1
699 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
700 vt_windows_collect_wim_patch bcd (loop)/$file
703 distro_specify_wim_patch
705 vt_windows_count_wim_patch vt_wim_cnt
706 if [ $vt_wim_cnt -eq 0 ]; then
707 distro_specify_wim_patch_phase2
714 vt_windows_chain_data "${1}${chosen_path}"
717 if [ -n "$vtoy_chain_mem_addr" ]; then
718 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
719 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
722 echo "chain empty failed"
727 function legacy_linux_menu_func {
728 if [ "$ventoy_compatible" = "NO" ]; then
730 if [ "$ventoy_fs_probe" = "udf" ]; then
732 set ventoy_fs_probe=iso9660
736 vt_load_cpio $vtoy_path/ventoy.cpio "$2" "$1" "busybox=$ventoy_busybox_ver"
738 vt_linux_clear_initrd
740 if [ -d (loop)/pmagic ]; then
741 vt_linux_specify_initrd_file /pmagic/initrd.img
743 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
744 if [ -d (loop)/$dir ]; then
745 vt_linux_parse_initrd_isolinux (loop)/$dir/
750 # special process for special distros
752 if [ -d (loop)/arch/boot/syslinux ]; then
753 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
754 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
755 elif [ -d (loop)/anarchy/boot/syslinux ]; then
756 vt_linux_parse_initrd_isolinux (loop)/anarchy/boot/syslinux/ /anarchy/
759 elif [ -d (loop)/manjaro ]; then
760 if [ -e (loop)/boot/grub/kernels.cfg ]; then
761 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
763 elif [ -e (loop)/boot/grub/grub.cfg ]; then
764 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
767 distro_specify_initrd_file
769 vt_linux_initrd_count vtcount
770 if [ $vtcount -eq 0 ]; then
771 if [ -d (loop)/rancheros ]; then
772 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
775 distro_specify_initrd_file_phase2
781 vt_linux_chain_data "${1}${chosen_path}"
784 if [ -n "$vtoy_chain_mem_addr" ]; then
785 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
786 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
789 echo "chain empty failed"
795 function legacy_unix_menu_func {
796 ventoy_unix_comm_proc $1 "${chosen_path}"
798 if [ -n "$vtoy_chain_mem_addr" ]; then
799 #ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
800 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
803 echo "chain empty failed"
809 function legacy_iso_menu_func {
811 if [ -d (loop)/ ]; then
817 vt_select_auto_install "${chosen_path}"
818 vt_select_persistence "${chosen_path}"
820 if vt_is_udf "${1}${chosen_path}"; then
821 set ventoy_fs_probe=udf
823 set ventoy_fs_probe=iso9660
824 vt_iso9660_nojoliet 0
827 loopback loop "${1}${chosen_path}"
831 if [ -n "$vtcompat" ]; then
832 set ventoy_compatible=YES
834 elif vt_check_mode 1; then
835 set ventoy_compatible=YES
837 vt_check_compatible (loop)
840 vt_img_sector "${1}${chosen_path}"
842 if [ "$ventoy_fs_probe" = "iso9660" ]; then
843 vt_select_conf_replace "${1}" "${chosen_path}"
846 if [ "$vtoy_os" = "Windows" ]; then
847 vt_check_compatible_pe (loop)
848 legacy_windows_menu_func "$1" "${chosen_path}"
849 elif [ "$vtoy_os" = "Unix" ]; then
850 legacy_unix_menu_func "$1" "${chosen_path}"
852 legacy_linux_menu_func "$1" "${chosen_path}"
856 function legacy_iso_memdisk {
858 linux16 $vtoy_path/memdisk iso raw
859 echo "Loading ISO file to memory ..."
865 function iso_endless_os_proc {
866 if [ -d (loop)/ ]; then
870 loopback loop "${1}${2}"
871 vt_img_sector "${1}${2}"
873 vt_load_cpio $vtoy_path/ventoy.cpio "$2" "$1" "busybox=$ventoy_busybox_ver"
874 vt_trailer_cpio "$1" "$2" noinit
878 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
881 set ventoy_bls_bootdev=/boot
882 set ventoy_loading_tip="Loading files ......"
885 configfile (loop)/endless/grub/grub.cfg
888 unset ventoy_bls_bootdev
889 unset ventoy_loading_tip
895 function ventoy_iso_busybox_ver {
897 if [ "$VTOY_EFI_ARCH" = "aa64" ]; then
898 set ventoy_busybox_ver=a64
900 set ventoy_busybox_ver=32
902 #special process for deepin-live iso
903 if [ "$vt_chosen_size" = "403701760" ]; then
904 if vt_str_str "$vt_chosen_path" "/deepin-live"; then
905 set ventoy_busybox_ver=64
907 elif vt_str_begin "$vt_volume_id" "PHOTON_"; then
908 set ventoy_busybox_ver=64
909 elif vt_str_begin "$vt_volume_id" "smgl-test-quinq-x86_64"; then
910 set ventoy_busybox_ver=64
916 function iso_common_menuentry {
920 vt_chosen_img_path vt_chosen_path vt_chosen_size
921 vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id
923 if vt_check_password "${vt_chosen_path}"; then
927 if vt_str_begin "$vt_volume_id" "Avira"; then
928 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
931 ventoy_iso_busybox_ver
933 #special process for Endless OS
934 if vt_str_begin "$vt_volume_id" "Endless-OS"; then
935 iso_endless_os_proc $vtoy_iso_part "$vt_chosen_path"
936 elif vt_str_begin "$vt_volume_id" "TENS-Public"; then
940 if [ "$grub_platform" = "pc" ]; then
941 if vt_check_mode 0; then
942 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
944 legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
947 if vt_check_mode 0; then
948 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
950 uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
955 function miso_common_menuentry {
956 vt_chosen_img_path vt_chosen_path vt_chosen_size
958 if vt_check_password "${vt_chosen_path}"; then
962 echo "memdisk mode boot for $vt_chosen_path"
966 if [ "$grub_platform" = "pc" ]; then
967 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
969 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
974 function common_unsupport_menuentry {
975 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
976 echo -e " 文件名中不能有中文或空格 \n"
977 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
981 function miso_unsupport_menuentry {
982 common_unsupport_menuentry
985 function iso_unsupport_menuentry {
986 common_unsupport_menuentry
989 function wim_common_menuentry {
990 vt_chosen_img_path vt_chosen_path vt_chosen_size
992 if vt_check_password "${vt_chosen_path}"; then
996 if vt_wim_check_bootable "${vtoy_iso_part}${vt_chosen_path}"; then
997 vt_wim_chain_data "${vtoy_iso_part}${vt_chosen_path}"
999 echo -e "\n This is NOT a bootable WIM file. \n"
1000 echo -e " 这不是一个可启动的 WIM 文件。\n"
1005 if [ -n "$vtoy_chain_mem_addr" ]; then
1006 if [ "$grub_platform" = "pc" ]; then
1007 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1010 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1015 echo "chain empty failed"
1020 function wim_unsupport_menuentry {
1021 common_unsupport_menuentry
1024 function efi_common_menuentry {
1025 vt_chosen_img_path vt_chosen_path vt_chosen_size
1027 if vt_check_password "${vt_chosen_path}"; then
1031 vt_concat_efi_iso "${vtoy_iso_part}${vt_chosen_path}" vtoy_iso_buf
1037 unset vtoy_dotefi_retry
1038 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} dotefi isoefi=on ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
1041 if [ -n "$vtoy_dotefi_retry" ]; then
1042 unset vtoy_dotefi_retry
1043 chainloader "${vtoy_iso_part}${vt_chosen_path}"
1050 function efi_unsupport_menuentry {
1051 common_unsupport_menuentry
1054 function vhd_common_menuentry {
1056 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
1057 if [ "$vtoy_iso_fs" != "ntfs" ]; then
1058 echo -e "!!! WARNING !!!\n"
1059 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
1060 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
1061 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
1066 vt_chosen_img_path vt_chosen_path vt_chosen_size
1068 if vt_check_password "${vt_chosen_path}"; then
1072 vt_patch_vhdboot "$vt_chosen_path"
1076 if [ -n "$vtoy_vhd_buf_addr" ]; then
1077 if [ "$grub_platform" = "pc" ]; then
1078 linux16 $vtoy_path/memdisk iso raw
1079 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1083 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1088 echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
1093 function vhd_unsupport_menuentry {
1094 common_unsupport_menuentry
1097 function vtoyboot_common_func {
1101 vt_get_vtoy_type "${1}" vtoytype parttype AltBootPart
1103 if vt_str_begin $vtoytype vhd; then
1105 elif [ "$vtoytype" = "raw" ]; then
1107 elif [ "$vtoytype" = "vdi" ]; then
1111 if [ $vtoysupport -eq 1 ]; then
1112 if [ "$grub_platform" = "pc" ]; then
1113 if [ "$parttype" = "gpt" -a $AltBootPart -eq 0 ]; then
1114 echo "The OS in the vdisk was created in UEFI mode, but current is Legacy BIOS mode."
1115 echo "虚拟磁盘内的系统是在UEFI模式下创建的,而当前系统是Legacy BIOS模式,可能无法正常启动。"
1119 if [ "$parttype" = "mbr" -a $AltBootPart -eq 0 ]; then
1120 echo "The OS in the vdisk was created in Legacy BIOS mode, but current is UEFI mode."
1121 echo "虚拟磁盘内的系统是在Legacy BIOS模式下创建的,而当前系统是UEFI模式,可能无法正常启动。"
1126 vt_img_sector "${1}"
1127 vt_raw_chain_data "${1}"
1131 if [ -n "$vtoy_chain_mem_addr" ]; then
1132 if [ "$grub_platform" = "pc" ]; then
1133 vt_acpi_param ${vtoy_chain_mem_addr} 512
1134 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} bios80 sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1137 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
1139 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi sector512 env_param=${ventoy_env_param} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1144 echo "chain empty failed!"
1148 echo "Unsupported vtoy type $vtoytype"
1153 function vtoy_common_menuentry {
1154 vt_chosen_img_path vt_chosen_path vt_chosen_size
1156 if vt_check_password "${vt_chosen_path}"; then
1160 vtoyboot_common_func "${vtoy_iso_part}${vt_chosen_path}"
1163 function vtoy_unsupport_menuentry {
1164 common_unsupport_menuentry
1168 #============================================================#
1169 # IMG file boot process #
1170 #============================================================#
1174 function ventoy_img_easyos {
1175 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1176 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1178 loopback easysfs (vtimghd,1)/easy.sfs
1179 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1181 if [ -n "$vt_module_ver" ]; then
1182 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1183 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1190 vt_set_boot_opt rdinit=/vtoy/vtoy
1193 syslinux_configfile (vtimghd,1)/syslinux.cfg
1200 function ventoy_img_volumio {
1201 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1202 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1207 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1210 syslinux_configfile (vtimghd,1)/syslinux.cfg
1216 function ventoy_img_openelec {
1219 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1220 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1222 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1223 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1228 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1231 set root=(vtimghd,1)
1232 syslinux_configfile (vtimghd,1)/syslinux.cfg
1236 loopback -d vtloopex
1240 function ventoy_img_freedombox {
1241 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1242 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1244 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1245 if [ -n "$vt_module_ver" ]; then
1246 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1252 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1255 configfile (vtimghd,1)/boot/grub/grub.cfg
1261 function ventoy_img_paldo {
1262 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1263 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1268 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1271 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1272 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1274 echo loading file...
1275 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1276 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1283 function ventoy_img_ubos {
1284 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1285 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1287 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1288 if [ -n "$vt_module_ver" ]; then
1289 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1295 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1298 echo loading file...
1299 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1300 initrd (vtimghd,2)/initramfs-linux.img
1307 function ventoy_img_recalbox {
1308 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1309 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1314 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1317 set root=(vtimghd,1)
1318 configfile (vtimghd,1)/boot/grub/grub.cfg
1324 function ventoy_img_batocera {
1325 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1326 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1331 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1334 set root=(vtimghd,1)
1335 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1341 function ventoy_img_memtest86 {
1342 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
1346 function img_unsupport_tip {
1347 echo -e "\n This IMG file is NOT supported now. \n"
1348 echo -e " 当前不支持启动此 IMG 文件 \n"
1349 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1353 function img_common_menuentry {
1354 set ventoy_compatible=YES
1355 set ventoy_busybox_ver=32
1357 vt_chosen_img_path vt_chosen_path vt_chosen_size
1359 if vt_check_password "${vt_chosen_path}"; then
1363 if [ -d (vtimghd)/ ]; then
1367 loopback vtimghd "${vtoy_iso_part}${vt_chosen_path}"
1368 vt_img_sector "${vtoy_iso_part}${vt_chosen_path}"
1370 vt_img_part_info (vtimghd)
1372 set vtback_root=$root
1376 vt_img_extra_initrd_reset
1378 vt_get_fs_label (vtimghd,1) vtImgHd1Label
1379 if [ -d (vtimghd,2)/lib ]; then
1380 vt_get_fs_label (vtimghd,2) vtImgHd2Label
1383 if [ -e (vtimghd,1)/etc/hostname ]; then
1384 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
1387 if [ -e (vtimghd,1)/easy.sfs ]; then
1389 elif [ -e (vtimghd,1)/volumio.initrd ]; then
1391 elif vt_str_begin "$vtImgHd1Label" "LAKKA"; then
1392 ventoy_img_openelec lakka
1393 elif vt_str_begin "$vtImgHd1Label" "LIBREELEC"; then
1394 ventoy_img_openelec LibreELEC
1395 elif vt_str_begin "$vtImgHd1Label" "paldo-live"; then
1397 elif vt_str_begin "$vtImgHostname" "freedombox"; then
1398 ventoy_img_freedombox
1399 elif vt_str_begin "$vtImgHd1Label" "BATOCERA"; then
1401 elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
1403 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
1405 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
1406 if [ "$grub_platform" = "pc" ]; then
1409 ventoy_img_memtest86
1412 vt_linux_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1413 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
1414 if [ "$grub_platform" = "pc" ]; then
1415 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1418 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi sector512 env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1423 set root=$vtback_root
1426 set ventoy_compatible=NO
1429 function img_unsupport_menuentry {
1430 common_unsupport_menuentry
1433 #############################################################
1434 #############################################################
1435 #############################################################
1436 ####### Main Process ###########
1437 #############################################################
1438 #############################################################
1439 #############################################################
1441 set VENTOY_VERSION="1.0.30"
1443 #ACPI not compatible with Window7/8, so disable by default
1444 set VTOY_PARAM_NO_ACPI=1
1446 # Default menu display mode, you can change it as you want.
1449 set VTOY_DEFAULT_MENU_MODE=0
1451 set VTOY_MEM_DISK_STR="[Memdisk]"
1452 set VTOY_ISO_RAW_STR="Compatible Mode"
1453 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
1455 set VTOY_F2_CMD="ventoy_power"
1456 set VTOY_F4_CMD="ventoy_localboot"
1457 set VTOY_F5_CMD="ventoy_diagnosis"
1458 set VTOY_F6_CMD="ventoy_ext_menu"
1460 if [ "$grub_platform" = "pc" ]; then
1461 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1463 if [ "$grub_cpu" = "i386" ]; then
1464 set VTOY_EFI_ARCH=ia32
1465 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION IA32 www.ventoy.net"
1466 elif [ "$grub_cpu" = "arm64" ]; then
1467 set VTOY_EFI_ARCH=aa64
1468 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION AA64 www.ventoy.net"
1470 set VTOY_EFI_ARCH=x64
1471 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1475 vt_device $root vtoy_dev
1477 if [ "$vtoy_dev" = "tftp" ]; then
1478 set vtoy_path=($root)
1479 for vtid in 0 1 2 3; do
1480 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
1481 set vtoy_iso_part=(hd$vtid,1)
1482 set vtoy_efi_part=(hd$vtid,2)
1489 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1490 set vt_plugin_path=$vtoy_iso_part
1492 set vt_plugin_path=$prefix
1493 vt_load_plugin $vt_plugin_path
1496 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1497 set vtoy_path=(ventoydisk)/ventoy
1499 set vtoy_path=($root)/ventoy
1502 set vtoydev=$vtoy_dev
1503 set vtoy_iso_part=($vtoy_dev,1)
1504 set vtoy_efi_part=($vtoy_dev,2)
1506 set vt_plugin_path=$vtoy_iso_part
1509 #Load Partition Table
1510 vt_load_part_table $vtoydev
1513 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1515 vt_load_plugin $vtoy_iso_part
1519 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1520 set timeout=$VTOY_MENU_TIMEOUT
1525 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1526 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1527 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1528 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1531 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
1532 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
1533 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
1534 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
1538 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1539 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1540 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
1542 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1543 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Tools F6:ExMenu"
1547 if [ -n "$vtoy_gfxmode" ]; then
1548 set gfxmode=$vtoy_gfxmode
1551 set gfxmode=1024x768
1556 if [ "$vtoy_display_mode" = "CLI" ]; then
1557 terminal_output console
1558 elif [ "$vtoy_display_mode" = "serial" ]; then
1559 if [ -n "$vtoy_serial_param" ]; then
1560 serial $vtoy_serial_param
1562 terminal_input serial
1563 terminal_output serial
1564 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1565 if [ -n "$vtoy_serial_param" ]; then
1566 serial $vtoy_serial_param
1568 terminal_input serial console
1569 terminal_output serial console
1571 if [ -n "$vtoy_theme" ]; then
1572 set theme=$vtoy_theme
1574 set theme=$prefix/themes/ventoy/theme.txt
1576 terminal_output gfxterm
1580 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
1582 echo -e "\n Syntax error detected in ventoy.json, please check! \n"
1583 echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
1584 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
1588 #export necessary variable
1595 export vtoy_iso_part
1596 export vtoy_efi_part
1597 export VENTOY_VERSION
1598 export VTOY_CUR_VIDEO_MODE
1599 export VTOY_EFI_ARCH
1601 #special VTOY_DEFAULT_IMAGE process
1602 if [ -n "$VTOY_DEFAULT_IMAGE" ]; then
1603 if regexp --set 1:vtHotkey --set 2:vtDefault "(F[2-9])>(.*)" "$VTOY_DEFAULT_IMAGE"; then
1605 set default="$vtDefault"
1606 if [ -z "$VTOY_MENU_TIMEOUT" ]; then
1609 set timeout=$VTOY_MENU_TIMEOUT
1615 if [ "$vtHotkey" = "F2" ]; then
1617 elif [ "$vtHotkey" = "F4" ]; then
1619 elif [ "$vtHotkey" = "F5" ]; then
1621 elif [ "$vtHotkey" = "F6" ]; then
1630 #colect all image files (iso files)
1631 set ventoy_img_count=0
1632 vt_list_img $vtoy_iso_part ventoy_img_count
1635 if [ $ventoy_img_count -gt 0 ]; then
1636 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1642 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1643 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1644 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1645 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1647 NO_ISO_MENU="No ISO files found"
1649 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1650 echo -e "\n Rebooting ... "