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 get_os_type {
21 for file in "efi/microsoft" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com"; do
22 if [ -e $1/$file ]; then
28 if [ -n "${vtdebug_flag}" ]; then
33 function locate_initrd {
34 vt_linux_locate_initrd
36 if [ -n "${vtdebug_flag}" ]; then
42 function find_wim_file {
45 for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" "winpe_x64.wim"; do
46 if [ -e $1/$file ]; then
47 set ventoy_wim_file=$1/$file
53 function distro_specify_initrd_file {
54 if [ -e (loop)/boot/all.rdz ]; then
55 vt_linux_specify_initrd_file /boot/all.rdz
56 elif [ -e (loop)/boot/xen.gz ]; then
57 if [ -e (loop)/install.img ]; then
58 vt_linux_specify_initrd_file /install.img
60 elif [ -d (loop)/casper ]; then
61 if [ -e (loop)/casper/initrd ]; then
62 vt_linux_specify_initrd_file /casper/initrd
64 if [ -e (loop)/casper/initrd-oem ]; then
65 vt_linux_specify_initrd_file /casper/initrd-oem
70 function uefi_windows_menu_func {
73 if [ "$ventoy_compatible" = "NO" ]; then
75 if [ -n "$ventoy_wim_file" ]; then
76 vt_windows_locate_wim $ventoy_wim_file
80 vt_windows_chain_data ${1}${chosen_path}
82 if [ -n "$vtoy_chain_mem_addr" ]; then
83 terminal_output console
84 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
87 echo "chain empty failed"
92 function uefi_linux_menu_func {
93 if [ "$ventoy_compatible" = "NO" ]; then
94 vt_load_cpio ${vtoy_path}/ventoy.cpio
98 for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
99 if [ -e (loop)/$file ]; then
100 vt_linux_parse_initrd_grub file (loop)/$file
104 vt_linux_initrd_count initrd_count
106 # special process for special distros
107 if vt_cmp $initrd_count eq 0; then
108 if [ -d (loop)/loader/entries ]; then
109 set LoadIsoEfiDriver=on
110 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
111 elif [ -d (loop)/boot/grub ]; then
112 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
116 vt_linux_initrd_count initrd_count
117 if vt_cmp $initrd_count eq 0; then
118 distro_specify_initrd_file
124 vt_linux_chain_data ${1}${chosen_path}
126 if [ -n "$vtoy_chain_mem_addr" ]; then
127 terminal_output console
128 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
131 echo "chain empty failed"
137 function uefi_iso_menu_func {
139 if [ -d (loop)/ ]; then
143 unset LoadIsoEfiDriver
145 vt_chosen_img_path chosen_path
147 if vt_is_udf ${1}${chosen_path}; then
148 set ventoy_fs_probe=udf
150 set ventoy_fs_probe=iso9660
153 loopback loop ${1}${chosen_path}
156 vt_check_compatible (loop)
158 vt_img_sector ${1}${chosen_path}
160 if [ "$vtoy_os" = "Windows" ]; then
161 uefi_windows_menu_func $1
163 uefi_linux_menu_func $1
166 terminal_output gfxterm
169 function legacy_windows_menu_func {
172 if [ "$ventoy_compatible" = "NO" ]; then
174 if [ -n "$ventoy_wim_file" ]; then
175 vt_windows_locate_wim $ventoy_wim_file
176 elif [ -n "${vtdebug_flag}" ]; then
177 echo No wim file found
181 vt_windows_chain_data ${1}${chosen_path}
183 if [ -n "${vtdebug_flag}" ]; then
187 if [ -n "$vtoy_chain_mem_addr" ]; then
188 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft
189 initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
192 echo "chain empty failed"
197 function legacy_linux_menu_func {
198 if [ "$ventoy_compatible" = "NO" ]; then
200 vt_load_cpio $vtoy_path/ventoy.cpio
202 vt_linux_clear_initrd
204 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
205 if [ -d (loop)/$dir ]; then
206 vt_linux_parse_initrd_isolinux (loop)/$dir/
210 vt_linux_initrd_count initrd_count
212 # special process for special distros
213 if vt_cmp $initrd_count eq 0; then
215 if [ -d (loop)/arch/boot/syslinux ]; then
216 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
217 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
220 elif [ -d (loop)/manjaro ]; then
221 if [ -e (loop)/boot/grub/kernels.cfg ]; then
222 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
224 elif [ -e (loop)/boot/grub/grub.cfg ]; then
225 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
229 vt_linux_initrd_count initrd_count
230 if vt_cmp $initrd_count eq 0; then
231 distro_specify_initrd_file
237 vt_linux_chain_data ${1}${chosen_path}
239 if [ -n "${vtdebug_flag}" ]; then
243 if [ -n "$vtoy_chain_mem_addr" ]; then
244 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag}
245 initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
248 echo "chain empty failed"
253 function legacy_iso_menu_func {
255 if [ -d (loop)/ ]; then
259 vt_chosen_img_path chosen_path
261 if vt_is_udf ${1}${chosen_path}; then
262 set ventoy_fs_probe=udf
264 set ventoy_fs_probe=iso9660
267 loopback loop ${1}${chosen_path}
271 vt_check_compatible (loop)
273 vt_img_sector ${1}${chosen_path}
275 if [ "$vtoy_os" = "Windows" ]; then
276 legacy_windows_menu_func $1
278 legacy_linux_menu_func $1
286 #############################################################
287 #############################################################
288 #############################################################
289 ####### Main Process ###########
290 #############################################################
291 #############################################################
292 #############################################################
294 set VENTOY_VERSION="1.0.00"
299 vt_device $root vtoy_dev
301 if [ "$vtoy_dev" = "tftp" ]; then
302 set vtoy_path=($root)
303 for vtid in 0 1 2 3; do
304 if [ -d (hd$vtid,2)/grub ]; then
305 set iso_path=(hd$vtid,1)
310 set vtoy_path=($root)/ventoy
311 set iso_path=($vtoy_dev,1)
316 if [ -f $iso_path/ventoy/ventoy.json ]; then
317 vt_load_plugin $iso_path
320 terminal_output gfxterm
322 if [ -n "$vtoy_theme" ]; then
323 set theme=$vtoy_theme
325 set theme=$prefix/themes/ventoy/theme.txt
328 if [ -n "$vtoy_gfxmode" ]; then
329 set gfxmode=$vtoy_gfxmode
334 #colect all image files (iso files)
335 set ventoy_img_count=0
336 vt_list_img $iso_path ventoy_img_count
338 #Dynamic menu for every iso file
339 if vt_cmp $ventoy_img_count ne 0; then
341 while vt_cmp $imgid lt $ventoy_img_count; do
342 vt_img_name $imgid img_name
343 menuentry "$img_name" {
344 if [ "$grub_platform" = "pc" ]; then
345 legacy_iso_menu_func $iso_path
347 uefi_iso_menu_func $iso_path
354 menuentry "No ISO files found (Press enter to reboot ...)" {
355 echo -e "\n Rebooting ... "