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 [ -e (loop)/boot/initrd.gz ]; then
177 vt_linux_specify_initrd_file /boot/initrd.gz
178 elif [ -f (loop)/boot/initrd ]; then
179 vt_linux_specify_initrd_file /boot/initrd
180 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
181 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
182 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
183 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
184 elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
185 vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
190 if [ -f (loop)/isolinux/initrd.gz ]; then
191 vt_linux_specify_initrd_file /isolinux/initrd.gz
194 if [ "$vt_chosen_size" = "1133375488" ]; then
195 if [ -d (loop)/boot/grub/x86_64-efi ]; then
202 function distro_specify_initrd_file_phase2 {
203 if [ -f (loop)/boot/initrd.img ]; then
204 vt_linux_specify_initrd_file /boot/initrd.img
205 elif [ -f (loop)/Setup/initrd.gz ]; then
206 vt_linux_specify_initrd_file /Setup/initrd.gz
207 elif [ -f (loop)/isolinux/initramfs ]; then
208 vt_linux_specify_initrd_file /isolinux/initramfs
209 elif [ -f (loop)/boot/iniramfs.igz ]; then
210 vt_linux_specify_initrd_file /boot/iniramfs.igz
211 elif [ -f (loop)/initrd-x86_64 ]; then
212 vt_linux_specify_initrd_file /initrd-x86_64
213 elif [ -f (loop)/live/initrd.img ]; then
214 vt_linux_specify_initrd_file /live/initrd.img
215 elif [ -f (loop)/initrd.img ]; then
216 vt_linux_specify_initrd_file /initrd.img
217 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
218 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
219 elif [ -f (loop)/CDlinux/initrd ]; then
220 vt_linux_specify_initrd_file /CDlinux/initrd
221 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
222 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
223 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
224 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
226 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
227 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
228 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
229 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
231 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
233 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
234 if [ "$grub_platform" != "pc" ]; then
235 vt_add_replace_file 0 "initrd.img"
237 elif [ -f (loop)/initrd ]; then
238 vt_linux_specify_initrd_file /initrd
239 elif [ -f (loop)/live/initrd1 ]; then
240 vt_linux_specify_initrd_file /live/initrd1
241 elif [ -f (loop)/isolinux/initrd.img ]; then
242 vt_linux_specify_initrd_file /isolinux/initrd.img
243 elif [ -f (loop)/isolinux/initrd.gz ]; then
244 vt_linux_specify_initrd_file /isolinux/initrd.gz
245 elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
246 vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
247 elif vt_strstr $vt_volume_id "Daphile"; then
248 vt_linux_parse_initrd_isolinux (loop)/isolinux/
249 elif [ -f (loop)/boot/rootfs.xz ]; then
250 vt_linux_specify_initrd_file /boot/rootfs.xz
251 if [ "$grub_platform" != "pc" ]; then
252 vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
258 function ventoy_get_ghostbsd_ver {
260 # vt_parse_iso_create_date $1/${chosen_path} vt_create_date
261 # if regexp "^202005" "$vt_create_date"; then
262 # set vt_freebsd_ver=12.x
265 set vt_freebsd_ver=12.x
268 function ventoy_get_furybsd_ver {
269 if regexp "13\.[0-9]" "$2"; then
270 set vt_freebsd_ver=13.x
272 set vt_freebsd_ver=12.x
276 function ventoy_get_freenas_ver {
277 set vt_freebsd_ver=11.x
279 if [ -e (loop)/FreeNAS-MANIFEST ]; then
280 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
281 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
282 set vt_freebsd_ver=13.x
283 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
284 set vt_freebsd_ver=12.x
285 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
286 set vt_freebsd_ver=11.x
291 function ventoy_get_midnightbsd_ver {
292 set vt_freebsd_ver=11.x
295 function ventoy_freebsd_proc {
296 set vtFreeBsdDistro=FreeBSD
298 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
299 ventoy_get_ghostbsd_ver $1 ${chosen_path}
300 elif vt_strstr "$vt_volume_id" "FREENAS"; then
301 ventoy_get_freenas_ver $1 ${chosen_path}
302 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
303 ventoy_get_furybsd_ver $1 ${chosen_path}
304 elif regexp "^13_[0-9]" "$vt_volume_id"; then
305 set vt_freebsd_ver=13.x
306 elif regexp "^12_[0-9]" "$vt_volume_id"; then
307 set vt_freebsd_ver=12.x
308 elif regexp "^11_[0-9]" "$vt_volume_id"; then
309 set vt_freebsd_ver=11.x
310 elif regexp "^10_[0-9]" "$vt_volume_id"; then
311 set vt_freebsd_ver=10.x
312 elif regexp "^9_[0-9]" "$vt_volume_id"; then
313 set vt_freebsd_ver=9.x
314 elif [ -d (loop)/usr/midnightbsd-dist ]; then
315 ventoy_get_midnightbsd_ver $1 ${chosen_path}
316 set vtFreeBsdDistro=MidnightBSD
317 elif [ -e (loop)/bin/freebsd-version ]; then
318 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
319 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
320 set vt_freebsd_ver=13.x
321 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
322 set vt_freebsd_ver=12.x
323 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
324 set vt_freebsd_ver=11.x
325 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
326 set vt_freebsd_ver=10.x
327 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
328 set vt_freebsd_ver=9.x
330 elif [ -e (loop)/README.TXT ]; then
331 vt_1st_line (loop)/README.TXT vt_freebsd_line1
332 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
333 set vt_freebsd_ver=13.x
334 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
335 set vt_freebsd_ver=12.x
336 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
337 set vt_freebsd_ver=11.x
338 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
339 set vt_freebsd_ver=10.x
340 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
341 set vt_freebsd_ver=9.x
343 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
344 set vt_freebsd_ver=9.x
346 set vt_freebsd_ver=12.x
349 set vt_freebsd_bit=64
350 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
351 if [ -e (loop)/$file ]; then
352 if file --is-i386-kfreebsd (loop)/$file; then
353 set vt_freebsd_bit=32
359 if [ -n "${vtdebug_flag}" ]; then
360 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
363 unset vt_unix_mod_path
364 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version" "/etc/fstab"; do
365 if [ -e (loop)${file} ]; then
366 set vt_unix_mod_path=${file}
371 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
372 set vtFreeBsdDistro=ClonOS
375 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
376 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
379 function ventoy_unix_comm_proc {
382 if [ "$ventoy_compatible" = "NO" ]; then
383 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
385 if [ "$vt_unix_type" = "FreeBSD" ]; then
386 ventoy_freebsd_proc $1 ${chosen_path}
387 elif [ "$vt_unix_type" = "NetBSD" ]; then
388 echo "NetBSD not supported"
393 if [ -n "${vtdebug_flag}" ]; then
394 echo "Unknown unix type"
399 vt_unix_chain_data ${1}${chosen_path}
404 function uefi_windows_menu_func {
407 if [ "$ventoy_compatible" = "NO" ]; then
409 if [ "$ventoy_fs_probe" = "iso9660" ]; then
411 vt_iso9660_nojoliet 1
415 for file in "efi/microsoft/boot/bcd"; do
416 vt_windows_collect_wim_patch bcd (loop)/$file
419 vt_windows_count_wim_patch vt_wim_cnt
420 if [ $vt_wim_cnt -eq 0 ]; then
421 distro_specify_wim_patch_phase2
428 vt_windows_chain_data ${1}${chosen_path}
431 if [ -n "$vtoy_chain_mem_addr" ]; then
433 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
436 echo "chain empty failed"
441 function uefi_linux_menu_func {
442 if [ "$ventoy_compatible" = "NO" ]; then
444 if [ "$ventoy_fs_probe" = "udf" ]; then
446 set ventoy_fs_probe=iso9660
450 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
452 vt_linux_clear_initrd
454 if [ -d (loop)/pmagic ]; then
455 vt_linux_specify_initrd_file /pmagic/initrd.img
457 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
458 if [ -e (loop)/$file ]; then
459 vt_linux_parse_initrd_grub file (loop)/$file
464 # special process for special distros
465 if [ -d (loop)/loader/entries ]; then
466 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
467 elif [ -d (loop)/boot/grub ]; then
468 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
471 distro_specify_initrd_file
473 vt_linux_initrd_count vtcount
474 if [ $vtcount -eq 0 ]; then
475 distro_specify_initrd_file_phase2
477 if [ "$vt_efi_dir" = "NO" ]; then
478 if [ -f (loop)/efi.img ]; then
479 vt_add_replace_file 0 "initrd"
486 if [ -d (loop)/loader/entries ]; then
487 vt_linux_get_main_initrd_index vtindex
489 if [ -d (loop)/arch ]; then
490 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
491 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
492 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
493 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
495 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
496 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
497 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
498 vt_add_replace_file $vtindex "boot\\initrd"
499 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
500 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
502 elif [ -d (loop)/EFI/boot/entries ]; then
503 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
504 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
505 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
506 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
508 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
509 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
510 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
517 vt_linux_chain_data ${1}${chosen_path}
519 if [ -n "$vtoy_chain_mem_addr" ]; then
521 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}
524 echo "chain empty failed"
529 function uefi_unix_menu_func {
530 ventoy_unix_comm_proc $1 ${chosen_path}
532 if [ -n "$vtoy_chain_mem_addr" ]; then
534 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}
537 echo "chain empty failed"
542 function uefi_iso_menu_func {
544 if [ -d (loop)/ ]; then
548 if [ -n "$vtisouefi" ]; then
549 set LoadIsoEfiDriver=on
551 elif vt_check_mode 2; then
552 set LoadIsoEfiDriver=on
554 unset LoadIsoEfiDriver
558 vt_select_auto_install ${chosen_path}
559 vt_select_persistence ${chosen_path}
561 if vt_is_udf ${1}${chosen_path}; then
562 set ventoy_fs_probe=udf
564 set ventoy_fs_probe=iso9660
565 vt_iso9660_nojoliet 0
568 loopback loop ${1}${chosen_path}
571 if [ -d (loop)/EFI ]; then
573 elif [ -d (loop)/efi ]; then
579 if [ -n "$vtcompat" ]; then
580 set ventoy_compatible=YES
582 elif vt_check_mode 1; then
583 set ventoy_compatible=YES
585 vt_check_compatible (loop)
588 vt_img_sector ${1}${chosen_path}
590 if [ "$vtoy_os" = "Windows" ]; then
591 vt_check_compatible_pe (loop)
592 uefi_windows_menu_func $1 ${chosen_path}
593 elif [ "$vtoy_os" = "Unix" ]; then
594 uefi_unix_menu_func $1 ${chosen_path}
596 uefi_linux_menu_func $1 ${chosen_path}
602 function uefi_iso_memdisk {
603 echo 'Loading ISO file to memory ...'
604 vt_load_img_memdisk ${1}${2} vtoy_iso_buf
607 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}
614 function legacy_windows_menu_func {
617 if [ "$ventoy_compatible" = "NO" ]; then
619 if [ "$ventoy_fs_probe" = "iso9660" ]; then
621 vt_iso9660_nojoliet 1
625 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
626 vt_windows_collect_wim_patch bcd (loop)/$file
629 distro_specify_wim_patch
631 vt_windows_count_wim_patch vt_wim_cnt
632 if [ $vt_wim_cnt -eq 0 ]; then
633 distro_specify_wim_patch_phase2
640 vt_windows_chain_data ${1}${chosen_path}
643 if [ -n "$vtoy_chain_mem_addr" ]; then
644 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
647 echo "chain empty failed"
652 function legacy_linux_menu_func {
653 if [ "$ventoy_compatible" = "NO" ]; then
655 if [ "$ventoy_fs_probe" = "udf" ]; then
657 set ventoy_fs_probe=iso9660
661 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
663 vt_linux_clear_initrd
665 if [ -d (loop)/pmagic ]; then
666 vt_linux_specify_initrd_file /pmagic/initrd.img
668 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
669 if [ -d (loop)/$dir ]; then
670 vt_linux_parse_initrd_isolinux (loop)/$dir/
675 # special process for special distros
677 if [ -d (loop)/arch/boot/syslinux ]; then
678 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
679 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
682 elif [ -d (loop)/manjaro ]; then
683 if [ -e (loop)/boot/grub/kernels.cfg ]; then
684 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
686 elif [ -e (loop)/boot/grub/grub.cfg ]; then
687 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
690 distro_specify_initrd_file
692 vt_linux_initrd_count vtcount
693 if [ $vtcount -eq 0 ]; then
694 if [ -d (loop)/rancheros ]; then
695 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
698 distro_specify_initrd_file_phase2
704 vt_linux_chain_data ${1}${chosen_path}
707 if [ -n "$vtoy_chain_mem_addr" ]; then
708 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
711 echo "chain empty failed"
717 function legacy_unix_menu_func {
718 ventoy_unix_comm_proc $1 ${chosen_path}
720 if [ -n "$vtoy_chain_mem_addr" ]; then
721 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
724 echo "chain empty failed"
730 function legacy_iso_menu_func {
732 if [ -d (loop)/ ]; then
737 vt_select_auto_install ${chosen_path}
738 vt_select_persistence ${chosen_path}
740 if vt_is_udf ${1}${chosen_path}; then
741 set ventoy_fs_probe=udf
743 set ventoy_fs_probe=iso9660
744 vt_iso9660_nojoliet 0
747 loopback loop ${1}${chosen_path}
751 if [ -n "$vtcompat" ]; then
752 set ventoy_compatible=YES
754 elif vt_check_mode 1; then
755 set ventoy_compatible=YES
757 vt_check_compatible (loop)
760 vt_img_sector ${1}${chosen_path}
762 if [ "$vtoy_os" = "Windows" ]; then
763 vt_check_compatible_pe (loop)
764 legacy_windows_menu_func $1 ${chosen_path}
765 elif [ "$vtoy_os" = "Unix" ]; then
766 legacy_unix_menu_func $1 ${chosen_path}
768 legacy_linux_menu_func $1 ${chosen_path}
772 function legacy_iso_memdisk {
774 linux16 $vtoy_path/memdisk iso raw
775 echo "Loading ISO file to memory ..."
781 function iso_endless_os_proc {
782 if [ -d (loop)/ ]; then
786 loopback loop ${1}${2}
787 vt_img_sector ${1}${2}
789 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
790 vt_trailer_cpio $1 $2 noinit
794 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
797 set ventoy_bls_bootdev=/boot
798 set ventoy_loading_tip="Loading files ......"
801 configfile (loop)/endless/grub/grub.cfg
804 unset ventoy_bls_bootdev
805 unset ventoy_loading_tip
811 function ventoy_iso_busybox_ver {
812 set ventoy_busybox_ver=32
814 #special process for deepin-live iso
815 if [ "$vt_chosen_size" = "403701760" ]; then
816 if vt_str_begin $vt_chosen_path "/deepin-live"; then
817 set ventoy_busybox_ver=64
819 elif vt_str_begin $vt_volume_id "PHOTON_"; then
820 set ventoy_busybox_ver=64
821 elif vt_str_begin $vt_volume_id "smgl-test-quinq-x86_64"; then
822 set ventoy_busybox_ver=64
827 function iso_common_menuentry {
831 vt_chosen_img_path vt_chosen_path vt_chosen_size
832 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
834 ventoy_iso_busybox_ver
836 #special process for Endless OS
837 if vt_str_begin $vt_volume_id "Endless-OS"; then
838 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
839 elif vt_str_begin $vt_volume_id "TENS-Public"; then
843 if [ "$grub_platform" = "pc" ]; then
844 if vt_check_mode 0; then
845 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
847 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
850 if vt_check_mode 0; then
851 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
853 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
858 function common_unsupport_menuentry {
859 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
860 echo -e " 文件名中不能有中文或空格 \n"
861 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
865 function iso_unsupport_menuentry {
866 common_unsupport_menuentry
869 function wim_common_menuentry {
870 vt_chosen_img_path vt_chosen_path vt_chosen_size
871 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
875 if [ -n "$vtoy_chain_mem_addr" ]; then
876 if [ "$grub_platform" = "pc" ]; then
877 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
880 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
885 echo "chain empty failed"
890 function wim_unsupport_menuentry {
891 common_unsupport_menuentry
894 function efi_common_menuentry {
895 vt_chosen_img_path vt_chosen_path vt_chosen_size
897 vt_concat_efi_iso ${vtoy_iso_part}${vt_chosen_path} vtoy_iso_buf
903 unset vtoy_dotefi_retry
904 chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} dotefi isoefi=on ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
907 if [ -n "$vtoy_dotefi_retry" ]; then
908 unset vtoy_dotefi_retry
909 chainloader ${vtoy_iso_part}${vt_chosen_path}
916 function efi_unsupport_menuentry {
917 common_unsupport_menuentry
921 #============================================================#
922 # IMG file boot process #
923 #============================================================#
927 function ventoy_img_easyos {
928 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
929 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
931 loopback easysfs (vtimghd,1)/easy.sfs
932 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
934 if [ -n "$vt_module_ver" ]; then
935 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
936 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
943 vt_set_boot_opt rdinit=/vtoy/vtoy
946 syslinux_configfile (vtimghd,1)/syslinux.cfg
953 function ventoy_img_volumio {
954 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
955 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
960 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
963 syslinux_configfile (vtimghd,1)/syslinux.cfg
969 function ventoy_img_openelec {
972 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
973 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
975 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
976 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
981 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
985 syslinux_configfile (vtimghd,1)/syslinux.cfg
993 function ventoy_img_freedombox {
994 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
995 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
997 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
998 if [ -n "$vt_module_ver" ]; then
999 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1005 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1008 configfile (vtimghd,1)/boot/grub/grub.cfg
1014 function ventoy_img_paldo {
1015 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1016 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1021 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1024 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1025 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1027 echo loading file...
1028 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1029 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1036 function ventoy_img_ubos {
1037 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1038 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1040 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1041 if [ -n "$vt_module_ver" ]; then
1042 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1048 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1051 echo loading file...
1052 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1053 initrd (vtimghd,2)/initramfs-linux.img
1060 function ventoy_img_recalbox {
1061 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1062 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1067 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1070 set root=(vtimghd,1)
1071 configfile (vtimghd,1)/boot/grub/grub.cfg
1077 function ventoy_img_batocera {
1078 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1079 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1084 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1087 set root=(vtimghd,1)
1088 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1094 function ventoy_img_memtest86 {
1095 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
1099 function img_unsupport_tip {
1100 echo -e "\n This IMG file is NOT supported now. \n"
1101 echo -e " 当前不支持启动此 IMG 文件 \n"
1102 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1106 function img_common_menuentry {
1107 set ventoy_compatible=YES
1108 set ventoy_busybox_ver=32
1110 vt_chosen_img_path vt_chosen_path vt_chosen_size
1112 if [ -d (vtimghd)/ ]; then
1116 loopback vtimghd ${vtoy_iso_part}${vt_chosen_path}
1117 vt_img_sector ${vtoy_iso_part}${vt_chosen_path}
1119 vt_img_part_info (vtimghd)
1121 set vtback_root=$root
1125 vt_img_extra_initrd_reset
1127 vt_get_fs_label (vtimghd,1) vtImgHd1Label
1128 if [ -d (vtimghd,2)/lib ]; then
1129 vt_get_fs_label (vtimghd,2) vtImgHd2Label
1132 if [ -e (vtimghd,1)/etc/hostname ]; then
1133 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
1136 if [ -e (vtimghd,1)/easy.sfs ]; then
1138 elif [ -e (vtimghd,1)/volumio.initrd ]; then
1140 elif vt_str_begin $vtImgHd1Label "LAKKA"; then
1141 ventoy_img_openelec lakka
1142 elif vt_str_begin $vtImgHd1Label "LIBREELEC"; then
1143 ventoy_img_openelec LibreELEC
1144 elif vt_str_begin $vtImgHd1Label "paldo-live"; then
1146 elif vt_str_begin $vtImgHostname "freedombox"; then
1147 ventoy_img_freedombox
1148 elif vt_str_begin $vtImgHd1Label "BATOCERA"; then
1150 elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
1152 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
1154 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
1155 if [ "$grub_platform" = "pc" ]; then
1158 ventoy_img_memtest86
1161 if [ "$grub_platform" = "pc" ]; then
1164 vt_linux_chain_data ${vtoy_iso_part}${vt_chosen_path}
1165 chainloader ${vtoy_path}/ventoy_x64.efi sector512 env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1170 set root=$vtback_root
1173 set ventoy_compatible=NO
1176 function img_unsupport_menuentry {
1177 common_unsupport_menuentry
1180 #############################################################
1181 #############################################################
1182 #############################################################
1183 ####### Main Process ###########
1184 #############################################################
1185 #############################################################
1186 #############################################################
1188 set VENTOY_VERSION="1.0.20"
1190 # Default menu display mode, you can change it as you want.
1193 set VTOY_DEFAULT_MENU_MODE=0
1195 set VTOY_MEM_DISK_STR="[Memdisk]"
1196 set VTOY_ISO_RAW_STR="Compatible Mode"
1197 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
1199 set VTOY_F2_CMD="ventoy_power"
1200 set VTOY_F4_CMD="ventoy_localboot"
1201 set VTOY_F5_CMD="ventoy_diagnosis"
1202 set VTOY_F6_CMD="ventoy_ext_menu"
1204 if [ "$grub_platform" = "pc" ]; then
1205 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1207 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1210 vt_device $root vtoy_dev
1212 if [ "$vtoy_dev" = "tftp" ]; then
1213 set vtoy_path=($root)
1214 for vtid in 0 1 2 3; do
1215 if [ -d (hd$vtid,2)/ventoy ]; then
1216 set vtoy_iso_part=(hd$vtid,1)
1217 set vtoy_efi_part=(hd$vtid,2)
1223 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1224 set vt_plugin_path=$vtoy_iso_part
1226 set vt_plugin_path=$prefix
1227 vt_load_plugin $vt_plugin_path
1230 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1231 set vtoy_path=(ventoydisk)/ventoy
1233 set vtoy_path=($root)/ventoy
1236 set vtoy_iso_part=($vtoy_dev,1)
1237 set vtoy_efi_part=($vtoy_dev,2)
1239 set vt_plugin_path=$vtoy_iso_part
1244 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1245 vt_load_plugin $vtoy_iso_part
1248 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1249 set timeout=$VTOY_MENU_TIMEOUT
1254 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1255 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1256 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1257 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1261 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1262 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1263 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
1265 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1266 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
1270 if [ -n "$vtoy_gfxmode" ]; then
1271 set gfxmode=$vtoy_gfxmode
1273 set gfxmode=1920x1080,1366x768,1024x768
1276 if [ "$vtoy_display_mode" = "CLI" ]; then
1277 terminal_output console
1278 elif [ "$vtoy_display_mode" = "serial" ]; then
1279 if [ -n "$vtoy_serial_param" ]; then
1280 serial $vtoy_serial_param
1282 terminal_input serial
1283 terminal_output serial
1284 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1285 if [ -n "$vtoy_serial_param" ]; then
1286 serial $vtoy_serial_param
1288 terminal_input serial console
1289 terminal_output serial console
1291 if [ -n "$vtoy_theme" ]; then
1292 set theme=$vtoy_theme
1294 set theme=$prefix/themes/ventoy/theme.txt
1296 terminal_output gfxterm
1299 #export necessary variable
1303 export vtoy_iso_part
1304 export vtoy_efi_part
1305 export VENTOY_VERSION
1310 #colect all image files (iso files)
1311 set ventoy_img_count=0
1312 vt_list_img $vtoy_iso_part ventoy_img_count
1315 if [ $ventoy_img_count -gt 0 ]; then
1316 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1322 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1323 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1324 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1325 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1327 NO_ISO_MENU="No ISO files found"
1329 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1330 echo -e "\n Rebooting ... "