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_vcfg_proc {
54 if vt_check_custom_boot "${1}" vt_vcfg; then
55 set vtoy_chosen_path="${1}"
56 vt_file_basefile "${vtoy_chosen_path}" vtoy_chosen_file
58 export vtoy_chosen_path
59 export vtoy_chosen_file
61 configfile "${vtoy_iso_part}${vt_vcfg}"
68 function ventoy_diagnosis {
70 configfile $prefix/debug.cfg
73 function ventoy_localboot {
74 configfile $prefix/localboot.cfg
77 function ventoy_ext_menu {
78 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
79 set ventoy_new_context=1
80 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
81 unset ventoy_new_context
83 echo "ventoy_grub.cfg NOT exist."
84 echo -e "\npress ENTER to exit ..."
89 function ventoy_checksum {
90 if [ -f "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}" ]; then
91 configfile $prefix/checksum.cfg
95 function ventoy_show_help {
96 if [ -f $prefix/help.tar.gz ]; then
97 if [ -z "$vtoy_help_txt_mem_addr" ]; then
98 vt_load_file_to_mem "auto" $prefix/help.tar.gz vtoy_help_txt_mem
101 loopback vt_help_tarfs mem:${vtoy_help_txt_mem_addr}:size:${vtoy_help_txt_mem_size}
102 if [ -f "(vt_help_tarfs)/help/${VTOY_HELP_TXT_LANGUAGE}.txt" ]; then
103 cat "(vt_help_tarfs)/help/${VTOY_HELP_TXT_LANGUAGE}.txt"
105 cat "(vt_help_tarfs)/help/en_US.txt"
107 loopback -d vt_help_tarfs
111 function get_os_type {
114 if vt_str_begin "$vt_volume_id" "DLC Boot"; then
115 if [ -f (loop)/DLCBoot.exe ]; then
119 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
120 if vt_file_exist_nocase (loop)/$file; then
127 if [ "$vtoy_os" = "Linux" ]; then
128 if vt_strstr "$vt_system_id" "FreeBSD"; then
130 set vt_unix_type=FreeBSD
131 elif [ -e (loop)/bin/freebsd-version ]; then
133 set vt_unix_type=FreeBSD
134 elif [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
136 set vt_unix_type=FreeBSD
137 elif vt_str_begin "$vt_system_id" "DragonFly"; then
139 set vt_unix_type=DragonFly
142 elif [ -e (loop)/boot/kernel/kernel ]; then
143 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
145 set vt_unix_type=FreeBSD
146 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
148 set vt_unix_type=NetBSD
153 if [ -n "${vtdebug_flag}" ]; then
154 echo ISO is "$vtoy_os"
158 function vt_check_compatible_pe {
159 #Check for PE without external tools
160 #set compatible if ISO file is less than 80MB
161 if [ $vt_chosen_size -GT 33554432 -a $vt_chosen_size -LE 83886080 ]; then
162 set ventoy_compatible=YES
168 function vt_check_compatible_linux {
169 if vt_str_begin "$vt_volume_id" "embootkit"; then
170 set ventoy_compatible=YES
171 elif [ -e "$1/casper/tinycore.gz" ]; then
172 set ventoy_compatible=YES
178 function locate_initrd {
179 vt_linux_locate_initrd
181 if [ -n "${vtdebug_flag}" ]; then
187 function locate_wim {
188 vt_windows_locate_wim_patch (loop) "$1"
190 if [ -n "${vtdebug_flag}" ]; then
191 echo '###############################################'
193 echo '###############################################'
198 function distro_specify_wim_patch {
199 if [ -d (loop)/h3pe ]; then
200 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
201 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
202 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
203 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
204 elif [ -d (loop)/2k10/winpe ]; then
205 vt_windows_collect_wim_patch wim /2k10/winpe/w1086pe.wim
206 vt_windows_collect_wim_patch wim /2k10/winpe/w8x86pe.wim
207 vt_windows_collect_wim_patch wim /2k10/winpe/w7x86pe.wim
211 function distro_specify_wim_patch_phase2 {
212 if [ -f (loop)/boot/boot.wim ]; then
213 vt_windows_collect_wim_patch wim /boot/boot.wim
216 if vt_str_begin "$vt_volume_id" "DLC Boot"; then
217 for vwfile in "/DLC1/WinPE/W11x64.wim" "/DLC1/WinPE/W10x64.wim" "/DLC1/WinPE/W10x86.wim"; do
218 if [ -f (loop)/$vwfile ]; then
219 vt_windows_collect_wim_patch wim $vwfile
227 function distro_specify_initrd_file {
228 if [ -e (loop)/boot/all.rdz ]; then
229 vt_linux_specify_initrd_file /boot/all.rdz
230 elif [ -e (loop)/boot/xen.gz ]; then
231 if [ -e (loop)/install.img ]; then
232 vt_linux_specify_initrd_file /install.img
234 elif [ -d (loop)/casper ]; then
235 if [ -e (loop)/casper/initrd ]; then
236 vt_linux_specify_initrd_file /casper/initrd
238 if [ -e (loop)/casper/initrd.gz ]; then
239 vt_linux_specify_initrd_file /casper/initrd.gz
241 if [ -e (loop)/casper/initrd-oem ]; then
242 vt_linux_specify_initrd_file /casper/initrd-oem
244 elif [ -e (loop)/boot/grub/initrd.xz ]; then
245 vt_linux_specify_initrd_file /boot/grub/initrd.xz
246 elif [ -e (loop)/initrd.gz ]; then
247 vt_linux_specify_initrd_file /initrd.gz
248 elif [ -e (loop)/slax/boot/initrfs.img ]; then
249 vt_linux_specify_initrd_file /slax/boot/initrfs.img
250 elif [ -e (loop)/minios/boot/initrfs.img ]; then
251 vt_linux_specify_initrd_file /minios/boot/initrfs.img
252 elif [ -e (loop)/pmagic/initrd.img ]; then
253 vt_linux_specify_initrd_file /pmagic/initrd.img
254 elif [ -e (loop)/boot/initrd.xz ]; then
255 vt_linux_specify_initrd_file /boot/initrd.xz
256 elif [ -e (loop)/boot/initrd.gz ]; then
257 vt_linux_specify_initrd_file /boot/initrd.gz
258 elif [ -f (loop)/boot/initrd ]; then
259 vt_linux_specify_initrd_file /boot/initrd
260 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
261 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
262 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
263 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
264 elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
265 vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
266 elif [ -f (loop)/boot/initrd.img ]; then
267 vt_linux_specify_initrd_file /boot/initrd.img
271 if [ -f (loop)/isolinux/initrd.gz ]; then
272 vt_linux_specify_initrd_file /isolinux/initrd.gz
275 if vt_str_begin "$vt_volume_id" "QUBES"; then
276 vt_linux_specify_initrd_file /images/pxeboot/initrd.img
279 if [ "$vt_chosen_size" = "1133375488" ]; then
280 if [ -d (loop)/boot/grub/x86_64-efi ]; then
281 vt_cpio_busybox64 "64h"
287 function distro_specify_initrd_file_phase2 {
288 if [ -f (loop)/boot/initrd.img ]; then
289 vt_linux_specify_initrd_file /boot/initrd.img
290 elif [ -f (loop)/Setup/initrd.gz ]; then
291 vt_linux_specify_initrd_file /Setup/initrd.gz
292 elif [ -f (loop)/isolinux/initramfs ]; then
293 vt_linux_specify_initrd_file /isolinux/initramfs
294 elif [ -f (loop)/boot/iniramfs.igz ]; then
295 vt_linux_specify_initrd_file /boot/iniramfs.igz
296 elif [ -f (loop)/initrd-x86_64 ]; then
297 vt_linux_specify_initrd_file /initrd-x86_64
298 elif [ -f (loop)/live/initrd.img ]; then
299 vt_linux_specify_initrd_file /live/initrd.img
300 elif [ -f (loop)/initrd.img ]; then
301 vt_linux_specify_initrd_file /initrd.img
302 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
303 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
304 elif [ -f (loop)/CDlinux/initrd ]; then
305 vt_linux_specify_initrd_file /CDlinux/initrd
306 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
307 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
308 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
309 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
311 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
312 vt_linux_specify_initrd_file /parabola/boot/x86_64/initramfs-linux-libre.img
313 if [ -f (loop)/parabola/boot/i686/initramfs-linux-libre.img ]; then
314 vt_linux_specify_initrd_file /parabola/boot/i686/initramfs-linux-libre.img
316 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
317 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
318 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
319 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
321 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
323 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
324 if [ "$grub_platform" != "pc" ]; then
325 vt_add_replace_file 0 "initrd.img"
327 elif [ -f (loop)/initrd ]; then
328 vt_linux_specify_initrd_file /initrd
329 elif [ -f (loop)/live/initrd1 ]; then
330 vt_linux_specify_initrd_file /live/initrd1
331 elif [ -f (loop)/isolinux/initrd.img ]; then
332 vt_linux_specify_initrd_file /isolinux/initrd.img
333 elif [ -f (loop)/isolinux/initrd.gz ]; then
334 vt_linux_specify_initrd_file /isolinux/initrd.gz
335 elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
336 vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
337 elif vt_strstr "$vt_volume_id" "Daphile"; then
338 vt_linux_parse_initrd_isolinux (loop)/isolinux/
339 elif [ -f (loop)/boot/rootfs.xz ]; then
340 vt_linux_specify_initrd_file /boot/rootfs.xz
341 if [ "$grub_platform" != "pc" ]; then
342 vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
344 elif [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
345 vt_linux_specify_initrd_file /arch/boot/x86_64/archiso.img
346 if [ "$grub_platform" != "pc" ]; then
347 vt_add_replace_file 0 "EFI\\archiso\\archiso.img"
349 elif [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
350 vt_linux_specify_initrd_file /blackarch/boot/x86_64/archiso.img
351 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
352 vt_linux_specify_initrd_file /blackarch/boot/x86_64/initramfs-linux.img
354 elif [ -f (loop)/install.amd/initrd.gz ]; then
355 vt_linux_specify_initrd_file /live/initrd2.img
356 vt_linux_specify_initrd_file /install.amd/initrd.gz
357 vt_linux_specify_initrd_file /install.amd/gtk/initrd.gz
358 elif [ -f (loop)/boot/grub/kernels.cfg ]; then
359 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
360 elif [ -f (loop)/austrumi/initrd.gz ]; then
361 vt_linux_specify_initrd_file /austrumi/initrd.gz
362 if [ -f (loop)/EFI/BOOT/bootx64.efi ]; then
363 vt_cpio_busybox64 "64h"
365 elif [ -f (loop)/boot/initfs.x86_64-efi ]; then
366 vt_linux_specify_initrd_file /boot/initfs.x86_64-efi
367 if [ -f (loop)/boot/initfs.i386-pc ]; then
368 vt_linux_specify_initrd_file /boot/initfs.i386-pc
370 elif [ -f (loop)/antiX/initrd.gz ]; then
371 vt_linux_specify_initrd_file /antiX/initrd.gz
372 elif [ -f (loop)/360Disk/initrd.gz ]; then
373 vt_linux_specify_initrd_file /360Disk/initrd.gz
374 elif [ -f (loop)/porteus/initrd.xz ]; then
375 vt_linux_specify_initrd_file /porteus/initrd.xz
376 elif [ -f (loop)/pyabr/boot/initrfs.img ]; then
377 vt_linux_specify_initrd_file /pyabr/boot/initrfs.img
378 elif [ -f (loop)/initrd0.img ]; then
379 vt_linux_specify_initrd_file /initrd0.img
380 elif [ -f (loop)/sysresccd/boot/i686/sysresccd.img ]; then
381 vt_linux_specify_initrd_file /sysresccd/boot/i686/sysresccd.img
382 elif [ -f (loop)/boot/full.cz ]; then
383 vt_linux_specify_initrd_file /boot/full.cz
384 elif [ -f (loop)/images/pxeboot/initrd.img ]; then
385 vt_linux_specify_initrd_file /images/pxeboot/initrd.img
390 function ventoy_get_ghostbsd_ver {
391 # fallback to parse version from elf /boot/kernel/kernel
392 set vt_freebsd_ver=xx
395 function ventoy_get_furybsd_ver {
396 if regexp "13\.[0-9]" "$2"; then
397 set vt_freebsd_ver=13.x
399 set vt_freebsd_ver=12.x
403 function ventoy_get_freenas_ver {
404 set vt_freebsd_ver=11.x
406 if [ -e (loop)/FreeNAS-MANIFEST ]; then
407 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
408 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
409 set vt_freebsd_ver=13.x
410 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
411 set vt_freebsd_ver=12.x
412 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
413 set vt_freebsd_ver=11.x
418 function ventoy_get_truenas_ver {
419 set vt_freebsd_ver=12.x
421 if [ -e (loop)/TrueNAS-MANIFEST ]; then
422 vt_parse_freenas_ver (loop)/TrueNAS-MANIFEST vt_truenas_ver
423 if regexp "^13\.[0-9]" "$vt_truenas_ver"; then
424 set vt_freebsd_ver=13.x
425 elif regexp "^12\.[0-9]" "$vt_truenas_ver"; then
426 set vt_freebsd_ver=12.x
427 elif regexp "^11\.[0-9]" "$vt_truenas_ver"; then
428 set vt_freebsd_ver=11.x
433 function ventoy_get_midnightbsd_ver {
434 if vt_str_begin "$vt_volume_id" "1_"; then
435 set vt_freebsd_ver=11.x
436 elif vt_str_begin "$vt_volume_id" "2_"; then
437 set vt_freebsd_ver=2.x
438 elif vt_str_begin "$vt_volume_id" "3_"; then
439 set vt_freebsd_ver=3.x
443 function ventoy_freebsd_proc {
444 set vtFreeBsdDistro=FreeBSD
445 set vt_freebsd_ver=xx
447 if [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
448 vt_unix_ko_fillmap /boot/kernel/geom_ventoy.ko
452 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
453 ventoy_get_ghostbsd_ver "$1" "${chosen_path}"
454 elif vt_strstr "$vt_volume_id" "FREENAS"; then
455 ventoy_get_freenas_ver "$1" "${chosen_path}"
456 elif vt_strstr "$vt_volume_id" "TRUENAS"; then
457 ventoy_get_truenas_ver "$1" "${chosen_path}"
458 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
459 ventoy_get_furybsd_ver "$1" "${chosen_path}"
460 elif regexp "^13_[0-9]" "$vt_volume_id"; then
461 set vt_freebsd_ver=13.x
462 elif regexp "^12_[0-9]" "$vt_volume_id"; then
463 set vt_freebsd_ver=12.x
464 elif regexp "^11_[0-9]" "$vt_volume_id"; then
465 set vt_freebsd_ver=11.x
466 elif regexp "^10_[0-9]" "$vt_volume_id"; then
467 set vt_freebsd_ver=10.x
468 elif regexp "^9_[0-9]" "$vt_volume_id"; then
469 set vt_freebsd_ver=9.x
470 elif [ -d (loop)/usr/midnightbsd-dist ]; then
471 ventoy_get_midnightbsd_ver "$1" "${chosen_path}"
472 set vtFreeBsdDistro=MidnightBSD
473 elif [ -e (loop)/bin/freebsd-version ]; then
474 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
475 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
476 set vt_freebsd_ver=13.x
477 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
478 set vt_freebsd_ver=12.x
479 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
480 set vt_freebsd_ver=11.x
481 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
482 set vt_freebsd_ver=10.x
483 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
484 set vt_freebsd_ver=9.x
486 elif [ -e (loop)/README.TXT ]; then
487 vt_1st_line (loop)/README.TXT vt_freebsd_line1
488 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
489 set vt_freebsd_ver=13.x
490 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
491 set vt_freebsd_ver=12.x
492 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
493 set vt_freebsd_ver=11.x
494 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
495 set vt_freebsd_ver=10.x
496 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
497 set vt_freebsd_ver=9.x
499 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
500 set vt_freebsd_ver=9.x
504 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
505 set vtFreeBsdDistro=ClonOS
508 set vt_freebsd_bit=64
509 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
510 if [ -e (loop)/$file ]; then
511 if file --is-i386-kfreebsd (loop)/$file; then
512 set vt_freebsd_bit=32
518 if [ "$vt_freebsd_ver" = "xx" ]; then
519 if [ -e (loop)/boot/kernel/kernel ]; then
520 vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel $vt_freebsd_bit vt_freebsd_ver
521 elif [ -e (loop)/boot/kernel/kernel.gz ]; then
522 vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel.gz $vt_freebsd_bit vt_freebsd_ver
525 if [ "$vt_freebsd_ver" = "xx" ]; then
526 set vt_freebsd_ver=13.x
530 if [ -n "${vtdebug_flag}" ]; then
531 echo "This is $vtFreeBsdDistro $vt_freebsd_ver ${vt_freebsd_bit}bit"
534 unset vt_unix_mod_path
535 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/TrueNAS-MANIFEST" "/version" "/etc/fstab"; do
536 if [ -e (loop)${file} ]; then
537 set vt_unix_mod_path=${file}
542 if [ -n "$vt_unix_mod_path" ]; then
543 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
544 vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
545 elif [ -e (loop)/easyre.ufs.uzip ]; then
546 vt_unix_replace_ko "/boot/grub/i386-pc/linux.mod" (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
547 if [ "$grub_platform" = "pc" ]; then
548 vt_unix_replace_grub_conf "/boot/grub/i386-pc/linux.mod" "cd9"
550 vt_unix_replace_conf FreeBSD "${1}${chosen_path}" "cd9"
555 function ventoy_dragonfly_proc {
557 unset vt_unix_mod_path
558 for file in "/boot/kernel/initrd.img.gz"; do
559 if [ -e (loop)${file} ]; then
560 set vt_unix_mod_path=${file}
565 vt_unix_replace_ko $vt_unix_mod_path ${vtoy_path}/dragonfly.mfs.xz
566 vt_unix_fill_image_desc
568 vt_unix_replace_conf DragonFly "${1}${chosen_path}"
571 function ventoy_unix_comm_proc {
574 vt_unix_check_vlnk "${1}${chosen_path}"
576 if [ "$ventoy_compatible" = "NO" ]; then
577 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
579 if [ "$vt_unix_type" = "FreeBSD" ]; then
580 ventoy_freebsd_proc "$1" "${chosen_path}"
581 elif [ "$vt_unix_type" = "DragonFly" ]; then
582 ventoy_dragonfly_proc "$1" "${chosen_path}"
583 elif [ "$vt_unix_type" = "NetBSD" ]; then
584 echo "NetBSD not supported"
588 if [ -n "${vtdebug_flag}" ]; then
589 echo "Unknown unix type"
594 vt_unix_chain_data "${1}${chosen_path}"
599 function uefi_windows_menu_func {
602 if vt_check_mode 4 "$vt_chosen_name"; then
603 vt_windows_chain_data "${1}${chosen_path}"
607 if [ "$ventoy_compatible" = "NO" ]; then
609 if [ "$ventoy_fs_probe" = "iso9660" ]; then
611 vt_iso9660_nojoliet 1
615 for file in "efi/microsoft/boot/bcd"; do
616 vt_windows_collect_wim_patch bcd (loop)/$file
619 vt_windows_count_wim_patch vt_wim_cnt
620 if [ $vt_wim_cnt -eq 0 ]; then
621 distro_specify_wim_patch_phase2
625 locate_wim "${chosen_path}"
627 vt_windows_chain_data "${1}${chosen_path}"
631 if [ -n "$vtoy_chain_mem_addr" ]; then
632 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
634 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}
637 echo "chain empty failed"
642 function uefi_find_replace_initrd {
643 if vt_get_efi_vdisk_offset "${1}${2}" vt_efivdisk_offset; then
644 loopback -s $vt_efivdisk_offset vtefivdisk "${1}${2}"
647 vt_search_replace_initrd (vtefivdisk) vt_rp_initrd
649 if [ -n "$vt_rp_initrd" ]; then
650 vt_add_replace_file $3 "$vt_rp_initrd"
653 loopback -d vtefivdisk
658 function uefi_linux_menu_func {
660 if [ "$ventoy_compatible" = "NO" ]; then
662 if [ "$ventoy_fs_probe" = "udf" ]; then
664 set ventoy_fs_probe=iso9660
668 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
670 vt_linux_clear_initrd
672 if [ -d (loop)/pmagic ]; then
673 vt_linux_specify_initrd_file /pmagic/initrd.img
675 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
676 if [ -e (loop)/$file ]; then
677 vt_linux_parse_initrd_grub file (loop)/$file
682 # special process for special distros
683 if [ -d (loop)/loader/entries ]; then
684 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
685 elif [ -d (loop)/boot/grub ]; then
686 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
689 distro_specify_initrd_file
691 vt_linux_initrd_count vtcount
693 if [ $vtcount -eq 0 ]; then
694 if [ -e (loop)/EFI/boot/livegrub.cfg ]; then
695 vt_linux_parse_initrd_grub file (loop)/EFI/boot/livegrub.cfg
697 distro_specify_initrd_file_phase2
699 if [ "$vt_efi_dir" = "NO" ]; then
700 if [ -f (loop)/efi.img ]; then
701 vt_add_replace_file 0 "initrd"
708 if [ -d (loop)/loader/entries ]; then
709 vt_linux_get_main_initrd_index vtindex
711 if [ -d (loop)/arch ]; then
712 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
713 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
714 elif [ -f (loop)/arch/boot/x86_64/initramfs-linux.img ]; then
715 vt_add_replace_file $vtindex "arch\\boot\\x86_64\\initramfs-linux.img"
716 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
717 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
719 elif [ -d (loop)/blackarch ]; then
720 if [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
721 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
722 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
723 vt_add_replace_file $vtindex "blackarch\\boot\\x86_64\\initramfs-linux.img"
725 elif [ -d (loop)/anarchy ]; then
726 if [ -f (loop)/anarchy/boot/x86_64/initramfs-linux.img ]; then
727 vt_add_replace_file $vtindex "anarchy\\boot\\x86_64\\initramfs-linux.img"
729 elif [ -d (loop)/parabola ]; then
730 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
731 vt_add_replace_file $vtindex "EFI\\parabolaiso\\parabolaiso.img"
732 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
733 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
735 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
736 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
737 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
738 vt_add_replace_file $vtindex "boot\\initrd"
739 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
740 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
743 vt_get_replace_file_cnt vt_replace_cnt
744 if [ $vt_replace_cnt -eq 0 ]; then
745 uefi_find_replace_initrd "$1" "$2" $vtindex
747 elif [ -d (loop)/EFI/boot/entries ]; then
748 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
749 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
750 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
751 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
753 elif [ -d (loop)/EFI/BOOT/entries ]; then
754 vt_linux_get_main_initrd_index vtindex
756 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
757 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
758 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
759 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
761 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
762 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
763 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
765 elif vt_str_begin "$vt_volume_id" "SolusLive"; then
766 vt_add_replace_file 0 "initrd"
772 vt_linux_chain_data "${1}${chosen_path}"
774 if [ -n "$LoadIsoEfiDriver" -a $vt_chosen_size -LT 104857600 ]; then
775 if [ -f (loop)/efi/clover/cloverx64.efi ]; then
776 unset LoadIsoEfiDriver
780 if [ -n "$vtoy_chain_mem_addr" ]; then
781 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
785 if vt_check_mode 3 "$vt_chosen_name"; then
787 elif vt_str_begin "$vt_volume_id" "KRD"; then
788 if [ -f (loop)/boot/grub/grub.cfg.sig ]; then
793 if [ -n "$vtGrub2Mode" ]; then
796 if [ "$VTOY_EFI_ARCH" != "mips" ]; then
797 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi fallback env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
803 set vtback_root=$root
805 set vtback_theme=$theme
808 vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
809 vt_set_boot_opt rdinit=/vtoy/vtoy
812 set vtback_cfg_find=0
813 for cfg in "/boot/grub/grub.cfg" "/EFI/BOOT/grub.cfg" "/EFI/debian/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "/grub/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
814 if [ -e "$cfg" ]; then
815 set vtback_cfg_find=1
821 if [ "$vtback_cfg_find" = "0" ]; then
823 echo "No bootfile found for UEFI!"
824 echo "Maybe the image does not support $VTOY_EFI_ARCH UEFI"
830 set root=$vtback_root
831 set theme=$vtback_theme
835 echo "chain empty failed"
840 function uefi_unix_menu_func {
841 ventoy_unix_comm_proc $1 "${chosen_path}"
843 if [ -n "$vtoy_chain_mem_addr" ]; then
844 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
846 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}
849 echo "chain empty failed"
854 function ventoy_reset_nojoliet {
855 if vt_str_begin "$vt_volume_id" "ARCARESCUE"; then
856 vt_iso9660_nojoliet 1
858 vt_iso9660_nojoliet 0
861 vt_append_extra_sector 0
864 function uefi_iso_menu_func {
866 if [ -d (loop)/ ]; then
870 if [ -n "$vtisouefi" ]; then
871 set LoadIsoEfiDriver=on
873 elif vt_check_mode 2 "$vt_chosen_name"; then
874 set LoadIsoEfiDriver=on
876 unset LoadIsoEfiDriver
880 vt_select_auto_install "${chosen_path}"
881 vt_select_persistence "${chosen_path}"
883 if vt_is_udf "${1}${chosen_path}"; then
884 set ventoy_fs_probe=udf
886 set ventoy_fs_probe=iso9660
887 ventoy_reset_nojoliet
889 # Lenovo EasyStartup need an addional sector for boundary check
890 if vt_str_begin "$vt_volume_id" "EasyStartup"; then
891 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
892 vt_append_extra_sector 1
896 loopback loop "${1}${chosen_path}"
899 if [ -d (loop)/EFI ]; then
901 elif [ -d (loop)/efi ]; then
907 if [ -n "$vtcompat" ]; then
908 set ventoy_compatible=YES
910 elif vt_check_mode 1 "$vt_chosen_name"; then
911 set ventoy_compatible=YES
913 vt_check_compatible (loop)
916 vt_img_sector "${1}${chosen_path}"
918 if [ "$ventoy_fs_probe" = "iso9660" ]; then
919 vt_select_conf_replace "${1}" "${chosen_path}"
922 if [ "$vtoy_os" = "Windows" ]; then
923 vt_check_compatible_pe (loop)
924 uefi_windows_menu_func "$1" "${chosen_path}"
925 elif [ "$vtoy_os" = "Unix" ]; then
926 uefi_unix_menu_func "$1" "${chosen_path}"
928 vt_check_compatible_linux (loop)
929 uefi_linux_menu_func "$1" "${chosen_path}"
935 function uefi_iso_memdisk {
936 echo 'Loading ISO file to memory ...'
937 vt_load_img_memdisk "${1}${2}" vtoy_iso_buf
940 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}
946 function vtoy_windows_wimboot {
947 if [ -f (loop)/x86/sources/boot.wim -a -f (loop)/x64/sources/boot.wim ]; then
948 vt_sel_wimboot vtoy_wimboot_bit
949 if [ "$vtoy_wimboot_bit" = "32" ]; then
950 set vtoy_wimboot_prefix=(loop)/x86
952 set vtoy_wimboot_prefix=(loop)/x64
955 set vtoy_wimboot_prefix=(loop)
956 if vt_is_pe64 $vtoy_wimboot_prefix/setup.exe; then
957 set vtoy_wimboot_bit=64
959 set vtoy_wimboot_bit=32
963 if [ -n "${vtdebug_flag}" ]; then
964 echo vtoy_wimboot_prefix=$vtoy_wimboot_prefix vtoy_wimboot_bit=$vtoy_wimboot_bit vt_wimkernel=$vt_wimkernel
967 for wmfile in sources/boot.wim boot/bcd boot/boot.sdi; do
968 if [ ! -f $vtoy_wimboot_prefix/$wmfile ]; then
973 if [ -f $vtoy_wimboot_prefix/sources/install.wim -o -f $vtoy_wimboot_prefix/sources/install.esd ]; then
974 vt_windows_wimboot_data "$vtoy_wimboot_prefix/sources/boot.wim" vtoy_init_exe
979 if [ "$grub_platform" = "pc" ]; then
980 linux16 "$vtoy_path/$vt_wimkernel" quiet
983 vt_set_wim_load_prompt 1 "Loading files......"
984 initrd16 newc:winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
985 newc:vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd \
986 newc:bcd:$vtoy_wimboot_prefix/boot/bcd \
987 newc:boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi \
988 newc:boot.wim:$vtoy_wimboot_prefix/sources/boot.wim
989 vt_set_wim_load_prompt 0
992 vt_set_wim_load_prompt 1 "Loading files......"
993 vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/sources/boot.wim vtoy_wimfile_mem
994 vt_set_wim_load_prompt 0
996 if [ $? -eq 0 ]; then
997 set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
999 set vtoy_wimfile_path=$vtoy_wimboot_prefix/sources/boot.wim
1003 chainloader "$vtoy_path/$vt_wimkernel" quiet \
1004 "vf=winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
1005 "vf=vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd" \
1006 "vf=bcd:$vtoy_wimboot_prefix/boot/bcd" \
1007 "vf=boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi" \
1008 "vf=boot.wim:$vtoy_wimfile_path" \
1009 pfsize=$vtoy_chain_file_size \
1010 pfread=$vtoy_chain_file_read
1016 function vtoy_winpe_wimboot {
1017 unset vtoy_boot_mgr_exe
1018 unset vtoy_boot_mgr_efi
1019 set vtoy_wimboot_prefix=(loop)
1020 set vtoy_bcd_path="$1"
1021 set vtoy_sdi_path="$2"
1022 set vtoy_wim_path="$3"
1023 set vtoy_mgr_flag="$4"
1025 if [ $vtoy_mgr_flag -eq 1 ]; then
1026 set vtoy_boot_mgr_exe="newc:bootmgr.exe:$vtoy_wimboot_prefix/$5"
1027 elif [ $vtoy_mgr_flag -eq 2 ]; then
1028 set vtoy_boot_mgr_efi="vf=bootmgr.efi:$vtoy_wimboot_prefix/$5"
1029 elif [ $vtoy_mgr_flag -eq 3 ]; then
1030 set vtoy_boot_mgr_exe="newc:bootmgr.exe:$vtoy_wimboot_prefix/$5"
1031 set vtoy_boot_mgr_efi="vf=bootmgr.efi:$vtoy_wimboot_prefix/$6"
1034 vt_windows_wimboot_data $vtoy_wimboot_prefix/$vtoy_wim_path vtoy_init_exe
1036 if [ "$grub_platform" = "pc" ]; then
1037 linux16 "$vtoy_path/$vt_wimkernel" quiet
1040 vt_set_wim_load_prompt 1 "Loading files......"
1041 initrd16 newc:$vtoy_init_exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
1042 $vtoy_boot_mgr_exe \
1043 newc:vtoy_wimboot:$vtoy_wimboot_prefix/$vtoy_bcd_path \
1044 newc:bcd:$vtoy_wimboot_prefix/$vtoy_bcd_path \
1045 newc:boot.sdi:$vtoy_wimboot_prefix/$vtoy_sdi_path \
1046 newc:boot.wim:$vtoy_wimboot_prefix/$vtoy_wim_path
1047 vt_set_wim_load_prompt 0
1050 vt_set_wim_load_prompt 1 "Loading files......"
1051 vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/$vtoy_wim_path vtoy_wimfile_mem
1052 vt_set_wim_load_prompt 0
1054 if [ $? -eq 0 ]; then
1055 set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
1057 set vtoy_wimfile_path=$vtoy_wimboot_prefix/$vtoy_wim_path
1061 chainloader "$vtoy_path/$vt_wimkernel" quiet \
1062 "vf=$vtoy_init_exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
1063 "vf=vtoy_wimboot:$vtoy_wimboot_prefix/$vtoy_bcd_path" \
1064 "$vtoy_boot_mgr_efi" \
1065 "vf=bcd:$vtoy_wimboot_prefix/$vtoy_bcd_path" \
1066 "vf=boot.sdi:$vtoy_wimboot_prefix/$vtoy_sdi_path" \
1067 "vf=boot.wim:$vtoy_wimfile_path" \
1068 pfsize=$vtoy_chain_file_size \
1069 pfread=$vtoy_chain_file_read
1075 function vtoy_wimboot_func {
1076 echo -e "\n===================== VENTOY WIMBOOT ===================\n"
1078 if [ "$grub_platform" = "pc" ]; then
1079 set vt_wimkernel=wimboot.x86_64.xz
1081 if [ "$grub_cpu" = "i386" ]; then
1082 set vt_wimkernel=wimboot.i386.efi.xz
1084 set vt_wimkernel=wimboot.x86_64.xz
1088 if vt_str_begin "$vt_volume_id" "Modified-Win10PEx64"; then
1089 vtoy_winpe_wimboot 'Boot/bcd' 'Boot/boot.sdi' 'sources/boot.wim' 1 'bootmgr.exe'
1091 vtoy_windows_wimboot
1095 function legacy_windows_menu_func {
1098 if vt_check_mode 4 "$vt_chosen_name"; then
1099 vt_windows_chain_data "${1}${chosen_path}"
1103 if [ "$ventoy_compatible" = "NO" ]; then
1105 if [ "$ventoy_fs_probe" = "iso9660" ]; then
1107 vt_iso9660_nojoliet 1
1108 loopback loop "$1$2"
1111 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD" "boot/bce"; do
1112 vt_windows_collect_wim_patch bcd (loop)/$file
1115 distro_specify_wim_patch
1117 vt_windows_count_wim_patch vt_wim_cnt
1118 if [ $vt_wim_cnt -eq 0 ]; then
1119 distro_specify_wim_patch_phase2
1123 locate_wim "${chosen_path}"
1126 vt_windows_chain_data "${1}${chosen_path}"
1130 if [ -n "$vtoy_chain_mem_addr" ]; then
1131 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1132 if [ "$ventoy_compatible" = "NO" ]; then
1133 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1135 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1139 echo "chain empty failed"
1144 function legacy_linux_menu_func {
1145 if [ "$ventoy_compatible" = "NO" ]; then
1147 if [ "$ventoy_fs_probe" = "udf" ]; then
1149 set ventoy_fs_probe=iso9660
1150 loopback loop "$1$2"
1154 if vt_syslinux_need_nojoliet "$1$2"; then
1155 vt_iso9660_nojoliet 1
1157 loopback loop "$1$2"
1160 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
1162 vt_linux_clear_initrd
1164 if [ -d (loop)/pmagic ]; then
1165 vt_linux_specify_initrd_file /pmagic/initrd.img
1167 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
1168 if [ -d (loop)/$dir ]; then
1169 vt_linux_parse_initrd_isolinux (loop)/$dir/
1174 # special process for special distros
1176 if [ -d (loop)/arch/boot/syslinux ]; then
1177 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
1178 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
1179 elif [ -d (loop)/anarchy/boot/syslinux ]; then
1180 vt_linux_parse_initrd_isolinux (loop)/anarchy/boot/syslinux/ /anarchy/
1183 elif [ -d (loop)/manjaro ]; then
1184 if [ -e (loop)/boot/grub/kernels.cfg ]; then
1185 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
1187 elif [ -e (loop)/boot/grub/grub.cfg ]; then
1188 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
1191 distro_specify_initrd_file
1193 vt_linux_initrd_count vtcount
1194 if [ $vtcount -eq 0 ]; then
1195 if [ -d (loop)/rancheros ]; then
1196 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
1199 distro_specify_initrd_file_phase2
1205 vt_linux_chain_data "${1}${chosen_path}"
1208 if [ -n "$vtoy_chain_mem_addr" ]; then
1209 if vt_check_mode 3 "$vt_chosen_name"; then
1210 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1214 set vtback_root=$root
1216 set vtback_theme=$theme
1219 vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
1220 vt_set_boot_opt rdinit=/vtoy/vtoy
1223 set vtback_cfg_find=0
1224 for cfg in "/boot/grub/grub.cfg" "/EFI/BOOT/grub.cfg" "/EFI/debian/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "/grub/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
1225 if [ -e "$cfg" ]; then
1226 set vtback_cfg_find=1
1233 set root=$vtback_root
1234 set theme=$vtback_theme
1238 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1239 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1243 echo "chain empty failed"
1249 function legacy_unix_menu_func {
1250 ventoy_unix_comm_proc $1 "${chosen_path}"
1252 if [ -n "$vtoy_chain_mem_addr" ]; then
1253 #ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1254 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1257 echo "chain empty failed"
1263 function legacy_iso_menu_func {
1265 if [ -d (loop)/ ]; then
1269 set chosen_path="$2"
1271 vt_select_auto_install "${chosen_path}"
1272 vt_select_persistence "${chosen_path}"
1274 if vt_is_udf "${1}${chosen_path}"; then
1275 set ventoy_fs_probe=udf
1277 set ventoy_fs_probe=iso9660
1278 ventoy_reset_nojoliet
1281 loopback loop "${1}${chosen_path}"
1285 if [ -n "$vtcompat" ]; then
1286 set ventoy_compatible=YES
1288 elif vt_check_mode 1 "$vt_chosen_name"; then
1289 set ventoy_compatible=YES
1291 vt_check_compatible (loop)
1294 vt_img_sector "${1}${chosen_path}"
1296 if [ "$ventoy_fs_probe" = "iso9660" ]; then
1297 vt_select_conf_replace "${1}" "${chosen_path}"
1300 if [ "$vtoy_os" = "Windows" ]; then
1301 vt_check_compatible_pe (loop)
1302 legacy_windows_menu_func "$1" "${chosen_path}"
1303 elif [ "$vtoy_os" = "Unix" ]; then
1304 legacy_unix_menu_func "$1" "${chosen_path}"
1306 vt_check_compatible_linux (loop)
1307 legacy_linux_menu_func "$1" "${chosen_path}"
1311 function legacy_iso_memdisk {
1313 linux16 $vtoy_path/memdisk iso raw
1314 echo "Loading ISO file to memory ..."
1320 function iso_endless_os_proc {
1321 if [ -d (loop)/ ]; then
1325 loopback loop "${1}${2}"
1326 vt_img_sector "${1}${2}"
1328 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
1329 vt_trailer_cpio "$1" "$2" noinit
1333 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
1336 set ventoy_bls_bootdev=/boot
1337 set ventoy_loading_tip="Loading files ......"
1340 configfile (loop)/endless/grub/grub.cfg
1343 unset ventoy_bls_bootdev
1344 unset ventoy_loading_tip
1350 function ventoy_iso_busybox_ver {
1352 if [ "$VTOY_EFI_ARCH" = "aa64" ]; then
1353 set ventoy_busybox_ver=a64
1354 elif [ "$VTOY_EFI_ARCH" = "mips" ]; then
1355 set ventoy_busybox_ver=m64
1357 set ventoy_busybox_ver=32
1359 #special process for deepin-live iso
1360 if [ "$vt_chosen_size" = "403701760" ]; then
1361 if vt_str_str "$vt_chosen_path" "/deepin-live"; then
1362 set ventoy_busybox_ver=64
1364 elif vt_str_begin "$vt_volume_id" "PHOTON_"; then
1365 set ventoy_busybox_ver=64
1366 elif vt_str_begin "$vt_volume_id" "smgl-test-quinq-x86_64"; then
1367 set ventoy_busybox_ver=64
1368 elif vt_str_begin "$vt_volume_id" "LDiagBootable"; then
1369 set ventoy_busybox_ver=64
1376 function iso_common_menuentry {
1380 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1382 vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id vt_volume_space
1383 if [ $vt_volume_space -NE $vt_chosen_size ]; then
1384 vt_mod $vt_chosen_size 2048 vt_chosen_size_mod
1385 if [ $vt_chosen_size_mod -ne 0 ]; then
1386 echo -e "\n $vt_volume_space $vt_chosen_size $vt_chosen_size_mod\n"
1387 echo -e "\n The size of the iso file \"$vt_chosen_size\" is invalid. File corrupted ?\n"
1388 echo -e " 此ISO文件的大小 \"$vt_chosen_size\" 有问题,请确认文件是否损坏。\n"
1389 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
1394 if vt_check_password "${vt_chosen_path}"; then
1398 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1402 if vt_str_begin "$vt_volume_id" "Avira"; then
1403 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
1406 ventoy_iso_busybox_ver
1408 #special process for Endless OS
1409 if vt_str_begin "$vt_volume_id" "Endless-OS"; then
1410 iso_endless_os_proc $vtoy_iso_part "$vt_chosen_path"
1411 elif vt_str_begin "$vt_volume_id" "TENS-Public"; then
1416 # auto memdisk mode for some special ISO files
1417 vt_iso_vd_id_parse "${vtoy_iso_part}${vt_chosen_path}"
1419 if vt_check_mode 0 "$vt_chosen_name"; then
1422 if [ "$grub_platform" = "pc" ]; then
1423 if vt_iso_vd_id_begin 1 0 "Memtest86+"; then
1425 elif vt_iso_vd_id_begin 0 1 "KolibriOS"; then
1431 if [ $vt_chosen_size -LE 67108864 ]; then
1432 if vt_str_begin "$vt_chosen_name" "iKuai"; then
1440 if [ "$grub_platform" = "pc" ]; then
1441 if [ -n "$vtMemDiskBoot" ]; then
1442 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1444 legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
1447 if [ -n "$vtMemDiskBoot" ]; then
1448 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1450 uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
1455 function miso_common_menuentry {
1456 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1458 if vt_check_password "${vt_chosen_path}"; then
1462 echo "memdisk mode boot for $vt_chosen_path"
1466 if [ "$grub_platform" = "pc" ]; then
1467 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1469 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1474 function common_unsupport_menuentry {
1475 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
1476 echo -e " 文件名中不能有中文或空格 \n"
1477 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1481 function miso_unsupport_menuentry {
1482 common_unsupport_menuentry
1485 function iso_unsupport_menuentry {
1486 common_unsupport_menuentry
1489 function wim_common_menuentry {
1490 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1492 if vt_check_password "${vt_chosen_path}"; then
1496 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1500 if vt_wim_check_bootable "${vtoy_iso_part}${vt_chosen_path}"; then
1501 vt_wim_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1503 echo -e "\n This is NOT a bootable WIM file. \n"
1504 echo -e " 这不是一个可启动的 WIM 文件。\n"
1509 if [ -n "$vtoy_chain_mem_addr" ]; then
1510 if [ "$grub_platform" = "pc" ]; then
1511 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1514 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}
1519 echo "chain empty failed"
1524 function wim_unsupport_menuentry {
1525 common_unsupport_menuentry
1528 function efi_common_menuentry {
1529 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1531 if vt_check_password "${vt_chosen_path}"; then
1535 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1540 if vt_is_vlnk_name "${vt_chosen_path}"; then
1541 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1542 if [ -z "$vt_vlnk_dst" ]; then
1543 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1548 vt_vlnk_dst="${vtoy_iso_part}${vt_chosen_path}"
1555 #first try with chainload
1557 set root=$vtoy_iso_part
1558 chainloader "${vt_vlnk_dst}"
1563 vt_concat_efi_iso "${vt_vlnk_dst}" vtoy_iso_buf
1564 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}
1570 function efi_unsupport_menuentry {
1571 common_unsupport_menuentry
1574 function vhdboot_common_func {
1575 vt_patch_vhdboot "$1"
1579 if [ -n "$vtoy_vhd_buf_addr" ]; then
1580 if [ "$grub_platform" = "pc" ]; then
1582 linux16 $vtoy_path/memdisk iso raw
1583 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1588 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}
1593 echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
1598 function vhd_common_menuentry {
1599 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1601 if vt_check_password "${vt_chosen_path}"; then
1605 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1610 if vt_is_vlnk_name "${vt_chosen_path}"; then
1611 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1612 if [ -z "$vt_vlnk_dst" ]; then
1613 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1618 vt_vlnk_dst="${vt_chosen_path}"
1619 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
1620 if [ "$vtoy_iso_fs" != "ntfs" ]; then
1621 echo -e "!!! WARNING !!!\n"
1622 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
1623 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
1624 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
1630 vhdboot_common_func "${vt_vlnk_dst}"
1633 function vhd_unsupport_menuentry {
1634 common_unsupport_menuentry
1637 function vtoyboot_common_func {
1641 vt_get_vtoy_type "${1}" vtoytype parttype AltBootPart
1643 if vt_str_begin $vtoytype vhd; then
1645 elif [ "$vtoytype" = "raw" ]; then
1647 elif [ "$vtoytype" = "vdi" ]; then
1651 if [ $vtoysupport -eq 1 ]; then
1652 if [ "$grub_platform" = "pc" ]; then
1653 if [ "$parttype" = "gpt" -a $AltBootPart -eq 0 ]; then
1654 echo "The OS in the vdisk was created in UEFI mode, but current is Legacy BIOS mode."
1655 echo "虚拟磁盘内的系统是在UEFI模式下创建的,而当前系统是Legacy BIOS模式,可能无法正常启动。"
1659 if [ "$parttype" = "mbr" -a $AltBootPart -eq 0 ]; then
1660 echo "The OS in the vdisk was created in Legacy BIOS mode, but current is UEFI mode."
1661 echo "虚拟磁盘内的系统是在Legacy BIOS模式下创建的,而当前系统是UEFI模式,可能无法正常启动。"
1666 vt_img_sector "${1}"
1667 vt_raw_chain_data "${1}"
1671 if [ -n "$vtoy_chain_mem_addr" ]; then
1672 if [ "$grub_platform" = "pc" ]; then
1673 vt_acpi_param ${vtoy_chain_mem_addr} 512
1674 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} bios80 sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1677 if vt_check_secureboot_var; then
1678 vt_acpi_param ${vtoy_chain_mem_addr} 512
1681 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}
1686 echo "chain empty failed!"
1690 echo "Unsupported vtoy type $vtoytype"
1695 function vtoy_common_menuentry {
1696 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1698 if vt_check_password "${vt_chosen_path}"; then
1702 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1707 if vt_is_vlnk_name "${vt_chosen_path}"; then
1708 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1709 if [ -z "$vt_vlnk_dst" ]; then
1710 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1715 vt_vlnk_dst="${vtoy_iso_part}${vt_chosen_path}"
1718 vtoyboot_common_func "${vt_vlnk_dst}"
1721 function vtoy_unsupport_menuentry {
1722 common_unsupport_menuentry
1726 #============================================================#
1727 # IMG file boot process #
1728 #============================================================#
1731 function only_uefi_tip {
1732 echo -e "\n This IMG file is only supported in UEFI mode. \n"
1733 echo -e "\n press ENTER to exit ..."
1737 function ventoy_img_easyos {
1738 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1739 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1741 loopback easysfs (vtimghd,1)/easy.sfs
1742 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1744 if [ -n "$vt_module_ver" ]; then
1745 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1746 if [ -e (easysfs)/lib/modules/$vt_module_ver/$mod ]; then
1747 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1755 vt_set_boot_opt rdinit=/vtoy/vtoy
1758 syslinux_configfile (vtimghd,1)/syslinux.cfg
1765 function ventoy_img_volumio {
1766 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1767 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1772 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1775 syslinux_configfile (vtimghd,1)/syslinux.cfg
1781 function ventoy_img_openelec {
1784 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1785 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1787 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1788 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1793 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1796 set root=(vtimghd,1)
1797 syslinux_configfile (vtimghd,1)/syslinux.cfg
1801 loopback -d vtloopex
1805 function ventoy_img_freedombox {
1806 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1807 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1809 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1810 if [ -n "$vt_module_ver" ]; then
1811 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1817 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1820 configfile (vtimghd,1)/boot/grub/grub.cfg
1826 function ventoy_img_paldo {
1827 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1828 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1833 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1836 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1837 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1839 echo loading file...
1840 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1841 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1848 function ventoy_img_ubos {
1849 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1850 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1852 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1853 if [ -n "$vt_module_ver" ]; then
1854 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1860 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1863 echo loading file...
1864 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1865 initrd (vtimghd,2)/initramfs-linux.img
1872 function ventoy_img_recalbox {
1873 if [ $vtoy_img_max_part_end -GT $vt_chosen_size ]; then
1874 echo -e "\nPlease extend the img file size before boot it. \n"
1879 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1880 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1882 if [ -e (vtimghd,1)/boot/recalbox ]; then
1883 loopback recalbox (vtimghd,1)/boot/recalbox
1884 vt_get_lib_module_ver (recalbox) /lib/modules/ vt_module_ver
1885 if [ -n "$vt_module_ver" ]; then
1886 vt_img_extra_initrd_append (recalbox)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1893 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1896 set root=(vtimghd,1)
1897 configfile (vtimghd,1)/boot/grub/grub.cfg
1903 function ventoy_img_esysrescue {
1904 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1905 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1910 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=esysrescue
1913 set root=(vtimghd,1)
1914 configfile (vtimghd,1)/boot/grub/grub.cfg
1920 function ventoy_img_batocera {
1921 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1922 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1927 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1930 set root=(vtimghd,1)
1931 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1937 function ventoy_img_openwrt {
1938 if [ -e (vtimghd,2)/lib64 ]; then
1939 set ventoy_busybox_ver=64
1942 vt_fs_enum_1st_dir (vtimghd,2) /lib/modules/ vt_dir_name
1944 if [ -f (vtimghd,2)/lib/modules/$vt_dir_name/dm-mod.ko ]; then
1945 set openwrt_plugin_need=0
1946 vt_img_extra_initrd_append (vtimghd,2)/lib/modules/$vt_dir_name/dm-mod.ko
1947 if [ -f (vtimghd,2)/lib/modules/$vt_dir_name/dax.ko ]; then
1948 vt_img_extra_initrd_append (vtimghd,2)/lib/modules/$vt_dir_name/dax.ko
1951 set openwrt_plugin_need=1
1952 if [ ! -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
1954 echo -e "\n ventoy_openwrt.xz not found. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
1955 echo -e " 未找到 ventoy_openwrt.xz 文件。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
1956 echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
1963 if vt_img_check_range "${vtoy_iso_part}${vt_chosen_path}"; then
1967 echo -e "\n IMG file need processed. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
1968 echo -e " 此 IMG 文件必须处理之后才能支持。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
1969 echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
1975 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1976 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1978 if [ $openwrt_plugin_need -eq 1 ]; then
1979 if [ -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
1980 vt_img_extra_initrd_append ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz
1985 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=openwrt
1988 set root=(vtimghd,1)
1989 configfile (vtimghd,1)/boot/grub/grub.cfg
1995 function ventoy_img_tails {
1996 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1997 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2002 vt_set_boot_opt rdinit=/vtoy/vtoy live-media=/dev/dm-1 ventoyos=tails
2005 set root=(vtimghd,1)
2006 configfile (vtimghd,1)/efi/debian/grub.cfg
2012 function ventoy_img_fydeos {
2013 if [ "$grub_platform" = "pc" ]; then
2018 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=64"
2019 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2024 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=fydeos
2027 set grubdisk=vtimghd
2028 set grubpartA=(vtimghd,3)
2029 set grubpartB=(vtimghd,5)
2030 set linuxpartA=(sda,3)
2031 set linuxpartB=(sda,5)
2033 set root=(vtimghd,12)
2034 configfile (vtimghd,12)/efi/boot/grub.cfg
2046 function ventoy_img_cloudready {
2047 if [ "$grub_platform" = "pc" ]; then
2052 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=64"
2053 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2058 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=cloudready
2061 set grubdisk=vtimghd
2062 set grubpartA=(vtimghd,3)
2063 set grubpartB=(vtimghd,5)
2064 set linuxpartA=(sda,3)
2065 set linuxpartB=(sda,5)
2067 set root=(vtimghd,12)
2068 configfile (vtimghd,12)/efi/boot/grub.cfg
2080 function ventoy_img_memtest86 {
2081 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
2085 function img_unsupport_tip {
2086 echo -e "\n This IMG file is NOT supported now. \n"
2087 echo -e " 当前不支持启动此 IMG 文件 \n"
2088 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
2092 function legacy_img_memdisk {
2093 linux16 $vtoy_path/memdisk
2094 echo "Loading img file to memory ..."
2101 function img_common_menuentry {
2102 set ventoy_compatible=YES
2103 set ventoy_busybox_ver=32
2104 unset LoadIsoEfiDriver
2106 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
2108 if vt_check_password "${vt_chosen_path}"; then
2112 if ventoy_vcfg_proc "${vt_chosen_path}"; then
2116 if [ "$grub_platform" = "pc" ]; then
2117 if vt_check_mode 0 "$vt_chosen_name"; then
2118 legacy_img_memdisk $vtoy_iso_part "$vt_chosen_path"
2123 loopback vtimghd "${vtoy_iso_part}${vt_chosen_path}"
2124 vt_img_sector "${vtoy_iso_part}${vt_chosen_path}"
2126 vt_img_part_info (vtimghd)
2128 set vtback_root=$root
2131 set vtback_theme=$theme
2134 vt_img_extra_initrd_reset
2137 vt_get_fs_label (vtimghd,1) vtImgHd1Label
2139 if [ "$vtImgHd1Label" = "STATE" ]; then
2140 vt_get_fs_label (vtimghd,3) vtImgHd3Label
2141 elif [ -d (vtimghd,2)/lib ]; then
2142 vt_get_fs_label (vtimghd,2) vtImgHd2Label
2145 if [ -e (vtimghd,1)/etc/hostname ]; then
2146 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
2149 if vt_str_begin "$vtImgHd3Label" "ROOT-"; then
2150 if [ -f (vtimghd,3)/etc/os-release.d/ID ]; then
2151 vt_1st_line (vtimghd,3)/etc/os-release.d/ID vt_release_line1
2152 if vt_str_begin "$vt_release_line1" "FydeOS"; then
2155 ventoy_img_cloudready
2157 elif [ -f (vtimghd,3)/etc/cloudready-release ]; then
2158 ventoy_img_cloudready
2159 elif [ -f (vtimghd,3)/etc/chrome_dev.conf ]; then
2160 ventoy_img_cloudready
2162 elif vt_str_begin "$vtImgHd1Label" "LAKKA"; then
2163 ventoy_img_openelec lakka
2164 elif vt_str_begin "$vtImgHd1Label" "LIBREELEC"; then
2165 ventoy_img_openelec LibreELEC
2166 elif vt_str_begin "$vtImgHd1Label" "paldo-live"; then
2168 elif vt_str_begin "$vtImgHostname" "freedombox"; then
2169 ventoy_img_freedombox
2170 elif vt_str_begin "$vtImgHd1Label" "BATOCERA"; then
2172 elif vt_str_begin "$vtImgHd1Label" "Tails"; then
2174 elif [ "$vtImgHd2Label" = "RECALBOX" -o "$vtImgHd1Label" = "RECALBOX" ]; then
2176 elif [ "$vtImgHd1Label" = "ESYSRESCUE" ]; then
2177 ventoy_img_esysrescue
2178 elif [ -e (vtimghd,1)/easy.sfs ]; then
2180 elif [ -e (vtimghd,1)/volumio.initrd ]; then
2182 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
2184 elif [ -f (vtimghd,2)/etc/openwrt_version ]; then
2186 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
2187 if [ "$grub_platform" = "pc" ]; then
2190 ventoy_img_memtest86
2193 vt_linux_chain_data "${vtoy_iso_part}${vt_chosen_path}"
2194 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
2195 if [ "$grub_platform" = "pc" ]; then
2196 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
2199 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}
2206 set root=$vtback_root
2208 set theme=$vtback_theme
2210 set ventoy_compatible=NO
2213 function img_unsupport_menuentry {
2214 common_unsupport_menuentry
2217 #############################################################
2218 #############################################################
2219 #############################################################
2220 ####### Main Process ###########
2221 #############################################################
2222 #############################################################
2223 #############################################################
2225 set VENTOY_VERSION="1.0.79"
2227 #ACPI not compatible with Window7/8, so disable by default
2228 set VTOY_PARAM_NO_ACPI=1
2230 # Default menu display mode, you can change it as you want.
2233 set VTOY_DEFAULT_MENU_MODE=0
2235 set VTOY_MEM_DISK_STR="[Memdisk]"
2236 set VTOY_ISO_RAW_STR="Compatible Mode"
2237 set VTOY_GRUB2_MODE_STR="GRUB2 Mode"
2238 set VTOY_WIMBOOT_MODE_STR="WIMBOOT Mode"
2239 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
2241 set VTOY_F2_CMD="vt_browser_disk"
2242 set VTOY_F4_CMD="ventoy_localboot"
2243 set VTOY_F5_CMD="ventoy_diagnosis"
2244 set VTOY_F6_CMD="ventoy_ext_menu"
2245 set VTOY_HELP_CMD="ventoy_show_help"
2246 set VTOY_CHKSUM_CMD="ventoy_checksum"
2247 set VTOY_HELP_TXT_LANGUAGE="en_US"
2248 set VTOY_CHKSUM_FILE_PATH="X"
2251 if [ "$grub_platform" = "pc" ]; then
2252 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
2254 if [ "$grub_cpu" = "i386" ]; then
2255 set VTOY_EFI_ARCH=ia32
2256 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION IA32 www.ventoy.net"
2257 elif [ "$grub_cpu" = "arm64" ]; then
2258 set VTOY_EFI_ARCH=aa64
2259 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION AA64 www.ventoy.net"
2260 elif [ "$grub_cpu" = "mips64el" ]; then
2261 set VTOY_EFI_ARCH=mips
2262 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION MIPS www.ventoy.net"
2264 set VTOY_EFI_ARCH=x64
2265 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
2269 vt_device $root vtoy_dev
2271 if [ "$vtoy_dev" = "tftp" ]; then
2272 set vtoy_path=($root)
2273 for vtid in 0 1 2 3; do
2274 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
2275 set vtoy_iso_part=(hd$vtid,1)
2276 set vtoy_efi_part=(hd$vtid,2)
2283 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
2284 set vt_plugin_path=$vtoy_iso_part
2286 set vt_plugin_path=$prefix
2287 vt_load_plugin $vt_plugin_path
2290 if [ "$prefix" = "(ventoydisk)/grub" ]; then
2291 set vtoy_path=(ventoydisk)/ventoy
2293 set vtoy_path=($root)/ventoy
2296 set vtoydev=$vtoy_dev
2297 set vtoy_iso_part=($vtoy_dev,1)
2298 set vtoy_efi_part=($vtoy_dev,2)
2300 vt_load_file_to_mem "auto" $prefix/fonts/unicode.pf2 vtoy_font_mem
2301 loadfont mem:${vtoy_font_mem_addr}:size:${vtoy_font_mem_size}
2303 set vt_plugin_path=$vtoy_iso_part
2306 #Load Partition Table
2307 vt_load_part_table $vtoydev
2310 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
2312 vt_load_plugin $vtoy_iso_part
2315 vt_check_json_path_case $vtoy_iso_part
2318 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
2319 set timeout=$VTOY_MENU_TIMEOUT
2324 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
2325 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
2326 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
2327 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
2330 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
2331 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
2332 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
2333 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
2337 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
2338 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
2339 set VTOY_HOTKEY_TIP="h:Help F1:Memdisk F2:Browser F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
2341 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
2342 set VTOY_HOTKEY_TIP="h:Help F1:Memdisk F2:Browser F3:ListView F4:Localboot F5:Tools F6:ExMenu"
2345 terminal_output console
2347 if [ -n "$vtoy_gfxmode" ]; then
2348 set gfxmode=$vtoy_gfxmode
2351 set gfxmode=1024x768
2356 if [ "$vtoy_display_mode" = "CLI" ]; then
2357 terminal_output console
2358 elif [ "$vtoy_display_mode" = "serial" ]; then
2359 if [ -n "$vtoy_serial_param" ]; then
2360 serial $vtoy_serial_param
2362 terminal_input serial
2363 terminal_output serial
2364 elif [ "$vtoy_display_mode" = "serial_console" ]; then
2365 if [ -n "$vtoy_serial_param" ]; then
2366 serial $vtoy_serial_param
2368 terminal_input serial console
2369 terminal_output serial console
2371 if [ -n "$vtoy_theme" ]; then
2374 set theme=$prefix/themes/ventoy/theme.txt
2376 terminal_output gfxterm
2379 if [ "$grub_platform" = "efi" ]; then
2380 set mouse_delta=4000
2381 # terminal_input --append mouse
2384 if [ -n "$VTOY_DEFAULT_KBD_LAYOUT" ]; then
2385 set_keyboard_layout "$VTOY_DEFAULT_KBD_LAYOUT"
2388 if [ -n "$VTOY_PLUGIN_PATH_CASE_MISMATCH" ]; then
2390 echo "$VTOY_PLUGIN_PATH_CASE_MISMATCH"
2391 echo -e "\n\nPath case does not match! ventoy directory and ventoy.json MUST be all lowercase!"
2392 echo -e "\n路径大小写不匹配!ventoy 目录和 ventoy.json 文件的名字必须是全部小写,请修正!"
2393 echo -e "\n\npress ENTER to continue (请按回车键继续) ..."
2397 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
2399 if [ -n "$VTOY_PLUGIN_ENCODE_ERROR" ]; then
2400 echo -e "\n Encoding type for ventoy.json is not supported, please convert to UTF-8.\n"
2401 echo -e " ventoy.json 文件编码格式不支持,请转换为 UTF-8 编码格式!\n"
2403 echo -e "\n Syntax error detected in ventoy.json, please check! \n"
2404 echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
2407 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
2412 for vtTFile in ventoy.json ventoy_grub.cfg; do
2413 if [ -f $vtoy_efi_part/ventoy/$vtTFile ]; then
2415 echo -e "\n You need to put $vtTFile in the 1st partition which hold the ISO files.\n"
2416 echo -e " $vtTFile 放错分区了,请放到镜像分区里的 ventoy 目录下(此目录需要手动创建)!\n"
2417 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
2422 #clear all input key before show main menu
2425 #export necessary variable
2433 export vtoy_iso_part
2434 export vtoy_efi_part
2435 export VENTOY_VERSION
2436 export VTOY_CUR_VIDEO_MODE
2437 export VTOY_EFI_ARCH
2438 export VTOY_MEM_DISK_STR
2439 export VTOY_ISO_RAW_STR
2440 export VTOY_GRUB2_MODE_STR
2441 export VTOY_WIMBOOT_MODE_STR
2442 export VTOY_ISO_UEFI_DRV_STR
2447 export VTOY_HELP_CMD
2448 export VTOY_CHKSUM_CMD
2449 export VTOY_HELP_TXT_LANGUAGE
2450 export VTOY_CHKSUM_FILE_PATH
2453 #colect all image files (iso files)
2454 set ventoy_img_count=0
2455 vt_list_img $vtoy_iso_part ventoy_img_count
2458 if [ $ventoy_img_count -gt 0 ]; then
2459 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
2465 if [ -n "$VTOY_NO_ISO_TIP" ]; then
2466 NO_ISO_MENU="No ISO or supported IMG files found, $VTOY_NO_ISO_TIP"
2467 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
2468 NO_ISO_MENU="No ISO or supported IMG files found, please check VTOY_DEFAULT_SEARCH_ROOT"
2470 NO_ISO_MENU="No ISO or supported IMG files found"
2472 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
2473 echo -e "\n Rebooting ... "
2479 #special VTOY_DEFAULT_IMAGE process
2480 if [ -n "$VTOY_DEFAULT_IMAGE" ]; then
2481 if regexp --set 1:vtHotkey --set 2:vtDefault "(F[2-9])>(.*)" "$VTOY_DEFAULT_IMAGE"; then
2483 set default="$vtDefault"
2484 if [ -z "$VTOY_MENU_TIMEOUT" ]; then
2487 set timeout=$VTOY_MENU_TIMEOUT
2495 if [ "$vtHotkey" = "F2" ]; then
2498 elif [ "$vtHotkey" = "F4" ]; then
2500 elif [ "$vtHotkey" = "F5" ]; then
2502 elif [ "$vtHotkey" = "F6" ]; then