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 {
53 configfile $prefix/debug.cfg
56 function ventoy_localboot {
57 configfile $prefix/localboot.cfg
60 function ventoy_ext_menu {
61 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
62 set ventoy_new_context=1
63 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
64 unset ventoy_new_context
66 echo "ventoy_grub.cfg NOT exist."
67 echo -e "\npress ENTER to exit ..."
72 function get_os_type {
75 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
76 if vt_file_exist_nocase (loop)/$file; then
82 if [ "$vtoy_os" = "Linux" ]; then
83 if vt_strstr "$vt_system_id" "FreeBSD"; then
85 set vt_unix_type=FreeBSD
86 elif [ -e (loop)/bin/freebsd-version ]; then
88 set vt_unix_type=FreeBSD
91 elif [ -e (loop)/boot/kernel/kernel ]; then
92 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
94 set vt_unix_type=FreeBSD
95 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
97 set vt_unix_type=NetBSD
102 if [ -n "${vtdebug_flag}" ]; then
107 function vt_check_compatible_pe {
108 #Check for PE without external tools
109 if [ -f $1/HBCD_PE.ini ]; then
110 set ventoy_compatible=YES
114 function locate_initrd {
115 vt_linux_locate_initrd
117 if [ -n "${vtdebug_flag}" ]; then
123 function locate_wim {
124 vt_windows_locate_wim_patch (loop)
126 if [ -n "${vtdebug_flag}" ]; then
127 echo '###############################################'
129 echo '###############################################'
134 function distro_specify_wim_patch {
135 if [ -d (loop)/h3pe ]; then
136 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
137 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
138 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
139 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
143 function distro_specify_wim_patch_phase2 {
144 if [ -f (loop)/boot/boot.wim ]; then
145 vt_windows_collect_wim_patch wim /boot/boot.wim
150 function distro_specify_initrd_file {
151 if [ -e (loop)/boot/all.rdz ]; then
152 vt_linux_specify_initrd_file /boot/all.rdz
153 elif [ -e (loop)/boot/xen.gz ]; then
154 if [ -e (loop)/install.img ]; then
155 vt_linux_specify_initrd_file /install.img
157 elif [ -d (loop)/casper ]; then
158 if [ -e (loop)/casper/initrd ]; then
159 vt_linux_specify_initrd_file /casper/initrd
161 if [ -e (loop)/casper/initrd.gz ]; then
162 vt_linux_specify_initrd_file /casper/initrd.gz
164 if [ -e (loop)/casper/initrd-oem ]; then
165 vt_linux_specify_initrd_file /casper/initrd-oem
167 elif [ -e (loop)/boot/grub/initrd.xz ]; then
168 vt_linux_specify_initrd_file /boot/grub/initrd.xz
169 elif [ -e (loop)/initrd.gz ]; then
170 vt_linux_specify_initrd_file /initrd.gz
171 elif [ -e (loop)/slax/boot/initrfs.img ]; then
172 vt_linux_specify_initrd_file /slax/boot/initrfs.img
173 elif [ -e (loop)/pmagic/initrd.img ]; then
174 vt_linux_specify_initrd_file /pmagic/initrd.img
175 elif [ -e (loop)/boot/initrd.xz ]; then
176 vt_linux_specify_initrd_file /boot/initrd.xz
177 elif [ -e (loop)/boot/initrd.gz ]; then
178 vt_linux_specify_initrd_file /boot/initrd.gz
179 elif [ -f (loop)/boot/initrd ]; then
180 vt_linux_specify_initrd_file /boot/initrd
181 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
182 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
183 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
184 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
185 elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
186 vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
191 if [ -f (loop)/isolinux/initrd.gz ]; then
192 vt_linux_specify_initrd_file /isolinux/initrd.gz
195 if [ "$vt_chosen_size" = "1133375488" ]; then
196 if [ -d (loop)/boot/grub/x86_64-efi ]; then
203 function distro_specify_initrd_file_phase2 {
204 if [ -f (loop)/boot/initrd.img ]; then
205 vt_linux_specify_initrd_file /boot/initrd.img
206 elif [ -f (loop)/Setup/initrd.gz ]; then
207 vt_linux_specify_initrd_file /Setup/initrd.gz
208 elif [ -f (loop)/isolinux/initramfs ]; then
209 vt_linux_specify_initrd_file /isolinux/initramfs
210 elif [ -f (loop)/boot/iniramfs.igz ]; then
211 vt_linux_specify_initrd_file /boot/iniramfs.igz
212 elif [ -f (loop)/initrd-x86_64 ]; then
213 vt_linux_specify_initrd_file /initrd-x86_64
214 elif [ -f (loop)/live/initrd.img ]; then
215 vt_linux_specify_initrd_file /live/initrd.img
216 elif [ -f (loop)/initrd.img ]; then
217 vt_linux_specify_initrd_file /initrd.img
218 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
219 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
220 elif [ -f (loop)/CDlinux/initrd ]; then
221 vt_linux_specify_initrd_file /CDlinux/initrd
222 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
223 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
224 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
225 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
227 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
228 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
229 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
230 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
232 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
234 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
235 if [ "$grub_platform" != "pc" ]; then
236 vt_add_replace_file 0 "initrd.img"
238 elif [ -f (loop)/initrd ]; then
239 vt_linux_specify_initrd_file /initrd
240 elif [ -f (loop)/live/initrd1 ]; then
241 vt_linux_specify_initrd_file /live/initrd1
242 elif [ -f (loop)/isolinux/initrd.img ]; then
243 vt_linux_specify_initrd_file /isolinux/initrd.img
244 elif [ -f (loop)/isolinux/initrd.gz ]; then
245 vt_linux_specify_initrd_file /isolinux/initrd.gz
246 elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
247 vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
248 elif vt_strstr $vt_volume_id "Daphile"; then
249 vt_linux_parse_initrd_isolinux (loop)/isolinux/
250 elif [ -f (loop)/boot/rootfs.xz ]; then
251 vt_linux_specify_initrd_file /boot/rootfs.xz
252 if [ "$grub_platform" != "pc" ]; then
253 vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
259 function ventoy_get_ghostbsd_ver {
261 # vt_parse_iso_create_date $1/${chosen_path} vt_create_date
262 # if regexp "^202005" "$vt_create_date"; then
263 # set vt_freebsd_ver=12.x
266 set vt_freebsd_ver=12.x
269 function ventoy_get_furybsd_ver {
270 if regexp "13\.[0-9]" "$2"; then
271 set vt_freebsd_ver=13.x
273 set vt_freebsd_ver=12.x
277 function ventoy_get_freenas_ver {
278 set vt_freebsd_ver=11.x
280 if [ -e (loop)/FreeNAS-MANIFEST ]; then
281 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
282 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
283 set vt_freebsd_ver=13.x
284 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
285 set vt_freebsd_ver=12.x
286 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
287 set vt_freebsd_ver=11.x
292 function ventoy_get_midnightbsd_ver {
293 set vt_freebsd_ver=11.x
296 function ventoy_freebsd_proc {
297 set vtFreeBsdDistro=FreeBSD
299 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
300 ventoy_get_ghostbsd_ver $1 ${chosen_path}
301 elif vt_strstr "$vt_volume_id" "FREENAS"; then
302 ventoy_get_freenas_ver $1 ${chosen_path}
303 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
304 ventoy_get_furybsd_ver $1 ${chosen_path}
305 elif regexp "^13_[0-9]" "$vt_volume_id"; then
306 set vt_freebsd_ver=13.x
307 elif regexp "^12_[0-9]" "$vt_volume_id"; then
308 set vt_freebsd_ver=12.x
309 elif regexp "^11_[0-9]" "$vt_volume_id"; then
310 set vt_freebsd_ver=11.x
311 elif regexp "^10_[0-9]" "$vt_volume_id"; then
312 set vt_freebsd_ver=10.x
313 elif regexp "^9_[0-9]" "$vt_volume_id"; then
314 set vt_freebsd_ver=9.x
315 elif [ -d (loop)/usr/midnightbsd-dist ]; then
316 ventoy_get_midnightbsd_ver $1 ${chosen_path}
317 set vtFreeBsdDistro=MidnightBSD
318 elif [ -e (loop)/bin/freebsd-version ]; then
319 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
320 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
321 set vt_freebsd_ver=13.x
322 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
323 set vt_freebsd_ver=12.x
324 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
325 set vt_freebsd_ver=11.x
326 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
327 set vt_freebsd_ver=10.x
328 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
329 set vt_freebsd_ver=9.x
331 elif [ -e (loop)/README.TXT ]; then
332 vt_1st_line (loop)/README.TXT vt_freebsd_line1
333 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
334 set vt_freebsd_ver=13.x
335 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
336 set vt_freebsd_ver=12.x
337 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
338 set vt_freebsd_ver=11.x
339 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
340 set vt_freebsd_ver=10.x
341 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
342 set vt_freebsd_ver=9.x
344 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
345 set vt_freebsd_ver=9.x
347 set vt_freebsd_ver=12.x
350 set vt_freebsd_bit=64
351 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
352 if [ -e (loop)/$file ]; then
353 if file --is-i386-kfreebsd (loop)/$file; then
354 set vt_freebsd_bit=32
360 if [ -n "${vtdebug_flag}" ]; then
361 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
364 unset vt_unix_mod_path
365 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version" "/etc/fstab"; do
366 if [ -e (loop)${file} ]; then
367 set vt_unix_mod_path=${file}
372 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
373 set vtFreeBsdDistro=ClonOS
376 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
377 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
380 function ventoy_unix_comm_proc {
383 if [ "$ventoy_compatible" = "NO" ]; then
384 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
386 if [ "$vt_unix_type" = "FreeBSD" ]; then
387 ventoy_freebsd_proc $1 ${chosen_path}
388 elif [ "$vt_unix_type" = "NetBSD" ]; then
389 echo "NetBSD not supported"
394 if [ -n "${vtdebug_flag}" ]; then
395 echo "Unknown unix type"
400 vt_unix_chain_data ${1}${chosen_path}
405 function uefi_windows_menu_func {
408 if [ "$ventoy_compatible" = "NO" ]; then
410 if [ "$ventoy_fs_probe" = "iso9660" ]; then
412 vt_iso9660_nojoliet 1
416 for file in "efi/microsoft/boot/bcd"; do
417 vt_windows_collect_wim_patch bcd (loop)/$file
420 vt_windows_count_wim_patch vt_wim_cnt
421 if [ $vt_wim_cnt -eq 0 ]; then
422 distro_specify_wim_patch_phase2
429 vt_windows_chain_data ${1}${chosen_path}
432 if [ -n "$vtoy_chain_mem_addr" ]; then
434 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
437 echo "chain empty failed"
442 function uefi_linux_menu_func {
443 if [ "$ventoy_compatible" = "NO" ]; then
445 if [ "$ventoy_fs_probe" = "udf" ]; then
447 set ventoy_fs_probe=iso9660
451 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
453 vt_linux_clear_initrd
455 if [ -d (loop)/pmagic ]; then
456 vt_linux_specify_initrd_file /pmagic/initrd.img
458 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
459 if [ -e (loop)/$file ]; then
460 vt_linux_parse_initrd_grub file (loop)/$file
465 # special process for special distros
466 if [ -d (loop)/loader/entries ]; then
467 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
468 elif [ -d (loop)/boot/grub ]; then
469 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
472 distro_specify_initrd_file
474 vt_linux_initrd_count vtcount
475 if [ $vtcount -eq 0 ]; then
476 distro_specify_initrd_file_phase2
478 if [ "$vt_efi_dir" = "NO" ]; then
479 if [ -f (loop)/efi.img ]; then
480 vt_add_replace_file 0 "initrd"
487 if [ -d (loop)/loader/entries ]; then
488 vt_linux_get_main_initrd_index vtindex
490 if [ -d (loop)/arch ]; then
491 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
492 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
493 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
494 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
496 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
497 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
498 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
499 vt_add_replace_file $vtindex "boot\\initrd"
500 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
501 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
503 elif [ -d (loop)/EFI/boot/entries ]; then
504 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
505 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
506 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
507 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
509 elif [ -d (loop)/EFI/BOOT/entries ]; then
510 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
511 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
513 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
514 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
515 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
522 vt_linux_chain_data ${1}${chosen_path}
524 if [ -n "$vtoy_chain_mem_addr" ]; then
526 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}
529 echo "chain empty failed"
534 function uefi_unix_menu_func {
535 ventoy_unix_comm_proc $1 ${chosen_path}
537 if [ -n "$vtoy_chain_mem_addr" ]; then
539 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}
542 echo "chain empty failed"
547 function uefi_iso_menu_func {
549 if [ -d (loop)/ ]; then
553 if [ -n "$vtisouefi" ]; then
554 set LoadIsoEfiDriver=on
556 elif vt_check_mode 2; then
557 set LoadIsoEfiDriver=on
559 unset LoadIsoEfiDriver
563 vt_select_auto_install ${chosen_path}
564 vt_select_persistence ${chosen_path}
566 if vt_is_udf ${1}${chosen_path}; then
567 set ventoy_fs_probe=udf
569 set ventoy_fs_probe=iso9660
570 vt_iso9660_nojoliet 0
573 loopback loop ${1}${chosen_path}
576 if [ -d (loop)/EFI ]; then
578 elif [ -d (loop)/efi ]; then
584 if [ -n "$vtcompat" ]; then
585 set ventoy_compatible=YES
587 elif vt_check_mode 1; then
588 set ventoy_compatible=YES
590 vt_check_compatible (loop)
593 vt_img_sector ${1}${chosen_path}
595 if [ "$vtoy_os" = "Windows" ]; then
596 vt_check_compatible_pe (loop)
597 uefi_windows_menu_func $1 ${chosen_path}
598 elif [ "$vtoy_os" = "Unix" ]; then
599 uefi_unix_menu_func $1 ${chosen_path}
601 uefi_linux_menu_func $1 ${chosen_path}
607 function uefi_iso_memdisk {
608 echo 'Loading ISO file to memory ...'
609 vt_load_img_memdisk ${1}${2} vtoy_iso_buf
612 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}
619 function legacy_windows_menu_func {
622 if [ "$ventoy_compatible" = "NO" ]; then
624 if [ "$ventoy_fs_probe" = "iso9660" ]; then
626 vt_iso9660_nojoliet 1
630 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
631 vt_windows_collect_wim_patch bcd (loop)/$file
634 distro_specify_wim_patch
636 vt_windows_count_wim_patch vt_wim_cnt
637 if [ $vt_wim_cnt -eq 0 ]; then
638 distro_specify_wim_patch_phase2
645 vt_windows_chain_data ${1}${chosen_path}
648 if [ -n "$vtoy_chain_mem_addr" ]; then
649 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
650 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
651 terminal_output gfxterm
654 echo "chain empty failed"
659 function legacy_linux_menu_func {
660 if [ "$ventoy_compatible" = "NO" ]; then
662 if [ "$ventoy_fs_probe" = "udf" ]; then
664 set ventoy_fs_probe=iso9660
668 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
670 vt_linux_clear_initrd
672 if [ -d (loop)/pmagic ]; then
673 vt_linux_specify_initrd_file /pmagic/initrd.img
675 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
676 if [ -d (loop)/$dir ]; then
677 vt_linux_parse_initrd_isolinux (loop)/$dir/
682 # special process for special distros
684 if [ -d (loop)/arch/boot/syslinux ]; then
685 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
686 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
689 elif [ -d (loop)/manjaro ]; then
690 if [ -e (loop)/boot/grub/kernels.cfg ]; then
691 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
693 elif [ -e (loop)/boot/grub/grub.cfg ]; then
694 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
697 distro_specify_initrd_file
699 vt_linux_initrd_count vtcount
700 if [ $vtcount -eq 0 ]; then
701 if [ -d (loop)/rancheros ]; then
702 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
705 distro_specify_initrd_file_phase2
711 vt_linux_chain_data ${1}${chosen_path}
714 if [ -n "$vtoy_chain_mem_addr" ]; then
715 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
718 echo "chain empty failed"
724 function legacy_unix_menu_func {
725 ventoy_unix_comm_proc $1 ${chosen_path}
727 if [ -n "$vtoy_chain_mem_addr" ]; then
728 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
731 echo "chain empty failed"
737 function legacy_iso_menu_func {
739 if [ -d (loop)/ ]; then
744 vt_select_auto_install ${chosen_path}
745 vt_select_persistence ${chosen_path}
747 if vt_is_udf ${1}${chosen_path}; then
748 set ventoy_fs_probe=udf
750 set ventoy_fs_probe=iso9660
751 vt_iso9660_nojoliet 0
754 loopback loop ${1}${chosen_path}
758 if [ -n "$vtcompat" ]; then
759 set ventoy_compatible=YES
761 elif vt_check_mode 1; then
762 set ventoy_compatible=YES
764 vt_check_compatible (loop)
767 vt_img_sector ${1}${chosen_path}
769 if [ "$vtoy_os" = "Windows" ]; then
770 vt_check_compatible_pe (loop)
771 legacy_windows_menu_func $1 ${chosen_path}
772 elif [ "$vtoy_os" = "Unix" ]; then
773 legacy_unix_menu_func $1 ${chosen_path}
775 legacy_linux_menu_func $1 ${chosen_path}
779 function legacy_iso_memdisk {
781 linux16 $vtoy_path/memdisk iso raw
782 echo "Loading ISO file to memory ..."
788 function iso_endless_os_proc {
789 if [ -d (loop)/ ]; then
793 loopback loop ${1}${2}
794 vt_img_sector ${1}${2}
796 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
797 vt_trailer_cpio $1 $2 noinit
801 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
804 set ventoy_bls_bootdev=/boot
805 set ventoy_loading_tip="Loading files ......"
808 configfile (loop)/endless/grub/grub.cfg
811 unset ventoy_bls_bootdev
812 unset ventoy_loading_tip
818 function ventoy_iso_busybox_ver {
819 set ventoy_busybox_ver=32
821 #special process for deepin-live iso
822 if [ "$vt_chosen_size" = "403701760" ]; then
823 if vt_str_str $vt_chosen_path "/deepin-live"; then
824 set ventoy_busybox_ver=64
826 elif vt_str_begin $vt_volume_id "PHOTON_"; then
827 set ventoy_busybox_ver=64
828 elif vt_str_begin $vt_volume_id "smgl-test-quinq-x86_64"; then
829 set ventoy_busybox_ver=64
834 function iso_common_menuentry {
838 vt_chosen_img_path vt_chosen_path vt_chosen_size
839 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
841 ventoy_iso_busybox_ver
843 #special process for Endless OS
844 if vt_str_begin $vt_volume_id "Endless-OS"; then
845 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
846 elif vt_str_begin $vt_volume_id "TENS-Public"; then
850 if [ "$grub_platform" = "pc" ]; then
851 if vt_check_mode 0; then
852 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
854 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
857 if vt_check_mode 0; then
858 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
860 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
865 function miso_common_menuentry {
866 vt_chosen_img_path vt_chosen_path vt_chosen_size
868 echo "memdisk mode boot for $vt_chosen_path"
872 if [ "$grub_platform" = "pc" ]; then
873 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
875 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
880 function common_unsupport_menuentry {
881 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
882 echo -e " 文件名中不能有中文或空格 \n"
883 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
887 function miso_unsupport_menuentry {
888 common_unsupport_menuentry
891 function iso_unsupport_menuentry {
892 common_unsupport_menuentry
895 function wim_common_menuentry {
896 vt_chosen_img_path vt_chosen_path vt_chosen_size
897 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
901 if [ -n "$vtoy_chain_mem_addr" ]; then
902 if [ "$grub_platform" = "pc" ]; then
903 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
904 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
905 terminal_output gfxterm
908 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
913 echo "chain empty failed"
918 function wim_unsupport_menuentry {
919 common_unsupport_menuentry
922 function efi_common_menuentry {
923 vt_chosen_img_path vt_chosen_path vt_chosen_size
925 vt_concat_efi_iso ${vtoy_iso_part}${vt_chosen_path} vtoy_iso_buf
931 unset vtoy_dotefi_retry
932 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}
935 if [ -n "$vtoy_dotefi_retry" ]; then
936 unset vtoy_dotefi_retry
937 chainloader ${vtoy_iso_part}${vt_chosen_path}
944 function efi_unsupport_menuentry {
945 common_unsupport_menuentry
949 function vhd_common_menuentry {
951 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
952 if [ "$vtoy_iso_fs" != "ntfs" ]; then
953 echo -e "!!! WARNING !!!\n"
954 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
955 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
956 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
961 vt_chosen_img_path vt_chosen_path vt_chosen_size
962 vt_patch_vhdboot ${vt_chosen_path}
966 if [ -n "$vtoy_vhd_buf_addr" ]; then
967 if [ "$grub_platform" = "pc" ]; then
968 linux16 $vtoy_path/memdisk iso raw
969 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
971 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
972 terminal_output gfxterm
976 chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
981 echo "Failed to boot vhd file"
986 function vhd_unsupport_menuentry {
987 common_unsupport_menuentry
991 #============================================================#
992 # IMG file boot process #
993 #============================================================#
997 function ventoy_img_easyos {
998 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
999 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1001 loopback easysfs (vtimghd,1)/easy.sfs
1002 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1004 if [ -n "$vt_module_ver" ]; then
1005 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1006 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1013 vt_set_boot_opt rdinit=/vtoy/vtoy
1016 syslinux_configfile (vtimghd,1)/syslinux.cfg
1023 function ventoy_img_volumio {
1024 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1025 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1030 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1033 syslinux_configfile (vtimghd,1)/syslinux.cfg
1039 function ventoy_img_openelec {
1042 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1043 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1045 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1046 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1051 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1054 set root=(vtimghd,1)
1055 syslinux_configfile (vtimghd,1)/syslinux.cfg
1059 loopback -d vtloopex
1063 function ventoy_img_freedombox {
1064 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1065 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1067 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1068 if [ -n "$vt_module_ver" ]; then
1069 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1075 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1078 configfile (vtimghd,1)/boot/grub/grub.cfg
1084 function ventoy_img_paldo {
1085 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1086 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1091 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1094 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1095 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1097 echo loading file...
1098 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1099 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1106 function ventoy_img_ubos {
1107 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1108 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1110 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1111 if [ -n "$vt_module_ver" ]; then
1112 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1118 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1121 echo loading file...
1122 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1123 initrd (vtimghd,2)/initramfs-linux.img
1130 function ventoy_img_recalbox {
1131 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1132 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1137 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1140 set root=(vtimghd,1)
1141 configfile (vtimghd,1)/boot/grub/grub.cfg
1147 function ventoy_img_batocera {
1148 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1149 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1154 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1157 set root=(vtimghd,1)
1158 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1164 function ventoy_img_memtest86 {
1165 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
1169 function img_unsupport_tip {
1170 echo -e "\n This IMG file is NOT supported now. \n"
1171 echo -e " 当前不支持启动此 IMG 文件 \n"
1172 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1176 function img_common_menuentry {
1177 set ventoy_compatible=YES
1178 set ventoy_busybox_ver=32
1180 vt_chosen_img_path vt_chosen_path vt_chosen_size
1182 if [ -d (vtimghd)/ ]; then
1186 loopback vtimghd ${vtoy_iso_part}${vt_chosen_path}
1187 vt_img_sector ${vtoy_iso_part}${vt_chosen_path}
1189 vt_img_part_info (vtimghd)
1191 set vtback_root=$root
1195 vt_img_extra_initrd_reset
1197 vt_get_fs_label (vtimghd,1) vtImgHd1Label
1198 if [ -d (vtimghd,2)/lib ]; then
1199 vt_get_fs_label (vtimghd,2) vtImgHd2Label
1202 if [ -e (vtimghd,1)/etc/hostname ]; then
1203 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
1206 if [ -e (vtimghd,1)/easy.sfs ]; then
1208 elif [ -e (vtimghd,1)/volumio.initrd ]; then
1210 elif vt_str_begin $vtImgHd1Label "LAKKA"; then
1211 ventoy_img_openelec lakka
1212 elif vt_str_begin $vtImgHd1Label "LIBREELEC"; then
1213 ventoy_img_openelec LibreELEC
1214 elif vt_str_begin $vtImgHd1Label "paldo-live"; then
1216 elif vt_str_begin $vtImgHostname "freedombox"; then
1217 ventoy_img_freedombox
1218 elif vt_str_begin $vtImgHd1Label "BATOCERA"; then
1220 elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
1222 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
1224 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
1225 if [ "$grub_platform" = "pc" ]; then
1228 ventoy_img_memtest86
1231 if [ "$grub_platform" = "pc" ]; then
1234 vt_linux_chain_data ${vtoy_iso_part}${vt_chosen_path}
1235 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}
1240 set root=$vtback_root
1243 set ventoy_compatible=NO
1246 function img_unsupport_menuentry {
1247 common_unsupport_menuentry
1250 #############################################################
1251 #############################################################
1252 #############################################################
1253 ####### Main Process ###########
1254 #############################################################
1255 #############################################################
1256 #############################################################
1258 set VENTOY_VERSION="1.0.21"
1260 # Default menu display mode, you can change it as you want.
1263 set VTOY_DEFAULT_MENU_MODE=0
1265 set VTOY_MEM_DISK_STR="[Memdisk]"
1266 set VTOY_ISO_RAW_STR="Compatible Mode"
1267 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
1269 set VTOY_F2_CMD="ventoy_power"
1270 set VTOY_F4_CMD="ventoy_localboot"
1271 set VTOY_F5_CMD="ventoy_diagnosis"
1272 set VTOY_F6_CMD="ventoy_ext_menu"
1274 if [ "$grub_platform" = "pc" ]; then
1275 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1277 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1280 vt_device $root vtoy_dev
1282 if [ "$vtoy_dev" = "tftp" ]; then
1283 set vtoy_path=($root)
1284 for vtid in 0 1 2 3; do
1285 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
1286 set vtoy_iso_part=(hd$vtid,1)
1287 set vtoy_efi_part=(hd$vtid,2)
1294 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1295 set vt_plugin_path=$vtoy_iso_part
1297 set vt_plugin_path=$prefix
1298 vt_load_plugin $vt_plugin_path
1301 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1302 set vtoy_path=(ventoydisk)/ventoy
1304 set vtoy_path=($root)/ventoy
1307 set vtoydev=$vtoy_dev
1308 set vtoy_iso_part=($vtoy_dev,1)
1309 set vtoy_efi_part=($vtoy_dev,2)
1311 set vt_plugin_path=$vtoy_iso_part
1314 #Load Partition Table
1315 vt_load_part_table $vtoydev
1318 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1319 vt_load_plugin $vtoy_iso_part
1322 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1323 set timeout=$VTOY_MENU_TIMEOUT
1328 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1329 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1330 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1331 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1334 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
1335 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
1336 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
1337 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
1341 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1342 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1343 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
1345 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1346 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Tools F6:ExMenu"
1350 if [ -n "$vtoy_gfxmode" ]; then
1351 set gfxmode=$vtoy_gfxmode
1354 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
1358 if [ "$vtoy_display_mode" = "CLI" ]; then
1359 terminal_output console
1360 elif [ "$vtoy_display_mode" = "serial" ]; then
1361 if [ -n "$vtoy_serial_param" ]; then
1362 serial $vtoy_serial_param
1364 terminal_input serial
1365 terminal_output serial
1366 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1367 if [ -n "$vtoy_serial_param" ]; then
1368 serial $vtoy_serial_param
1370 terminal_input serial console
1371 terminal_output serial console
1373 if [ -n "$vtoy_theme" ]; then
1374 set theme=$vtoy_theme
1376 set theme=$prefix/themes/ventoy/theme.txt
1378 terminal_output gfxterm
1381 #export necessary variable
1385 export vtoy_iso_part
1386 export vtoy_efi_part
1387 export VENTOY_VERSION
1388 export VTOY_CUR_VIDEO_MODE
1393 #colect all image files (iso files)
1394 set ventoy_img_count=0
1395 vt_list_img $vtoy_iso_part ventoy_img_count
1398 if [ $ventoy_img_count -gt 0 ]; then
1399 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1405 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1406 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1407 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1408 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1410 NO_ISO_MENU="No ISO files found"
1412 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1413 echo -e "\n Rebooting ... "