]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
support eweOS ISO (#3068)
[Ventoy.git] / INSTALL / grub / grub.cfg
1 #************************************************************************************
2 # Copyright (c) 2020, longpanda <admin@ventoy.net>
3 #
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.
8 #
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.
13 #
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/>.
16 #
17 #************************************************************************************
18
19 if [ "$grub_platform" = "pc" ]; then
20 insmod setkey
21 insmod regexp
22 fi
23
24 function ventoy_pause {
25 echo "press Enter to continue ......"
26 read vtTmpPause
27 }
28
29 function ventoy_debug_pause {
30 if [ -n "${vtdebug_flag}" ]; then
31 echo "press Enter to continue ......"
32 read vtTmpPause
33 fi
34 }
35
36 function ventoy_cli_console {
37 if [ -z "$vtoy_display_mode" ]; then
38 terminal_output console
39 elif [ "$vtoy_display_mode" = "GUI" ]; then
40 terminal_output console
41 fi
42 }
43
44 function ventoy_gui_console {
45 if [ -z "$vtoy_display_mode" ]; then
46 terminal_output gfxterm
47 elif [ "$vtoy_display_mode" = "GUI" ]; then
48 terminal_output gfxterm
49 fi
50 }
51
52 function ventoy_acpi_param {
53 if [ "$VTOY_PARAM_NO_ACPI" != "1" ]; then
54 vt_acpi_param "$1" "$2"
55 fi
56 }
57
58 function ventoy_vcfg_proc {
59 if vt_check_custom_boot "${1}" vt_vcfg; then
60 set vtoy_chosen_path="${1}"
61 vt_file_basefile "${vtoy_chosen_path}" vtoy_chosen_file
62
63 export vtoy_chosen_path
64 export vtoy_chosen_file
65 ventoy_debug_pause
66 configfile "${vtoy_iso_part}${vt_vcfg}"
67 true
68 else
69 false
70 fi
71 }
72
73 function ventoy_language {
74 configfile $prefix/menulang.cfg
75 }
76
77 function ventoy_diagnosis {
78 vt_enum_video_mode
79 configfile $prefix/debug.cfg
80 }
81
82 function ventoy_localboot {
83 configfile $prefix/localboot.cfg
84 }
85
86 function ventoy_ext_menu {
87 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
88 set ventoy_new_context=1
89 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
90 unset ventoy_new_context
91 else
92 echo "ventoy_grub.cfg NOT exist."
93 echo -en "\n$VTLANG_ENTER_EXIT ..."
94 read vtInputKey
95 fi
96 }
97
98 function ventoy_checksum {
99 if [ -f "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}" ]; then
100 configfile $prefix/checksum.cfg
101 fi
102 }
103
104 function ventoy_show_help {
105 if [ -f $prefix/help.tar.gz ]; then
106 if [ -z "$vtoy_help_txt_mem_addr" ]; then
107 vt_load_file_to_mem "auto" $prefix/help.tar.gz vtoy_help_txt_mem
108 fi
109
110 loopback vt_help_tarfs mem:${vtoy_help_txt_mem_addr}:size:${vtoy_help_txt_mem_size}
111 vt_cur_menu_lang vtCurLang
112 if [ -f "(vt_help_tarfs)/help/${vtCurLang}.txt" ]; then
113 cat "(vt_help_tarfs)/help/${vtCurLang}.txt"
114 else
115 cat "(vt_help_tarfs)/help/en_US.txt"
116 fi
117 loopback -d vt_help_tarfs
118 fi
119 }
120
121 function ventoy_load_menu_lang_file {
122 vt_load_file_to_mem "auto" $prefix/menu.tar.gz vtoy_menu_lang_mem
123 loopback vt_menu_tarfs mem:${vtoy_menu_lang_mem_addr}:size:${vtoy_menu_lang_mem_size}
124 }
125
126 function get_os_type {
127 set vtoy_os=Linux
128 export vtoy_os
129
130 if vt_str_begin "$vt_volume_id" "DLC Boot"; then
131 if [ -f (loop)/DLCBoot.exe ]; then
132 set vtoy_os=Windows
133 fi
134 else
135 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
136 if vt_file_exist_nocase (loop)/$file; then
137 set vtoy_os=Windows
138 break
139 fi
140 done
141 fi
142
143 if [ "$vtoy_os" = "Linux" ]; then
144 if vt_strstr "$vt_system_id" "FreeBSD"; then
145 set vtoy_os=Unix
146 set vt_unix_type=FreeBSD
147 elif [ -e (loop)/bin/freebsd-version ]; then
148 set vtoy_os=Unix
149 set vt_unix_type=FreeBSD
150 elif [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
151 set vtoy_os=Unix
152 set vt_unix_type=FreeBSD
153 elif vt_str_begin "$vt_system_id" "DragonFly"; then
154 set vtoy_os=Unix
155 set vt_unix_type=DragonFly
156
157
158 elif [ -e (loop)/boot/kernel/kernel ]; then
159 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
160 set vtoy_os=Unix
161 set vt_unix_type=FreeBSD
162 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
163 set vtoy_os=Unix
164 set vt_unix_type=NetBSD
165 fi
166 fi
167 fi
168
169 if [ -n "${vtdebug_flag}" ]; then
170 echo ISO is "$vtoy_os"
171 fi
172 }
173
174 function vt_check_compatible_pe {
175 #Check for PE without external tools
176 #set compatible if ISO file is less than 80MB
177 if [ $vt_chosen_size -GT 33554432 -a $vt_chosen_size -LE 83886080 ]; then
178 set ventoy_compatible=YES
179 fi
180
181 return
182 }
183
184 function vt_check_compatible_linux {
185 if vt_str_begin "$vt_volume_id" "embootkit"; then
186 set ventoy_compatible=YES
187 elif [ -e "$1/casper/tinycore.gz" ]; then
188 set ventoy_compatible=YES
189 fi
190
191 return
192 }
193
194 function locate_initrd {
195 vt_linux_locate_initrd
196
197 if [ -n "${vtdebug_flag}" ]; then
198 vt_linux_dump_initrd
199 ventoy_debug_pause
200 fi
201 }
202
203 function locate_wim {
204 vt_windows_locate_wim_patch (loop) "$1"
205
206 if [ -n "${vtdebug_flag}" ]; then
207 echo '###############################################'
208 vt_dump_wim_patch
209 echo '###############################################'
210 ventoy_debug_pause
211 fi
212 }
213
214 function distro_specify_wim_patch {
215 if [ -d (loop)/h3pe ]; then
216 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
217 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
218 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
219 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
220 elif [ -d (loop)/2k10/winpe ]; then
221 vt_windows_collect_wim_patch wim /2k10/winpe/w1086pe.wim
222 vt_windows_collect_wim_patch wim /2k10/winpe/w8x86pe.wim
223 vt_windows_collect_wim_patch wim /2k10/winpe/w7x86pe.wim
224 fi
225 }
226
227 function distro_specify_wim_patch_phase2 {
228 if [ -f (loop)/boot/boot.wim ]; then
229 vt_windows_collect_wim_patch wim /boot/boot.wim
230 elif [ -f (loop)/sources/boot.wim ]; then
231 vt_windows_collect_wim_patch wim /sources/boot.wim
232 fi
233
234 if vt_str_begin "$vt_volume_id" "DLC Boot"; then
235 for vwfile in "/DLC1/WinPE/W11x64.wim" "/DLC1/WinPE/W10x64.wim" "/DLC1/WinPE/W10x86.wim"; do
236 if [ -f (loop)/$vwfile ]; then
237 vt_windows_collect_wim_patch wim $vwfile
238 fi
239 done
240 fi
241
242 }
243
244
245 function distro_specify_initrd_file {
246 if [ -e (loop)/boot/all.rdz ]; then
247 vt_linux_specify_initrd_file /boot/all.rdz
248 elif [ -e (loop)/boot/xen.gz ]; then
249 if [ -e (loop)/install.img ]; then
250 vt_linux_specify_initrd_file /install.img
251 fi
252 elif [ -d (loop)/casper ]; then
253 if [ -e (loop)/casper/initrd ]; then
254 vt_linux_specify_initrd_file /casper/initrd
255 fi
256 if [ -e (loop)/casper/initrd.gz ]; then
257 vt_linux_specify_initrd_file /casper/initrd.gz
258 fi
259 if [ -e (loop)/casper/initrd-oem ]; then
260 vt_linux_specify_initrd_file /casper/initrd-oem
261 fi
262 elif [ -e (loop)/boot/grub/initrd.xz ]; then
263 vt_linux_specify_initrd_file /boot/grub/initrd.xz
264 elif [ -e (loop)/initrd.gz ]; then
265 vt_linux_specify_initrd_file /initrd.gz
266 elif [ -e (loop)/slax/boot/initrfs.img ]; then
267 vt_linux_specify_initrd_file /slax/boot/initrfs.img
268 elif [ -e (loop)/minios/boot/initrfs.img ]; then
269 vt_linux_specify_initrd_file /minios/boot/initrfs.img
270 elif [ -e (loop)/pmagic/initrd.img ]; then
271 vt_linux_specify_initrd_file /pmagic/initrd.img
272 elif [ -e (loop)/boot/initrd.xz ]; then
273 vt_linux_specify_initrd_file /boot/initrd.xz
274 elif [ -e (loop)/boot/initrd.gz ]; then
275 vt_linux_specify_initrd_file /boot/initrd.gz
276 elif [ -f (loop)/boot/initrd ]; then
277 vt_linux_specify_initrd_file /boot/initrd
278 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
279 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
280 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
281 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
282 elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
283 vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
284 elif [ -f (loop)/boot/initrd.img ]; then
285 vt_linux_specify_initrd_file /boot/initrd.img
286
287 fi
288
289 if [ -f (loop)/isolinux/initrd.gz ]; then
290 vt_linux_specify_initrd_file /isolinux/initrd.gz
291 fi
292
293 if vt_str_begin "$vt_volume_id" "QUBES"; then
294 vt_linux_specify_initrd_file /images/pxeboot/initrd.img
295 fi
296
297 if [ "$vt_chosen_size" = "1133375488" ]; then
298 if [ -d (loop)/boot/grub/x86_64-efi ]; then
299 vt_cpio_busybox64 "64h"
300 fi
301 fi
302 }
303
304
305 function distro_specify_initrd_file_phase2 {
306 if [ -f (loop)/boot/initrd.img ]; then
307 vt_linux_specify_initrd_file /boot/initrd.img
308 elif [ -f (loop)/Setup/initrd.gz ]; then
309 vt_linux_specify_initrd_file /Setup/initrd.gz
310 elif [ -f (loop)/isolinux/initramfs ]; then
311 vt_linux_specify_initrd_file /isolinux/initramfs
312 elif [ -f (loop)/boot/iniramfs.igz ]; then
313 vt_linux_specify_initrd_file /boot/iniramfs.igz
314 elif [ -f (loop)/initrd-x86_64 ]; then
315 vt_linux_specify_initrd_file /initrd-x86_64
316 elif [ -f (loop)/live/initrd.img ]; then
317 vt_linux_specify_initrd_file /live/initrd.img
318 elif [ -f (loop)/initrd.img ]; then
319 vt_linux_specify_initrd_file /initrd.img
320 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
321 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
322 elif [ -f (loop)/CDlinux/initrd ]; then
323 vt_linux_specify_initrd_file /CDlinux/initrd
324 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
325 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
326 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
327 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
328 fi
329 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
330 vt_linux_specify_initrd_file /parabola/boot/x86_64/initramfs-linux-libre.img
331 if [ -f (loop)/parabola/boot/i686/initramfs-linux-libre.img ]; then
332 vt_linux_specify_initrd_file /parabola/boot/i686/initramfs-linux-libre.img
333 fi
334 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
335 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
336 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
337 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
338 fi
339 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
340 #Qubes
341 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
342 if [ "$grub_platform" != "pc" ]; then
343 vt_add_replace_file 0 "initrd.img"
344 fi
345 elif [ -f (loop)/initrd ]; then
346 vt_linux_specify_initrd_file /initrd
347 elif [ -f (loop)/live/initrd1 ]; then
348 vt_linux_specify_initrd_file /live/initrd1
349 elif [ -f (loop)/isolinux/initrd.img ]; then
350 vt_linux_specify_initrd_file /isolinux/initrd.img
351 elif [ -f (loop)/isolinux/initrd.gz ]; then
352 vt_linux_specify_initrd_file /isolinux/initrd.gz
353 elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
354 vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
355 elif vt_strstr "$vt_volume_id" "Daphile"; then
356 vt_linux_parse_initrd_isolinux (loop)/isolinux/
357 elif [ -f (loop)/boot/rootfs.xz ]; then
358 vt_linux_specify_initrd_file /boot/rootfs.xz
359 if [ "$grub_platform" != "pc" ]; then
360 vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
361 fi
362 elif [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
363 vt_linux_specify_initrd_file /arch/boot/x86_64/archiso.img
364 if [ "$grub_platform" != "pc" ]; then
365 vt_add_replace_file 0 "EFI\\archiso\\archiso.img"
366 fi
367 elif [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
368 vt_linux_specify_initrd_file /blackarch/boot/x86_64/archiso.img
369 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
370 vt_linux_specify_initrd_file /blackarch/boot/x86_64/initramfs-linux.img
371
372 elif [ -f (loop)/install.amd/initrd.gz ]; then
373 vt_linux_specify_initrd_file /live/initrd2.img
374 vt_linux_specify_initrd_file /install.amd/initrd.gz
375 vt_linux_specify_initrd_file /install.amd/gtk/initrd.gz
376 elif [ -f (loop)/boot/grub/kernels.cfg ]; then
377 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
378 elif [ -f (loop)/austrumi/initrd.gz ]; then
379 vt_linux_specify_initrd_file /austrumi/initrd.gz
380 if [ -f (loop)/EFI/BOOT/bootx64.efi ]; then
381 vt_cpio_busybox64 "64h"
382 fi
383 elif [ -f (loop)/boot/initfs.x86_64-efi ]; then
384 vt_linux_specify_initrd_file /boot/initfs.x86_64-efi
385 if [ -f (loop)/boot/initfs.i386-pc ]; then
386 vt_linux_specify_initrd_file /boot/initfs.i386-pc
387 fi
388 elif [ -f (loop)/antiX/initrd.gz ]; then
389 vt_linux_specify_initrd_file /antiX/initrd.gz
390 elif [ -f (loop)/360Disk/initrd.gz ]; then
391 vt_linux_specify_initrd_file /360Disk/initrd.gz
392 elif [ -f (loop)/porteus/initrd.xz ]; then
393 vt_linux_specify_initrd_file /porteus/initrd.xz
394 elif [ -f (loop)/pyabr/boot/initrfs.img ]; then
395 vt_linux_specify_initrd_file /pyabr/boot/initrfs.img
396 elif [ -f (loop)/initrd0.img ]; then
397 vt_linux_specify_initrd_file /initrd0.img
398 elif [ -f (loop)/sysresccd/boot/i686/sysresccd.img ]; then
399 vt_linux_specify_initrd_file /sysresccd/boot/i686/sysresccd.img
400 elif [ -f (loop)/boot/full.cz ]; then
401 vt_linux_specify_initrd_file /boot/full.cz
402 elif [ -f (loop)/images/pxeboot/initrd.img ]; then
403 vt_linux_specify_initrd_file /images/pxeboot/initrd.img
404 elif [ -f (loop)/live/initrd ]; then
405 vt_linux_specify_initrd_file /live/initrd
406 elif [ -f (loop)/initramfs-linux.img ]; then
407 vt_linux_specify_initrd_file /initramfs-linux.img
408 fi
409 }
410
411
412 function ventoy_get_ghostbsd_ver {
413 # fallback to parse version from elf /boot/kernel/kernel
414 set vt_freebsd_ver=xx
415 }
416
417 function ventoy_get_furybsd_ver {
418 set vt_freebsd_ver=12.x
419 if regexp --set 1:vtFuryVer "(14|13)\.[0-9]" "$2"; then
420 set vt_freebsd_ver=${vtFuryVer}.x
421 fi
422 }
423
424 function ventoy_get_freenas_ver {
425 set vt_freebsd_ver=11.x
426
427 if [ -e (loop)/FreeNAS-MANIFEST ]; then
428 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
429 if regexp --set 1:vtNasVer "^(14|13|12|11)\.[0-9]" "$vt_freenas_ver"; then
430 set vt_freebsd_ver=${vtNasVer}.x
431 fi
432 fi
433 }
434
435 function ventoy_get_truenas_ver {
436 set vt_freebsd_ver=12.x
437
438 if [ -e (loop)/TrueNAS-MANIFEST ]; then
439 vt_parse_freenas_ver (loop)/TrueNAS-MANIFEST vt_truenas_ver
440 if regexp --set 1:vtTNasVer "^(14|13|12|11)\.[0-9]" "$vt_truenas_ver"; then
441 set vt_freebsd_ver=${vtTNasVer}.x
442 fi
443 fi
444 }
445
446 function ventoy_get_midnightbsd_ver {
447 if vt_str_begin "$vt_volume_id" "1_"; then
448 set vt_freebsd_ver=11.x
449 elif vt_str_begin "$vt_volume_id" "2_"; then
450 set vt_freebsd_ver=2.x
451 elif vt_str_begin "$vt_volume_id" "3_"; then
452 set vt_freebsd_ver=3.x
453 fi
454 }
455
456 function ventoy_freebsd_proc {
457 set vtFreeBsdDistro=FreeBSD
458 set vt_freebsd_ver=xx
459
460 if [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
461 vt_unix_ko_fillmap /boot/kernel/geom_ventoy.ko
462 return
463 fi
464
465 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
466 ventoy_get_ghostbsd_ver "$1" "${chosen_path}"
467 elif vt_strstr "$vt_volume_id" "FREENAS"; then
468 ventoy_get_freenas_ver "$1" "${chosen_path}"
469 elif vt_strstr "$vt_volume_id" "TRUENAS"; then
470 ventoy_get_truenas_ver "$1" "${chosen_path}"
471 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
472 ventoy_get_furybsd_ver "$1" "${chosen_path}"
473 elif regexp --set 1:vtBsdVerNum "^(14|13|12|11|10|9)_[0-9]" "$vt_volume_id"; then
474 set vt_freebsd_ver=${vtBsdVerNum}.x
475 elif [ -d (loop)/usr/midnightbsd-dist ]; then
476 ventoy_get_midnightbsd_ver "$1" "${chosen_path}"
477 set vtFreeBsdDistro=MidnightBSD
478 elif [ -e (loop)/bin/freebsd-version ]; then
479 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
480 if regexp --set 1:vtBsdVerNum "\"(14|13|12|11|10|9)\.[0-9]-" "$vt_userland_ver"; then
481 set vt_freebsd_ver=${vtBsdVerNum}.x
482 fi
483 elif [ -e (loop)/README.TXT ]; then
484 vt_1st_line (loop)/README.TXT vt_freebsd_line1
485 if regexp --set 1:vtBsdVerNum "FreeBSD (14|13|12|11|10|9)\.[0-9]-" "$vt_freebsd_line1"; then
486 set vt_freebsd_ver=${vtBsdVerNum}.x
487 fi
488 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
489 set vt_freebsd_ver=9.x
490 fi
491
492
493 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
494 set vtFreeBsdDistro=ClonOS
495 fi
496
497 set vt_freebsd_bit=64
498 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
499 if [ -e (loop)/$file ]; then
500 if file --is-i386-kfreebsd (loop)/$file; then
501 set vt_freebsd_bit=32
502 fi
503 break
504 fi
505 done
506
507 if [ "$vt_freebsd_ver" = "xx" ]; then
508 if [ -e (loop)/boot/kernel/kernel ]; then
509 vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel $vt_freebsd_bit vt_freebsd_ver
510 elif [ -e (loop)/boot/kernel/kernel.gz ]; then
511 vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel.gz $vt_freebsd_bit vt_freebsd_ver
512 fi
513
514 if [ "$vt_freebsd_ver" = "xx" ]; then
515 set vt_freebsd_ver=14.x
516 fi
517 fi
518
519 if [ -n "${vtdebug_flag}" ]; then
520 echo "This is $vtFreeBsdDistro $vt_freebsd_ver ${vt_freebsd_bit}bit"
521 fi
522
523 unset vt_unix_mod_path
524 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/TrueNAS-MANIFEST" "/version" "/etc/fstab"; do
525 if [ -e (loop)${file} ]; then
526 set vt_unix_mod_path=${file}
527 break
528 fi
529 done
530
531 if [ -n "$vt_unix_mod_path" ]; then
532 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
533 vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
534 elif [ -e (loop)/easyre.ufs.uzip ]; then
535 vt_unix_replace_ko "/boot/grub/i386-pc/linux.mod" (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
536 if [ "$grub_platform" = "pc" ]; then
537 vt_unix_replace_grub_conf "/boot/grub/i386-pc/linux.mod" "cd9"
538 else
539 vt_unix_replace_conf FreeBSD "${1}${chosen_path}" "cd9"
540 fi
541 fi
542 }
543
544 function ventoy_dragonfly_proc {
545
546 unset vt_unix_mod_path
547 for file in "/boot/kernel/initrd.img.gz"; do
548 if [ -e (loop)${file} ]; then
549 set vt_unix_mod_path=${file}
550 break
551 fi
552 done
553
554 vt_unix_replace_ko $vt_unix_mod_path ${vtoy_path}/dragonfly.mfs.xz
555 vt_unix_fill_image_desc
556 vt_unix_gzip_new_ko
557 vt_unix_replace_conf DragonFly "${1}${chosen_path}"
558 }
559
560 function ventoy_unix_comm_proc {
561 vt_unix_reset
562
563 vt_unix_check_vlnk "${1}${chosen_path}"
564
565 if [ "$ventoy_compatible" = "NO" ]; then
566 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
567
568 if [ "$vt_unix_type" = "FreeBSD" ]; then
569 ventoy_freebsd_proc "$1" "${chosen_path}"
570 elif [ "$vt_unix_type" = "DragonFly" ]; then
571 ventoy_dragonfly_proc "$1" "${chosen_path}"
572 elif [ "$vt_unix_type" = "NetBSD" ]; then
573 echo "NetBSD not supported"
574
575
576 else
577 if [ -n "${vtdebug_flag}" ]; then
578 echo "Unknown unix type"
579 fi
580 fi
581 fi
582
583 vt_unix_chain_data "${1}${chosen_path}"
584 ventoy_debug_pause
585 }
586
587
588 function uefi_windows_menu_func {
589 vt_windows_reset
590
591 unset vt_cur_wimboot_mode
592 if vt_check_mode 4 "$vt_chosen_name"; then
593 set vt_cur_wimboot_mode=1
594 fi
595
596 if [ "$ventoy_compatible" = "NO" -o "$vt_cur_wimboot_mode" = "1" ]; then
597 if [ "$ventoy_fs_probe" = "iso9660" ]; then
598 loopback -d loop
599 vt_iso9660_nojoliet 1
600 loopback loop "$1$2"
601 fi
602
603 for file in "efi/microsoft/boot/bcd"; do
604 vt_windows_collect_wim_patch bcd (loop)/$file
605 done
606
607 vt_windows_count_wim_patch vt_wim_cnt
608 if [ $vt_wim_cnt -eq 0 ]; then
609 distro_specify_wim_patch_phase2
610 fi
611
612 ventoy_debug_pause
613 locate_wim "${chosen_path}"
614 fi
615
616 vt_windows_chain_data "${1}${chosen_path}"
617 ventoy_debug_pause
618
619 if [ "$vt_cur_wimboot_mode" = "1" ]; then
620 vtoy_wimboot_func
621 fi
622
623 if [ -n "$vtoy_chain_mem_addr" ]; then
624 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
625 ventoy_cli_console
626 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} iso_${ventoy_fs_probe} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
627 boot
628 else
629 echo "chain empty failed"
630 ventoy_pause
631 fi
632 }
633
634 function uefi_find_replace_initrd {
635 if vt_get_efi_vdisk_offset "${1}${2}" vt_efivdisk_offset; then
636 loopback -s $vt_efivdisk_offset vtefivdisk "${1}${2}"
637
638 unset vt_rp_initrd
639 vt_search_replace_initrd (vtefivdisk) vt_rp_initrd
640
641 if [ -n "$vt_rp_initrd" ]; then
642 vt_add_replace_file $3 "$vt_rp_initrd"
643 fi
644
645 loopback -d vtefivdisk
646 ventoy_debug_pause
647 fi
648 }
649
650 function uefi_linux_menu_func {
651
652 if [ "$ventoy_compatible" = "NO" ]; then
653
654 if [ "$ventoy_fs_probe" = "udf" ]; then
655 loopback -d loop
656 set ventoy_fs_probe=iso9660
657 loopback loop "$1$2"
658 fi
659
660 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
661
662 vt_linux_clear_initrd
663
664 if [ -d (loop)/pmagic ]; then
665 vt_linux_specify_initrd_file /pmagic/initrd.img
666 else
667 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
668 if [ -e (loop)/$file ]; then
669 vt_linux_parse_initrd_grub file (loop)/$file
670 fi
671 done
672 fi
673
674 # special process for special distros
675 if [ -d (loop)/loader/entries ]; then
676 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
677 elif [ -d (loop)/boot/grub ]; then
678 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
679 fi
680
681 distro_specify_initrd_file
682
683 vt_linux_initrd_count vtcount
684
685 if [ $vtcount -eq 0 ]; then
686 if [ -e (loop)/EFI/boot/livegrub.cfg ]; then
687 vt_linux_parse_initrd_grub file (loop)/EFI/boot/livegrub.cfg
688 fi
689 distro_specify_initrd_file_phase2
690
691 if [ "$vt_efi_dir" = "NO" ]; then
692 if [ -f (loop)/efi.img ]; then
693 vt_add_replace_file 0 "initrd"
694 fi
695 fi
696 fi
697
698 locate_initrd
699
700 if [ -d (loop)/loader/entries ]; then
701 vt_linux_get_main_initrd_index vtindex
702
703 if [ -d (loop)/arch ]; then
704 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
705 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
706 elif [ -f (loop)/arch/boot/x86_64/initramfs-linux.img ]; then
707 vt_add_replace_file $vtindex "arch\\boot\\x86_64\\initramfs-linux.img"
708 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
709 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
710 fi
711 elif [ -d (loop)/blackarch ]; then
712 if [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
713 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
714 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
715 vt_add_replace_file $vtindex "blackarch\\boot\\x86_64\\initramfs-linux.img"
716 fi
717 elif [ -d (loop)/anarchy ]; then
718 if [ -f (loop)/anarchy/boot/x86_64/initramfs-linux.img ]; then
719 vt_add_replace_file $vtindex "anarchy\\boot\\x86_64\\initramfs-linux.img"
720 fi
721 elif [ -d (loop)/parabola ]; then
722 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
723 vt_add_replace_file $vtindex "EFI\\parabolaiso\\parabolaiso.img"
724 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
725 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
726 fi
727 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
728 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
729 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
730 vt_add_replace_file $vtindex "boot\\initrd"
731 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
732 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
733 fi
734
735 vt_get_replace_file_cnt vt_replace_cnt
736 if [ $vt_replace_cnt -eq 0 ]; then
737 uefi_find_replace_initrd "$1" "$2" $vtindex
738 fi
739 elif [ -d (loop)/EFI/boot/entries ]; then
740 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
741 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
742 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
743 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
744 fi
745 elif [ -d (loop)/EFI/BOOT/entries ]; then
746 vt_linux_get_main_initrd_index vtindex
747
748 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
749 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
750 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
751 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
752 fi
753 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
754 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
755 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
756
757 elif vt_str_begin "$vt_volume_id" "SolusLive"; then
758 vt_add_replace_file 0 "initrd"
759
760 fi
761
762 fi
763
764 vt_linux_chain_data "${1}${chosen_path}"
765
766 if [ -n "$LoadIsoEfiDriver" -a $vt_chosen_size -LT 104857600 ]; then
767 if [ -f (loop)/efi/clover/cloverx64.efi ]; then
768 unset LoadIsoEfiDriver
769 fi
770 fi
771
772 if [ -n "$vtoy_chain_mem_addr" ]; then
773 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
774 ventoy_cli_console
775
776 unset vtGrub2Mode
777 if vt_check_mode 3 "$vt_chosen_name"; then
778 set vtGrub2Mode=1
779 elif vt_str_begin "$vt_volume_id" "HOLO_"; then
780 if [ -d (loop)/loader/entries ]; then
781 set vtGrub2Mode=1
782 fi
783 elif vt_str_begin "$vt_volume_id" "KRD"; then
784 if [ -f (loop)/boot/grub/grub.cfg.sig ]; then
785 set vtGrub2Mode=1
786 fi
787 fi
788
789 if [ -n "$vtGrub2Mode" ]; then
790 ventoy_debug_pause
791 else
792 if [ "$VTOY_EFI_ARCH" != "mips" ]; then
793 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi fallback env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
794 boot
795 fi
796 fi
797
798 # fallback
799 set vtback_root=$root
800 vt_push_last_entry
801 set vtback_theme=$theme
802 unset theme
803
804 vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
805 vt_set_boot_opt rdinit=/vtoy/vtoy
806
807 set root=(loop)
808 set vtback_cfg_find=0
809 for cfg in "/boot/grub/grub.cfg" "/EFI/BOOT/grub.cfg" "/EFI/debian/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "/grub/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
810 if [ -e "$cfg" ]; then
811 set vtback_cfg_find=1
812 configfile "$cfg"
813 break
814 fi
815 done
816 if [ $vtback_cfg_find -eq 0 ]; then
817 if [ -f (loop)/loader/loader.conf -a -d (loop)/loader/entries ]; then
818 if vt_str_begin "$vt_volume_id" "HOLO_"; then
819 set root=(loop,2)
820 vt_systemd_menu (loop,2) vt_sys_menu_mem
821 else
822 vt_systemd_menu (loop) vt_sys_menu_mem
823 fi
824 set vtback_cfg_find=1
825 configfile "mem:${vt_sys_menu_mem_addr}:size:${vt_sys_menu_mem_size}"
826 fi
827 fi
828
829 if [ $vtback_cfg_find -eq 0 ]; then
830 if [ -f (loop)/boot/isolinux/syslnx64.cfg ]; then
831 syslinux_configfile (loop)/boot/isolinux/syslnx64.cfg
832 set vtback_cfg_find=1
833 elif [ -f (loop)/boot/syslinux/porteus.cfg ]; then
834 syslinux_configfile (loop)/boot/syslinux/porteus.cfg
835 set vtback_cfg_find=1
836 fi
837 fi
838
839 if [ "$vtback_cfg_find" = "0" ]; then
840 echo " "
841 echo "No bootfile found for UEFI!"
842 echo "Maybe the image does not support $VTOY_EFI_ARCH UEFI"
843 echo " "
844 sleep 30
845 fi
846
847 vt_unset_boot_opt
848 set root=$vtback_root
849 set theme=$vtback_theme
850 vt_pop_last_entry
851 ventoy_gui_console
852 else
853 echo "chain empty failed"
854 ventoy_pause
855 fi
856 }
857
858 function uefi_unix_menu_func {
859 ventoy_unix_comm_proc $1 "${chosen_path}"
860
861 if [ -n "$vtoy_chain_mem_addr" ]; then
862 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
863 ventoy_cli_console
864 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
865 boot
866 else
867 echo "chain empty failed"
868 ventoy_pause
869 fi
870 }
871
872 function ventoy_reset_nojoliet {
873 if vt_str_begin "$vt_volume_id" "ARCARESCUE"; then
874 vt_iso9660_nojoliet 1
875 else
876 vt_iso9660_nojoliet 0
877 fi
878
879 vt_append_extra_sector 0
880 }
881
882 function uefi_iso_menu_func {
883 if [ -n "$vtisouefi" ]; then
884 set LoadIsoEfiDriver=on
885 unset vtisouefi
886 elif vt_check_mode 2 "$vt_chosen_name"; then
887 set LoadIsoEfiDriver=on
888 else
889 unset LoadIsoEfiDriver
890 fi
891
892 set chosen_path="$2"
893 vt_select_auto_install "${chosen_path}"
894 vt_select_persistence "${chosen_path}"
895
896 if ! vt_is_udf "${1}${chosen_path}"; then
897 # Lenovo EasyStartup need an addional sector for boundary check
898 if vt_str_begin "$vt_volume_id" "EasyStartup"; then
899 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
900 vt_append_extra_sector 1
901 fi
902 fi
903
904 if [ -d (loop)/EFI ]; then
905 set vt_efi_dir=YES
906 elif [ -d (loop)/efi ]; then
907 set vt_efi_dir=YES
908 else
909 set vt_efi_dir=NO
910 fi
911
912 if [ -n "$vtcompat" ]; then
913 set ventoy_compatible=YES
914 unset vtcompat
915 elif vt_check_mode 1 "$vt_chosen_name"; then
916 set ventoy_compatible=YES
917 else
918 vt_check_compatible (loop)
919 fi
920
921 vt_img_sector "${1}${chosen_path}"
922
923 if [ "$ventoy_fs_probe" = "iso9660" ]; then
924 vt_select_conf_replace "${1}" "${chosen_path}"
925 fi
926
927 if [ "$vtoy_os" = "Windows" ]; then
928 vt_check_compatible_pe (loop)
929 uefi_windows_menu_func "$1" "${chosen_path}"
930 elif [ "$vtoy_os" = "Unix" ]; then
931 uefi_unix_menu_func "$1" "${chosen_path}"
932 else
933 vt_check_compatible_linux (loop)
934 uefi_linux_menu_func "$1" "${chosen_path}"
935 fi
936
937 ventoy_gui_console
938 }
939
940 function uefi_iso_memdisk {
941 echo 'Loading ISO file to memory ...'
942 vt_load_img_memdisk "${1}${2}" vtoy_iso_buf
943
944 ventoy_cli_console
945 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
946 boot
947
948 ventoy_gui_console
949 }
950
951 function vtoy_windows_wimboot {
952 if [ -f (loop)/x86/sources/boot.wim -a -f (loop)/x64/sources/boot.wim ]; then
953 vt_sel_wimboot vtoy_wimboot_bit
954 if [ "$vtoy_wimboot_bit" = "32" ]; then
955 set vtoy_wimboot_prefix=(loop)/x86
956 else
957 set vtoy_wimboot_prefix=(loop)/x64
958 fi
959 else
960 set vtoy_wimboot_prefix=(loop)
961 if vt_is_pe64 $vtoy_wimboot_prefix/setup.exe; then
962 set vtoy_wimboot_bit=64
963 else
964 set vtoy_wimboot_bit=32
965 fi
966 fi
967
968 if [ -n "${vtdebug_flag}" ]; then
969 echo vtoy_wimboot_prefix=$vtoy_wimboot_prefix vtoy_wimboot_bit=$vtoy_wimboot_bit vt_wimkernel=$vt_wimkernel
970 fi
971
972 vt_windows_wimboot_data "$vtoy_wimboot_prefix/sources/boot.wim" vtoy_init_exe vtoy_wim_bit
973
974 if [ "$grub_platform" = "pc" ]; then
975 linux16 "$vtoy_path/$vt_wimkernel" quiet
976 ventoy_debug_pause
977
978 vt_set_wim_load_prompt 1 "Loading files......"
979 initrd16 newc:winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
980 newc:vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd \
981 newc:bcd:$vtoy_wimboot_prefix/boot/bcd \
982 newc:boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi \
983 newc:boot.wim:$vtoy_wimboot_prefix/sources/boot.wim
984 vt_set_wim_load_prompt 0
985 boot
986 else
987 vt_set_wim_load_prompt 1 "Loading files......"
988 vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/sources/boot.wim vtoy_wimfile_mem
989 vt_set_wim_load_prompt 0
990
991 if [ $? -eq 0 ]; then
992 set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
993 else
994 set vtoy_wimfile_path=$vtoy_wimboot_prefix/sources/boot.wim
995 fi
996
997 ventoy_cli_console
998 chainloader "$vtoy_path/$vt_wimkernel" quiet \
999 "vf=winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
1000 "vf=vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd" \
1001 "vf=bcd:$vtoy_wimboot_prefix/boot/bcd" \
1002 "vf=boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi" \
1003 "vf=boot.wim:$vtoy_wimfile_path" \
1004 pfsize=$vtoy_chain_file_size \
1005 pfread=$vtoy_chain_file_read
1006 boot
1007 ventoy_gui_console
1008 fi
1009 }
1010
1011 function vtoy_winpe_wimboot {
1012 unset vtoy_boot_sdi_legacy
1013 unset vtoy_boot_sdi_efi
1014
1015 set vtoy_wimboot_prefix=(loop)
1016 set vtoy_wim_path="$1"
1017
1018 if [ -n "${vtdebug_flag}" ]; then
1019 echo "winpe_wimboot $1 $2 $3"
1020 fi
1021
1022 if [ "$2" != "0" ]; then
1023 set vtoy_boot_sdi_legacy="newc:boot.sdi:$vtoy_wimboot_prefix/$2"
1024 set vtoy_boot_sdi_efi="vf=boot.sdi:$vtoy_wimboot_prefix/$2"
1025 fi
1026
1027 vt_windows_wimboot_data $vtoy_wimboot_prefix/$vtoy_wim_path vtoy_init_exe vtoy_wim_bit
1028
1029 if [ "$grub_platform" = "pc" ]; then
1030 linux16 "$vtoy_path/$vt_wimkernel" quiet
1031 ventoy_debug_pause
1032
1033 vt_set_wim_load_prompt 1 "Loading files......"
1034 initrd16 newc:$vtoy_init_exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
1035 newc:vtoy_wimboot:$vtoy_path/$vt_wimkernel \
1036 newc:bootmgr.exe:mem:${vtoy_pe_bootmgr_mem_addr}:size:${vtoy_pe_bootmgr_mem_size} \
1037 newc:bcd:mem:${vtoy_pe_bcd_mem_addr}:size:${vtoy_pe_bcd_mem_size} \
1038 $vtoy_boot_sdi_legacy \
1039 newc:boot.wim:$vtoy_wimboot_prefix/$vtoy_wim_path
1040 vt_set_wim_load_prompt 0
1041 boot
1042 else
1043 if [ "$VTOY_EFI_ARCH" = "x64" -a "$vtoy_wim_bit" = "32" ]; then
1044 echo -e "\nThis is 32bit Windows and does NOT support x86_64 UEFI firmware.\n"
1045 echo -e "这是32位的 Windows 系统,不支持当前的64位 UEFI 环境。\n"
1046 fi
1047
1048 vt_set_wim_load_prompt 1 "Loading files......"
1049 vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/$vtoy_wim_path vtoy_wimfile_mem
1050 vt_set_wim_load_prompt 0
1051
1052 if [ $? -eq 0 ]; then
1053 set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
1054 else
1055 set vtoy_wimfile_path=$vtoy_wimboot_prefix/$vtoy_wim_path
1056 fi
1057
1058 unset vtoy_boot_efi_path
1059 if [ -F (loop)/efi/boot/boot${VTOY_EFI_ARCH}.efi ]; then
1060 set vtoy_boot_efi_path="vf=bootx64.efi:(loop)/efi/boot/boot${VTOY_EFI_ARCH}.efi"
1061 fi
1062
1063 ventoy_cli_console
1064 chainloader "$vtoy_path/$vt_wimkernel" quiet \
1065 "vf=$vtoy_init_exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
1066 "vf=vtoy_wimboot:$vtoy_path/$vt_wimkernel" \
1067 "vf=bcd:mem:${vtoy_pe_bcd_mem_addr}:size:${vtoy_pe_bcd_mem_size}" \
1068 "$vtoy_boot_sdi_efi" \
1069 "$vtoy_boot_efi_path" \
1070 "vf=boot.wim:$vtoy_wimfile_path" \
1071 pfsize=$vtoy_chain_file_size \
1072 pfread=$vtoy_chain_file_read
1073 boot
1074 ventoy_gui_console
1075 fi
1076 }
1077
1078 function vtoy_wimboot_func {
1079 if [ "$grub_platform" = "pc" ]; then
1080 set vt_wimkernel=wimboot.x86_64.xz
1081 else
1082 if [ "$grub_cpu" = "i386" ]; then
1083 set vt_wimkernel=wimboot.i386.efi.xz
1084 else
1085 set vt_wimkernel=wimboot.x86_64.xz
1086 fi
1087 fi
1088
1089 if vt_is_standard_winiso (loop); then
1090 echo -e "\n==================== VENTOY WIMBOOT ==================\n"
1091 vtoy_windows_wimboot
1092 else
1093 vt_sel_winpe_wim (loop)
1094 if [ -n "$vtoy_pe_wim_path" ]; then
1095 echo -e "\n==================== VENTOY WIMBOOT ==================\n"
1096
1097 vt_fs_ignore_case 1
1098 vt_load_file_to_mem "auto" $vtoy_path/common_bcd.xz vtoy_pe_bcd_mem
1099
1100 set vt_sdi_path=0
1101 for vsdi in "boot/boot.sdi" "2K10/FONTS/boot.sdi" "SSTR/boot.sdi" "ISPE/BOOT.SDI" \
1102 "boot/uqi.sdi" "ISYL/boot.sdi" "WEPE/WEPE.SDI" ; do
1103 if [ -F "(loop)/$vsdi" ]; then
1104 set vt_sdi_path=$vsdi
1105 break
1106 fi
1107 done
1108
1109 if [ "$grub_platform" = "pc" ]; then
1110 vt_load_file_to_mem "auto" $vtoy_path/common_bootmgr.xz vtoy_pe_bootmgr_mem
1111 vtoy_winpe_wimboot "$vtoy_pe_wim_path" "$vt_sdi_path" 1
1112 else
1113 vtoy_winpe_wimboot "$vtoy_pe_wim_path" "$vt_sdi_path" 0
1114 fi
1115
1116 vt_fs_ignore_case 0
1117 fi
1118 fi
1119 }
1120
1121 function legacy_windows_menu_func {
1122 vt_windows_reset
1123
1124 unset vt_cur_wimboot_mode
1125 if vt_check_mode 4 "$vt_chosen_name"; then
1126 set vt_cur_wimboot_mode=1
1127 fi
1128
1129 if [ "$ventoy_compatible" = "NO" -o "$vt_cur_wimboot_mode" = "1" ]; then
1130 if [ "$ventoy_fs_probe" = "iso9660" ]; then
1131 loopback -d loop
1132 vt_iso9660_nojoliet 1
1133 loopback loop "$1$2"
1134 fi
1135
1136 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD" "boot/bce"; do
1137 vt_windows_collect_wim_patch bcd (loop)/$file
1138 done
1139
1140 distro_specify_wim_patch
1141
1142 vt_windows_count_wim_patch vt_wim_cnt
1143 if [ $vt_wim_cnt -eq 0 ]; then
1144 distro_specify_wim_patch_phase2
1145 fi
1146
1147 ventoy_debug_pause
1148 if [ -z "$vt_cur_wimboot_mode" ]; then
1149 locate_wim "${chosen_path}"
1150 fi
1151 fi
1152
1153 vt_windows_chain_data "${1}${chosen_path}"
1154 ventoy_debug_pause
1155
1156 if [ "$vt_cur_wimboot_mode" = "1" ]; then
1157 vtoy_wimboot_func
1158 fi
1159
1160 if [ -n "$vtoy_chain_mem_addr" ]; then
1161 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1162 if [ "$ventoy_compatible" = "NO" ]; then
1163 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1164 else
1165 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1166 fi
1167 boot
1168 else
1169 echo "chain empty failed"
1170 ventoy_pause
1171 fi
1172 }
1173
1174 function legacy_linux_menu_func {
1175 if [ "$ventoy_compatible" = "NO" ]; then
1176
1177 if [ "$ventoy_fs_probe" = "udf" ]; then
1178 loopback -d loop
1179 set ventoy_fs_probe=iso9660
1180 loopback loop "$1$2"
1181 fi
1182
1183
1184 if vt_syslinux_need_nojoliet "$1$2"; then
1185 vt_iso9660_nojoliet 1
1186 loopback -d loop
1187 loopback loop "$1$2"
1188 fi
1189
1190 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
1191
1192 vt_linux_clear_initrd
1193
1194 if [ -d (loop)/pmagic ]; then
1195 vt_linux_specify_initrd_file /pmagic/initrd.img
1196 else
1197 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
1198 if [ -d (loop)/$dir ]; then
1199 vt_linux_parse_initrd_isolinux (loop)/$dir/
1200 fi
1201 done
1202 fi
1203
1204 # special process for special distros
1205 #archlinux
1206 if [ -d (loop)/arch/boot/syslinux ]; then
1207 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
1208 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
1209 elif [ -d (loop)/anarchy/boot/syslinux ]; then
1210 vt_linux_parse_initrd_isolinux (loop)/anarchy/boot/syslinux/ /anarchy/
1211
1212 #manjaro
1213 elif [ -d (loop)/manjaro ]; then
1214 if [ -e (loop)/boot/grub/kernels.cfg ]; then
1215 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
1216 fi
1217 elif [ -e (loop)/boot/grub/grub.cfg ]; then
1218 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
1219 fi
1220
1221 distro_specify_initrd_file
1222
1223 vt_linux_initrd_count vtcount
1224 if [ $vtcount -eq 0 ]; then
1225 if [ -d (loop)/rancheros ]; then
1226 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
1227 fi
1228
1229 distro_specify_initrd_file_phase2
1230 fi
1231
1232 locate_initrd
1233 fi
1234
1235 vt_linux_chain_data "${1}${chosen_path}"
1236 ventoy_debug_pause
1237
1238 if [ -n "$vtoy_chain_mem_addr" ]; then
1239 unset vtGrub2Mode
1240 if vt_check_mode 3 "$vt_chosen_name"; then
1241 set vtGrub2Mode=1
1242 elif vt_str_begin "$vt_volume_id" "HOLO_"; then
1243 if [ -d (loop)/loader/entries ]; then
1244 set vtGrub2Mode=1
1245 fi
1246 fi
1247
1248 if [ -n "$vtGrub2Mode" ]; then
1249 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1250 ventoy_cli_console
1251
1252 # fallback
1253 set vtback_root=$root
1254 vt_push_last_entry
1255 set vtback_theme=$theme
1256 unset theme
1257
1258 vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
1259 vt_set_boot_opt rdinit=/vtoy/vtoy
1260
1261 set root=(loop)
1262 set vtback_cfg_find=0
1263 for cfg in "/boot/grub/grub.cfg" "/EFI/BOOT/grub.cfg" "/EFI/debian/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "/grub/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
1264 if [ -e "$cfg" ]; then
1265 set vtback_cfg_find=1
1266 configfile "$cfg"
1267 break
1268 fi
1269 done
1270 if [ $vtback_cfg_find -eq 0 ]; then
1271 if [ -f (loop)/loader/loader.conf -a -d (loop)/loader/entries ]; then
1272 if vt_str_begin "$vt_volume_id" "HOLO_"; then
1273 set root=(loop,2)
1274 vt_systemd_menu (loop,2) vt_sys_menu_mem
1275 else
1276 vt_systemd_menu (loop) vt_sys_menu_mem
1277 fi
1278 set vtback_cfg_find=1
1279 configfile "mem:${vt_sys_menu_mem_addr}:size:${vt_sys_menu_mem_size}"
1280 fi
1281 fi
1282
1283 if [ $vtback_cfg_find -eq 0 ]; then
1284 if [ -f (loop)/boot/isolinux/syslnx64.cfg ]; then
1285 syslinux_configfile (loop)/boot/isolinux/syslnx64.cfg
1286 set vtback_cfg_find=1
1287 elif [ -f (loop)/boot/syslinux/porteus.cfg ]; then
1288 syslinux_configfile (loop)/boot/syslinux/porteus.cfg
1289 set vtback_cfg_find=1
1290 fi
1291 fi
1292
1293 vt_unset_boot_opt
1294 set root=$vtback_root
1295 set theme=$vtback_theme
1296 vt_pop_last_entry
1297 ventoy_gui_console
1298 else
1299 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1300 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1301 boot
1302 fi
1303 else
1304 echo "chain empty failed"
1305 ventoy_pause
1306 fi
1307 }
1308
1309
1310 function legacy_unix_menu_func {
1311 ventoy_unix_comm_proc $1 "${chosen_path}"
1312
1313 if [ -n "$vtoy_chain_mem_addr" ]; then
1314 #ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1315 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1316 boot
1317 else
1318 echo "chain empty failed"
1319 ventoy_pause
1320 fi
1321 }
1322
1323
1324 function legacy_iso_menu_func {
1325 set chosen_path="$2"
1326
1327 vt_select_auto_install "${chosen_path}"
1328 vt_select_persistence "${chosen_path}"
1329
1330 if [ -n "$vtcompat" ]; then
1331 set ventoy_compatible=YES
1332 unset vtcompat
1333 elif vt_check_mode 1 "$vt_chosen_name"; then
1334 set ventoy_compatible=YES
1335 else
1336 vt_check_compatible (loop)
1337 fi
1338
1339 vt_img_sector "${1}${chosen_path}"
1340
1341 if [ "$ventoy_fs_probe" = "iso9660" ]; then
1342 vt_select_conf_replace "${1}" "${chosen_path}"
1343 fi
1344
1345 if [ "$vtoy_os" = "Windows" ]; then
1346 vt_check_compatible_pe (loop)
1347 legacy_windows_menu_func "$1" "${chosen_path}"
1348 elif [ "$vtoy_os" = "Unix" ]; then
1349 legacy_unix_menu_func "$1" "${chosen_path}"
1350 else
1351 vt_check_compatible_linux (loop)
1352 legacy_linux_menu_func "$1" "${chosen_path}"
1353 fi
1354 vt_secondary_recover_mode
1355 }
1356
1357 function legacy_iso_memdisk {
1358
1359 linux16 $vtoy_path/memdisk iso raw
1360 echo "Loading ISO file to memory ..."
1361 initrd16 "${1}${2}"
1362 boot
1363 }
1364
1365
1366 function iso_endless_os_proc {
1367 if [ -d (loop)/ ]; then
1368 loopback -d loop
1369 fi
1370
1371 loopback loop "${1}${2}"
1372 vt_img_sector "${1}${2}"
1373
1374 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
1375 vt_trailer_cpio "$1" "$2" noinit
1376
1377 ventoy_debug_pause
1378
1379 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
1380
1381 set eosimage=loop
1382 set ventoy_bls_bootdev=/boot
1383 set ventoy_loading_tip="Loading files ......"
1384
1385 export eosimage
1386 configfile (loop)/endless/grub/grub.cfg
1387
1388 unset eosimage
1389 unset ventoy_bls_bootdev
1390 unset ventoy_loading_tip
1391
1392 vt_unset_boot_opt
1393 }
1394
1395
1396 function ventoy_iso_busybox_ver {
1397
1398 if [ "$VTOY_EFI_ARCH" = "aa64" ]; then
1399 set ventoy_busybox_ver=a64
1400 elif [ "$VTOY_EFI_ARCH" = "mips" ]; then
1401 set ventoy_busybox_ver=m64
1402 else
1403 set ventoy_busybox_ver=32
1404
1405 #special process for deepin-live iso
1406 if [ "$vt_chosen_size" = "403701760" ]; then
1407 if vt_str_str "$vt_chosen_path" "/deepin-live"; then
1408 set ventoy_busybox_ver=64
1409 fi
1410 elif vt_str_begin "$vt_volume_id" "PHOTON_"; then
1411 set ventoy_busybox_ver=64
1412 elif vt_str_begin "$vt_volume_id" "smgl-test-quinq-x86_64"; then
1413 set ventoy_busybox_ver=64
1414 elif vt_str_begin "$vt_volume_id" "LDiagBootable"; then
1415 set ventoy_busybox_ver=64
1416 elif vt_str_begin "$vt_volume_id" "KAOS_"; then
1417 set ventoy_busybox_ver=64
1418
1419 fi
1420 fi
1421 }
1422
1423
1424 function iso_common_menuentry {
1425 unset vt_system_id
1426 unset vt_volume_id
1427
1428 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1429
1430 vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id vt_volume_space
1431 if [ $vt_volume_space -NE $vt_chosen_size ]; then
1432 vt_mod $vt_chosen_size 2048 vt_chosen_size_mod
1433 if [ $vt_chosen_size_mod -ne 0 ]; then
1434 echo -e "\n $vt_volume_space $vt_chosen_size $vt_chosen_size_mod\n"
1435 echo -e "\n The size of the iso file \"$vt_chosen_size\" is invalid. File corrupted ?\n"
1436 echo -e " 此ISO文件的大小 \"$vt_chosen_size\" 有问题,请确认文件是否损坏。\n"
1437 echo -en "\n$VTLANG_ENTER_CONTINUE ..."
1438 read vtInputKey
1439 fi
1440 fi
1441
1442 if vt_check_password "${vt_chosen_path}"; then
1443 return
1444 fi
1445
1446 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1447 return
1448 fi
1449
1450
1451
1452 #secondary boot menu
1453 if vt_is_udf "${vtoy_iso_part}${vt_chosen_path}"; then
1454 set ventoy_fs_probe=udf
1455 else
1456 set ventoy_fs_probe=iso9660
1457 ventoy_reset_nojoliet
1458 fi
1459
1460 if [ -d (loop)/ ]; then
1461 loopback -d loop
1462 fi
1463 loopback loop "${vtoy_iso_part}${vt_chosen_path}"
1464
1465 get_os_type (loop)
1466
1467 ventoy_debug_pause
1468
1469 if vt_need_secondary_menu "$vt_chosen_name"; then
1470 vt_show_secondary_menu "$vt_chosen_path" "$vtoy_os" $vt_chosen_size
1471 if [ "$VTOY_SECOND_EXIT" = "1" ]; then
1472 return
1473 fi
1474 fi
1475
1476
1477 if vt_str_begin "$vt_volume_id" "Avira"; then
1478 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
1479 fi
1480
1481 ventoy_iso_busybox_ver
1482
1483 #special process for Endless OS
1484 if vt_str_begin "$vt_volume_id" "Endless-OS"; then
1485 iso_endless_os_proc $vtoy_iso_part "$vt_chosen_path"
1486 elif vt_str_begin "$vt_volume_id" "TENS-Public"; then
1487 set vtcompat=1
1488 fi
1489
1490
1491 # auto memdisk mode for some special ISO files
1492 vt_iso_vd_id_parse "${vtoy_iso_part}${vt_chosen_path}"
1493 unset vtMemDiskBoot
1494 if vt_check_mode 0 "$vt_chosen_name"; then
1495 set vtMemDiskBoot=1
1496 else
1497 if [ "$grub_platform" = "pc" ]; then
1498 if vt_iso_vd_id_begin 1 0 "Memtest86+"; then
1499 set vtMemDiskBoot=1
1500 elif vt_iso_vd_id_begin 0 1 "KolibriOS"; then
1501 set vtMemDiskBoot=1
1502 fi
1503 fi
1504
1505 #For iKuai8 (<64MB)
1506 if [ $vt_chosen_size -LE 67108864 ]; then
1507 if vt_str_begin "$vt_chosen_name" "iKuai"; then
1508 set vtMemDiskBoot=1
1509 fi
1510 fi
1511 fi
1512 vt_iso_vd_id_clear
1513
1514
1515 if [ "$grub_platform" = "pc" ]; then
1516 if [ -n "$vtMemDiskBoot" ]; then
1517 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1518 else
1519 legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
1520 fi
1521 else
1522 if [ -n "$vtMemDiskBoot" ]; then
1523 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1524 else
1525 uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
1526 fi
1527 fi
1528
1529 vt_secondary_recover_mode
1530 }
1531
1532 function miso_common_menuentry {
1533 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1534
1535 if vt_check_password "${vt_chosen_path}"; then
1536 return
1537 fi
1538
1539 echo "memdisk mode boot for $vt_chosen_path"
1540 echo ""
1541 ventoy_debug_pause
1542
1543 if [ "$grub_platform" = "pc" ]; then
1544 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1545 else
1546 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1547 fi
1548 }
1549
1550
1551 function common_unsupport_menuentry {
1552 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
1553 echo -e " 文件名中不能有中文或空格 \n"
1554 echo -en "\n$VTLANG_ENTER_EXIT ..."
1555 read vtInputKey
1556 }
1557
1558 function miso_unsupport_menuentry {
1559 common_unsupport_menuentry
1560 }
1561
1562 function iso_unsupport_menuentry {
1563 common_unsupport_menuentry
1564 }
1565
1566 function wim_common_menuentry {
1567 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1568
1569 if vt_check_password "${vt_chosen_path}"; then
1570 return
1571 fi
1572
1573 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1574 return
1575 fi
1576
1577 if vt_wim_check_bootable "${vtoy_iso_part}${vt_chosen_path}"; then
1578 vt_wim_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1579 else
1580 echo -e "\n This is NOT a bootable WIM file. \n"
1581 echo -e " 这不是一个可启动的 WIM 文件。\n"
1582 fi
1583
1584 ventoy_debug_pause
1585
1586 if [ -n "$vtoy_chain_mem_addr" ]; then
1587 if [ "$grub_platform" = "pc" ]; then
1588 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1589 else
1590 ventoy_cli_console
1591 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1592 ventoy_gui_console
1593 fi
1594 boot
1595 else
1596 echo "chain empty failed"
1597 ventoy_pause
1598 fi
1599 }
1600
1601 function wim_unsupport_menuentry {
1602 common_unsupport_menuentry
1603 }
1604
1605 function efi_common_menuentry {
1606 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1607
1608 if vt_check_password "${vt_chosen_path}"; then
1609 return
1610 fi
1611
1612 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1613 return
1614 fi
1615
1616 unset vt_vlnk_dst
1617 if vt_is_vlnk_name "${vt_chosen_path}"; then
1618 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1619 if [ -z "$vt_vlnk_dst" ]; then
1620 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1621 ventoy_pause
1622 return
1623 fi
1624 else
1625 vt_vlnk_dst="${vtoy_iso_part}${vt_chosen_path}"
1626 fi
1627
1628 ventoy_debug_pause
1629
1630 ventoy_cli_console
1631
1632 #first try with chainload
1633 set vtOldRoot=$root
1634 set root=$vtoy_iso_part
1635 chainloader "${vt_vlnk_dst}"
1636 boot
1637
1638 #retry with isoboot
1639 set root=$vtOldRoot
1640 vt_concat_efi_iso "${vt_vlnk_dst}" vtoy_iso_buf
1641 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} dotefi isoefi=on ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
1642 boot
1643
1644 ventoy_gui_console
1645 }
1646
1647 function efi_unsupport_menuentry {
1648 common_unsupport_menuentry
1649 }
1650
1651 function vhdboot_common_func {
1652 vt_patch_vhdboot "$1"
1653
1654 ventoy_debug_pause
1655
1656 if [ -n "$vtoy_vhd_buf_addr" ]; then
1657 if [ "$grub_platform" = "pc" ]; then
1658 ventoy_cli_console
1659 linux16 $vtoy_path/memdisk iso raw
1660 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1661 boot
1662 ventoy_gui_console
1663 else
1664 ventoy_cli_console
1665 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1666 boot
1667 ventoy_gui_console
1668 fi
1669 else
1670 echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
1671 ventoy_pause
1672 fi
1673 }
1674
1675 function vhd_common_menuentry {
1676 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1677
1678 if vt_check_password "${vt_chosen_path}"; then
1679 return
1680 fi
1681
1682 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1683 return
1684 fi
1685
1686 unset vt_vlnk_dst
1687 if vt_is_vlnk_name "${vt_chosen_path}"; then
1688 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1689 if [ -z "$vt_vlnk_dst" ]; then
1690 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1691 ventoy_pause
1692 return
1693 fi
1694 else
1695 vt_vlnk_dst="${vt_chosen_path}"
1696 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
1697 if [ "$vtoy_iso_fs" != "ntfs" ]; then
1698 echo -e "!!! WARNING !!!\n"
1699 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
1700 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
1701 echo -en "\n$VTLANG_ENTER_CONTINUE ..."
1702 read vtInputKey
1703 fi
1704 fi
1705 fi
1706
1707 vhdboot_common_func "${vt_vlnk_dst}"
1708 }
1709
1710 function vhd_unsupport_menuentry {
1711 common_unsupport_menuentry
1712 }
1713
1714 function vtoyboot_common_func {
1715 set AltBootPart=0
1716 set vtoysupport=0
1717
1718 vt_get_vtoy_type "${1}" vtoytype parttype AltBootPart
1719
1720 if vt_str_begin $vtoytype vhd; then
1721 set vtoysupport=1
1722 elif [ "$vtoytype" = "raw" ]; then
1723 set vtoysupport=1
1724 elif [ "$vtoytype" = "vdi" ]; then
1725 set vtoysupport=1
1726 fi
1727
1728 if [ $vtoysupport -eq 1 ]; then
1729 if [ "$grub_platform" = "pc" ]; then
1730 if [ "$parttype" = "gpt" -a $AltBootPart -eq 0 ]; then
1731 echo "The OS in the vdisk was created in UEFI mode, but current is Legacy BIOS mode."
1732 echo "虚拟磁盘内的系统是在UEFI模式下创建的,而当前系统是Legacy BIOS模式,可能无法正常启动。"
1733 ventoy_pause
1734 fi
1735 else
1736 if [ "$parttype" = "mbr" -a $AltBootPart -eq 0 ]; then
1737 echo "The OS in the vdisk was created in Legacy BIOS mode, but current is UEFI mode."
1738 echo "虚拟磁盘内的系统是在Legacy BIOS模式下创建的,而当前系统是UEFI模式,可能无法正常启动。"
1739 ventoy_pause
1740 fi
1741 fi
1742
1743 vt_img_sector "${1}"
1744 vt_raw_chain_data "${1}"
1745
1746 ventoy_debug_pause
1747
1748 if [ -n "$vtoy_chain_mem_addr" ]; then
1749 if [ "$grub_platform" = "pc" ]; then
1750 vt_acpi_param ${vtoy_chain_mem_addr} 512
1751 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} bios80 sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1752 boot
1753 else
1754 if vt_check_secureboot_var; then
1755 vt_acpi_param ${vtoy_chain_mem_addr} 512
1756 fi
1757 ventoy_cli_console
1758 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi sector512 env_param=${ventoy_env_param} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1759 boot
1760 ventoy_gui_console
1761 fi
1762 else
1763 echo "chain empty failed!"
1764 ventoy_pause
1765 fi
1766 else
1767 echo "Unsupported vtoy type $vtoytype"
1768 ventoy_pause
1769 fi
1770 }
1771
1772 function vtoy_common_menuentry {
1773 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1774
1775 if vt_check_password "${vt_chosen_path}"; then
1776 return
1777 fi
1778
1779 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1780 return
1781 fi
1782
1783 unset vt_vlnk_dst
1784 if vt_is_vlnk_name "${vt_chosen_path}"; then
1785 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1786 if [ -z "$vt_vlnk_dst" ]; then
1787 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1788 ventoy_pause
1789 return
1790 fi
1791 else
1792 vt_vlnk_dst="${vtoy_iso_part}${vt_chosen_path}"
1793 fi
1794
1795 vtoyboot_common_func "${vt_vlnk_dst}"
1796 }
1797
1798 function vtoy_unsupport_menuentry {
1799 common_unsupport_menuentry
1800 }
1801
1802 #
1803 #============================================================#
1804 # IMG file boot process #
1805 #============================================================#
1806 #
1807
1808 function only_uefi_tip {
1809 echo -e "\n This IMG file is only supported in UEFI mode. \n"
1810 echo -en "\n$VTLANG_ENTER_EXIT ..."
1811 read vtInputKey
1812 }
1813
1814 function ventoy_img_easyos {
1815 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1816 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1817
1818 loopback easysfs (vtimghd,1)/easy.sfs
1819 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1820
1821 if [ -n "$vt_module_ver" ]; then
1822 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1823 if [ -e (easysfs)/lib/modules/$vt_module_ver/$mod ]; then
1824 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1825 fi
1826 done
1827 fi
1828
1829 ventoy_debug_pause
1830
1831 #boot image file
1832 vt_set_boot_opt rdinit=/vtoy/vtoy
1833 vt_img_hook_root
1834
1835 syslinux_configfile (vtimghd,1)/syslinux.cfg
1836
1837 vt_img_unhook_root
1838 vt_unset_boot_opt
1839 loopback -d easysfs
1840 }
1841
1842 function ventoy_img_easyos2 {
1843 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1844 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1845
1846 if [ -e (vtimghd,2)/easyos/easy.sfs ]; then
1847 loopback easysfs (vtimghd,2)/easyos/easy.sfs
1848 elif [ -d (vtimghd,2)/easyos/releases ]; then
1849 vt_fs_enum_1st_dir (vtimghd,2) /easyos/releases/ vt_dir_name
1850 loopback easysfs (vtimghd,2)/easyos/releases/$vt_dir_name/easy.sfs
1851 fi
1852
1853 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1854
1855 if [ -n "$vt_module_ver" ]; then
1856 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1857 if [ -e (easysfs)/lib/modules/$vt_module_ver/$mod ]; then
1858 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1859 fi
1860 done
1861 fi
1862
1863 ventoy_debug_pause
1864
1865 #boot image file
1866 vt_set_boot_opt rdinit=/vtoy/vtoy
1867 vt_img_hook_root
1868
1869 vt_limine_menu (vtimghd,1)/limine.cfg vt_sys_menu_mem
1870 configfile "mem:${vt_sys_menu_mem_addr}:size:${vt_sys_menu_mem_size}"
1871
1872 vt_img_unhook_root
1873 vt_unset_boot_opt
1874 loopback -d easysfs
1875 }
1876
1877 function ventoy_img_volumio {
1878 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1879 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1880
1881 ventoy_debug_pause
1882
1883 #boot image file
1884 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1885 vt_img_hook_root
1886
1887 syslinux_configfile (vtimghd,1)/syslinux.cfg
1888
1889 vt_img_unhook_root
1890 vt_unset_boot_opt
1891 }
1892
1893 function ventoy_img_openelec {
1894 elec_ver=$1
1895
1896 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1897 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1898
1899 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1900 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1901
1902 if [ "$elec_ver" = "LibreELEC" ]; then
1903 if [ -f (vtimghd,1)/system ]; then
1904 loopback elecsfs (vtimghd,1)/system
1905 vt_get_lib_module_ver (elecsfs) /usr/lib/kernel-overlays/base/lib/modules/ vt_module_ver
1906 if [ -n "$vt_module_ver" ]; then
1907 for mod in "kernel/drivers/md/dm-mod.ko"; do
1908 if [ -e (elecsfs)/usr/lib/kernel-overlays/base/lib/modules/$vt_module_ver/$mod ]; then
1909 vt_img_extra_initrd_append (elecsfs)/usr/lib/kernel-overlays/base/lib/modules/$vt_module_ver/$mod
1910 fi
1911 done
1912 fi
1913 fi
1914 fi
1915
1916 ventoy_debug_pause
1917
1918 #boot image file
1919 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1920 vt_img_hook_root
1921
1922 set root=(vtimghd,1)
1923 syslinux_configfile (vtimghd,1)/syslinux.cfg
1924
1925 vt_img_unhook_root
1926 vt_unset_boot_opt
1927 loopback -d vtloopex
1928 loopback -d elecsfs
1929 }
1930
1931
1932 function ventoy_img_freedombox {
1933 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1934 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1935
1936 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1937 if [ -n "$vt_module_ver" ]; then
1938 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1939 fi
1940
1941 ventoy_debug_pause
1942
1943 #boot image file
1944 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1945 vt_img_hook_root
1946
1947 configfile (vtimghd,1)/boot/grub/grub.cfg
1948
1949 vt_img_unhook_root
1950 vt_unset_boot_opt
1951 }
1952
1953 function ventoy_img_paldo {
1954 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1955 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1956
1957 ventoy_debug_pause
1958
1959 #boot image file
1960 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1961 vt_img_hook_root
1962
1963 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1964 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1965
1966 echo loading file...
1967 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1968 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1969 boot
1970
1971 vt_img_unhook_root
1972 vt_unset_boot_opt
1973 }
1974
1975 function ventoy_img_ubos {
1976 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1977 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1978
1979 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1980 if [ -n "$vt_module_ver" ]; then
1981 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1982 fi
1983
1984 ventoy_debug_pause
1985
1986 #boot image file
1987 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1988 vt_img_hook_root
1989
1990 echo loading file...
1991 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1992 initrd (vtimghd,2)/initramfs-linux.img
1993 boot
1994
1995 vt_img_unhook_root
1996 vt_unset_boot_opt
1997 }
1998
1999 function ventoy_img_recalbox {
2000 if [ $vtoy_img_max_part_end -GT $vt_chosen_size ]; then
2001 echo -e "\nPlease extend the img file size before boot it. \n"
2002 ventoy_pause
2003 return
2004 fi
2005
2006 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2007 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2008
2009 if [ -e (vtimghd,1)/boot/recalbox ]; then
2010 loopback recalbox (vtimghd,1)/boot/recalbox
2011 vt_get_lib_module_ver (recalbox) /lib/modules/ vt_module_ver
2012 if [ -n "$vt_module_ver" ]; then
2013 vt_img_extra_initrd_append (recalbox)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
2014 fi
2015 fi
2016
2017 ventoy_debug_pause
2018
2019 #boot image file
2020 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
2021 vt_img_hook_root
2022
2023 set root=(vtimghd,1)
2024 configfile (vtimghd,1)/boot/grub/grub.cfg
2025
2026 vt_img_unhook_root
2027 vt_unset_boot_opt
2028 }
2029
2030 function ventoy_img_esysrescue {
2031 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2032 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2033
2034 ventoy_debug_pause
2035
2036 #boot image file
2037 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=esysrescue
2038 vt_img_hook_root
2039
2040 set root=(vtimghd,1)
2041 configfile (vtimghd,1)/boot/grub/grub.cfg
2042
2043 vt_img_unhook_root
2044 vt_unset_boot_opt
2045 }
2046
2047 function ventoy_img_batocera {
2048 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2049 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2050
2051 ventoy_debug_pause
2052
2053 #boot image file
2054 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
2055 vt_img_hook_root
2056
2057 set root=(vtimghd,1)
2058 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
2059
2060 vt_img_unhook_root
2061 vt_unset_boot_opt
2062 }
2063
2064 function ventoy_img_openwrt {
2065 if [ -e (vtimghd,2)/lib64 ]; then
2066 set ventoy_busybox_ver=64
2067 fi
2068
2069 vt_fs_enum_1st_dir (vtimghd,2) /lib/modules/ vt_dir_name
2070
2071 if [ -f (vtimghd,2)/lib/modules/$vt_dir_name/dm-mod.ko ]; then
2072 set openwrt_plugin_need=0
2073 vt_img_extra_initrd_append (vtimghd,2)/lib/modules/$vt_dir_name/dm-mod.ko
2074 if [ -f (vtimghd,2)/lib/modules/$vt_dir_name/dax.ko ]; then
2075 vt_img_extra_initrd_append (vtimghd,2)/lib/modules/$vt_dir_name/dax.ko
2076 fi
2077 else
2078 set openwrt_plugin_need=1
2079 if [ ! -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
2080 ventoy_gui_console
2081 echo -e "\n ventoy_openwrt.xz not found. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
2082 echo -e " 未找到 ventoy_openwrt.xz 文件。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
2083 echo -en "\n$VTLANG_ENTER_EXIT ..."
2084 read vtInputKey
2085 ventoy_cli_console
2086 return
2087 fi
2088 fi
2089
2090 if vt_img_check_range "${vtoy_iso_part}${vt_chosen_path}"; then
2091 ventoy_debug_pause
2092 else
2093 ventoy_gui_console
2094 echo -e "\n IMG file need processed. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
2095 echo -e " 此 IMG 文件必须处理之后才能支持。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
2096 echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
2097 read vtInputKey
2098 ventoy_cli_console
2099 return
2100 fi
2101
2102 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2103 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2104
2105 if [ $openwrt_plugin_need -eq 1 ]; then
2106 if [ -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
2107 vt_img_extra_initrd_append ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz
2108 fi
2109 fi
2110
2111 #boot image file
2112 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=openwrt
2113 vt_img_hook_root
2114
2115 set root=(vtimghd,1)
2116 configfile (vtimghd,1)/boot/grub/grub.cfg
2117
2118 vt_img_unhook_root
2119 vt_unset_boot_opt
2120 }
2121
2122 function ventoy_img_tails {
2123 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2124 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2125
2126 ventoy_debug_pause
2127
2128 #boot image file
2129 vt_set_boot_opt rdinit=/vtoy/vtoy live-media=/dev/dm-1 ventoyos=tails
2130 vt_img_hook_root
2131
2132 set root=(vtimghd,1)
2133 configfile (vtimghd,1)/efi/debian/grub.cfg
2134
2135 vt_img_unhook_root
2136 vt_unset_boot_opt
2137 }
2138
2139 function ventoy_img_fydeos {
2140 if [ "$grub_platform" = "pc" ]; then
2141 only_uefi_tip
2142 return
2143 fi
2144
2145 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=64"
2146 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2147
2148 ventoy_debug_pause
2149
2150 #boot image file
2151 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=fydeos
2152 vt_img_hook_root
2153
2154 set grubdisk=vtimghd
2155 set grubpartA=(vtimghd,3)
2156 set grubpartB=(vtimghd,5)
2157 set linuxpartA=(sda,3)
2158 set linuxpartB=(sda,5)
2159
2160 set root=(vtimghd,12)
2161 configfile (vtimghd,12)/efi/boot/grub.cfg
2162
2163 vt_img_unhook_root
2164 vt_unset_boot_opt
2165
2166 unset grubdisk
2167 unset grubpartA
2168 unset grubpartB
2169 unset linuxpartA
2170 unset linuxpartB
2171 }
2172
2173 function ventoy_img_cloudready {
2174 if [ "$grub_platform" = "pc" ]; then
2175 only_uefi_tip
2176 return
2177 fi
2178
2179 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=64"
2180 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2181
2182 ventoy_debug_pause
2183
2184 #boot image file
2185 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=cloudready
2186 vt_img_hook_root
2187
2188 set grubdisk=vtimghd
2189 set grubpartA=(vtimghd,3)
2190 set grubpartB=(vtimghd,5)
2191 set linuxpartA=(sda,3)
2192 set linuxpartB=(sda,5)
2193
2194 set root=(vtimghd,12)
2195 configfile (vtimghd,12)/efi/boot/grub.cfg
2196
2197 vt_img_unhook_root
2198 vt_unset_boot_opt
2199
2200 unset grubdisk
2201 unset grubpartA
2202 unset grubpartB
2203 unset linuxpartA
2204 unset linuxpartB
2205 }
2206
2207
2208 function ventoy_img_fwts {
2209 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
2210 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2211
2212 ventoy_debug_pause
2213
2214 #boot image file
2215 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=fwts
2216 vt_img_hook_root
2217
2218 configfile $prefix/distro/fwts.cfg
2219
2220 vt_img_unhook_root
2221 vt_unset_boot_opt
2222 }
2223
2224 function ventoy_img_memtest86 {
2225 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
2226 boot
2227 }
2228
2229 function img_unsupport_tip {
2230 echo -e "\n This IMG file is NOT supported now. \n"
2231 echo -e " 当前不支持启动此 IMG 文件 \n"
2232 echo -en "\n$VTLANG_ENTER_EXIT ..."
2233 read vtInputKey
2234 }
2235
2236 function legacy_img_memdisk {
2237 linux16 $vtoy_path/memdisk
2238 echo "Loading img file to memory ..."
2239 initrd16 "${1}${2}"
2240
2241 ventoy_cli_console
2242 boot
2243 }
2244
2245 function img_common_menuentry {
2246 set ventoy_compatible=YES
2247 set ventoy_busybox_ver=32
2248 unset LoadIsoEfiDriver
2249
2250 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
2251
2252 if vt_check_password "${vt_chosen_path}"; then
2253 return
2254 fi
2255
2256 if ventoy_vcfg_proc "${vt_chosen_path}"; then
2257 return
2258 fi
2259
2260 if [ "$grub_platform" = "pc" ]; then
2261 if vt_check_mode 0 "$vt_chosen_name"; then
2262 legacy_img_memdisk $vtoy_iso_part "$vt_chosen_path"
2263 return
2264 fi
2265 fi
2266
2267 loopback vtimghd "${vtoy_iso_part}${vt_chosen_path}"
2268 vt_img_sector "${vtoy_iso_part}${vt_chosen_path}"
2269
2270 vt_img_part_info (vtimghd)
2271
2272 set vtback_root=$root
2273 ventoy_cli_console
2274 vt_push_last_entry
2275 set vtback_theme=$theme
2276 unset theme
2277
2278 vt_img_extra_initrd_reset
2279
2280
2281 vt_get_fs_label (vtimghd,1) vtImgHd1Label
2282
2283 if [ "$vtImgHd1Label" = "STATE" ]; then
2284 vt_get_fs_label (vtimghd,3) vtImgHd3Label
2285 elif [ -d (vtimghd,2)/lib ]; then
2286 vt_get_fs_label (vtimghd,2) vtImgHd2Label
2287 fi
2288
2289 if [ -z "$vtImgHd1Label" ]; then
2290 if [ -d (vtimghd,2)/efi ]; then
2291 vt_get_fs_label (vtimghd,3) vtImgHd3Label
2292 elif [ -d (vtimghd,12)/efi ]; then
2293 vt_get_fs_label (vtimghd,3) vtImgHd3Label
2294 fi
2295 fi
2296
2297 if [ -e (vtimghd,1)/etc/hostname ]; then
2298 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
2299 fi
2300
2301 if vt_str_begin "$vtImgHd3Label" "ROOT-"; then
2302 if [ -f (vtimghd,3)/etc/os-release.d/ID ]; then
2303 vt_1st_line (vtimghd,3)/etc/os-release.d/ID vt_release_line1
2304 if vt_str_begin "$vt_release_line1" "FydeOS"; then
2305 ventoy_img_fydeos
2306 else
2307 ventoy_img_cloudready
2308 fi
2309 elif [ -f (vtimghd,3)/etc/cloudready-release ]; then
2310 ventoy_img_cloudready
2311 elif [ -f (vtimghd,3)/etc/chrome_dev.conf ]; then
2312 ventoy_img_cloudready
2313 fi
2314 elif vt_str_begin "$vtImgHd3Label" "fwts-result"; then
2315 ventoy_img_fwts
2316 elif vt_str_begin "$vtImgHd1Label" "LAKKA"; then
2317 ventoy_img_openelec lakka
2318 elif vt_str_begin "$vtImgHd1Label" "LIBREELEC"; then
2319 ventoy_img_openelec LibreELEC
2320 elif vt_str_begin "$vtImgHd1Label" "paldo-live"; then
2321 ventoy_img_paldo
2322 elif vt_str_begin "$vtImgHostname" "freedombox"; then
2323 ventoy_img_freedombox
2324 elif vt_str_begin "$vtImgHd1Label" "BATOCERA"; then
2325 ventoy_img_batocera
2326 elif vt_str_begin "$vtImgHd1Label" "Tails"; then
2327 ventoy_img_tails
2328 elif [ "$vtImgHd2Label" = "RECALBOX" -o "$vtImgHd1Label" = "RECALBOX" ]; then
2329 ventoy_img_recalbox
2330 elif [ "$vtImgHd1Label" = "ESYSRESCUE" ]; then
2331 ventoy_img_esysrescue
2332 elif [ -e (vtimghd,1)/easy.sfs ]; then
2333 ventoy_img_easyos
2334 elif [ -d (vtimghd,2)/easyos ]; then
2335 ventoy_img_easyos2
2336 elif [ -e (vtimghd,1)/volumio.initrd ]; then
2337 ventoy_img_volumio
2338 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
2339 ventoy_img_ubos
2340 elif [ -f (vtimghd,2)/etc/openwrt_version ]; then
2341 ventoy_img_openwrt
2342 else
2343 if [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
2344 if [ "$grub_platform" = "pc" ]; then
2345 img_unsupport_tip
2346 fi
2347 fi
2348
2349 #common chain
2350 vt_linux_chain_data "${vtoy_iso_part}${vt_chosen_path}"
2351 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
2352 if [ "$grub_platform" = "pc" ]; then
2353 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
2354 boot
2355 else
2356 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi sector512 env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
2357 boot
2358 fi
2359 fi
2360
2361 loopback -d vtimghd
2362
2363 set root=$vtback_root
2364 vt_pop_last_entry
2365 set theme=$vtback_theme
2366 ventoy_gui_console
2367 set ventoy_compatible=NO
2368 }
2369
2370 function img_unsupport_menuentry {
2371 common_unsupport_menuentry
2372 }
2373
2374 function mimg_common_menuentry {
2375 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
2376
2377 if vt_check_password "${vt_chosen_path}"; then
2378 return
2379 fi
2380
2381 echo "memdisk mode boot for $vt_chosen_path"
2382 echo ""
2383 ventoy_debug_pause
2384
2385 if [ "$grub_platform" = "pc" ]; then
2386 legacy_img_memdisk $vtoy_iso_part "$vt_chosen_path"
2387 else
2388 vt_load_img_memdisk "$vtoy_iso_part$vt_chosen_path" vtoy_img_buf
2389 ventoy_cli_console
2390 chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_img_buf_addr}:size:${vtoy_img_buf_size}
2391 boot
2392 ventoy_gui_console
2393 fi
2394 }
2395
2396 #############################################################
2397 #############################################################
2398 #############################################################
2399 ####### Main Process ###########
2400 #############################################################
2401 #############################################################
2402 #############################################################
2403
2404 set VENTOY_VERSION="1.0.99"
2405
2406 #ACPI not compatible with Window7/8, so disable by default
2407 set VTOY_PARAM_NO_ACPI=1
2408
2409 # Default menu display mode, you can change it as you want.
2410 # 0: List mode
2411 # 1: TreeView mode
2412 set VTOY_DEFAULT_MENU_MODE=0
2413
2414 set VTOY_MEM_DISK_STR="[Memdisk]"
2415 set VTOY_ISO_RAW_STR="Compatible Mode"
2416 set VTOY_GRUB2_MODE_STR="GRUB2 Mode"
2417 set VTOY_WIMBOOT_MODE_STR="WIMBOOT Mode"
2418 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
2419
2420 set VTOY_F2_CMD="vt_browser_disk"
2421 set VTOY_F4_CMD="ventoy_localboot"
2422 set VTOY_F5_CMD="ventoy_diagnosis"
2423 set VTOY_F6_CMD="ventoy_ext_menu"
2424 set VTOY_HELP_CMD="ventoy_show_help"
2425 set VTOY_CHKSUM_CMD="ventoy_checksum"
2426 set VTOY_HELP_TXT_LANGUAGE="en_US"
2427 set VTOY_CHKSUM_FILE_PATH="X"
2428 set VTOY_LANG_CMD="ventoy_language"
2429
2430
2431 if [ "$grub_platform" = "pc" ]; then
2432 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
2433 else
2434 if [ "$grub_cpu" = "i386" ]; then
2435 set VTOY_EFI_ARCH=ia32
2436 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION IA32 www.ventoy.net"
2437 elif [ "$grub_cpu" = "arm64" ]; then
2438 set VTOY_EFI_ARCH=aa64
2439 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION AA64 www.ventoy.net"
2440 elif [ "$grub_cpu" = "mips64el" ]; then
2441 set VTOY_EFI_ARCH=mips
2442 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION MIPS www.ventoy.net"
2443 else
2444 set VTOY_EFI_ARCH=x64
2445 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
2446 fi
2447 fi
2448
2449 vt_device $root vtoy_dev
2450
2451 if [ "$vtoy_dev" = "tftp" ]; then
2452 set vtoy_path=($root)
2453 for vtid in 0 1 2 3; do
2454 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
2455 set vtoy_iso_part=(hd$vtid,1)
2456 set vtoy_efi_part=(hd$vtid,2)
2457 set vtoydev=hd$vtid
2458 break
2459 fi
2460 done
2461 loadfont ascii
2462
2463 if [ -n "$vtoy_efi_part" ]; then
2464 vt_load_file_to_mem "auto" $vtoy_efi_part/grub/fonts/unicode.pf2 vtoy_font_mem
2465 loadfont mem:${vtoy_font_mem_addr}:size:${vtoy_font_mem_size}
2466 fi
2467
2468 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
2469 set vt_plugin_path=$vtoy_iso_part
2470 else
2471 set vt_plugin_path=$prefix
2472 vt_load_plugin $vt_plugin_path
2473 fi
2474 else
2475 if [ "$prefix" = "(ventoydisk)/grub" ]; then
2476 set vtoy_path=(ventoydisk)/ventoy
2477 else
2478 set vtoy_path=($root)/ventoy
2479 fi
2480
2481 set vtoydev=$vtoy_dev
2482 set vtoy_iso_part=($vtoy_dev,1)
2483 set vtoy_efi_part=($vtoy_dev,2)
2484
2485 vt_load_file_to_mem "auto" $prefix/fonts/unicode.pf2 vtoy_font_mem
2486 loadfont mem:${vtoy_font_mem_addr}:size:${vtoy_font_mem_size}
2487
2488 set vt_plugin_path=$vtoy_iso_part
2489 fi
2490
2491 #Load Partition Table
2492 vt_load_part_table $vtoydev
2493
2494 #Load menu lang file
2495 ventoy_load_menu_lang_file
2496
2497 #Load Plugin
2498 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
2499 clear
2500 vt_load_plugin $vtoy_iso_part
2501 clear
2502 else
2503 vt_check_json_path_case $vtoy_iso_part
2504 fi
2505
2506 if [ -n "$VTOY_MENU_LANGUAGE" ]; then
2507 vt_init_menu_lang "$VTOY_MENU_LANGUAGE"
2508 else
2509 vt_init_menu_lang en_US
2510 fi
2511
2512 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
2513 set timeout=$VTOY_MENU_TIMEOUT
2514 else
2515 unset timeout
2516 fi
2517
2518 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
2519 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
2520 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
2521 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
2522 fi
2523
2524 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
2525 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
2526 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
2527 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
2528 fi
2529
2530
2531 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
2532 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
2533 else
2534 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
2535 fi
2536
2537 terminal_output console
2538
2539 if [ -n "$vtoy_gfxmode" ]; then
2540 set gfxmode=$vtoy_gfxmode
2541 set gfxpayload=keep
2542 else
2543 set gfxmode=1024x768
2544 set gfxpayload=keep
2545 fi
2546
2547
2548 if [ "$vtoy_display_mode" = "CLI" ]; then
2549 terminal_output console
2550 elif [ "$vtoy_display_mode" = "serial" ]; then
2551 if [ -n "$vtoy_serial_param" ]; then
2552 serial $vtoy_serial_param
2553 fi
2554 terminal_input serial
2555 terminal_output serial
2556 elif [ "$vtoy_display_mode" = "serial_console" ]; then
2557 if [ -n "$vtoy_serial_param" ]; then
2558 serial $vtoy_serial_param
2559 fi
2560 terminal_input serial console
2561 terminal_output serial console
2562 else
2563 if [ "$vtoy_gfxmode" = "max" ]; then
2564 set gfxmode=1024x768
2565 terminal_output gfxterm
2566
2567 vt_enum_video_mode
2568 vt_get_video_mode 0 vtCurMode
2569 terminal_output console
2570 set gfxmode=$vtCurMode
2571 terminal_output gfxterm
2572 elif [ "$vtoy_res_fit" = "1" ]; then
2573 terminal_output gfxterm
2574 fi
2575
2576 if [ -n "$vtoy_theme" ]; then
2577 vt_set_theme
2578 else
2579 set theme=$prefix/themes/ventoy/theme.txt
2580 fi
2581 terminal_output gfxterm
2582 fi
2583
2584 if [ "$grub_platform" = "efi" ]; then
2585 set mouse_delta=4000
2586 # terminal_input --append mouse
2587 fi
2588
2589 if [ -n "$VTOY_DEFAULT_KBD_LAYOUT" ]; then
2590 set_keyboard_layout "$VTOY_DEFAULT_KBD_LAYOUT"
2591 fi
2592
2593 if [ -n "$VTOY_PLUGIN_PATH_CASE_MISMATCH" ]; then
2594 clear
2595 echo "$VTOY_PLUGIN_PATH_CASE_MISMATCH"
2596 echo -e "\n\nPath case does not match! ventoy directory and ventoy.json MUST be all lowercase!"
2597 echo -e "\n路径大小写不匹配!ventoy 目录和 ventoy.json 文件的名字必须是全部小写,请修正!"
2598 echo -e "\n\npress ENTER to continue (请按回车键继续) ..."
2599 read vtInputKey
2600 fi
2601
2602 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
2603 clear
2604 if [ -n "$VTOY_PLUGIN_ENCODE_ERROR" ]; then
2605 echo -e "\n Encoding type for ventoy.json is not supported, please convert to UTF-8.\n"
2606 echo -e " ventoy.json 文件编码格式不支持,请转换为 UTF-8 编码格式!\n"
2607 else
2608 echo -e "\n Syntax error detected in ventoy.json, please check! \n"
2609 echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
2610 fi
2611
2612 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
2613 read vtInputKey
2614 fi
2615
2616
2617 for vtTFile in ventoy.json ventoy_grub.cfg; do
2618 if [ -f $vtoy_efi_part/ventoy/$vtTFile ]; then
2619 clear
2620 echo -e "\n You need to put $vtTFile in the 1st partition which hold the ISO files.\n"
2621 echo -e " $vtTFile 放错分区了,请放到镜像分区里的 ventoy 目录下(此目录需要手动创建)!\n"
2622 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
2623 read vtInputKey
2624 fi
2625 done
2626
2627 #clear all input key before show main menu
2628 vt_clear_key
2629
2630 #export necessary variable
2631 export theme
2632 export gfxmode
2633 export gfxpayload
2634 export vtoydev
2635 export vtoy_path
2636 export vtdebug_flag
2637 export vtoy_iso_fs
2638 export vtoy_iso_part
2639 export vtoy_efi_part
2640 export VENTOY_VERSION
2641 export VTOY_CUR_VIDEO_MODE
2642 export VTOY_EFI_ARCH
2643 export VTOY_MEM_DISK_STR
2644 export VTOY_ISO_RAW_STR
2645 export VTOY_GRUB2_MODE_STR
2646 export VTOY_WIMBOOT_MODE_STR
2647 export VTOY_ISO_UEFI_DRV_STR
2648 export VTOY_F2_CMD
2649 export VTOY_F4_CMD
2650 export VTOY_F5_CMD
2651 export VTOY_F6_CMD
2652 export VTOY_HELP_CMD
2653 export VTOY_CHKSUM_CMD
2654 export VTOY_HELP_TXT_LANGUAGE
2655 export VTOY_CHKSUM_FILE_PATH
2656 export VTOY_LANG_CMD
2657
2658
2659 #colect all image files (iso files)
2660 set ventoy_img_count=0
2661 vt_list_img $vtoy_iso_part ventoy_img_count
2662
2663 #Main menu
2664 if [ $ventoy_img_count -gt 0 ]; then
2665 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
2666 vt_dynamic_menu 0 0
2667 else
2668 vt_dynamic_menu 0 1
2669 fi
2670 else
2671 if [ -n "$VTOY_NO_ISO_TIP" ]; then
2672 NO_ISO_MENU="No ISO or supported IMG files found, $VTOY_NO_ISO_TIP"
2673 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
2674 NO_ISO_MENU="No ISO or supported IMG files found, please check VTOY_DEFAULT_SEARCH_ROOT"
2675 else
2676 NO_ISO_MENU="No ISO or supported IMG files found"
2677 fi
2678 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
2679 echo -e "\n Rebooting ... "
2680 reboot
2681 }
2682 fi
2683
2684
2685 #special VTOY_DEFAULT_IMAGE process
2686 if [ -n "$VTOY_DEFAULT_IMAGE" ]; then
2687 if regexp --set 1:vtHotkey --set 2:vtDefault "(F[2-9])>(.*)" "$VTOY_DEFAULT_IMAGE"; then
2688
2689 set default="$vtDefault"
2690 if [ -z "$VTOY_MENU_TIMEOUT" ]; then
2691 set timeout=0
2692 else
2693 set timeout=$VTOY_MENU_TIMEOUT
2694 fi
2695
2696 export timeout
2697 export default
2698
2699 vt_fn_mutex_lock 1
2700
2701 if [ "$vtHotkey" = "F2" ]; then
2702 unset timeout
2703 vt_browser_disk
2704 elif [ "$vtHotkey" = "F4" ]; then
2705 ventoy_localboot
2706 elif [ "$vtHotkey" = "F5" ]; then
2707 ventoy_diagnosis
2708 elif [ "$vtHotkey" = "F6" ]; then
2709 ventoy_ext_menu
2710 fi
2711
2712 vt_fn_mutex_lock 0
2713
2714 unset timeout
2715 unset default
2716 fi
2717 fi
2718