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