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