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