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 # rhel5/CentOS5 and all other distributions based on them
51 if $GREP -q 'el5' /proc
/version
; then
54 # rhel6/CentOS6 and all other distributions based on them
55 elif $GREP -q 'el6' /proc
/version
; then
58 # rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
59 elif $GREP -q 'el[78]' /proc
/version
; then
62 # Maybe rhel9 rhel1x use the same way? Who knows!
63 elif $EGREP -q 'el9|el1[0-9]' /proc
/version
; then
66 # Fedora : do the same process with rhel7
67 elif $GREP -q '\.fc[0-9][0-9]\.' /proc
/version
; then
71 elif $GREP -q '[Dd]ebian' /proc
/version
; then
74 # Ubuntu : do the same process with debian
75 elif $GREP -q '[Uu]buntu' /proc
/version
; then
78 # Deepin : do the same process with debian
79 elif $GREP -q '[Dd]eepin' /proc
/version
; then
83 elif $GREP -q 'SUSE' /proc
/version
; then
87 elif $EGREP -q 'archlinux|ARCH' /proc
/version
; then
91 elif $EGREP -q 'kiosk' /proc
/version
; then
95 elif $EGREP -q '[Gg]entoo' /proc
/version
; then
99 elif $EGREP -q 'tinycore' /proc
/version
; then
100 echo 'tinycore'; return
103 elif $EGREP -q 'manjaro|MANJARO' /proc
/version
; then
104 echo 'manjaro'; return
107 elif $EGREP -q 'mageia' /proc
/version
; then
108 echo 'mageia'; return
111 elif $GREP -i -q 'PCLinuxOS' /proc
/version
; then
115 elif $GREP -i -q 'kaos' /proc
/version
; then
119 elif $GREP -q 'Alpine' /proc
/version
; then
120 echo 'alpine'; return
123 elif $GREP -i -q 'NixOS' /proc
/version
; then
128 if [ -e /lib
/debian
-installer ]; then
129 echo 'debian'; return
132 if [ -e /etc
/os
-release ]; then
133 if $GREP -q 'XenServer' /etc
/os
-release; then
135 elif $GREP -q 'SUSE ' /etc
/os
-release; then
137 elif $GREP -q 'uruk' /etc
/os
-release; then
138 echo 'debian'; return
142 if $BUSYBOX_PATH/dmesg
| $GREP -q -m1 "Xen:"; then
147 if [ -e /etc
/HOSTNAME
] && $GREP -i -q 'slackware' /etc
/HOSTNAME
; then
148 echo 'slackware'; return
151 if [ -e /init
]; then
152 if $GREP -i -q zeroshell
/init
; then
153 echo 'zeroshell'; return
157 if $EGREP -q 'ALT ' /proc
/version
; then
161 if $EGREP -q 'porteus' /proc
/version
; then
162 echo 'debian'; return
165 if $GREP -q 'Clear Linux ' /proc
/version
; then
169 if $GREP -q 'artix' /proc
/version
; then
173 if $GREP -q 'berry ' /proc
/version
; then
177 if $GREP -q 'Gobo ' /proc
/version
; then
181 if $GREP -q 'NuTyX' /proc
/version
; then
186 vtLineNum
=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
187 if [ $vtLineNum -gt 0 ]; then
192 if $GREP -q 'android.x86' /proc
/version
; then
193 echo 'android'; return
196 if $GREP -q 'adelielinux' /proc
/version
; then
197 echo 'adelie'; return
200 if $GREP -q 'pmagic' /proc
/version
; then
201 echo 'pmagic'; return
204 if $GREP -q 'CDlinux' /proc
/cmdline
; then
205 echo 'cdlinux'; return
208 if $GREP -q 'parabola' /proc
/version
; then
209 echo 'parabola'; return
212 if $GREP -q 'cucumber' /proc
/version
; then
213 echo 'cucumber'; return
216 if $GREP -q 'fatdog' /proc
/version
; then
217 echo 'fatdog'; return
220 if $GREP -q 'KWORT' /proc
/version
; then
224 if $GREP -q 'iwamoto' /proc
/version
; then
231 VTOS
=$(ventoy_get_os_type)
232 echo "OS=###${VTOS}###" >>$VTLOG
233 if [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
234 $BUSYBOX_PATH/sh
"$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
238 ####################################################################
240 # Step 3 : Check for debug break #
242 ####################################################################
243 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
245 echo -e "\n\n\033[32m ################################################# \033[0m"
246 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
247 echo -e "\033[32m ################################################# \033[0m \n"
248 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
251 exec $BUSYBOX_PATH/sh
255 ####################################################################
257 # Step 4 : Hand over to real init #
259 ####################################################################
260 $BUSYBOX_PATH/umount
/proc
261 if [ "$rmproc" = "Y" ]; then
262 $BUSYBOX_PATH/rm -rf /proc
265 if [ -f $VTOY_PATH/ventoy_persistent_map
]; then
266 export PERSISTENT
='YES'
267 export PERSISTENCE
='true'
272 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
274 for vtinit
in $user_rdinit /init
/sbin
/init
/linuxrc
; do
275 if [ -d /ventoy_rdroot
]; then
276 if [ -e "/ventoy_rdroot$vtinit" ]; then
277 # switch_root will check /init file, this is a cheat code
278 echo 'switch_root' > /init
279 exec $BUSYBOX_PATH/switch_root
/ventoy_rdroot
"$vtinit"
282 if [ -e "$vtinit" ];then
283 if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
284 $BUSYBOX_PATH/sh
"$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
291 # Should never reach here
292 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
293 exec $BUSYBOX_PATH/sh