]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/grub/grub.cfg
Update README.md
[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 get_os_type {
20 set vtoy_os=Linux
21 for file in "efi/microsoft" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com"; do
22 if [ -e $1/$file ]; then
23 set vtoy_os=Windows
24 break
25 fi
26 done
27
28 if [ -n "${vtdebug_flag}" ]; then
29 echo ISO is $vtoy_os
30 fi
31 }
32
33 function locate_initrd {
34 vt_linux_locate_initrd
35
36 if [ -n "${vtdebug_flag}" ]; then
37 vt_linux_dump_initrd
38 sleep 5
39 fi
40 }
41
42 function find_wim_file {
43 unset ventoy_wim_file
44
45 for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" "winpe_x64.wim"; do
46 if [ -e $1/$file ]; then
47 set ventoy_wim_file=$1/$file
48 break
49 fi
50 done
51 }
52
53 function distro_specify_initrd_file {
54 if [ -e (loop)/boot/all.rdz ]; then
55 vt_linux_specify_initrd_file /boot/all.rdz
56 elif [ -e (loop)/boot/xen.gz ]; then
57 if [ -e (loop)/install.img ]; then
58 vt_linux_specify_initrd_file /install.img
59 fi
60 elif [ -d (loop)/casper ]; then
61 if [ -e (loop)/casper/initrd ]; then
62 vt_linux_specify_initrd_file /casper/initrd
63 fi
64 if [ -e (loop)/casper/initrd-oem ]; then
65 vt_linux_specify_initrd_file /casper/initrd-oem
66 fi
67 elif [ -e (loop)/boot/grub/initrd.xz ]; then
68 vt_linux_specify_initrd_file /boot/grub/initrd.xz
69 elif [ -e (loop)/initrd.gz ]; then
70 vt_linux_specify_initrd_file /initrd.gz
71 elif [ -e (loop)/slax/boot/initrfs.img ]; then
72 vt_linux_specify_initrd_file /slax/boot/initrfs.img
73 elif [ -e (loop)/pmagic/initrd.img ]; then
74 vt_linux_specify_initrd_file /pmagic/initrd.img
75 elif [ -e (loop)/boot/initrd.xz ]; then
76 vt_linux_specify_initrd_file /boot/initrd.xz
77 elif [ -f (loop)/boot/initrd ]; then
78 vt_linux_specify_initrd_file /boot/initrd
79
80 fi
81 }
82
83 function uefi_windows_menu_func {
84 vt_windows_reset
85
86 if [ "$ventoy_compatible" = "NO" ]; then
87 find_wim_file (loop)
88 if [ -n "$ventoy_wim_file" ]; then
89 vt_windows_locate_wim $ventoy_wim_file
90 fi
91 fi
92
93 vt_windows_chain_data ${1}${chosen_path}
94
95 if [ -n "${vtdebug_flag}" ]; then
96 sleep 5
97 fi
98
99 if [ -n "$vtoy_chain_mem_addr" ]; then
100 terminal_output console
101 chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
102 boot
103 else
104 echo "chain empty failed"
105 sleep 5
106 fi
107 }
108
109 function uefi_linux_menu_func {
110 if [ "$ventoy_compatible" = "NO" ]; then
111 vt_load_cpio ${vtoy_path}/ventoy.cpio
112
113 vt_linux_clear_initrd
114
115 if [ -d (loop)/pmagic ]; then
116 vt_linux_specify_initrd_file /pmagic/initrd.img
117 else
118 for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
119 if [ -e (loop)/$file ]; then
120 vt_linux_parse_initrd_grub file (loop)/$file
121 fi
122 done
123 fi
124
125 # special process for special distros
126 if [ -d (loop)/loader/entries ]; then
127 set LoadIsoEfiDriver=on
128 vt_linux_parse_initrd_grub dir (loop)/loader/entries/
129 elif [ -d (loop)/boot/grub ]; then
130 vt_linux_parse_initrd_grub dir (loop)/boot/grub/
131 fi
132
133 if [ -e (loop)/syslinux/alt0/full.cz ]; then
134 set LoadIsoEfiDriver=on
135 set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
136 fi
137
138 distro_specify_initrd_file
139
140 locate_initrd
141 fi
142
143 vt_linux_chain_data ${1}${chosen_path}
144
145 if [ -n "$vtoy_chain_mem_addr" ]; then
146 terminal_output console
147 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}
148 boot
149 else
150 echo "chain empty failed"
151 sleep 5
152 fi
153 }
154
155
156 function uefi_iso_menu_func {
157
158 if [ -d (loop)/ ]; then
159 loopback -d loop
160 fi
161
162 if [ -n "$vtisouefi" ]; then
163 set LoadIsoEfiDriver=on
164 unset vtisouefi
165 elif [ -n "$VTOY_ISO_UEFI_DRV" ]; then
166 set LoadIsoEfiDriver=on
167 else
168 unset LoadIsoEfiDriver
169 fi
170
171 vt_chosen_img_path chosen_path
172
173 if vt_is_udf ${1}${chosen_path}; then
174 set ventoy_fs_probe=udf
175 else
176 set ventoy_fs_probe=iso9660
177 fi
178
179 loopback loop ${1}${chosen_path}
180 get_os_type (loop)
181
182 if [ -n "$vtcompat" ]; then
183 set ventoy_compatible=YES
184 unset vtcompat
185 elif [ -n "$VTOY_ISO_RAW" ]; then
186 set ventoy_compatible=YES
187 else
188 vt_check_compatible (loop)
189 fi
190
191 vt_img_sector ${1}${chosen_path}
192
193 if [ "$vtoy_os" = "Windows" ]; then
194 if [ "$ventoy_fs_probe" = "iso9660" ]; then
195 set ventoy_compatible=YES
196 fi
197
198 uefi_windows_menu_func $1
199 else
200 uefi_linux_menu_func $1
201 fi
202
203 terminal_output gfxterm
204 }
205
206 function uefi_iso_memdisk {
207 vt_chosen_img_path chosen_path
208
209 echo 'Loading ISO file to memory ...'
210 vt_load_iso_to_mem ${1}${chosen_path} vtoy_iso_buf
211
212 terminal_output console
213 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}
214 boot
215 }
216
217
218
219
220 function legacy_windows_menu_func {
221 vt_windows_reset
222
223 if [ "$ventoy_compatible" = "NO" ]; then
224 find_wim_file (loop)
225 if [ -n "$ventoy_wim_file" ]; then
226 vt_windows_locate_wim $ventoy_wim_file
227 elif [ -n "${vtdebug_flag}" ]; then
228 echo No wim file found
229 fi
230 fi
231
232 vt_windows_chain_data ${1}${chosen_path}
233
234 if [ -n "${vtdebug_flag}" ]; then
235 sleep 5
236 fi
237
238 if [ -n "$vtoy_chain_mem_addr" ]; then
239 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft
240 initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
241 boot
242 else
243 echo "chain empty failed"
244 sleep 5
245 fi
246 }
247
248 function legacy_linux_menu_func {
249 if [ "$ventoy_compatible" = "NO" ]; then
250
251 vt_load_cpio $vtoy_path/ventoy.cpio
252
253 vt_linux_clear_initrd
254
255 if [ -d (loop)/pmagic ]; then
256 vt_linux_specify_initrd_file /pmagic/initrd.img
257 else
258 for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
259 if [ -d (loop)/$dir ]; then
260 vt_linux_parse_initrd_isolinux (loop)/$dir/
261 fi
262 done
263 fi
264
265 # special process for special distros
266 #archlinux
267 if [ -d (loop)/arch/boot/syslinux ]; then
268 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
269 vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
270
271 #manjaro
272 elif [ -d (loop)/manjaro ]; then
273 if [ -e (loop)/boot/grub/kernels.cfg ]; then
274 vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
275 fi
276 elif [ -e (loop)/boot/grub/grub.cfg ]; then
277 vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
278 fi
279
280 distro_specify_initrd_file
281
282 locate_initrd
283 fi
284
285 vt_linux_chain_data ${1}${chosen_path}
286
287 if [ -n "${vtdebug_flag}" ]; then
288 sleep 5
289 fi
290
291 if [ -n "$vtoy_chain_mem_addr" ]; then
292 linux16 $vtoy_path/ipxe.krn ${vtdebug_flag}
293 initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
294 boot
295 else
296 echo "chain empty failed"
297 sleep 5
298 fi
299 }
300
301 function legacy_iso_menu_func {
302
303 if [ -d (loop)/ ]; then
304 loopback -d loop
305 fi
306
307 vt_chosen_img_path chosen_path
308
309 if vt_is_udf ${1}${chosen_path}; then
310 set ventoy_fs_probe=udf
311 else
312 set ventoy_fs_probe=iso9660
313 fi
314
315 loopback loop ${1}${chosen_path}
316
317 get_os_type (loop)
318
319 if [ -n "$vtcompat" ]; then
320 set ventoy_compatible=YES
321 unset vtcompat
322 elif [ -n "$VTOY_ISO_RAW" ]; then
323 set ventoy_compatible=YES
324 else
325 vt_check_compatible (loop)
326 fi
327
328 vt_img_sector ${1}${chosen_path}
329
330 if [ "$vtoy_os" = "Windows" ]; then
331 if [ "$ventoy_fs_probe" = "iso9660" ]; then
332 set ventoy_compatible=YES
333 fi
334 legacy_windows_menu_func $1
335 else
336 legacy_linux_menu_func $1
337 fi
338 }
339
340 function legacy_iso_memdisk {
341 vt_chosen_img_path chosen_path
342
343 linux16 $vtoy_path/memdisk iso raw
344 echo "Loading ISO file to memory ..."
345 initrd16 ${1}${chosen_path}
346 boot
347 }
348
349
350 #############################################################
351 #############################################################
352 #############################################################
353 ####### Main Process ###########
354 #############################################################
355 #############################################################
356 #############################################################
357
358 set VENTOY_VERSION="1.0.06"
359
360 #disable timeout
361 unset timeout
362
363 set VTOY_MEM_DISK_STR="MEMDISK"
364 set VTOY_ISO_RAW_STR="ISO RAW"
365 set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
366
367 vt_device $root vtoy_dev
368
369 if [ "$vtoy_dev" = "tftp" ]; then
370 set vtoy_path=($root)
371 for vtid in 0 1 2 3; do
372 if [ -d (hd$vtid,2)/ventoy ]; then
373 set iso_path=(hd$vtid,1)
374 break
375 fi
376 done
377 else
378 set vtoy_path=($root)/ventoy
379 set iso_path=($vtoy_dev,1)
380 fi
381
382 loadfont ascii
383
384 if [ -f $iso_path/ventoy/ventoy.json ]; then
385 vt_load_plugin $iso_path
386 fi
387
388 terminal_output gfxterm
389
390 if [ -n "$vtoy_theme" ]; then
391 set theme=$vtoy_theme
392 else
393 set theme=$prefix/themes/ventoy/theme.txt
394 fi
395
396 if [ -n "$vtoy_gfxmode" ]; then
397 set gfxmode=$vtoy_gfxmode
398 else
399 set gfxmode=1024x768
400 fi
401
402 #colect all image files (iso files)
403 set ventoy_img_count=0
404 vt_list_img $iso_path ventoy_img_count
405
406 #Dynamic menu for every iso file
407 if vt_cmp $ventoy_img_count ne 0; then
408 set imgid=0
409 while vt_cmp $imgid lt $ventoy_img_count; do
410 vt_img_name $imgid img_name
411 menuentry "$img_name" {
412 if [ "$grub_platform" = "pc" ]; then
413 if [ -n "$VTOY_MEM_DISK" ]; then
414 legacy_iso_memdisk $iso_path
415 else
416 legacy_iso_menu_func $iso_path
417 fi
418 else
419 if [ -n "$VTOY_MEM_DISK" ]; then
420 uefi_iso_memdisk $iso_path
421 else
422 uefi_iso_menu_func $iso_path
423 fi
424 fi
425 }
426
427 vt_incr imgid 1
428 done
429 else
430 menuentry "No ISO files found (Press enter to reboot ...)" {
431 echo -e "\n Rebooting ... "
432 reboot
433 }
434 fi
435