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
41 ####################################################################
43 # Step 2 : Do OS specific hook #
45 ####################################################################
46 ventoy_get_os_type
() {
47 echo "kernel version" >> $VTLOG
48 $CAT /proc
/version
>> $VTLOG
50 if [ -d /twres
]; then
51 if $GREP -q 'Phoenix' /init
; then
52 echo 'phoenixos'; return
56 # rhel5/CentOS5 and all other distributions based on them
57 if $GREP -q 'el5' /proc
/version
; then
60 # rhel6/CentOS6 and all other distributions based on them
61 elif $GREP -q 'el6' /proc
/version
; then
64 # rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
65 elif $GREP -q 'el[78]' /proc
/version
; then
68 # Maybe rhel9 rhel1x use the same way? Who knows!
69 elif $EGREP -q 'el9|el1[0-9]' /proc
/version
; then
72 # Fedora : do the same process with rhel7
73 elif $GREP -q '\.fc[0-9][0-9]\.' /proc
/version
; then
77 elif $GREP -q '[Dd]ebian' /proc
/version
; then
80 # Ubuntu : do the same process with debian
81 elif $GREP -q '[Uu]buntu' /proc
/version
; then
84 # Deepin : do the same process with debian
85 elif $GREP -q '[Dd]eepin' /proc
/version
; then
89 elif $GREP -q 'SUSE' /proc
/version
; then
93 elif $EGREP -q 'archlinux|ARCH' /proc
/version
; then
97 elif $EGREP -q 'kiosk' /proc
/version
; then
101 elif $EGREP -q '[Gg]entoo' /proc
/version
; then
102 if $GREP -q 'daphile' /proc
/version
; then
103 echo 'daphile'; return
106 echo 'gentoo'; return
109 elif $EGREP -q 'tinycore' /proc
/version
; then
110 echo 'tinycore'; return
113 elif $EGREP -q 'manjaro|MANJARO' /proc
/version
; then
114 echo 'manjaro'; return
117 elif $EGREP -q 'mageia' /proc
/version
; then
118 echo 'mageia'; return
121 elif $GREP -i -q 'PCLinuxOS' /proc
/version
; then
125 elif $GREP -i -q 'kaos' /proc
/version
; then
129 elif $GREP -q 'Alpine' /proc
/version
; then
130 echo 'alpine'; return
132 elif $GREP -i -q 'PhoenixOS' /proc
/version
; then
133 echo 'phoenixos'; return
136 elif $GREP -i -q 'NixOS' /proc
/version
; then
142 if [ -e /lib
/debian
-installer ]; then
143 echo 'debian'; return
146 if [ -e /etc
/os
-release ]; then
147 if $GREP -q 'XenServer' /etc
/os
-release; then
149 elif $GREP -q 'SUSE ' /etc
/os
-release; then
151 elif $GREP -q 'uruk' /etc
/os
-release; then
152 echo 'debian'; return
153 elif $GREP -q 'Solus' /etc
/os
-release; then
158 if $BUSYBOX_PATH/dmesg
| $GREP -q -m1 "Xen:"; then
163 if [ -e /etc
/HOSTNAME
] && $GREP -i -q 'slackware' /etc
/HOSTNAME
; then
164 echo 'slackware'; return
167 if [ -e /init
]; then
168 if $GREP -i -q zeroshell
/init
; then
169 echo 'zeroshell'; return
173 if $EGREP -q 'ALT ' /proc
/version
; then
177 if $EGREP -q 'porteus' /proc
/version
; then
178 echo 'debian'; return
181 if $GREP -q 'Clear Linux ' /proc
/version
; then
185 if $GREP -q 'artix' /proc
/version
; then
189 if $GREP -q 'berry ' /proc
/version
; then
193 if $GREP -q 'Gobo ' /proc
/version
; then
197 if $GREP -q 'NuTyX' /proc
/version
; then
202 vtLineNum
=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
203 if [ $vtLineNum -gt 0 ]; then
208 if $GREP -q 'android.x86' /proc
/version
; then
209 echo 'android'; return
212 if $GREP -q 'adelielinux' /proc
/version
; then
213 echo 'adelie'; return
216 if $GREP -q 'pmagic' /proc
/version
; then
217 echo 'pmagic'; return
220 if $GREP -q 'CDlinux' /proc
/cmdline
; then
221 echo 'cdlinux'; return
224 if $GREP -q 'parabola' /proc
/version
; then
225 echo 'parabola'; return
228 if $GREP -q 'cucumber' /proc
/version
; then
229 echo 'cucumber'; return
232 if $GREP -q 'fatdog' /proc
/version
; then
233 echo 'fatdog'; return
236 if $GREP -q 'KWORT' /proc
/version
; then
240 if $GREP -q 'iwamoto' /proc
/version
; then
244 if $GREP -q 'hyperbola' /proc
/cmdline
; then
245 echo 'hyperbola'; return
248 if $GREP -q 'CRUX' /proc
/version
; then
252 if [ -f /init
]; then
253 if $GREP -q 'AryaLinux' /init
; then
254 echo 'aryalinux'; return
255 elif $GREP -q 'Dragora' /init
; then
256 echo 'dragora'; return
261 if $GREP -q 'slackware' /proc
/version
; then
262 echo 'slackware'; return
265 if $BUSYBOX_PATH/hostname
| $GREP -q 'smoothwall'; then
266 echo 'smoothwall'; return
269 if $GREP -q 'photon' /proc
/version
; then
270 echo 'photon'; return
273 if $GREP -q 'ploplinux' /proc
/version
; then
274 echo 'ploplinux'; return
277 if $GREP -q 'lunar' /proc
/version
; then
281 if $GREP -q 'SMGL-' /proc
/version
; then
285 if $GREP -q 'rancher' /proc
/version
; then
286 echo 'rancher'; return
290 if [ -e /init
]; then
291 if $GREP -q -m1 'T2 SDE' /init
; then
296 if $GREP -q 'wifislax' /proc
/version
; then
297 echo 'wifislax'; return
300 if $GREP -q 'pisilinux' /proc
/version
; then
301 echo 'pisilinux'; return
304 if $GREP -q 'blackPanther' /proc
/version
; then
305 echo 'blackPanther'; return
308 if $GREP -q 'primeos' /proc
/version
; then
309 echo 'primeos'; return
312 if $GREP -q 'austrumi' /proc
/version
; then
313 echo 'austrumi'; return
319 VTOS
=$(ventoy_get_os_type)
320 echo "OS=###${VTOS}###" >>$VTLOG
321 if [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
322 $BUSYBOX_PATH/sh
"$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
326 ####################################################################
328 # Step 3 : Check for debug break #
330 ####################################################################
331 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
333 echo -e "\n\n\033[32m ################################################# \033[0m"
334 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
335 echo -e "\033[32m ################################################# \033[0m \n"
336 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
339 exec $BUSYBOX_PATH/sh
343 ####################################################################
345 # Step 4 : Hand over to real init #
347 ####################################################################
348 $BUSYBOX_PATH/umount
/proc
349 if [ "$rmproc" = "Y" ]; then
350 $BUSYBOX_PATH/rm -rf /proc
353 if [ -f $VTOY_PATH/ventoy_persistent_map
]; then
354 export PERSISTENT
='YES'
355 export PERSISTENCE
='true'
360 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD vtcmdline
362 for vtinit
in $user_rdinit /init
/sbin
/init
/linuxrc
; do
363 if [ -d /ventoy_rdroot
]; then
364 if [ -e "/ventoy_rdroot$vtinit" ]; then
365 # switch_root will check /init file, this is a cheat code
366 echo 'switch_root' > /init
367 exec $BUSYBOX_PATH/switch_root
/ventoy_rdroot
"$vtinit"
370 if [ -e "$vtinit" ];then
371 if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
372 $BUSYBOX_PATH/sh
"$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
379 # Should never reach here
380 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
381 exec $BUSYBOX_PATH/sh