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 [ -d (loop)/EFI/BOOT/entries ]; then
509 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
510 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
512 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
513 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
514 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
521 vt_linux_chain_data ${1}${chosen_path}
523 if [ -n "$vtoy_chain_mem_addr" ]; then
525 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}
528 echo "chain empty failed"
533 function uefi_unix_menu_func {
534 ventoy_unix_comm_proc $1 ${chosen_path}
536 if [ -n "$vtoy_chain_mem_addr" ]; then
538 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}
541 echo "chain empty failed"
546 function uefi_iso_menu_func {
548 if [ -d (loop)/ ]; then
552 if [ -n "$vtisouefi" ]; then
553 set LoadIsoEfiDriver=on
555 elif vt_check_mode 2; then
556 set LoadIsoEfiDriver=on
558 unset LoadIsoEfiDriver
562 vt_select_auto_install ${chosen_path}
563 vt_select_persistence ${chosen_path}
565 if vt_is_udf ${1}${chosen_path}; then
566 set ventoy_fs_probe=udf
568 set ventoy_fs_probe=iso9660
569 vt_iso9660_nojoliet 0
572 loopback loop ${1}${chosen_path}
575 if [ -d (loop)/EFI ]; then
577 elif [ -d (loop)/efi ]; then
583 if [ -n "$vtcompat" ]; then
584 set ventoy_compatible=YES
586 elif vt_check_mode 1; then
587 set ventoy_compatible=YES
589 vt_check_compatible (loop)
592 vt_img_sector ${1}${chosen_path}
594 if [ "$vtoy_os" = "Windows" ]; then
595 vt_check_compatible_pe (loop)
596 uefi_windows_menu_func $1 ${chosen_path}
597 elif [ "$vtoy_os" = "Unix" ]; then
598 uefi_unix_menu_func $1 ${chosen_path}
600 uefi_linux_menu_func $1 ${chosen_path}
606 function uefi_iso_memdisk {
607 echo 'Loading ISO file to memory ...'
608 vt_load_img_memdisk ${1}${2} vtoy_iso_buf
611 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}
618 function legacy_windows_menu_func {
621 if [ "$ventoy_compatible" = "NO" ]; then
623 if [ "$ventoy_fs_probe" = "iso9660" ]; then
625 vt_iso9660_nojoliet 1
629 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
630 vt_windows_collect_wim_patch bcd (loop)/$file
633 distro_specify_wim_patch
635 vt_windows_count_wim_patch vt_wim_cnt
636 if [ $vt_wim_cnt -eq 0 ]; then
637 distro_specify_wim_patch_phase2
644 vt_windows_chain_data ${1}${chosen_path}
647 if [ -n "$vtoy_chain_mem_addr" ]; then
648 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
649 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
650 terminal_output gfxterm
653 echo "chain empty failed"
658 function legacy_linux_menu_func {
659 if [ "$ventoy_compatible" = "NO" ]; then
661 if [ "$ventoy_fs_probe" = "udf" ]; then
663 set ventoy_fs_probe=iso9660
667 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
669 vt_linux_clear_initrd
671 if [ -d (loop)/pmagic ]; then
672 vt_linux_specify_initrd_file /pmagic/initrd.img
674 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
675 if [ -d (loop)/$dir ]; then
676 vt_linux_parse_initrd_isolinux (loop)/$dir/
681 # special process for special distros
683 if [ -d (loop)/arch/boot/syslinux ]; then
684 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
685 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
688 elif [ -d (loop)/manjaro ]; then
689 if [ -e (loop)/boot/grub/kernels.cfg ]; then
690 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
692 elif [ -e (loop)/boot/grub/grub.cfg ]; then
693 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
696 distro_specify_initrd_file
698 vt_linux_initrd_count vtcount
699 if [ $vtcount -eq 0 ]; then
700 if [ -d (loop)/rancheros ]; then
701 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
704 distro_specify_initrd_file_phase2
710 vt_linux_chain_data ${1}${chosen_path}
713 if [ -n "$vtoy_chain_mem_addr" ]; then
714 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
717 echo "chain empty failed"
723 function legacy_unix_menu_func {
724 ventoy_unix_comm_proc $1 ${chosen_path}
726 if [ -n "$vtoy_chain_mem_addr" ]; then
727 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
730 echo "chain empty failed"
736 function legacy_iso_menu_func {
738 if [ -d (loop)/ ]; then
743 vt_select_auto_install ${chosen_path}
744 vt_select_persistence ${chosen_path}
746 if vt_is_udf ${1}${chosen_path}; then
747 set ventoy_fs_probe=udf
749 set ventoy_fs_probe=iso9660
750 vt_iso9660_nojoliet 0
753 loopback loop ${1}${chosen_path}
757 if [ -n "$vtcompat" ]; then
758 set ventoy_compatible=YES
760 elif vt_check_mode 1; then
761 set ventoy_compatible=YES
763 vt_check_compatible (loop)
766 vt_img_sector ${1}${chosen_path}
768 if [ "$vtoy_os" = "Windows" ]; then
769 vt_check_compatible_pe (loop)
770 legacy_windows_menu_func $1 ${chosen_path}
771 elif [ "$vtoy_os" = "Unix" ]; then
772 legacy_unix_menu_func $1 ${chosen_path}
774 legacy_linux_menu_func $1 ${chosen_path}
778 function legacy_iso_memdisk {
780 linux16 $vtoy_path/memdisk iso raw
781 echo "Loading ISO file to memory ..."
787 function iso_endless_os_proc {
788 if [ -d (loop)/ ]; then
792 loopback loop ${1}${2}
793 vt_img_sector ${1}${2}
795 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
796 vt_trailer_cpio $1 $2 noinit
800 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
803 set ventoy_bls_bootdev=/boot
804 set ventoy_loading_tip="Loading files ......"
807 configfile (loop)/endless/grub/grub.cfg
810 unset ventoy_bls_bootdev
811 unset ventoy_loading_tip
817 function ventoy_iso_busybox_ver {
818 set ventoy_busybox_ver=32
820 #special process for deepin-live iso
821 if [ "$vt_chosen_size" = "403701760" ]; then
822 if vt_str_str $vt_chosen_path "/deepin-live"; then
823 set ventoy_busybox_ver=64
825 elif vt_str_begin $vt_volume_id "PHOTON_"; then
826 set ventoy_busybox_ver=64
827 elif vt_str_begin $vt_volume_id "smgl-test-quinq-x86_64"; then
828 set ventoy_busybox_ver=64
833 function iso_common_menuentry {
837 vt_chosen_img_path vt_chosen_path vt_chosen_size
838 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
840 ventoy_iso_busybox_ver
842 #special process for Endless OS
843 if vt_str_begin $vt_volume_id "Endless-OS"; then
844 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
845 elif vt_str_begin $vt_volume_id "TENS-Public"; then
849 if [ "$grub_platform" = "pc" ]; then
850 if vt_check_mode 0; then
851 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
853 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
856 if vt_check_mode 0; then
857 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
859 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
864 function miso_common_menuentry {
865 vt_chosen_img_path vt_chosen_path vt_chosen_size
867 if [ "$grub_platform" = "pc" ]; then
868 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
870 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
875 function common_unsupport_menuentry {
876 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
877 echo -e " 文件名中不能有中文或空格 \n"
878 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
882 function miso_unsupport_menuentry {
883 common_unsupport_menuentry
886 function iso_unsupport_menuentry {
887 common_unsupport_menuentry
890 function wim_common_menuentry {
891 vt_chosen_img_path vt_chosen_path vt_chosen_size
892 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
896 if [ -n "$vtoy_chain_mem_addr" ]; then
897 if [ "$grub_platform" = "pc" ]; then
898 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
899 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
900 terminal_output gfxterm
903 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
908 echo "chain empty failed"
913 function wim_unsupport_menuentry {
914 common_unsupport_menuentry
917 function efi_common_menuentry {
918 vt_chosen_img_path vt_chosen_path vt_chosen_size
920 vt_concat_efi_iso ${vtoy_iso_part}${vt_chosen_path} vtoy_iso_buf
926 unset vtoy_dotefi_retry
927 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}
930 if [ -n "$vtoy_dotefi_retry" ]; then
931 unset vtoy_dotefi_retry
932 chainloader ${vtoy_iso_part}${vt_chosen_path}
939 function efi_unsupport_menuentry {
940 common_unsupport_menuentry
944 function vhd_common_menuentry {
946 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
947 if [ "$vtoy_iso_fs" != "ntfs" ]; then
948 echo -e "!!! WARNING !!!\n"
949 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
950 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
951 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
956 vt_chosen_img_path vt_chosen_path vt_chosen_size
957 vt_patch_vhdboot ${vtoy_iso_part} ${vt_chosen_path}
961 if [ -n "$vtoy_vhd_buf_addr" ]; then
962 if [ "$grub_platform" = "pc" ]; then
963 linux16 $vtoy_path/memdisk iso raw
964 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
966 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
967 terminal_output gfxterm
971 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}
976 echo "Failed to boot vhd file"
981 function vhd_unsupport_menuentry {
982 common_unsupport_menuentry
986 #============================================================#
987 # IMG file boot process #
988 #============================================================#
992 function ventoy_img_easyos {
993 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
994 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
996 loopback easysfs (vtimghd,1)/easy.sfs
997 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
999 if [ -n "$vt_module_ver" ]; then
1000 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1001 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1008 vt_set_boot_opt rdinit=/vtoy/vtoy
1011 syslinux_configfile (vtimghd,1)/syslinux.cfg
1018 function ventoy_img_volumio {
1019 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1020 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1025 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1028 syslinux_configfile (vtimghd,1)/syslinux.cfg
1034 function ventoy_img_openelec {
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 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1041 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1046 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1049 set root=(vtimghd,1)
1050 syslinux_configfile (vtimghd,1)/syslinux.cfg
1054 loopback -d vtloopex
1058 function ventoy_img_freedombox {
1059 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1060 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1062 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1063 if [ -n "$vt_module_ver" ]; then
1064 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1070 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1073 configfile (vtimghd,1)/boot/grub/grub.cfg
1079 function ventoy_img_paldo {
1080 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1081 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1086 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1089 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1090 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1092 echo loading file...
1093 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1094 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1101 function ventoy_img_ubos {
1102 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1103 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1105 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1106 if [ -n "$vt_module_ver" ]; then
1107 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1113 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1116 echo loading file...
1117 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1118 initrd (vtimghd,2)/initramfs-linux.img
1125 function ventoy_img_recalbox {
1126 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1127 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1132 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1135 set root=(vtimghd,1)
1136 configfile (vtimghd,1)/boot/grub/grub.cfg
1142 function ventoy_img_batocera {
1143 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1144 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1149 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1152 set root=(vtimghd,1)
1153 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1159 function ventoy_img_memtest86 {
1160 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
1164 function img_unsupport_tip {
1165 echo -e "\n This IMG file is NOT supported now. \n"
1166 echo -e " 当前不支持启动此 IMG 文件 \n"
1167 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1171 function img_common_menuentry {
1172 set ventoy_compatible=YES
1173 set ventoy_busybox_ver=32
1175 vt_chosen_img_path vt_chosen_path vt_chosen_size
1177 if [ -d (vtimghd)/ ]; then
1181 loopback vtimghd ${vtoy_iso_part}${vt_chosen_path}
1182 vt_img_sector ${vtoy_iso_part}${vt_chosen_path}
1184 vt_img_part_info (vtimghd)
1186 set vtback_root=$root
1190 vt_img_extra_initrd_reset
1192 vt_get_fs_label (vtimghd,1) vtImgHd1Label
1193 if [ -d (vtimghd,2)/lib ]; then
1194 vt_get_fs_label (vtimghd,2) vtImgHd2Label
1197 if [ -e (vtimghd,1)/etc/hostname ]; then
1198 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
1201 if [ -e (vtimghd,1)/easy.sfs ]; then
1203 elif [ -e (vtimghd,1)/volumio.initrd ]; then
1205 elif vt_str_begin $vtImgHd1Label "LAKKA"; then
1206 ventoy_img_openelec lakka
1207 elif vt_str_begin $vtImgHd1Label "LIBREELEC"; then
1208 ventoy_img_openelec LibreELEC
1209 elif vt_str_begin $vtImgHd1Label "paldo-live"; then
1211 elif vt_str_begin $vtImgHostname "freedombox"; then
1212 ventoy_img_freedombox
1213 elif vt_str_begin $vtImgHd1Label "BATOCERA"; then
1215 elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
1217 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
1219 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
1220 if [ "$grub_platform" = "pc" ]; then
1223 ventoy_img_memtest86
1226 if [ "$grub_platform" = "pc" ]; then
1229 vt_linux_chain_data ${vtoy_iso_part}${vt_chosen_path}
1230 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}
1235 set root=$vtback_root
1238 set ventoy_compatible=NO
1241 function img_unsupport_menuentry {
1242 common_unsupport_menuentry
1245 #############################################################
1246 #############################################################
1247 #############################################################
1248 ####### Main Process ###########
1249 #############################################################
1250 #############################################################
1251 #############################################################
1253 set VENTOY_VERSION="1.0.20"
1255 # Default menu display mode, you can change it as you want.
1258 set VTOY_DEFAULT_MENU_MODE=0
1260 set VTOY_MEM_DISK_STR="[Memdisk]"
1261 set VTOY_ISO_RAW_STR="Compatible Mode"
1262 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
1264 set VTOY_F2_CMD="ventoy_power"
1265 set VTOY_F4_CMD="ventoy_localboot"
1266 set VTOY_F5_CMD="ventoy_diagnosis"
1267 set VTOY_F6_CMD="ventoy_ext_menu"
1269 if [ "$grub_platform" = "pc" ]; then
1270 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1272 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1275 vt_device $root vtoy_dev
1277 if [ "$vtoy_dev" = "tftp" ]; then
1278 set vtoy_path=($root)
1279 for vtid in 0 1 2 3; do
1280 if [ -d (hd$vtid,2)/ventoy ]; then
1281 set vtoy_iso_part=(hd$vtid,1)
1282 set vtoy_efi_part=(hd$vtid,2)
1288 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1289 set vt_plugin_path=$vtoy_iso_part
1291 set vt_plugin_path=$prefix
1292 vt_load_plugin $vt_plugin_path
1295 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1296 set vtoy_path=(ventoydisk)/ventoy
1298 set vtoy_path=($root)/ventoy
1301 set vtoy_iso_part=($vtoy_dev,1)
1302 set vtoy_efi_part=($vtoy_dev,2)
1304 set vt_plugin_path=$vtoy_iso_part
1309 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1310 vt_load_plugin $vtoy_iso_part
1313 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1314 set timeout=$VTOY_MENU_TIMEOUT
1319 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1320 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1321 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1322 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1325 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
1326 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
1327 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
1328 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
1332 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1333 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1334 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
1336 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1337 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
1341 if [ -n "$vtoy_gfxmode" ]; then
1342 set gfxmode=$vtoy_gfxmode
1344 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
1347 if [ "$vtoy_display_mode" = "CLI" ]; then
1348 terminal_output console
1349 elif [ "$vtoy_display_mode" = "serial" ]; then
1350 if [ -n "$vtoy_serial_param" ]; then
1351 serial $vtoy_serial_param
1353 terminal_input serial
1354 terminal_output serial
1355 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1356 if [ -n "$vtoy_serial_param" ]; then
1357 serial $vtoy_serial_param
1359 terminal_input serial console
1360 terminal_output serial console
1362 if [ -n "$vtoy_theme" ]; then
1363 set theme=$vtoy_theme
1365 set theme=$prefix/themes/ventoy/theme.txt
1367 terminal_output gfxterm
1370 #export necessary variable
1374 export vtoy_iso_part
1375 export vtoy_efi_part
1376 export VENTOY_VERSION
1381 #colect all image files (iso files)
1382 set ventoy_img_count=0
1383 vt_list_img $vtoy_iso_part ventoy_img_count
1386 if [ $ventoy_img_count -gt 0 ]; then
1387 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1393 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1394 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1395 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1396 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1398 NO_ISO_MENU="No ISO files found"
1400 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1401 echo -e "\n Rebooting ... "