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)/hyperbola/boot/x86_64/hyperiso.img ]; then
210 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
211 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
212 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
214 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
216 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
217 if [ "$grub_platform" != "pc" ]; then
218 vt_add_replace_file 0 "initrd.img"
220 elif [ -f (loop)/initrd ]; then
221 vt_linux_specify_initrd_file /initrd
222 elif [ -f (loop)/live/initrd1 ]; then
223 vt_linux_specify_initrd_file /live/initrd1
228 function ventoy_get_ghostbsd_ver {
230 # vt_parse_iso_create_date $1/${chosen_path} vt_create_date
231 # if regexp "^202005" "$vt_create_date"; then
232 # set vt_freebsd_ver=12.x
235 set vt_freebsd_ver=12.x
238 function ventoy_get_furybsd_ver {
239 if regexp "13\.[0-9]" "$2"; then
240 set vt_freebsd_ver=13.x
242 set vt_freebsd_ver=12.x
246 function ventoy_get_freenas_ver {
247 set vt_freebsd_ver=11.x
249 if [ -e (loop)/FreeNAS-MANIFEST ]; then
250 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
251 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
252 set vt_freebsd_ver=13.x
253 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
254 set vt_freebsd_ver=12.x
255 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
256 set vt_freebsd_ver=11.x
261 function ventoy_freebsd_proc {
262 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
263 ventoy_get_ghostbsd_ver $1 ${chosen_path}
264 elif vt_strstr "$vt_volume_id" "FREENAS"; then
265 ventoy_get_freenas_ver $1 ${chosen_path}
266 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
267 ventoy_get_furybsd_ver $1 ${chosen_path}
268 elif regexp "^13_[0-9]" "$vt_volume_id"; then
269 set vt_freebsd_ver=13.x
270 elif regexp "^12_[0-9]" "$vt_volume_id"; then
271 set vt_freebsd_ver=12.x
272 elif regexp "^11_[0-9]" "$vt_volume_id"; then
273 set vt_freebsd_ver=11.x
274 elif regexp "^10_[0-9]" "$vt_volume_id"; then
275 set vt_freebsd_ver=10.x
276 elif regexp "^9_[0-9]" "$vt_volume_id"; then
277 set vt_freebsd_ver=9.x
278 elif [ -e (loop)/bin/freebsd-version ]; then
279 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
280 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
281 set vt_freebsd_ver=13.x
282 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
283 set vt_freebsd_ver=12.x
284 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
285 set vt_freebsd_ver=11.x
286 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
287 set vt_freebsd_ver=10.x
288 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
289 set vt_freebsd_ver=9.x
291 elif [ -e (loop)/README.TXT ]; then
292 vt_1st_line (loop)/README.TXT vt_freebsd_line1
293 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
294 set vt_freebsd_ver=13.x
295 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
296 set vt_freebsd_ver=12.x
297 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
298 set vt_freebsd_ver=11.x
299 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
300 set vt_freebsd_ver=10.x
301 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
302 set vt_freebsd_ver=9.x
304 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
305 set vt_freebsd_ver=9.x
307 set vt_freebsd_ver=12.x
310 set vt_freebsd_bit=64
311 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
312 if [ -e (loop)/$file ]; then
313 if file --is-i386-kfreebsd (loop)/$file; then
314 set vt_freebsd_bit=32
320 if [ -n "${vtdebug_flag}" ]; then
321 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
324 unset vt_unix_mod_path
325 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version" "/etc/fstab"; do
326 if [ -e (loop)${file} ]; then
327 set vt_unix_mod_path=${file}
332 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
333 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
336 function ventoy_unix_comm_proc {
339 if [ "$ventoy_compatible" = "NO" ]; then
340 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
342 if [ "$vt_unix_type" = "FreeBSD" ]; then
343 ventoy_freebsd_proc $1 ${chosen_path}
344 elif [ "$vt_unix_type" = "NetBSD" ]; then
345 echo "NetBSD not supported"
350 if [ -n "${vtdebug_flag}" ]; then
351 echo "Unknown unix type"
356 vt_unix_chain_data ${1}${chosen_path}
361 function uefi_windows_menu_func {
364 if [ "$ventoy_compatible" = "NO" ]; then
366 if [ "$ventoy_fs_probe" = "iso9660" ]; then
368 vt_iso9660_nojoliet 1
372 for file in "efi/microsoft/boot/bcd"; do
373 vt_windows_collect_wim_patch bcd (loop)/$file
376 vt_windows_count_wim_patch vt_wim_cnt
377 if [ $vt_wim_cnt -eq 0 ]; then
378 distro_specify_wim_patch_phase2
385 vt_windows_chain_data ${1}${chosen_path}
388 if [ -n "$vtoy_chain_mem_addr" ]; then
390 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
393 echo "chain empty failed"
398 function uefi_linux_menu_func {
399 if [ "$ventoy_compatible" = "NO" ]; then
401 if [ "$ventoy_fs_probe" = "udf" ]; then
403 set ventoy_fs_probe=iso9660
407 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
409 vt_linux_clear_initrd
411 if [ -d (loop)/pmagic ]; then
412 vt_linux_specify_initrd_file /pmagic/initrd.img
414 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
415 if [ -e (loop)/$file ]; then
416 vt_linux_parse_initrd_grub file (loop)/$file
421 # special process for special distros
422 if [ -d (loop)/loader/entries ]; then
423 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
424 elif [ -d (loop)/boot/grub ]; then
425 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
428 distro_specify_initrd_file
430 vt_linux_initrd_count vtcount
431 if [ $vtcount -eq 0 ]; then
432 distro_specify_initrd_file_phase2
434 if [ "$vt_efi_dir" = "NO" ]; then
435 if [ -f (loop)/efi.img ]; then
436 vt_add_replace_file 0 "initrd"
443 if [ -d (loop)/loader/entries ]; then
444 vt_linux_get_main_initrd_index vtindex
446 if [ -d (loop)/arch ]; then
447 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
448 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
449 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
450 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
452 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
453 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
454 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
455 vt_add_replace_file $vtindex "boot\\initrd"
457 elif [ -d (loop)/EFI/boot/entries ]; then
458 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
459 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
460 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
461 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
463 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
464 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
465 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
470 vt_linux_chain_data ${1}${chosen_path}
472 if [ -n "$vtoy_chain_mem_addr" ]; then
474 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}
477 echo "chain empty failed"
482 function uefi_unix_menu_func {
483 ventoy_unix_comm_proc $1 ${chosen_path}
485 if [ -n "$vtoy_chain_mem_addr" ]; then
487 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}
490 echo "chain empty failed"
495 function uefi_iso_menu_func {
497 if [ -d (loop)/ ]; then
501 if [ -n "$vtisouefi" ]; then
502 set LoadIsoEfiDriver=on
504 elif vt_check_mode 2; then
505 set LoadIsoEfiDriver=on
507 unset LoadIsoEfiDriver
511 vt_select_auto_install ${chosen_path}
512 vt_select_persistence ${chosen_path}
514 if vt_is_udf ${1}${chosen_path}; then
515 set ventoy_fs_probe=udf
517 set ventoy_fs_probe=iso9660
518 vt_iso9660_nojoliet 0
521 loopback loop ${1}${chosen_path}
524 if [ -d (loop)/EFI ]; then
526 elif [ -d (loop)/efi ]; then
532 if [ -n "$vtcompat" ]; then
533 set ventoy_compatible=YES
535 elif vt_check_mode 1; then
536 set ventoy_compatible=YES
538 vt_check_compatible (loop)
541 vt_img_sector ${1}${chosen_path}
543 if [ "$vtoy_os" = "Windows" ]; then
544 vt_check_compatible_pe (loop)
545 uefi_windows_menu_func $1 ${chosen_path}
546 elif [ "$vtoy_os" = "Unix" ]; then
547 uefi_unix_menu_func $1 ${chosen_path}
549 uefi_linux_menu_func $1 ${chosen_path}
555 function uefi_iso_memdisk {
556 echo 'Loading ISO file to memory ...'
557 vt_load_img_memdisk ${1}${2} vtoy_iso_buf
560 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}
567 function legacy_windows_menu_func {
570 if [ "$ventoy_compatible" = "NO" ]; then
572 if [ "$ventoy_fs_probe" = "iso9660" ]; then
574 vt_iso9660_nojoliet 1
578 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
579 vt_windows_collect_wim_patch bcd (loop)/$file
582 distro_specify_wim_patch
584 vt_windows_count_wim_patch vt_wim_cnt
585 if [ $vt_wim_cnt -eq 0 ]; then
586 distro_specify_wim_patch_phase2
593 vt_windows_chain_data ${1}${chosen_path}
596 if [ -n "$vtoy_chain_mem_addr" ]; then
597 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
600 echo "chain empty failed"
605 function legacy_linux_menu_func {
606 if [ "$ventoy_compatible" = "NO" ]; then
608 if [ "$ventoy_fs_probe" = "udf" ]; then
610 set ventoy_fs_probe=iso9660
614 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
616 vt_linux_clear_initrd
618 if [ -d (loop)/pmagic ]; then
619 vt_linux_specify_initrd_file /pmagic/initrd.img
621 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
622 if [ -d (loop)/$dir ]; then
623 vt_linux_parse_initrd_isolinux (loop)/$dir/
628 # special process for special distros
630 if [ -d (loop)/arch/boot/syslinux ]; then
631 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
632 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
635 elif [ -d (loop)/manjaro ]; then
636 if [ -e (loop)/boot/grub/kernels.cfg ]; then
637 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
639 elif [ -e (loop)/boot/grub/grub.cfg ]; then
640 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
643 distro_specify_initrd_file
645 vt_linux_initrd_count vtcount
646 if [ $vtcount -eq 0 ]; then
647 distro_specify_initrd_file_phase2
653 vt_linux_chain_data ${1}${chosen_path}
656 if [ -n "$vtoy_chain_mem_addr" ]; then
657 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
660 echo "chain empty failed"
666 function legacy_unix_menu_func {
667 ventoy_unix_comm_proc $1 ${chosen_path}
669 if [ -n "$vtoy_chain_mem_addr" ]; then
670 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
673 echo "chain empty failed"
679 function legacy_iso_menu_func {
681 if [ -d (loop)/ ]; then
686 vt_select_auto_install ${chosen_path}
687 vt_select_persistence ${chosen_path}
689 if vt_is_udf ${1}${chosen_path}; then
690 set ventoy_fs_probe=udf
692 set ventoy_fs_probe=iso9660
693 vt_iso9660_nojoliet 0
696 loopback loop ${1}${chosen_path}
700 if [ -n "$vtcompat" ]; then
701 set ventoy_compatible=YES
703 elif vt_check_mode 1; then
704 set ventoy_compatible=YES
706 vt_check_compatible (loop)
709 vt_img_sector ${1}${chosen_path}
711 if [ "$vtoy_os" = "Windows" ]; then
712 vt_check_compatible_pe (loop)
713 legacy_windows_menu_func $1 ${chosen_path}
714 elif [ "$vtoy_os" = "Unix" ]; then
715 legacy_unix_menu_func $1 ${chosen_path}
717 legacy_linux_menu_func $1 ${chosen_path}
721 function legacy_iso_memdisk {
723 linux16 $vtoy_path/memdisk iso raw
724 echo "Loading ISO file to memory ..."
730 function iso_endless_os_proc {
731 if [ -d (loop)/ ]; then
735 loopback loop ${1}${2}
736 vt_img_sector ${1}${2}
738 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
739 vt_trailer_cpio $1 $2 noinit
743 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
746 set ventoy_bls_bootdev=/boot
747 set ventoy_loading_tip="Loading files ......"
750 configfile (loop)/endless/grub/grub.cfg
753 unset ventoy_bls_bootdev
754 unset ventoy_loading_tip
760 function ventoy_iso_busybox_ver {
761 set ventoy_busybox_ver=32
763 #special process for deepin-live iso
764 if [ "$vt_chosen_size" = "403701760" ]; then
765 if vt_str_begin $vt_chosen_path "/deepin-live"; then
766 set ventoy_busybox_ver=64
771 function iso_common_menuentry {
775 vt_chosen_img_path vt_chosen_path vt_chosen_size
776 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
778 ventoy_iso_busybox_ver
780 #special process for Endless OS
781 if vt_str_begin $vt_volume_id "Endless-OS"; then
782 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
785 if [ "$grub_platform" = "pc" ]; then
786 if vt_check_mode 0; then
787 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
789 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
792 if vt_check_mode 0; then
793 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
795 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
800 function common_unsupport_menuentry {
801 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
802 echo -e " 文件名中不能有中文或空格 \n"
803 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
807 function iso_unsupport_menuentry {
808 common_unsupport_menuentry
811 function wim_common_menuentry {
812 vt_chosen_img_path vt_chosen_path vt_chosen_size
813 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
817 if [ -n "$vtoy_chain_mem_addr" ]; then
818 if [ "$grub_platform" = "pc" ]; then
819 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
822 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
827 echo "chain empty failed"
832 function wim_unsupport_menuentry {
833 common_unsupport_menuentry
836 function efi_common_menuentry {
837 vt_chosen_img_path vt_chosen_path vt_chosen_size
839 vt_concat_efi_iso ${vtoy_iso_part}${vt_chosen_path} vtoy_iso_buf
844 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}
849 function efi_unsupport_menuentry {
850 common_unsupport_menuentry
854 #============================================================#
855 # IMG file boot process #
856 #============================================================#
860 function ventoy_img_easyos {
861 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
862 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
864 loopback easysfs (vtimghd,1)/easy.sfs
865 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
867 if [ -n "$vt_module_ver" ]; then
868 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
869 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
876 vt_set_boot_opt rdinit=/vtoy/vtoy
879 syslinux_configfile (vtimghd,1)/syslinux.cfg
886 function ventoy_img_volumio {
887 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
888 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
893 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
896 syslinux_configfile (vtimghd,1)/syslinux.cfg
902 function ventoy_img_fydeos {
904 set ventoy_busybox_ver=64
906 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
907 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
909 # loopback easysfs (vtimghd,1)/easy.sfs
910 # vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
912 # if [ -n "$vt_module_ver" ]; then
913 # for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
914 # vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
921 vt_set_boot_opt rdinit=/vtoy/vtoy
924 set root=(vtimghd,12)
925 configfile (vtimghd,12)/efi/boot/grub.cfg
926 #syslinux_configfile (vtimghd,12)/syslinux/syslinux.cfg
933 function img_common_menuentry {
934 set ventoy_busybox_ver=32
936 vt_chosen_img_path vt_chosen_path vt_chosen_size
938 if [ -d (vtimghd)/ ]; then
942 loopback vtimghd ${vtoy_iso_part}${vt_chosen_path}
943 vt_img_sector ${vtoy_iso_part}${vt_chosen_path}
945 vt_img_part_info (vtimghd)
947 set vtback_root=$root
951 vt_img_extra_initrd_reset
953 if [ -e (vtimghd,1)/easy.sfs ]; then
955 elif [ -e (vtimghd,1)/volumio.initrd ]; then
957 elif [ -e (vtimghd,3)/etc/os-release ]; then
958 if vt_file_strstr (vtimghd,3)/etc/os-release FydeOS; then
963 echo -e "\n This IMG file is NOT supported now. \n"
964 echo -e " 当前不支持启动此 IMG 文件 \n"
965 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
969 set root=$vtback_root
974 function img_unsupport_menuentry {
975 common_unsupport_menuentry
978 #############################################################
979 #############################################################
980 #############################################################
981 ####### Main Process ###########
982 #############################################################
983 #############################################################
984 #############################################################
986 set VENTOY_VERSION="1.0.18"
988 # Default menu display mode, you can change it as you want.
991 set VTOY_DEFAULT_MENU_MODE=0
993 set VTOY_MEM_DISK_STR="[Memdisk]"
994 set VTOY_ISO_RAW_STR="Compatible Mode"
995 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
997 set VTOY_F2_CMD="ventoy_power"
998 set VTOY_F4_CMD="ventoy_localboot"
999 set VTOY_F5_CMD="ventoy_diagnosis"
1000 set VTOY_F6_CMD="ventoy_ext_menu"
1002 if [ "$grub_platform" = "pc" ]; then
1003 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1005 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1008 vt_device $root vtoy_dev
1010 if [ "$vtoy_dev" = "tftp" ]; then
1011 set vtoy_path=($root)
1012 for vtid in 0 1 2 3; do
1013 if [ -d (hd$vtid,2)/ventoy ]; then
1014 set vtoy_iso_part=(hd$vtid,1)
1015 set vtoy_efi_part=(hd$vtid,2)
1021 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1022 set vt_plugin_path=$vtoy_iso_part
1024 set vt_plugin_path=$prefix
1025 vt_load_plugin $vt_plugin_path
1028 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1029 set vtoy_path=(ventoydisk)/ventoy
1031 set vtoy_path=($root)/ventoy
1034 set vtoy_iso_part=($vtoy_dev,1)
1035 set vtoy_efi_part=($vtoy_dev,2)
1037 set vt_plugin_path=$vtoy_iso_part
1042 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1043 vt_load_plugin $vtoy_iso_part
1046 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1047 set timeout=$VTOY_MENU_TIMEOUT
1052 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1053 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1054 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1055 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1059 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1060 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1061 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
1063 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1064 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
1068 if [ -n "$vtoy_gfxmode" ]; then
1069 set gfxmode=$vtoy_gfxmode
1071 set gfxmode=1920x1080,1366x768,1024x768
1074 if [ "$vtoy_display_mode" = "CLI" ]; then
1075 terminal_output console
1076 elif [ "$vtoy_display_mode" = "serial" ]; then
1077 if [ -n "$vtoy_serial_param" ]; then
1078 serial $vtoy_serial_param
1080 terminal_input serial
1081 terminal_output serial
1082 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1083 if [ -n "$vtoy_serial_param" ]; then
1084 serial $vtoy_serial_param
1086 terminal_input serial console
1087 terminal_output serial console
1089 if [ -n "$vtoy_theme" ]; then
1090 set theme=$vtoy_theme
1092 set theme=$prefix/themes/ventoy/theme.txt
1094 terminal_output gfxterm
1097 #export necessary variable
1101 export vtoy_iso_part
1102 export vtoy_efi_part
1103 export VENTOY_VERSION
1108 #colect all image files (iso files)
1109 set ventoy_img_count=0
1110 vt_list_img $vtoy_iso_part ventoy_img_count
1113 if [ $ventoy_img_count -gt 0 ]; then
1114 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1120 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1121 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1122 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1123 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1125 NO_ISO_MENU="No ISO files found"
1127 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1128 echo -e "\n Rebooting ... "