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