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