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