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