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