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