]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/ventoy_chain.sh
Correct EFI chainloader image device path (#2397)
[Ventoy.git] / IMG / cpio / ventoy / ventoy_chain.sh
1 #!/ventoy/busybox/sh
2 #************************************************************************************
3 # Copyright (c) 2020, longpanda <admin@ventoy.net>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, see <http://www.gnu.org/licenses/>.
17 #
18 #************************************************************************************
19
20 ####################################################################
21 # #
22 # Step 1 : Parse kernel parameter #
23 # #
24 ####################################################################
25 if ! [ -e /proc ]; then
26 $BUSYBOX_PATH/mkdir /proc
27 rmproc='Y'
28 fi
29 $BUSYBOX_PATH/mount -t proc proc /proc
30
31 # vtinit=xxx to replace rdinit=xxx
32 vtcmdline=$($CAT /proc/cmdline)
33 for i in $vtcmdline; do
34 if echo $i | $GREP -q vtinit; then
35 user_rdinit=${i#vtinit=}
36 echo "user set user_rdinit=${user_rdinit}" >>$VTLOG
37 fi
38 done
39
40 ####################################################################
41 # #
42 # Step 2 : Do OS specific hook #
43 # #
44 ####################################################################
45 ventoy_get_os_type() {
46 echo "kernel version" >> $VTLOG
47 $CAT /proc/version >> $VTLOG
48
49 if [ -d /twres ]; then
50 if $GREP -q 'Phoenix' /init; then
51 echo 'phoenixos'; return
52 fi
53 fi
54
55 # PrimeOS :
56 if $GREP -q 'PrimeOS' /proc/version; then
57 echo 'primeos'; return
58
59 # Debian :
60 elif $GREP -q '[Dd]ebian' /proc/version; then
61 echo 'debian'; return
62
63 # Ubuntu : do the same process with debian
64 elif $GREP -q '[Uu]buntu' /proc/version; then
65 echo 'debian'; return
66
67 # Deepin : do the same process with debian
68 elif $GREP -q '[Dd]eepin' /proc/version; then
69 echo 'debian'; return
70
71 # rhel5/CentOS5 and all other distributions based on them
72 elif $GREP -q 'el5' /proc/version; then
73 echo 'rhel5'; return
74
75 # rhel6/CentOS6 and all other distributions based on them
76 elif $GREP -q 'el6' /proc/version; then
77 if [ -f /sbin/detectcd ]; then
78 if $GREP -q -i 'LENOVO-EasyStartup' /sbin/detectcd; then
79 echo 'easystartup'; return
80 fi
81 fi
82
83 echo 'rhel6'; return
84
85 # rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
86 elif $GREP -q 'el[78]' /proc/version; then
87 echo 'rhel7'; return
88
89 # Maybe rhel9 rhel1x use the same way? Who knows!
90 elif $EGREP -q 'el9|el1[0-9]' /proc/version; then
91 echo 'rhel7'; return
92
93 # Fedora : do the same process with rhel7
94 elif $GREP -q '\.fc[0-9][0-9]\.' /proc/version; then
95 echo 'rhel7'; return
96
97 elif $GREP -q 'euleros' /proc/version; then
98 echo 'rhel7'; return
99
100 # SUSE
101 elif $GREP -q 'SUSE' /proc/version; then
102 echo 'suse'; return
103
104 # ArchLinux
105 elif $EGREP -q 'archlinux|ARCH' /proc/version; then
106 echo 'arch'; return
107
108 # kiosk
109 elif $EGREP -q 'kiosk' /proc/version; then
110 echo 'kiosk'; return
111
112 # gentoo
113 elif $EGREP -q '[Gg]entoo' /proc/version; then
114 if $GREP -q 'daphile' /proc/version; then
115 echo 'daphile'; return
116 fi
117
118 echo 'gentoo'; return
119
120 # TinyCore
121 elif $EGREP -q 'tinycore' /proc/version; then
122 echo 'tinycore'; return
123
124 # manjaro
125 elif $EGREP -q 'manjaro|MANJARO' /proc/version; then
126 echo 'manjaro'; return
127
128 # mageia
129 elif $EGREP -q 'mageia' /proc/version; then
130 echo 'mageia'; return
131
132 # pclinux OS
133 elif $GREP -i -q 'PCLinuxOS' /proc/version; then
134 echo 'pclos'; return
135
136 # KaOS
137 elif $GREP -i -q 'kaos' /proc/version; then
138 echo 'kaos'; return
139
140 # Alpine
141 elif $GREP -q 'Alpine' /proc/version; then
142 echo 'alpine'; return
143
144 elif $GREP -i -q 'PhoenixOS' /proc/version; then
145 echo 'phoenixos'; return
146
147 # NixOS
148 elif $GREP -i -q 'NixOS' /proc/version; then
149 echo 'nixos'; return
150
151
152 fi
153
154 if [ -e /lib/debian-installer ]; then
155 echo 'debian'; return
156 fi
157
158 if [ -e /etc/os-release ]; then
159 if $GREP -q 'XenServer' /etc/os-release; then
160 echo 'xen'; return
161 elif $GREP -q 'SUSE ' /etc/os-release; then
162 echo 'suse'; return
163 elif $GREP -q 'uruk' /etc/os-release; then
164 echo 'debian'; return
165 elif $GREP -q 'Solus' /etc/os-release; then
166 echo 'rhel7'; return
167 elif $GREP -q 'openEuler' /etc/os-release; then
168 echo 'openEuler'; return
169 elif $GREP -q 'fuyu' /etc/os-release; then
170 echo 'openEuler'; return
171 elif $GREP -q 'deepin' /etc/os-release; then
172 echo 'debian'; return
173 elif $GREP -q 'chinauos' /etc/os-release; then
174 echo 'debian'; return
175 fi
176 fi
177
178 if $BUSYBOX_PATH/dmesg | $GREP -q -m1 "Xen:"; then
179 echo 'xen'; return
180 fi
181
182
183 if [ -e /etc/HOSTNAME ] && $GREP -i -q 'slackware' /etc/HOSTNAME; then
184 echo 'slackware'; return
185 fi
186
187 if [ -e /init ]; then
188 if $GREP -i -q zeroshell /init; then
189 echo 'zeroshell'; return
190 fi
191 fi
192
193 if $EGREP -q 'ALT ' /proc/version; then
194 echo 'alt'; return
195 fi
196
197 if $EGREP -q 'porteus' /proc/version; then
198 echo 'debian'; return
199 fi
200
201 if $GREP -q 'Clear Linux ' /proc/version; then
202 echo 'clear'; return
203 fi
204
205 if $GREP -q 'artix' /proc/version; then
206 echo 'arch'; return
207 fi
208
209 if $GREP -q 'berry ' /proc/version; then
210 echo 'berry'; return
211 fi
212
213 if $GREP -q 'Gobo ' /proc/version; then
214 echo 'gobo'; return
215 fi
216
217 if $GREP -q 'NuTyX' /proc/version; then
218 echo 'nutyx'; return
219 fi
220
221 if [ -d /gnu ]; then
222 vtLineNum=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
223 if [ $vtLineNum -gt 0 ]; then
224 echo 'guix'; return
225 fi
226 fi
227
228 if $GREP -q 'android.x86' /proc/version; then
229 echo 'android'; return
230 fi
231
232 if $GREP -q 'android.google' /proc/version; then
233 echo 'android'; return
234 fi
235
236 if $GREP -q 'adelielinux' /proc/version; then
237 echo 'adelie'; return
238 fi
239
240 if $GREP -q 'pmagic' /proc/version; then
241 echo 'pmagic'; return
242 fi
243
244 if $GREP -q 'CDlinux' /proc/cmdline; then
245 echo 'cdlinux'; return
246 fi
247
248 if $GREP -q 'parabola' /proc/version; then
249 echo 'parabola'; return
250 fi
251
252 if $GREP -q 'cucumber' /proc/version; then
253 echo 'cucumber'; return
254 fi
255
256 if $GREP -q 'fatdog' /proc/version; then
257 echo 'fatdog'; return
258 fi
259
260 if $GREP -q 'KWORT' /proc/version; then
261 echo 'kwort'; return
262 fi
263
264 if $GREP -q 'iwamoto' /proc/version; then
265 echo 'vine'; return
266 fi
267
268 if $GREP -q 'hyperbola' /proc/cmdline; then
269 echo 'hyperbola'; return
270 fi
271
272 if $GREP -q 'CRUX' /proc/version; then
273 echo 'crux'; return
274 fi
275
276 if [ -f /init ]; then
277 if $GREP -q 'AryaLinux' /init; then
278 echo 'aryalinux'; return
279 elif $GREP -q 'Dragora' /init; then
280 echo 'dragora'; return
281
282 fi
283 fi
284
285 if $GREP -q 'slackware' /proc/version; then
286 echo 'slackware'; return
287 fi
288
289 if $BUSYBOX_PATH/hostname | $GREP -q 'smoothwall'; then
290 echo 'smoothwall'; return
291 fi
292
293 if $GREP -q 'photon' /proc/version; then
294 echo 'photon'; return
295 fi
296
297 if $GREP -q 'ploplinux' /proc/version; then
298 echo 'ploplinux'; return
299 fi
300
301 if $GREP -q 'lunar' /proc/version; then
302 echo 'lunar'; return
303 fi
304
305 if $GREP -q 'SMGL-' /proc/version; then
306 echo 'smgl'; return
307 fi
308
309 if $GREP -q 'rancher' /proc/version; then
310 echo 'rancher'; return
311 fi
312
313
314 if [ -e /init ]; then
315 if $GREP -q -m1 'T2 SDE' /init; then
316 echo 't2'; return
317 fi
318 fi
319
320 if $GREP -q 'wifislax' /proc/version; then
321 echo 'wifislax'; return
322 fi
323
324 if $GREP -q 'pisilinux' /proc/version; then
325 echo 'pisilinux'; return
326 fi
327
328 if $GREP -q 'blackPanther' /proc/version; then
329 echo 'blackPanther'; return
330 fi
331
332 if $GREP -q 'primeos' /proc/version; then
333 echo 'primeos'; return
334 fi
335
336 if $GREP -q 'austrumi' /proc/version; then
337 echo 'austrumi'; return
338 fi
339
340 if [ -f /DISTRO_SPECS ]; then
341 if $GREP -q '[Pp]uppy' /DISTRO_SPECS; then
342 echo 'debian'; return
343 elif $GREP -q 'veket' /DISTRO_SPECS; then
344 echo 'debian'; return
345 fi
346 fi
347
348 if [ -f /etc/openEuler-release ]; then
349 echo "openEuler"; return
350 fi
351
352
353 #special arch based iso file check
354 if [ -f /init ]; then
355 if $GREP -q 'mount_handler' /init; then
356 if [ -d /hooks ]; then
357 if $BUSYBOX_PATH/ls -1 /hooks/ | $GREP -q '.*iso$'; then
358 echo "arch"; return
359 fi
360 elif [ -d /hook ]; then
361 if $BUSYBOX_PATH/ls -1 /hook/ | $GREP -q '.*iso$'; then
362 echo "arch"; return
363 fi
364 fi
365 fi
366 fi
367
368
369 #Kylin V10 Server
370 if [ -f /usr/sbin/dhclient ]; then
371 if $BUSYBOX_PATH/strings /usr/sbin/dhclient | $GREP -i -q -m1 openeuler; then
372 echo 'openEuler'; return
373 fi
374 fi
375
376 if $GREP -q 'chimera' /proc/version; then
377 echo 'chimera'; return
378 fi
379
380 echo "default"
381 }
382
383 VTOS=$(ventoy_get_os_type)
384 echo "OS=###${VTOS}###" >>$VTLOG
385 if [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
386 $BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
387 fi
388
389
390
391 if $GREP -q -i Untangle /proc/version; then
392 for vtPara in $($CAT /proc/cmdline); do
393 vtItemkey=$(echo $vtPara | $AWK -F= '{print $1}')
394 vtItemVal=$(echo $vtPara | $AWK -F= '{print $2}')
395 if $GREP -q -m1 "^$vtItemkey\$" $VTOY_PATH/hook/default/export.list; then
396 vtEnvExport="$vtEnvExport $vtItemkey=$vtItemVal"
397 fi
398 done
399
400 echo "================ env export ================" >> $VTLOG
401 echo $vtEnvExport >> $VTLOG
402 echo "============================================" >> $VTLOG
403 fi
404
405
406
407 ####################################################################
408 # #
409 # Step 3 : Run LiveInjection Hook #
410 # #
411 ####################################################################
412 if [ -f "/live_injection_7ed136ec_7a61_4b54_adc3_ae494d5106ea/hook.sh" ]; then
413 $BUSYBOX_PATH/sh "/live_injection_7ed136ec_7a61_4b54_adc3_ae494d5106ea/hook.sh" $VTOS
414 fi
415
416
417 ####################################################################
418 # #
419 # Step 4 : Check for debug break #
420 # #
421 ####################################################################
422 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
423 $SLEEP 5
424 echo -e "\n\n\033[32m ################################################# \033[0m"
425 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
426 echo -e "\033[32m ################################################# \033[0m \n"
427 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
428 $CAT $VTOY_PATH/log
429 fi
430 exec $BUSYBOX_PATH/sh
431 fi
432
433
434 ####################################################################
435 # #
436 # Step 5 : Hand over to real init #
437 # #
438 ####################################################################
439 $BUSYBOX_PATH/umount /proc
440 if [ "$rmproc" = "Y" ]; then
441 $BUSYBOX_PATH/rm -rf /proc
442 fi
443
444 if [ -f $VTOY_PATH/ventoy_persistent_map ]; then
445 export PERSISTENT='YES'
446 export PERSISTENCE='true'
447 fi
448
449 cd /
450
451 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD vtcmdline
452
453 for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
454 if [ -d /ventoy_rdroot ]; then
455 if [ -e "/ventoy_rdroot$vtinit" ]; then
456 # switch_root will check /init file, this is a cheat code
457 echo 'switch_root' > /init
458 exec $BUSYBOX_PATH/switch_root /ventoy_rdroot "$vtinit"
459 fi
460 else
461 if [ -e "$vtinit" ];then
462 if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
463 $BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
464 fi
465
466 if [ -z "$vtEnvExport" ]; then
467 exec "$vtinit"
468 else
469 exec env $vtEnvExport "$vtinit"
470 fi
471 fi
472 fi
473 done
474
475 # Should never reach here
476 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
477 exec $BUSYBOX_PATH/sh