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