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
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
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 ..."
712 function iso_deepin_live_proc {
713 if [ -d (loop)/ ]; then
717 loopback loop ${1}${2}
718 vt_img_sector ${1}${2}
720 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
721 vt_trailer_cpio $1 $2 noinit
725 vt_set_boot_opt rdinit=/ventoy/loop/deepin/ventoy-init.sh live-media=/dev/mapper/ventoy
727 set ventoy_loading_tip="Loading files ......"
729 linux (loop)/live/vmlinuz boot=live components locales=zh_CN.UTF-8 splash quiet
730 initrd (loop)/live/initrd.img
733 unset ventoy_loading_tip
739 function iso_endless_os_proc {
740 if [ -d (loop)/ ]; then
744 loopback loop ${1}${2}
745 vt_img_sector ${1}${2}
747 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
748 vt_trailer_cpio $1 $2 noinit
752 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
755 set ventoy_bls_bootdev=/boot
756 set ventoy_loading_tip="Loading files ......"
759 configfile (loop)/endless/grub/grub.cfg
762 unset ventoy_bls_bootdev
763 unset ventoy_loading_tip
768 function iso_common_menuentry {
772 vt_chosen_img_path vt_chosen_path vt_chosen_size
773 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
775 #special process for deepin-live iso
776 if [ "$vt_chosen_size" = "403701760" ]; then
777 if vt_str_begin $vt_chosen_path "/deepin-live"; then
778 iso_deepin_live_proc $vtoy_iso_part $vt_chosen_path
782 #special process for Endless OS
783 if vt_str_begin $vt_volume_id "Endless-OS"; then
784 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
787 if [ "$grub_platform" = "pc" ]; then
788 if vt_check_mode 0; then
789 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
791 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
794 if vt_check_mode 0; then
795 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
797 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
802 function common_unsupport_menuentry {
803 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
804 echo -e " 文件名中不能有中文或空格 \n"
805 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
809 function iso_unsupport_menuentry {
810 common_unsupport_menuentry
813 function wim_common_menuentry {
814 vt_chosen_img_path vt_chosen_path vt_chosen_size
815 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
819 if [ -n "$vtoy_chain_mem_addr" ]; then
820 if [ "$grub_platform" = "pc" ]; then
821 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
824 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
829 echo "chain empty failed"
834 function wim_unsupport_menuentry {
835 common_unsupport_menuentry
838 function efi_common_menuentry {
839 vt_chosen_img_path vt_chosen_path vt_chosen_size
841 vt_concat_efi_iso ${vtoy_iso_part}${vt_chosen_path} vtoy_iso_buf
846 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}
851 function efi_unsupport_menuentry {
852 common_unsupport_menuentry
859 function img_common_menuentry {
861 echo "To be implement"
864 function img_unsupport_menuentry {
865 common_unsupport_menuentry
868 #############################################################
869 #############################################################
870 #############################################################
871 ####### Main Process ###########
872 #############################################################
873 #############################################################
874 #############################################################
876 set VENTOY_VERSION="1.0.18"
878 # Default menu display mode, you can change it as you want.
881 set VTOY_DEFAULT_MENU_MODE=0
883 set VTOY_MEM_DISK_STR="[Memdisk]"
884 set VTOY_ISO_RAW_STR="Compatible Mode"
885 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
887 set VTOY_F2_CMD="ventoy_power"
888 set VTOY_F4_CMD="ventoy_localboot"
889 set VTOY_F5_CMD="ventoy_diagnosis"
890 set VTOY_F6_CMD="ventoy_ext_menu"
892 if [ "$grub_platform" = "pc" ]; then
893 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
895 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
898 vt_device $root vtoy_dev
900 if [ "$vtoy_dev" = "tftp" ]; then
901 set vtoy_path=($root)
902 for vtid in 0 1 2 3; do
903 if [ -d (hd$vtid,2)/ventoy ]; then
904 set vtoy_iso_part=(hd$vtid,1)
905 set vtoy_efi_part=(hd$vtid,2)
911 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
912 set vt_plugin_path=$vtoy_iso_part
914 set vt_plugin_path=$prefix
915 vt_load_plugin $vt_plugin_path
918 if [ "$prefix" = "(ventoydisk)/grub" ]; then
919 set vtoy_path=(ventoydisk)/ventoy
921 set vtoy_path=($root)/ventoy
924 set vtoy_iso_part=($vtoy_dev,1)
925 set vtoy_efi_part=($vtoy_dev,2)
927 set vt_plugin_path=$vtoy_iso_part
932 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
933 vt_load_plugin $vtoy_iso_part
936 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
937 set timeout=$VTOY_MENU_TIMEOUT
942 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
943 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
944 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
945 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
949 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
950 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
951 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
953 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
954 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
958 if [ -n "$vtoy_gfxmode" ]; then
959 set gfxmode=$vtoy_gfxmode
961 set gfxmode=1920x1080,1366x768,1024x768
964 if [ "$vtoy_display_mode" = "CLI" ]; then
965 terminal_output console
966 elif [ "$vtoy_display_mode" = "serial" ]; then
967 if [ -n "$vtoy_serial_param" ]; then
968 serial $vtoy_serial_param
970 terminal_input serial
971 terminal_output serial
972 elif [ "$vtoy_display_mode" = "serial_console" ]; then
973 if [ -n "$vtoy_serial_param" ]; then
974 serial $vtoy_serial_param
976 terminal_input serial console
977 terminal_output serial console
979 if [ -n "$vtoy_theme" ]; then
980 set theme=$vtoy_theme
982 set theme=$prefix/themes/ventoy/theme.txt
984 terminal_output gfxterm
987 #export necessary variable
993 export VENTOY_VERSION
998 #colect all image files (iso files)
999 set ventoy_img_count=0
1000 vt_list_img $vtoy_iso_part ventoy_img_count
1003 if [ $ventoy_img_count -gt 0 ]; then
1004 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1010 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1011 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1012 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1013 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1015 NO_ISO_MENU="No ISO files found"
1017 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1018 echo -e "\n Rebooting ... "