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_language {
69 configfile $prefix/menulang.cfg
72 function ventoy_diagnosis {
74 configfile $prefix/debug.cfg
77 function ventoy_localboot {
78 configfile $prefix/localboot.cfg
81 function ventoy_ext_menu {
82 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
83 set ventoy_new_context=1
84 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
85 unset ventoy_new_context
87 echo "ventoy_grub.cfg NOT exist."
88 echo -e "\npress ENTER to exit ..."
93 function ventoy_checksum {
94 if [ -f "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}" ]; then
95 configfile $prefix/checksum.cfg
99 function ventoy_show_help {
100 if [ -f $prefix/help.tar.gz ]; then
101 if [ -z "$vtoy_help_txt_mem_addr" ]; then
102 vt_load_file_to_mem "auto" $prefix/help.tar.gz vtoy_help_txt_mem
105 loopback vt_help_tarfs mem:${vtoy_help_txt_mem_addr}:size:${vtoy_help_txt_mem_size}
106 if [ -f "(vt_help_tarfs)/help/${VTOY_HELP_TXT_LANGUAGE}.txt" ]; then
107 cat "(vt_help_tarfs)/help/${VTOY_HELP_TXT_LANGUAGE}.txt"
109 cat "(vt_help_tarfs)/help/en_US.txt"
111 loopback -d vt_help_tarfs
115 function ventoy_load_menu_lang_file {
116 vt_load_file_to_mem "auto" $vtoy_efi_part/grub/menu.tar.gz vtoy_menu_lang_mem
117 loopback vt_menu_tarfs mem:${vtoy_menu_lang_mem_addr}:size:${vtoy_menu_lang_mem_size}
120 function get_os_type {
123 if vt_str_begin "$vt_volume_id" "DLC Boot"; then
124 if [ -f (loop)/DLCBoot.exe ]; then
128 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
129 if vt_file_exist_nocase (loop)/$file; then
136 if [ "$vtoy_os" = "Linux" ]; then
137 if vt_strstr "$vt_system_id" "FreeBSD"; then
139 set vt_unix_type=FreeBSD
140 elif [ -e (loop)/bin/freebsd-version ]; then
142 set vt_unix_type=FreeBSD
143 elif [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
145 set vt_unix_type=FreeBSD
146 elif vt_str_begin "$vt_system_id" "DragonFly"; then
148 set vt_unix_type=DragonFly
151 elif [ -e (loop)/boot/kernel/kernel ]; then
152 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
154 set vt_unix_type=FreeBSD
155 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
157 set vt_unix_type=NetBSD
162 if [ -n "${vtdebug_flag}" ]; then
163 echo ISO is "$vtoy_os"
167 function vt_check_compatible_pe {
168 #Check for PE without external tools
169 #set compatible if ISO file is less than 80MB
170 if [ $vt_chosen_size -GT 33554432 -a $vt_chosen_size -LE 83886080 ]; then
171 set ventoy_compatible=YES
177 function vt_check_compatible_linux {
178 if vt_str_begin "$vt_volume_id" "embootkit"; then
179 set ventoy_compatible=YES
180 elif [ -e "$1/casper/tinycore.gz" ]; then
181 set ventoy_compatible=YES
187 function locate_initrd {
188 vt_linux_locate_initrd
190 if [ -n "${vtdebug_flag}" ]; then
196 function locate_wim {
197 vt_windows_locate_wim_patch (loop) "$1"
199 if [ -n "${vtdebug_flag}" ]; then
200 echo '###############################################'
202 echo '###############################################'
207 function distro_specify_wim_patch {
208 if [ -d (loop)/h3pe ]; then
209 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
210 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
211 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
212 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
213 elif [ -d (loop)/2k10/winpe ]; then
214 vt_windows_collect_wim_patch wim /2k10/winpe/w1086pe.wim
215 vt_windows_collect_wim_patch wim /2k10/winpe/w8x86pe.wim
216 vt_windows_collect_wim_patch wim /2k10/winpe/w7x86pe.wim
220 function distro_specify_wim_patch_phase2 {
221 if [ -f (loop)/boot/boot.wim ]; then
222 vt_windows_collect_wim_patch wim /boot/boot.wim
225 if vt_str_begin "$vt_volume_id" "DLC Boot"; then
226 for vwfile in "/DLC1/WinPE/W11x64.wim" "/DLC1/WinPE/W10x64.wim" "/DLC1/WinPE/W10x86.wim"; do
227 if [ -f (loop)/$vwfile ]; then
228 vt_windows_collect_wim_patch wim $vwfile
236 function distro_specify_initrd_file {
237 if [ -e (loop)/boot/all.rdz ]; then
238 vt_linux_specify_initrd_file /boot/all.rdz
239 elif [ -e (loop)/boot/xen.gz ]; then
240 if [ -e (loop)/install.img ]; then
241 vt_linux_specify_initrd_file /install.img
243 elif [ -d (loop)/casper ]; then
244 if [ -e (loop)/casper/initrd ]; then
245 vt_linux_specify_initrd_file /casper/initrd
247 if [ -e (loop)/casper/initrd.gz ]; then
248 vt_linux_specify_initrd_file /casper/initrd.gz
250 if [ -e (loop)/casper/initrd-oem ]; then
251 vt_linux_specify_initrd_file /casper/initrd-oem
253 elif [ -e (loop)/boot/grub/initrd.xz ]; then
254 vt_linux_specify_initrd_file /boot/grub/initrd.xz
255 elif [ -e (loop)/initrd.gz ]; then
256 vt_linux_specify_initrd_file /initrd.gz
257 elif [ -e (loop)/slax/boot/initrfs.img ]; then
258 vt_linux_specify_initrd_file /slax/boot/initrfs.img
259 elif [ -e (loop)/minios/boot/initrfs.img ]; then
260 vt_linux_specify_initrd_file /minios/boot/initrfs.img
261 elif [ -e (loop)/pmagic/initrd.img ]; then
262 vt_linux_specify_initrd_file /pmagic/initrd.img
263 elif [ -e (loop)/boot/initrd.xz ]; then
264 vt_linux_specify_initrd_file /boot/initrd.xz
265 elif [ -e (loop)/boot/initrd.gz ]; then
266 vt_linux_specify_initrd_file /boot/initrd.gz
267 elif [ -f (loop)/boot/initrd ]; then
268 vt_linux_specify_initrd_file /boot/initrd
269 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
270 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
271 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
272 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
273 elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
274 vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
275 elif [ -f (loop)/boot/initrd.img ]; then
276 vt_linux_specify_initrd_file /boot/initrd.img
280 if [ -f (loop)/isolinux/initrd.gz ]; then
281 vt_linux_specify_initrd_file /isolinux/initrd.gz
284 if vt_str_begin "$vt_volume_id" "QUBES"; then
285 vt_linux_specify_initrd_file /images/pxeboot/initrd.img
288 if [ "$vt_chosen_size" = "1133375488" ]; then
289 if [ -d (loop)/boot/grub/x86_64-efi ]; then
290 vt_cpio_busybox64 "64h"
296 function distro_specify_initrd_file_phase2 {
297 if [ -f (loop)/boot/initrd.img ]; then
298 vt_linux_specify_initrd_file /boot/initrd.img
299 elif [ -f (loop)/Setup/initrd.gz ]; then
300 vt_linux_specify_initrd_file /Setup/initrd.gz
301 elif [ -f (loop)/isolinux/initramfs ]; then
302 vt_linux_specify_initrd_file /isolinux/initramfs
303 elif [ -f (loop)/boot/iniramfs.igz ]; then
304 vt_linux_specify_initrd_file /boot/iniramfs.igz
305 elif [ -f (loop)/initrd-x86_64 ]; then
306 vt_linux_specify_initrd_file /initrd-x86_64
307 elif [ -f (loop)/live/initrd.img ]; then
308 vt_linux_specify_initrd_file /live/initrd.img
309 elif [ -f (loop)/initrd.img ]; then
310 vt_linux_specify_initrd_file /initrd.img
311 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
312 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
313 elif [ -f (loop)/CDlinux/initrd ]; then
314 vt_linux_specify_initrd_file /CDlinux/initrd
315 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
316 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
317 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
318 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
320 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
321 vt_linux_specify_initrd_file /parabola/boot/x86_64/initramfs-linux-libre.img
322 if [ -f (loop)/parabola/boot/i686/initramfs-linux-libre.img ]; then
323 vt_linux_specify_initrd_file /parabola/boot/i686/initramfs-linux-libre.img
325 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
326 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
327 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
328 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
330 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
332 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
333 if [ "$grub_platform" != "pc" ]; then
334 vt_add_replace_file 0 "initrd.img"
336 elif [ -f (loop)/initrd ]; then
337 vt_linux_specify_initrd_file /initrd
338 elif [ -f (loop)/live/initrd1 ]; then
339 vt_linux_specify_initrd_file /live/initrd1
340 elif [ -f (loop)/isolinux/initrd.img ]; then
341 vt_linux_specify_initrd_file /isolinux/initrd.img
342 elif [ -f (loop)/isolinux/initrd.gz ]; then
343 vt_linux_specify_initrd_file /isolinux/initrd.gz
344 elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
345 vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
346 elif vt_strstr "$vt_volume_id" "Daphile"; then
347 vt_linux_parse_initrd_isolinux (loop)/isolinux/
348 elif [ -f (loop)/boot/rootfs.xz ]; then
349 vt_linux_specify_initrd_file /boot/rootfs.xz
350 if [ "$grub_platform" != "pc" ]; then
351 vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
353 elif [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
354 vt_linux_specify_initrd_file /arch/boot/x86_64/archiso.img
355 if [ "$grub_platform" != "pc" ]; then
356 vt_add_replace_file 0 "EFI\\archiso\\archiso.img"
358 elif [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
359 vt_linux_specify_initrd_file /blackarch/boot/x86_64/archiso.img
360 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
361 vt_linux_specify_initrd_file /blackarch/boot/x86_64/initramfs-linux.img
363 elif [ -f (loop)/install.amd/initrd.gz ]; then
364 vt_linux_specify_initrd_file /live/initrd2.img
365 vt_linux_specify_initrd_file /install.amd/initrd.gz
366 vt_linux_specify_initrd_file /install.amd/gtk/initrd.gz
367 elif [ -f (loop)/boot/grub/kernels.cfg ]; then
368 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
369 elif [ -f (loop)/austrumi/initrd.gz ]; then
370 vt_linux_specify_initrd_file /austrumi/initrd.gz
371 if [ -f (loop)/EFI/BOOT/bootx64.efi ]; then
372 vt_cpio_busybox64 "64h"
374 elif [ -f (loop)/boot/initfs.x86_64-efi ]; then
375 vt_linux_specify_initrd_file /boot/initfs.x86_64-efi
376 if [ -f (loop)/boot/initfs.i386-pc ]; then
377 vt_linux_specify_initrd_file /boot/initfs.i386-pc
379 elif [ -f (loop)/antiX/initrd.gz ]; then
380 vt_linux_specify_initrd_file /antiX/initrd.gz
381 elif [ -f (loop)/360Disk/initrd.gz ]; then
382 vt_linux_specify_initrd_file /360Disk/initrd.gz
383 elif [ -f (loop)/porteus/initrd.xz ]; then
384 vt_linux_specify_initrd_file /porteus/initrd.xz
385 elif [ -f (loop)/pyabr/boot/initrfs.img ]; then
386 vt_linux_specify_initrd_file /pyabr/boot/initrfs.img
387 elif [ -f (loop)/initrd0.img ]; then
388 vt_linux_specify_initrd_file /initrd0.img
389 elif [ -f (loop)/sysresccd/boot/i686/sysresccd.img ]; then
390 vt_linux_specify_initrd_file /sysresccd/boot/i686/sysresccd.img
391 elif [ -f (loop)/boot/full.cz ]; then
392 vt_linux_specify_initrd_file /boot/full.cz
393 elif [ -f (loop)/images/pxeboot/initrd.img ]; then
394 vt_linux_specify_initrd_file /images/pxeboot/initrd.img
399 function ventoy_get_ghostbsd_ver {
400 # fallback to parse version from elf /boot/kernel/kernel
401 set vt_freebsd_ver=xx
404 function ventoy_get_furybsd_ver {
405 if regexp "13\.[0-9]" "$2"; then
406 set vt_freebsd_ver=13.x
408 set vt_freebsd_ver=12.x
412 function ventoy_get_freenas_ver {
413 set vt_freebsd_ver=11.x
415 if [ -e (loop)/FreeNAS-MANIFEST ]; then
416 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
417 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
418 set vt_freebsd_ver=13.x
419 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
420 set vt_freebsd_ver=12.x
421 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
422 set vt_freebsd_ver=11.x
427 function ventoy_get_truenas_ver {
428 set vt_freebsd_ver=12.x
430 if [ -e (loop)/TrueNAS-MANIFEST ]; then
431 vt_parse_freenas_ver (loop)/TrueNAS-MANIFEST vt_truenas_ver
432 if regexp "^13\.[0-9]" "$vt_truenas_ver"; then
433 set vt_freebsd_ver=13.x
434 elif regexp "^12\.[0-9]" "$vt_truenas_ver"; then
435 set vt_freebsd_ver=12.x
436 elif regexp "^11\.[0-9]" "$vt_truenas_ver"; then
437 set vt_freebsd_ver=11.x
442 function ventoy_get_midnightbsd_ver {
443 if vt_str_begin "$vt_volume_id" "1_"; then
444 set vt_freebsd_ver=11.x
445 elif vt_str_begin "$vt_volume_id" "2_"; then
446 set vt_freebsd_ver=2.x
447 elif vt_str_begin "$vt_volume_id" "3_"; then
448 set vt_freebsd_ver=3.x
452 function ventoy_freebsd_proc {
453 set vtFreeBsdDistro=FreeBSD
454 set vt_freebsd_ver=xx
456 if [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
457 vt_unix_ko_fillmap /boot/kernel/geom_ventoy.ko
461 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
462 ventoy_get_ghostbsd_ver "$1" "${chosen_path}"
463 elif vt_strstr "$vt_volume_id" "FREENAS"; then
464 ventoy_get_freenas_ver "$1" "${chosen_path}"
465 elif vt_strstr "$vt_volume_id" "TRUENAS"; then
466 ventoy_get_truenas_ver "$1" "${chosen_path}"
467 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
468 ventoy_get_furybsd_ver "$1" "${chosen_path}"
469 elif regexp "^13_[0-9]" "$vt_volume_id"; then
470 set vt_freebsd_ver=13.x
471 elif regexp "^12_[0-9]" "$vt_volume_id"; then
472 set vt_freebsd_ver=12.x
473 elif regexp "^11_[0-9]" "$vt_volume_id"; then
474 set vt_freebsd_ver=11.x
475 elif regexp "^10_[0-9]" "$vt_volume_id"; then
476 set vt_freebsd_ver=10.x
477 elif regexp "^9_[0-9]" "$vt_volume_id"; then
478 set vt_freebsd_ver=9.x
479 elif [ -d (loop)/usr/midnightbsd-dist ]; then
480 ventoy_get_midnightbsd_ver "$1" "${chosen_path}"
481 set vtFreeBsdDistro=MidnightBSD
482 elif [ -e (loop)/bin/freebsd-version ]; then
483 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
484 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
485 set vt_freebsd_ver=13.x
486 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
487 set vt_freebsd_ver=12.x
488 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
489 set vt_freebsd_ver=11.x
490 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
491 set vt_freebsd_ver=10.x
492 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
493 set vt_freebsd_ver=9.x
495 elif [ -e (loop)/README.TXT ]; then
496 vt_1st_line (loop)/README.TXT vt_freebsd_line1
497 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
498 set vt_freebsd_ver=13.x
499 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
500 set vt_freebsd_ver=12.x
501 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
502 set vt_freebsd_ver=11.x
503 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
504 set vt_freebsd_ver=10.x
505 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
506 set vt_freebsd_ver=9.x
508 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
509 set vt_freebsd_ver=9.x
513 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
514 set vtFreeBsdDistro=ClonOS
517 set vt_freebsd_bit=64
518 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
519 if [ -e (loop)/$file ]; then
520 if file --is-i386-kfreebsd (loop)/$file; then
521 set vt_freebsd_bit=32
527 if [ "$vt_freebsd_ver" = "xx" ]; then
528 if [ -e (loop)/boot/kernel/kernel ]; then
529 vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel $vt_freebsd_bit vt_freebsd_ver
530 elif [ -e (loop)/boot/kernel/kernel.gz ]; then
531 vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel.gz $vt_freebsd_bit vt_freebsd_ver
534 if [ "$vt_freebsd_ver" = "xx" ]; then
535 set vt_freebsd_ver=13.x
539 if [ -n "${vtdebug_flag}" ]; then
540 echo "This is $vtFreeBsdDistro $vt_freebsd_ver ${vt_freebsd_bit}bit"
543 unset vt_unix_mod_path
544 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/TrueNAS-MANIFEST" "/version" "/etc/fstab"; do
545 if [ -e (loop)${file} ]; then
546 set vt_unix_mod_path=${file}
551 if [ -n "$vt_unix_mod_path" ]; then
552 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
553 vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
554 elif [ -e (loop)/easyre.ufs.uzip ]; then
555 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
556 if [ "$grub_platform" = "pc" ]; then
557 vt_unix_replace_grub_conf "/boot/grub/i386-pc/linux.mod" "cd9"
559 vt_unix_replace_conf FreeBSD "${1}${chosen_path}" "cd9"
564 function ventoy_dragonfly_proc {
566 unset vt_unix_mod_path
567 for file in "/boot/kernel/initrd.img.gz"; do
568 if [ -e (loop)${file} ]; then
569 set vt_unix_mod_path=${file}
574 vt_unix_replace_ko $vt_unix_mod_path ${vtoy_path}/dragonfly.mfs.xz
575 vt_unix_fill_image_desc
577 vt_unix_replace_conf DragonFly "${1}${chosen_path}"
580 function ventoy_unix_comm_proc {
583 vt_unix_check_vlnk "${1}${chosen_path}"
585 if [ "$ventoy_compatible" = "NO" ]; then
586 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
588 if [ "$vt_unix_type" = "FreeBSD" ]; then
589 ventoy_freebsd_proc "$1" "${chosen_path}"
590 elif [ "$vt_unix_type" = "DragonFly" ]; then
591 ventoy_dragonfly_proc "$1" "${chosen_path}"
592 elif [ "$vt_unix_type" = "NetBSD" ]; then
593 echo "NetBSD not supported"
597 if [ -n "${vtdebug_flag}" ]; then
598 echo "Unknown unix type"
603 vt_unix_chain_data "${1}${chosen_path}"
608 function uefi_windows_menu_func {
611 unset vt_cur_wimboot_mode
612 if vt_check_mode 4 "$vt_chosen_name"; then
613 set vt_cur_wimboot_mode=1
616 if [ "$ventoy_compatible" = "NO" -o "$vt_cur_wimboot_mode" = "1" ]; then
617 if [ "$ventoy_fs_probe" = "iso9660" ]; then
619 vt_iso9660_nojoliet 1
623 for file in "efi/microsoft/boot/bcd"; do
624 vt_windows_collect_wim_patch bcd (loop)/$file
627 vt_windows_count_wim_patch vt_wim_cnt
628 if [ $vt_wim_cnt -eq 0 ]; then
629 distro_specify_wim_patch_phase2
633 locate_wim "${chosen_path}"
636 vt_windows_chain_data "${1}${chosen_path}"
639 if [ "$vt_cur_wimboot_mode" = "1" ]; then
643 if [ -n "$vtoy_chain_mem_addr" ]; then
644 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
646 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}
649 echo "chain empty failed"
654 function uefi_find_replace_initrd {
655 if vt_get_efi_vdisk_offset "${1}${2}" vt_efivdisk_offset; then
656 loopback -s $vt_efivdisk_offset vtefivdisk "${1}${2}"
659 vt_search_replace_initrd (vtefivdisk) vt_rp_initrd
661 if [ -n "$vt_rp_initrd" ]; then
662 vt_add_replace_file $3 "$vt_rp_initrd"
665 loopback -d vtefivdisk
670 function uefi_linux_menu_func {
672 if [ "$ventoy_compatible" = "NO" ]; then
674 if [ "$ventoy_fs_probe" = "udf" ]; then
676 set ventoy_fs_probe=iso9660
680 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
682 vt_linux_clear_initrd
684 if [ -d (loop)/pmagic ]; then
685 vt_linux_specify_initrd_file /pmagic/initrd.img
687 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
688 if [ -e (loop)/$file ]; then
689 vt_linux_parse_initrd_grub file (loop)/$file
694 # special process for special distros
695 if [ -d (loop)/loader/entries ]; then
696 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
697 elif [ -d (loop)/boot/grub ]; then
698 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
701 distro_specify_initrd_file
703 vt_linux_initrd_count vtcount
705 if [ $vtcount -eq 0 ]; then
706 if [ -e (loop)/EFI/boot/livegrub.cfg ]; then
707 vt_linux_parse_initrd_grub file (loop)/EFI/boot/livegrub.cfg
709 distro_specify_initrd_file_phase2
711 if [ "$vt_efi_dir" = "NO" ]; then
712 if [ -f (loop)/efi.img ]; then
713 vt_add_replace_file 0 "initrd"
720 if [ -d (loop)/loader/entries ]; then
721 vt_linux_get_main_initrd_index vtindex
723 if [ -d (loop)/arch ]; then
724 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
725 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
726 elif [ -f (loop)/arch/boot/x86_64/initramfs-linux.img ]; then
727 vt_add_replace_file $vtindex "arch\\boot\\x86_64\\initramfs-linux.img"
728 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
729 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
731 elif [ -d (loop)/blackarch ]; then
732 if [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
733 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
734 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
735 vt_add_replace_file $vtindex "blackarch\\boot\\x86_64\\initramfs-linux.img"
737 elif [ -d (loop)/anarchy ]; then
738 if [ -f (loop)/anarchy/boot/x86_64/initramfs-linux.img ]; then
739 vt_add_replace_file $vtindex "anarchy\\boot\\x86_64\\initramfs-linux.img"
741 elif [ -d (loop)/parabola ]; then
742 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
743 vt_add_replace_file $vtindex "EFI\\parabolaiso\\parabolaiso.img"
744 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
745 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
747 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
748 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
749 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
750 vt_add_replace_file $vtindex "boot\\initrd"
751 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
752 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
755 vt_get_replace_file_cnt vt_replace_cnt
756 if [ $vt_replace_cnt -eq 0 ]; then
757 uefi_find_replace_initrd "$1" "$2" $vtindex
759 elif [ -d (loop)/EFI/boot/entries ]; then
760 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
761 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
762 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
763 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
765 elif [ -d (loop)/EFI/BOOT/entries ]; then
766 vt_linux_get_main_initrd_index vtindex
768 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
769 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
770 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
771 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
773 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
774 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
775 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
777 elif vt_str_begin "$vt_volume_id" "SolusLive"; then
778 vt_add_replace_file 0 "initrd"
784 vt_linux_chain_data "${1}${chosen_path}"
786 if [ -n "$LoadIsoEfiDriver" -a $vt_chosen_size -LT 104857600 ]; then
787 if [ -f (loop)/efi/clover/cloverx64.efi ]; then
788 unset LoadIsoEfiDriver
792 if [ -n "$vtoy_chain_mem_addr" ]; then
793 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
797 if vt_check_mode 3 "$vt_chosen_name"; then
799 elif vt_str_begin "$vt_volume_id" "HOLO_"; then
800 if [ -d (loop)/loader/entries ]; then
803 elif vt_str_begin "$vt_volume_id" "KRD"; then
804 if [ -f (loop)/boot/grub/grub.cfg.sig ]; then
809 if [ -n "$vtGrub2Mode" ]; then
812 if [ "$VTOY_EFI_ARCH" != "mips" ]; then
813 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}
819 set vtback_root=$root
821 set vtback_theme=$theme
824 vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
825 vt_set_boot_opt rdinit=/vtoy/vtoy
828 set vtback_cfg_find=0
829 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
830 if [ -e "$cfg" ]; then
831 set vtback_cfg_find=1
836 if [ $vtback_cfg_find -eq 0 ]; then
837 if [ -f (loop)/loader/loader.conf -a -d (loop)/loader/entries ]; then
838 if vt_str_begin "$vt_volume_id" "HOLO_"; then
840 vt_systemd_menu (loop,2) vt_sys_menu_mem
842 vt_systemd_menu (loop) vt_sys_menu_mem
844 set vtback_cfg_find=1
845 configfile "mem:${vt_sys_menu_mem_addr}:size:${vt_sys_menu_mem_size}"
849 if [ "$vtback_cfg_find" = "0" ]; then
851 echo "No bootfile found for UEFI!"
852 echo "Maybe the image does not support $VTOY_EFI_ARCH UEFI"
858 set root=$vtback_root
859 set theme=$vtback_theme
863 echo "chain empty failed"
868 function uefi_unix_menu_func {
869 ventoy_unix_comm_proc $1 "${chosen_path}"
871 if [ -n "$vtoy_chain_mem_addr" ]; then
872 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
874 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}
877 echo "chain empty failed"
882 function ventoy_reset_nojoliet {
883 if vt_str_begin "$vt_volume_id" "ARCARESCUE"; then
884 vt_iso9660_nojoliet 1
886 vt_iso9660_nojoliet 0
889 vt_append_extra_sector 0
892 function uefi_iso_menu_func {
894 if [ -d (loop)/ ]; then
898 if [ -n "$vtisouefi" ]; then
899 set LoadIsoEfiDriver=on
901 elif vt_check_mode 2 "$vt_chosen_name"; then
902 set LoadIsoEfiDriver=on
904 unset LoadIsoEfiDriver
908 vt_select_auto_install "${chosen_path}"
909 vt_select_persistence "${chosen_path}"
911 if vt_is_udf "${1}${chosen_path}"; then
912 set ventoy_fs_probe=udf
914 set ventoy_fs_probe=iso9660
915 ventoy_reset_nojoliet
917 # Lenovo EasyStartup need an addional sector for boundary check
918 if vt_str_begin "$vt_volume_id" "EasyStartup"; then
919 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
920 vt_append_extra_sector 1
924 loopback loop "${1}${chosen_path}"
927 if [ -d (loop)/EFI ]; then
929 elif [ -d (loop)/efi ]; then
935 if [ -n "$vtcompat" ]; then
936 set ventoy_compatible=YES
938 elif vt_check_mode 1 "$vt_chosen_name"; then
939 set ventoy_compatible=YES
941 vt_check_compatible (loop)
944 if vt_need_secondary_menu "$vt_chosen_name"; then
945 vt_show_secondary_menu "$vt_chosen_path" "$vtoy_os" $vt_chosen_size
946 if vt_check_mode 0 "$vt_chosen_name"; then
947 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
948 vt_secondary_recover_mode
953 vt_img_sector "${1}${chosen_path}"
955 if [ "$ventoy_fs_probe" = "iso9660" ]; then
956 vt_select_conf_replace "${1}" "${chosen_path}"
959 if [ "$vtoy_os" = "Windows" ]; then
960 vt_check_compatible_pe (loop)
961 uefi_windows_menu_func "$1" "${chosen_path}"
962 elif [ "$vtoy_os" = "Unix" ]; then
963 uefi_unix_menu_func "$1" "${chosen_path}"
965 vt_check_compatible_linux (loop)
966 uefi_linux_menu_func "$1" "${chosen_path}"
970 vt_secondary_recover_mode
973 function uefi_iso_memdisk {
974 echo 'Loading ISO file to memory ...'
975 vt_load_img_memdisk "${1}${2}" vtoy_iso_buf
978 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}
984 function vtoy_windows_wimboot {
985 if [ -f (loop)/x86/sources/boot.wim -a -f (loop)/x64/sources/boot.wim ]; then
986 vt_sel_wimboot vtoy_wimboot_bit
987 if [ "$vtoy_wimboot_bit" = "32" ]; then
988 set vtoy_wimboot_prefix=(loop)/x86
990 set vtoy_wimboot_prefix=(loop)/x64
993 set vtoy_wimboot_prefix=(loop)
994 if vt_is_pe64 $vtoy_wimboot_prefix/setup.exe; then
995 set vtoy_wimboot_bit=64
997 set vtoy_wimboot_bit=32
1001 if [ -n "${vtdebug_flag}" ]; then
1002 echo vtoy_wimboot_prefix=$vtoy_wimboot_prefix vtoy_wimboot_bit=$vtoy_wimboot_bit vt_wimkernel=$vt_wimkernel
1005 vt_windows_wimboot_data "$vtoy_wimboot_prefix/sources/boot.wim" vtoy_init_exe vtoy_wim_bit
1007 if [ "$grub_platform" = "pc" ]; then
1008 linux16 "$vtoy_path/$vt_wimkernel" quiet
1011 vt_set_wim_load_prompt 1 "Loading files......"
1012 initrd16 newc:winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
1013 newc:vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd \
1014 newc:bcd:$vtoy_wimboot_prefix/boot/bcd \
1015 newc:boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi \
1016 newc:boot.wim:$vtoy_wimboot_prefix/sources/boot.wim
1017 vt_set_wim_load_prompt 0
1020 vt_set_wim_load_prompt 1 "Loading files......"
1021 vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/sources/boot.wim vtoy_wimfile_mem
1022 vt_set_wim_load_prompt 0
1024 if [ $? -eq 0 ]; then
1025 set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
1027 set vtoy_wimfile_path=$vtoy_wimboot_prefix/sources/boot.wim
1031 chainloader "$vtoy_path/$vt_wimkernel" quiet \
1032 "vf=winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
1033 "vf=vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd" \
1034 "vf=bcd:$vtoy_wimboot_prefix/boot/bcd" \
1035 "vf=boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi" \
1036 "vf=boot.wim:$vtoy_wimfile_path" \
1037 pfsize=$vtoy_chain_file_size \
1038 pfread=$vtoy_chain_file_read
1044 function vtoy_winpe_wimboot {
1045 unset vtoy_boot_sdi_legacy
1046 unset vtoy_boot_sdi_efi
1048 set vtoy_wimboot_prefix=(loop)
1049 set vtoy_wim_path="$1"
1051 if [ -n "${vtdebug_flag}" ]; then
1052 echo "winpe_wimboot $1 $2 $3"
1055 if [ "$2" != "0" ]; then
1056 set vtoy_boot_sdi_legacy="newc:boot.sdi:$vtoy_wimboot_prefix/$2"
1057 set vtoy_boot_sdi_efi="vf=boot.sdi:$vtoy_wimboot_prefix/$2"
1060 vt_windows_wimboot_data $vtoy_wimboot_prefix/$vtoy_wim_path vtoy_init_exe vtoy_wim_bit
1062 if [ "$grub_platform" = "pc" ]; then
1063 linux16 "$vtoy_path/$vt_wimkernel" quiet
1066 vt_set_wim_load_prompt 1 "Loading files......"
1067 initrd16 newc:$vtoy_init_exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
1068 newc:vtoy_wimboot:$vtoy_path/$vt_wimkernel \
1069 newc:bootmgr.exe:mem:${vtoy_pe_bootmgr_mem_addr}:size:${vtoy_pe_bootmgr_mem_size} \
1070 newc:bcd:mem:${vtoy_pe_bcd_mem_addr}:size:${vtoy_pe_bcd_mem_size} \
1071 $vtoy_boot_sdi_legacy \
1072 newc:boot.wim:$vtoy_wimboot_prefix/$vtoy_wim_path
1073 vt_set_wim_load_prompt 0
1076 if [ "$VTOY_EFI_ARCH" = "x64" -a "$vtoy_wim_bit" = "32" ]; then
1077 echo -e "\nThis is 32bit Windows and does NOT support x86_64 UEFI firmware.\n"
1078 echo -e "这是32位的 Windows 系统,不支持当前的64位 UEFI 环境。\n"
1081 vt_set_wim_load_prompt 1 "Loading files......"
1082 vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/$vtoy_wim_path vtoy_wimfile_mem
1083 vt_set_wim_load_prompt 0
1085 if [ $? -eq 0 ]; then
1086 set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
1088 set vtoy_wimfile_path=$vtoy_wimboot_prefix/$vtoy_wim_path
1091 unset vtoy_boot_efi_path
1092 if [ -F (loop)/efi/boot/boot${VTOY_EFI_ARCH}.efi ]; then
1093 set vtoy_boot_efi_path="vf=bootx64.efi:(loop)/efi/boot/boot${VTOY_EFI_ARCH}.efi"
1097 chainloader "$vtoy_path/$vt_wimkernel" quiet \
1098 "vf=$vtoy_init_exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
1099 "vf=vtoy_wimboot:$vtoy_path/$vt_wimkernel" \
1100 "vf=bcd:mem:${vtoy_pe_bcd_mem_addr}:size:${vtoy_pe_bcd_mem_size}" \
1101 "$vtoy_boot_sdi_efi" \
1102 "$vtoy_boot_efi_path" \
1103 "vf=boot.wim:$vtoy_wimfile_path" \
1104 pfsize=$vtoy_chain_file_size \
1105 pfread=$vtoy_chain_file_read
1111 function vtoy_wimboot_func {
1112 if [ "$grub_platform" = "pc" ]; then
1113 set vt_wimkernel=wimboot.x86_64.xz
1115 if [ "$grub_cpu" = "i386" ]; then
1116 set vt_wimkernel=wimboot.i386.efi.xz
1118 set vt_wimkernel=wimboot.x86_64.xz
1122 if vt_is_standard_winiso (loop); then
1123 echo -e "\n==================== VENTOY WIMBOOT ==================\n"
1124 vtoy_windows_wimboot
1126 vt_sel_winpe_wim (loop)
1127 if [ -n "$vtoy_pe_wim_path" ]; then
1128 echo -e "\n==================== VENTOY WIMBOOT ==================\n"
1131 vt_load_file_to_mem "auto" $vtoy_path/common_bcd.xz vtoy_pe_bcd_mem
1134 for vsdi in "boot/boot.sdi" "2K10/FONTS/boot.sdi" "SSTR/boot.sdi" "ISPE/BOOT.SDI" \
1135 "boot/uqi.sdi" "ISYL/boot.sdi" "WEPE/WEPE.SDI" ; do
1136 if [ -F "(loop)/$vsdi" ]; then
1137 set vt_sdi_path=$vsdi
1142 if [ "$grub_platform" = "pc" ]; then
1143 vt_load_file_to_mem "auto" $vtoy_path/common_bootmgr.xz vtoy_pe_bootmgr_mem
1144 vtoy_winpe_wimboot "$vtoy_pe_wim_path" "$vt_sdi_path" 1
1146 vtoy_winpe_wimboot "$vtoy_pe_wim_path" "$vt_sdi_path" 0
1154 function legacy_windows_menu_func {
1157 unset vt_cur_wimboot_mode
1158 if vt_check_mode 4 "$vt_chosen_name"; then
1159 set vt_cur_wimboot_mode=1
1162 if [ "$ventoy_compatible" = "NO" -o "$vt_cur_wimboot_mode" = "1" ]; then
1163 if [ "$ventoy_fs_probe" = "iso9660" ]; then
1165 vt_iso9660_nojoliet 1
1166 loopback loop "$1$2"
1169 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD" "boot/bce"; do
1170 vt_windows_collect_wim_patch bcd (loop)/$file
1173 distro_specify_wim_patch
1175 vt_windows_count_wim_patch vt_wim_cnt
1176 if [ $vt_wim_cnt -eq 0 ]; then
1177 distro_specify_wim_patch_phase2
1181 if [ -z "$vt_cur_wimboot_mode" ]; then
1182 locate_wim "${chosen_path}"
1186 vt_windows_chain_data "${1}${chosen_path}"
1189 if [ "$vt_cur_wimboot_mode" = "1" ]; then
1193 if [ -n "$vtoy_chain_mem_addr" ]; then
1194 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1195 if [ "$ventoy_compatible" = "NO" ]; then
1196 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1198 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1202 echo "chain empty failed"
1207 function legacy_linux_menu_func {
1208 if [ "$ventoy_compatible" = "NO" ]; then
1210 if [ "$ventoy_fs_probe" = "udf" ]; then
1212 set ventoy_fs_probe=iso9660
1213 loopback loop "$1$2"
1217 if vt_syslinux_need_nojoliet "$1$2"; then
1218 vt_iso9660_nojoliet 1
1220 loopback loop "$1$2"
1223 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
1225 vt_linux_clear_initrd
1227 if [ -d (loop)/pmagic ]; then
1228 vt_linux_specify_initrd_file /pmagic/initrd.img
1230 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
1231 if [ -d (loop)/$dir ]; then
1232 vt_linux_parse_initrd_isolinux (loop)/$dir/
1237 # special process for special distros
1239 if [ -d (loop)/arch/boot/syslinux ]; then
1240 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
1241 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
1242 elif [ -d (loop)/anarchy/boot/syslinux ]; then
1243 vt_linux_parse_initrd_isolinux (loop)/anarchy/boot/syslinux/ /anarchy/
1246 elif [ -d (loop)/manjaro ]; then
1247 if [ -e (loop)/boot/grub/kernels.cfg ]; then
1248 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
1250 elif [ -e (loop)/boot/grub/grub.cfg ]; then
1251 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
1254 distro_specify_initrd_file
1256 vt_linux_initrd_count vtcount
1257 if [ $vtcount -eq 0 ]; then
1258 if [ -d (loop)/rancheros ]; then
1259 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
1262 distro_specify_initrd_file_phase2
1268 vt_linux_chain_data "${1}${chosen_path}"
1271 if [ -n "$vtoy_chain_mem_addr" ]; then
1273 if vt_check_mode 3 "$vt_chosen_name"; then
1275 elif vt_str_begin "$vt_volume_id" "HOLO_"; then
1276 if [ -d (loop)/loader/entries ]; then
1281 if [ -n "$vtGrub2Mode" ]; then
1282 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1286 set vtback_root=$root
1288 set vtback_theme=$theme
1291 vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
1292 vt_set_boot_opt rdinit=/vtoy/vtoy
1295 set vtback_cfg_find=0
1296 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
1297 if [ -e "$cfg" ]; then
1298 set vtback_cfg_find=1
1303 if [ $vtback_cfg_find -eq 0 ]; then
1304 if [ -f (loop)/loader/loader.conf -a -d (loop)/loader/entries ]; then
1305 if vt_str_begin "$vt_volume_id" "HOLO_"; then
1307 vt_systemd_menu (loop,2) vt_sys_menu_mem
1309 vt_systemd_menu (loop) vt_sys_menu_mem
1311 set vtback_cfg_find=1
1312 configfile "mem:${vt_sys_menu_mem_addr}:size:${vt_sys_menu_mem_size}"
1317 set root=$vtback_root
1318 set theme=$vtback_theme
1322 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1323 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1327 echo "chain empty failed"
1333 function legacy_unix_menu_func {
1334 ventoy_unix_comm_proc $1 "${chosen_path}"
1336 if [ -n "$vtoy_chain_mem_addr" ]; then
1337 #ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1338 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1341 echo "chain empty failed"
1347 function legacy_iso_menu_func {
1349 if [ -d (loop)/ ]; then
1353 set chosen_path="$2"
1355 vt_select_auto_install "${chosen_path}"
1356 vt_select_persistence "${chosen_path}"
1358 if vt_is_udf "${1}${chosen_path}"; then
1359 set ventoy_fs_probe=udf
1361 set ventoy_fs_probe=iso9660
1362 ventoy_reset_nojoliet
1365 loopback loop "${1}${chosen_path}"
1369 if [ -n "$vtcompat" ]; then
1370 set ventoy_compatible=YES
1372 elif vt_check_mode 1 "$vt_chosen_name"; then
1373 set ventoy_compatible=YES
1375 vt_check_compatible (loop)
1378 if vt_need_secondary_menu "$vt_chosen_name"; then
1379 vt_show_secondary_menu "$vt_chosen_path" "$vtoy_os" $vt_chosen_size
1380 if vt_check_mode 0 "$vt_chosen_name"; then
1381 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1382 vt_secondary_recover_mode
1387 vt_img_sector "${1}${chosen_path}"
1389 if [ "$ventoy_fs_probe" = "iso9660" ]; then
1390 vt_select_conf_replace "${1}" "${chosen_path}"
1393 if [ "$vtoy_os" = "Windows" ]; then
1394 vt_check_compatible_pe (loop)
1395 legacy_windows_menu_func "$1" "${chosen_path}"
1396 elif [ "$vtoy_os" = "Unix" ]; then
1397 legacy_unix_menu_func "$1" "${chosen_path}"
1399 vt_check_compatible_linux (loop)
1400 legacy_linux_menu_func "$1" "${chosen_path}"
1402 vt_secondary_recover_mode
1405 function legacy_iso_memdisk {
1407 linux16 $vtoy_path/memdisk iso raw
1408 echo "Loading ISO file to memory ..."
1414 function iso_endless_os_proc {
1415 if [ -d (loop)/ ]; then
1419 loopback loop "${1}${2}"
1420 vt_img_sector "${1}${2}"
1422 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
1423 vt_trailer_cpio "$1" "$2" noinit
1427 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
1430 set ventoy_bls_bootdev=/boot
1431 set ventoy_loading_tip="Loading files ......"
1434 configfile (loop)/endless/grub/grub.cfg
1437 unset ventoy_bls_bootdev
1438 unset ventoy_loading_tip
1444 function ventoy_iso_busybox_ver {
1446 if [ "$VTOY_EFI_ARCH" = "aa64" ]; then
1447 set ventoy_busybox_ver=a64
1448 elif [ "$VTOY_EFI_ARCH" = "mips" ]; then
1449 set ventoy_busybox_ver=m64
1451 set ventoy_busybox_ver=32
1453 #special process for deepin-live iso
1454 if [ "$vt_chosen_size" = "403701760" ]; then
1455 if vt_str_str "$vt_chosen_path" "/deepin-live"; then
1456 set ventoy_busybox_ver=64
1458 elif vt_str_begin "$vt_volume_id" "PHOTON_"; then
1459 set ventoy_busybox_ver=64
1460 elif vt_str_begin "$vt_volume_id" "smgl-test-quinq-x86_64"; then
1461 set ventoy_busybox_ver=64
1462 elif vt_str_begin "$vt_volume_id" "LDiagBootable"; then
1463 set ventoy_busybox_ver=64
1470 function iso_common_menuentry {
1474 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1476 vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id vt_volume_space
1477 if [ $vt_volume_space -NE $vt_chosen_size ]; then
1478 vt_mod $vt_chosen_size 2048 vt_chosen_size_mod
1479 if [ $vt_chosen_size_mod -ne 0 ]; then
1480 echo -e "\n $vt_volume_space $vt_chosen_size $vt_chosen_size_mod\n"
1481 echo -e "\n The size of the iso file \"$vt_chosen_size\" is invalid. File corrupted ?\n"
1482 echo -e " 此ISO文件的大小 \"$vt_chosen_size\" 有问题,请确认文件是否损坏。\n"
1483 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
1488 if vt_check_password "${vt_chosen_path}"; then
1492 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1496 if vt_str_begin "$vt_volume_id" "Avira"; then
1497 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
1500 ventoy_iso_busybox_ver
1502 #special process for Endless OS
1503 if vt_str_begin "$vt_volume_id" "Endless-OS"; then
1504 iso_endless_os_proc $vtoy_iso_part "$vt_chosen_path"
1505 elif vt_str_begin "$vt_volume_id" "TENS-Public"; then
1510 # auto memdisk mode for some special ISO files
1511 vt_iso_vd_id_parse "${vtoy_iso_part}${vt_chosen_path}"
1513 if vt_check_mode 0 "$vt_chosen_name"; then
1516 if [ "$grub_platform" = "pc" ]; then
1517 if vt_iso_vd_id_begin 1 0 "Memtest86+"; then
1519 elif vt_iso_vd_id_begin 0 1 "KolibriOS"; then
1525 if [ $vt_chosen_size -LE 67108864 ]; then
1526 if vt_str_begin "$vt_chosen_name" "iKuai"; then
1534 if [ "$grub_platform" = "pc" ]; then
1535 if [ -n "$vtMemDiskBoot" ]; then
1536 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1538 legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
1541 if [ -n "$vtMemDiskBoot" ]; then
1542 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1544 uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
1549 function miso_common_menuentry {
1550 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1552 if vt_check_password "${vt_chosen_path}"; then
1556 echo "memdisk mode boot for $vt_chosen_path"
1560 if [ "$grub_platform" = "pc" ]; then
1561 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1563 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1568 function common_unsupport_menuentry {
1569 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
1570 echo -e " 文件名中不能有中文或空格 \n"
1571 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1575 function miso_unsupport_menuentry {
1576 common_unsupport_menuentry
1579 function iso_unsupport_menuentry {
1580 common_unsupport_menuentry
1583 function wim_common_menuentry {
1584 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1586 if vt_check_password "${vt_chosen_path}"; then
1590 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1594 if vt_wim_check_bootable "${vtoy_iso_part}${vt_chosen_path}"; then
1595 vt_wim_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1597 echo -e "\n This is NOT a bootable WIM file. \n"
1598 echo -e " 这不是一个可启动的 WIM 文件。\n"
1603 if [ -n "$vtoy_chain_mem_addr" ]; then
1604 if [ "$grub_platform" = "pc" ]; then
1605 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1608 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}
1613 echo "chain empty failed"
1618 function wim_unsupport_menuentry {
1619 common_unsupport_menuentry
1622 function efi_common_menuentry {
1623 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1625 if vt_check_password "${vt_chosen_path}"; then
1629 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1634 if vt_is_vlnk_name "${vt_chosen_path}"; then
1635 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1636 if [ -z "$vt_vlnk_dst" ]; then
1637 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1642 vt_vlnk_dst="${vtoy_iso_part}${vt_chosen_path}"
1649 #first try with chainload
1651 set root=$vtoy_iso_part
1652 chainloader "${vt_vlnk_dst}"
1657 vt_concat_efi_iso "${vt_vlnk_dst}" vtoy_iso_buf
1658 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}
1664 function efi_unsupport_menuentry {
1665 common_unsupport_menuentry
1668 function vhdboot_common_func {
1669 vt_patch_vhdboot "$1"
1673 if [ -n "$vtoy_vhd_buf_addr" ]; then
1674 if [ "$grub_platform" = "pc" ]; then
1676 linux16 $vtoy_path/memdisk iso raw
1677 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1682 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}
1687 echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
1692 function vhd_common_menuentry {
1693 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1695 if vt_check_password "${vt_chosen_path}"; then
1699 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1704 if vt_is_vlnk_name "${vt_chosen_path}"; then
1705 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1706 if [ -z "$vt_vlnk_dst" ]; then
1707 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1712 vt_vlnk_dst="${vt_chosen_path}"
1713 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
1714 if [ "$vtoy_iso_fs" != "ntfs" ]; then
1715 echo -e "!!! WARNING !!!\n"
1716 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
1717 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
1718 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
1724 vhdboot_common_func "${vt_vlnk_dst}"
1727 function vhd_unsupport_menuentry {
1728 common_unsupport_menuentry
1731 function vtoyboot_common_func {
1735 vt_get_vtoy_type "${1}" vtoytype parttype AltBootPart
1737 if vt_str_begin $vtoytype vhd; then
1739 elif [ "$vtoytype" = "raw" ]; then
1741 elif [ "$vtoytype" = "vdi" ]; then
1745 if [ $vtoysupport -eq 1 ]; then
1746 if [ "$grub_platform" = "pc" ]; then
1747 if [ "$parttype" = "gpt" -a $AltBootPart -eq 0 ]; then
1748 echo "The OS in the vdisk was created in UEFI mode, but current is Legacy BIOS mode."
1749 echo "虚拟磁盘内的系统是在UEFI模式下创建的,而当前系统是Legacy BIOS模式,可能无法正常启动。"
1753 if [ "$parttype" = "mbr" -a $AltBootPart -eq 0 ]; then
1754 echo "The OS in the vdisk was created in Legacy BIOS mode, but current is UEFI mode."
1755 echo "虚拟磁盘内的系统是在Legacy BIOS模式下创建的,而当前系统是UEFI模式,可能无法正常启动。"
1760 vt_img_sector "${1}"
1761 vt_raw_chain_data "${1}"
1765 if [ -n "$vtoy_chain_mem_addr" ]; then
1766 if [ "$grub_platform" = "pc" ]; then
1767 vt_acpi_param ${vtoy_chain_mem_addr} 512
1768 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} bios80 sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1771 if vt_check_secureboot_var; then
1772 vt_acpi_param ${vtoy_chain_mem_addr} 512
1775 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}
1780 echo "chain empty failed!"
1784 echo "Unsupported vtoy type $vtoytype"
1789 function vtoy_common_menuentry {
1790 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1792 if vt_check_password "${vt_chosen_path}"; then
1796 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1801 if vt_is_vlnk_name "${vt_chosen_path}"; then
1802 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1803 if [ -z "$vt_vlnk_dst" ]; then
1804 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1809 vt_vlnk_dst="${vtoy_iso_part}${vt_chosen_path}"
1812 vtoyboot_common_func "${vt_vlnk_dst}"
1815 function vtoy_unsupport_menuentry {
1816 common_unsupport_menuentry
1820 #============================================================#
1821 # IMG file boot process #
1822 #============================================================#
1825 function only_uefi_tip {
1826 echo -e "\n This IMG file is only supported in UEFI mode. \n"
1827 echo -e "\n press ENTER to exit ..."
1831 function ventoy_img_easyos {
1832 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1833 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1835 loopback easysfs (vtimghd,1)/easy.sfs
1836 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1838 if [ -n "$vt_module_ver" ]; then
1839 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1840 if [ -e (easysfs)/lib/modules/$vt_module_ver/$mod ]; then
1841 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1849 vt_set_boot_opt rdinit=/vtoy/vtoy
1852 syslinux_configfile (vtimghd,1)/syslinux.cfg
1859 function ventoy_img_easyos2 {
1860 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1861 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1863 if [ -e (vtimghd,2)/easyos/easy.sfs ]; then
1864 loopback easysfs (vtimghd,2)/easyos/easy.sfs
1865 elif [ -d (vtimghd,2)/easyos/releases ]; then
1866 vt_fs_enum_1st_dir (vtimghd,2) /easyos/releases/ vt_dir_name
1867 loopback easysfs (vtimghd,2)/easyos/releases/$vt_dir_name/easy.sfs
1870 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1872 if [ -n "$vt_module_ver" ]; then
1873 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1874 if [ -e (easysfs)/lib/modules/$vt_module_ver/$mod ]; then
1875 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1883 vt_set_boot_opt rdinit=/vtoy/vtoy
1886 vt_limine_menu (vtimghd,1)/limine.cfg vt_sys_menu_mem
1887 configfile "mem:${vt_sys_menu_mem_addr}:size:${vt_sys_menu_mem_size}"
1894 function ventoy_img_volumio {
1895 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1896 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1901 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1904 syslinux_configfile (vtimghd,1)/syslinux.cfg
1910 function ventoy_img_openelec {
1913 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1914 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1916 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1917 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1922 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1925 set root=(vtimghd,1)
1926 syslinux_configfile (vtimghd,1)/syslinux.cfg
1930 loopback -d vtloopex
1934 function ventoy_img_freedombox {
1935 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1936 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1938 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1939 if [ -n "$vt_module_ver" ]; then
1940 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1946 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1949 configfile (vtimghd,1)/boot/grub/grub.cfg
1955 function ventoy_img_paldo {
1956 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1957 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1962 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1965 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1966 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1968 echo loading file...
1969 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1970 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1977 function ventoy_img_ubos {
1978 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1979 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1981 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1982 if [ -n "$vt_module_ver" ]; then
1983 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1989 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1992 echo loading file...
1993 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1994 initrd (vtimghd,2)/initramfs-linux.img
2001 function ventoy_img_recalbox {
2002 if [ $vtoy_img_max_part_end -GT $vt_chosen_size ]; then
2003 echo -e "\nPlease extend the img file size before boot it. \n"
2008 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2009 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2011 if [ -e (vtimghd,1)/boot/recalbox ]; then
2012 loopback recalbox (vtimghd,1)/boot/recalbox
2013 vt_get_lib_module_ver (recalbox) /lib/modules/ vt_module_ver
2014 if [ -n "$vt_module_ver" ]; then
2015 vt_img_extra_initrd_append (recalbox)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
2022 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
2025 set root=(vtimghd,1)
2026 configfile (vtimghd,1)/boot/grub/grub.cfg
2032 function ventoy_img_esysrescue {
2033 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2034 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2039 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=esysrescue
2042 set root=(vtimghd,1)
2043 configfile (vtimghd,1)/boot/grub/grub.cfg
2049 function ventoy_img_batocera {
2050 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2051 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2056 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
2059 set root=(vtimghd,1)
2060 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
2066 function ventoy_img_openwrt {
2067 if [ -e (vtimghd,2)/lib64 ]; then
2068 set ventoy_busybox_ver=64
2071 vt_fs_enum_1st_dir (vtimghd,2) /lib/modules/ vt_dir_name
2073 if [ -f (vtimghd,2)/lib/modules/$vt_dir_name/dm-mod.ko ]; then
2074 set openwrt_plugin_need=0
2075 vt_img_extra_initrd_append (vtimghd,2)/lib/modules/$vt_dir_name/dm-mod.ko
2076 if [ -f (vtimghd,2)/lib/modules/$vt_dir_name/dax.ko ]; then
2077 vt_img_extra_initrd_append (vtimghd,2)/lib/modules/$vt_dir_name/dax.ko
2080 set openwrt_plugin_need=1
2081 if [ ! -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
2083 echo -e "\n ventoy_openwrt.xz not found. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
2084 echo -e " 未找到 ventoy_openwrt.xz 文件。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
2085 echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
2092 if vt_img_check_range "${vtoy_iso_part}${vt_chosen_path}"; then
2096 echo -e "\n IMG file need processed. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
2097 echo -e " 此 IMG 文件必须处理之后才能支持。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
2098 echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
2104 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2105 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2107 if [ $openwrt_plugin_need -eq 1 ]; then
2108 if [ -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
2109 vt_img_extra_initrd_append ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz
2114 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=openwrt
2117 set root=(vtimghd,1)
2118 configfile (vtimghd,1)/boot/grub/grub.cfg
2124 function ventoy_img_tails {
2125 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2126 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2131 vt_set_boot_opt rdinit=/vtoy/vtoy live-media=/dev/dm-1 ventoyos=tails
2134 set root=(vtimghd,1)
2135 configfile (vtimghd,1)/efi/debian/grub.cfg
2141 function ventoy_img_fydeos {
2142 if [ "$grub_platform" = "pc" ]; then
2147 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=64"
2148 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2153 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=fydeos
2156 set grubdisk=vtimghd
2157 set grubpartA=(vtimghd,3)
2158 set grubpartB=(vtimghd,5)
2159 set linuxpartA=(sda,3)
2160 set linuxpartB=(sda,5)
2162 set root=(vtimghd,12)
2163 configfile (vtimghd,12)/efi/boot/grub.cfg
2175 function ventoy_img_cloudready {
2176 if [ "$grub_platform" = "pc" ]; then
2181 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=64"
2182 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2187 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=cloudready
2190 set grubdisk=vtimghd
2191 set grubpartA=(vtimghd,3)
2192 set grubpartB=(vtimghd,5)
2193 set linuxpartA=(sda,3)
2194 set linuxpartB=(sda,5)
2196 set root=(vtimghd,12)
2197 configfile (vtimghd,12)/efi/boot/grub.cfg
2209 function ventoy_img_memtest86 {
2210 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
2214 function img_unsupport_tip {
2215 echo -e "\n This IMG file is NOT supported now. \n"
2216 echo -e " 当前不支持启动此 IMG 文件 \n"
2217 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
2221 function legacy_img_memdisk {
2222 linux16 $vtoy_path/memdisk
2223 echo "Loading img file to memory ..."
2230 function img_common_menuentry {
2231 set ventoy_compatible=YES
2232 set ventoy_busybox_ver=32
2233 unset LoadIsoEfiDriver
2235 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
2237 if vt_check_password "${vt_chosen_path}"; then
2241 if ventoy_vcfg_proc "${vt_chosen_path}"; then
2245 if [ "$grub_platform" = "pc" ]; then
2246 if vt_check_mode 0 "$vt_chosen_name"; then
2247 legacy_img_memdisk $vtoy_iso_part "$vt_chosen_path"
2252 loopback vtimghd "${vtoy_iso_part}${vt_chosen_path}"
2253 vt_img_sector "${vtoy_iso_part}${vt_chosen_path}"
2255 vt_img_part_info (vtimghd)
2257 set vtback_root=$root
2260 set vtback_theme=$theme
2263 vt_img_extra_initrd_reset
2266 vt_get_fs_label (vtimghd,1) vtImgHd1Label
2268 if [ "$vtImgHd1Label" = "STATE" ]; then
2269 vt_get_fs_label (vtimghd,3) vtImgHd3Label
2270 elif [ -d (vtimghd,2)/lib ]; then
2271 vt_get_fs_label (vtimghd,2) vtImgHd2Label
2274 if [ -e (vtimghd,1)/etc/hostname ]; then
2275 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
2278 if vt_str_begin "$vtImgHd3Label" "ROOT-"; then
2279 if [ -f (vtimghd,3)/etc/os-release.d/ID ]; then
2280 vt_1st_line (vtimghd,3)/etc/os-release.d/ID vt_release_line1
2281 if vt_str_begin "$vt_release_line1" "FydeOS"; then
2284 ventoy_img_cloudready
2286 elif [ -f (vtimghd,3)/etc/cloudready-release ]; then
2287 ventoy_img_cloudready
2288 elif [ -f (vtimghd,3)/etc/chrome_dev.conf ]; then
2289 ventoy_img_cloudready
2291 elif vt_str_begin "$vtImgHd1Label" "LAKKA"; then
2292 ventoy_img_openelec lakka
2293 elif vt_str_begin "$vtImgHd1Label" "LIBREELEC"; then
2294 ventoy_img_openelec LibreELEC
2295 elif vt_str_begin "$vtImgHd1Label" "paldo-live"; then
2297 elif vt_str_begin "$vtImgHostname" "freedombox"; then
2298 ventoy_img_freedombox
2299 elif vt_str_begin "$vtImgHd1Label" "BATOCERA"; then
2301 elif vt_str_begin "$vtImgHd1Label" "Tails"; then
2303 elif [ "$vtImgHd2Label" = "RECALBOX" -o "$vtImgHd1Label" = "RECALBOX" ]; then
2305 elif [ "$vtImgHd1Label" = "ESYSRESCUE" ]; then
2306 ventoy_img_esysrescue
2307 elif [ -e (vtimghd,1)/easy.sfs ]; then
2309 elif [ -d (vtimghd,2)/easyos ]; then
2311 elif [ -e (vtimghd,1)/volumio.initrd ]; then
2313 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
2315 elif [ -f (vtimghd,2)/etc/openwrt_version ]; then
2317 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
2318 if [ "$grub_platform" = "pc" ]; then
2321 ventoy_img_memtest86
2324 vt_linux_chain_data "${vtoy_iso_part}${vt_chosen_path}"
2325 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
2326 if [ "$grub_platform" = "pc" ]; then
2327 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
2330 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}
2337 set root=$vtback_root
2339 set theme=$vtback_theme
2341 set ventoy_compatible=NO
2344 function img_unsupport_menuentry {
2345 common_unsupport_menuentry
2348 #############################################################
2349 #############################################################
2350 #############################################################
2351 ####### Main Process ###########
2352 #############################################################
2353 #############################################################
2354 #############################################################
2356 set VENTOY_VERSION="1.0.83"
2358 #ACPI not compatible with Window7/8, so disable by default
2359 set VTOY_PARAM_NO_ACPI=1
2361 # Default menu display mode, you can change it as you want.
2364 set VTOY_DEFAULT_MENU_MODE=0
2366 set VTOY_MEM_DISK_STR="[Memdisk]"
2367 set VTOY_ISO_RAW_STR="Compatible Mode"
2368 set VTOY_GRUB2_MODE_STR="GRUB2 Mode"
2369 set VTOY_WIMBOOT_MODE_STR="WIMBOOT Mode"
2370 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
2372 set VTOY_F2_CMD="vt_browser_disk"
2373 set VTOY_F4_CMD="ventoy_localboot"
2374 set VTOY_F5_CMD="ventoy_diagnosis"
2375 set VTOY_F6_CMD="ventoy_ext_menu"
2376 set VTOY_HELP_CMD="ventoy_show_help"
2377 set VTOY_CHKSUM_CMD="ventoy_checksum"
2378 set VTOY_HELP_TXT_LANGUAGE="en_US"
2379 set VTOY_CHKSUM_FILE_PATH="X"
2380 set VTOY_LANG_CMD="ventoy_language"
2383 if [ "$grub_platform" = "pc" ]; then
2384 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
2386 if [ "$grub_cpu" = "i386" ]; then
2387 set VTOY_EFI_ARCH=ia32
2388 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION IA32 www.ventoy.net"
2389 elif [ "$grub_cpu" = "arm64" ]; then
2390 set VTOY_EFI_ARCH=aa64
2391 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION AA64 www.ventoy.net"
2392 elif [ "$grub_cpu" = "mips64el" ]; then
2393 set VTOY_EFI_ARCH=mips
2394 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION MIPS www.ventoy.net"
2396 set VTOY_EFI_ARCH=x64
2397 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
2401 vt_device $root vtoy_dev
2403 if [ "$vtoy_dev" = "tftp" ]; then
2404 set vtoy_path=($root)
2405 for vtid in 0 1 2 3; do
2406 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
2407 set vtoy_iso_part=(hd$vtid,1)
2408 set vtoy_efi_part=(hd$vtid,2)
2415 if [ -n "$vtoy_efi_part" ]; then
2416 vt_load_file_to_mem "auto" $vtoy_efi_part/grub/fonts/unicode.pf2 vtoy_font_mem
2417 loadfont mem:${vtoy_font_mem_addr}:size:${vtoy_font_mem_size}
2420 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
2421 set vt_plugin_path=$vtoy_iso_part
2423 set vt_plugin_path=$prefix
2424 vt_load_plugin $vt_plugin_path
2427 if [ "$prefix" = "(ventoydisk)/grub" ]; then
2428 set vtoy_path=(ventoydisk)/ventoy
2430 set vtoy_path=($root)/ventoy
2433 set vtoydev=$vtoy_dev
2434 set vtoy_iso_part=($vtoy_dev,1)
2435 set vtoy_efi_part=($vtoy_dev,2)
2437 vt_load_file_to_mem "auto" $prefix/fonts/unicode.pf2 vtoy_font_mem
2438 loadfont mem:${vtoy_font_mem_addr}:size:${vtoy_font_mem_size}
2440 set vt_plugin_path=$vtoy_iso_part
2443 #Load Partition Table
2444 vt_load_part_table $vtoydev
2446 #Load menu lang file
2447 ventoy_load_menu_lang_file
2450 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
2452 vt_load_plugin $vtoy_iso_part
2455 vt_check_json_path_case $vtoy_iso_part
2459 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
2460 set timeout=$VTOY_MENU_TIMEOUT
2465 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
2466 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
2467 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
2468 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
2471 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
2472 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
2473 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
2474 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
2478 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
2479 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
2481 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
2484 terminal_output console
2486 if [ -n "$vtoy_gfxmode" ]; then
2487 set gfxmode=$vtoy_gfxmode
2490 set gfxmode=1024x768
2495 if [ "$vtoy_display_mode" = "CLI" ]; then
2496 terminal_output console
2497 elif [ "$vtoy_display_mode" = "serial" ]; then
2498 if [ -n "$vtoy_serial_param" ]; then
2499 serial $vtoy_serial_param
2501 terminal_input serial
2502 terminal_output serial
2503 elif [ "$vtoy_display_mode" = "serial_console" ]; then
2504 if [ -n "$vtoy_serial_param" ]; then
2505 serial $vtoy_serial_param
2507 terminal_input serial console
2508 terminal_output serial console
2510 if [ -n "$vtoy_theme" ]; then
2513 set theme=$prefix/themes/ventoy/theme.txt
2515 terminal_output gfxterm
2518 if [ "$grub_platform" = "efi" ]; then
2519 set mouse_delta=4000
2520 # terminal_input --append mouse
2523 if [ -n "$VTOY_DEFAULT_KBD_LAYOUT" ]; then
2524 set_keyboard_layout "$VTOY_DEFAULT_KBD_LAYOUT"
2527 if [ -n "$VTOY_PLUGIN_PATH_CASE_MISMATCH" ]; then
2529 echo "$VTOY_PLUGIN_PATH_CASE_MISMATCH"
2530 echo -e "\n\nPath case does not match! ventoy directory and ventoy.json MUST be all lowercase!"
2531 echo -e "\n路径大小写不匹配!ventoy 目录和 ventoy.json 文件的名字必须是全部小写,请修正!"
2532 echo -e "\n\npress ENTER to continue (请按回车键继续) ..."
2536 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
2538 if [ -n "$VTOY_PLUGIN_ENCODE_ERROR" ]; then
2539 echo -e "\n Encoding type for ventoy.json is not supported, please convert to UTF-8.\n"
2540 echo -e " ventoy.json 文件编码格式不支持,请转换为 UTF-8 编码格式!\n"
2542 echo -e "\n Syntax error detected in ventoy.json, please check! \n"
2543 echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
2546 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
2551 for vtTFile in ventoy.json ventoy_grub.cfg; do
2552 if [ -f $vtoy_efi_part/ventoy/$vtTFile ]; then
2554 echo -e "\n You need to put $vtTFile in the 1st partition which hold the ISO files.\n"
2555 echo -e " $vtTFile 放错分区了,请放到镜像分区里的 ventoy 目录下(此目录需要手动创建)!\n"
2556 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
2561 #clear all input key before show main menu
2564 #export necessary variable
2572 export vtoy_iso_part
2573 export vtoy_efi_part
2574 export VENTOY_VERSION
2575 export VTOY_CUR_VIDEO_MODE
2576 export VTOY_EFI_ARCH
2577 export VTOY_MEM_DISK_STR
2578 export VTOY_ISO_RAW_STR
2579 export VTOY_GRUB2_MODE_STR
2580 export VTOY_WIMBOOT_MODE_STR
2581 export VTOY_ISO_UEFI_DRV_STR
2586 export VTOY_HELP_CMD
2587 export VTOY_CHKSUM_CMD
2588 export VTOY_HELP_TXT_LANGUAGE
2589 export VTOY_CHKSUM_FILE_PATH
2590 export VTOY_LANG_CMD
2593 #colect all image files (iso files)
2594 set ventoy_img_count=0
2595 vt_list_img $vtoy_iso_part ventoy_img_count
2598 if [ $ventoy_img_count -gt 0 ]; then
2599 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
2605 if [ -n "$VTOY_NO_ISO_TIP" ]; then
2606 NO_ISO_MENU="No ISO or supported IMG files found, $VTOY_NO_ISO_TIP"
2607 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
2608 NO_ISO_MENU="No ISO or supported IMG files found, please check VTOY_DEFAULT_SEARCH_ROOT"
2610 NO_ISO_MENU="No ISO or supported IMG files found"
2612 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
2613 echo -e "\n Rebooting ... "
2619 #special VTOY_DEFAULT_IMAGE process
2620 if [ -n "$VTOY_DEFAULT_IMAGE" ]; then
2621 if regexp --set 1:vtHotkey --set 2:vtDefault "(F[2-9])>(.*)" "$VTOY_DEFAULT_IMAGE"; then
2623 set default="$vtDefault"
2624 if [ -z "$VTOY_MENU_TIMEOUT" ]; then
2627 set timeout=$VTOY_MENU_TIMEOUT
2635 if [ "$vtHotkey" = "F2" ]; then
2638 elif [ "$vtHotkey" = "F4" ]; then
2640 elif [ "$vtHotkey" = "F5" ]; then
2642 elif [ "$vtHotkey" = "F6" ]; then