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