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