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_power {
22 echo '<0> Return to menu'
23 echo -e '\nPlease enter your choice:'
28 if [ "$vtOpt" = "1" ]; then
29 echo -e '\n\nSystem is rebooting ... \n'
32 elif [ "$vtOpt" = "2" ]; then
33 echo -e '\n\nSystem is halting ... \n'
39 function get_os_type {
41 for file in "efi/microsoft" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" "BOOT/etfsboot.com"; do
42 if [ -e $1/$file ]; then
48 if [ -n "${vtdebug_flag}" ]; then
53 function vt_check_pe {
56 if [ -f $1/HBCD_PE.ini ]; then
57 set ventoy_compatible=YES
59 elif [ -f $1/easyu.flg ]; then
61 elif [ -f $1/USM.ICO ]; then
63 elif [ -d $1/USM_TOOL ]; then
68 function locate_initrd {
69 vt_linux_locate_initrd
71 if [ -n "${vtdebug_flag}" ]; then
77 function find_wim_file {
80 for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" \
81 "winpe_x64.wim" "boot/10pex64.wim" "BOOT/USM1PE6L.WIM" "BOOT/USM1PE6F.WIM"; do
82 if [ -e $1/$file ]; then
83 set ventoy_wim_file=$1/$file
89 function distro_specify_initrd_file {
90 if [ -e (loop)/boot/all.rdz ]; then
91 vt_linux_specify_initrd_file /boot/all.rdz
92 elif [ -e (loop)/boot/xen.gz ]; then
93 if [ -e (loop)/install.img ]; then
94 vt_linux_specify_initrd_file /install.img
96 elif [ -d (loop)/casper ]; then
97 if [ -e (loop)/casper/initrd ]; then
98 vt_linux_specify_initrd_file /casper/initrd
100 if [ -e (loop)/casper/initrd-oem ]; then
101 vt_linux_specify_initrd_file /casper/initrd-oem
103 elif [ -e (loop)/boot/grub/initrd.xz ]; then
104 vt_linux_specify_initrd_file /boot/grub/initrd.xz
105 elif [ -e (loop)/initrd.gz ]; then
106 vt_linux_specify_initrd_file /initrd.gz
107 elif [ -e (loop)/slax/boot/initrfs.img ]; then
108 vt_linux_specify_initrd_file /slax/boot/initrfs.img
109 elif [ -e (loop)/pmagic/initrd.img ]; then
110 vt_linux_specify_initrd_file /pmagic/initrd.img
111 elif [ -e (loop)/boot/initrd.xz ]; then
112 vt_linux_specify_initrd_file /boot/initrd.xz
113 elif [ -f (loop)/boot/initrd ]; then
114 vt_linux_specify_initrd_file /boot/initrd
115 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
116 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
117 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
118 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
124 function distro_specify_initrd_file_phase2 {
125 if [ -f (loop)/boot/initrd.img ]; then
126 vt_linux_specify_initrd_file /boot/initrd.img
127 elif [ -f (loop)/Setup/initrd.gz ]; then
128 vt_linux_specify_initrd_file /Setup/initrd.gz
129 elif [ -f (loop)/isolinux/initramfs ]; then
130 vt_linux_specify_initrd_file /isolinux/initramfs
131 elif [ -f (loop)/boot/iniramfs.igz ]; then
132 vt_linux_specify_initrd_file /boot/iniramfs.igz
133 elif [ -f (loop)/initrd-x86_64 ]; then
134 vt_linux_specify_initrd_file /initrd-x86_64
139 function uefi_windows_menu_func {
142 if [ "$ventoy_compatible" = "NO" ]; then
144 if [ -n "$ventoy_wim_file" ]; then
145 vt_windows_locate_wim $ventoy_wim_file
149 vt_windows_chain_data ${1}${chosen_path}
151 if [ -n "${vtdebug_flag}" ]; then
155 if [ -n "$vtoy_chain_mem_addr" ]; then
156 terminal_output console
157 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
160 echo "chain empty failed"
165 function uefi_linux_menu_func {
166 if [ "$ventoy_compatible" = "NO" ]; then
167 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1
169 vt_linux_clear_initrd
171 if [ -d (loop)/pmagic ]; then
172 vt_linux_specify_initrd_file /pmagic/initrd.img
174 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
175 if [ -e (loop)/$file ]; then
176 vt_linux_parse_initrd_grub file (loop)/$file
181 # special process for special distros
182 if [ -d (loop)/loader/entries ]; then
183 set LoadIsoEfiDriver=on
184 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
185 elif [ -d (loop)/boot/grub ]; then
186 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
189 if [ -e (loop)/syslinux/alt0/full.cz ]; then
190 set LoadIsoEfiDriver=on
191 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
194 distro_specify_initrd_file
196 vt_linux_initrd_count vtcount
197 if [ $vtcount -eq 0 ]; then
198 distro_specify_initrd_file_phase2
200 if [ "$vt_efi_dir" = "NO" ]; then
201 if [ -f (loop)/efi.img ]; then
202 vt_add_replace_file 0 "initrd"
210 vt_linux_chain_data ${1}${chosen_path}
212 if [ -n "$vtoy_chain_mem_addr" ]; then
213 terminal_output console
214 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}
217 echo "chain empty failed"
223 function uefi_iso_menu_func {
225 if [ -d (loop)/ ]; then
229 if [ -n "$vtisouefi" ]; then
230 set LoadIsoEfiDriver=on
232 elif vt_check_mode 2; then
233 set LoadIsoEfiDriver=on
235 unset LoadIsoEfiDriver
238 vt_chosen_img_path chosen_path
240 if vt_is_udf ${1}${chosen_path}; then
241 set ventoy_fs_probe=udf
243 set ventoy_fs_probe=iso9660
246 loopback loop ${1}${chosen_path}
249 if [ -d (loop)/EFI ]; then
251 elif [ -d (loop)/efi ]; then
257 if [ -n "$vtcompat" ]; then
258 set ventoy_compatible=YES
260 elif vt_check_mode 1; then
261 set ventoy_compatible=YES
263 vt_check_compatible (loop)
266 vt_img_sector ${1}${chosen_path}
268 if [ "$vtoy_os" = "Windows" ]; then
270 if [ "$VT_PE_SUPPORT" != "YES" ]; then
271 if [ "$ventoy_fs_probe" = "iso9660" ]; then
272 set ventoy_compatible=YES
276 uefi_windows_menu_func $1 ${chosen_path}
278 uefi_linux_menu_func $1 ${chosen_path}
281 terminal_output gfxterm
284 function uefi_iso_memdisk {
285 vt_chosen_img_path chosen_path
287 echo 'Loading ISO file to memory ...'
288 vt_load_iso_to_mem ${1}${chosen_path} vtoy_iso_buf
290 terminal_output console
291 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}
296 function legacy_windows_menu_func {
299 if [ "$ventoy_compatible" = "NO" ]; then
301 if [ -n "$ventoy_wim_file" ]; then
302 vt_windows_locate_wim $ventoy_wim_file
303 elif [ -n "${vtdebug_flag}" ]; then
304 echo No wim file found
308 vt_windows_chain_data ${1}${chosen_path}
310 if [ -n "${vtdebug_flag}" ]; then
314 if [ -n "$vtoy_chain_mem_addr" ]; then
315 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
318 echo "chain empty failed"
323 function legacy_linux_menu_func {
324 if [ "$ventoy_compatible" = "NO" ]; then
325 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
327 vt_linux_clear_initrd
329 if [ -d (loop)/pmagic ]; then
330 vt_linux_specify_initrd_file /pmagic/initrd.img
332 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
333 if [ -d (loop)/$dir ]; then
334 vt_linux_parse_initrd_isolinux (loop)/$dir/
339 # special process for special distros
341 if [ -d (loop)/arch/boot/syslinux ]; then
342 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
343 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
346 elif [ -d (loop)/manjaro ]; then
347 if [ -e (loop)/boot/grub/kernels.cfg ]; then
348 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
350 elif [ -e (loop)/boot/grub/grub.cfg ]; then
351 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
354 distro_specify_initrd_file
356 vt_linux_initrd_count vtcount
357 if [ $vtcount -eq 0 ]; then
358 distro_specify_initrd_file_phase2
364 vt_linux_chain_data ${1}${chosen_path}
366 if [ -n "${vtdebug_flag}" ]; then
370 if [ -n "$vtoy_chain_mem_addr" ]; then
371 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
374 echo "chain empty failed"
379 function legacy_iso_menu_func {
381 if [ -d (loop)/ ]; then
385 vt_chosen_img_path chosen_path
387 if vt_is_udf ${1}${chosen_path}; then
388 set ventoy_fs_probe=udf
390 set ventoy_fs_probe=iso9660
393 loopback loop ${1}${chosen_path}
397 if [ -n "$vtcompat" ]; then
398 set ventoy_compatible=YES
400 elif vt_check_mode 1; then
401 set ventoy_compatible=YES
403 vt_check_compatible (loop)
406 vt_img_sector ${1}${chosen_path}
408 if [ "$vtoy_os" = "Windows" ]; then
410 if [ "$VT_PE_SUPPORT" != "YES" ]; then
411 if [ "$ventoy_fs_probe" = "iso9660" ]; then
412 set ventoy_compatible=YES
416 legacy_windows_menu_func $1 ${chosen_path}
418 legacy_linux_menu_func $1 ${chosen_path}
422 function legacy_iso_memdisk {
423 vt_chosen_img_path chosen_path
425 linux16 $vtoy_path/memdisk iso raw
426 echo "Loading ISO file to memory ..."
427 initrd16 ${1}${chosen_path}
431 function common_menuentry {
432 if [ "$grub_platform" = "pc" ]; then
433 if vt_check_mode 0; then
434 legacy_iso_memdisk $iso_path
436 legacy_iso_menu_func $iso_path
439 if vt_check_mode 0; then
440 uefi_iso_memdisk $iso_path
442 uefi_iso_menu_func $iso_path
448 #############################################################
449 #############################################################
450 #############################################################
451 ####### Main Process ###########
452 #############################################################
453 #############################################################
454 #############################################################
456 set VENTOY_VERSION="1.0.10"
458 # Default menu display mode, you can change it as you want.
461 set VTOY_DEFAULT_MENU_MODE=0
466 set VTOY_MEM_DISK_STR="MEMDISK"
467 set VTOY_ISO_RAW_STR="ISO RAW"
468 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
470 set VTOY_F2_CMD="ventoy_power"
472 if [ "$grub_platform" = "pc" ]; then
473 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
475 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
478 vt_device $root vtoy_dev
480 if [ "$vtoy_dev" = "tftp" ]; then
481 set vtoy_path=($root)
482 for vtid in 0 1 2 3; do
483 if [ -d (hd$vtid,2)/ventoy ]; then
484 set iso_path=(hd$vtid,1)
489 set vtoy_path=($root)/ventoy
490 set iso_path=($vtoy_dev,1)
496 if [ -f $iso_path/ventoy/ventoy.json ]; then
497 vt_load_plugin $iso_path
501 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
502 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
503 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView"
505 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
506 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView"
510 if [ -n "$vtoy_gfxmode" ]; then
511 set gfxmode=$vtoy_gfxmode
513 set gfxmode=1920x1080,1366x768,1024x768
516 if [ -n "$vtoy_theme" ]; then
517 set theme=$vtoy_theme
519 set theme=$prefix/themes/ventoy/theme.txt
522 terminal_output gfxterm
524 #colect all image files (iso files)
525 set ventoy_img_count=0
526 vt_list_img $iso_path ventoy_img_count
529 if [ $ventoy_img_count -gt 0 ]; then
530 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
536 menuentry "No ISO files found (Press enter to reboot ...)" {
537 echo -e "\n Rebooting ... "