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_power {
48 configfile $prefix/power.cfg
51 function ventoy_diagnosis {
52 configfile $prefix/debug.cfg
55 function ventoy_localboot {
56 configfile $prefix/localboot.cfg
59 function ventoy_ext_menu {
60 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
61 set ventoy_new_context=1
62 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
63 unset ventoy_new_context
65 echo "ventoy_grub.cfg NOT exist."
66 echo -e "\npress ENTER to exit ..."
71 function get_os_type {
74 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
75 if vt_file_exist_nocase (loop)/$file; then
81 if [ "$vtoy_os" = "Linux" ]; then
82 if vt_strstr "$vt_system_id" "FreeBSD"; then
84 set vt_unix_type=FreeBSD
85 elif [ -e (loop)/bin/freebsd-version ]; then
87 set vt_unix_type=FreeBSD
90 elif [ -e (loop)/boot/kernel/kernel ]; then
91 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
93 set vt_unix_type=FreeBSD
94 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
96 set vt_unix_type=NetBSD
101 if [ -n "${vtdebug_flag}" ]; then
106 function vt_check_compatible_pe {
107 #Check for PE without external tools
108 if [ -f $1/HBCD_PE.ini ]; then
109 set ventoy_compatible=YES
113 function locate_initrd {
114 vt_linux_locate_initrd
116 if [ -n "${vtdebug_flag}" ]; then
122 function locate_wim {
123 vt_windows_locate_wim_patch (loop)
125 if [ -n "${vtdebug_flag}" ]; then
126 echo '###############################################'
128 echo '###############################################'
133 function distro_specify_wim_patch {
134 if [ -d (loop)/h3pe ]; then
135 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
136 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
137 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
138 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
142 function distro_specify_wim_patch_phase2 {
143 if [ -f (loop)/boot/boot.wim ]; then
144 vt_windows_collect_wim_patch wim /boot/boot.wim
149 function distro_specify_initrd_file {
150 if [ -e (loop)/boot/all.rdz ]; then
151 vt_linux_specify_initrd_file /boot/all.rdz
152 elif [ -e (loop)/boot/xen.gz ]; then
153 if [ -e (loop)/install.img ]; then
154 vt_linux_specify_initrd_file /install.img
156 elif [ -d (loop)/casper ]; then
157 if [ -e (loop)/casper/initrd ]; then
158 vt_linux_specify_initrd_file /casper/initrd
160 if [ -e (loop)/casper/initrd-oem ]; then
161 vt_linux_specify_initrd_file /casper/initrd-oem
163 elif [ -e (loop)/boot/grub/initrd.xz ]; then
164 vt_linux_specify_initrd_file /boot/grub/initrd.xz
165 elif [ -e (loop)/initrd.gz ]; then
166 vt_linux_specify_initrd_file /initrd.gz
167 elif [ -e (loop)/slax/boot/initrfs.img ]; then
168 vt_linux_specify_initrd_file /slax/boot/initrfs.img
169 elif [ -e (loop)/pmagic/initrd.img ]; then
170 vt_linux_specify_initrd_file /pmagic/initrd.img
171 elif [ -e (loop)/boot/initrd.xz ]; then
172 vt_linux_specify_initrd_file /boot/initrd.xz
173 elif [ -f (loop)/boot/initrd ]; then
174 vt_linux_specify_initrd_file /boot/initrd
175 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
176 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
177 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
178 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
185 function distro_specify_initrd_file_phase2 {
186 if [ -f (loop)/boot/initrd.img ]; then
187 vt_linux_specify_initrd_file /boot/initrd.img
188 elif [ -f (loop)/Setup/initrd.gz ]; then
189 vt_linux_specify_initrd_file /Setup/initrd.gz
190 elif [ -f (loop)/isolinux/initramfs ]; then
191 vt_linux_specify_initrd_file /isolinux/initramfs
192 elif [ -f (loop)/boot/iniramfs.igz ]; then
193 vt_linux_specify_initrd_file /boot/iniramfs.igz
194 elif [ -f (loop)/initrd-x86_64 ]; then
195 vt_linux_specify_initrd_file /initrd-x86_64
196 elif [ -f (loop)/live/initrd.img ]; then
197 vt_linux_specify_initrd_file /live/initrd.img
198 elif [ -f (loop)/initrd.img ]; then
199 vt_linux_specify_initrd_file /initrd.img
200 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
201 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
202 elif [ -f (loop)/CDlinux/initrd ]; then
203 vt_linux_specify_initrd_file /CDlinux/initrd
204 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
205 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
206 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
207 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
209 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
211 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
212 if [ "$grub_platform" != "pc" ]; then
213 vt_add_replace_file 0 "initrd.img"
215 elif [ -f (loop)/initrd ]; then
216 vt_linux_specify_initrd_file /initrd
217 elif [ -f (loop)/live/initrd1 ]; then
218 vt_linux_specify_initrd_file /live/initrd1
223 function ventoy_get_ghostbsd_ver {
225 # vt_parse_iso_create_date $1/${chosen_path} vt_create_date
226 # if regexp "^202005" "$vt_create_date"; then
227 # set vt_freebsd_ver=12.x
230 set vt_freebsd_ver=12.x
233 function ventoy_get_freenas_ver {
234 set vt_freebsd_ver=11.x
236 if [ -e (loop)/FreeNAS-MANIFEST ]; then
237 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
238 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
239 set vt_freebsd_ver=13.x
240 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
241 set vt_freebsd_ver=12.x
242 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
243 set vt_freebsd_ver=11.x
248 function ventoy_freebsd_proc {
249 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
250 ventoy_get_ghostbsd_ver $1 ${chosen_path}
251 elif vt_strstr "$vt_volume_id" "FREENAS"; then
252 ventoy_get_freenas_ver $1 ${chosen_path}
253 elif regexp "^13_[0-9]" "$vt_volume_id"; then
254 set vt_freebsd_ver=13.x
255 elif regexp "^12_[0-9]" "$vt_volume_id"; then
256 set vt_freebsd_ver=12.x
257 elif regexp "^11_[0-9]" "$vt_volume_id"; then
258 set vt_freebsd_ver=11.x
259 elif regexp "^10_[0-9]" "$vt_volume_id"; then
260 set vt_freebsd_ver=10.x
261 elif regexp "^9_[0-9]" "$vt_volume_id"; then
262 set vt_freebsd_ver=9.x
263 elif [ -e (loop)/bin/freebsd-version ]; then
264 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
265 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
266 set vt_freebsd_ver=13.x
267 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
268 set vt_freebsd_ver=12.x
269 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
270 set vt_freebsd_ver=11.x
271 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
272 set vt_freebsd_ver=10.x
273 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
274 set vt_freebsd_ver=9.x
276 elif [ -e (loop)/README.TXT ]; then
277 vt_1st_line (loop)/README.TXT vt_freebsd_line1
278 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
279 set vt_freebsd_ver=13.x
280 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
281 set vt_freebsd_ver=12.x
282 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
283 set vt_freebsd_ver=11.x
284 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
285 set vt_freebsd_ver=10.x
286 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
287 set vt_freebsd_ver=9.x
289 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
290 set vt_freebsd_ver=9.x
292 set vt_freebsd_ver=12.x
295 set vt_freebsd_bit=64
296 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
297 if [ -e (loop)/$file ]; then
298 if file --is-i386-kfreebsd (loop)/$file; then
299 set vt_freebsd_bit=32
305 if [ -n "${vtdebug_flag}" ]; then
306 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
309 unset vt_unix_mod_path
310 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version"; do
311 if [ -e (loop)${file} ]; then
312 set vt_unix_mod_path=${file}
317 vt_unix_replace_ko $vt_unix_mod_path (vtunix)/ventoy_unix/FreeBSD/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
318 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
321 function ventoy_unix_comm_proc {
324 if [ "$ventoy_compatible" = "NO" ]; then
325 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
327 if [ "$vt_unix_type" = "FreeBSD" ]; then
328 ventoy_freebsd_proc $1 ${chosen_path}
329 elif [ "$vt_unix_type" = "NetBSD" ]; then
330 echo "NetBSD not supported"
335 if [ -n "${vtdebug_flag}" ]; then
336 echo "Unknown unix type"
341 vt_unix_chain_data ${1}${chosen_path}
346 function uefi_windows_menu_func {
349 if [ "$ventoy_compatible" = "NO" ]; then
351 if [ "$ventoy_fs_probe" = "iso9660" ]; then
353 vt_iso9660_nojoliet 1
357 for file in "efi/microsoft/boot/bcd"; do
358 vt_windows_collect_wim_patch bcd (loop)/$file
361 vt_windows_count_wim_patch vt_wim_cnt
362 if [ $vt_wim_cnt -eq 0 ]; then
363 distro_specify_wim_patch_phase2
370 vt_windows_chain_data ${1}${chosen_path}
373 if [ -n "$vtoy_chain_mem_addr" ]; then
375 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
378 echo "chain empty failed"
383 function uefi_linux_menu_func {
384 if [ "$ventoy_compatible" = "NO" ]; then
386 if [ "$ventoy_fs_probe" = "udf" ]; then
388 set ventoy_fs_probe=iso9660
392 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
394 vt_linux_clear_initrd
396 if [ -d (loop)/pmagic ]; then
397 vt_linux_specify_initrd_file /pmagic/initrd.img
399 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
400 if [ -e (loop)/$file ]; then
401 vt_linux_parse_initrd_grub file (loop)/$file
406 # special process for special distros
407 if [ -d (loop)/loader/entries ]; then
408 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
409 elif [ -d (loop)/boot/grub ]; then
410 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
413 distro_specify_initrd_file
415 vt_linux_initrd_count vtcount
416 if [ $vtcount -eq 0 ]; then
417 distro_specify_initrd_file_phase2
419 if [ "$vt_efi_dir" = "NO" ]; then
420 if [ -f (loop)/efi.img ]; then
421 vt_add_replace_file 0 "initrd"
428 if [ -d (loop)/loader/entries ]; then
429 vt_linux_get_main_initrd_index vtindex
431 if [ -d (loop)/arch ]; then
432 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
433 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
434 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
435 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
437 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
438 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
439 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
440 vt_add_replace_file $vtindex "boot\\initrd"
442 elif [ -d (loop)/EFI/boot/entries ]; then
443 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
444 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
446 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
447 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
448 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
453 vt_linux_chain_data ${1}${chosen_path}
455 if [ -n "$vtoy_chain_mem_addr" ]; then
457 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
460 echo "chain empty failed"
465 function uefi_unix_menu_func {
466 ventoy_unix_comm_proc $1 ${chosen_path}
468 if [ -n "$vtoy_chain_mem_addr" ]; then
470 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
473 echo "chain empty failed"
478 function uefi_iso_menu_func {
480 if [ -d (loop)/ ]; then
484 if [ -n "$vtisouefi" ]; then
485 set LoadIsoEfiDriver=on
487 elif vt_check_mode 2; then
488 set LoadIsoEfiDriver=on
490 unset LoadIsoEfiDriver
494 vt_select_auto_install ${chosen_path}
495 vt_select_persistence ${chosen_path}
497 if vt_is_udf ${1}${chosen_path}; then
498 set ventoy_fs_probe=udf
500 set ventoy_fs_probe=iso9660
501 vt_iso9660_nojoliet 0
504 loopback loop ${1}${chosen_path}
507 if [ -d (loop)/EFI ]; then
509 elif [ -d (loop)/efi ]; then
515 if [ -n "$vtcompat" ]; then
516 set ventoy_compatible=YES
518 elif vt_check_mode 1; then
519 set ventoy_compatible=YES
521 vt_check_compatible (loop)
524 vt_img_sector ${1}${chosen_path}
526 if [ "$vtoy_os" = "Windows" ]; then
527 vt_check_compatible_pe (loop)
528 uefi_windows_menu_func $1 ${chosen_path}
529 elif [ "$vtoy_os" = "Unix" ]; then
530 uefi_unix_menu_func $1 ${chosen_path}
532 uefi_linux_menu_func $1 ${chosen_path}
538 function uefi_iso_memdisk {
539 echo 'Loading ISO file to memory ...'
540 vt_load_img_memdisk ${1}${2} vtoy_iso_buf
543 chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
550 function legacy_windows_menu_func {
553 if [ "$ventoy_compatible" = "NO" ]; then
555 if [ "$ventoy_fs_probe" = "iso9660" ]; then
557 vt_iso9660_nojoliet 1
561 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
562 vt_windows_collect_wim_patch bcd (loop)/$file
565 distro_specify_wim_patch
567 vt_windows_count_wim_patch vt_wim_cnt
568 if [ $vt_wim_cnt -eq 0 ]; then
569 distro_specify_wim_patch_phase2
576 vt_windows_chain_data ${1}${chosen_path}
579 if [ -n "$vtoy_chain_mem_addr" ]; then
580 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
583 echo "chain empty failed"
588 function legacy_linux_menu_func {
589 if [ "$ventoy_compatible" = "NO" ]; then
591 if [ "$ventoy_fs_probe" = "udf" ]; then
593 set ventoy_fs_probe=iso9660
597 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
599 vt_linux_clear_initrd
601 if [ -d (loop)/pmagic ]; then
602 vt_linux_specify_initrd_file /pmagic/initrd.img
604 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
605 if [ -d (loop)/$dir ]; then
606 vt_linux_parse_initrd_isolinux (loop)/$dir/
611 # special process for special distros
613 if [ -d (loop)/arch/boot/syslinux ]; then
614 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
615 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
618 elif [ -d (loop)/manjaro ]; then
619 if [ -e (loop)/boot/grub/kernels.cfg ]; then
620 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
622 elif [ -e (loop)/boot/grub/grub.cfg ]; then
623 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
626 distro_specify_initrd_file
628 vt_linux_initrd_count vtcount
629 if [ $vtcount -eq 0 ]; then
630 distro_specify_initrd_file_phase2
636 vt_linux_chain_data ${1}${chosen_path}
639 if [ -n "$vtoy_chain_mem_addr" ]; then
640 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
643 echo "chain empty failed"
649 function legacy_unix_menu_func {
650 ventoy_unix_comm_proc $1 ${chosen_path}
652 if [ -n "$vtoy_chain_mem_addr" ]; then
653 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
656 echo "chain empty failed"
662 function legacy_iso_menu_func {
664 if [ -d (loop)/ ]; then
669 vt_select_auto_install ${chosen_path}
670 vt_select_persistence ${chosen_path}
672 if vt_is_udf ${1}${chosen_path}; then
673 set ventoy_fs_probe=udf
675 set ventoy_fs_probe=iso9660
676 vt_iso9660_nojoliet 0
679 loopback loop ${1}${chosen_path}
683 if [ -n "$vtcompat" ]; then
684 set ventoy_compatible=YES
686 elif vt_check_mode 1; then
687 set ventoy_compatible=YES
689 vt_check_compatible (loop)
692 vt_img_sector ${1}${chosen_path}
694 if [ "$vtoy_os" = "Windows" ]; then
695 vt_check_compatible_pe (loop)
696 legacy_windows_menu_func $1 ${chosen_path}
697 elif [ "$vtoy_os" = "Unix" ]; then
698 legacy_unix_menu_func $1 ${chosen_path}
700 legacy_linux_menu_func $1 ${chosen_path}
704 function legacy_iso_memdisk {
706 linux16 $vtoy_path/memdisk iso raw
707 echo "Loading ISO file to memory ..."
713 function iso_endless_os_proc {
714 if [ -d (loop)/ ]; then
718 loopback loop ${1}${2}
719 vt_img_sector ${1}${2}
721 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
722 vt_trailer_cpio $1 $2 noinit
726 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
729 set ventoy_bls_bootdev=/boot
730 set ventoy_loading_tip="Loading files ......"
733 configfile (loop)/endless/grub/grub.cfg
736 unset ventoy_bls_bootdev
737 unset ventoy_loading_tip
743 function ventoy_iso_busybox_ver {
744 set ventoy_busybox_ver=32
746 #special process for deepin-live iso
747 if [ "$vt_chosen_size" = "403701760" ]; then
748 if vt_str_begin $vt_chosen_path "/deepin-live"; then
749 set ventoy_busybox_ver=64
754 function iso_common_menuentry {
758 vt_chosen_img_path vt_chosen_path vt_chosen_size
759 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
761 ventoy_iso_busybox_ver
763 #special process for Endless OS
764 if vt_str_begin $vt_volume_id "Endless-OS"; then
765 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
768 if [ "$grub_platform" = "pc" ]; then
769 if vt_check_mode 0; then
770 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
772 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
775 if vt_check_mode 0; then
776 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
778 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
783 function common_unsupport_menuentry {
784 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
785 echo -e " 文件名中不能有中文或空格 \n"
786 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
790 function iso_unsupport_menuentry {
791 common_unsupport_menuentry
794 function wim_common_menuentry {
795 vt_chosen_img_path vt_chosen_path vt_chosen_size
796 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
800 if [ -n "$vtoy_chain_mem_addr" ]; then
801 if [ "$grub_platform" = "pc" ]; then
802 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
805 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
810 echo "chain empty failed"
815 function wim_unsupport_menuentry {
816 common_unsupport_menuentry
819 function efi_common_menuentry {
820 vt_chosen_img_path vt_chosen_path vt_chosen_size
822 vt_concat_efi_iso ${vtoy_iso_part}${vt_chosen_path} vtoy_iso_buf
827 chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} isoefi=on ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
832 function efi_unsupport_menuentry {
833 common_unsupport_menuentry
837 function ventoy_img_busybox_ver {
838 set ventoy_busybox_ver=32
840 if [ -e (vtimghd,2)/etc/openwrt_release ]; then
841 if vt_file_strstr (vtimghd,2)/etc/openwrt_release x86_64; then
842 set ventoy_busybox_ver=64
847 function img_common_menuentry {
849 echo "To be implement"
852 function img_unsupport_menuentry {
853 common_unsupport_menuentry
856 #############################################################
857 #############################################################
858 #############################################################
859 ####### Main Process ###########
860 #############################################################
861 #############################################################
862 #############################################################
864 set VENTOY_VERSION="1.0.18"
866 # Default menu display mode, you can change it as you want.
869 set VTOY_DEFAULT_MENU_MODE=0
871 set VTOY_MEM_DISK_STR="[Memdisk]"
872 set VTOY_ISO_RAW_STR="Compatible Mode"
873 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
875 set VTOY_F2_CMD="ventoy_power"
876 set VTOY_F4_CMD="ventoy_localboot"
877 set VTOY_F5_CMD="ventoy_diagnosis"
878 set VTOY_F6_CMD="ventoy_ext_menu"
880 if [ "$grub_platform" = "pc" ]; then
881 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
883 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
886 vt_device $root vtoy_dev
888 if [ "$vtoy_dev" = "tftp" ]; then
889 set vtoy_path=($root)
890 for vtid in 0 1 2 3; do
891 if [ -d (hd$vtid,2)/ventoy ]; then
892 set vtoy_iso_part=(hd$vtid,1)
893 set vtoy_efi_part=(hd$vtid,2)
899 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
900 set vt_plugin_path=$vtoy_iso_part
902 set vt_plugin_path=$prefix
903 vt_load_plugin $vt_plugin_path
906 if [ "$prefix" = "(ventoydisk)/grub" ]; then
907 set vtoy_path=(ventoydisk)/ventoy
909 set vtoy_path=($root)/ventoy
912 set vtoy_iso_part=($vtoy_dev,1)
913 set vtoy_efi_part=($vtoy_dev,2)
915 set vt_plugin_path=$vtoy_iso_part
920 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
921 vt_load_plugin $vtoy_iso_part
924 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
925 set timeout=$VTOY_MENU_TIMEOUT
930 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
931 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
932 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
933 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
937 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
938 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
939 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
941 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
942 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
946 if [ -n "$vtoy_gfxmode" ]; then
947 set gfxmode=$vtoy_gfxmode
949 set gfxmode=1920x1080,1366x768,1024x768
952 if [ "$vtoy_display_mode" = "CLI" ]; then
953 terminal_output console
954 elif [ "$vtoy_display_mode" = "serial" ]; then
955 if [ -n "$vtoy_serial_param" ]; then
956 serial $vtoy_serial_param
958 terminal_input serial
959 terminal_output serial
960 elif [ "$vtoy_display_mode" = "serial_console" ]; then
961 if [ -n "$vtoy_serial_param" ]; then
962 serial $vtoy_serial_param
964 terminal_input serial console
965 terminal_output serial console
967 if [ -n "$vtoy_theme" ]; then
968 set theme=$vtoy_theme
970 set theme=$prefix/themes/ventoy/theme.txt
972 terminal_output gfxterm
975 #export necessary variable
981 export VENTOY_VERSION
986 #colect all image files (iso files)
987 set ventoy_img_count=0
988 vt_list_img $vtoy_iso_part ventoy_img_count
991 if [ $ventoy_img_count -gt 0 ]; then
992 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
998 if [ -n "$VTOY_NO_ISO_TIP" ]; then
999 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1000 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1001 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1003 NO_ISO_MENU="No ISO files found"
1005 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1006 echo -e "\n Rebooting ... "