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