]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
wimboot mode support Bob.Ombs.Modified.Win10PEx64 (#1842)
[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 if vt_check_mode 4 "$vt_chosen_name"; then
603 vt_windows_chain_data "${1}${chosen_path}"
604 ventoy_debug_pause
605 vtoy_wimboot_func
606 else
607 if [ "$ventoy_compatible" = "NO" ]; then
608
609 if [ "$ventoy_fs_probe" = "iso9660" ]; then
610 loopback -d loop
611 vt_iso9660_nojoliet 1
612 loopback loop "$1$2"
613 fi
614
615 for file in "efi/microsoft/boot/bcd"; do
616 vt_windows_collect_wim_patch bcd (loop)/$file
617 done
618
619 vt_windows_count_wim_patch vt_wim_cnt
620 if [ $vt_wim_cnt -eq 0 ]; then
621 distro_specify_wim_patch_phase2
622 fi
623
624 ventoy_debug_pause
625 locate_wim "${chosen_path}"
626 fi
627 vt_windows_chain_data "${1}${chosen_path}"
628 ventoy_debug_pause
629 fi
630
631 if [ -n "$vtoy_chain_mem_addr" ]; then
632 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
633 ventoy_cli_console
634 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}
635 boot
636 else
637 echo "chain empty failed"
638 ventoy_pause
639 fi
640 }
641
642 function uefi_find_replace_initrd {
643 if vt_get_efi_vdisk_offset "${1}${2}" vt_efivdisk_offset; then
644 loopback -s $vt_efivdisk_offset vtefivdisk "${1}${2}"
645
646 unset vt_rp_initrd
647 vt_search_replace_initrd (vtefivdisk) vt_rp_initrd
648
649 if [ -n "$vt_rp_initrd" ]; then
650 vt_add_replace_file $3 "$vt_rp_initrd"
651 fi
652
653 loopback -d vtefivdisk
654 ventoy_debug_pause
655 fi
656 }
657
658 function uefi_linux_menu_func {
659
660 if [ "$ventoy_compatible" = "NO" ]; then
661
662 if [ "$ventoy_fs_probe" = "udf" ]; then
663 loopback -d loop
664 set ventoy_fs_probe=iso9660
665 loopback loop "$1$2"
666 fi
667
668 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
669
670 vt_linux_clear_initrd
671
672 if [ -d (loop)/pmagic ]; then
673 vt_linux_specify_initrd_file /pmagic/initrd.img
674 else
675 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
676 if [ -e (loop)/$file ]; then
677 vt_linux_parse_initrd_grub file (loop)/$file
678 fi
679 done
680 fi
681
682 # special process for special distros
683 if [ -d (loop)/loader/entries ]; then
684 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
685 elif [ -d (loop)/boot/grub ]; then
686 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
687 fi
688
689 distro_specify_initrd_file
690
691 vt_linux_initrd_count vtcount
692
693 if [ $vtcount -eq 0 ]; then
694 if [ -e (loop)/EFI/boot/livegrub.cfg ]; then
695 vt_linux_parse_initrd_grub file (loop)/EFI/boot/livegrub.cfg
696 fi
697 distro_specify_initrd_file_phase2
698
699 if [ "$vt_efi_dir" = "NO" ]; then
700 if [ -f (loop)/efi.img ]; then
701 vt_add_replace_file 0 "initrd"
702 fi
703 fi
704 fi
705
706 locate_initrd
707
708 if [ -d (loop)/loader/entries ]; then
709 vt_linux_get_main_initrd_index vtindex
710
711 if [ -d (loop)/arch ]; then
712 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
713 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
714 elif [ -f (loop)/arch/boot/x86_64/initramfs-linux.img ]; then
715 vt_add_replace_file $vtindex "arch\\boot\\x86_64\\initramfs-linux.img"
716 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
717 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
718 fi
719 elif [ -d (loop)/blackarch ]; then
720 if [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
721 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
722 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
723 vt_add_replace_file $vtindex "blackarch\\boot\\x86_64\\initramfs-linux.img"
724 fi
725 elif [ -d (loop)/anarchy ]; then
726 if [ -f (loop)/anarchy/boot/x86_64/initramfs-linux.img ]; then
727 vt_add_replace_file $vtindex "anarchy\\boot\\x86_64\\initramfs-linux.img"
728 fi
729 elif [ -d (loop)/parabola ]; then
730 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
731 vt_add_replace_file $vtindex "EFI\\parabolaiso\\parabolaiso.img"
732 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
733 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
734 fi
735 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
736 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
737 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
738 vt_add_replace_file $vtindex "boot\\initrd"
739 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
740 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
741 fi
742
743 vt_get_replace_file_cnt vt_replace_cnt
744 if [ $vt_replace_cnt -eq 0 ]; then
745 uefi_find_replace_initrd "$1" "$2" $vtindex
746 fi
747 elif [ -d (loop)/EFI/boot/entries ]; then
748 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
749 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
750 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
751 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
752 fi
753 elif [ -d (loop)/EFI/BOOT/entries ]; then
754 vt_linux_get_main_initrd_index vtindex
755
756 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
757 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
758 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
759 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
760 fi
761 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
762 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
763 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
764
765 elif vt_str_begin "$vt_volume_id" "SolusLive"; then
766 vt_add_replace_file 0 "initrd"
767
768 fi
769
770 fi
771
772 vt_linux_chain_data "${1}${chosen_path}"
773
774 if [ -n "$LoadIsoEfiDriver" -a $vt_chosen_size -LT 104857600 ]; then
775 if [ -f (loop)/efi/clover/cloverx64.efi ]; then
776 unset LoadIsoEfiDriver
777 fi
778 fi
779
780 if [ -n "$vtoy_chain_mem_addr" ]; then
781 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
782 ventoy_cli_console
783
784 unset vtGrub2Mode
785 if vt_check_mode 3 "$vt_chosen_name"; then
786 set vtGrub2Mode=1
787 elif vt_str_begin "$vt_volume_id" "KRD"; then
788 if [ -f (loop)/boot/grub/grub.cfg.sig ]; then
789 set vtGrub2Mode=1
790 fi
791 fi
792
793 if [ -n "$vtGrub2Mode" ]; then
794 ventoy_debug_pause
795 else
796 if [ "$VTOY_EFI_ARCH" != "mips" ]; then
797 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}
798 boot
799 fi
800 fi
801
802 # fallback
803 set vtback_root=$root
804 vt_push_last_entry
805 set vtback_theme=$theme
806 unset theme
807
808 vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
809 vt_set_boot_opt rdinit=/vtoy/vtoy
810
811 set root=(loop)
812 set vtback_cfg_find=0
813 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
814 if [ -e "$cfg" ]; then
815 set vtback_cfg_find=1
816 configfile "$cfg"
817 break
818 fi
819 done
820
821 if [ "$vtback_cfg_find" = "0" ]; then
822 echo " "
823 echo "No bootfile found for UEFI!"
824 echo "Maybe the image does not support $VTOY_EFI_ARCH UEFI"
825 echo " "
826 sleep 30
827 fi
828
829 vt_unset_boot_opt
830 set root=$vtback_root
831 set theme=$vtback_theme
832 vt_pop_last_entry
833 ventoy_gui_console
834 else
835 echo "chain empty failed"
836 ventoy_pause
837 fi
838 }
839
840 function uefi_unix_menu_func {
841 ventoy_unix_comm_proc $1 "${chosen_path}"
842
843 if [ -n "$vtoy_chain_mem_addr" ]; then
844 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
845 ventoy_cli_console
846 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}
847 boot
848 else
849 echo "chain empty failed"
850 ventoy_pause
851 fi
852 }
853
854 function ventoy_reset_nojoliet {
855 if vt_str_begin "$vt_volume_id" "ARCARESCUE"; then
856 vt_iso9660_nojoliet 1
857 else
858 vt_iso9660_nojoliet 0
859 fi
860
861 vt_append_extra_sector 0
862 }
863
864 function uefi_iso_menu_func {
865
866 if [ -d (loop)/ ]; then
867 loopback -d loop
868 fi
869
870 if [ -n "$vtisouefi" ]; then
871 set LoadIsoEfiDriver=on
872 unset vtisouefi
873 elif vt_check_mode 2 "$vt_chosen_name"; then
874 set LoadIsoEfiDriver=on
875 else
876 unset LoadIsoEfiDriver
877 fi
878
879 set chosen_path="$2"
880 vt_select_auto_install "${chosen_path}"
881 vt_select_persistence "${chosen_path}"
882
883 if vt_is_udf "${1}${chosen_path}"; then
884 set ventoy_fs_probe=udf
885 else
886 set ventoy_fs_probe=iso9660
887 ventoy_reset_nojoliet
888
889 # Lenovo EasyStartup need an addional sector for boundary check
890 if vt_str_begin "$vt_volume_id" "EasyStartup"; then
891 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
892 vt_append_extra_sector 1
893 fi
894 fi
895
896 loopback loop "${1}${chosen_path}"
897 get_os_type (loop)
898
899 if [ -d (loop)/EFI ]; then
900 set vt_efi_dir=YES
901 elif [ -d (loop)/efi ]; then
902 set vt_efi_dir=YES
903 else
904 set vt_efi_dir=NO
905 fi
906
907 if [ -n "$vtcompat" ]; then
908 set ventoy_compatible=YES
909 unset vtcompat
910 elif vt_check_mode 1 "$vt_chosen_name"; then
911 set ventoy_compatible=YES
912 else
913 vt_check_compatible (loop)
914 fi
915
916 vt_img_sector "${1}${chosen_path}"
917
918 if [ "$ventoy_fs_probe" = "iso9660" ]; then
919 vt_select_conf_replace "${1}" "${chosen_path}"
920 fi
921
922 if [ "$vtoy_os" = "Windows" ]; then
923 vt_check_compatible_pe (loop)
924 uefi_windows_menu_func "$1" "${chosen_path}"
925 elif [ "$vtoy_os" = "Unix" ]; then
926 uefi_unix_menu_func "$1" "${chosen_path}"
927 else
928 vt_check_compatible_linux (loop)
929 uefi_linux_menu_func "$1" "${chosen_path}"
930 fi
931
932 ventoy_gui_console
933 }
934
935 function uefi_iso_memdisk {
936 echo 'Loading ISO file to memory ...'
937 vt_load_img_memdisk "${1}${2}" vtoy_iso_buf
938
939 ventoy_cli_console
940 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}
941 boot
942
943 ventoy_gui_console
944 }
945
946 function vtoy_windows_wimboot {
947 if [ -f (loop)/x86/sources/boot.wim -a -f (loop)/x64/sources/boot.wim ]; then
948 vt_sel_wimboot vtoy_wimboot_bit
949 if [ "$vtoy_wimboot_bit" = "32" ]; then
950 set vtoy_wimboot_prefix=(loop)/x86
951 else
952 set vtoy_wimboot_prefix=(loop)/x64
953 fi
954 else
955 set vtoy_wimboot_prefix=(loop)
956 if vt_is_pe64 $vtoy_wimboot_prefix/setup.exe; then
957 set vtoy_wimboot_bit=64
958 else
959 set vtoy_wimboot_bit=32
960 fi
961 fi
962
963 if [ -n "${vtdebug_flag}" ]; then
964 echo vtoy_wimboot_prefix=$vtoy_wimboot_prefix vtoy_wimboot_bit=$vtoy_wimboot_bit vt_wimkernel=$vt_wimkernel
965 fi
966
967 for wmfile in sources/boot.wim boot/bcd boot/boot.sdi; do
968 if [ ! -f $vtoy_wimboot_prefix/$wmfile ]; then
969 return
970 fi
971 done
972
973 if [ -f $vtoy_wimboot_prefix/sources/install.wim -o -f $vtoy_wimboot_prefix/sources/install.esd ]; then
974 vt_windows_wimboot_data "$vtoy_wimboot_prefix/sources/boot.wim" vtoy_init_exe
975 else
976 return
977 fi
978
979 if [ "$grub_platform" = "pc" ]; then
980 linux16 "$vtoy_path/$vt_wimkernel" quiet
981 ventoy_debug_pause
982
983 vt_set_wim_load_prompt 1 "Loading files......"
984 initrd16 newc:winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
985 newc:vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd \
986 newc:bcd:$vtoy_wimboot_prefix/boot/bcd \
987 newc:boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi \
988 newc:boot.wim:$vtoy_wimboot_prefix/sources/boot.wim
989 vt_set_wim_load_prompt 0
990 boot
991 else
992 vt_set_wim_load_prompt 1 "Loading files......"
993 vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/sources/boot.wim vtoy_wimfile_mem
994 vt_set_wim_load_prompt 0
995
996 if [ $? -eq 0 ]; then
997 set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
998 else
999 set vtoy_wimfile_path=$vtoy_wimboot_prefix/sources/boot.wim
1000 fi
1001
1002 ventoy_cli_console
1003 chainloader "$vtoy_path/$vt_wimkernel" quiet \
1004 "vf=winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
1005 "vf=vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd" \
1006 "vf=bcd:$vtoy_wimboot_prefix/boot/bcd" \
1007 "vf=boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi" \
1008 "vf=boot.wim:$vtoy_wimfile_path" \
1009 pfsize=$vtoy_chain_file_size \
1010 pfread=$vtoy_chain_file_read
1011 boot
1012 ventoy_gui_console
1013 fi
1014 }
1015
1016 function vtoy_winpe_wimboot {
1017 unset vtoy_boot_mgr_exe
1018 unset vtoy_boot_mgr_efi
1019 set vtoy_wimboot_prefix=(loop)
1020 set vtoy_bcd_path="$1"
1021 set vtoy_sdi_path="$2"
1022 set vtoy_wim_path="$3"
1023 set vtoy_mgr_flag="$4"
1024
1025 if [ $vtoy_mgr_flag -eq 1 ]; then
1026 set vtoy_boot_mgr_exe="newc:bootmgr.exe:$vtoy_wimboot_prefix/$5"
1027 elif [ $vtoy_mgr_flag -eq 2 ]; then
1028 set vtoy_boot_mgr_efi="vf=bootmgr.efi:$vtoy_wimboot_prefix/$5"
1029 elif [ $vtoy_mgr_flag -eq 3 ]; then
1030 set vtoy_boot_mgr_exe="newc:bootmgr.exe:$vtoy_wimboot_prefix/$5"
1031 set vtoy_boot_mgr_efi="vf=bootmgr.efi:$vtoy_wimboot_prefix/$6"
1032 fi
1033
1034 vt_windows_wimboot_data $vtoy_wimboot_prefix/$vtoy_wim_path vtoy_init_exe
1035
1036 if [ "$grub_platform" = "pc" ]; then
1037 linux16 "$vtoy_path/$vt_wimkernel" quiet
1038 ventoy_debug_pause
1039
1040 vt_set_wim_load_prompt 1 "Loading files......"
1041 initrd16 newc:$vtoy_init_exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
1042 $vtoy_boot_mgr_exe \
1043 newc:vtoy_wimboot:$vtoy_wimboot_prefix/$vtoy_bcd_path \
1044 newc:bcd:$vtoy_wimboot_prefix/$vtoy_bcd_path \
1045 newc:boot.sdi:$vtoy_wimboot_prefix/$vtoy_sdi_path \
1046 newc:boot.wim:$vtoy_wimboot_prefix/$vtoy_wim_path
1047 vt_set_wim_load_prompt 0
1048 boot
1049 else
1050 vt_set_wim_load_prompt 1 "Loading files......"
1051 vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/$vtoy_wim_path vtoy_wimfile_mem
1052 vt_set_wim_load_prompt 0
1053
1054 if [ $? -eq 0 ]; then
1055 set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
1056 else
1057 set vtoy_wimfile_path=$vtoy_wimboot_prefix/$vtoy_wim_path
1058 fi
1059
1060 ventoy_cli_console
1061 chainloader "$vtoy_path/$vt_wimkernel" quiet \
1062 "vf=$vtoy_init_exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
1063 "vf=vtoy_wimboot:$vtoy_wimboot_prefix/$vtoy_bcd_path" \
1064 "$vtoy_boot_mgr_efi" \
1065 "vf=bcd:$vtoy_wimboot_prefix/$vtoy_bcd_path" \
1066 "vf=boot.sdi:$vtoy_wimboot_prefix/$vtoy_sdi_path" \
1067 "vf=boot.wim:$vtoy_wimfile_path" \
1068 pfsize=$vtoy_chain_file_size \
1069 pfread=$vtoy_chain_file_read
1070 boot
1071 ventoy_gui_console
1072 fi
1073 }
1074
1075 function vtoy_wimboot_func {
1076 echo -e "\n===================== VENTOY WIMBOOT ===================\n"
1077
1078 if [ "$grub_platform" = "pc" ]; then
1079 set vt_wimkernel=wimboot.x86_64.xz
1080 else
1081 if [ "$grub_cpu" = "i386" ]; then
1082 set vt_wimkernel=wimboot.i386.efi.xz
1083 else
1084 set vt_wimkernel=wimboot.x86_64.xz
1085 fi
1086 fi
1087
1088 if vt_str_begin "$vt_volume_id" "Modified-Win10PEx64"; then
1089 vtoy_winpe_wimboot 'Boot/bcd' 'Boot/boot.sdi' 'sources/boot.wim' 1 'bootmgr.exe'
1090 else
1091 vtoy_windows_wimboot
1092 fi
1093 }
1094
1095 function legacy_windows_menu_func {
1096 vt_windows_reset
1097
1098 if vt_check_mode 4 "$vt_chosen_name"; then
1099 vt_windows_chain_data "${1}${chosen_path}"
1100 ventoy_debug_pause
1101 vtoy_wimboot_func
1102 else
1103 if [ "$ventoy_compatible" = "NO" ]; then
1104
1105 if [ "$ventoy_fs_probe" = "iso9660" ]; then
1106 loopback -d loop
1107 vt_iso9660_nojoliet 1
1108 loopback loop "$1$2"
1109 fi
1110
1111 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD" "boot/bce"; do
1112 vt_windows_collect_wim_patch bcd (loop)/$file
1113 done
1114
1115 distro_specify_wim_patch
1116
1117 vt_windows_count_wim_patch vt_wim_cnt
1118 if [ $vt_wim_cnt -eq 0 ]; then
1119 distro_specify_wim_patch_phase2
1120 fi
1121
1122 ventoy_debug_pause
1123 locate_wim "${chosen_path}"
1124 fi
1125
1126 vt_windows_chain_data "${1}${chosen_path}"
1127 ventoy_debug_pause
1128 fi
1129
1130 if [ -n "$vtoy_chain_mem_addr" ]; then
1131 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1132 if [ "$ventoy_compatible" = "NO" ]; then
1133 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1134 else
1135 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1136 fi
1137 boot
1138 else
1139 echo "chain empty failed"
1140 ventoy_pause
1141 fi
1142 }
1143
1144 function legacy_linux_menu_func {
1145 if [ "$ventoy_compatible" = "NO" ]; then
1146
1147 if [ "$ventoy_fs_probe" = "udf" ]; then
1148 loopback -d loop
1149 set ventoy_fs_probe=iso9660
1150 loopback loop "$1$2"
1151 fi
1152
1153
1154 if vt_syslinux_need_nojoliet "$1$2"; then
1155 vt_iso9660_nojoliet 1
1156 loopback -d loop
1157 loopback loop "$1$2"
1158 fi
1159
1160 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
1161
1162 vt_linux_clear_initrd
1163
1164 if [ -d (loop)/pmagic ]; then
1165 vt_linux_specify_initrd_file /pmagic/initrd.img
1166 else
1167 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
1168 if [ -d (loop)/$dir ]; then
1169 vt_linux_parse_initrd_isolinux (loop)/$dir/
1170 fi
1171 done
1172 fi
1173
1174 # special process for special distros
1175 #archlinux
1176 if [ -d (loop)/arch/boot/syslinux ]; then
1177 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
1178 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
1179 elif [ -d (loop)/anarchy/boot/syslinux ]; then
1180 vt_linux_parse_initrd_isolinux (loop)/anarchy/boot/syslinux/ /anarchy/
1181
1182 #manjaro
1183 elif [ -d (loop)/manjaro ]; then
1184 if [ -e (loop)/boot/grub/kernels.cfg ]; then
1185 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
1186 fi
1187 elif [ -e (loop)/boot/grub/grub.cfg ]; then
1188 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
1189 fi
1190
1191 distro_specify_initrd_file
1192
1193 vt_linux_initrd_count vtcount
1194 if [ $vtcount -eq 0 ]; then
1195 if [ -d (loop)/rancheros ]; then
1196 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
1197 fi
1198
1199 distro_specify_initrd_file_phase2
1200 fi
1201
1202 locate_initrd
1203 fi
1204
1205 vt_linux_chain_data "${1}${chosen_path}"
1206 ventoy_debug_pause
1207
1208 if [ -n "$vtoy_chain_mem_addr" ]; then
1209 if vt_check_mode 3 "$vt_chosen_name"; then
1210 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1211 ventoy_cli_console
1212
1213 # fallback
1214 set vtback_root=$root
1215 vt_push_last_entry
1216 set vtback_theme=$theme
1217 unset theme
1218
1219 vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
1220 vt_set_boot_opt rdinit=/vtoy/vtoy
1221
1222 set root=(loop)
1223 set vtback_cfg_find=0
1224 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
1225 if [ -e "$cfg" ]; then
1226 set vtback_cfg_find=1
1227 configfile "$cfg"
1228 break
1229 fi
1230 done
1231
1232 vt_unset_boot_opt
1233 set root=$vtback_root
1234 set theme=$vtback_theme
1235 vt_pop_last_entry
1236 ventoy_gui_console
1237 else
1238 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1239 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1240 boot
1241 fi
1242 else
1243 echo "chain empty failed"
1244 ventoy_pause
1245 fi
1246 }
1247
1248
1249 function legacy_unix_menu_func {
1250 ventoy_unix_comm_proc $1 "${chosen_path}"
1251
1252 if [ -n "$vtoy_chain_mem_addr" ]; then
1253 #ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
1254 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1255 boot
1256 else
1257 echo "chain empty failed"
1258 ventoy_pause
1259 fi
1260 }
1261
1262
1263 function legacy_iso_menu_func {
1264
1265 if [ -d (loop)/ ]; then
1266 loopback -d loop
1267 fi
1268
1269 set chosen_path="$2"
1270
1271 vt_select_auto_install "${chosen_path}"
1272 vt_select_persistence "${chosen_path}"
1273
1274 if vt_is_udf "${1}${chosen_path}"; then
1275 set ventoy_fs_probe=udf
1276 else
1277 set ventoy_fs_probe=iso9660
1278 ventoy_reset_nojoliet
1279 fi
1280
1281 loopback loop "${1}${chosen_path}"
1282
1283 get_os_type (loop)
1284
1285 if [ -n "$vtcompat" ]; then
1286 set ventoy_compatible=YES
1287 unset vtcompat
1288 elif vt_check_mode 1 "$vt_chosen_name"; then
1289 set ventoy_compatible=YES
1290 else
1291 vt_check_compatible (loop)
1292 fi
1293
1294 vt_img_sector "${1}${chosen_path}"
1295
1296 if [ "$ventoy_fs_probe" = "iso9660" ]; then
1297 vt_select_conf_replace "${1}" "${chosen_path}"
1298 fi
1299
1300 if [ "$vtoy_os" = "Windows" ]; then
1301 vt_check_compatible_pe (loop)
1302 legacy_windows_menu_func "$1" "${chosen_path}"
1303 elif [ "$vtoy_os" = "Unix" ]; then
1304 legacy_unix_menu_func "$1" "${chosen_path}"
1305 else
1306 vt_check_compatible_linux (loop)
1307 legacy_linux_menu_func "$1" "${chosen_path}"
1308 fi
1309 }
1310
1311 function legacy_iso_memdisk {
1312
1313 linux16 $vtoy_path/memdisk iso raw
1314 echo "Loading ISO file to memory ..."
1315 initrd16 "${1}${2}"
1316 boot
1317 }
1318
1319
1320 function iso_endless_os_proc {
1321 if [ -d (loop)/ ]; then
1322 loopback -d loop
1323 fi
1324
1325 loopback loop "${1}${2}"
1326 vt_img_sector "${1}${2}"
1327
1328 vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
1329 vt_trailer_cpio "$1" "$2" noinit
1330
1331 ventoy_debug_pause
1332
1333 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
1334
1335 set eosimage=loop
1336 set ventoy_bls_bootdev=/boot
1337 set ventoy_loading_tip="Loading files ......"
1338
1339 export eosimage
1340 configfile (loop)/endless/grub/grub.cfg
1341
1342 unset eosimage
1343 unset ventoy_bls_bootdev
1344 unset ventoy_loading_tip
1345
1346 vt_unset_boot_opt
1347 }
1348
1349
1350 function ventoy_iso_busybox_ver {
1351
1352 if [ "$VTOY_EFI_ARCH" = "aa64" ]; then
1353 set ventoy_busybox_ver=a64
1354 elif [ "$VTOY_EFI_ARCH" = "mips" ]; then
1355 set ventoy_busybox_ver=m64
1356 else
1357 set ventoy_busybox_ver=32
1358
1359 #special process for deepin-live iso
1360 if [ "$vt_chosen_size" = "403701760" ]; then
1361 if vt_str_str "$vt_chosen_path" "/deepin-live"; then
1362 set ventoy_busybox_ver=64
1363 fi
1364 elif vt_str_begin "$vt_volume_id" "PHOTON_"; then
1365 set ventoy_busybox_ver=64
1366 elif vt_str_begin "$vt_volume_id" "smgl-test-quinq-x86_64"; then
1367 set ventoy_busybox_ver=64
1368 elif vt_str_begin "$vt_volume_id" "LDiagBootable"; then
1369 set ventoy_busybox_ver=64
1370
1371 fi
1372 fi
1373 }
1374
1375
1376 function iso_common_menuentry {
1377 unset vt_system_id
1378 unset vt_volume_id
1379
1380 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1381
1382 vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id vt_volume_space
1383 if [ $vt_volume_space -NE $vt_chosen_size ]; then
1384 vt_mod $vt_chosen_size 2048 vt_chosen_size_mod
1385 if [ $vt_chosen_size_mod -ne 0 ]; then
1386 echo -e "\n $vt_volume_space $vt_chosen_size $vt_chosen_size_mod\n"
1387 echo -e "\n The size of the iso file \"$vt_chosen_size\" is invalid. File corrupted ?\n"
1388 echo -e " 此ISO文件的大小 \"$vt_chosen_size\" 有问题,请确认文件是否损坏。\n"
1389 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
1390 read vtInputKey
1391 fi
1392 fi
1393
1394 if vt_check_password "${vt_chosen_path}"; then
1395 return
1396 fi
1397
1398 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1399 return
1400 fi
1401
1402 if vt_str_begin "$vt_volume_id" "Avira"; then
1403 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
1404 fi
1405
1406 ventoy_iso_busybox_ver
1407
1408 #special process for Endless OS
1409 if vt_str_begin "$vt_volume_id" "Endless-OS"; then
1410 iso_endless_os_proc $vtoy_iso_part "$vt_chosen_path"
1411 elif vt_str_begin "$vt_volume_id" "TENS-Public"; then
1412 set vtcompat=1
1413 fi
1414
1415
1416 # auto memdisk mode for some special ISO files
1417 vt_iso_vd_id_parse "${vtoy_iso_part}${vt_chosen_path}"
1418 unset vtMemDiskBoot
1419 if vt_check_mode 0 "$vt_chosen_name"; then
1420 set vtMemDiskBoot=1
1421 else
1422 if [ "$grub_platform" = "pc" ]; then
1423 if vt_iso_vd_id_begin 1 0 "Memtest86+"; then
1424 set vtMemDiskBoot=1
1425 elif vt_iso_vd_id_begin 0 1 "KolibriOS"; then
1426 set vtMemDiskBoot=1
1427 fi
1428 fi
1429
1430 #For iKuai8 (<64MB)
1431 if [ $vt_chosen_size -LE 67108864 ]; then
1432 if vt_str_begin "$vt_chosen_name" "iKuai"; then
1433 set vtMemDiskBoot=1
1434 fi
1435 fi
1436 fi
1437 vt_iso_vd_id_clear
1438
1439
1440 if [ "$grub_platform" = "pc" ]; then
1441 if [ -n "$vtMemDiskBoot" ]; then
1442 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1443 else
1444 legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
1445 fi
1446 else
1447 if [ -n "$vtMemDiskBoot" ]; then
1448 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1449 else
1450 uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
1451 fi
1452 fi
1453 }
1454
1455 function miso_common_menuentry {
1456 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1457
1458 if vt_check_password "${vt_chosen_path}"; then
1459 return
1460 fi
1461
1462 echo "memdisk mode boot for $vt_chosen_path"
1463 echo ""
1464 ventoy_debug_pause
1465
1466 if [ "$grub_platform" = "pc" ]; then
1467 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1468 else
1469 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1470 fi
1471 }
1472
1473
1474 function common_unsupport_menuentry {
1475 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
1476 echo -e " 文件名中不能有中文或空格 \n"
1477 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1478 read vtInputKey
1479 }
1480
1481 function miso_unsupport_menuentry {
1482 common_unsupport_menuentry
1483 }
1484
1485 function iso_unsupport_menuentry {
1486 common_unsupport_menuentry
1487 }
1488
1489 function wim_common_menuentry {
1490 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1491
1492 if vt_check_password "${vt_chosen_path}"; then
1493 return
1494 fi
1495
1496 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1497 return
1498 fi
1499
1500 if vt_wim_check_bootable "${vtoy_iso_part}${vt_chosen_path}"; then
1501 vt_wim_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1502 else
1503 echo -e "\n This is NOT a bootable WIM file. \n"
1504 echo -e " 这不是一个可启动的 WIM 文件。\n"
1505 fi
1506
1507 ventoy_debug_pause
1508
1509 if [ -n "$vtoy_chain_mem_addr" ]; then
1510 if [ "$grub_platform" = "pc" ]; then
1511 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1512 else
1513 ventoy_cli_console
1514 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}
1515 ventoy_gui_console
1516 fi
1517 boot
1518 else
1519 echo "chain empty failed"
1520 ventoy_pause
1521 fi
1522 }
1523
1524 function wim_unsupport_menuentry {
1525 common_unsupport_menuentry
1526 }
1527
1528 function efi_common_menuentry {
1529 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1530
1531 if vt_check_password "${vt_chosen_path}"; then
1532 return
1533 fi
1534
1535 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1536 return
1537 fi
1538
1539 unset vt_vlnk_dst
1540 if vt_is_vlnk_name "${vt_chosen_path}"; then
1541 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1542 if [ -z "$vt_vlnk_dst" ]; then
1543 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1544 ventoy_pause
1545 return
1546 fi
1547 else
1548 vt_vlnk_dst="${vtoy_iso_part}${vt_chosen_path}"
1549 fi
1550
1551 ventoy_debug_pause
1552
1553 ventoy_cli_console
1554
1555 #first try with chainload
1556 set vtOldRoot=$root
1557 set root=$vtoy_iso_part
1558 chainloader "${vt_vlnk_dst}"
1559 boot
1560
1561 #retry with isoboot
1562 set root=$vtOldRoot
1563 vt_concat_efi_iso "${vt_vlnk_dst}" vtoy_iso_buf
1564 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}
1565 boot
1566
1567 ventoy_gui_console
1568 }
1569
1570 function efi_unsupport_menuentry {
1571 common_unsupport_menuentry
1572 }
1573
1574 function vhdboot_common_func {
1575 vt_patch_vhdboot "$1"
1576
1577 ventoy_debug_pause
1578
1579 if [ -n "$vtoy_vhd_buf_addr" ]; then
1580 if [ "$grub_platform" = "pc" ]; then
1581 ventoy_cli_console
1582 linux16 $vtoy_path/memdisk iso raw
1583 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1584 boot
1585 ventoy_gui_console
1586 else
1587 ventoy_cli_console
1588 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}
1589 boot
1590 ventoy_gui_console
1591 fi
1592 else
1593 echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
1594 ventoy_pause
1595 fi
1596 }
1597
1598 function vhd_common_menuentry {
1599 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1600
1601 if vt_check_password "${vt_chosen_path}"; then
1602 return
1603 fi
1604
1605 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1606 return
1607 fi
1608
1609 unset vt_vlnk_dst
1610 if vt_is_vlnk_name "${vt_chosen_path}"; then
1611 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1612 if [ -z "$vt_vlnk_dst" ]; then
1613 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1614 ventoy_pause
1615 return
1616 fi
1617 else
1618 vt_vlnk_dst="${vt_chosen_path}"
1619 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
1620 if [ "$vtoy_iso_fs" != "ntfs" ]; then
1621 echo -e "!!! WARNING !!!\n"
1622 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
1623 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
1624 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
1625 read vtInputKey
1626 fi
1627 fi
1628 fi
1629
1630 vhdboot_common_func "${vt_vlnk_dst}"
1631 }
1632
1633 function vhd_unsupport_menuentry {
1634 common_unsupport_menuentry
1635 }
1636
1637 function vtoyboot_common_func {
1638 set AltBootPart=0
1639 set vtoysupport=0
1640
1641 vt_get_vtoy_type "${1}" vtoytype parttype AltBootPart
1642
1643 if vt_str_begin $vtoytype vhd; then
1644 set vtoysupport=1
1645 elif [ "$vtoytype" = "raw" ]; then
1646 set vtoysupport=1
1647 elif [ "$vtoytype" = "vdi" ]; then
1648 set vtoysupport=1
1649 fi
1650
1651 if [ $vtoysupport -eq 1 ]; then
1652 if [ "$grub_platform" = "pc" ]; then
1653 if [ "$parttype" = "gpt" -a $AltBootPart -eq 0 ]; then
1654 echo "The OS in the vdisk was created in UEFI mode, but current is Legacy BIOS mode."
1655 echo "虚拟磁盘内的系统是在UEFI模式下创建的,而当前系统是Legacy BIOS模式,可能无法正常启动。"
1656 ventoy_pause
1657 fi
1658 else
1659 if [ "$parttype" = "mbr" -a $AltBootPart -eq 0 ]; then
1660 echo "The OS in the vdisk was created in Legacy BIOS mode, but current is UEFI mode."
1661 echo "虚拟磁盘内的系统是在Legacy BIOS模式下创建的,而当前系统是UEFI模式,可能无法正常启动。"
1662 ventoy_pause
1663 fi
1664 fi
1665
1666 vt_img_sector "${1}"
1667 vt_raw_chain_data "${1}"
1668
1669 ventoy_debug_pause
1670
1671 if [ -n "$vtoy_chain_mem_addr" ]; then
1672 if [ "$grub_platform" = "pc" ]; then
1673 vt_acpi_param ${vtoy_chain_mem_addr} 512
1674 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} bios80 sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1675 boot
1676 else
1677 if vt_check_secureboot_var; then
1678 vt_acpi_param ${vtoy_chain_mem_addr} 512
1679 fi
1680 ventoy_cli_console
1681 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}
1682 boot
1683 ventoy_gui_console
1684 fi
1685 else
1686 echo "chain empty failed!"
1687 ventoy_pause
1688 fi
1689 else
1690 echo "Unsupported vtoy type $vtoytype"
1691 ventoy_pause
1692 fi
1693 }
1694
1695 function vtoy_common_menuentry {
1696 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
1697
1698 if vt_check_password "${vt_chosen_path}"; then
1699 return
1700 fi
1701
1702 if ventoy_vcfg_proc "${vt_chosen_path}"; then
1703 return
1704 fi
1705
1706 unset vt_vlnk_dst
1707 if vt_is_vlnk_name "${vt_chosen_path}"; then
1708 vt_get_vlnk_dst "${vtoy_iso_part}${vt_chosen_path}" vt_vlnk_dst
1709 if [ -z "$vt_vlnk_dst" ]; then
1710 echo -e "\n### VLNK FILE NOT FOUND ###\n### VLNK 文件不存在 ###\n"
1711 ventoy_pause
1712 return
1713 fi
1714 else
1715 vt_vlnk_dst="${vtoy_iso_part}${vt_chosen_path}"
1716 fi
1717
1718 vtoyboot_common_func "${vt_vlnk_dst}"
1719 }
1720
1721 function vtoy_unsupport_menuentry {
1722 common_unsupport_menuentry
1723 }
1724
1725 #
1726 #============================================================#
1727 # IMG file boot process #
1728 #============================================================#
1729 #
1730
1731 function only_uefi_tip {
1732 echo -e "\n This IMG file is only supported in UEFI mode. \n"
1733 echo -e "\n press ENTER to exit ..."
1734 read vtInputKey
1735 }
1736
1737 function ventoy_img_easyos {
1738 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1739 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1740
1741 loopback easysfs (vtimghd,1)/easy.sfs
1742 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1743
1744 if [ -n "$vt_module_ver" ]; then
1745 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1746 if [ -e (easysfs)/lib/modules/$vt_module_ver/$mod ]; then
1747 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1748 fi
1749 done
1750 fi
1751
1752 ventoy_debug_pause
1753
1754 #boot image file
1755 vt_set_boot_opt rdinit=/vtoy/vtoy
1756 vt_img_hook_root
1757
1758 syslinux_configfile (vtimghd,1)/syslinux.cfg
1759
1760 vt_img_unhook_root
1761 vt_unset_boot_opt
1762 loopback -d easysfs
1763 }
1764
1765 function ventoy_img_volumio {
1766 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1767 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1768
1769 ventoy_debug_pause
1770
1771 #boot image file
1772 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1773 vt_img_hook_root
1774
1775 syslinux_configfile (vtimghd,1)/syslinux.cfg
1776
1777 vt_img_unhook_root
1778 vt_unset_boot_opt
1779 }
1780
1781 function ventoy_img_openelec {
1782 elec_ver=$1
1783
1784 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1785 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1786
1787 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1788 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1789
1790 ventoy_debug_pause
1791
1792 #boot image file
1793 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1794 vt_img_hook_root
1795
1796 set root=(vtimghd,1)
1797 syslinux_configfile (vtimghd,1)/syslinux.cfg
1798
1799 vt_img_unhook_root
1800 vt_unset_boot_opt
1801 loopback -d vtloopex
1802 }
1803
1804
1805 function ventoy_img_freedombox {
1806 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1807 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1808
1809 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1810 if [ -n "$vt_module_ver" ]; then
1811 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1812 fi
1813
1814 ventoy_debug_pause
1815
1816 #boot image file
1817 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1818 vt_img_hook_root
1819
1820 configfile (vtimghd,1)/boot/grub/grub.cfg
1821
1822 vt_img_unhook_root
1823 vt_unset_boot_opt
1824 }
1825
1826 function ventoy_img_paldo {
1827 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1828 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1829
1830 ventoy_debug_pause
1831
1832 #boot image file
1833 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1834 vt_img_hook_root
1835
1836 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1837 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1838
1839 echo loading file...
1840 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1841 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1842 boot
1843
1844 vt_img_unhook_root
1845 vt_unset_boot_opt
1846 }
1847
1848 function ventoy_img_ubos {
1849 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1850 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1851
1852 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1853 if [ -n "$vt_module_ver" ]; then
1854 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1855 fi
1856
1857 ventoy_debug_pause
1858
1859 #boot image file
1860 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1861 vt_img_hook_root
1862
1863 echo loading file...
1864 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1865 initrd (vtimghd,2)/initramfs-linux.img
1866 boot
1867
1868 vt_img_unhook_root
1869 vt_unset_boot_opt
1870 }
1871
1872 function ventoy_img_recalbox {
1873 if [ $vtoy_img_max_part_end -GT $vt_chosen_size ]; then
1874 echo -e "\nPlease extend the img file size before boot it. \n"
1875 ventoy_pause
1876 return
1877 fi
1878
1879 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1880 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1881
1882 if [ -e (vtimghd,1)/boot/recalbox ]; then
1883 loopback recalbox (vtimghd,1)/boot/recalbox
1884 vt_get_lib_module_ver (recalbox) /lib/modules/ vt_module_ver
1885 if [ -n "$vt_module_ver" ]; then
1886 vt_img_extra_initrd_append (recalbox)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1887 fi
1888 fi
1889
1890 ventoy_debug_pause
1891
1892 #boot image file
1893 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1894 vt_img_hook_root
1895
1896 set root=(vtimghd,1)
1897 configfile (vtimghd,1)/boot/grub/grub.cfg
1898
1899 vt_img_unhook_root
1900 vt_unset_boot_opt
1901 }
1902
1903 function ventoy_img_esysrescue {
1904 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1905 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1906
1907 ventoy_debug_pause
1908
1909 #boot image file
1910 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=esysrescue
1911 vt_img_hook_root
1912
1913 set root=(vtimghd,1)
1914 configfile (vtimghd,1)/boot/grub/grub.cfg
1915
1916 vt_img_unhook_root
1917 vt_unset_boot_opt
1918 }
1919
1920 function ventoy_img_batocera {
1921 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1922 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1923
1924 ventoy_debug_pause
1925
1926 #boot image file
1927 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1928 vt_img_hook_root
1929
1930 set root=(vtimghd,1)
1931 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1932
1933 vt_img_unhook_root
1934 vt_unset_boot_opt
1935 }
1936
1937 function ventoy_img_openwrt {
1938 if [ -e (vtimghd,2)/lib64 ]; then
1939 set ventoy_busybox_ver=64
1940 fi
1941
1942 vt_fs_enum_1st_dir (vtimghd,2) /lib/modules/ vt_dir_name
1943
1944 if [ -f (vtimghd,2)/lib/modules/$vt_dir_name/dm-mod.ko ]; then
1945 set openwrt_plugin_need=0
1946 vt_img_extra_initrd_append (vtimghd,2)/lib/modules/$vt_dir_name/dm-mod.ko
1947 if [ -f (vtimghd,2)/lib/modules/$vt_dir_name/dax.ko ]; then
1948 vt_img_extra_initrd_append (vtimghd,2)/lib/modules/$vt_dir_name/dax.ko
1949 fi
1950 else
1951 set openwrt_plugin_need=1
1952 if [ ! -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
1953 ventoy_gui_console
1954 echo -e "\n ventoy_openwrt.xz not found. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
1955 echo -e " 未找到 ventoy_openwrt.xz 文件。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
1956 echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
1957 read vtInputKey
1958 ventoy_cli_console
1959 return
1960 fi
1961 fi
1962
1963 if vt_img_check_range "${vtoy_iso_part}${vt_chosen_path}"; then
1964 ventoy_debug_pause
1965 else
1966 ventoy_gui_console
1967 echo -e "\n IMG file need processed. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
1968 echo -e " 此 IMG 文件必须处理之后才能支持。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
1969 echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
1970 read vtInputKey
1971 ventoy_cli_console
1972 return
1973 fi
1974
1975 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1976 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1977
1978 if [ $openwrt_plugin_need -eq 1 ]; then
1979 if [ -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
1980 vt_img_extra_initrd_append ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz
1981 fi
1982 fi
1983
1984 #boot image file
1985 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=openwrt
1986 vt_img_hook_root
1987
1988 set root=(vtimghd,1)
1989 configfile (vtimghd,1)/boot/grub/grub.cfg
1990
1991 vt_img_unhook_root
1992 vt_unset_boot_opt
1993 }
1994
1995 function ventoy_img_tails {
1996 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1997 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1998
1999 ventoy_debug_pause
2000
2001 #boot image file
2002 vt_set_boot_opt rdinit=/vtoy/vtoy live-media=/dev/dm-1 ventoyos=tails
2003 vt_img_hook_root
2004
2005 set root=(vtimghd,1)
2006 configfile (vtimghd,1)/efi/debian/grub.cfg
2007
2008 vt_img_unhook_root
2009 vt_unset_boot_opt
2010 }
2011
2012 function ventoy_img_fydeos {
2013 if [ "$grub_platform" = "pc" ]; then
2014 only_uefi_tip
2015 return
2016 fi
2017
2018 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=64"
2019 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2020
2021 ventoy_debug_pause
2022
2023 #boot image file
2024 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=fydeos
2025 vt_img_hook_root
2026
2027 set grubdisk=vtimghd
2028 set grubpartA=(vtimghd,3)
2029 set grubpartB=(vtimghd,5)
2030 set linuxpartA=(sda,3)
2031 set linuxpartB=(sda,5)
2032
2033 set root=(vtimghd,12)
2034 configfile (vtimghd,12)/efi/boot/grub.cfg
2035
2036 vt_img_unhook_root
2037 vt_unset_boot_opt
2038
2039 unset grubdisk
2040 unset grubpartA
2041 unset grubpartB
2042 unset linuxpartA
2043 unset linuxpartB
2044 }
2045
2046 function ventoy_img_cloudready {
2047 if [ "$grub_platform" = "pc" ]; then
2048 only_uefi_tip
2049 return
2050 fi
2051
2052 vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=64"
2053 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
2054
2055 ventoy_debug_pause
2056
2057 #boot image file
2058 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=cloudready
2059 vt_img_hook_root
2060
2061 set grubdisk=vtimghd
2062 set grubpartA=(vtimghd,3)
2063 set grubpartB=(vtimghd,5)
2064 set linuxpartA=(sda,3)
2065 set linuxpartB=(sda,5)
2066
2067 set root=(vtimghd,12)
2068 configfile (vtimghd,12)/efi/boot/grub.cfg
2069
2070 vt_img_unhook_root
2071 vt_unset_boot_opt
2072
2073 unset grubdisk
2074 unset grubpartA
2075 unset grubpartB
2076 unset linuxpartA
2077 unset linuxpartB
2078 }
2079
2080 function ventoy_img_memtest86 {
2081 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
2082 boot
2083 }
2084
2085 function img_unsupport_tip {
2086 echo -e "\n This IMG file is NOT supported now. \n"
2087 echo -e " 当前不支持启动此 IMG 文件 \n"
2088 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
2089 read vtInputKey
2090 }
2091
2092 function legacy_img_memdisk {
2093 linux16 $vtoy_path/memdisk
2094 echo "Loading img file to memory ..."
2095 initrd16 "${1}${2}"
2096
2097 ventoy_cli_console
2098 boot
2099 }
2100
2101 function img_common_menuentry {
2102 set ventoy_compatible=YES
2103 set ventoy_busybox_ver=32
2104 unset LoadIsoEfiDriver
2105
2106 vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
2107
2108 if vt_check_password "${vt_chosen_path}"; then
2109 return
2110 fi
2111
2112 if ventoy_vcfg_proc "${vt_chosen_path}"; then
2113 return
2114 fi
2115
2116 if [ "$grub_platform" = "pc" ]; then
2117 if vt_check_mode 0 "$vt_chosen_name"; then
2118 legacy_img_memdisk $vtoy_iso_part "$vt_chosen_path"
2119 return
2120 fi
2121 fi
2122
2123 loopback vtimghd "${vtoy_iso_part}${vt_chosen_path}"
2124 vt_img_sector "${vtoy_iso_part}${vt_chosen_path}"
2125
2126 vt_img_part_info (vtimghd)
2127
2128 set vtback_root=$root
2129 ventoy_cli_console
2130 vt_push_last_entry
2131 set vtback_theme=$theme
2132 unset theme
2133
2134 vt_img_extra_initrd_reset
2135
2136
2137 vt_get_fs_label (vtimghd,1) vtImgHd1Label
2138
2139 if [ "$vtImgHd1Label" = "STATE" ]; then
2140 vt_get_fs_label (vtimghd,3) vtImgHd3Label
2141 elif [ -d (vtimghd,2)/lib ]; then
2142 vt_get_fs_label (vtimghd,2) vtImgHd2Label
2143 fi
2144
2145 if [ -e (vtimghd,1)/etc/hostname ]; then
2146 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
2147 fi
2148
2149 if vt_str_begin "$vtImgHd3Label" "ROOT-"; then
2150 if [ -f (vtimghd,3)/etc/os-release.d/ID ]; then
2151 vt_1st_line (vtimghd,3)/etc/os-release.d/ID vt_release_line1
2152 if vt_str_begin "$vt_release_line1" "FydeOS"; then
2153 ventoy_img_fydeos
2154 else
2155 ventoy_img_cloudready
2156 fi
2157 elif [ -f (vtimghd,3)/etc/cloudready-release ]; then
2158 ventoy_img_cloudready
2159 elif [ -f (vtimghd,3)/etc/chrome_dev.conf ]; then
2160 ventoy_img_cloudready
2161 fi
2162 elif vt_str_begin "$vtImgHd1Label" "LAKKA"; then
2163 ventoy_img_openelec lakka
2164 elif vt_str_begin "$vtImgHd1Label" "LIBREELEC"; then
2165 ventoy_img_openelec LibreELEC
2166 elif vt_str_begin "$vtImgHd1Label" "paldo-live"; then
2167 ventoy_img_paldo
2168 elif vt_str_begin "$vtImgHostname" "freedombox"; then
2169 ventoy_img_freedombox
2170 elif vt_str_begin "$vtImgHd1Label" "BATOCERA"; then
2171 ventoy_img_batocera
2172 elif vt_str_begin "$vtImgHd1Label" "Tails"; then
2173 ventoy_img_tails
2174 elif [ "$vtImgHd2Label" = "RECALBOX" -o "$vtImgHd1Label" = "RECALBOX" ]; then
2175 ventoy_img_recalbox
2176 elif [ "$vtImgHd1Label" = "ESYSRESCUE" ]; then
2177 ventoy_img_esysrescue
2178 elif [ -e (vtimghd,1)/easy.sfs ]; then
2179 ventoy_img_easyos
2180 elif [ -e (vtimghd,1)/volumio.initrd ]; then
2181 ventoy_img_volumio
2182 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
2183 ventoy_img_ubos
2184 elif [ -f (vtimghd,2)/etc/openwrt_version ]; then
2185 ventoy_img_openwrt
2186 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
2187 if [ "$grub_platform" = "pc" ]; then
2188 img_unsupport_tip
2189 else
2190 ventoy_img_memtest86
2191 fi
2192 else
2193 vt_linux_chain_data "${vtoy_iso_part}${vt_chosen_path}"
2194 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
2195 if [ "$grub_platform" = "pc" ]; then
2196 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
2197 boot
2198 else
2199 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}
2200 boot
2201 fi
2202 fi
2203
2204 loopback -d vtimghd
2205
2206 set root=$vtback_root
2207 vt_pop_last_entry
2208 set theme=$vtback_theme
2209 ventoy_gui_console
2210 set ventoy_compatible=NO
2211 }
2212
2213 function img_unsupport_menuentry {
2214 common_unsupport_menuentry
2215 }
2216
2217 #############################################################
2218 #############################################################
2219 #############################################################
2220 ####### Main Process ###########
2221 #############################################################
2222 #############################################################
2223 #############################################################
2224
2225 set VENTOY_VERSION="1.0.79"
2226
2227 #ACPI not compatible with Window7/8, so disable by default
2228 set VTOY_PARAM_NO_ACPI=1
2229
2230 # Default menu display mode, you can change it as you want.
2231 # 0: List mode
2232 # 1: TreeView mode
2233 set VTOY_DEFAULT_MENU_MODE=0
2234
2235 set VTOY_MEM_DISK_STR="[Memdisk]"
2236 set VTOY_ISO_RAW_STR="Compatible Mode"
2237 set VTOY_GRUB2_MODE_STR="GRUB2 Mode"
2238 set VTOY_WIMBOOT_MODE_STR="WIMBOOT Mode"
2239 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
2240
2241 set VTOY_F2_CMD="vt_browser_disk"
2242 set VTOY_F4_CMD="ventoy_localboot"
2243 set VTOY_F5_CMD="ventoy_diagnosis"
2244 set VTOY_F6_CMD="ventoy_ext_menu"
2245 set VTOY_HELP_CMD="ventoy_show_help"
2246 set VTOY_CHKSUM_CMD="ventoy_checksum"
2247 set VTOY_HELP_TXT_LANGUAGE="en_US"
2248 set VTOY_CHKSUM_FILE_PATH="X"
2249
2250
2251 if [ "$grub_platform" = "pc" ]; then
2252 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
2253 else
2254 if [ "$grub_cpu" = "i386" ]; then
2255 set VTOY_EFI_ARCH=ia32
2256 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION IA32 www.ventoy.net"
2257 elif [ "$grub_cpu" = "arm64" ]; then
2258 set VTOY_EFI_ARCH=aa64
2259 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION AA64 www.ventoy.net"
2260 elif [ "$grub_cpu" = "mips64el" ]; then
2261 set VTOY_EFI_ARCH=mips
2262 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION MIPS www.ventoy.net"
2263 else
2264 set VTOY_EFI_ARCH=x64
2265 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
2266 fi
2267 fi
2268
2269 vt_device $root vtoy_dev
2270
2271 if [ "$vtoy_dev" = "tftp" ]; then
2272 set vtoy_path=($root)
2273 for vtid in 0 1 2 3; do
2274 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
2275 set vtoy_iso_part=(hd$vtid,1)
2276 set vtoy_efi_part=(hd$vtid,2)
2277 set vtoydev=hd$vtid
2278 break
2279 fi
2280 done
2281 loadfont ascii
2282
2283 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
2284 set vt_plugin_path=$vtoy_iso_part
2285 else
2286 set vt_plugin_path=$prefix
2287 vt_load_plugin $vt_plugin_path
2288 fi
2289 else
2290 if [ "$prefix" = "(ventoydisk)/grub" ]; then
2291 set vtoy_path=(ventoydisk)/ventoy
2292 else
2293 set vtoy_path=($root)/ventoy
2294 fi
2295
2296 set vtoydev=$vtoy_dev
2297 set vtoy_iso_part=($vtoy_dev,1)
2298 set vtoy_efi_part=($vtoy_dev,2)
2299
2300 vt_load_file_to_mem "auto" $prefix/fonts/unicode.pf2 vtoy_font_mem
2301 loadfont mem:${vtoy_font_mem_addr}:size:${vtoy_font_mem_size}
2302
2303 set vt_plugin_path=$vtoy_iso_part
2304 fi
2305
2306 #Load Partition Table
2307 vt_load_part_table $vtoydev
2308
2309 #Load Plugin
2310 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
2311 clear
2312 vt_load_plugin $vtoy_iso_part
2313 clear
2314 else
2315 vt_check_json_path_case $vtoy_iso_part
2316 fi
2317
2318 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
2319 set timeout=$VTOY_MENU_TIMEOUT
2320 else
2321 unset timeout
2322 fi
2323
2324 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
2325 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
2326 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
2327 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
2328 fi
2329
2330 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
2331 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
2332 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
2333 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
2334 fi
2335
2336
2337 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
2338 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
2339 set VTOY_HOTKEY_TIP="h:Help F1:Memdisk F2:Browser F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
2340 else
2341 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
2342 set VTOY_HOTKEY_TIP="h:Help F1:Memdisk F2:Browser F3:ListView F4:Localboot F5:Tools F6:ExMenu"
2343 fi
2344
2345 terminal_output console
2346
2347 if [ -n "$vtoy_gfxmode" ]; then
2348 set gfxmode=$vtoy_gfxmode
2349 set gfxpayload=keep
2350 else
2351 set gfxmode=1024x768
2352 set gfxpayload=keep
2353 fi
2354
2355
2356 if [ "$vtoy_display_mode" = "CLI" ]; then
2357 terminal_output console
2358 elif [ "$vtoy_display_mode" = "serial" ]; then
2359 if [ -n "$vtoy_serial_param" ]; then
2360 serial $vtoy_serial_param
2361 fi
2362 terminal_input serial
2363 terminal_output serial
2364 elif [ "$vtoy_display_mode" = "serial_console" ]; then
2365 if [ -n "$vtoy_serial_param" ]; then
2366 serial $vtoy_serial_param
2367 fi
2368 terminal_input serial console
2369 terminal_output serial console
2370 else
2371 if [ -n "$vtoy_theme" ]; then
2372 vt_set_theme
2373 else
2374 set theme=$prefix/themes/ventoy/theme.txt
2375 fi
2376 terminal_output gfxterm
2377 fi
2378
2379 if [ "$grub_platform" = "efi" ]; then
2380 set mouse_delta=4000
2381 # terminal_input --append mouse
2382 fi
2383
2384 if [ -n "$VTOY_DEFAULT_KBD_LAYOUT" ]; then
2385 set_keyboard_layout "$VTOY_DEFAULT_KBD_LAYOUT"
2386 fi
2387
2388 if [ -n "$VTOY_PLUGIN_PATH_CASE_MISMATCH" ]; then
2389 clear
2390 echo "$VTOY_PLUGIN_PATH_CASE_MISMATCH"
2391 echo -e "\n\nPath case does not match! ventoy directory and ventoy.json MUST be all lowercase!"
2392 echo -e "\n路径大小写不匹配!ventoy 目录和 ventoy.json 文件的名字必须是全部小写,请修正!"
2393 echo -e "\n\npress ENTER to continue (请按回车键继续) ..."
2394 read vtInputKey
2395 fi
2396
2397 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
2398 clear
2399 if [ -n "$VTOY_PLUGIN_ENCODE_ERROR" ]; then
2400 echo -e "\n Encoding type for ventoy.json is not supported, please convert to UTF-8.\n"
2401 echo -e " ventoy.json 文件编码格式不支持,请转换为 UTF-8 编码格式!\n"
2402 else
2403 echo -e "\n Syntax error detected in ventoy.json, please check! \n"
2404 echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
2405 fi
2406
2407 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
2408 read vtInputKey
2409 fi
2410
2411
2412 for vtTFile in ventoy.json ventoy_grub.cfg; do
2413 if [ -f $vtoy_efi_part/ventoy/$vtTFile ]; then
2414 clear
2415 echo -e "\n You need to put $vtTFile in the 1st partition which hold the ISO files.\n"
2416 echo -e " $vtTFile 放错分区了,请放到镜像分区里的 ventoy 目录下(此目录需要手动创建)!\n"
2417 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
2418 read vtInputKey
2419 fi
2420 done
2421
2422 #clear all input key before show main menu
2423 vt_clear_key
2424
2425 #export necessary variable
2426 export theme
2427 export gfxmode
2428 export gfxpayload
2429 export vtoydev
2430 export vtoy_path
2431 export vtdebug_flag
2432 export vtoy_iso_fs
2433 export vtoy_iso_part
2434 export vtoy_efi_part
2435 export VENTOY_VERSION
2436 export VTOY_CUR_VIDEO_MODE
2437 export VTOY_EFI_ARCH
2438 export VTOY_MEM_DISK_STR
2439 export VTOY_ISO_RAW_STR
2440 export VTOY_GRUB2_MODE_STR
2441 export VTOY_WIMBOOT_MODE_STR
2442 export VTOY_ISO_UEFI_DRV_STR
2443 export VTOY_F2_CMD
2444 export VTOY_F4_CMD
2445 export VTOY_F5_CMD
2446 export VTOY_F6_CMD
2447 export VTOY_HELP_CMD
2448 export VTOY_CHKSUM_CMD
2449 export VTOY_HELP_TXT_LANGUAGE
2450 export VTOY_CHKSUM_FILE_PATH
2451
2452
2453 #colect all image files (iso files)
2454 set ventoy_img_count=0
2455 vt_list_img $vtoy_iso_part ventoy_img_count
2456
2457 #Main menu
2458 if [ $ventoy_img_count -gt 0 ]; then
2459 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
2460 vt_dynamic_menu 0 0
2461 else
2462 vt_dynamic_menu 0 1
2463 fi
2464 else
2465 if [ -n "$VTOY_NO_ISO_TIP" ]; then
2466 NO_ISO_MENU="No ISO or supported IMG files found, $VTOY_NO_ISO_TIP"
2467 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
2468 NO_ISO_MENU="No ISO or supported IMG files found, please check VTOY_DEFAULT_SEARCH_ROOT"
2469 else
2470 NO_ISO_MENU="No ISO or supported IMG files found"
2471 fi
2472 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
2473 echo -e "\n Rebooting ... "
2474 reboot
2475 }
2476 fi
2477
2478
2479 #special VTOY_DEFAULT_IMAGE process
2480 if [ -n "$VTOY_DEFAULT_IMAGE" ]; then
2481 if regexp --set 1:vtHotkey --set 2:vtDefault "(F[2-9])>(.*)" "$VTOY_DEFAULT_IMAGE"; then
2482
2483 set default="$vtDefault"
2484 if [ -z "$VTOY_MENU_TIMEOUT" ]; then
2485 set timeout=0
2486 else
2487 set timeout=$VTOY_MENU_TIMEOUT
2488 fi
2489
2490 export timeout
2491 export default
2492
2493 vt_fn_mutex_lock 1
2494
2495 if [ "$vtHotkey" = "F2" ]; then
2496 unset timeout
2497 vt_browser_disk
2498 elif [ "$vtHotkey" = "F4" ]; then
2499 ventoy_localboot
2500 elif [ "$vtHotkey" = "F5" ]; then
2501 ventoy_diagnosis
2502 elif [ "$vtHotkey" = "F6" ]; then
2503 ventoy_ext_menu
2504 fi
2505
2506 vt_fn_mutex_lock 0
2507
2508 unset timeout
2509 unset default
2510 fi
2511 fi
2512