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