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