]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
update VentoyWorker.sh for nvme
[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
256 fi
257 }
258
259 function ventoy_get_ghostbsd_ver {
260
261 # vt_parse_iso_create_date $1/${chosen_path} vt_create_date
262 # if regexp "^202005" "$vt_create_date"; then
263 # set vt_freebsd_ver=12.x
264 # fi
265
266 set vt_freebsd_ver=12.x
267 }
268
269 function ventoy_get_furybsd_ver {
270 if regexp "13\.[0-9]" "$2"; then
271 set vt_freebsd_ver=13.x
272 else
273 set vt_freebsd_ver=12.x
274 fi
275 }
276
277 function ventoy_get_freenas_ver {
278 set vt_freebsd_ver=11.x
279
280 if [ -e (loop)/FreeNAS-MANIFEST ]; then
281 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
282 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
283 set vt_freebsd_ver=13.x
284 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
285 set vt_freebsd_ver=12.x
286 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
287 set vt_freebsd_ver=11.x
288 fi
289 fi
290 }
291
292 function ventoy_get_midnightbsd_ver {
293 set vt_freebsd_ver=11.x
294 }
295
296 function ventoy_freebsd_proc {
297 set vtFreeBsdDistro=FreeBSD
298
299 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
300 ventoy_get_ghostbsd_ver $1 ${chosen_path}
301 elif vt_strstr "$vt_volume_id" "FREENAS"; then
302 ventoy_get_freenas_ver $1 ${chosen_path}
303 elif vt_strstr "$vt_volume_id" "FURYBSD"; then
304 ventoy_get_furybsd_ver $1 ${chosen_path}
305 elif regexp "^13_[0-9]" "$vt_volume_id"; then
306 set vt_freebsd_ver=13.x
307 elif regexp "^12_[0-9]" "$vt_volume_id"; then
308 set vt_freebsd_ver=12.x
309 elif regexp "^11_[0-9]" "$vt_volume_id"; then
310 set vt_freebsd_ver=11.x
311 elif regexp "^10_[0-9]" "$vt_volume_id"; then
312 set vt_freebsd_ver=10.x
313 elif regexp "^9_[0-9]" "$vt_volume_id"; then
314 set vt_freebsd_ver=9.x
315 elif [ -d (loop)/usr/midnightbsd-dist ]; then
316 ventoy_get_midnightbsd_ver $1 ${chosen_path}
317 set vtFreeBsdDistro=MidnightBSD
318 elif [ -e (loop)/bin/freebsd-version ]; then
319 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
320 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
321 set vt_freebsd_ver=13.x
322 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
323 set vt_freebsd_ver=12.x
324 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
325 set vt_freebsd_ver=11.x
326 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
327 set vt_freebsd_ver=10.x
328 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
329 set vt_freebsd_ver=9.x
330 fi
331 elif [ -e (loop)/README.TXT ]; then
332 vt_1st_line (loop)/README.TXT vt_freebsd_line1
333 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
334 set vt_freebsd_ver=13.x
335 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
336 set vt_freebsd_ver=12.x
337 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
338 set vt_freebsd_ver=11.x
339 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
340 set vt_freebsd_ver=10.x
341 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
342 set vt_freebsd_ver=9.x
343 fi
344 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
345 set vt_freebsd_ver=9.x
346 else
347 set vt_freebsd_ver=12.x
348 fi
349
350 set vt_freebsd_bit=64
351 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
352 if [ -e (loop)/$file ]; then
353 if file --is-i386-kfreebsd (loop)/$file; then
354 set vt_freebsd_bit=32
355 fi
356 break
357 fi
358 done
359
360 if [ -n "${vtdebug_flag}" ]; then
361 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
362 fi
363
364 unset vt_unix_mod_path
365 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version" "/etc/fstab"; do
366 if [ -e (loop)${file} ]; then
367 set vt_unix_mod_path=${file}
368 break
369 fi
370 done
371
372 if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
373 set vtFreeBsdDistro=ClonOS
374 fi
375
376 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
377 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
378 }
379
380 function ventoy_unix_comm_proc {
381 vt_unix_reset
382
383 if [ "$ventoy_compatible" = "NO" ]; then
384 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
385
386 if [ "$vt_unix_type" = "FreeBSD" ]; then
387 ventoy_freebsd_proc $1 ${chosen_path}
388 elif [ "$vt_unix_type" = "NetBSD" ]; then
389 echo "NetBSD not supported"
390
391
392
393 else
394 if [ -n "${vtdebug_flag}" ]; then
395 echo "Unknown unix type"
396 fi
397 fi
398 fi
399
400 vt_unix_chain_data ${1}${chosen_path}
401 ventoy_debug_pause
402 }
403
404
405 function uefi_windows_menu_func {
406 vt_windows_reset
407
408 if [ "$ventoy_compatible" = "NO" ]; then
409
410 if [ "$ventoy_fs_probe" = "iso9660" ]; then
411 loopback -d loop
412 vt_iso9660_nojoliet 1
413 loopback loop $1$2
414 fi
415
416 for file in "efi/microsoft/boot/bcd"; do
417 vt_windows_collect_wim_patch bcd (loop)/$file
418 done
419
420 vt_windows_count_wim_patch vt_wim_cnt
421 if [ $vt_wim_cnt -eq 0 ]; then
422 distro_specify_wim_patch_phase2
423 fi
424
425 ventoy_debug_pause
426 locate_wim
427 fi
428
429 vt_windows_chain_data ${1}${chosen_path}
430 ventoy_debug_pause
431
432 if [ -n "$vtoy_chain_mem_addr" ]; then
433 ventoy_cli_console
434 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
435 boot
436 else
437 echo "chain empty failed"
438 ventoy_pause
439 fi
440 }
441
442 function uefi_linux_menu_func {
443 if [ "$ventoy_compatible" = "NO" ]; then
444
445 if [ "$ventoy_fs_probe" = "udf" ]; then
446 loopback -d loop
447 set ventoy_fs_probe=iso9660
448 loopback loop $1$2
449 fi
450
451 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
452
453 vt_linux_clear_initrd
454
455 if [ -d (loop)/pmagic ]; then
456 vt_linux_specify_initrd_file /pmagic/initrd.img
457 else
458 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
459 if [ -e (loop)/$file ]; then
460 vt_linux_parse_initrd_grub file (loop)/$file
461 fi
462 done
463 fi
464
465 # special process for special distros
466 if [ -d (loop)/loader/entries ]; then
467 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
468 elif [ -d (loop)/boot/grub ]; then
469 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
470 fi
471
472 distro_specify_initrd_file
473
474 vt_linux_initrd_count vtcount
475 if [ $vtcount -eq 0 ]; then
476 distro_specify_initrd_file_phase2
477
478 if [ "$vt_efi_dir" = "NO" ]; then
479 if [ -f (loop)/efi.img ]; then
480 vt_add_replace_file 0 "initrd"
481 fi
482 fi
483 fi
484
485 locate_initrd
486
487 if [ -d (loop)/loader/entries ]; then
488 vt_linux_get_main_initrd_index vtindex
489
490 if [ -d (loop)/arch ]; then
491 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
492 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
493 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
494 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
495 fi
496 elif [ -d (loop)/parabola ]; then
497 if [ -f (loop)/parabola/boot/x86_64/parabola.img ]; then
498 vt_add_replace_file $vtindex "EFI\\parabola\\parabola.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 [ -f (loop)/EFI/BOOT/initrd.gz ]; then
503 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
504 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
505 vt_add_replace_file $vtindex "boot\\initrd"
506 elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
507 vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
508 fi
509 elif [ -d (loop)/EFI/boot/entries ]; then
510 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
511 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
512 elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
513 vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
514 fi
515 elif [ -d (loop)/EFI/BOOT/entries ]; then
516 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
517 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
518 fi
519 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
520 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
521 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
522
523
524 fi
525
526 fi
527
528 vt_linux_chain_data ${1}${chosen_path}
529
530 if [ -n "$vtoy_chain_mem_addr" ]; then
531 ventoy_cli_console
532 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}
533 boot
534 else
535 echo "chain empty failed"
536 ventoy_pause
537 fi
538 }
539
540 function uefi_unix_menu_func {
541 ventoy_unix_comm_proc $1 ${chosen_path}
542
543 if [ -n "$vtoy_chain_mem_addr" ]; then
544 ventoy_cli_console
545 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}
546 boot
547 else
548 echo "chain empty failed"
549 ventoy_pause
550 fi
551 }
552
553 function uefi_iso_menu_func {
554
555 if [ -d (loop)/ ]; then
556 loopback -d loop
557 fi
558
559 if [ -n "$vtisouefi" ]; then
560 set LoadIsoEfiDriver=on
561 unset vtisouefi
562 elif vt_check_mode 2; then
563 set LoadIsoEfiDriver=on
564 else
565 unset LoadIsoEfiDriver
566 fi
567
568 set chosen_path=$2
569 vt_select_auto_install ${chosen_path}
570 vt_select_persistence ${chosen_path}
571
572 if vt_is_udf ${1}${chosen_path}; then
573 set ventoy_fs_probe=udf
574 else
575 set ventoy_fs_probe=iso9660
576 vt_iso9660_nojoliet 0
577 fi
578
579 loopback loop ${1}${chosen_path}
580 get_os_type (loop)
581
582 if [ -d (loop)/EFI ]; then
583 set vt_efi_dir=YES
584 elif [ -d (loop)/efi ]; then
585 set vt_efi_dir=YES
586 else
587 set vt_efi_dir=NO
588 fi
589
590 if [ -n "$vtcompat" ]; then
591 set ventoy_compatible=YES
592 unset vtcompat
593 elif vt_check_mode 1; then
594 set ventoy_compatible=YES
595 else
596 vt_check_compatible (loop)
597 fi
598
599 vt_img_sector ${1}${chosen_path}
600
601 if [ "$vtoy_os" = "Windows" ]; then
602 vt_check_compatible_pe (loop)
603 uefi_windows_menu_func $1 ${chosen_path}
604 elif [ "$vtoy_os" = "Unix" ]; then
605 uefi_unix_menu_func $1 ${chosen_path}
606 else
607 uefi_linux_menu_func $1 ${chosen_path}
608 fi
609
610 ventoy_gui_console
611 }
612
613 function uefi_iso_memdisk {
614 echo 'Loading ISO file to memory ...'
615 vt_load_img_memdisk ${1}${2} vtoy_iso_buf
616
617 ventoy_cli_console
618 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}
619 boot
620
621 ventoy_gui_console
622 }
623
624
625 function legacy_windows_menu_func {
626 vt_windows_reset
627
628 if [ "$ventoy_compatible" = "NO" ]; then
629
630 if [ "$ventoy_fs_probe" = "iso9660" ]; then
631 loopback -d loop
632 vt_iso9660_nojoliet 1
633 loopback loop $1$2
634 fi
635
636 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
637 vt_windows_collect_wim_patch bcd (loop)/$file
638 done
639
640 distro_specify_wim_patch
641
642 vt_windows_count_wim_patch vt_wim_cnt
643 if [ $vt_wim_cnt -eq 0 ]; then
644 distro_specify_wim_patch_phase2
645 fi
646
647 ventoy_debug_pause
648 locate_wim
649 fi
650
651 vt_windows_chain_data ${1}${chosen_path}
652 ventoy_debug_pause
653
654 if [ -n "$vtoy_chain_mem_addr" ]; then
655 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
656 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
657 terminal_output gfxterm
658 boot
659 else
660 echo "chain empty failed"
661 ventoy_pause
662 fi
663 }
664
665 function legacy_linux_menu_func {
666 if [ "$ventoy_compatible" = "NO" ]; then
667
668 if [ "$ventoy_fs_probe" = "udf" ]; then
669 loopback -d loop
670 set ventoy_fs_probe=iso9660
671 loopback loop $1$2
672 fi
673
674 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
675
676 vt_linux_clear_initrd
677
678 if [ -d (loop)/pmagic ]; then
679 vt_linux_specify_initrd_file /pmagic/initrd.img
680 else
681 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
682 if [ -d (loop)/$dir ]; then
683 vt_linux_parse_initrd_isolinux (loop)/$dir/
684 fi
685 done
686 fi
687
688 # special process for special distros
689 #archlinux
690 if [ -d (loop)/arch/boot/syslinux ]; then
691 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
692 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
693
694 #manjaro
695 elif [ -d (loop)/manjaro ]; then
696 if [ -e (loop)/boot/grub/kernels.cfg ]; then
697 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
698 fi
699 elif [ -e (loop)/boot/grub/grub.cfg ]; then
700 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
701 fi
702
703 distro_specify_initrd_file
704
705 vt_linux_initrd_count vtcount
706 if [ $vtcount -eq 0 ]; then
707 if [ -d (loop)/rancheros ]; then
708 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
709 fi
710
711 distro_specify_initrd_file_phase2
712 fi
713
714 locate_initrd
715 fi
716
717 vt_linux_chain_data ${1}${chosen_path}
718 ventoy_debug_pause
719
720 if [ -n "$vtoy_chain_mem_addr" ]; then
721 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
722 boot
723 else
724 echo "chain empty failed"
725 ventoy_pause
726 fi
727 }
728
729
730 function legacy_unix_menu_func {
731 ventoy_unix_comm_proc $1 ${chosen_path}
732
733 if [ -n "$vtoy_chain_mem_addr" ]; then
734 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
735 boot
736 else
737 echo "chain empty failed"
738 ventoy_pause
739 fi
740 }
741
742
743 function legacy_iso_menu_func {
744
745 if [ -d (loop)/ ]; then
746 loopback -d loop
747 fi
748
749 set chosen_path=$2
750 vt_select_auto_install ${chosen_path}
751 vt_select_persistence ${chosen_path}
752
753 if vt_is_udf ${1}${chosen_path}; then
754 set ventoy_fs_probe=udf
755 else
756 set ventoy_fs_probe=iso9660
757 vt_iso9660_nojoliet 0
758 fi
759
760 loopback loop ${1}${chosen_path}
761
762 get_os_type (loop)
763
764 if [ -n "$vtcompat" ]; then
765 set ventoy_compatible=YES
766 unset vtcompat
767 elif vt_check_mode 1; then
768 set ventoy_compatible=YES
769 else
770 vt_check_compatible (loop)
771 fi
772
773 vt_img_sector ${1}${chosen_path}
774
775 if [ "$vtoy_os" = "Windows" ]; then
776 vt_check_compatible_pe (loop)
777 legacy_windows_menu_func $1 ${chosen_path}
778 elif [ "$vtoy_os" = "Unix" ]; then
779 legacy_unix_menu_func $1 ${chosen_path}
780 else
781 legacy_linux_menu_func $1 ${chosen_path}
782 fi
783 }
784
785 function legacy_iso_memdisk {
786
787 linux16 $vtoy_path/memdisk iso raw
788 echo "Loading ISO file to memory ..."
789 initrd16 ${1}${2}
790 boot
791 }
792
793
794 function iso_endless_os_proc {
795 if [ -d (loop)/ ]; then
796 loopback -d loop
797 fi
798
799 loopback loop ${1}${2}
800 vt_img_sector ${1}${2}
801
802 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1 "busybox=$ventoy_busybox_ver"
803 vt_trailer_cpio $1 $2 noinit
804
805 ventoy_debug_pause
806
807 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
808
809 set eosimage=loop
810 set ventoy_bls_bootdev=/boot
811 set ventoy_loading_tip="Loading files ......"
812
813 export eosimage
814 configfile (loop)/endless/grub/grub.cfg
815
816 unset eosimage
817 unset ventoy_bls_bootdev
818 unset ventoy_loading_tip
819
820 vt_unset_boot_opt
821 }
822
823
824 function ventoy_iso_busybox_ver {
825 set ventoy_busybox_ver=32
826
827 #special process for deepin-live iso
828 if [ "$vt_chosen_size" = "403701760" ]; then
829 if vt_str_str $vt_chosen_path "/deepin-live"; then
830 set ventoy_busybox_ver=64
831 fi
832 elif vt_str_begin $vt_volume_id "PHOTON_"; then
833 set ventoy_busybox_ver=64
834 elif vt_str_begin $vt_volume_id "smgl-test-quinq-x86_64"; then
835 set ventoy_busybox_ver=64
836
837 fi
838 }
839
840 function iso_common_menuentry {
841 unset vt_system_id
842 unset vt_volume_id
843
844 vt_chosen_img_path vt_chosen_path vt_chosen_size
845 vt_parse_iso_volume ${vtoy_iso_part}${vt_chosen_path} vt_system_id vt_volume_id
846
847 ventoy_iso_busybox_ver
848
849 #special process for Endless OS
850 if vt_str_begin $vt_volume_id "Endless-OS"; then
851 iso_endless_os_proc $vtoy_iso_part $vt_chosen_path
852 elif vt_str_begin $vt_volume_id "TENS-Public"; then
853 set vtcompat=1
854 fi
855
856 if [ "$grub_platform" = "pc" ]; then
857 if vt_check_mode 0; then
858 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
859 else
860 legacy_iso_menu_func $vtoy_iso_part $vt_chosen_path
861 fi
862 else
863 if vt_check_mode 0; then
864 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
865 else
866 uefi_iso_menu_func $vtoy_iso_part $vt_chosen_path
867 fi
868 fi
869 }
870
871 function miso_common_menuentry {
872 vt_chosen_img_path vt_chosen_path vt_chosen_size
873
874 echo "memdisk mode boot for $vt_chosen_path"
875 echo ""
876 ventoy_debug_pause
877
878 if [ "$grub_platform" = "pc" ]; then
879 legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
880 else
881 uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
882 fi
883 }
884
885
886 function common_unsupport_menuentry {
887 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
888 echo -e " 文件名中不能有中文或空格 \n"
889 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
890 read vtInputKey
891 }
892
893 function miso_unsupport_menuentry {
894 common_unsupport_menuentry
895 }
896
897 function iso_unsupport_menuentry {
898 common_unsupport_menuentry
899 }
900
901 function wim_common_menuentry {
902 vt_chosen_img_path vt_chosen_path vt_chosen_size
903 vt_wim_chain_data ${vtoy_iso_part}${vt_chosen_path}
904
905 ventoy_debug_pause
906
907 if [ -n "$vtoy_chain_mem_addr" ]; then
908 if [ "$grub_platform" = "pc" ]; then
909 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
910 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
911 terminal_output gfxterm
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
955 function vhd_common_menuentry {
956
957 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
958 if [ "$vtoy_iso_fs" != "ntfs" ]; then
959 echo -e "!!! WARNING !!!\n"
960 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
961 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
962 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
963 read vtInputKey
964 fi
965 fi
966
967 vt_chosen_img_path vt_chosen_path vt_chosen_size
968 vt_patch_vhdboot ${vt_chosen_path}
969
970 ventoy_debug_pause
971
972 if [ -n "$vtoy_vhd_buf_addr" ]; then
973 if [ "$grub_platform" = "pc" ]; then
974 linux16 $vtoy_path/memdisk iso raw
975 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
976
977 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
978 terminal_output gfxterm
979 boot
980 else
981 ventoy_cli_console
982 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}
983 boot
984 ventoy_gui_console
985 fi
986 else
987 echo "Failed to boot vhd file"
988 ventoy_pause
989 fi
990 }
991
992 function vhd_unsupport_menuentry {
993 common_unsupport_menuentry
994 }
995
996 #
997 #============================================================#
998 # IMG file boot process #
999 #============================================================#
1000 #
1001
1002
1003 function ventoy_img_easyos {
1004 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1005 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1006
1007 loopback easysfs (vtimghd,1)/easy.sfs
1008 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1009
1010 if [ -n "$vt_module_ver" ]; then
1011 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1012 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1013 done
1014 fi
1015
1016 ventoy_debug_pause
1017
1018 #boot image file
1019 vt_set_boot_opt rdinit=/vtoy/vtoy
1020 vt_img_hook_root
1021
1022 syslinux_configfile (vtimghd,1)/syslinux.cfg
1023
1024 vt_img_unhook_root
1025 vt_unset_boot_opt
1026 loopback -d easysfs
1027 }
1028
1029 function ventoy_img_volumio {
1030 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1031 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1032
1033 ventoy_debug_pause
1034
1035 #boot image file
1036 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1037 vt_img_hook_root
1038
1039 syslinux_configfile (vtimghd,1)/syslinux.cfg
1040
1041 vt_img_unhook_root
1042 vt_unset_boot_opt
1043 }
1044
1045 function ventoy_img_openelec {
1046 elec_ver=$1
1047
1048 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1049 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1050
1051 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1052 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1053
1054 ventoy_debug_pause
1055
1056 #boot image file
1057 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1058 vt_img_hook_root
1059
1060 set root=(vtimghd,1)
1061 syslinux_configfile (vtimghd,1)/syslinux.cfg
1062
1063 vt_img_unhook_root
1064 vt_unset_boot_opt
1065 loopback -d vtloopex
1066 }
1067
1068
1069 function ventoy_img_freedombox {
1070 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1071 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1072
1073 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1074 if [ -n "$vt_module_ver" ]; then
1075 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1076 fi
1077
1078 ventoy_debug_pause
1079
1080 #boot image file
1081 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1082 vt_img_hook_root
1083
1084 configfile (vtimghd,1)/boot/grub/grub.cfg
1085
1086 vt_img_unhook_root
1087 vt_unset_boot_opt
1088 }
1089
1090 function ventoy_img_paldo {
1091 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1092 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1093
1094 ventoy_debug_pause
1095
1096 #boot image file
1097 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1098 vt_img_hook_root
1099
1100 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1101 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1102
1103 echo loading file...
1104 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1105 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1106 boot
1107
1108 vt_img_unhook_root
1109 vt_unset_boot_opt
1110 }
1111
1112 function ventoy_img_ubos {
1113 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1114 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1115
1116 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1117 if [ -n "$vt_module_ver" ]; then
1118 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1119 fi
1120
1121 ventoy_debug_pause
1122
1123 #boot image file
1124 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1125 vt_img_hook_root
1126
1127 echo loading file...
1128 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1129 initrd (vtimghd,2)/initramfs-linux.img
1130 boot
1131
1132 vt_img_unhook_root
1133 vt_unset_boot_opt
1134 }
1135
1136 function ventoy_img_recalbox {
1137 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1138 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1139
1140 ventoy_debug_pause
1141
1142 #boot image file
1143 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1144 vt_img_hook_root
1145
1146 set root=(vtimghd,1)
1147 configfile (vtimghd,1)/boot/grub/grub.cfg
1148
1149 vt_img_unhook_root
1150 vt_unset_boot_opt
1151 }
1152
1153 function ventoy_img_batocera {
1154 vt_load_cpio $vtoy_path/ventoy.cpio ${vt_chosen_path} ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1155 vt_trailer_cpio ${vtoy_iso_part} ${vt_chosen_path} noinit
1156
1157 ventoy_debug_pause
1158
1159 #boot image file
1160 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1161 vt_img_hook_root
1162
1163 set root=(vtimghd,1)
1164 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1165
1166 vt_img_unhook_root
1167 vt_unset_boot_opt
1168 }
1169
1170 function ventoy_img_memtest86 {
1171 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
1172 boot
1173 }
1174
1175 function img_unsupport_tip {
1176 echo -e "\n This IMG file is NOT supported now. \n"
1177 echo -e " 当前不支持启动此 IMG 文件 \n"
1178 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1179 read vtInputKey
1180 }
1181
1182 function img_common_menuentry {
1183 set ventoy_compatible=YES
1184 set ventoy_busybox_ver=32
1185
1186 vt_chosen_img_path vt_chosen_path vt_chosen_size
1187
1188 if [ -d (vtimghd)/ ]; then
1189 loopback -d vtimghd
1190 fi
1191
1192 loopback vtimghd ${vtoy_iso_part}${vt_chosen_path}
1193 vt_img_sector ${vtoy_iso_part}${vt_chosen_path}
1194
1195 vt_img_part_info (vtimghd)
1196
1197 set vtback_root=$root
1198 ventoy_cli_console
1199 vt_push_last_entry
1200
1201 vt_img_extra_initrd_reset
1202
1203 vt_get_fs_label (vtimghd,1) vtImgHd1Label
1204 if [ -d (vtimghd,2)/lib ]; then
1205 vt_get_fs_label (vtimghd,2) vtImgHd2Label
1206 fi
1207
1208 if [ -e (vtimghd,1)/etc/hostname ]; then
1209 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
1210 fi
1211
1212 if [ -e (vtimghd,1)/easy.sfs ]; then
1213 ventoy_img_easyos
1214 elif [ -e (vtimghd,1)/volumio.initrd ]; then
1215 ventoy_img_volumio
1216 elif vt_str_begin $vtImgHd1Label "LAKKA"; then
1217 ventoy_img_openelec lakka
1218 elif vt_str_begin $vtImgHd1Label "LIBREELEC"; then
1219 ventoy_img_openelec LibreELEC
1220 elif vt_str_begin $vtImgHd1Label "paldo-live"; then
1221 ventoy_img_paldo
1222 elif vt_str_begin $vtImgHostname "freedombox"; then
1223 ventoy_img_freedombox
1224 elif vt_str_begin $vtImgHd1Label "BATOCERA"; then
1225 ventoy_img_batocera
1226 elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
1227 ventoy_img_recalbox
1228 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
1229 ventoy_img_ubos
1230 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
1231 if [ "$grub_platform" = "pc" ]; then
1232 img_unsupport_tip
1233 else
1234 ventoy_img_memtest86
1235 fi
1236 else
1237 if [ "$grub_platform" = "pc" ]; then
1238 img_unsupport_tip
1239 else
1240 vt_linux_chain_data ${vtoy_iso_part}${vt_chosen_path}
1241 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}
1242 boot
1243 fi
1244 fi
1245
1246 set root=$vtback_root
1247 vt_pop_last_entry
1248 ventoy_gui_console
1249 set ventoy_compatible=NO
1250 }
1251
1252 function img_unsupport_menuentry {
1253 common_unsupport_menuentry
1254 }
1255
1256 #############################################################
1257 #############################################################
1258 #############################################################
1259 ####### Main Process ###########
1260 #############################################################
1261 #############################################################
1262 #############################################################
1263
1264 set VENTOY_VERSION="1.0.21"
1265
1266 # Default menu display mode, you can change it as you want.
1267 # 0: List mode
1268 # 1: TreeView mode
1269 set VTOY_DEFAULT_MENU_MODE=0
1270
1271 set VTOY_MEM_DISK_STR="[Memdisk]"
1272 set VTOY_ISO_RAW_STR="Compatible Mode"
1273 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
1274
1275 set VTOY_F2_CMD="ventoy_power"
1276 set VTOY_F4_CMD="ventoy_localboot"
1277 set VTOY_F5_CMD="ventoy_diagnosis"
1278 set VTOY_F6_CMD="ventoy_ext_menu"
1279
1280 if [ "$grub_platform" = "pc" ]; then
1281 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1282 else
1283 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1284 fi
1285
1286 vt_device $root vtoy_dev
1287
1288 if [ "$vtoy_dev" = "tftp" ]; then
1289 set vtoy_path=($root)
1290 for vtid in 0 1 2 3; do
1291 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
1292 set vtoy_iso_part=(hd$vtid,1)
1293 set vtoy_efi_part=(hd$vtid,2)
1294 set vtoydev=hd$vtid
1295 break
1296 fi
1297 done
1298 loadfont ascii
1299
1300 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1301 set vt_plugin_path=$vtoy_iso_part
1302 else
1303 set vt_plugin_path=$prefix
1304 vt_load_plugin $vt_plugin_path
1305 fi
1306 else
1307 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1308 set vtoy_path=(ventoydisk)/ventoy
1309 else
1310 set vtoy_path=($root)/ventoy
1311 fi
1312
1313 set vtoydev=$vtoy_dev
1314 set vtoy_iso_part=($vtoy_dev,1)
1315 set vtoy_efi_part=($vtoy_dev,2)
1316 loadfont unicode
1317 set vt_plugin_path=$vtoy_iso_part
1318 fi
1319
1320 #Load Partition Table
1321 vt_load_part_table $vtoydev
1322
1323 #Load Plugin
1324 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1325 vt_load_plugin $vtoy_iso_part
1326 fi
1327
1328 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1329 set timeout=$VTOY_MENU_TIMEOUT
1330 else
1331 unset timeout
1332 fi
1333
1334 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1335 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1336 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1337 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1338 fi
1339
1340 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
1341 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
1342 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
1343 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
1344 fi
1345
1346
1347 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1348 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1349 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
1350 else
1351 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1352 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Tools F6:ExMenu"
1353 fi
1354
1355
1356 if [ -n "$vtoy_gfxmode" ]; then
1357 set gfxmode=$vtoy_gfxmode
1358 set gfxpayload=keep
1359 else
1360 set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
1361 set gfxpayload=keep
1362 fi
1363
1364 if [ "$vtoy_display_mode" = "CLI" ]; then
1365 terminal_output console
1366 elif [ "$vtoy_display_mode" = "serial" ]; then
1367 if [ -n "$vtoy_serial_param" ]; then
1368 serial $vtoy_serial_param
1369 fi
1370 terminal_input serial
1371 terminal_output serial
1372 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1373 if [ -n "$vtoy_serial_param" ]; then
1374 serial $vtoy_serial_param
1375 fi
1376 terminal_input serial console
1377 terminal_output serial console
1378 else
1379 if [ -n "$vtoy_theme" ]; then
1380 set theme=$vtoy_theme
1381 else
1382 set theme=$prefix/themes/ventoy/theme.txt
1383 fi
1384 terminal_output gfxterm
1385 fi
1386
1387 #export necessary variable
1388 export theme
1389 export gfxmode
1390 export vtoydev
1391 export vtoy_iso_part
1392 export vtoy_efi_part
1393 export VENTOY_VERSION
1394 export VTOY_CUR_VIDEO_MODE
1395
1396
1397
1398
1399 #colect all image files (iso files)
1400 set ventoy_img_count=0
1401 vt_list_img $vtoy_iso_part ventoy_img_count
1402
1403 #Main menu
1404 if [ $ventoy_img_count -gt 0 ]; then
1405 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1406 vt_dynamic_menu 0 0
1407 else
1408 vt_dynamic_menu 0 1
1409 fi
1410 else
1411 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1412 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1413 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1414 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1415 else
1416 NO_ISO_MENU="No ISO files found"
1417 fi
1418 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1419 echo -e "\n Rebooting ... "
1420 reboot
1421 }
1422 fi