2 #************************************************************************************
3 # Copyright (c) 2020, longpanda <admin@ventoy.net>
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.
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.
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/>.
18 #************************************************************************************
20 ####################################################################
22 # Step 1 : Parse kernel parameter #
24 ####################################################################
25 if ! [ -e /proc
]; then
26 $BUSYBOX_PATH/mkdir /proc
29 $BUSYBOX_PATH/mount
-t proc proc
/proc
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
40 ####################################################################
42 # Step 2 : Do OS specific hook #
44 ####################################################################
45 ventoy_get_os_type
() {
46 echo "kernel version" >> $VTLOG
47 $CAT /proc
/version
>> $VTLOG
49 if [ -d /twres
]; then
50 if $GREP -q 'Phoenix' /init
; then
51 echo 'phoenixos'; return
56 if $GREP -q 'PrimeOS' /proc
/version
; then
57 echo 'primeos'; return
60 elif $GREP -q '[Dd]ebian' /proc
/version
; then
63 # Ubuntu : do the same process with debian
64 elif $GREP -q '[Uu]buntu' /proc
/version
; then
67 # Deepin : do the same process with debian
68 elif $GREP -q '[Dd]eepin' /proc
/version
; then
71 # rhel5/CentOS5 and all other distributions based on them
72 elif $GREP -q 'el5' /proc
/version
; then
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
85 # rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
86 elif $GREP -q 'el[78]' /proc
/version
; then
89 # Maybe rhel9 rhel1x use the same way? Who knows!
90 elif $EGREP -q 'el9|el1[0-9]' /proc
/version
; then
93 # Fedora : do the same process with rhel7
94 elif $GREP -q '\.fc[0-9][0-9]\.' /proc
/version
; then
98 elif $GREP -q 'SUSE' /proc
/version
; then
102 elif $EGREP -q 'archlinux|ARCH' /proc
/version
; then
106 elif $EGREP -q 'kiosk' /proc
/version
; then
110 elif $EGREP -q '[Gg]entoo' /proc
/version
; then
111 if $GREP -q 'daphile' /proc
/version
; then
112 echo 'daphile'; return
115 echo 'gentoo'; return
118 elif $EGREP -q 'tinycore' /proc
/version
; then
119 echo 'tinycore'; return
122 elif $EGREP -q 'manjaro|MANJARO' /proc
/version
; then
123 echo 'manjaro'; return
126 elif $EGREP -q 'mageia' /proc
/version
; then
127 echo 'mageia'; return
130 elif $GREP -i -q 'PCLinuxOS' /proc
/version
; then
134 elif $GREP -i -q 'kaos' /proc
/version
; then
138 elif $GREP -q 'Alpine' /proc
/version
; then
139 echo 'alpine'; return
141 elif $GREP -i -q 'PhoenixOS' /proc
/version
; then
142 echo 'phoenixos'; return
145 elif $GREP -i -q 'NixOS' /proc
/version
; then
151 if [ -e /lib
/debian
-installer ]; then
152 echo 'debian'; return
155 if [ -e /etc
/os
-release ]; then
156 if $GREP -q 'XenServer' /etc
/os
-release; then
158 elif $GREP -q 'SUSE ' /etc
/os
-release; then
160 elif $GREP -q 'uruk' /etc
/os
-release; then
161 echo 'debian'; return
162 elif $GREP -q 'Solus' /etc
/os
-release; then
164 elif $GREP -q 'openEuler' /etc
/os
-release; then
165 echo 'openEuler'; return
166 elif $GREP -q 'fuyu' /etc
/os
-release; then
167 echo 'openEuler'; return
168 elif $GREP -q 'deepin' /etc
/os
-release; then
169 echo 'debian'; return
170 elif $GREP -q 'chinauos' /etc
/os
-release; then
171 echo 'debian'; return
175 if $BUSYBOX_PATH/dmesg
| $GREP -q -m1 "Xen:"; then
180 if [ -e /etc
/HOSTNAME
] && $GREP -i -q 'slackware' /etc
/HOSTNAME
; then
181 echo 'slackware'; return
184 if [ -e /init
]; then
185 if $GREP -i -q zeroshell
/init
; then
186 echo 'zeroshell'; return
190 if $EGREP -q 'ALT ' /proc
/version
; then
194 if $EGREP -q 'porteus' /proc
/version
; then
195 echo 'debian'; return
198 if $GREP -q 'Clear Linux ' /proc
/version
; then
202 if $GREP -q 'artix' /proc
/version
; then
206 if $GREP -q 'berry ' /proc
/version
; then
210 if $GREP -q 'Gobo ' /proc
/version
; then
214 if $GREP -q 'NuTyX' /proc
/version
; then
219 vtLineNum
=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
220 if [ $vtLineNum -gt 0 ]; then
225 if $GREP -q 'android.x86' /proc
/version
; then
226 echo 'android'; return
229 if $GREP -q 'adelielinux' /proc
/version
; then
230 echo 'adelie'; return
233 if $GREP -q 'pmagic' /proc
/version
; then
234 echo 'pmagic'; return
237 if $GREP -q 'CDlinux' /proc
/cmdline
; then
238 echo 'cdlinux'; return
241 if $GREP -q 'parabola' /proc
/version
; then
242 echo 'parabola'; return
245 if $GREP -q 'cucumber' /proc
/version
; then
246 echo 'cucumber'; return
249 if $GREP -q 'fatdog' /proc
/version
; then
250 echo 'fatdog'; return
253 if $GREP -q 'KWORT' /proc
/version
; then
257 if $GREP -q 'iwamoto' /proc
/version
; then
261 if $GREP -q 'hyperbola' /proc
/cmdline
; then
262 echo 'hyperbola'; return
265 if $GREP -q 'CRUX' /proc
/version
; then
269 if [ -f /init
]; then
270 if $GREP -q 'AryaLinux' /init
; then
271 echo 'aryalinux'; return
272 elif $GREP -q 'Dragora' /init
; then
273 echo 'dragora'; return
278 if $GREP -q 'slackware' /proc
/version
; then
279 echo 'slackware'; return
282 if $BUSYBOX_PATH/hostname
| $GREP -q 'smoothwall'; then
283 echo 'smoothwall'; return
286 if $GREP -q 'photon' /proc
/version
; then
287 echo 'photon'; return
290 if $GREP -q 'ploplinux' /proc
/version
; then
291 echo 'ploplinux'; return
294 if $GREP -q 'lunar' /proc
/version
; then
298 if $GREP -q 'SMGL-' /proc
/version
; then
302 if $GREP -q 'rancher' /proc
/version
; then
303 echo 'rancher'; return
307 if [ -e /init
]; then
308 if $GREP -q -m1 'T2 SDE' /init
; then
313 if $GREP -q 'wifislax' /proc
/version
; then
314 echo 'wifislax'; return
317 if $GREP -q 'pisilinux' /proc
/version
; then
318 echo 'pisilinux'; return
321 if $GREP -q 'blackPanther' /proc
/version
; then
322 echo 'blackPanther'; return
325 if $GREP -q 'primeos' /proc
/version
; then
326 echo 'primeos'; return
329 if $GREP -q 'austrumi' /proc
/version
; then
330 echo 'austrumi'; return
333 if [ -f /DISTRO_SPECS
]; then
334 if $GREP -q '[Pp]uppy' /DISTRO_SPECS
; then
335 echo 'debian'; return
336 elif $GREP -q 'veket' /DISTRO_SPECS
; then
337 echo 'debian'; return
341 if [ -f /etc
/openEuler
-release ]; then
342 echo "openEuler"; return
345 if $GREP -q 'venom' /proc
/version
; then
352 VTOS
=$(ventoy_get_os_type)
353 echo "OS=###${VTOS}###" >>$VTLOG
354 if [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
355 $BUSYBOX_PATH/sh
"$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
360 if $GREP -q -i Untangle
/proc
/version
; then
361 for vtPara
in $($CAT /proc/cmdline); do
362 vtItemkey
=$(echo $vtPara | $AWK -F= '{print $1}')
363 vtItemVal
=$(echo $vtPara | $AWK -F= '{print $2}')
364 if $GREP -q -m1 "^$vtItemkey\$" $VTOY_PATH/hook
/default
/export.list
; then
365 vtEnvExport
="$vtEnvExport $vtItemkey=$vtItemVal"
369 echo "================ env export ================" >> $VTLOG
370 echo $vtEnvExport >> $VTLOG
371 echo "============================================" >> $VTLOG
376 ####################################################################
378 # Step 3 : Run LiveInjection Hook #
380 ####################################################################
381 if [ -f "/live_injection_7ed136ec_7a61_4b54_adc3_ae494d5106ea/hook.sh" ]; then
382 $BUSYBOX_PATH/sh
"/live_injection_7ed136ec_7a61_4b54_adc3_ae494d5106ea/hook.sh" $VTOS
386 ####################################################################
388 # Step 4 : Check for debug break #
390 ####################################################################
391 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
393 echo -e "\n\n\033[32m ################################################# \033[0m"
394 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
395 echo -e "\033[32m ################################################# \033[0m \n"
396 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
399 exec $BUSYBOX_PATH/sh
403 ####################################################################
405 # Step 5 : Hand over to real init #
407 ####################################################################
408 $BUSYBOX_PATH/umount
/proc
409 if [ "$rmproc" = "Y" ]; then
410 $BUSYBOX_PATH/rm -rf /proc
413 if [ -f $VTOY_PATH/ventoy_persistent_map
]; then
414 export PERSISTENT
='YES'
415 export PERSISTENCE
='true'
420 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD vtcmdline
422 for vtinit
in $user_rdinit /init
/sbin
/init
/linuxrc
; do
423 if [ -d /ventoy_rdroot
]; then
424 if [ -e "/ventoy_rdroot$vtinit" ]; then
425 # switch_root will check /init file, this is a cheat code
426 echo 'switch_root' > /init
427 exec $BUSYBOX_PATH/switch_root
/ventoy_rdroot
"$vtinit"
430 if [ -e "$vtinit" ];then
431 if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
432 $BUSYBOX_PATH/sh
"$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
435 if [ -z "$vtEnvExport" ]; then
438 exec env
$vtEnvExport "$vtinit"
444 # Should never reach here
445 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
446 exec $BUSYBOX_PATH/sh