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 : Process ko #
44 ####################################################################
45 $BUSYBOX_PATH/mkdir -p /ventoy
/modules
46 $BUSYBOX_PATH/ls -1a / | $EGREP '\.ko$|\.ko.[gx]z$' | while read vtline
; do
47 if [ "${vtline:0:1}" = "." ]; then
48 $BUSYBOX_PATH/mv /${vtline} /ventoy
/modules
/${vtline:1}
50 $BUSYBOX_PATH/mv /${vtline} /ventoy
/modules
/
54 if [ -e /vtloopex.
tar.xz
]; then
55 echo "extract vtloopex ..." >> $VTLOG
56 $BUSYBOX_PATH/tar -xJf /vtloopex.
tar.xz
-C $VTOY_PATH/
57 $BUSYBOX_PATH/rm -f /vtloopex.
tar.xz
61 ####################################################################
63 # Step 3 : Do OS specific hook #
65 ####################################################################
66 ventoy_get_os_type
() {
67 echo "kernel version" >> $VTLOG
68 $CAT /proc
/version
>> $VTLOG
70 if $GREP -q 'endless' /proc
/version
; then
71 echo 'endless'; return
74 if $GREP -q 'OpenWrt' /proc
/version
; then
75 echo 'openwrt'; return
78 if [ -e /BOOT_SPECS
]; then
79 if $GREP -q 'easyos' /BOOT_SPECS
; then
84 if [ -e /etc
/os
-release ]; then
85 if $GREP -q 'volumio' /etc
/os
-release; then
86 echo 'volumio'; return
90 if $GREP -q 'ventoyos=' /proc
/cmdline
; then
91 $SED "s/.*ventoyos=\([a-zA-Z0-9_-]*\).*/\1/" /proc
/cmdline
; return
94 if [ -d /twres
]; then
95 if $GREP -q 'Phoenix' /init
; then
96 echo 'phoenixos'; return
100 # rhel5/CentOS5 and all other distributions based on them
101 if $GREP -q 'el5' /proc
/version
; then
104 # rhel6/CentOS6 and all other distributions based on them
105 elif $GREP -q 'el6' /proc
/version
; then
108 # rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
109 elif $GREP -q 'el[78]' /proc
/version
; then
112 # Maybe rhel9 rhel1x use the same way? Who knows!
113 elif $EGREP -q 'el9|el1[0-9]' /proc
/version
; then
116 # Fedora : do the same process with rhel7
117 elif $GREP -q '\.fc[0-9][0-9]\.' /proc
/version
; then
121 elif $GREP -q '[Dd]ebian' /proc
/version
; then
122 echo 'debian'; return
124 # Ubuntu : do the same process with debian
125 elif $GREP -q '[Uu]buntu' /proc
/version
; then
126 echo 'debian'; return
128 # Deepin : do the same process with debian
129 elif $GREP -q '[Dd]eepin' /proc
/version
; then
130 echo 'debian'; return
133 elif $GREP -q 'SUSE' /proc
/version
; then
137 elif $EGREP -q 'archlinux|ARCH' /proc
/version
; then
141 elif $EGREP -q 'kiosk' /proc
/version
; then
145 elif $EGREP -q '[Gg]entoo' /proc
/version
; then
146 if $GREP -q 'daphile' /proc
/version
; then
147 echo 'daphile'; return
150 echo 'gentoo'; return
153 elif $EGREP -q 'tinycore' /proc
/version
; then
154 echo 'tinycore'; return
157 elif $EGREP -q 'manjaro|MANJARO' /proc
/version
; then
158 echo 'manjaro'; return
161 elif $EGREP -q 'mageia' /proc
/version
; then
162 echo 'mageia'; return
165 elif $GREP -i -q 'PCLinuxOS' /proc
/version
; then
169 elif $GREP -i -q 'kaos' /proc
/version
; then
173 elif $GREP -q 'Alpine' /proc
/version
; then
174 echo 'alpine'; return
176 elif $GREP -i -q 'PhoenixOS' /proc
/version
; then
177 echo 'phoenixos'; return
180 elif $GREP -i -q 'NixOS' /proc
/version
; then
186 if [ -e /lib
/debian
-installer ]; then
187 echo 'debian'; return
190 if [ -e /etc
/os
-release ]; then
191 if $GREP -q 'XenServer' /etc
/os
-release; then
193 elif $GREP -q 'SUSE ' /etc
/os
-release; then
195 elif $GREP -q 'uruk' /etc
/os
-release; then
196 echo 'debian'; return
197 elif $GREP -q 'Solus' /etc
/os
-release; then
199 elif $GREP -q 'openEuler' /etc
/os
-release; then
200 echo 'openEuler'; return
201 elif $GREP -q 'fuyu' /etc
/os
-release; then
202 echo 'openEuler'; return
203 elif $GREP -q 'deepin' /etc
/os
-release; then
204 echo 'debian'; return
205 elif $GREP -q 'chinauos' /etc
/os
-release; then
206 echo 'debian'; return
210 if $BUSYBOX_PATH/dmesg
| $GREP -q -m1 "Xen:"; then
215 if [ -e /etc
/HOSTNAME
] && $GREP -i -q 'slackware' /etc
/HOSTNAME
; then
216 echo 'slackware'; return
219 if [ -e /init
]; then
220 if $GREP -i -q zeroshell
/init
; then
221 echo 'zeroshell'; return
225 if $EGREP -q 'ALT ' /proc
/version
; then
229 if $EGREP -q 'porteus' /proc
/version
; then
230 echo 'debian'; return
233 if $GREP -q 'Clear Linux ' /proc
/version
; then
237 if $GREP -q 'artix' /proc
/version
; then
241 if $GREP -q 'berry ' /proc
/version
; then
245 if $GREP -q 'Gobo ' /proc
/version
; then
249 if $GREP -q 'NuTyX' /proc
/version
; then
254 vtLineNum
=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
255 if [ $vtLineNum -gt 0 ]; then
260 if $GREP -q 'android.x86' /proc
/version
; then
261 echo 'android'; return
264 if $GREP -q 'adelielinux' /proc
/version
; then
265 echo 'adelie'; return
268 if $GREP -q 'pmagic' /proc
/version
; then
269 echo 'pmagic'; return
272 if $GREP -q 'CDlinux' /proc
/cmdline
; then
273 echo 'cdlinux'; return
276 if $GREP -q 'parabola' /proc
/version
; then
277 echo 'parabola'; return
280 if $GREP -q 'cucumber' /proc
/version
; then
281 echo 'cucumber'; return
284 if $GREP -q 'fatdog' /proc
/version
; then
285 echo 'fatdog'; return
288 if $GREP -q 'KWORT' /proc
/version
; then
292 if $GREP -q 'iwamoto' /proc
/version
; then
296 if $GREP -q 'hyperbola' /proc
/cmdline
; then
297 echo 'hyperbola'; return
300 if $GREP -q 'CRUX' /proc
/version
; then
304 if [ -f /init
]; then
305 if $GREP -q 'AryaLinux' /init
; then
306 echo 'aryalinux'; return
307 elif $GREP -q 'Dragora' /init
; then
308 echo 'dragora'; return
313 if $GREP -q 'slackware' /proc
/version
; then
314 echo 'slackware'; return
317 if $BUSYBOX_PATH/hostname
| $GREP -q 'smoothwall'; then
318 echo 'smoothwall'; return
321 if $GREP -q 'photon' /proc
/version
; then
322 echo 'photon'; return
325 if $GREP -q 'ploplinux' /proc
/version
; then
326 echo 'ploplinux'; return
329 if $GREP -q 'lunar' /proc
/version
; then
333 if $GREP -q 'SMGL-' /proc
/version
; then
337 if $GREP -q 'rancher' /proc
/version
; then
338 echo 'rancher'; return
342 if [ -e /init
]; then
343 if $GREP -q -m1 'T2 SDE' /init
; then
348 if $GREP -q 'wifislax' /proc
/version
; then
349 echo 'wifislax'; return
352 if $GREP -q 'pisilinux' /proc
/version
; then
353 echo 'pisilinux'; return
356 if $GREP -q 'blackPanther' /proc
/version
; then
357 echo 'blackPanther'; return
360 if $GREP -q 'primeos' /proc
/version
; then
361 echo 'primeos'; return
364 if $GREP -q 'austrumi' /proc
/version
; then
365 echo 'austrumi'; return
368 if [ -f /DISTRO_SPECS
]; then
369 if $GREP -q '[Pp]uppy' /DISTRO_SPECS
; then
370 echo 'debian'; return
371 elif $GREP -q 'veket' /DISTRO_SPECS
; then
372 echo 'debian'; return
376 if [ -f /etc
/openEuler
-release ]; then
377 echo "openEuler"; return
383 VTOS
=$(ventoy_get_os_type)
384 echo "OS=###${VTOS}###" >>$VTLOG
385 if [ -e "$VTOY_PATH/loop/$VTOS/ventoy-hook.sh" ]; then
386 $BUSYBOX_PATH/sh
"$VTOY_PATH/loop/$VTOS/ventoy-hook.sh"
387 elif [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
388 $BUSYBOX_PATH/sh
"$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
392 ####################################################################
394 # Step 4 : Check for debug break #
396 ####################################################################
397 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
399 echo -e "\n\n\033[32m ################################################# \033[0m"
400 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
401 echo -e "\033[32m ################################################# \033[0m \n"
402 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
405 exec $BUSYBOX_PATH/sh
409 ####################################################################
411 # Step 5 : Hand over to real init #
413 ####################################################################
414 $BUSYBOX_PATH/umount
/proc
415 if [ "$rmproc" = "Y" ]; then
416 $BUSYBOX_PATH/rm -rf /proc
419 if [ -f $VTOY_PATH/ventoy_persistent_map
]; then
420 export PERSISTENT
='YES'
421 export PERSISTENCE
='true'
426 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD vtcmdline
428 for vtinit
in $user_rdinit /init
/sbin
/init
/linuxrc
; do
429 if [ -d /ventoy_rdroot
]; then
430 if [ -e "/ventoy_rdroot$vtinit" ]; then
431 # switch_root will check /init file, this is a cheat code
432 echo 'switch_root' > /init
433 exec $BUSYBOX_PATH/switch_root
/ventoy_rdroot
"$vtinit"
436 if [ -e "$vtinit" ];then
437 if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
438 $BUSYBOX_PATH/sh
"$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
445 # Should never reach here
446 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
447 exec $BUSYBOX_PATH/sh