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