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