]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/ventoy_loop.sh
1. Boot menu over serial supported
[Ventoy.git] / IMG / cpio / ventoy / ventoy_loop.sh
1 #!/ventoy/busybox/sh
2 #************************************************************************************
3 # Copyright (c) 2020, longpanda <admin@ventoy.net>
4 #
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.
9 #
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.
14 #
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/>.
17 #
18 #************************************************************************************
19
20 ####################################################################
21 # #
22 # Step 1 : Parse kernel parameter #
23 # #
24 ####################################################################
25 if ! [ -e /proc ]; then
26 $BUSYBOX_PATH/mkdir /proc
27 rmproc='Y'
28 fi
29 $BUSYBOX_PATH/mount -t proc proc /proc
30
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
37 fi
38 done
39
40
41 ####################################################################
42 # #
43 # Step 2 : Do OS specific hook #
44 # #
45 ####################################################################
46 ventoy_get_os_type() {
47 echo "kernel version" >> $VTLOG
48 $CAT /proc/version >> $VTLOG
49
50 # deepin-live
51 if $GREP -q 'deepin' /proc/version; then
52 echo 'deepin'; return
53 fi
54
55 if $GREP -q 'endless' /proc/version; then
56 echo 'endless'; return
57 fi
58
59 echo "default"
60 }
61
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"
66 fi
67
68
69 ####################################################################
70 # #
71 # Step 3 : Check for debug break #
72 # #
73 ####################################################################
74 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
75 $SLEEP 5
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
80 $CAT $VTOY_PATH/log
81 fi
82 exec $BUSYBOX_PATH/sh
83 fi
84
85
86 ####################################################################
87 # #
88 # Step 3 : Hand over to real init #
89 # #
90 ####################################################################
91 $BUSYBOX_PATH/umount /proc
92 if [ "$rmproc" = "Y" ]; then
93 $BUSYBOX_PATH/rm -rf /proc
94 fi
95
96 cd /
97
98 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
99
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"
106 fi
107 else
108 if [ -e "$vtinit" ];then
109 exec "$vtinit"
110 fi
111 fi
112 done
113
114 # Should never reach here
115 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
116 exec $BUSYBOX_PATH/sh