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
51 if $GREP -q 'deepin' /proc
/version
; then
55 if $GREP -q 'endless' /proc
/version
; then
56 echo 'endless'; return
62 VTOS
=$(ventoy_get_os_type)
63 echo "OS=###${VTOS}###" >>$VTLOG
64 if [ -e "$VTOY_PATH/loop/$VTOS/ventoy-hook.sh" ]; then
65 $BUSYBOX_PATH/sh
"$VTOY_PATH/loop/$VTOS/ventoy-hook.sh"
69 ####################################################################
71 # Step 3 : Check for debug break #
73 ####################################################################
74 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
76 echo -e "\n\n\033[32m ################################################# \033[0m"
77 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
78 echo -e "\033[32m ################################################# \033[0m \n"
79 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
86 ####################################################################
88 # Step 3 : Hand over to real init #
90 ####################################################################
91 $BUSYBOX_PATH/umount
/proc
92 if [ "$rmproc" = "Y" ]; then
93 $BUSYBOX_PATH/rm -rf /proc
98 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
100 for vtinit
in $user_rdinit /sbin
/init
/init
/linuxrc
; do
101 if [ -d /ventoy_rdroot
]; then
102 if [ -e "/ventoy_rdroot$vtinit" ]; then
103 # switch_root will check /init file, this is a cheat code
104 echo 'switch_root' > /init
105 exec $BUSYBOX_PATH/switch_root
/ventoy_rdroot
"$vtinit"
108 if [ -e "$vtinit" ];then
114 # Should never reach here
115 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
116 exec $BUSYBOX_PATH/sh