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