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