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