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