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