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