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
71 if $GREP -q 'deepin' /proc
/version
; then
75 if $GREP -q 'endless' /proc
/version
; then
76 echo 'endless'; return
79 if $GREP -q 'OpenWrt' /proc
/version
; then
80 echo 'openwrt'; return
83 if [ -e /BOOT_SPECS
]; then
84 if $GREP -q 'easyos' /BOOT_SPECS
; then
89 if [ -e /etc
/os
-release ]; then
90 if $GREP -q 'volumio' /etc
/os
-release; then
91 echo 'volumio'; return
98 VTOS
=$(ventoy_get_os_type)
99 echo "OS=###${VTOS}###" >>$VTLOG
100 if [ -e "$VTOY_PATH/loop/$VTOS/ventoy-hook.sh" ]; then
101 $BUSYBOX_PATH/sh
"$VTOY_PATH/loop/$VTOS/ventoy-hook.sh"
105 ####################################################################
107 # Step 4 : Check for debug break #
109 ####################################################################
110 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
112 echo -e "\n\n\033[32m ################################################# \033[0m"
113 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
114 echo -e "\033[32m ################################################# \033[0m \n"
115 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
118 exec $BUSYBOX_PATH/sh
122 ####################################################################
124 # Step 5 : Hand over to real init #
126 ####################################################################
127 $BUSYBOX_PATH/umount
/proc
128 if [ "$rmproc" = "Y" ]; then
129 $BUSYBOX_PATH/rm -rf /proc
134 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
136 for vtinit
in $user_rdinit /init
/sbin
/init
/linuxrc
; do
137 if [ -d /ventoy_rdroot
]; then
138 if [ -e "/ventoy_rdroot$vtinit" ]; then
139 # switch_root will check /init file, this is a cheat code
140 echo 'switch_root' > /init
141 exec $BUSYBOX_PATH/switch_root
/ventoy_rdroot
"$vtinit"
144 if [ -e "$vtinit" ];then
150 # Should never reach here
151 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
152 exec $BUSYBOX_PATH/sh