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 "${vtdebug_flag}" ]; then
86 if [ -n "$vtoy_chain_mem_addr" ]; then
87 terminal_output console
88 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
91 echo "chain empty failed"
96 function uefi_linux_menu_func {
97 if [ "$ventoy_compatible" = "NO" ]; then
98 vt_load_cpio ${vtoy_path}/ventoy.cpio
100 vt_linux_clear_initrd
102 for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
103 if [ -e (loop)/$file ]; then
104 vt_linux_parse_initrd_grub file (loop)/$file
108 vt_linux_initrd_count initrd_count
110 # special process for special distros
111 if vt_cmp $initrd_count eq 0; then
112 if [ -d (loop)/loader/entries ]; then
113 set LoadIsoEfiDriver=on
114 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
115 elif [ -d (loop)/boot/grub ]; then
116 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
120 vt_linux_initrd_count initrd_count
121 if vt_cmp $initrd_count eq 0; then
122 distro_specify_initrd_file
128 vt_linux_chain_data ${1}${chosen_path}
130 if [ -n "$vtoy_chain_mem_addr" ]; then
131 terminal_output console
132 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
135 echo "chain empty failed"
141 function uefi_iso_menu_func {
143 if [ -d (loop)/ ]; then
147 unset LoadIsoEfiDriver
149 vt_chosen_img_path chosen_path
151 if vt_is_udf ${1}${chosen_path}; then
152 set ventoy_fs_probe=udf
154 set ventoy_fs_probe=iso9660
157 loopback loop ${1}${chosen_path}
160 vt_check_compatible (loop)
162 vt_img_sector ${1}${chosen_path}
164 if [ "$vtoy_os" = "Windows" ]; then
165 if [ "$ventoy_fs_probe" = "iso9660" ]; then
166 set ventoy_compatible=YES
169 uefi_windows_menu_func $1
171 uefi_linux_menu_func $1
174 terminal_output gfxterm
177 function legacy_windows_menu_func {
180 if [ "$ventoy_compatible" = "NO" ]; then
182 if [ -n "$ventoy_wim_file" ]; then
183 vt_windows_locate_wim $ventoy_wim_file
184 elif [ -n "${vtdebug_flag}" ]; then
185 echo No wim file found
189 vt_windows_chain_data ${1}${chosen_path}
191 if [ -n "${vtdebug_flag}" ]; then
195 if [ -n "$vtoy_chain_mem_addr" ]; then
196 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft
197 initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
200 echo "chain empty failed"
205 function legacy_linux_menu_func {
206 if [ "$ventoy_compatible" = "NO" ]; then
208 vt_load_cpio $vtoy_path/ventoy.cpio
210 vt_linux_clear_initrd
212 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
213 if [ -d (loop)/$dir ]; then
214 vt_linux_parse_initrd_isolinux (loop)/$dir/
218 vt_linux_initrd_count initrd_count
220 # special process for special distros
221 if vt_cmp $initrd_count eq 0; then
223 if [ -d (loop)/arch/boot/syslinux ]; then
224 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
225 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
228 elif [ -d (loop)/manjaro ]; then
229 if [ -e (loop)/boot/grub/kernels.cfg ]; then
230 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
232 elif [ -e (loop)/boot/grub/grub.cfg ]; then
233 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
237 vt_linux_initrd_count initrd_count
238 if vt_cmp $initrd_count eq 0; then
239 distro_specify_initrd_file
245 vt_linux_chain_data ${1}${chosen_path}
247 if [ -n "${vtdebug_flag}" ]; then
251 if [ -n "$vtoy_chain_mem_addr" ]; then
252 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag}
253 initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
256 echo "chain empty failed"
261 function legacy_iso_menu_func {
263 if [ -d (loop)/ ]; then
267 vt_chosen_img_path chosen_path
269 if vt_is_udf ${1}${chosen_path}; then
270 set ventoy_fs_probe=udf
272 set ventoy_fs_probe=iso9660
275 loopback loop ${1}${chosen_path}
279 vt_check_compatible (loop)
281 vt_img_sector ${1}${chosen_path}
283 if [ "$vtoy_os" = "Windows" ]; then
284 if [ "$ventoy_fs_probe" = "iso9660" ]; then
285 set ventoy_compatible=YES
287 legacy_windows_menu_func $1
289 legacy_linux_menu_func $1
297 #############################################################
298 #############################################################
299 #############################################################
300 ####### Main Process ###########
301 #############################################################
302 #############################################################
303 #############################################################
305 set VENTOY_VERSION="1.0.01"
310 vt_device $root vtoy_dev
312 if [ "$vtoy_dev" = "tftp" ]; then
313 set vtoy_path=($root)
314 for vtid in 0 1 2 3; do
315 if [ -d (hd$vtid,2)/grub ]; then
316 set iso_path=(hd$vtid,1)
321 set vtoy_path=($root)/ventoy
322 set iso_path=($vtoy_dev,1)
327 if [ -f $iso_path/ventoy/ventoy.json ]; then
328 vt_load_plugin $iso_path
331 terminal_output gfxterm
333 if [ -n "$vtoy_theme" ]; then
334 set theme=$vtoy_theme
336 set theme=$prefix/themes/ventoy/theme.txt
339 if [ -n "$vtoy_gfxmode" ]; then
340 set gfxmode=$vtoy_gfxmode
345 #colect all image files (iso files)
346 set ventoy_img_count=0
347 vt_list_img $iso_path ventoy_img_count
349 #Dynamic menu for every iso file
350 if vt_cmp $ventoy_img_count ne 0; then
352 while vt_cmp $imgid lt $ventoy_img_count; do
353 vt_img_name $imgid img_name
354 menuentry "$img_name" {
355 if [ "$grub_platform" = "pc" ]; then
356 legacy_iso_menu_func $iso_path
358 uefi_iso_menu_func $iso_path
365 menuentry "No ISO files found (Press enter to reboot ...)" {
366 echo -e "\n Rebooting ... "