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.gz ]; then
161 vt_linux_specify_initrd_file /casper/initrd.gz
163 if [ -e (loop)/casper/initrd-oem ]; then
164 vt_linux_specify_initrd_file /casper/initrd-oem
166 elif [ -e (loop)/boot/grub/initrd.xz ]; then
167 vt_linux_specify_initrd_file /boot/grub/initrd.xz
168 elif [ -e (loop)/initrd.gz ]; then
169 vt_linux_specify_initrd_file /initrd.gz
170 elif [ -e (loop)/slax/boot/initrfs.img ]; then
171 vt_linux_specify_initrd_file /slax/boot/initrfs.img
172 elif [ -e (loop)/pmagic/initrd.img ]; then
173 vt_linux_specify_initrd_file /pmagic/initrd.img
174 elif [ -e (loop)/boot/initrd.xz ]; then
175 vt_linux_specify_initrd_file /boot/initrd.xz
176 elif [ -f (loop)/boot/initrd ]; then
177 vt_linux_specify_initrd_file /boot/initrd
178 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
179 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
180 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
181 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
188 function distro_specify_initrd_file_phase2 {
189 if [ -f (loop)/boot/initrd.img ]; then
190 vt_linux_specify_initrd_file /boot/initrd.img
191 elif [ -f (loop)/Setup/initrd.gz ]; then
192 vt_linux_specify_initrd_file /Setup/initrd.gz
193 elif [ -f (loop)/isolinux/initramfs ]; then
194 vt_linux_specify_initrd_file /isolinux/initramfs
195 elif [ -f (loop)/boot/iniramfs.igz ]; then
196 vt_linux_specify_initrd_file /boot/iniramfs.igz
197 elif [ -f (loop)/initrd-x86_64 ]; then
198 vt_linux_specify_initrd_file /initrd-x86_64
199 elif [ -f (loop)/live/initrd.img ]; then
200 vt_linux_specify_initrd_file /live/initrd.img
201 elif [ -f (loop)/initrd.img ]; then
202 vt_linux_specify_initrd_file /initrd.img
203 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
204 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
205 elif [ -f (loop)/CDlinux/initrd ]; then
206 vt_linux_specify_initrd_file /CDlinux/initrd
207 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
208 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
209 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
210 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
212 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
213 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
214 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
215 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
217 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
219 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
220 if [ "$grub_platform" != "pc" ]; then
221 vt_add_replace_file 0 "initrd.img"
223 elif [ -f (loop)/initrd ]; then
224 vt_linux_specify_initrd_file /initrd
225 elif [ -f (loop)/live/initrd1 ]; then
226 vt_linux_specify_initrd_file /live/initrd1
227 elif vt_strstr $vt_volume_id "Daphile"; then
228 vt_linux_parse_initrd_isolinux (loop)/isolinux/
233 function ventoy_get_ghostbsd_ver {
235 # vt_parse_iso_create_date $1/${chosen_path} vt_create_date
236 # if regexp "^202005" "$vt_create_date"; then
237 # set vt_freebsd_ver=12.x
240 set vt_freebsd_ver=12.x
243 function ventoy_get_furybsd_ver {
244 if regexp "13\.[0-9]" "$2"; then
245 set vt_freebsd_ver=13.x
247 set vt_freebsd_ver=12.x
251 function ventoy_get_freenas_ver {
252 set vt_freebsd_ver=11.x
254 if [ -e (loop)/FreeNAS-MANIFEST ]; then
255 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
256 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
257 set vt_freebsd_ver=13.x
258 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
259 set vt_freebsd_ver=12.x
260 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
261 set vt_freebsd_ver=11.x
266 function ventoy_freebsd_proc {
267 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
268 ventoy_get_ghostbsd_ver $1 ${chosen_path}
269 elif vt_strstr "$vt_volume_id" "FREENAS"; then
270 ventoy_get_freenas_ver $1 ${chosen_path}
271 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
272 ventoy_get_furybsd_ver $1 ${chosen_path}
273 elif regexp "^13_[0-9]" "$vt_volume_id"; then
274 set vt_freebsd_ver=13.x
275 elif regexp "^12_[0-9]" "$vt_volume_id"; then
276 set vt_freebsd_ver=12.x
277 elif regexp "^11_[0-9]" "$vt_volume_id"; then
278 set vt_freebsd_ver=11.x
279 elif regexp "^10_[0-9]" "$vt_volume_id"; then
280 set vt_freebsd_ver=10.x
281 elif regexp "^9_[0-9]" "$vt_volume_id"; then
282 set vt_freebsd_ver=9.x
283 elif [ -e (loop)/bin/freebsd-version ]; then
284 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
285 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
286 set vt_freebsd_ver=13.x
287 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
288 set vt_freebsd_ver=12.x
289 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
290 set vt_freebsd_ver=11.x
291 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
292 set vt_freebsd_ver=10.x
293 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
294 set vt_freebsd_ver=9.x
296 elif [ -e (loop)/README.TXT ]; then
297 vt_1st_line (loop)/README.TXT vt_freebsd_line1
298 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
299 set vt_freebsd_ver=13.x
300 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
301 set vt_freebsd_ver=12.x
302 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
303 set vt_freebsd_ver=11.x
304 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
305 set vt_freebsd_ver=10.x
306 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
307 set vt_freebsd_ver=9.x
309 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
310 set vt_freebsd_ver=9.x
312 set vt_freebsd_ver=12.x
315 set vt_freebsd_bit=64
316 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
317 if [ -e (loop)/$file ]; then
318 if file --is-i386-kfreebsd (loop)/$file; then
319 set vt_freebsd_bit=32
325 if [ -n "${vtdebug_flag}" ]; then
326 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
329 unset vt_unix_mod_path
330 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version" "/etc/fstab"; do
331 if [ -e (loop)${file} ]; then
332 set vt_unix_mod_path=${file}
337 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
338 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
341 function ventoy_unix_comm_proc {
344 if [ "$ventoy_compatible" = "NO" ]; then
345 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
347 if [ "$vt_unix_type" = "FreeBSD" ]; then
348 ventoy_freebsd_proc $1 ${chosen_path}
349 elif [ "$vt_unix_type" = "NetBSD" ]; then
350 echo "NetBSD not supported"
355 if [ -n "${vtdebug_flag}" ]; then
356 echo "Unknown unix type"
361 vt_unix_chain_data ${1}${chosen_path}
366 function uefi_windows_menu_func {
369 if [ "$ventoy_compatible" = "NO" ]; then
371 if [ "$ventoy_fs_probe" = "iso9660" ]; then
373 vt_iso9660_nojoliet 1
377 for file in "efi/microsoft/boot/bcd"; do
378 vt_windows_collect_wim_patch bcd (loop)/$file
381 vt_windows_count_wim_patch vt_wim_cnt
382 if [ $vt_wim_cnt -eq 0 ]; then
383 distro_specify_wim_patch_phase2
390 vt_windows_chain_data ${1}${chosen_path}
393 if [ -n "$vtoy_chain_mem_addr" ]; then
395 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
398 echo "chain empty failed"
403 function uefi_linux_menu_func {
404 if [ "$ventoy_compatible" = "NO" ]; then
406 if [ "$ventoy_fs_probe" = "udf" ]; then
408 set ventoy_fs_probe=iso9660
412 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
414 vt_linux_clear_initrd
416 if [ -d (loop)/pmagic ]; then
417 vt_linux_specify_initrd_file /pmagic/initrd.img
419 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
420 if [ -e (loop)/$file ]; then
421 vt_linux_parse_initrd_grub file (loop)/$file
426 # special process for special distros
427 if [ -d (loop)/loader/entries ]; then
428 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
429 elif [ -d (loop)/boot/grub ]; then
430 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
433 distro_specify_initrd_file
435 vt_linux_initrd_count vtcount
436 if [ $vtcount -eq 0 ]; then
437 distro_specify_initrd_file_phase2
439 if [ "$vt_efi_dir" = "NO" ]; then
440 if [ -f (loop)/efi.img ]; then
441 vt_add_replace_file 0 "initrd"
448 if [ -d (loop)/loader/entries ]; then
449 vt_linux_get_main_initrd_index vtindex
451 if [ -d (loop)/arch ]; then
452 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
453 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
454 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
455 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
457 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
458 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
459 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
460 vt_add_replace_file $vtindex "boot\\initrd"
462 elif [ -d (loop)/EFI/boot/entries ]; then
463 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
464 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
465 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
466 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
468 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
469 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
470 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
475 vt_linux_chain_data ${1}${chosen_path}
477 if [ -n "$vtoy_chain_mem_addr" ]; then
479 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}
482 echo "chain empty failed"
487 function uefi_unix_menu_func {
488 ventoy_unix_comm_proc $1 ${chosen_path}
490 if [ -n "$vtoy_chain_mem_addr" ]; then
492 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}
495 echo "chain empty failed"
500 function uefi_iso_menu_func {
502 if [ -d (loop)/ ]; then
506 if [ -n "$vtisouefi" ]; then
507 set LoadIsoEfiDriver=on
509 elif vt_check_mode 2; then
510 set LoadIsoEfiDriver=on
512 unset LoadIsoEfiDriver
516 vt_select_auto_install ${chosen_path}
517 vt_select_persistence ${chosen_path}
519 if vt_is_udf ${1}${chosen_path}; then
520 set ventoy_fs_probe=udf
522 set ventoy_fs_probe=iso9660
523 vt_iso9660_nojoliet 0
526 loopback loop ${1}${chosen_path}
529 if [ -d (loop)/EFI ]; then
531 elif [ -d (loop)/efi ]; then
537 if [ -n "$vtcompat" ]; then
538 set ventoy_compatible=YES
540 elif vt_check_mode 1; then
541 set ventoy_compatible=YES
543 vt_check_compatible (loop)
546 vt_img_sector ${1}${chosen_path}
548 if [ "$vtoy_os" = "Windows" ]; then
549 vt_check_compatible_pe (loop)
550 uefi_windows_menu_func $1 ${chosen_path}
551 elif [ "$vtoy_os" = "Unix" ]; then
552 uefi_unix_menu_func $1 ${chosen_path}
554 uefi_linux_menu_func $1 ${chosen_path}
560 function uefi_iso_memdisk {
561 echo 'Loading ISO file to memory ...'
562 vt_load_img_memdisk ${1}${2} vtoy_iso_buf
565 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}
572 function legacy_windows_menu_func {
575 if [ "$ventoy_compatible" = "NO" ]; then
577 if [ "$ventoy_fs_probe" = "iso9660" ]; then
579 vt_iso9660_nojoliet 1
583 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
584 vt_windows_collect_wim_patch bcd (loop)/$file
587 distro_specify_wim_patch
589 vt_windows_count_wim_patch vt_wim_cnt
590 if [ $vt_wim_cnt -eq 0 ]; then
591 distro_specify_wim_patch_phase2
598 vt_windows_chain_data ${1}${chosen_path}
601 if [ -n "$vtoy_chain_mem_addr" ]; then
602 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
605 echo "chain empty failed"
610 function legacy_linux_menu_func {
611 if [ "$ventoy_compatible" = "NO" ]; then
613 if [ "$ventoy_fs_probe" = "udf" ]; then
615 set ventoy_fs_probe=iso9660
619 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
621 vt_linux_clear_initrd
623 if [ -d (loop)/pmagic ]; then
624 vt_linux_specify_initrd_file /pmagic/initrd.img
626 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
627 if [ -d (loop)/$dir ]; then
628 vt_linux_parse_initrd_isolinux (loop)/$dir/
633 # special process for special distros
635 if [ -d (loop)/arch/boot/syslinux ]; then
636 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
637 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
640 elif [ -d (loop)/manjaro ]; then
641 if [ -e (loop)/boot/grub/kernels.cfg ]; then
642 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
644 elif [ -e (loop)/boot/grub/grub.cfg ]; then
645 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
648 distro_specify_initrd_file
650 vt_linux_initrd_count vtcount
651 if [ $vtcount -eq 0 ]; then
652 distro_specify_initrd_file_phase2
658 vt_linux_chain_data ${1}${chosen_path}
661 if [ -n "$vtoy_chain_mem_addr" ]; then
662 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
665 echo "chain empty failed"
671 function legacy_unix_menu_func {
672 ventoy_unix_comm_proc $1 ${chosen_path}
674 if [ -n "$vtoy_chain_mem_addr" ]; then
675 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
678 echo "chain empty failed"
684 function legacy_iso_menu_func {
686 if [ -d (loop)/ ]; then
691 vt_select_auto_install ${chosen_path}
692 vt_select_persistence ${chosen_path}
694 if vt_is_udf ${1}${chosen_path}; then
695 set ventoy_fs_probe=udf
697 set ventoy_fs_probe=iso9660
698 vt_iso9660_nojoliet 0
701 loopback loop ${1}${chosen_path}
705 if [ -n "$vtcompat" ]; then
706 set ventoy_compatible=YES
708 elif vt_check_mode 1; then
709 set ventoy_compatible=YES
711 vt_check_compatible (loop)
714 vt_img_sector ${1}${chosen_path}
716 if [ "$vtoy_os" = "Windows" ]; then
717 vt_check_compatible_pe (loop)
718 legacy_windows_menu_func $1 ${chosen_path}
719 elif [ "$vtoy_os" = "Unix" ]; then
720 legacy_unix_menu_func $1 ${chosen_path}
722 legacy_linux_menu_func $1 ${chosen_path}
726 function legacy_iso_memdisk {
728 linux16 $vtoy_path/memdisk iso raw
729 echo "Loading ISO file to memory ..."
735 function iso_endless_os_proc {
736 if [ -d (loop)/ ]; then
740 loopback loop ${1}${2}
741 vt_img_sector ${1}${2}
743 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
744 vt_trailer_cpio $1 $2 noinit
748 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
751 set ventoy_bls_bootdev=/boot
752 set ventoy_loading_tip="Loading files ......"
755 configfile (loop)/endless/grub/grub.cfg
758 unset ventoy_bls_bootdev
759 unset ventoy_loading_tip
765 function ventoy_iso_busybox_ver {
766 set ventoy_busybox_ver=32
768 #special process for deepin-live iso
769 if [ "$vt_chosen_size" = "403701760" ]; then
770 if vt_str_begin $vt_chosen_path "/deepin-live"; then
771 set ventoy_busybox_ver=64
776 function iso_common_menuentry {
780 vt_chosen_img_path vt_chosen_path vt_chosen_size
781 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
783 ventoy_iso_busybox_ver
785 #special process for Endless OS
786 if vt_str_begin $vt_volume_id "Endless-OS"; then
787 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
790 if [ "$grub_platform" = "pc" ]; then
791 if vt_check_mode 0; then
792 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
794 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
797 if vt_check_mode 0; then
798 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
800 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
805 function common_unsupport_menuentry {
806 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
807 echo -e " 文件名中不能有中文或空格 \n"
808 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
812 function iso_unsupport_menuentry {
813 common_unsupport_menuentry
816 function wim_common_menuentry {
817 vt_chosen_img_path vt_chosen_path vt_chosen_size
818 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
822 if [ -n "$vtoy_chain_mem_addr" ]; then
823 if [ "$grub_platform" = "pc" ]; then
824 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
827 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
832 echo "chain empty failed"
837 function wim_unsupport_menuentry {
838 common_unsupport_menuentry
841 function efi_common_menuentry {
842 vt_chosen_img_path vt_chosen_path vt_chosen_size
844 vt_concat_efi_iso ${vtoy_iso_part}${vt_chosen_path} vtoy_iso_buf
849 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}
854 function efi_unsupport_menuentry {
855 common_unsupport_menuentry
859 #============================================================#
860 # IMG file boot process #
861 #============================================================#
865 function ventoy_img_easyos {
866 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
867 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
869 loopback easysfs (vtimghd,1)/easy.sfs
870 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
872 if [ -n "$vt_module_ver" ]; then
873 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
874 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
881 vt_set_boot_opt rdinit=/vtoy/vtoy
884 syslinux_configfile (vtimghd,1)/syslinux.cfg
891 function ventoy_img_volumio {
892 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
893 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
898 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
901 syslinux_configfile (vtimghd,1)/syslinux.cfg
908 function img_common_menuentry {
909 set ventoy_busybox_ver=32
911 vt_chosen_img_path vt_chosen_path vt_chosen_size
913 if [ -d (vtimghd)/ ]; then
917 loopback vtimghd ${vtoy_iso_part}${vt_chosen_path}
918 vt_img_sector ${vtoy_iso_part}${vt_chosen_path}
920 vt_img_part_info (vtimghd)
922 set vtback_root=$root
926 vt_img_extra_initrd_reset
928 #vt_get_fs_label (vtimghd,1) vtImgHd1Label
930 if [ -e (vtimghd,1)/easy.sfs ]; then
932 elif [ -e (vtimghd,1)/volumio.initrd ]; then
937 echo -e "\n This IMG file is NOT supported now. \n"
938 echo -e " 当前不支持启动此 IMG 文件 \n"
939 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
943 set root=$vtback_root
948 function img_unsupport_menuentry {
949 common_unsupport_menuentry
952 #############################################################
953 #############################################################
954 #############################################################
955 ####### Main Process ###########
956 #############################################################
957 #############################################################
958 #############################################################
960 set VENTOY_VERSION="1.0.19"
962 # Default menu display mode, you can change it as you want.
965 set VTOY_DEFAULT_MENU_MODE=0
967 set VTOY_MEM_DISK_STR="[Memdisk]"
968 set VTOY_ISO_RAW_STR="Compatible Mode"
969 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
971 set VTOY_F2_CMD="ventoy_power"
972 set VTOY_F4_CMD="ventoy_localboot"
973 set VTOY_F5_CMD="ventoy_diagnosis"
974 set VTOY_F6_CMD="ventoy_ext_menu"
976 if [ "$grub_platform" = "pc" ]; then
977 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
979 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
982 vt_device $root vtoy_dev
984 if [ "$vtoy_dev" = "tftp" ]; then
985 set vtoy_path=($root)
986 for vtid in 0 1 2 3; do
987 if [ -d (hd$vtid,2)/ventoy ]; then
988 set vtoy_iso_part=(hd$vtid,1)
989 set vtoy_efi_part=(hd$vtid,2)
995 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
996 set vt_plugin_path=$vtoy_iso_part
998 set vt_plugin_path=$prefix
999 vt_load_plugin $vt_plugin_path
1002 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1003 set vtoy_path=(ventoydisk)/ventoy
1005 set vtoy_path=($root)/ventoy
1008 set vtoy_iso_part=($vtoy_dev,1)
1009 set vtoy_efi_part=($vtoy_dev,2)
1011 set vt_plugin_path=$vtoy_iso_part
1016 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1017 vt_load_plugin $vtoy_iso_part
1020 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1021 set timeout=$VTOY_MENU_TIMEOUT
1026 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1027 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1028 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1029 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1033 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1034 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1035 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
1037 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1038 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
1042 if [ -n "$vtoy_gfxmode" ]; then
1043 set gfxmode=$vtoy_gfxmode
1045 set gfxmode=1920x1080,1366x768,1024x768
1048 if [ "$vtoy_display_mode" = "CLI" ]; then
1049 terminal_output console
1050 elif [ "$vtoy_display_mode" = "serial" ]; then
1051 if [ -n "$vtoy_serial_param" ]; then
1052 serial $vtoy_serial_param
1054 terminal_input serial
1055 terminal_output serial
1056 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1057 if [ -n "$vtoy_serial_param" ]; then
1058 serial $vtoy_serial_param
1060 terminal_input serial console
1061 terminal_output serial console
1063 if [ -n "$vtoy_theme" ]; then
1064 set theme=$vtoy_theme
1066 set theme=$prefix/themes/ventoy/theme.txt
1068 terminal_output gfxterm
1071 #export necessary variable
1075 export vtoy_iso_part
1076 export vtoy_efi_part
1077 export VENTOY_VERSION
1082 #colect all image files (iso files)
1083 set ventoy_img_count=0
1084 vt_list_img $vtoy_iso_part ventoy_img_count
1087 if [ $ventoy_img_count -gt 0 ]; then
1088 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1094 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1095 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1096 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1097 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1099 NO_ISO_MENU="No ISO files found"
1101 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1102 echo -e "\n Rebooting ... "