]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
support for 360Udisk
[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 "$vtoy_chain_mem_addr" ]; then
626 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
627 ventoy_cli_console
628 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}
629 boot
630 else
631 echo "chain empty failed"
632 ventoy_pause
633 fi
634 }
635
636 function uefi_unix_menu_func {
637 ventoy_unix_comm_proc $1 "${chosen_path}"
638
639 if [ -n "$vtoy_chain_mem_addr" ]; then
640 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
641 ventoy_cli_console
642 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}
643 boot
644 else
645 echo "chain empty failed"
646 ventoy_pause
647 fi
648 }
649
650 function uefi_iso_menu_func {
651
652 if [ -d (loop)/ ]; then
653 loopback -d loop
654 fi
655
656 if [ -n "$vtisouefi" ]; then
657 set LoadIsoEfiDriver=on
658 unset vtisouefi
659 elif vt_check_mode 2; then
660 set LoadIsoEfiDriver=on
661 else
662 unset LoadIsoEfiDriver
663 fi
664
665 set chosen_path="$2"
666 vt_select_auto_install "${chosen_path}"
667 vt_select_persistence "${chosen_path}"
668
669 if vt_is_udf "${1}${chosen_path}"; then
670 set ventoy_fs_probe=udf
671 else
672 set ventoy_fs_probe=iso9660
673 vt_iso9660_nojoliet 0
674 fi
675
676 loopback loop "${1}${chosen_path}"
677 get_os_type (loop)
678
679 if [ -d (loop)/EFI ]; then
680 set vt_efi_dir=YES
681 elif [ -d (loop)/efi ]; then
682 set vt_efi_dir=YES
683 else
684 set vt_efi_dir=NO
685 fi
686
687 if [ -n "$vtcompat" ]; then
688 set ventoy_compatible=YES
689 unset vtcompat
690 elif vt_check_mode 1; then
691 set ventoy_compatible=YES
692 else
693 vt_check_compatible (loop)
694 fi
695
696 vt_img_sector "${1}${chosen_path}"
697
698 if [ "$ventoy_fs_probe" = "iso9660" ]; then
699 vt_select_conf_replace "${1}" "${chosen_path}"
700 fi
701
702 if [ "$vtoy_os" = "Windows" ]; then
703 vt_check_compatible_pe (loop)
704 uefi_windows_menu_func "$1" "${chosen_path}"
705 elif [ "$vtoy_os" = "Unix" ]; then
706 uefi_unix_menu_func "$1" "${chosen_path}"
707 else
708 uefi_linux_menu_func "$1" "${chosen_path}"
709 fi
710
711 ventoy_gui_console
712 }
713
714 function uefi_iso_memdisk {
715 echo 'Loading ISO file to memory ...'
716 vt_load_img_memdisk "${1}${2}" vtoy_iso_buf
717
718 ventoy_cli_console
719 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}
720 boot
721
722 ventoy_gui_console
723 }
724
725
726 function legacy_windows_menu_func {
727 vt_windows_reset
728
729 if [ "$ventoy_compatible" = "NO" ]; then
730
731 if [ "$ventoy_fs_probe" = "iso9660" ]; then
732 loopback -d loop
733 vt_iso9660_nojoliet 1
734 loopback loop "$1$2"
735 fi
736
737 for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
738 vt_windows_collect_wim_patch bcd (loop)/$file
739 done
740
741 distro_specify_wim_patch
742
743 vt_windows_count_wim_patch vt_wim_cnt
744 if [ $vt_wim_cnt -eq 0 ]; then
745 distro_specify_wim_patch_phase2
746 fi
747
748 ventoy_debug_pause
749 locate_wim
750 fi
751
752 vt_windows_chain_data "${1}${chosen_path}"
753 ventoy_debug_pause
754
755 if [ -n "$vtoy_chain_mem_addr" ]; then
756 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
757 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
758 boot
759 else
760 echo "chain empty failed"
761 ventoy_pause
762 fi
763 }
764
765 function legacy_linux_menu_func {
766 if [ "$ventoy_compatible" = "NO" ]; then
767
768 if [ "$ventoy_fs_probe" = "udf" ]; then
769 loopback -d loop
770 set ventoy_fs_probe=iso9660
771 loopback loop "$1$2"
772 fi
773
774 vt_load_cpio $vtoy_path/ventoy.cpio "$2" "$1" "busybox=$ventoy_busybox_ver"
775
776 vt_linux_clear_initrd
777
778 if [ -d (loop)/pmagic ]; then
779 vt_linux_specify_initrd_file /pmagic/initrd.img
780 else
781 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
782 if [ -d (loop)/$dir ]; then
783 vt_linux_parse_initrd_isolinux (loop)/$dir/
784 fi
785 done
786 fi
787
788 # special process for special distros
789 #archlinux
790 if [ -d (loop)/arch/boot/syslinux ]; then
791 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
792 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
793 elif [ -d (loop)/anarchy/boot/syslinux ]; then
794 vt_linux_parse_initrd_isolinux (loop)/anarchy/boot/syslinux/ /anarchy/
795
796 #manjaro
797 elif [ -d (loop)/manjaro ]; then
798 if [ -e (loop)/boot/grub/kernels.cfg ]; then
799 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
800 fi
801 elif [ -e (loop)/boot/grub/grub.cfg ]; then
802 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
803 fi
804
805 distro_specify_initrd_file
806
807 vt_linux_initrd_count vtcount
808 if [ $vtcount -eq 0 ]; then
809 if [ -d (loop)/rancheros ]; then
810 vt_linux_parse_initrd_isolinux (loop)/boot/ /boot/isolinux/
811 fi
812
813 distro_specify_initrd_file_phase2
814 fi
815
816 locate_initrd
817 fi
818
819 vt_linux_chain_data "${1}${chosen_path}"
820 ventoy_debug_pause
821
822 if [ -n "$vtoy_chain_mem_addr" ]; then
823 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
824 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
825 boot
826 else
827 echo "chain empty failed"
828 ventoy_pause
829 fi
830 }
831
832
833 function legacy_unix_menu_func {
834 ventoy_unix_comm_proc $1 "${chosen_path}"
835
836 if [ -n "$vtoy_chain_mem_addr" ]; then
837 #ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
838 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
839 boot
840 else
841 echo "chain empty failed"
842 ventoy_pause
843 fi
844 }
845
846
847 function legacy_iso_menu_func {
848
849 if [ -d (loop)/ ]; then
850 loopback -d loop
851 fi
852
853 set chosen_path="$2"
854
855 vt_select_auto_install "${chosen_path}"
856 vt_select_persistence "${chosen_path}"
857
858 if vt_is_udf "${1}${chosen_path}"; then
859 set ventoy_fs_probe=udf
860 else
861 set ventoy_fs_probe=iso9660
862 vt_iso9660_nojoliet 0
863 fi
864
865 loopback loop "${1}${chosen_path}"
866
867 get_os_type (loop)
868
869 if [ -n "$vtcompat" ]; then
870 set ventoy_compatible=YES
871 unset vtcompat
872 elif vt_check_mode 1; then
873 set ventoy_compatible=YES
874 else
875 vt_check_compatible (loop)
876 fi
877
878 vt_img_sector "${1}${chosen_path}"
879
880 if [ "$ventoy_fs_probe" = "iso9660" ]; then
881 vt_select_conf_replace "${1}" "${chosen_path}"
882 fi
883
884 if [ "$vtoy_os" = "Windows" ]; then
885 vt_check_compatible_pe (loop)
886 legacy_windows_menu_func "$1" "${chosen_path}"
887 elif [ "$vtoy_os" = "Unix" ]; then
888 legacy_unix_menu_func "$1" "${chosen_path}"
889 else
890 legacy_linux_menu_func "$1" "${chosen_path}"
891 fi
892 }
893
894 function legacy_iso_memdisk {
895
896 linux16 $vtoy_path/memdisk iso raw
897 echo "Loading ISO file to memory ..."
898 initrd16 "${1}${2}"
899 boot
900 }
901
902
903 function iso_endless_os_proc {
904 if [ -d (loop)/ ]; then
905 loopback -d loop
906 fi
907
908 loopback loop "${1}${2}"
909 vt_img_sector "${1}${2}"
910
911 vt_load_cpio $vtoy_path/ventoy.cpio "$2" "$1" "busybox=$ventoy_busybox_ver"
912 vt_trailer_cpio "$1" "$2" noinit
913
914 ventoy_debug_pause
915
916 vt_set_boot_opt '@kparams' rdinit=/vtoy/vtoy
917
918 set eosimage=loop
919 set ventoy_bls_bootdev=/boot
920 set ventoy_loading_tip="Loading files ......"
921
922 export eosimage
923 configfile (loop)/endless/grub/grub.cfg
924
925 unset eosimage
926 unset ventoy_bls_bootdev
927 unset ventoy_loading_tip
928
929 vt_unset_boot_opt
930 }
931
932
933 function ventoy_iso_busybox_ver {
934
935 if [ "$VTOY_EFI_ARCH" = "aa64" ]; then
936 set ventoy_busybox_ver=a64
937 else
938 set ventoy_busybox_ver=32
939
940 #special process for deepin-live iso
941 if [ "$vt_chosen_size" = "403701760" ]; then
942 if vt_str_str "$vt_chosen_path" "/deepin-live"; then
943 set ventoy_busybox_ver=64
944 fi
945 elif vt_str_begin "$vt_volume_id" "PHOTON_"; then
946 set ventoy_busybox_ver=64
947 elif vt_str_begin "$vt_volume_id" "smgl-test-quinq-x86_64"; then
948 set ventoy_busybox_ver=64
949
950 fi
951 fi
952 }
953
954 function iso_common_menuentry {
955 unset vt_system_id
956 unset vt_volume_id
957
958 vt_chosen_img_path vt_chosen_path vt_chosen_size
959 vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id
960
961 if vt_check_password "${vt_chosen_path}"; then
962 return
963 fi
964
965 if vt_str_begin "$vt_volume_id" "Avira"; then
966 vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
967 fi
968
969 ventoy_iso_busybox_ver
970
971 #special process for Endless OS
972 if vt_str_begin "$vt_volume_id" "Endless-OS"; then
973 iso_endless_os_proc $vtoy_iso_part "$vt_chosen_path"
974 elif vt_str_begin "$vt_volume_id" "TENS-Public"; then
975 set vtcompat=1
976 fi
977
978 if [ "$grub_platform" = "pc" ]; then
979 if vt_check_mode 0; then
980 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
981 else
982 legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
983 fi
984 else
985 if vt_check_mode 0; then
986 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
987 else
988 uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
989 fi
990 fi
991 }
992
993 function miso_common_menuentry {
994 vt_chosen_img_path vt_chosen_path vt_chosen_size
995
996 if vt_check_password "${vt_chosen_path}"; then
997 return
998 fi
999
1000 echo "memdisk mode boot for $vt_chosen_path"
1001 echo ""
1002 ventoy_debug_pause
1003
1004 if [ "$grub_platform" = "pc" ]; then
1005 legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1006 else
1007 uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
1008 fi
1009 }
1010
1011
1012 function common_unsupport_menuentry {
1013 echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
1014 echo -e " 文件名中不能有中文或空格 \n"
1015 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1016 read vtInputKey
1017 }
1018
1019 function miso_unsupport_menuentry {
1020 common_unsupport_menuentry
1021 }
1022
1023 function iso_unsupport_menuentry {
1024 common_unsupport_menuentry
1025 }
1026
1027 function wim_common_menuentry {
1028 vt_chosen_img_path vt_chosen_path vt_chosen_size
1029
1030 if vt_check_password "${vt_chosen_path}"; then
1031 return
1032 fi
1033
1034 if vt_wim_check_bootable "${vtoy_iso_part}${vt_chosen_path}"; then
1035 vt_wim_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1036 else
1037 echo -e "\n This is NOT a bootable WIM file. \n"
1038 echo -e " 这不是一个可启动的 WIM 文件。\n"
1039 fi
1040
1041 ventoy_debug_pause
1042
1043 if [ -n "$vtoy_chain_mem_addr" ]; then
1044 if [ "$grub_platform" = "pc" ]; then
1045 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1046 else
1047 ventoy_cli_console
1048 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}
1049 ventoy_gui_console
1050 fi
1051 boot
1052 else
1053 echo "chain empty failed"
1054 ventoy_pause
1055 fi
1056 }
1057
1058 function wim_unsupport_menuentry {
1059 common_unsupport_menuentry
1060 }
1061
1062 function efi_common_menuentry {
1063 vt_chosen_img_path vt_chosen_path vt_chosen_size
1064
1065 if vt_check_password "${vt_chosen_path}"; then
1066 return
1067 fi
1068
1069 vt_concat_efi_iso "${vtoy_iso_part}${vt_chosen_path}" vtoy_iso_buf
1070
1071 ventoy_debug_pause
1072
1073 ventoy_cli_console
1074
1075 unset vtoy_dotefi_retry
1076 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}
1077 boot
1078
1079 if [ -n "$vtoy_dotefi_retry" ]; then
1080 unset vtoy_dotefi_retry
1081 chainloader "${vtoy_iso_part}${vt_chosen_path}"
1082 boot
1083 fi
1084
1085 ventoy_gui_console
1086 }
1087
1088 function efi_unsupport_menuentry {
1089 common_unsupport_menuentry
1090 }
1091
1092 function vhd_common_menuentry {
1093
1094 if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
1095 if [ "$vtoy_iso_fs" != "ntfs" ]; then
1096 echo -e "!!! WARNING !!!\n"
1097 echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
1098 echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
1099 echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
1100 read vtInputKey
1101 fi
1102 fi
1103
1104 vt_chosen_img_path vt_chosen_path vt_chosen_size
1105
1106 if vt_check_password "${vt_chosen_path}"; then
1107 return
1108 fi
1109
1110 vt_patch_vhdboot "$vt_chosen_path"
1111
1112 ventoy_debug_pause
1113
1114 if [ -n "$vtoy_vhd_buf_addr" ]; then
1115 if [ "$grub_platform" = "pc" ]; then
1116 linux16 $vtoy_path/memdisk iso raw
1117 initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
1118 boot
1119 else
1120 ventoy_cli_console
1121 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}
1122 boot
1123 ventoy_gui_console
1124 fi
1125 else
1126 echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
1127 ventoy_pause
1128 fi
1129 }
1130
1131 function vhd_unsupport_menuentry {
1132 common_unsupport_menuentry
1133 }
1134
1135 function vtoyboot_common_func {
1136 set AltBootPart=0
1137 set vtoysupport=0
1138
1139 vt_get_vtoy_type "${1}" vtoytype parttype AltBootPart
1140
1141 if vt_str_begin $vtoytype vhd; then
1142 set vtoysupport=1
1143 elif [ "$vtoytype" = "raw" ]; then
1144 set vtoysupport=1
1145 elif [ "$vtoytype" = "vdi" ]; then
1146 set vtoysupport=1
1147 fi
1148
1149 if [ $vtoysupport -eq 1 ]; then
1150 if [ "$grub_platform" = "pc" ]; then
1151 if [ "$parttype" = "gpt" -a $AltBootPart -eq 0 ]; then
1152 echo "The OS in the vdisk was created in UEFI mode, but current is Legacy BIOS mode."
1153 echo "虚拟磁盘内的系统是在UEFI模式下创建的,而当前系统是Legacy BIOS模式,可能无法正常启动。"
1154 ventoy_pause
1155 fi
1156 else
1157 if [ "$parttype" = "mbr" -a $AltBootPart -eq 0 ]; then
1158 echo "The OS in the vdisk was created in Legacy BIOS mode, but current is UEFI mode."
1159 echo "虚拟磁盘内的系统是在Legacy BIOS模式下创建的,而当前系统是UEFI模式,可能无法正常启动。"
1160 ventoy_pause
1161 fi
1162 fi
1163
1164 vt_img_sector "${1}"
1165 vt_raw_chain_data "${1}"
1166
1167 ventoy_debug_pause
1168
1169 if [ -n "$vtoy_chain_mem_addr" ]; then
1170 if [ "$grub_platform" = "pc" ]; then
1171 vt_acpi_param ${vtoy_chain_mem_addr} 512
1172 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} bios80 sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1173 boot
1174 else
1175 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
1176 ventoy_cli_console
1177 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}
1178 boot
1179 ventoy_gui_console
1180 fi
1181 else
1182 echo "chain empty failed!"
1183 ventoy_pause
1184 fi
1185 else
1186 echo "Unsupported vtoy type $vtoytype"
1187 ventoy_pause
1188 fi
1189 }
1190
1191 function vtoy_common_menuentry {
1192 vt_chosen_img_path vt_chosen_path vt_chosen_size
1193
1194 if vt_check_password "${vt_chosen_path}"; then
1195 return
1196 fi
1197
1198 vtoyboot_common_func "${vtoy_iso_part}${vt_chosen_path}"
1199 }
1200
1201 function vtoy_unsupport_menuentry {
1202 common_unsupport_menuentry
1203 }
1204
1205 #
1206 #============================================================#
1207 # IMG file boot process #
1208 #============================================================#
1209 #
1210
1211
1212 function ventoy_img_easyos {
1213 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1214 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1215
1216 loopback easysfs (vtimghd,1)/easy.sfs
1217 vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
1218
1219 if [ -n "$vt_module_ver" ]; then
1220 for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
1221 vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
1222 done
1223 fi
1224
1225 ventoy_debug_pause
1226
1227 #boot image file
1228 vt_set_boot_opt rdinit=/vtoy/vtoy
1229 vt_img_hook_root
1230
1231 syslinux_configfile (vtimghd,1)/syslinux.cfg
1232
1233 vt_img_unhook_root
1234 vt_unset_boot_opt
1235 loopback -d easysfs
1236 }
1237
1238 function ventoy_img_volumio {
1239 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1240 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1241
1242 ventoy_debug_pause
1243
1244 #boot image file
1245 vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
1246 vt_img_hook_root
1247
1248 syslinux_configfile (vtimghd,1)/syslinux.cfg
1249
1250 vt_img_unhook_root
1251 vt_unset_boot_opt
1252 }
1253
1254 function ventoy_img_openelec {
1255 elec_ver=$1
1256
1257 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1258 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1259
1260 loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
1261 vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
1262
1263 ventoy_debug_pause
1264
1265 #boot image file
1266 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
1267 vt_img_hook_root
1268
1269 set root=(vtimghd,1)
1270 syslinux_configfile (vtimghd,1)/syslinux.cfg
1271
1272 vt_img_unhook_root
1273 vt_unset_boot_opt
1274 loopback -d vtloopex
1275 }
1276
1277
1278 function ventoy_img_freedombox {
1279 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1280 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1281
1282 vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
1283 if [ -n "$vt_module_ver" ]; then
1284 vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
1285 fi
1286
1287 ventoy_debug_pause
1288
1289 #boot image file
1290 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
1291 vt_img_hook_root
1292
1293 configfile (vtimghd,1)/boot/grub/grub.cfg
1294
1295 vt_img_unhook_root
1296 vt_unset_boot_opt
1297 }
1298
1299 function ventoy_img_paldo {
1300 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1301 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1302
1303 ventoy_debug_pause
1304
1305 #boot image file
1306 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
1307 vt_img_hook_root
1308
1309 vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
1310 vt_file_basename $vt_paldo_entry_conf vtPaldoVer
1311
1312 echo loading file...
1313 linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
1314 initrd (vtimghd,1)/initramfs-${vtPaldoVer}
1315 boot
1316
1317 vt_img_unhook_root
1318 vt_unset_boot_opt
1319 }
1320
1321 function ventoy_img_ubos {
1322 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1323 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1324
1325 vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
1326 if [ -n "$vt_module_ver" ]; then
1327 vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
1328 fi
1329
1330 ventoy_debug_pause
1331
1332 #boot image file
1333 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
1334 vt_img_hook_root
1335
1336 echo loading file...
1337 linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
1338 initrd (vtimghd,2)/initramfs-linux.img
1339 boot
1340
1341 vt_img_unhook_root
1342 vt_unset_boot_opt
1343 }
1344
1345 function ventoy_img_recalbox {
1346 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1347 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1348
1349 ventoy_debug_pause
1350
1351 #boot image file
1352 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
1353 vt_img_hook_root
1354
1355 set root=(vtimghd,1)
1356 configfile (vtimghd,1)/boot/grub/grub.cfg
1357
1358 vt_img_unhook_root
1359 vt_unset_boot_opt
1360 }
1361
1362 function ventoy_img_batocera {
1363 vt_load_cpio $vtoy_path/ventoy.cpio "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
1364 vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
1365
1366 ventoy_debug_pause
1367
1368 #boot image file
1369 vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
1370 vt_img_hook_root
1371
1372 set root=(vtimghd,1)
1373 syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
1374
1375 vt_img_unhook_root
1376 vt_unset_boot_opt
1377 }
1378
1379 function ventoy_img_memtest86 {
1380 chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
1381 boot
1382 }
1383
1384 function img_unsupport_tip {
1385 echo -e "\n This IMG file is NOT supported now. \n"
1386 echo -e " 当前不支持启动此 IMG 文件 \n"
1387 echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
1388 read vtInputKey
1389 }
1390
1391 function img_common_menuentry {
1392 set ventoy_compatible=YES
1393 set ventoy_busybox_ver=32
1394
1395 vt_chosen_img_path vt_chosen_path vt_chosen_size
1396
1397 if vt_check_password "${vt_chosen_path}"; then
1398 return
1399 fi
1400
1401 if [ -d (vtimghd)/ ]; then
1402 loopback -d vtimghd
1403 fi
1404
1405 loopback vtimghd "${vtoy_iso_part}${vt_chosen_path}"
1406 vt_img_sector "${vtoy_iso_part}${vt_chosen_path}"
1407
1408 vt_img_part_info (vtimghd)
1409
1410 set vtback_root=$root
1411 ventoy_cli_console
1412 vt_push_last_entry
1413
1414 vt_img_extra_initrd_reset
1415
1416 vt_get_fs_label (vtimghd,1) vtImgHd1Label
1417 if [ -d (vtimghd,2)/lib ]; then
1418 vt_get_fs_label (vtimghd,2) vtImgHd2Label
1419 fi
1420
1421 if [ -e (vtimghd,1)/etc/hostname ]; then
1422 vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
1423 fi
1424
1425 if [ -e (vtimghd,1)/easy.sfs ]; then
1426 ventoy_img_easyos
1427 elif [ -e (vtimghd,1)/volumio.initrd ]; then
1428 ventoy_img_volumio
1429 elif vt_str_begin "$vtImgHd1Label" "LAKKA"; then
1430 ventoy_img_openelec lakka
1431 elif vt_str_begin "$vtImgHd1Label" "LIBREELEC"; then
1432 ventoy_img_openelec LibreELEC
1433 elif vt_str_begin "$vtImgHd1Label" "paldo-live"; then
1434 ventoy_img_paldo
1435 elif vt_str_begin "$vtImgHostname" "freedombox"; then
1436 ventoy_img_freedombox
1437 elif vt_str_begin "$vtImgHd1Label" "BATOCERA"; then
1438 ventoy_img_batocera
1439 elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
1440 ventoy_img_recalbox
1441 elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
1442 ventoy_img_ubos
1443 elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
1444 if [ "$grub_platform" = "pc" ]; then
1445 img_unsupport_tip
1446 else
1447 ventoy_img_memtest86
1448 fi
1449 else
1450 vt_linux_chain_data "${vtoy_iso_part}${vt_chosen_path}"
1451 ventoy_acpi_param ${vtoy_chain_mem_addr} 512
1452 if [ "$grub_platform" = "pc" ]; then
1453 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
1454 boot
1455 else
1456 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}
1457 boot
1458 fi
1459 fi
1460
1461 set root=$vtback_root
1462 vt_pop_last_entry
1463 ventoy_gui_console
1464 set ventoy_compatible=NO
1465 }
1466
1467 function img_unsupport_menuentry {
1468 common_unsupport_menuentry
1469 }
1470
1471 #############################################################
1472 #############################################################
1473 #############################################################
1474 ####### Main Process ###########
1475 #############################################################
1476 #############################################################
1477 #############################################################
1478
1479 set VENTOY_VERSION="1.0.32"
1480
1481 #ACPI not compatible with Window7/8, so disable by default
1482 set VTOY_PARAM_NO_ACPI=1
1483
1484 # Default menu display mode, you can change it as you want.
1485 # 0: List mode
1486 # 1: TreeView mode
1487 set VTOY_DEFAULT_MENU_MODE=0
1488
1489 set VTOY_MEM_DISK_STR="[Memdisk]"
1490 set VTOY_ISO_RAW_STR="Compatible Mode"
1491 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
1492
1493 set VTOY_F2_CMD="ventoy_power"
1494 set VTOY_F4_CMD="ventoy_localboot"
1495 set VTOY_F5_CMD="ventoy_diagnosis"
1496 set VTOY_F6_CMD="ventoy_ext_menu"
1497
1498 if [ "$grub_platform" = "pc" ]; then
1499 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
1500 else
1501 if [ "$grub_cpu" = "i386" ]; then
1502 set VTOY_EFI_ARCH=ia32
1503 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION IA32 www.ventoy.net"
1504 elif [ "$grub_cpu" = "arm64" ]; then
1505 set VTOY_EFI_ARCH=aa64
1506 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION AA64 www.ventoy.net"
1507 else
1508 set VTOY_EFI_ARCH=x64
1509 set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
1510 fi
1511 fi
1512
1513 vt_device $root vtoy_dev
1514
1515 if [ "$vtoy_dev" = "tftp" ]; then
1516 set vtoy_path=($root)
1517 for vtid in 0 1 2 3; do
1518 if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
1519 set vtoy_iso_part=(hd$vtid,1)
1520 set vtoy_efi_part=(hd$vtid,2)
1521 set vtoydev=hd$vtid
1522 break
1523 fi
1524 done
1525 loadfont ascii
1526
1527 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1528 set vt_plugin_path=$vtoy_iso_part
1529 else
1530 set vt_plugin_path=$prefix
1531 vt_load_plugin $vt_plugin_path
1532 fi
1533 else
1534 if [ "$prefix" = "(ventoydisk)/grub" ]; then
1535 set vtoy_path=(ventoydisk)/ventoy
1536 else
1537 set vtoy_path=($root)/ventoy
1538 fi
1539
1540 set vtoydev=$vtoy_dev
1541 set vtoy_iso_part=($vtoy_dev,1)
1542 set vtoy_efi_part=($vtoy_dev,2)
1543 loadfont unicode
1544 set vt_plugin_path=$vtoy_iso_part
1545 fi
1546
1547 #Load Partition Table
1548 vt_load_part_table $vtoydev
1549
1550 #Load Plugin
1551 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
1552 clear
1553 vt_load_plugin $vtoy_iso_part
1554 clear
1555 fi
1556
1557 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
1558 set timeout=$VTOY_MENU_TIMEOUT
1559 else
1560 unset timeout
1561 fi
1562
1563 if [ -f $vtoy_iso_part/ventoy/ventoy_wimboot.img ]; then
1564 vt_load_wimboot $vtoy_iso_part/ventoy/ventoy_wimboot.img
1565 elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
1566 vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
1567 fi
1568
1569 if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
1570 vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
1571 elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
1572 vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
1573 fi
1574
1575
1576 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1577 set VTOY_F3_CMD="vt_dynamic_menu 1 1"
1578 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
1579 else
1580 set VTOY_F3_CMD="vt_dynamic_menu 1 0"
1581 set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Tools F6:ExMenu"
1582 fi
1583
1584
1585 if [ -n "$vtoy_gfxmode" ]; then
1586 set gfxmode=$vtoy_gfxmode
1587 set gfxpayload=keep
1588 else
1589 set gfxmode=1024x768
1590 set gfxpayload=keep
1591 fi
1592
1593
1594 if [ "$vtoy_display_mode" = "CLI" ]; then
1595 terminal_output console
1596 elif [ "$vtoy_display_mode" = "serial" ]; then
1597 if [ -n "$vtoy_serial_param" ]; then
1598 serial $vtoy_serial_param
1599 fi
1600 terminal_input serial
1601 terminal_output serial
1602 elif [ "$vtoy_display_mode" = "serial_console" ]; then
1603 if [ -n "$vtoy_serial_param" ]; then
1604 serial $vtoy_serial_param
1605 fi
1606 terminal_input serial console
1607 terminal_output serial console
1608 else
1609 if [ -n "$vtoy_theme" ]; then
1610 set theme=$vtoy_theme
1611 else
1612 set theme=$prefix/themes/ventoy/theme.txt
1613 fi
1614 terminal_output gfxterm
1615 fi
1616
1617
1618 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
1619 clear
1620 echo -e "\n Syntax error detected in ventoy.json, please check! \n"
1621 echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
1622 echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
1623 read vtInputKey
1624 fi
1625
1626 #export necessary variable
1627 export theme
1628 export gfxmode
1629 export gfxpayload
1630 export vtoydev
1631 export vtoy_path
1632 export vtdebug_flag
1633 export vtoy_iso_part
1634 export vtoy_efi_part
1635 export VENTOY_VERSION
1636 export VTOY_CUR_VIDEO_MODE
1637 export VTOY_EFI_ARCH
1638
1639 #special VTOY_DEFAULT_IMAGE process
1640 if [ -n "$VTOY_DEFAULT_IMAGE" ]; then
1641 if regexp --set 1:vtHotkey --set 2:vtDefault "(F[2-9])>(.*)" "$VTOY_DEFAULT_IMAGE"; then
1642
1643 set default="$vtDefault"
1644 if [ -z "$VTOY_MENU_TIMEOUT" ]; then
1645 set timeout=0
1646 else
1647 set timeout=$VTOY_MENU_TIMEOUT
1648 fi
1649
1650 export timeout
1651 export default
1652
1653 if [ "$vtHotkey" = "F2" ]; then
1654 ventoy_power
1655 elif [ "$vtHotkey" = "F4" ]; then
1656 ventoy_localboot
1657 elif [ "$vtHotkey" = "F5" ]; then
1658 ventoy_diagnosis
1659 elif [ "$vtHotkey" = "F6" ]; then
1660 ventoy_ext_menu
1661 fi
1662
1663 unset timeout
1664 unset default
1665 fi
1666 fi
1667
1668 #colect all image files (iso files)
1669 set ventoy_img_count=0
1670 vt_list_img $vtoy_iso_part ventoy_img_count
1671
1672 #Main menu
1673 if [ $ventoy_img_count -gt 0 ]; then
1674 if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
1675 vt_dynamic_menu 0 0
1676 else
1677 vt_dynamic_menu 0 1
1678 fi
1679 else
1680 if [ -n "$VTOY_NO_ISO_TIP" ]; then
1681 NO_ISO_MENU="No ISO files found, $VTOY_NO_ISO_TIP"
1682 elif [ -n "$VTOY_DEFAULT_SEARCH_ROOT" ]; then
1683 NO_ISO_MENU="No ISO files found, please check VTOY_DEFAULT_SEARCH_ROOT"
1684 else
1685 NO_ISO_MENU="No ISO files found"
1686 fi
1687 menuentry "$NO_ISO_MENU (Press enter to reboot ...)" {
1688 echo -e "\n Rebooting ... "
1689 reboot
1690 }
1691 fi