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