]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
1.0.18 release
[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 if [ -n "${vtdebug_flag}" ]; then
21 echo "press Enter to continue ......"
22 read vtTmpPause
23 fi
24 }
25
26 function ventoy_debug_pause {
27 if [ -n "${vtdebug_flag}" ]; then
28 echo "press Enter to continue ......"
29 read vtTmpPause
30 fi
31 }
32
33 function ventoy_cli_console {
34 if [ "$grub_platform" = "pc" ]; then
35 #terminal_output vga_text
36 terminal_output console
37 else
38 if [ "$vtoy_display_mode" != "CLI" ]; then
39 terminal_output console
40 fi
41 fi
42 }
43
44 function ventoy_gui_console {
45 if [ "$grub_platform" = "pc" ]; then
46 if [ "$vtoy_display_mode" = "CLI" ]; then
47 terminal_output console
48 else
49 terminal_output gfxterm
50 fi
51 else
52 if [ "$vtoy_display_mode" != "CLI" ]; then
53 terminal_output gfxterm
54 fi
55 fi
56 }
57
58 function ventoy_power {
59 configfile $prefix/power.cfg
60 }
61
62 function ventoy_diagnosis {
63 configfile $prefix/debug.cfg
64 }
65
66 function ventoy_localboot {
67 configfile $prefix/localboot.cfg
68 }
69
70 function ventoy_ext_menu {
71 if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
72 set ventoy_new_context=1
73 configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
74 unset ventoy_new_context
75 else
76 echo "ventoy_grub.cfg NOT exist."
77 echo -e "\npress ENTER to exit ..."
78 read vtInputKey
79 fi
80 }
81
82 function get_os_type {
83 set vtoy_os=Linux
84
85 for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
86 if vt_file_exist_nocase (loop)/$file; then
87 set vtoy_os=Windows
88 break
89 fi
90 done
91
92 if [ "$vtoy_os" = "Linux" ]; then
93 if vt_strstr "$vt_system_id" "FreeBSD"; then
94 set vtoy_os=Unix
95 set vt_unix_type=FreeBSD
96 elif [ -e (loop)/bin/freebsd-version ]; then
97 set vtoy_os=Unix
98 set vt_unix_type=FreeBSD
99
100
101 elif [ -e (loop)/boot/kernel/kernel ]; then
102 if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
103 set vtoy_os=Unix
104 set vt_unix_type=FreeBSD
105 elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
106 set vtoy_os=Unix
107 set vt_unix_type=NetBSD
108 fi
109 fi
110 fi
111
112 if [ -n "${vtdebug_flag}" ]; then
113 echo ISO is $vtoy_os
114 fi
115 }
116
117 function vt_check_compatible_pe {
118 #Check for PE without external tools
119 if [ -f $1/HBCD_PE.ini ]; then
120 set ventoy_compatible=YES
121 fi
122 }
123
124 function locate_initrd {
125 vt_linux_locate_initrd
126
127 if [ -n "${vtdebug_flag}" ]; then
128 vt_linux_dump_initrd
129 ventoy_debug_pause
130 fi
131 }
132
133 function locate_wim {
134 vt_windows_locate_wim_patch (loop)
135
136 if [ -n "${vtdebug_flag}" ]; then
137 echo '###############################################'
138 vt_dump_wim_patch
139 echo '###############################################'
140 ventoy_debug_pause
141 fi
142 }
143
144 function distro_specify_wim_patch {
145 if [ -d (loop)/h3pe ]; then
146 vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
147 vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
148 vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
149 vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
150 fi
151 }
152
153 function distro_specify_wim_patch_phase2 {
154 if [ -f (loop)/boot/boot.wim ]; then
155 vt_windows_collect_wim_patch wim /boot/boot.wim
156 fi
157 }
158
159
160 function distro_specify_initrd_file {
161 if [ -e (loop)/boot/all.rdz ]; then
162 vt_linux_specify_initrd_file /boot/all.rdz
163 elif [ -e (loop)/boot/xen.gz ]; then
164 if [ -e (loop)/install.img ]; then
165 vt_linux_specify_initrd_file /install.img
166 fi
167 elif [ -d (loop)/casper ]; then
168 if [ -e (loop)/casper/initrd ]; then
169 vt_linux_specify_initrd_file /casper/initrd
170 fi
171 if [ -e (loop)/casper/initrd-oem ]; then
172 vt_linux_specify_initrd_file /casper/initrd-oem
173 fi
174 elif [ -e (loop)/boot/grub/initrd.xz ]; then
175 vt_linux_specify_initrd_file /boot/grub/initrd.xz
176 elif [ -e (loop)/initrd.gz ]; then
177 vt_linux_specify_initrd_file /initrd.gz
178 elif [ -e (loop)/slax/boot/initrfs.img ]; then
179 vt_linux_specify_initrd_file /slax/boot/initrfs.img
180 elif [ -e (loop)/pmagic/initrd.img ]; then
181 vt_linux_specify_initrd_file /pmagic/initrd.img
182 elif [ -e (loop)/boot/initrd.xz ]; then
183 vt_linux_specify_initrd_file /boot/initrd.xz
184 elif [ -f (loop)/boot/initrd ]; then
185 vt_linux_specify_initrd_file /boot/initrd
186 elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
187 vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
188 elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
189 vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
190
191
192 fi
193 }
194
195
196 function distro_specify_initrd_file_phase2 {
197 if [ -f (loop)/boot/initrd.img ]; then
198 vt_linux_specify_initrd_file /boot/initrd.img
199 elif [ -f (loop)/Setup/initrd.gz ]; then
200 vt_linux_specify_initrd_file /Setup/initrd.gz
201 elif [ -f (loop)/isolinux/initramfs ]; then
202 vt_linux_specify_initrd_file /isolinux/initramfs
203 elif [ -f (loop)/boot/iniramfs.igz ]; then
204 vt_linux_specify_initrd_file /boot/iniramfs.igz
205 elif [ -f (loop)/initrd-x86_64 ]; then
206 vt_linux_specify_initrd_file /initrd-x86_64
207 elif [ -f (loop)/live/initrd.img ]; then
208 vt_linux_specify_initrd_file /live/initrd.img
209 elif [ -f (loop)/initrd.img ]; then
210 vt_linux_specify_initrd_file /initrd.img
211 elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
212 vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
213 elif [ -f (loop)/CDlinux/initrd ]; then
214 vt_linux_specify_initrd_file /CDlinux/initrd
215 elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
216 vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
217 if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
218 vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
219 fi
220 elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
221 #Qubes
222 vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
223 if [ "$grub_platform" != "pc" ]; then
224 vt_add_replace_file 0 "initrd.img"
225 fi
226 elif [ -f (loop)/initrd ]; then
227 vt_linux_specify_initrd_file /initrd
228 elif [ -f (loop)/live/initrd1 ]; then
229 vt_linux_specify_initrd_file /live/initrd1
230
231 fi
232 }
233
234 function ventoy_get_ghostbsd_ver {
235
236 # vt_parse_iso_create_date $1/${chosen_path} vt_create_date
237 # if regexp "^202005" "$vt_create_date"; then
238 # set vt_freebsd_ver=12.x
239 # fi
240
241 set vt_freebsd_ver=12.x
242 }
243
244 function ventoy_get_freenas_ver {
245 set vt_freebsd_ver=11.x
246
247 if [ -e (loop)/FreeNAS-MANIFEST ]; then
248 vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
249 if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
250 set vt_freebsd_ver=13.x
251 elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
252 set vt_freebsd_ver=12.x
253 elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
254 set vt_freebsd_ver=11.x
255 fi
256 fi
257 }
258
259 function ventoy_freebsd_proc {
260 if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
261 ventoy_get_ghostbsd_ver $1 ${chosen_path}
262 elif vt_strstr "$vt_volume_id" "FREENAS"; then
263 ventoy_get_freenas_ver $1 ${chosen_path}
264 elif regexp "^13_[0-9]" "$vt_volume_id"; then
265 set vt_freebsd_ver=13.x
266 elif regexp "^12_[0-9]" "$vt_volume_id"; then
267 set vt_freebsd_ver=12.x
268 elif regexp "^11_[0-9]" "$vt_volume_id"; then
269 set vt_freebsd_ver=11.x
270 elif regexp "^10_[0-9]" "$vt_volume_id"; then
271 set vt_freebsd_ver=10.x
272 elif regexp "^9_[0-9]" "$vt_volume_id"; then
273 set vt_freebsd_ver=9.x
274 elif [ -e (loop)/bin/freebsd-version ]; then
275 vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
276 if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
277 set vt_freebsd_ver=13.x
278 elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
279 set vt_freebsd_ver=12.x
280 elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
281 set vt_freebsd_ver=11.x
282 elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
283 set vt_freebsd_ver=10.x
284 elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
285 set vt_freebsd_ver=9.x
286 fi
287 elif [ -e (loop)/README.TXT ]; then
288 vt_1st_line (loop)/README.TXT vt_freebsd_line1
289 if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
290 set vt_freebsd_ver=13.x
291 elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
292 set vt_freebsd_ver=12.x
293 elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
294 set vt_freebsd_ver=11.x
295 elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
296 set vt_freebsd_ver=10.x
297 elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
298 set vt_freebsd_ver=9.x
299 fi
300 elif vt_strstr "${chosen_path}" "MidnightBSD"; then
301 set vt_freebsd_ver=9.x
302 else
303 set vt_freebsd_ver=12.x
304 fi
305
306 set vt_freebsd_bit=64
307 for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
308 if [ -e (loop)/$file ]; then
309 if file --is-i386-kfreebsd (loop)/$file; then
310 set vt_freebsd_bit=32
311 fi
312 break
313 fi
314 done
315
316 if [ -n "${vtdebug_flag}" ]; then
317 echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
318 fi
319
320 unset vt_unix_mod_path
321 for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version"; do
322 if [ -e (loop)${file} ]; then
323 set vt_unix_mod_path=${file}
324 break
325 fi
326 done
327
328 vt_unix_replace_ko $vt_unix_mod_path (vtunix)/ventoy_unix/FreeBSD/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
329 vt_unix_replace_conf FreeBSD ${1}${chosen_path}
330 }
331
332 function ventoy_unix_comm_proc {
333 vt_unix_reset
334
335 if [ "$ventoy_compatible" = "NO" ]; then
336 loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
337
338 if [ "$vt_unix_type" = "FreeBSD" ]; then
339 ventoy_freebsd_proc $1 ${chosen_path}
340 elif [ "$vt_unix_type" = "NetBSD" ]; then
341 echo "NetBSD not supported"
342
343
344
345 else
346 if [ -n "${vtdebug_flag}" ]; then
347 echo "Unknown unix type"
348 fi
349 fi
350 fi
351
352 vt_unix_chain_data ${1}${chosen_path}
353 ventoy_debug_pause
354 }
355
356
357 function uefi_windows_menu_func {
358 vt_windows_reset
359
360 if [ "$ventoy_compatible" = "NO" ]; then
361
362 if [ "$ventoy_fs_probe" = "iso9660" ]; then
363 loopback -d loop
364 vt_iso9660_nojoliet 1
365 loopback loop $1$2
366 fi
367
368 for file in "efi/microsoft/boot/bcd"; do
369 vt_windows_collect_wim_patch bcd (loop)/$file
370 done
371
372 vt_windows_count_wim_patch vt_wim_cnt
373 if [ $vt_wim_cnt -eq 0 ]; then
374 distro_specify_wim_patch_phase2
375 fi
376
377 ventoy_debug_pause
378 locate_wim
379 fi
380
381 vt_windows_chain_data ${1}${chosen_path}
382 ventoy_debug_pause
383
384 if [ -n "$vtoy_chain_mem_addr" ]; then
385 ventoy_cli_console
386 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
387 boot
388 else
389 echo "chain empty failed"
390 ventoy_pause
391 fi
392 }
393
394 function uefi_linux_menu_func {
395 if [ "$ventoy_compatible" = "NO" ]; then
396
397 if [ "$ventoy_fs_probe" = "udf" ]; then
398 loopback -d loop
399 set ventoy_fs_probe=iso9660
400 loopback loop $1$2
401 fi
402
403 vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1
404
405 vt_linux_clear_initrd
406
407 if [ -d (loop)/pmagic ]; then
408 vt_linux_specify_initrd_file /pmagic/initrd.img
409 else
410 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
411 if [ -e (loop)/$file ]; then
412 vt_linux_parse_initrd_grub file (loop)/$file
413 fi
414 done
415 fi
416
417 # special process for special distros
418 if [ -d (loop)/loader/entries ]; then
419 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
420 elif [ -d (loop)/boot/grub ]; then
421 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
422 fi
423
424 distro_specify_initrd_file
425
426 vt_linux_initrd_count vtcount
427 if [ $vtcount -eq 0 ]; then
428 distro_specify_initrd_file_phase2
429
430 if [ "$vt_efi_dir" = "NO" ]; then
431 if [ -f (loop)/efi.img ]; then
432 vt_add_replace_file 0 "initrd"
433 fi
434 fi
435 fi
436
437 locate_initrd
438
439 if [ -d (loop)/loader/entries ]; then
440 vt_linux_get_main_initrd_index vtindex
441
442 if [ -d (loop)/arch ]; then
443 if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
444 vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
445 elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
446 vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
447 fi
448 elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
449 vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
450 elif [ -f (loop)/loader/entries/thinstation.conf ]; then
451 vt_add_replace_file $vtindex "boot\\initrd"
452 fi
453 elif [ -d (loop)/EFI/boot/entries ]; then
454 if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
455 vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
456 fi
457 elif [ -e (loop)/syslinux/alt0/full.cz ]; then
458 vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
459 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
460 fi
461
462 fi
463
464 vt_linux_chain_data ${1}${chosen_path}
465
466 if [ -n "$vtoy_chain_mem_addr" ]; then
467 ventoy_cli_console
468 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}
469 boot
470 else
471 echo "chain empty failed"
472 ventoy_pause
473 fi
474 }
475
476 function uefi_unix_menu_func {
477 ventoy_unix_comm_proc $1 ${chosen_path}
478
479 if [ -n "$vtoy_chain_mem_addr" ]; then
480 ventoy_cli_console
481 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}
482 boot
483 else
484 echo "chain empty failed"
485 ventoy_pause
486 fi
487 }
488
489 function uefi_iso_menu_func {
490
491 if [ -d (loop)/ ]; then
492 loopback -d loop
493 fi
494
495 if [ -n "$vtisouefi" ]; then
496 set LoadIsoEfiDriver=on
497 unset vtisouefi
498 elif vt_check_mode 2; then
499 set LoadIsoEfiDriver=on
500 else
501 unset LoadIsoEfiDriver
502 fi
503
504 vt_chosen_img_path chosen_path
505 vt_select_auto_install ${chosen_path}
506 vt_select_persistence ${chosen_path}
507
508 if vt_is_udf ${1}${chosen_path}; then
509 set ventoy_fs_probe=udf
510 else
511 set ventoy_fs_probe=iso9660
512 vt_iso9660_nojoliet 0
513 fi
514
515 loopback loop ${1}${chosen_path}
516 vt_parse_iso_volume ${1}${chosen_path} vt_system_id vt_volume_id
517 get_os_type (loop)
518
519 if [ -d (loop)/EFI ]; then
520 set vt_efi_dir=YES
521 elif [ -d (loop)/efi ]; then
522 set vt_efi_dir=YES
523 else
524 set vt_efi_dir=NO
525 fi
526
527 if [ -n "$vtcompat" ]; then
528 set ventoy_compatible=YES
529 unset vtcompat
530 elif vt_check_mode 1; then
531 set ventoy_compatible=YES
532 else
533 vt_check_compatible (loop)
534 fi
535
536 vt_img_sector ${1}${chosen_path}
537
538 if [ "$vtoy_os" = "Windows" ]; then
539 vt_check_compatible_pe (loop)
540 uefi_windows_menu_func $1 ${chosen_path}
541 elif [ "$vtoy_os" = "Unix" ]; then
542 uefi_unix_menu_func $1 ${chosen_path}
543 else
544 uefi_linux_menu_func $1 ${chosen_path}
545 fi
546
547 ventoy_gui_console
548 }
549
550 function uefi_iso_memdisk {
551 vt_chosen_img_path chosen_path
552
553 echo 'Loading ISO file to memory ...'
554 vt_load_iso_to_mem ${1}${chosen_path} vtoy_iso_buf
555
556 ventoy_cli_console
557 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}
558 boot
559
560 ventoy_gui_console
561 }
562
563
564 function legacy_windows_menu_func {
565 vt_windows_reset
566
567 if [ "$ventoy_compatible" = "NO" ]; then
568
569 if [ "$ventoy_fs_probe" = "iso9660" ]; then
570 loopback -d loop
571 vt_iso9660_nojoliet 1
572 loopback loop $1$2
573 fi
574
575 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
576 vt_windows_collect_wim_patch bcd (loop)/$file
577 done
578
579 distro_specify_wim_patch
580
581 vt_windows_count_wim_patch vt_wim_cnt
582 if [ $vt_wim_cnt -eq 0 ]; then
583 distro_specify_wim_patch_phase2
584 fi
585
586 ventoy_debug_pause
587 locate_wim
588 fi
589
590 vt_windows_chain_data ${1}${chosen_path}
591 ventoy_debug_pause
592
593 if [ -n "$vtoy_chain_mem_addr" ]; then
594 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
595 boot
596 else
597 echo "chain empty failed"
598 ventoy_pause
599 fi
600 }
601
602 function legacy_linux_menu_func {
603 if [ "$ventoy_compatible" = "NO" ]; then
604
605 if [ "$ventoy_fs_probe" = "udf" ]; then
606 loopback -d loop
607 set ventoy_fs_probe=iso9660
608 loopback loop $1$2
609 fi
610
611 vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
612
613 vt_linux_clear_initrd
614
615 if [ -d (loop)/pmagic ]; then
616 vt_linux_specify_initrd_file /pmagic/initrd.img
617 else
618 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
619 if [ -d (loop)/$dir ]; then
620 vt_linux_parse_initrd_isolinux (loop)/$dir/
621 fi
622 done
623 fi
624
625 # special process for special distros
626 #archlinux
627 if [ -d (loop)/arch/boot/syslinux ]; then
628 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
629 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
630
631 #manjaro
632 elif [ -d (loop)/manjaro ]; then
633 if [ -e (loop)/boot/grub/kernels.cfg ]; then
634 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
635 fi
636 elif [ -e (loop)/boot/grub/grub.cfg ]; then
637 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
638 fi
639
640 distro_specify_initrd_file
641
642 vt_linux_initrd_count vtcount
643 if [ $vtcount -eq 0 ]; then
644 distro_specify_initrd_file_phase2
645 fi
646
647 locate_initrd
648 fi
649
650 vt_linux_chain_data ${1}${chosen_path}
651 ventoy_debug_pause
652
653 if [ -n "$vtoy_chain_mem_addr" ]; then
654 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
655 boot
656 else
657 echo "chain empty failed"
658 ventoy_pause
659 fi
660 }
661
662
663 function legacy_unix_menu_func {
664 ventoy_unix_comm_proc $1 ${chosen_path}
665
666 if [ -n "$vtoy_chain_mem_addr" ]; then
667 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
668 boot
669 else
670 echo "chain empty failed"
671 ventoy_pause
672 fi
673 }
674
675
676 function legacy_iso_menu_func {
677
678 if [ -d (loop)/ ]; then
679 loopback -d loop
680 fi
681
682 vt_chosen_img_path chosen_path
683 vt_select_auto_install ${chosen_path}
684 vt_select_persistence ${chosen_path}
685
686 if vt_is_udf ${1}${chosen_path}; then
687 set ventoy_fs_probe=udf
688 else
689 set ventoy_fs_probe=iso9660
690 vt_iso9660_nojoliet 0
691 fi
692
693 loopback loop ${1}${chosen_path}
694 vt_parse_iso_volume ${1}${chosen_path} vt_system_id vt_volume_id
695 get_os_type (loop)
696
697 if [ -n "$vtcompat" ]; then
698 set ventoy_compatible=YES
699 unset vtcompat
700 elif vt_check_mode 1; then
701 set ventoy_compatible=YES
702 else
703 vt_check_compatible (loop)
704 fi
705
706 vt_img_sector ${1}${chosen_path}
707
708 if [ "$vtoy_os" = "Windows" ]; then
709 vt_check_compatible_pe (loop)
710 legacy_windows_menu_func $1 ${chosen_path}
711 elif [ "$vtoy_os" = "Unix" ]; then
712 legacy_unix_menu_func $1 ${chosen_path}
713 else
714 legacy_linux_menu_func $1 ${chosen_path}
715 fi
716 }
717
718 function legacy_iso_memdisk {
719 vt_chosen_img_path chosen_path
720
721 linux16 $vtoy_path/memdisk iso raw
722 echo "Loading ISO file to memory ..."
723 initrd16 ${1}${chosen_path}
724 boot
725 }
726
727 function iso_common_menuentry {
728 unset vt_system_id
729 unset vt_volume_id
730
731 if [ "$grub_platform" = "pc" ]; then
732 if vt_check_mode 0; then
733 legacy_iso_memdisk $vtoy_iso_part
734 else
735 legacy_iso_menu_func $vtoy_iso_part
736 fi
737 else
738 if vt_check_mode 0; then
739 uefi_iso_memdisk $vtoy_iso_part
740 else
741 uefi_iso_menu_func $vtoy_iso_part
742 fi
743 fi
744 }
745
746 function common_unsupport_menuentry {
747 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
748 echo -e " 文件名中不能有中文或空格 \n"
749 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
750 read vtInputKey
751 }
752
753 function iso_unsupport_menuentry {
754 common_unsupport_menuentry
755 }
756
757 function wim_common_menuentry {
758 vt_chosen_img_path chosen_path
759 vt_wim_chain_data ${vtoy_iso_part}${chosen_path}
760
761 ventoy_debug_pause
762
763 if [ -n "$vtoy_chain_mem_addr" ]; then
764 if [ "$grub_platform" = "pc" ]; then
765 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
766 else
767 ventoy_cli_console
768 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
769 ventoy_gui_console
770 fi
771 boot
772 else
773 echo "chain empty failed"
774 ventoy_pause
775 fi
776 }
777
778 function wim_unsupport_menuentry {
779 common_unsupport_menuentry
780 }
781
782 function efi_common_menuentry {
783 vt_chosen_img_path chosen_path
784
785 ventoy_cli_console
786 chainloader ${vtoy_iso_part}${chosen_path}
787 boot
788 ventoy_gui_console
789 }
790
791 function efi_unsupport_menuentry {
792 common_unsupport_menuentry
793 }
794
795
796
797 #############################################################
798 #############################################################
799 #############################################################
800 ####### Main Process ###########
801 #############################################################
802 #############################################################
803 #############################################################
804
805 set VENTOY_VERSION="1.0.18"
806
807 # Default menu display mode, you can change it as you want.
808 # 0: List mode
809 # 1: TreeView mode
810 set VTOY_DEFAULT_MENU_MODE=0
811
812 set VTOY_MEM_DISK_STR="[Memdisk]"
813 set VTOY_ISO_RAW_STR="Compatible Mode"
814 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
815
816 set VTOY_F2_CMD="ventoy_power"
817 set VTOY_F4_CMD="ventoy_localboot"
818 set VTOY_F5_CMD="ventoy_diagnosis"
819 set VTOY_F6_CMD="ventoy_ext_menu"
820
821 if [ "$grub_platform" = "pc" ]; then
822 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
823 else
824 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
825 fi
826
827 vt_device $root vtoy_dev
828
829 if [ "$vtoy_dev" = "tftp" ]; then
830 set vtoy_path=($root)
831 for vtid in 0 1 2 3; do
832 if [ -d (hd$vtid,2)/ventoy ]; then
833 set vtoy_iso_part=(hd$vtid,1)
834 set vtoy_efi_part=(hd$vtid,2)
835 break
836 fi
837 done
838 loadfont ascii
839
840 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
841 set vt_plugin_path=$vtoy_iso_part
842 else
843 set vt_plugin_path=$prefix
844 vt_load_plugin $vt_plugin_path
845 fi
846 else
847 if [ "$prefix" = "(ventoydisk)/grub" ]; then
848 set vtoy_path=(ventoydisk)/ventoy
849 else
850 set vtoy_path=($root)/ventoy
851 fi
852
853 set vtoy_iso_part=($vtoy_dev,1)
854 set vtoy_efi_part=($vtoy_dev,2)
855 loadfont unicode
856 set vt_plugin_path=$vtoy_iso_part
857 fi
858
859
860 #Load Plugin
861 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
862 vt_load_plugin $vtoy_iso_part
863 fi
864
865 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
866 set timeout=$VTOY_MENU_TIMEOUT
867 else
868 unset timeout
869 fi
870
871 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
872 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
873 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
874 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
875 fi
876
877
878 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
879 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
880 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
881 else
882 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
883 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
884 fi
885
886
887 if [ -n "$vtoy_gfxmode" ]; then
888 set gfxmode=$vtoy_gfxmode
889 else
890 set gfxmode=1920x1080,1366x768,1024x768
891 fi
892
893 if [ "$vtoy_display_mode" = "CLI" ]; then
894 terminal_output console
895 else
896 if [ -n "$vtoy_theme" ]; then
897 set theme=$vtoy_theme
898 else
899 set theme=$prefix/themes/ventoy/theme.txt
900 fi
901 terminal_output gfxterm
902 fi
903
904 #export necessary variable
905 export theme
906 export gfxmode
907 export vtoy_dev
908 export vtoy_iso_part
909 export vtoy_efi_part
910 export VENTOY_VERSION
911
912
913
914
915 #colect all image files (iso files)
916 set ventoy_img_count=0
917 vt_list_img $vtoy_iso_part ventoy_img_count
918
919 #Main menu
920 if [ $ventoy_img_count -gt 0 ]; then
921 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
922 vt_dynamic_menu 0 0
923 else
924 vt_dynamic_menu 0 1
925 fi
926 else
927 if [ -n "$VTOY_NO_ISO_TIP" ]; then
928 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
929 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
930 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
931 else
932 NO_ISO_MENU="No ISO files found"
933 fi
934 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
935 echo -e "\n Rebooting ... "
936 reboot
937 }
938 fi