/
grub.cfg
2712 lines (2248 loc) · 85.8 KB
/
grub.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
if [ "$grub_platform" = "pc" ]; then
insmod setkey
insmod regexp
fi
function ventoy_pause {
echo "press Enter to continue ......"
read vtTmpPause
}
function ventoy_debug_pause {
if [ -n "${vtdebug_flag}" ]; then
echo "press Enter to continue ......"
read vtTmpPause
fi
}
function ventoy_cli_console {
if [ -z "$vtoy_display_mode" ]; then
terminal_output console
elif [ "$vtoy_display_mode" = "GUI" ]; then
terminal_output console
fi
}
function ventoy_gui_console {
if [ -z "$vtoy_display_mode" ]; then
terminal_output gfxterm
elif [ "$vtoy_display_mode" = "GUI" ]; then
terminal_output gfxterm
fi
}
function ventoy_acpi_param {
if [ "$VTOY_PARAM_NO_ACPI" != "1" ]; then
vt_acpi_param "$1" "$2"
fi
}
function ventoy_vcfg_proc {
if vt_check_custom_boot "${1}" vt_vcfg; then
set vtoy_chosen_path="${1}"
vt_file_basefile "${vtoy_chosen_path}" vtoy_chosen_file
export vtoy_chosen_path
export vtoy_chosen_file
ventoy_debug_pause
configfile "${vtoy_iso_part}${vt_vcfg}"
true
else
false
fi
}
function ventoy_language {
configfile $prefix/menulang.cfg
}
function ventoy_diagnosis {
vt_enum_video_mode
configfile $prefix/debug.cfg
}
function ventoy_localboot {
configfile $prefix/localboot.cfg
}
function ventoy_ext_menu {
if [ -e $vt_plugin_path/ventoy/ventoy_grub.cfg ]; then
set ventoy_new_context=1
configfile $vt_plugin_path/ventoy/ventoy_grub.cfg
unset ventoy_new_context
else
echo "ventoy_grub.cfg NOT exist."
echo -en "\n$VTLANG_ENTER_EXIT ..."
read vtInputKey
fi
}
function ventoy_checksum {
if [ -f "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}" ]; then
configfile $prefix/checksum.cfg
fi
}
function ventoy_show_help {
if [ -f $prefix/help.tar.gz ]; then
if [ -z "$vtoy_help_txt_mem_addr" ]; then
vt_load_file_to_mem "auto" $prefix/help.tar.gz vtoy_help_txt_mem
fi
loopback vt_help_tarfs mem:${vtoy_help_txt_mem_addr}:size:${vtoy_help_txt_mem_size}
vt_cur_menu_lang vtCurLang
if [ -f "(vt_help_tarfs)/help/${vtCurLang}.txt" ]; then
cat "(vt_help_tarfs)/help/${vtCurLang}.txt"
else
cat "(vt_help_tarfs)/help/en_US.txt"
fi
loopback -d vt_help_tarfs
fi
}
function ventoy_load_menu_lang_file {
vt_load_file_to_mem "auto" $prefix/menu.tar.gz vtoy_menu_lang_mem
loopback vt_menu_tarfs mem:${vtoy_menu_lang_mem_addr}:size:${vtoy_menu_lang_mem_size}
}
function get_os_type {
set vtoy_os=Linux
export vtoy_os
if vt_str_begin "$vt_volume_id" "DLC Boot"; then
if [ -f (loop)/DLCBoot.exe ]; then
set vtoy_os=Windows
fi
else
for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
if vt_file_exist_nocase (loop)/$file; then
set vtoy_os=Windows
break
fi
done
fi
if [ "$vtoy_os" = "Linux" ]; then
if vt_strstr "$vt_system_id" "FreeBSD"; then
set vtoy_os=Unix
set vt_unix_type=FreeBSD
elif [ -e (loop)/bin/freebsd-version ]; then
set vtoy_os=Unix
set vt_unix_type=FreeBSD
elif [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
set vtoy_os=Unix
set vt_unix_type=FreeBSD
elif vt_str_begin "$vt_system_id" "DragonFly"; then
set vtoy_os=Unix
set vt_unix_type=DragonFly
elif [ -e (loop)/boot/kernel/kernel ]; then
if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
set vtoy_os=Unix
set vt_unix_type=FreeBSD
elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
set vtoy_os=Unix
set vt_unix_type=NetBSD
fi
fi
fi
if [ -n "${vtdebug_flag}" ]; then
echo ISO is "$vtoy_os"
fi
}
function vt_check_compatible_pe {
#Check for PE without external tools
#set compatible if ISO file is less than 80MB
if [ $vt_chosen_size -GT 33554432 -a $vt_chosen_size -LE 83886080 ]; then
set ventoy_compatible=YES
fi
return
}
function vt_check_compatible_linux {
if vt_str_begin "$vt_volume_id" "embootkit"; then
set ventoy_compatible=YES
elif [ -e "$1/casper/tinycore.gz" ]; then
set ventoy_compatible=YES
fi
return
}
function locate_initrd {
vt_linux_locate_initrd
if [ -n "${vtdebug_flag}" ]; then
vt_linux_dump_initrd
ventoy_debug_pause
fi
}
function locate_wim {
vt_windows_locate_wim_patch (loop) "$1"
if [ -n "${vtdebug_flag}" ]; then
echo '###############################################'
vt_dump_wim_patch
echo '###############################################'
ventoy_debug_pause
fi
}
function distro_specify_wim_patch {
if [ -d (loop)/h3pe ]; then
vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
elif [ -d (loop)/2k10/winpe ]; then
vt_windows_collect_wim_patch wim /2k10/winpe/w1086pe.wim
vt_windows_collect_wim_patch wim /2k10/winpe/w8x86pe.wim
vt_windows_collect_wim_patch wim /2k10/winpe/w7x86pe.wim
fi
}
function distro_specify_wim_patch_phase2 {
if [ -f (loop)/boot/boot.wim ]; then
vt_windows_collect_wim_patch wim /boot/boot.wim
elif [ -f (loop)/sources/boot.wim ]; then
vt_windows_collect_wim_patch wim /sources/boot.wim
fi
if vt_str_begin "$vt_volume_id" "DLC Boot"; then
for vwfile in "/DLC1/WinPE/W11x64.wim" "/DLC1/WinPE/W10x64.wim" "/DLC1/WinPE/W10x86.wim"; do
if [ -f (loop)/$vwfile ]; then
vt_windows_collect_wim_patch wim $vwfile
fi
done
fi
}
function distro_specify_initrd_file {
if [ -e (loop)/boot/all.rdz ]; then
vt_linux_specify_initrd_file /boot/all.rdz
elif [ -e (loop)/boot/xen.gz ]; then
if [ -e (loop)/install.img ]; then
vt_linux_specify_initrd_file /install.img
fi
elif [ -d (loop)/casper ]; then
if [ -e (loop)/casper/initrd ]; then
vt_linux_specify_initrd_file /casper/initrd
fi
if [ -e (loop)/casper/initrd.gz ]; then
vt_linux_specify_initrd_file /casper/initrd.gz
fi
if [ -e (loop)/casper/initrd-oem ]; then
vt_linux_specify_initrd_file /casper/initrd-oem
fi
elif [ -e (loop)/boot/grub/initrd.xz ]; then
vt_linux_specify_initrd_file /boot/grub/initrd.xz
elif [ -e (loop)/initrd.gz ]; then
vt_linux_specify_initrd_file /initrd.gz
elif [ -e (loop)/slax/boot/initrfs.img ]; then
vt_linux_specify_initrd_file /slax/boot/initrfs.img
elif [ -e (loop)/minios/boot/initrfs.img ]; then
vt_linux_specify_initrd_file /minios/boot/initrfs.img
elif [ -e (loop)/pmagic/initrd.img ]; then
vt_linux_specify_initrd_file /pmagic/initrd.img
elif [ -e (loop)/boot/initrd.xz ]; then
vt_linux_specify_initrd_file /boot/initrd.xz
elif [ -e (loop)/boot/initrd.gz ]; then
vt_linux_specify_initrd_file /boot/initrd.gz
elif [ -f (loop)/boot/initrd ]; then
vt_linux_specify_initrd_file /boot/initrd
elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
elif [ -f (loop)/boot/isolinux/initramfs_data64.cpio.gz ]; then
vt_linux_specify_initrd_file /boot/isolinux/initramfs_data64.cpio.gz
elif [ -f (loop)/boot/initrd.img ]; then
vt_linux_specify_initrd_file /boot/initrd.img
fi
if [ -f (loop)/isolinux/initrd.gz ]; then
vt_linux_specify_initrd_file /isolinux/initrd.gz
fi
if vt_str_begin "$vt_volume_id" "QUBES"; then
vt_linux_specify_initrd_file /images/pxeboot/initrd.img
fi
if [ "$vt_chosen_size" = "1133375488" ]; then
if [ -d (loop)/boot/grub/x86_64-efi ]; then
vt_cpio_busybox64 "64h"
fi
fi
}
function distro_specify_initrd_file_phase2 {
if [ -f (loop)/boot/initrd.img ]; then
vt_linux_specify_initrd_file /boot/initrd.img
elif [ -f (loop)/Setup/initrd.gz ]; then
vt_linux_specify_initrd_file /Setup/initrd.gz
elif [ -f (loop)/isolinux/initramfs ]; then
vt_linux_specify_initrd_file /isolinux/initramfs
elif [ -f (loop)/boot/iniramfs.igz ]; then
vt_linux_specify_initrd_file /boot/iniramfs.igz
elif [ -f (loop)/initrd-x86_64 ]; then
vt_linux_specify_initrd_file /initrd-x86_64
elif [ -f (loop)/live/initrd.img ]; then
vt_linux_specify_initrd_file /live/initrd.img
elif [ -f (loop)/initrd.img ]; then
vt_linux_specify_initrd_file /initrd.img
elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
elif [ -f (loop)/CDlinux/initrd ]; then
vt_linux_specify_initrd_file /CDlinux/initrd
elif [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
vt_linux_specify_initrd_file /parabola/boot/x86_64/parabolaiso.img
if [ -f (loop)/parabola/boot/i686/parabolaiso.img ]; then
vt_linux_specify_initrd_file /parabola/boot/i686/parabolaiso.img
fi
elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
vt_linux_specify_initrd_file /parabola/boot/x86_64/initramfs-linux-libre.img
if [ -f (loop)/parabola/boot/i686/initramfs-linux-libre.img ]; then
vt_linux_specify_initrd_file /parabola/boot/i686/initramfs-linux-libre.img
fi
elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
vt_linux_specify_initrd_file /hyperbola/boot/x86_64/hyperiso.img
if [ -f (loop)/hyperbola/boot/i686/hyperiso.img ]; then
vt_linux_specify_initrd_file /hyperbola/boot/i686/hyperiso.img
fi
elif [ -f (loop)/EFI/BOOT/initrd.img ]; then
#Qubes
vt_linux_specify_initrd_file /EFI/BOOT/initrd.img
if [ "$grub_platform" != "pc" ]; then
vt_add_replace_file 0 "initrd.img"
fi
elif [ -f (loop)/initrd ]; then
vt_linux_specify_initrd_file /initrd
elif [ -f (loop)/live/initrd1 ]; then
vt_linux_specify_initrd_file /live/initrd1
elif [ -f (loop)/isolinux/initrd.img ]; then
vt_linux_specify_initrd_file /isolinux/initrd.img
elif [ -f (loop)/isolinux/initrd.gz ]; then
vt_linux_specify_initrd_file /isolinux/initrd.gz
elif [ -f (loop)/syslinux/kernel/initramfs.gz ]; then
vt_linux_specify_initrd_file /syslinux/kernel/initramfs.gz
elif vt_strstr "$vt_volume_id" "Daphile"; then
vt_linux_parse_initrd_isolinux (loop)/isolinux/
elif [ -f (loop)/boot/rootfs.xz ]; then
vt_linux_specify_initrd_file /boot/rootfs.xz
if [ "$grub_platform" != "pc" ]; then
vt_add_replace_file 0 "minimal\\x86_64\\rootfs.xz"
fi
elif [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
vt_linux_specify_initrd_file /arch/boot/x86_64/archiso.img
if [ "$grub_platform" != "pc" ]; then
vt_add_replace_file 0 "EFI\\archiso\\archiso.img"
fi
elif [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
vt_linux_specify_initrd_file /blackarch/boot/x86_64/archiso.img
elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
vt_linux_specify_initrd_file /blackarch/boot/x86_64/initramfs-linux.img
elif [ -f (loop)/install.amd/initrd.gz ]; then
vt_linux_specify_initrd_file /live/initrd2.img
vt_linux_specify_initrd_file /install.amd/initrd.gz
vt_linux_specify_initrd_file /install.amd/gtk/initrd.gz
elif [ -f (loop)/boot/grub/kernels.cfg ]; then
vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
elif [ -f (loop)/austrumi/initrd.gz ]; then
vt_linux_specify_initrd_file /austrumi/initrd.gz
if [ -f (loop)/EFI/BOOT/bootx64.efi ]; then
vt_cpio_busybox64 "64h"
fi
elif [ -f (loop)/boot/initfs.x86_64-efi ]; then
vt_linux_specify_initrd_file /boot/initfs.x86_64-efi
if [ -f (loop)/boot/initfs.i386-pc ]; then
vt_linux_specify_initrd_file /boot/initfs.i386-pc
fi
elif [ -f (loop)/antiX/initrd.gz ]; then
vt_linux_specify_initrd_file /antiX/initrd.gz
elif [ -f (loop)/360Disk/initrd.gz ]; then
vt_linux_specify_initrd_file /360Disk/initrd.gz
elif [ -f (loop)/porteus/initrd.xz ]; then
vt_linux_specify_initrd_file /porteus/initrd.xz
elif [ -f (loop)/pyabr/boot/initrfs.img ]; then
vt_linux_specify_initrd_file /pyabr/boot/initrfs.img
elif [ -f (loop)/initrd0.img ]; then
vt_linux_specify_initrd_file /initrd0.img
elif [ -f (loop)/sysresccd/boot/i686/sysresccd.img ]; then
vt_linux_specify_initrd_file /sysresccd/boot/i686/sysresccd.img
elif [ -f (loop)/boot/full.cz ]; then
vt_linux_specify_initrd_file /boot/full.cz
elif [ -f (loop)/images/pxeboot/initrd.img ]; then
vt_linux_specify_initrd_file /images/pxeboot/initrd.img
elif [ -f (loop)/live/initrd ]; then
vt_linux_specify_initrd_file /live/initrd
fi
}
function ventoy_get_ghostbsd_ver {
# fallback to parse version from elf /boot/kernel/kernel
set vt_freebsd_ver=xx
}
function ventoy_get_furybsd_ver {
set vt_freebsd_ver=12.x
if regexp --set 1:vtFuryVer "(14|13)\.[0-9]" "$2"; then
set vt_freebsd_ver=${vtFuryVer}.x
fi
}
function ventoy_get_freenas_ver {
set vt_freebsd_ver=11.x
if [ -e (loop)/FreeNAS-MANIFEST ]; then
vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
if regexp --set 1:vtNasVer "^(14|13|12|11)\.[0-9]" "$vt_freenas_ver"; then
set vt_freebsd_ver=${vtNasVer}.x
fi
fi
}
function ventoy_get_truenas_ver {
set vt_freebsd_ver=12.x
if [ -e (loop)/TrueNAS-MANIFEST ]; then
vt_parse_freenas_ver (loop)/TrueNAS-MANIFEST vt_truenas_ver
if regexp --set 1:vtTNasVer "^(14|13|12|11)\.[0-9]" "$vt_truenas_ver"; then
set vt_freebsd_ver=${vtTNasVer}.x
fi
fi
}
function ventoy_get_midnightbsd_ver {
if vt_str_begin "$vt_volume_id" "1_"; then
set vt_freebsd_ver=11.x
elif vt_str_begin "$vt_volume_id" "2_"; then
set vt_freebsd_ver=2.x
elif vt_str_begin "$vt_volume_id" "3_"; then
set vt_freebsd_ver=3.x
fi
}
function ventoy_freebsd_proc {
set vtFreeBsdDistro=FreeBSD
set vt_freebsd_ver=xx
if [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
vt_unix_ko_fillmap /boot/kernel/geom_ventoy.ko
return
fi
if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
ventoy_get_ghostbsd_ver "$1" "${chosen_path}"
elif vt_strstr "$vt_volume_id" "FREENAS"; then
ventoy_get_freenas_ver "$1" "${chosen_path}"
elif vt_strstr "$vt_volume_id" "TRUENAS"; then
ventoy_get_truenas_ver "$1" "${chosen_path}"
elif vt_strstr "$vt_volume_id" "FURYBSD"; then
ventoy_get_furybsd_ver "$1" "${chosen_path}"
elif regexp --set 1:vtBsdVerNum "^(14|13|12|11|10|9)_[0-9]" "$vt_volume_id"; then
set vt_freebsd_ver=${vtBsdVerNum}.x
elif [ -d (loop)/usr/midnightbsd-dist ]; then
ventoy_get_midnightbsd_ver "$1" "${chosen_path}"
set vtFreeBsdDistro=MidnightBSD
elif [ -e (loop)/bin/freebsd-version ]; then
vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
if regexp --set 1:vtBsdVerNum "\"(14|13|12|11|10|9)\.[0-9]-" "$vt_userland_ver"; then
set vt_freebsd_ver=${vtBsdVerNum}.x
fi
elif [ -e (loop)/README.TXT ]; then
vt_1st_line (loop)/README.TXT vt_freebsd_line1
if regexp --set 1:vtBsdVerNum "FreeBSD (14|13|12|11|10|9)\.[0-9]-" "$vt_freebsd_line1"; then
set vt_freebsd_ver=${vtBsdVerNum}.x
fi
elif vt_strstr "${chosen_path}" "MidnightBSD"; then
set vt_freebsd_ver=9.x
fi
if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
set vtFreeBsdDistro=ClonOS
fi
set vt_freebsd_bit=64
for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
if [ -e (loop)/$file ]; then
if file --is-i386-kfreebsd (loop)/$file; then
set vt_freebsd_bit=32
fi
break
fi
done
if [ "$vt_freebsd_ver" = "xx" ]; then
if [ -e (loop)/boot/kernel/kernel ]; then
vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel $vt_freebsd_bit vt_freebsd_ver
elif [ -e (loop)/boot/kernel/kernel.gz ]; then
vt_unix_parse_freebsd_ver_elf (loop)/boot/kernel/kernel.gz $vt_freebsd_bit vt_freebsd_ver
fi
if [ "$vt_freebsd_ver" = "xx" ]; then
set vt_freebsd_ver=14.x
fi
fi
if [ -n "${vtdebug_flag}" ]; then
echo "This is $vtFreeBsdDistro $vt_freebsd_ver ${vt_freebsd_bit}bit"
fi
unset vt_unix_mod_path
for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/TrueNAS-MANIFEST" "/version" "/etc/fstab"; do
if [ -e (loop)${file} ]; then
set vt_unix_mod_path=${file}
break
fi
done
if [ -n "$vt_unix_mod_path" ]; then
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
vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
elif [ -e (loop)/easyre.ufs.uzip ]; then
vt_unix_replace_ko "/boot/grub/i386-pc/linux.mod" (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
if [ "$grub_platform" = "pc" ]; then
vt_unix_replace_grub_conf "/boot/grub/i386-pc/linux.mod" "cd9"
else
vt_unix_replace_conf FreeBSD "${1}${chosen_path}" "cd9"
fi
fi
}
function ventoy_dragonfly_proc {
unset vt_unix_mod_path
for file in "/boot/kernel/initrd.img.gz"; do
if [ -e (loop)${file} ]; then
set vt_unix_mod_path=${file}
break
fi
done
vt_unix_replace_ko $vt_unix_mod_path ${vtoy_path}/dragonfly.mfs.xz
vt_unix_fill_image_desc
vt_unix_gzip_new_ko
vt_unix_replace_conf DragonFly "${1}${chosen_path}"
}
function ventoy_unix_comm_proc {
vt_unix_reset
vt_unix_check_vlnk "${1}${chosen_path}"
if [ "$ventoy_compatible" = "NO" ]; then
loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
if [ "$vt_unix_type" = "FreeBSD" ]; then
ventoy_freebsd_proc "$1" "${chosen_path}"
elif [ "$vt_unix_type" = "DragonFly" ]; then
ventoy_dragonfly_proc "$1" "${chosen_path}"
elif [ "$vt_unix_type" = "NetBSD" ]; then
echo "NetBSD not supported"
else
if [ -n "${vtdebug_flag}" ]; then
echo "Unknown unix type"
fi
fi
fi
vt_unix_chain_data "${1}${chosen_path}"
ventoy_debug_pause
}
function uefi_windows_menu_func {
vt_windows_reset
unset vt_cur_wimboot_mode
if vt_check_mode 4 "$vt_chosen_name"; then
set vt_cur_wimboot_mode=1
fi
if [ "$ventoy_compatible" = "NO" -o "$vt_cur_wimboot_mode" = "1" ]; then
if [ "$ventoy_fs_probe" = "iso9660" ]; then
loopback -d loop
vt_iso9660_nojoliet 1
loopback loop "$1$2"
fi
for file in "efi/microsoft/boot/bcd"; do
vt_windows_collect_wim_patch bcd (loop)/$file
done
vt_windows_count_wim_patch vt_wim_cnt
if [ $vt_wim_cnt -eq 0 ]; then
distro_specify_wim_patch_phase2
fi
ventoy_debug_pause
locate_wim "${chosen_path}"
fi
vt_windows_chain_data "${1}${chosen_path}"
ventoy_debug_pause
if [ "$vt_cur_wimboot_mode" = "1" ]; then
vtoy_wimboot_func
fi
if [ -n "$vtoy_chain_mem_addr" ]; then
ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} iso_${ventoy_fs_probe} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
boot
else
echo "chain empty failed"
ventoy_pause
fi
}
function uefi_find_replace_initrd {
if vt_get_efi_vdisk_offset "${1}${2}" vt_efivdisk_offset; then
loopback -s $vt_efivdisk_offset vtefivdisk "${1}${2}"
unset vt_rp_initrd
vt_search_replace_initrd (vtefivdisk) vt_rp_initrd
if [ -n "$vt_rp_initrd" ]; then
vt_add_replace_file $3 "$vt_rp_initrd"
fi
loopback -d vtefivdisk
ventoy_debug_pause
fi
}
function uefi_linux_menu_func {
if [ "$ventoy_compatible" = "NO" ]; then
if [ "$ventoy_fs_probe" = "udf" ]; then
loopback -d loop
set ventoy_fs_probe=iso9660
loopback loop "$1$2"
fi
vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
vt_linux_clear_initrd
if [ -d (loop)/pmagic ]; then
vt_linux_specify_initrd_file /pmagic/initrd.img
else
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
if [ -e (loop)/$file ]; then
vt_linux_parse_initrd_grub file (loop)/$file
fi
done
fi
# special process for special distros
if [ -d (loop)/loader/entries ]; then
vt_linux_parse_initrd_grub dir (loop)/loader/entries/
elif [ -d (loop)/boot/grub ]; then
vt_linux_parse_initrd_grub dir (loop)/boot/grub/
fi
distro_specify_initrd_file
vt_linux_initrd_count vtcount
if [ $vtcount -eq 0 ]; then
if [ -e (loop)/EFI/boot/livegrub.cfg ]; then
vt_linux_parse_initrd_grub file (loop)/EFI/boot/livegrub.cfg
fi
distro_specify_initrd_file_phase2
if [ "$vt_efi_dir" = "NO" ]; then
if [ -f (loop)/efi.img ]; then
vt_add_replace_file 0 "initrd"
fi
fi
fi
locate_initrd
if [ -d (loop)/loader/entries ]; then
vt_linux_get_main_initrd_index vtindex
if [ -d (loop)/arch ]; then
if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
elif [ -f (loop)/arch/boot/x86_64/initramfs-linux.img ]; then
vt_add_replace_file $vtindex "arch\\boot\\x86_64\\initramfs-linux.img"
elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
fi
elif [ -d (loop)/blackarch ]; then
if [ -f (loop)/blackarch/boot/x86_64/archiso.img ]; then
vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
elif [ -f (loop)/blackarch/boot/x86_64/initramfs-linux.img ]; then
vt_add_replace_file $vtindex "blackarch\\boot\\x86_64\\initramfs-linux.img"
fi
elif [ -d (loop)/anarchy ]; then
if [ -f (loop)/anarchy/boot/x86_64/initramfs-linux.img ]; then
vt_add_replace_file $vtindex "anarchy\\boot\\x86_64\\initramfs-linux.img"
fi
elif [ -d (loop)/parabola ]; then
if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
vt_add_replace_file $vtindex "EFI\\parabolaiso\\parabolaiso.img"
elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
fi
elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
elif [ -f (loop)/loader/entries/thinstation.conf ]; then
vt_add_replace_file $vtindex "boot\\initrd"
elif [ -f (loop)/loader/entries/pisi-efi-x86_64.conf ]; then
vt_add_replace_file $vtindex "EFI\\pisi\\initrd.img"
fi
vt_get_replace_file_cnt vt_replace_cnt
if [ $vt_replace_cnt -eq 0 ]; then
uefi_find_replace_initrd "$1" "$2" $vtindex
fi
elif [ -d (loop)/EFI/boot/entries ]; then
if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
fi
elif [ -d (loop)/EFI/BOOT/entries ]; then
vt_linux_get_main_initrd_index vtindex
if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
elif [ -f (loop)/parabola/boot/x86_64/initramfs-linux-libre.img ]; then
vt_add_replace_file $vtindex "parabola\\boot\\x86_64\\initramfs-linux-libre.img"
fi
elif [ -e (loop)/syslinux/alt0/full.cz ]; then
vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
elif vt_str_begin "$vt_volume_id" "SolusLive"; then
vt_add_replace_file 0 "initrd"
fi
fi
vt_linux_chain_data "${1}${chosen_path}"
if [ -n "$LoadIsoEfiDriver" -a $vt_chosen_size -LT 104857600 ]; then
if [ -f (loop)/efi/clover/cloverx64.efi ]; then
unset LoadIsoEfiDriver
fi
fi
if [ -n "$vtoy_chain_mem_addr" ]; then
ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
ventoy_cli_console
unset vtGrub2Mode
if vt_check_mode 3 "$vt_chosen_name"; then
set vtGrub2Mode=1
elif vt_str_begin "$vt_volume_id" "HOLO_"; then
if [ -d (loop)/loader/entries ]; then
set vtGrub2Mode=1
fi
elif vt_str_begin "$vt_volume_id" "KRD"; then
if [ -f (loop)/boot/grub/grub.cfg.sig ]; then
set vtGrub2Mode=1
fi
fi
if [ -n "$vtGrub2Mode" ]; then
ventoy_debug_pause
else
if [ "$VTOY_EFI_ARCH" != "mips" ]; then
chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi fallback env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
boot
fi
fi
# fallback
set vtback_root=$root
vt_push_last_entry
set vtback_theme=$theme
unset theme
vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
vt_set_boot_opt rdinit=/vtoy/vtoy
set root=(loop)
set vtback_cfg_find=0
for cfg in "/boot/grub/grub.cfg" "/EFI/BOOT/grub.cfg" "/EFI/debian/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "/grub/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
if [ -e "$cfg" ]; then
set vtback_cfg_find=1
configfile "$cfg"
break
fi
done
if [ $vtback_cfg_find -eq 0 ]; then
if [ -f (loop)/loader/loader.conf -a -d (loop)/loader/entries ]; then
if vt_str_begin "$vt_volume_id" "HOLO_"; then
set root=(loop,2)
vt_systemd_menu (loop,2) vt_sys_menu_mem
else
vt_systemd_menu (loop) vt_sys_menu_mem
fi
set vtback_cfg_find=1
configfile "mem:${vt_sys_menu_mem_addr}:size:${vt_sys_menu_mem_size}"
fi
fi
if [ $vtback_cfg_find -eq 0 ]; then
if [ -f (loop)/boot/isolinux/syslnx64.cfg ]; then
syslinux_configfile (loop)/boot/isolinux/syslnx64.cfg
set vtback_cfg_find=1
elif [ -f (loop)/boot/syslinux/porteus.cfg ]; then
syslinux_configfile (loop)/boot/syslinux/porteus.cfg
set vtback_cfg_find=1
fi
fi
if [ "$vtback_cfg_find" = "0" ]; then
echo " "
echo "No bootfile found for UEFI!"
echo "Maybe the image does not support $VTOY_EFI_ARCH UEFI"
echo " "
sleep 30
fi
vt_unset_boot_opt
set root=$vtback_root
set theme=$vtback_theme
vt_pop_last_entry
ventoy_gui_console
else
echo "chain empty failed"
ventoy_pause
fi
}
function uefi_unix_menu_func {
ventoy_unix_comm_proc $1 "${chosen_path}"
if [ -n "$vtoy_chain_mem_addr" ]; then
ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
boot
else
echo "chain empty failed"
ventoy_pause
fi
}
function ventoy_reset_nojoliet {
if vt_str_begin "$vt_volume_id" "ARCARESCUE"; then
vt_iso9660_nojoliet 1
else
vt_iso9660_nojoliet 0
fi
vt_append_extra_sector 0
}
function uefi_iso_menu_func {
if [ -n "$vtisouefi" ]; then
set LoadIsoEfiDriver=on
unset vtisouefi
elif vt_check_mode 2 "$vt_chosen_name"; then
set LoadIsoEfiDriver=on
else
unset LoadIsoEfiDriver
fi
set chosen_path="$2"
vt_select_auto_install "${chosen_path}"
vt_select_persistence "${chosen_path}"
if ! vt_is_udf "${1}${chosen_path}"; then
# Lenovo EasyStartup need an addional sector for boundary check
if vt_str_begin "$vt_volume_id" "EasyStartup"; then
vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
vt_append_extra_sector 1
fi
fi
if [ -d (loop)/EFI ]; then
set vt_efi_dir=YES
elif [ -d (loop)/efi ]; then
set vt_efi_dir=YES
else
set vt_efi_dir=NO
fi
if [ -n "$vtcompat" ]; then
set ventoy_compatible=YES
unset vtcompat
elif vt_check_mode 1 "$vt_chosen_name"; then
set ventoy_compatible=YES
else
vt_check_compatible (loop)
fi
vt_img_sector "${1}${chosen_path}"
if [ "$ventoy_fs_probe" = "iso9660" ]; then
vt_select_conf_replace "${1}" "${chosen_path}"
fi
if [ "$vtoy_os" = "Windows" ]; then
vt_check_compatible_pe (loop)
uefi_windows_menu_func "$1" "${chosen_path}"
elif [ "$vtoy_os" = "Unix" ]; then
uefi_unix_menu_func "$1" "${chosen_path}"
else
vt_check_compatible_linux (loop)
uefi_linux_menu_func "$1" "${chosen_path}"
fi
ventoy_gui_console
}
function uefi_iso_memdisk {
echo 'Loading ISO file to memory ...'
vt_load_img_memdisk "${1}${2}" vtoy_iso_buf
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
boot
ventoy_gui_console
}
function vtoy_windows_wimboot {
if [ -f (loop)/x86/sources/boot.wim -a -f (loop)/x64/sources/boot.wim ]; then
vt_sel_wimboot vtoy_wimboot_bit
if [ "$vtoy_wimboot_bit" = "32" ]; then
set vtoy_wimboot_prefix=(loop)/x86
else
set vtoy_wimboot_prefix=(loop)/x64
fi
else
set vtoy_wimboot_prefix=(loop)
if vt_is_pe64 $vtoy_wimboot_prefix/setup.exe; then
set vtoy_wimboot_bit=64
else
set vtoy_wimboot_bit=32
fi
fi
if [ -n "${vtdebug_flag}" ]; then
echo vtoy_wimboot_prefix=$vtoy_wimboot_prefix vtoy_wimboot_bit=$vtoy_wimboot_bit vt_wimkernel=$vt_wimkernel
fi
vt_windows_wimboot_data "$vtoy_wimboot_prefix/sources/boot.wim" vtoy_init_exe vtoy_wim_bit
if [ "$grub_platform" = "pc" ]; then
linux16 "$vtoy_path/$vt_wimkernel" quiet
ventoy_debug_pause
vt_set_wim_load_prompt 1 "Loading files......"
initrd16 newc:winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size} \
newc:vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd \
newc:bcd:$vtoy_wimboot_prefix/boot/bcd \
newc:boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi \
newc:boot.wim:$vtoy_wimboot_prefix/sources/boot.wim
vt_set_wim_load_prompt 0
boot
else
vt_set_wim_load_prompt 1 "Loading files......"
vt_load_file_to_mem "nodecompress" $vtoy_wimboot_prefix/sources/boot.wim vtoy_wimfile_mem
vt_set_wim_load_prompt 0
if [ $? -eq 0 ]; then
set vtoy_wimfile_path=mem:${vtoy_wimfile_mem_addr}:size:${vtoy_wimfile_mem_size}
else
set vtoy_wimfile_path=$vtoy_wimboot_prefix/sources/boot.wim
fi
ventoy_cli_console
chainloader "$vtoy_path/$vt_wimkernel" quiet \
"vf=winpeshl.exe:mem:${vtoy_wimboot_mem_addr}:size:${vtoy_wimboot_mem_size}" \
"vf=vtoy_wimboot:$vtoy_wimboot_prefix/boot/bcd" \
"vf=bcd:$vtoy_wimboot_prefix/boot/bcd" \
"vf=boot.sdi:$vtoy_wimboot_prefix/boot/boot.sdi" \