264be5619db7a9e3341c6cc4273c72dea9dc49be
[people/pravin/BKO.git] / bko / live / ubuntu / U9.10 / init
1 #!/bin/sh
2
3 [ -d /dev ] || mkdir -m 0755 /dev
4 [ -d /root ] || mkdir -m 0700 /root
5 [ -d /sys ] || mkdir /sys
6 [ -d /proc ] || mkdir /proc
7 [ -d /tmp ] || mkdir /tmp
8 mkdir -p /var/lock
9 mount -t sysfs -o nodev,noexec,nosuid none /sys 
10 mount -t proc -o nodev,noexec,nosuid none /proc 
11
12 grep -q '\<quiet\>' /proc/cmdline || echo "Loading, please wait..."
13
14 # Note that this only becomes /dev on the real filesystem if udev's scripts
15 # are used; which they will be, but it's worth pointing out
16 mount -t tmpfs -o mode=0755 udev /dev
17 [ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
18 [ -e /dev/null ] || mknod /dev/null c 1 3
19 > /dev/.initramfs-tools
20 mkdir /dev/.initramfs
21
22 # Export the dpkg architecture
23 export DPKG_ARCH=
24 . /conf/arch.conf
25
26 # Set modprobe env
27 export MODPROBE_OPTIONS="-qb"
28
29 # Export relevant variables
30 export ROOT=
31 export ROOTDELAY=
32 export ROOTFLAGS=
33 export ROOTFSTYPE=
34 export IPOPTS=
35 export break=
36 export init=/sbin/init
37 export quiet=n
38 export readonly=y
39 export rootmnt=/root
40 export debug=
41 export panic=
42 export blacklist=
43 export resume_offset=
44
45 # Bring in the main config
46 . /conf/initramfs.conf
47 for conf in conf/conf.d/*; do
48         [ -f ${conf} ] && . ${conf}
49 done
50 . /scripts/functions
51
52 # Parse command line options
53 for x in $(cat /proc/cmdline); do
54         case $x in
55         init=*)
56                 init=${x#init=}
57                 ;;
58         root=*)
59                 ROOT=${x#root=}
60                 case $ROOT in
61                 LABEL=*)
62                         ROOT="${ROOT#LABEL=}"
63
64                         # support / in LABEL= paths (escape to \x2f)
65                         case "${ROOT}" in
66                         *[/]*)
67                         if [ -x "$(command -v sed)" ]; then
68                                 ROOT="$(echo ${ROOT} | sed 's,/,\\x2f,g')"
69                         else
70                                 if [ "${ROOT}" != "${ROOT#/}" ]; then
71                                         ROOT="\x2f${ROOT#/}"
72                                 fi
73                                 if [ "${ROOT}" != "${ROOT%/}" ]; then
74                                         ROOT="${ROOT%/}\x2f"
75                                 fi
76                                 IFS='/'
77                                 newroot=
78                                 for s in $ROOT; do
79                                         if [ -z "${newroot}" ]; then
80                                                 newroot="${s}"
81                                         else
82                                                 newroot="${newroot}\\x2f${s}"
83                                         fi
84                                 done
85                                 unset IFS
86                                 ROOT="${newroot}"
87                         fi
88                         esac
89                         ROOT="/dev/disk/by-label/${ROOT}"
90                         ;;
91                 UUID=*)
92                         ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
93                         ;;
94                 /dev/nfs)
95                         [ -z "${BOOT}" ] && BOOT=nfs
96                         ;;
97                 esac
98                 ;;
99         rootflags=*)
100                 ROOTFLAGS="-o ${x#rootflags=}"
101                 ;;
102         rootfstype=*)
103                 ROOTFSTYPE="${x#rootfstype=}"
104                 ;;
105         rootdelay=*)
106                 ROOTDELAY="${x#rootdelay=}"
107                 case ${ROOTDELAY} in
108                 *[![:digit:].]*)
109                         ROOTDELAY=
110                         ;;
111                 esac
112                 ;;
113         resumedelay=*)
114                 RESUMEDELAY="${x#resumedelay=}"
115                 ;;
116         loop=*)
117                 LOOP="${x#loop=}"
118                 ;;
119         loopflags=*)
120                 LOOPFLAGS="-o ${x#loopflags=}"
121                 ;;
122         loopfstype=*)
123                 LOOPFSTYPE="${x#loopfstype=}"
124                 ;;
125         cryptopts=*)
126                 cryptopts="${x#cryptopts=}"
127                 ;;
128         nfsroot=*)
129                 NFSROOT="${x#nfsroot=}"
130                 ;;
131         netboot=*)
132                 NETBOOT="${x#netboot=}"
133                 ;;
134         ip=*)
135                 IPOPTS="${x#ip=}"
136                 ;;
137         boot=*)
138                 BOOT=${x#boot=}
139                 ;;
140         resume=*)
141                 RESUME="${x#resume=}"
142                 ;;
143         resume_offset=*)
144                 resume_offset="${x#resume_offset=}"
145                 ;;
146         noresume)
147                 noresume=y
148                 ;;
149         panic=*)
150                 panic="${x#panic=}"
151                 case ${panic} in
152                 *[![:digit:].]*)
153                         panic=
154                         ;;
155                 esac
156                 ;;
157         quiet)
158                 quiet=y
159                 ;;
160         ro)
161                 readonly=y
162                 ;;
163         rw)
164                 readonly=n
165                 ;;
166         debug)
167                 debug=y
168                 quiet=n
169                 exec >/dev/.initramfs/initramfs.debug 2>&1
170                 set -x
171                 ;;
172         debug=*)
173                 debug=y
174                 quiet=n
175                 set -x
176                 ;;
177         break=*)
178                 break=${x#break=}
179                 ;;
180         break)
181                 break=premount
182                 ;;
183         blacklist=*)
184                 blacklist=${x#blacklist=}
185                 ;;
186         esac
187 done
188
189 if [ -z "${noresume}" ]; then
190         export resume=${RESUME}
191 else
192         export noresume
193 fi
194
195 depmod -a
196 maybe_break top
197
198 # export BOOT variable value for compcache,
199 # so we know if we run from casper
200 export BOOT
201
202 # Don't do log messages here to avoid confusing usplash
203 run_scripts /scripts/init-top
204
205 maybe_break modules
206 log_begin_msg "Loading essential drivers..."
207 load_modules
208 log_end_msg
209
210 maybe_break premount
211 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
212 run_scripts /scripts/init-premount
213 [ "$quiet" != "y" ] && log_end_msg
214
215 maybe_break mount
216 log_begin_msg "Mounting root file system..."
217 . /scripts/${BOOT}
218 parse_numeric ${ROOT}
219 mountroot
220 log_end_msg
221
222 maybe_break bottom
223 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
224 run_scripts /scripts/init-bottom
225 [ "$quiet" != "y" ] && log_end_msg
226
227 # Move virtual filesystems over to the real filesystem
228 mount -n -o move /sys ${rootmnt}/sys
229 mount -n -o move /proc ${rootmnt}/proc
230
231 # Check init bootarg
232 if [ -n "${init}" ] && [ ! -x "${rootmnt}${init}" ]; then
233         echo "Target filesystem doesn't have ${init}."
234         init=
235 fi
236
237 # Search for valid init
238 if [ -z "${init}" ] ; then
239         for init in /sbin/init /etc/init /bin/init /bin/sh; do
240                 if [ ! -x "${rootmnt}${init}" ]; then
241                         continue
242                 fi
243                 break
244         done
245 fi
246
247 # No init on rootmount
248 if [ ! -x "${rootmnt}${init}" ]; then
249         panic "No init found. Try passing init= bootarg."
250 fi
251
252 # Confuses /etc/init.d/rc
253 if [ -n ${debug} ]; then
254         unset debug
255 fi
256
257 # Chain to real filesystem
258 maybe_break init
259 exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console 2>&1
260 panic "Could not execute run-init."