]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
0be3f0895f44fcedde5058c4f5408f7b6b71ac56
[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_power {
54 configfile $prefix/power.cfg
55 }
56
57 function ventoy_diagnosis {
58 vt_enum_video_mode
59 configfile $prefix/debug.cfg
60 }
61
62 function ventoy_localboot {
63 configfile $prefix/localboot.cfg
64 }
65
66 function ventoy_ext_menu {
67 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
68 set ventoy_new_context=1
69 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
70 unset ventoy_new_context
71 else
72 echo "ventoy_grub.cfg NOT exist."
73 echo -e "\npress ENTER to exit ..."
74 read vtInputKey
75 fi
76 }
77
78 function get_os_type {
79 set vtoy_os=Linux
80
81 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
82 if vt_file_exist_nocase (loop)/$file; then
83 set vtoy_os=Windows
84 break
85 fi
86 done
87
88 if [ "$vtoy_os" = "Linux" ]; then
89 if vt_strstr "$vt_system_id" "FreeBSD"; then
90 set vtoy_os=Unix
91 set vt_unix_type=FreeBSD
92 elif [ -e (loop)/bin/freebsd-version ]; then
93 set vtoy_os=Unix
94 set vt_unix_type=FreeBSD
95 elif vt_str_begin "$vt_system_id" "DragonFly"; then
96 set vtoy_os=Unix
97 set vt_unix_type=DragonFly
98
99
100 elif [ -e (loop)/boot/kernel/kernel ]; then
101 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
102 set vtoy_os=Unix
103 set vt_unix_type=FreeBSD
104 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
105 set vtoy_os=Unix
106 set vt_unix_type=NetBSD
107 fi
108 fi
109 fi
110
111 if [ -n "${vtdebug_flag}" ]; then
112 echo ISO is "$vtoy_os"
113 fi
114 }
115
116 function vt_check_compatible_pe {
117 #Check for PE without external tools
118 if [ -f "$1/HBCD_PE.ini" ]; then
119 set ventoy_compatible=YES
120 fi
121 }
122
123 function locate_initrd {
124 vt_linux_locate_initrd
125
126 if [ -n "${vtdebug_flag}" ]; then
127 vt_linux_dump_initrd
128 ventoy_debug_pause
129 fi
130 }
131
132 function locate_wim {
133 vt_windows_locate_wim_patch (loop)
134
135 if [ -n "${vtdebug_flag}" ]; then
136 echo '###############################################'
137 vt_dump_wim_patch
138 echo '###############################################'
139 ventoy_debug_pause
140 fi
141 }
142
143 function distro_specify_wim_patch {
144 if [ -d (loop)/h3pe ]; then
145 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
146 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
147 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
148 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
149 fi
150 }
151
152 function distro_specify_wim_patch_phase2 {
153 if [ -f (loop)/boot/boot.wim ]; then
154 vt_windows_collect_wim_patch wim /boot/boot.wim
155 fi
156 }
157
158
159 function distro_specify_initrd_file {
160 if [ -e (loop)/boot/all.rdz ]; then
161 vt_linux_specify_initrd_file /boot/all.rdz
162 elif [ -e (loop)/boot/xen.gz ]; then
163 if [ -e (loop)/install.img ]; then
164 vt_linux_specify_initrd_file /install.img
165 fi
166 elif [ -d (loop)/casper ]; then
167 if [ -e (loop)/casper/initrd ]; then
168 vt_linux_specify_initrd_file /casper/initrd
169 fi
170 if [ -e (loop)/casper/initrd.gz ]; then
171 vt_linux_specify_initrd_file /casper/initrd.gz
172 fi
173 if [ -e (loop)/casper/initrd-oem ]; then
174 vt_linux_specify_initrd_file /casper/initrd-oem
175 fi
176 elif [ -e (loop)/boot/grub/initrd.xz ]; then
177 vt_linux_specify_initrd_file /boot/grub/initrd.xz
178 elif [ -e (loop)/initrd.gz ]; then
179 vt_linux_specify_initrd_file /initrd.gz
180 elif [ -e (loop)/slax/boot/initrfs.img ]; then
181 vt_linux_specify_initrd_file /slax/boot/initrfs.img
182 elif [ -e (loop)/pmagic/initrd.img ]; then
183 vt_linux_specify_initrd_file /pmagic/initrd.img
184 elif [ -e (loop)/boot/initrd.xz ]; then
185 vt_linux_specify_initrd_file /boot/initrd.xz
186 elif [ -e (loop)/boot/initrd.gz ]; then
187 vt_linux_specify_initrd_file /boot/initrd.gz
188 elif [ -f (loop)/boot/initrd ]; then
189 vt_linux_specify_initrd_file /boot/initrd
190 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
191 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
192 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
193 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
194 elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
195 vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
196
197
198 fi
199
200 if [ -f (loop)/isolinux/initrd.gz ]; then
201 vt_linux_specify_initrd_file /isolinux/initrd.gz
202 fi
203
204 if [ "$vt_chosen_size" = "1133375488" ]; then
205 if [ -d (loop)/boot/grub/x86_64-efi ]; then
206 vt_cpio_busybox64 "64h"
207 fi
208 fi
209 }
210
211
212 function distro_specify_initrd_file_phase2 {
213 if [ -f (loop)/boot/initrd.img ]; then
214 vt_linux_specify_initrd_file /boot/initrd.img
215 elif [ -f (loop)/Setup/initrd.gz ]; then
216 vt_linux_specify_initrd_file /Setup/initrd.gz
217 elif [ -f (loop)/isolinux/initramfs ]; then
218 vt_linux_specify_initrd_file /isolinux/initramfs
219 elif [ -f (loop)/boot/iniramfs.igz ]; then
220 vt_linux_specify_initrd_file /boot/iniramfs.igz
221 elif [ -f (loop)/initrd-x86_64 ]; then
222 vt_linux_specify_initrd_file /initrd-x86_64
223 elif [ -f (loop)/live/initrd.img ]; then
224 vt_linux_specify_initrd_file /live/initrd.img
225 elif [ -f (loop)/initrd.img ]; then
226 vt_linux_specify_initrd_file /initrd.img
227 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
228 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
229 elif [ -f (loop)/CDlinux/initrd ]; then
230 vt_linux_specify_initrd_file /CDlinux/initrd
231 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
232 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
233 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
234 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
235 fi
236 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
237 vt_linux_specify_initrd_file /parabola/boot/x86_64/initramfs-linux-libre.img
238 if [ -f (loop)/parabola/boot/i686/initramfs-linux-libre.img ]; then
239 vt_linux_specify_initrd_file /parabola/boot/i686/initramfs-linux-libre.img
240 fi
241 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
242 vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
243 if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
244 vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
245 fi
246 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
247 #Qubes
248 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
249 if [ "$grub_platform" != "pc" ]; then
250 vt_add_replace_file 0 "initrd.img"
251 fi
252 elif [ -f (loop)/initrd ]; then
253 vt_linux_specify_initrd_file /initrd
254 elif [ -f (loop)/live/initrd1 ]; then
255 vt_linux_specify_initrd_file /live/initrd1
256 elif [ -f (loop)/isolinux/initrd.img ]; then
257 vt_linux_specify_initrd_file /isolinux/initrd.img
258 elif [ -f (loop)/isolinux/initrd.gz ]; then
259 vt_linux_specify_initrd_file /isolinux/initrd.gz
260 elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
261 vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
262 elif vt_strstr "$vt_volume_id" "Daphile"; then
263 vt_linux_parse_initrd_isolinux (loop)/isolinux/
264 elif [ -f (loop)/boot/rootfs.xz ]; then
265 vt_linux_specify_initrd_file /boot/rootfs.xz
266 if [ "$grub_platform" != "pc" ]; then
267 vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
268 fi
269 elif [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
270 vt_linux_specify_initrd_file /arch/boot/x86_64/archiso.img
271 if [ "$grub_platform" != "pc" ]; then
272 vt_add_replace_file 0 "EFI\\archiso\\archiso.img"
273 fi
274 elif [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
275 vt_linux_specify_initrd_file /blackarch/boot/x86_64/archiso.img
276 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
277 vt_linux_specify_initrd_file /blackarch/boot/x86_64/initramfs-linux.img
278
279 elif [ -f (loop)/install.amd/initrd.gz ]; then
280 vt_linux_specify_initrd_file /live/initrd2.img
281 vt_linux_specify_initrd_file /install.amd/initrd.gz
282 vt_linux_specify_initrd_file /install.amd/gtk/initrd.gz
283 elif [ -f (loop)/boot/grub/kernels.cfg ]; then
284 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
285 elif [ -f (loop)/austrumi/initrd.gz ]; then
286 vt_linux_specify_initrd_file /austrumi/initrd.gz
287 if [ -f (loop)/EFI/BOOT/bootx64.efi ]; then
288 vt_cpio_busybox64 "64h"
289 fi
290
291 fi
292 }
293
294 function ventoy_get_ghostbsd_ver {
295
296 # vt_parse_iso_create_date "$1/${chosen_path}" vt_create_date
297 # if regexp "^202005" "$vt_create_date"; then
298 # set vt_freebsd_ver=12.x
299 # fi
300
301 set vt_freebsd_ver=12.x
302 }
303
304 function ventoy_get_furybsd_ver {
305 if regexp "13\.[0-9]" "$2"; then
306 set vt_freebsd_ver=13.x
307 else
308 set vt_freebsd_ver=12.x
309 fi
310 }
311
312 function ventoy_get_freenas_ver {
313 set vt_freebsd_ver=11.x
314
315 if [ -e (loop)/FreeNAS-MANIFEST ]; then
316 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
317 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
318 set vt_freebsd_ver=13.x
319 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
320 set vt_freebsd_ver=12.x
321 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
322 set vt_freebsd_ver=11.x
323 fi
324 fi
325 }
326
327 function ventoy_get_truenas_ver {
328 set vt_freebsd_ver=12.x
329
330 if [ -e (loop)/TrueNAS-MANIFEST ]; then
331 vt_parse_freenas_ver (loop)/TrueNAS-MANIFEST vt_truenas_ver
332 if regexp "^13\.[0-9]" "$vt_truenas_ver"; then
333 set vt_freebsd_ver=13.x
334 elif regexp "^12\.[0-9]" "$vt_truenas_ver"; then
335 set vt_freebsd_ver=12.x
336 elif regexp "^11\.[0-9]" "$vt_truenas_ver"; then
337 set vt_freebsd_ver=11.x
338 fi
339 fi
340 }
341
342 function ventoy_get_midnightbsd_ver {
343 set vt_freebsd_ver=11.x
344 }
345
346 function ventoy_freebsd_proc {
347 set vtFreeBsdDistro=FreeBSD
348
349 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
350 ventoy_get_ghostbsd_ver "$1" "${chosen_path}"
351 elif vt_strstr "$vt_volume_id" "FREENAS"; then
352 ventoy_get_freenas_ver "$1" "${chosen_path}"
353 elif vt_strstr "$vt_volume_id" "TRUENAS"; then
354 ventoy_get_truenas_ver "$1" "${chosen_path}"
355 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
356 ventoy_get_furybsd_ver "$1" "${chosen_path}"
357 elif regexp "^13_[0-9]" "$vt_volume_id"; then
358 set vt_freebsd_ver=13.x
359 elif regexp "^12_[0-9]" "$vt_volume_id"; then
360 set vt_freebsd_ver=12.x
361 elif regexp "^11_[0-9]" "$vt_volume_id"; then
362 set vt_freebsd_ver=11.x
363 elif regexp "^10_[0-9]" "$vt_volume_id"; then
364 set vt_freebsd_ver=10.x
365 elif regexp "^9_[0-9]" "$vt_volume_id"; then
366 set vt_freebsd_ver=9.x
367 elif [ -d (loop)/usr/midnightbsd-dist ]; then
368 ventoy_get_midnightbsd_ver "$1" "${chosen_path}"
369 set vtFreeBsdDistro=MidnightBSD
370 elif [ -e (loop)/bin/freebsd-version ]; then
371 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
372 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
373 set vt_freebsd_ver=13.x
374 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
375 set vt_freebsd_ver=12.x
376 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
377 set vt_freebsd_ver=11.x
378 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
379 set vt_freebsd_ver=10.x
380 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
381 set vt_freebsd_ver=9.x
382 fi
383 elif [ -e (loop)/README.TXT ]; then
384 vt_1st_line (loop)/README.TXT vt_freebsd_line1
385 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
386 set vt_freebsd_ver=13.x
387 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
388 set vt_freebsd_ver=12.x
389 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
390 set vt_freebsd_ver=11.x
391 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
392 set vt_freebsd_ver=10.x
393 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
394 set vt_freebsd_ver=9.x
395 fi
396 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
397 set vt_freebsd_ver=9.x
398 else
399 set vt_freebsd_ver=12.x
400 fi
401
402 set vt_freebsd_bit=64
403 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
404 if [ -e (loop)/$file ]; then
405 if file --is-i386-kfreebsd (loop)/$file; then
406 set vt_freebsd_bit=32
407 fi
408 break
409 fi
410 done
411
412 if [ -n "${vtdebug_flag}" ]; then
413 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
414 fi
415
416 unset vt_unix_mod_path
417 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/TrueNAS-MANIFEST" "/version" "/etc/fstab"; do
418 if [ -e (loop)${file} ]; then
419 set vt_unix_mod_path=${file}
420 break
421 fi
422 done
423
424 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
425 set vtFreeBsdDistro=ClonOS
426 fi
427
428 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
429 vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
430 }
431
432 function ventoy_dragonfly_proc {
433
434 unset vt_unix_mod_path
435 for file in "/boot/kernel/initrd.img.gz"; do
436 if [ -e (loop)${file} ]; then
437 set vt_unix_mod_path=${file}
438 break
439 fi
440 done
441
442 vt_unix_replace_ko $vt_unix_mod_path ${vtoy_path}/dragonfly.mfs.xz
443 vt_unix_fill_image_desc
444 vt_unix_gzip_new_ko
445 vt_unix_replace_conf DragonFly "${1}${chosen_path}"
446 }
447
448 function ventoy_unix_comm_proc {
449 vt_unix_reset
450
451 if [ "$ventoy_compatible" = "NO" ]; then
452 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
453
454 if [ "$vt_unix_type" = "FreeBSD" ]; then
455 ventoy_freebsd_proc "$1" "${chosen_path}"
456 elif [ "$vt_unix_type" = "DragonFly" ]; then
457 ventoy_dragonfly_proc "$1" "${chosen_path}"
458 elif [ "$vt_unix_type" = "NetBSD" ]; then
459 echo "NetBSD not supported"
460
461
462 else
463 if [ -n "${vtdebug_flag}" ]; then
464 echo "Unknown unix type"
465 fi
466 fi
467 fi
468
469 vt_unix_chain_data "${1}${chosen_path}"
470 ventoy_debug_pause
471 }
472
473
474 function uefi_windows_menu_func {
475 vt_windows_reset
476
477 if [ "$ventoy_compatible" = "NO" ]; then
478
479 if [ "$ventoy_fs_probe" = "iso9660" ]; then
480 loopback -d loop
481 vt_iso9660_nojoliet 1
482 loopback loop "$1$2"
483 fi
484
485 for file in "efi/microsoft/boot/bcd"; do
486 vt_windows_collect_wim_patch bcd (loop)/$file
487 done
488
489 vt_windows_count_wim_patch vt_wim_cnt
490 if [ $vt_wim_cnt -eq 0 ]; then
491 distro_specify_wim_patch_phase2
492 fi
493
494 ventoy_debug_pause
495 locate_wim
496 fi
497
498 vt_windows_chain_data "${1}${chosen_path}"
499 ventoy_debug_pause
500
501 if [ -n "$vtoy_chain_mem_addr" ]; then
502 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
503 ventoy_cli_console
504 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}
505 boot
506 else
507 echo "chain empty failed"
508 ventoy_pause
509 fi
510 }
511
512 function uefi_linux_menu_func {
513
514 if [ "$ventoy_compatible" = "NO" ]; then
515
516 if [ "$ventoy_fs_probe" = "udf" ]; then
517 loopback -d loop
518 set ventoy_fs_probe=iso9660
519 loopback loop "$1$2"
520 fi
521
522 vt_load_cpio ${vtoy_path}/ventoy.cpio "$2" "$1" "busybox=$ventoy_busybox_ver"
523
524 vt_linux_clear_initrd
525
526 if [ -d (loop)/pmagic ]; then
527 vt_linux_specify_initrd_file /pmagic/initrd.img
528 else
529 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
530 if [ -e (loop)/$file ]; then
531 vt_linux_parse_initrd_grub file (loop)/$file
532 fi
533 done
534 fi
535
536 # special process for special distros
537 if [ -d (loop)/loader/entries ]; then
538 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
539 elif [ -d (loop)/boot/grub ]; then
540 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
541 fi
542
543 distro_specify_initrd_file
544
545 vt_linux_initrd_count vtcount
546
547 if [ $vtcount -eq 0 ]; then
548 distro_specify_initrd_file_phase2
549
550 if [ "$vt_efi_dir" = "NO" ]; then
551 if [ -f (loop)/efi.img ]; then
552 vt_add_replace_file 0 "initrd"
553 fi
554 fi
555 fi
556
557 locate_initrd
558
559 if [ -d (loop)/loader/entries ]; then
560 vt_linux_get_main_initrd_index vtindex
561
562 if [ -d (loop)/arch ]; then
563 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
564 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
565 elif [ -f (loop)/arch/boot/x86_64/initramfs-linux.img ]; then
566 vt_add_replace_file $vtindex "arch\\boot\\x86_64\\initramfs-linux.img"
567 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
568 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
569 fi
570 elif [ -d (loop)/blackarch ]; then
571 if [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
572 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
573 elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
574 vt_add_replace_file $vtindex "blackarch\\boot\\x86_64\\initramfs-linux.img"
575 fi
576 elif [ -d (loop)/anarchy ]; then
577 if [ -f (loop)/anarchy/boot/x86_64/initramfs-linux.img ]; then
578 vt_add_replace_file $vtindex "anarchy\\boot\\x86_64\\initramfs-linux.img"
579 fi
580 elif [ -d (loop)/parabola ]; then
581 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
582 vt_add_replace_file $vtindex "EFI\\parabolaiso\\parabolaiso.img"
583 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
584 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
585 fi
586 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
587 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
588 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
589 vt_add_replace_file $vtindex "boot\\initrd"
590 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
591 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
592 fi
593 elif [ -d (loop)/EFI/boot/entries ]; then
594 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
595 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
596 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
597 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
598 fi
599 elif [ -d (loop)/EFI/BOOT/entries ]; then
600 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
601 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
602 elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
603 vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
604 fi
605 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
606 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
607 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
608
609
610 fi
611
612 fi
613
614 vt_linux_chain_data "${1}${chosen_path}"
615
616 if [ -n "$vtoy_chain_mem_addr" ]; then
617 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
618 ventoy_cli_console
619 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}
620 boot
621 else
622 echo "chain empty failed"
623 ventoy_pause
624 fi
625 }
626
627 function uefi_unix_menu_func {
628 ventoy_unix_comm_proc $1 "${chosen_path}"
629
630 if [ -n "$vtoy_chain_mem_addr" ]; then
631 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
632 ventoy_cli_console
633 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}
634 boot
635 else
636 echo "chain empty failed"
637 ventoy_pause
638 fi
639 }
640
641 function uefi_iso_menu_func {
642
643 if [ -d (loop)/ ]; then
644 loopback -d loop
645 fi
646
647 if [ -n "$vtisouefi" ]; then
648 set LoadIsoEfiDriver=on
649 unset vtisouefi
650 elif vt_check_mode 2; then
651 set LoadIsoEfiDriver=on
652 else
653 unset LoadIsoEfiDriver
654 fi
655
656 set chosen_path="$2"
657 vt_select_auto_install "${chosen_path}"
658 vt_select_persistence "${chosen_path}"
659
660 if vt_is_udf "${1}${chosen_path}"; then
661 set ventoy_fs_probe=udf
662 else
663 set ventoy_fs_probe=iso9660
664 vt_iso9660_nojoliet 0
665 fi
666
667 loopback loop "${1}${chosen_path}"
668 get_os_type (loop)
669
670 if [ -d (loop)/EFI ]; then
671 set vt_efi_dir=YES
672 elif [ -d (loop)/efi ]; then
673 set vt_efi_dir=YES
674 else
675 set vt_efi_dir=NO
676 fi
677
678 if [ -n "$vtcompat" ]; then
679 set ventoy_compatible=YES
680 unset vtcompat
681 elif vt_check_mode 1; then
682 set ventoy_compatible=YES
683 else
684 vt_check_compatible (loop)
685 fi
686
687 vt_img_sector "${1}${chosen_path}"
688
689 if [ "$ventoy_fs_probe" = "iso9660" ]; then
690 vt_select_conf_replace "${1}" "${chosen_path}"
691 fi
692
693 if [ "$vtoy_os" = "Windows" ]; then
694 vt_check_compatible_pe (loop)
695 uefi_windows_menu_func "$1" "${chosen_path}"
696 elif [ "$vtoy_os" = "Unix" ]; then
697 uefi_unix_menu_func "$1" "${chosen_path}"
698 else
699 uefi_linux_menu_func "$1" "${chosen_path}"
700 fi
701
702 ventoy_gui_console
703 }
704
705 function uefi_iso_memdisk {
706 echo 'Loading ISO file to memory ...'
707 vt_load_img_memdisk "${1}${2}" vtoy_iso_buf
708
709 ventoy_cli_console
710 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}
711 boot
712
713 ventoy_gui_console
714 }
715
716
717 function legacy_windows_menu_func {
718 vt_windows_reset
719
720 if [ "$ventoy_compatible" = "NO" ]; then
721
722 if [ "$ventoy_fs_probe" = "iso9660" ]; then
723 loopback -d loop
724 vt_iso9660_nojoliet 1
725 loopback loop "$1$2"
726 fi
727
728 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
729 vt_windows_collect_wim_patch bcd (loop)/$file
730 done
731
732 distro_specify_wim_patch
733
734 vt_windows_count_wim_patch vt_wim_cnt
735 if [ $vt_wim_cnt -eq 0 ]; then
736 distro_specify_wim_patch_phase2
737 fi
738
739 ventoy_debug_pause
740 locate_wim
741 fi
742
743 vt_windows_chain_data "${1}${chosen_path}"
744 ventoy_debug_pause
745
746 if [ -n "$vtoy_chain_mem_addr" ]; then
747 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
748 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
749 boot
750 else
751 echo "chain empty failed"
752 ventoy_pause
753 fi
754 }
755
756 function legacy_linux_menu_func {
757 if [ "$ventoy_compatible" = "NO" ]; then
758
759 if [ "$ventoy_fs_probe" = "udf" ]; then
760 loopback -d loop
761 set ventoy_fs_probe=iso9660
762 loopback loop "$1$2"
763 fi
764
765 vt_load_cpio $vtoy_path/ventoy.cpio "$2" "$1" "busybox=$ventoy_busybox_ver"
766
767 vt_linux_clear_initrd
768
769 if [ -d (loop)/pmagic ]; then
770 vt_linux_specify_initrd_file /pmagic/initrd.img
771 else
772 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
773 if [ -d (loop)/$dir ]; then
774 vt_linux_parse_initrd_isolinux (loop)/$dir/
775 fi
776 done
777 fi
778
779 # special process for special distros
780 #archlinux
781 if [ -d (loop)/arch/boot/syslinux ]; then
782 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
783 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
784 elif [ -d (loop)/anarchy/boot/syslinux ]; then
785 vt_linux_parse_initrd_isolinux (loop)/anarchy/boot/syslinux/ /anarchy/
786
787 #manjaro
788 elif [ -d (loop)/manjaro ]; then
789 if [ -e (loop)/boot/grub/kernels.cfg ]; then
790 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
791 fi
792 elif [ -e (loop)/boot/grub/grub.cfg ]; then
793 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
794 fi
795
796 distro_specify_initrd_file
797
798 vt_linux_initrd_count vtcount
799 if [ $vtcount -eq 0 ]; then
800 if [ -d (loop)/rancheros ]; then
801 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
802 fi
803
804 distro_specify_initrd_file_phase2
805 fi
806
807 locate_initrd
808 fi
809
810 vt_linux_chain_data "${1}${chosen_path}"
811 ventoy_debug_pause
812
813 if [ -n "$vtoy_chain_mem_addr" ]; then
814 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
815 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
816 boot
817 else
818 echo "chain empty failed"
819 ventoy_pause
820 fi
821 }
822
823
824 function legacy_unix_menu_func {
825 ventoy_unix_comm_proc $1 "${chosen_path}"
826
827 if [ -n "$vtoy_chain_mem_addr" ]; then
828 #ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
829 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
830 boot
831 else
832 echo "chain empty failed"
833 ventoy_pause
834 fi
835 }
836
837
838 function legacy_iso_menu_func {
839
840 if [ -d (loop)/ ]; then
841 loopback -d loop
842 fi
843
844 set chosen_path="$2"
845
846 vt_select_auto_install "${chosen_path}"
847 vt_select_persistence "${chosen_path}"
848
849 if vt_is_udf "${1}${chosen_path}"; then
850 set ventoy_fs_probe=udf
851 else
852 set ventoy_fs_probe=iso9660
853 vt_iso9660_nojoliet 0
854 fi
855
856 loopback loop "${1}${chosen_path}"
857
858 get_os_type (loop)
859
860 if [ -n "$vtcompat" ]; then
861 set ventoy_compatible=YES
862 unset vtcompat
863 elif vt_check_mode 1; then
864 set ventoy_compatible=YES
865 else
866 vt_check_compatible (loop)
867 fi
868
869 vt_img_sector "${1}${chosen_path}"
870
871 if [ "$ventoy_fs_probe" = "iso9660" ]; then
872 vt_select_conf_replace "${1}" "${chosen_path}"
873 fi
874
875 if [ "$vtoy_os" = "Windows" ]; then
876 vt_check_compatible_pe (loop)
877 legacy_windows_menu_func "$1" "${chosen_path}"
878 elif [ "$vtoy_os" = "Unix" ]; then
879 legacy_unix_menu_func "$1" "${chosen_path}"
880 else
881 legacy_linux_menu_func "$1" "${chosen_path}"
882 fi
883 }
884
885 function legacy_iso_memdisk {
886
887 linux16 $vtoy_path/memdisk iso raw
888 echo "Loading ISO file to memory ..."
889 initrd16 "${1}${2}"
890 boot
891 }
892
893
894 function iso_endless_os_proc {
895 if [ -d (loop)/ ]; then
896 loopback -d loop
897 fi
898
899 loopback loop "${1}${2}"
900 vt_img_sector "${1}${2}"
901
902 vt_load_cpio $vtoy_path/ventoy.cpio "$2" "$1" "busybox=$ventoy_busybox_ver"
903 vt_trailer_cpio "$1" "$2" noinit
904
905 ventoy_debug_pause
906
907 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
908
909 set eosimage=loop
910 set ventoy_bls_bootdev=/boot
911 set ventoy_loading_tip="Loading files ......"
912
913 export eosimage
914 configfile (loop)/endless/grub/grub.cfg
915
916 unset eosimage
917 unset ventoy_bls_bootdev
918 unset ventoy_loading_tip
919
920 vt_unset_boot_opt
921 }
922
923
924 function ventoy_iso_busybox_ver {
925
926 if [ "$VTOY_EFI_ARCH" = "aa64" ]; then
927 set ventoy_busybox_ver=a64
928 else
929 set ventoy_busybox_ver=32
930
931 #special process for deepin-live iso
932 if [ "$vt_chosen_size" = "403701760" ]; then
933 if vt_str_str "$vt_chosen_path" "/deepin-live"; then
934 set ventoy_busybox_ver=64
935 fi
936 elif vt_str_begin "$vt_volume_id" "PHOTON_"; then
937 set ventoy_busybox_ver=64
938 elif vt_str_begin "$vt_volume_id" "smgl-test-quinq-x86_64"; then
939 set ventoy_busybox_ver=64
940
941 fi
942 fi
943 }
944
945 function iso_common_menuentry {
946 unset vt_system_id
947 unset vt_volume_id
948
949 vt_chosen_img_path vt_chosen_path vt_chosen_size
950 vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id
951
952 if vt_check_password "${vt_chosen_path}"; then
953 return
954 fi
955
956 if vt_str_begin "$vt_volume_id" "Avira"; then
957 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
958 fi
959
960 ventoy_iso_busybox_ver
961
962 #special process for Endless OS
963 if vt_str_begin "$vt_volume_id" "Endless-OS"; then
964 iso_endless_os_proc $vtoy_iso_part "$vt_chosen_path"
965 elif vt_str_begin "$vt_volume_id" "TENS-Public"; then
966 set vtcompat=1
967 fi
968
969 if [ "$grub_platform" = "pc" ]; then
970 if vt_check_mode 0; then
971 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
972 else
973 legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
974 fi
975 else
976 if vt_check_mode 0; then
977 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
978 else
979 uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
980 fi
981 fi
982 }
983
984 function miso_common_menuentry {
985 vt_chosen_img_path vt_chosen_path vt_chosen_size
986
987 if vt_check_password "${vt_chosen_path}"; then
988 return
989 fi
990
991 echo "memdisk mode boot for $vt_chosen_path"
992 echo ""
993 ventoy_debug_pause
994
995 if [ "$grub_platform" = "pc" ]; then
996 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
997 else
998 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
999 fi
1000 }
1001
1002
1003 function common_unsupport_menuentry {
1004 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
1005 echo -e " 文件名中不能有中文或空格 \n"
1006 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1007 read vtInputKey
1008 }
1009
1010 function miso_unsupport_menuentry {
1011 common_unsupport_menuentry
1012 }
1013
1014 function iso_unsupport_menuentry {
1015 common_unsupport_menuentry
1016 }
1017
1018 function wim_common_menuentry {
1019 vt_chosen_img_path vt_chosen_path vt_chosen_size
1020
1021 if vt_check_password "${vt_chosen_path}"; then
1022 return
1023 fi
1024
1025 if vt_wim_check_bootable "${vtoy_iso_part}${vt_chosen_path}"; then
1026 vt_wim_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1027 else
1028 echo -e "\n This is NOT a bootable WIM file. \n"
1029 echo -e " 这不是一个可启动的 WIM 文件。\n"
1030 fi
1031
1032 ventoy_debug_pause
1033
1034 if [ -n "$vtoy_chain_mem_addr" ]; then
1035 if [ "$grub_platform" = "pc" ]; then
1036 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1037 else
1038 ventoy_cli_console
1039 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}
1040 ventoy_gui_console
1041 fi
1042 boot
1043 else
1044 echo "chain empty failed"
1045 ventoy_pause
1046 fi
1047 }
1048
1049 function wim_unsupport_menuentry {
1050 common_unsupport_menuentry
1051 }
1052
1053 function efi_common_menuentry {
1054 vt_chosen_img_path vt_chosen_path vt_chosen_size
1055
1056 if vt_check_password "${vt_chosen_path}"; then
1057 return
1058 fi
1059
1060 vt_concat_efi_iso "${vtoy_iso_part}${vt_chosen_path}" vtoy_iso_buf
1061
1062 ventoy_debug_pause
1063
1064 ventoy_cli_console
1065
1066 unset vtoy_dotefi_retry
1067 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}
1068 boot
1069
1070 if [ -n "$vtoy_dotefi_retry" ]; then
1071 unset vtoy_dotefi_retry
1072 chainloader "${vtoy_iso_part}${vt_chosen_path}"
1073 boot
1074 fi
1075
1076 ventoy_gui_console
1077 }
1078
1079 function efi_unsupport_menuentry {
1080 common_unsupport_menuentry
1081 }
1082
1083 function vhd_common_menuentry {
1084
1085 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
1086 if [ "$vtoy_iso_fs" != "ntfs" ]; then
1087 echo -e "!!! WARNING !!!\n"
1088 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
1089 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
1090 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
1091 read vtInputKey
1092 fi
1093 fi
1094
1095 vt_chosen_img_path vt_chosen_path vt_chosen_size
1096
1097 if vt_check_password "${vt_chosen_path}"; then
1098 return
1099 fi
1100
1101 vt_patch_vhdboot "$vt_chosen_path"
1102
1103 ventoy_debug_pause
1104
1105 if [ -n "$vtoy_vhd_buf_addr" ]; then
1106 if [ "$grub_platform" = "pc" ]; then
1107 linux16 $vtoy_path/memdisk iso raw
1108 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1109 boot
1110 else
1111 ventoy_cli_console
1112 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}
1113 boot
1114 ventoy_gui_console
1115 fi
1116 else
1117 echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
1118 ventoy_pause
1119 fi
1120 }
1121
1122 function vhd_unsupport_menuentry {
1123 common_unsupport_menuentry
1124 }
1125
1126 function vtoyboot_common_func {
1127 set AltBootPart=0
1128 set vtoysupport=0
1129
1130 vt_get_vtoy_type "${1}" vtoytype parttype AltBootPart
1131
1132 if vt_str_begin $vtoytype vhd; then
1133 set vtoysupport=1
1134 elif [ "$vtoytype" = "raw" ]; then
1135 set vtoysupport=1
1136 elif [ "$vtoytype" = "vdi" ]; then
1137 set vtoysupport=1
1138 fi
1139
1140 if [ $vtoysupport -eq 1 ]; then
1141 if [ "$grub_platform" = "pc" ]; then
1142 if [ "$parttype" = "gpt" -a $AltBootPart -eq 0 ]; then
1143 echo "The OS in the vdisk was created in UEFI mode, but current is Legacy BIOS mode."
1144 echo "虚拟磁盘内的系统是在UEFI模式下创建的,而当前系统是Legacy BIOS模式,可能无法正常启动。"
1145 ventoy_pause
1146 fi
1147 else
1148 if [ "$parttype" = "mbr" -a $AltBootPart -eq 0 ]; then
1149 echo "The OS in the vdisk was created in Legacy BIOS mode, but current is UEFI mode."
1150 echo "虚拟磁盘内的系统是在Legacy BIOS模式下创建的,而当前系统是UEFI模式,可能无法正常启动。"
1151 ventoy_pause
1152 fi
1153 fi
1154
1155 vt_img_sector "${1}"
1156 vt_raw_chain_data "${1}"
1157
1158 ventoy_debug_pause
1159
1160 if [ -n "$vtoy_chain_mem_addr" ]; then
1161 if [ "$grub_platform" = "pc" ]; then
1162 vt_acpi_param ${vtoy_chain_mem_addr} 512
1163 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} bios80 sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1164 boot
1165 else
1166 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
1167 ventoy_cli_console
1168 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}
1169 boot
1170 ventoy_gui_console
1171 fi
1172 else
1173 echo "chain empty failed!"
1174 ventoy_pause
1175 fi
1176 else
1177 echo "Unsupported vtoy type $vtoytype"
1178 ventoy_pause
1179 fi
1180 }
1181
1182 function vtoy_common_menuentry {
1183 vt_chosen_img_path vt_chosen_path vt_chosen_size
1184
1185 if vt_check_password "${vt_chosen_path}"; then
1186 return
1187 fi
1188
1189 vtoyboot_common_func "${vtoy_iso_part}${vt_chosen_path}"
1190 }
1191
1192 function vtoy_unsupport_menuentry {
1193 common_unsupport_menuentry
1194 }
1195
1196 #
1197 #============================================================#
1198 # IMG file boot process #
1199 #============================================================#
1200 #
1201
1202
1203 function ventoy_img_easyos {
1204 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1205 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1206
1207 loopback easysfs (vtimghd,1)/easy.sfs
1208 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1209
1210 if [ -n "$vt_module_ver" ]; then
1211 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1212 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1213 done
1214 fi
1215
1216 ventoy_debug_pause
1217
1218 #boot image file
1219 vt_set_boot_opt rdinit=/vtoy/vtoy
1220 vt_img_hook_root
1221
1222 syslinux_configfile (vtimghd,1)/syslinux.cfg
1223
1224 vt_img_unhook_root
1225 vt_unset_boot_opt
1226 loopback -d easysfs
1227 }
1228
1229 function ventoy_img_volumio {
1230 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1231 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1232
1233 ventoy_debug_pause
1234
1235 #boot image file
1236 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1237 vt_img_hook_root
1238
1239 syslinux_configfile (vtimghd,1)/syslinux.cfg
1240
1241 vt_img_unhook_root
1242 vt_unset_boot_opt
1243 }
1244
1245 function ventoy_img_openelec {
1246 elec_ver=$1
1247
1248 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1249 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1250
1251 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1252 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1253
1254 ventoy_debug_pause
1255
1256 #boot image file
1257 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1258 vt_img_hook_root
1259
1260 set root=(vtimghd,1)
1261 syslinux_configfile (vtimghd,1)/syslinux.cfg
1262
1263 vt_img_unhook_root
1264 vt_unset_boot_opt
1265 loopback -d vtloopex
1266 }
1267
1268
1269 function ventoy_img_freedombox {
1270 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1271 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1272
1273 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1274 if [ -n "$vt_module_ver" ]; then
1275 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1276 fi
1277
1278 ventoy_debug_pause
1279
1280 #boot image file
1281 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1282 vt_img_hook_root
1283
1284 configfile (vtimghd,1)/boot/grub/grub.cfg
1285
1286 vt_img_unhook_root
1287 vt_unset_boot_opt
1288 }
1289
1290 function ventoy_img_paldo {
1291 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1292 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1293
1294 ventoy_debug_pause
1295
1296 #boot image file
1297 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1298 vt_img_hook_root
1299
1300 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1301 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1302
1303 echo loading file...
1304 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1305 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1306 boot
1307
1308 vt_img_unhook_root
1309 vt_unset_boot_opt
1310 }
1311
1312 function ventoy_img_ubos {
1313 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1314 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1315
1316 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1317 if [ -n "$vt_module_ver" ]; then
1318 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1319 fi
1320
1321 ventoy_debug_pause
1322
1323 #boot image file
1324 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1325 vt_img_hook_root
1326
1327 echo loading file...
1328 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1329 initrd (vtimghd,2)/initramfs-linux.img
1330 boot
1331
1332 vt_img_unhook_root
1333 vt_unset_boot_opt
1334 }
1335
1336 function ventoy_img_recalbox {
1337 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1338 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1339
1340 ventoy_debug_pause
1341
1342 #boot image file
1343 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1344 vt_img_hook_root
1345
1346 set root=(vtimghd,1)
1347 configfile (vtimghd,1)/boot/grub/grub.cfg
1348
1349 vt_img_unhook_root
1350 vt_unset_boot_opt
1351 }
1352
1353 function ventoy_img_batocera {
1354 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1355 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1356
1357 ventoy_debug_pause
1358
1359 #boot image file
1360 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1361 vt_img_hook_root
1362
1363 set root=(vtimghd,1)
1364 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1365
1366 vt_img_unhook_root
1367 vt_unset_boot_opt
1368 }
1369
1370 function ventoy_img_memtest86 {
1371 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
1372 boot
1373 }
1374
1375 function img_unsupport_tip {
1376 echo -e "\n This IMG file is NOT supported now. \n"
1377 echo -e " 当前不支持启动此 IMG 文件 \n"
1378 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1379 read vtInputKey
1380 }
1381
1382 function img_common_menuentry {
1383 set ventoy_compatible=YES
1384 set ventoy_busybox_ver=32
1385
1386 vt_chosen_img_path vt_chosen_path vt_chosen_size
1387
1388 if vt_check_password "${vt_chosen_path}"; then
1389 return
1390 fi
1391
1392 if [ -d (vtimghd)/ ]; then
1393 loopback -d vtimghd
1394 fi
1395
1396 loopback vtimghd "${vtoy_iso_part}${vt_chosen_path}"
1397 vt_img_sector "${vtoy_iso_part}${vt_chosen_path}"
1398
1399 vt_img_part_info (vtimghd)
1400
1401 set vtback_root=$root
1402 ventoy_cli_console
1403 vt_push_last_entry
1404
1405 vt_img_extra_initrd_reset
1406
1407 vt_get_fs_label (vtimghd,1) vtImgHd1Label
1408 if [ -d (vtimghd,2)/lib ]; then
1409 vt_get_fs_label (vtimghd,2) vtImgHd2Label
1410 fi
1411
1412 if [ -e (vtimghd,1)/etc/hostname ]; then
1413 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
1414 fi
1415
1416 if [ -e (vtimghd,1)/easy.sfs ]; then
1417 ventoy_img_easyos
1418 elif [ -e (vtimghd,1)/volumio.initrd ]; then
1419 ventoy_img_volumio
1420 elif vt_str_begin "$vtImgHd1Label" "LAKKA"; then
1421 ventoy_img_openelec lakka
1422 elif vt_str_begin "$vtImgHd1Label" "LIBREELEC"; then
1423 ventoy_img_openelec LibreELEC
1424 elif vt_str_begin "$vtImgHd1Label" "paldo-live"; then
1425 ventoy_img_paldo
1426 elif vt_str_begin "$vtImgHostname" "freedombox"; then
1427 ventoy_img_freedombox
1428 elif vt_str_begin "$vtImgHd1Label" "BATOCERA"; then
1429 ventoy_img_batocera
1430 elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
1431 ventoy_img_recalbox
1432 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
1433 ventoy_img_ubos
1434 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
1435 if [ "$grub_platform" = "pc" ]; then
1436 img_unsupport_tip
1437 else
1438 ventoy_img_memtest86
1439 fi
1440 else
1441 vt_linux_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1442 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
1443 if [ "$grub_platform" = "pc" ]; then
1444 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1445 boot
1446 else
1447 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}
1448 boot
1449 fi
1450 fi
1451
1452 set root=$vtback_root
1453 vt_pop_last_entry
1454 ventoy_gui_console
1455 set ventoy_compatible=NO
1456 }
1457
1458 function img_unsupport_menuentry {
1459 common_unsupport_menuentry
1460 }
1461
1462 #############################################################
1463 #############################################################
1464 #############################################################
1465 ####### Main Process ###########
1466 #############################################################
1467 #############################################################
1468 #############################################################
1469
1470 set VENTOY_VERSION="1.0.31"
1471
1472 #ACPI not compatible with Window7/8, so disable by default
1473 set VTOY_PARAM_NO_ACPI=1
1474
1475 # Default menu display mode, you can change it as you want.
1476 # 0: List mode
1477 # 1: TreeView mode
1478 set VTOY_DEFAULT_MENU_MODE=0
1479
1480 set VTOY_MEM_DISK_STR="[Memdisk]"
1481 set VTOY_ISO_RAW_STR="Compatible Mode"
1482 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
1483
1484 set VTOY_F2_CMD="ventoy_power"
1485 set VTOY_F4_CMD="ventoy_localboot"
1486 set VTOY_F5_CMD="ventoy_diagnosis"
1487 set VTOY_F6_CMD="ventoy_ext_menu"
1488
1489 if [ "$grub_platform" = "pc" ]; then
1490 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1491 else
1492 if [ "$grub_cpu" = "i386" ]; then
1493 set VTOY_EFI_ARCH=ia32
1494 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION IA32 www.ventoy.net"
1495 elif [ "$grub_cpu" = "arm64" ]; then
1496 set VTOY_EFI_ARCH=aa64
1497 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION AA64 www.ventoy.net"
1498 else
1499 set VTOY_EFI_ARCH=x64
1500 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1501 fi
1502 fi
1503
1504 vt_device $root vtoy_dev
1505
1506 if [ "$vtoy_dev" = "tftp" ]; then
1507 set vtoy_path=($root)
1508 for vtid in 0 1 2 3; do
1509 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
1510 set vtoy_iso_part=(hd$vtid,1)
1511 set vtoy_efi_part=(hd$vtid,2)
1512 set vtoydev=hd$vtid
1513 break
1514 fi
1515 done
1516 loadfont ascii
1517
1518 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1519 set vt_plugin_path=$vtoy_iso_part
1520 else
1521 set vt_plugin_path=$prefix
1522 vt_load_plugin $vt_plugin_path
1523 fi
1524 else
1525 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1526 set vtoy_path=(ventoydisk)/ventoy
1527 else
1528 set vtoy_path=($root)/ventoy
1529 fi
1530
1531 set vtoydev=$vtoy_dev
1532 set vtoy_iso_part=($vtoy_dev,1)
1533 set vtoy_efi_part=($vtoy_dev,2)
1534 loadfont unicode
1535 set vt_plugin_path=$vtoy_iso_part
1536 fi
1537
1538 #Load Partition Table
1539 vt_load_part_table $vtoydev
1540
1541 #Load Plugin
1542 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1543 clear
1544 vt_load_plugin $vtoy_iso_part
1545 clear
1546 fi
1547
1548 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1549 set timeout=$VTOY_MENU_TIMEOUT
1550 else
1551 unset timeout
1552 fi
1553
1554 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1555 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1556 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1557 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1558 fi
1559
1560 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
1561 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
1562 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
1563 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
1564 fi
1565
1566
1567 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1568 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1569 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
1570 else
1571 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1572 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Tools F6:ExMenu"
1573 fi
1574
1575
1576 if [ -n "$vtoy_gfxmode" ]; then
1577 set gfxmode=$vtoy_gfxmode
1578 set gfxpayload=keep
1579 else
1580 set gfxmode=1024x768
1581 set gfxpayload=keep
1582 fi
1583
1584
1585 if [ "$vtoy_display_mode" = "CLI" ]; then
1586 terminal_output console
1587 elif [ "$vtoy_display_mode" = "serial" ]; then
1588 if [ -n "$vtoy_serial_param" ]; then
1589 serial $vtoy_serial_param
1590 fi
1591 terminal_input serial
1592 terminal_output serial
1593 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1594 if [ -n "$vtoy_serial_param" ]; then
1595 serial $vtoy_serial_param
1596 fi
1597 terminal_input serial console
1598 terminal_output serial console
1599 else
1600 if [ -n "$vtoy_theme" ]; then
1601 set theme=$vtoy_theme
1602 else
1603 set theme=$prefix/themes/ventoy/theme.txt
1604 fi
1605 terminal_output gfxterm
1606 fi
1607
1608
1609 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
1610 clear
1611 echo -e "\n Syntax error detected in ventoy.json, please check! \n"
1612 echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
1613 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
1614 read vtInputKey
1615 fi
1616
1617 #export necessary variable
1618 export theme
1619 export gfxmode
1620 export gfxpayload
1621 export vtoydev
1622 export vtoy_path
1623 export vtdebug_flag
1624 export vtoy_iso_part
1625 export vtoy_efi_part
1626 export VENTOY_VERSION
1627 export VTOY_CUR_VIDEO_MODE
1628 export VTOY_EFI_ARCH
1629
1630 #special VTOY_DEFAULT_IMAGE process
1631 if [ -n "$VTOY_DEFAULT_IMAGE" ]; then
1632 if regexp --set 1:vtHotkey --set 2:vtDefault "(F[2-9])>(.*)" "$VTOY_DEFAULT_IMAGE"; then
1633
1634 set default="$vtDefault"
1635 if [ -z "$VTOY_MENU_TIMEOUT" ]; then
1636 set timeout=0
1637 else
1638 set timeout=$VTOY_MENU_TIMEOUT
1639 fi
1640
1641 export timeout
1642 export default
1643
1644 if [ "$vtHotkey" = "F2" ]; then
1645 ventoy_power
1646 elif [ "$vtHotkey" = "F4" ]; then
1647 ventoy_localboot
1648 elif [ "$vtHotkey" = "F5" ]; then
1649 ventoy_diagnosis
1650 elif [ "$vtHotkey" = "F6" ]; then
1651 ventoy_ext_menu
1652 fi
1653
1654 unset timeout
1655 unset default
1656 fi
1657 fi
1658
1659 #colect all image files (iso files)
1660 set ventoy_img_count=0
1661 vt_list_img $vtoy_iso_part ventoy_img_count
1662
1663 #Main menu
1664 if [ $ventoy_img_count -gt 0 ]; then
1665 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1666 vt_dynamic_menu 0 0
1667 else
1668 vt_dynamic_menu 0 1
1669 fi
1670 else
1671 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1672 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1673 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1674 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1675 else
1676 NO_ISO_MENU="No ISO files found"
1677 fi
1678 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1679 echo -e "\n Rebooting ... "
1680 reboot
1681 }
1682 fi