Fixed DNS issues with ubuntu-9.10
[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         httpfs=*)
132                 HTTPFS="${x#httpfs=}"
133                 ;;
134         iscsifs=*)
135                 ISCSIFS="${x#iscsifs=}"
136                 ;;
137         target=*)
138                 TARGET="${x#target=}"
139                 ;;
140         netboot=*)
141                 NETBOOT="${x#netboot=}"
142                 ;;
143         ip=*)
144                 IPOPTS="${x#ip=}"
145                 ;;
146         boot=*)
147                 BOOT=${x#boot=}
148                 ;;
149         resume=*)
150                 RESUME="${x#resume=}"
151                 ;;
152         resume_offset=*)
153                 resume_offset="${x#resume_offset=}"
154                 ;;
155         noresume)
156                 noresume=y
157                 ;;
158         panic=*)
159                 panic="${x#panic=}"
160                 case ${panic} in
161                 *[![:digit:].]*)
162                         panic=
163                         ;;
164                 esac
165                 ;;
166         quiet)
167                 quiet=y
168                 ;;
169         ro)
170                 readonly=y
171                 ;;
172         rw)
173                 readonly=n
174                 ;;
175         debug)
176                 debug=y
177                 quiet=n
178                 exec >/dev/.initramfs/initramfs.debug 2>&1
179                 set -x
180                 ;;
181         debug=*)
182                 debug=y
183                 quiet=n
184                 set -x
185                 ;;
186         break=*)
187                 break=${x#break=}
188                 ;;
189         break)
190                 break=premount
191                 ;;
192         blacklist=*)
193                 blacklist=${x#blacklist=}
194                 ;;
195         esac
196 done
197
198 if [ -z "${noresume}" ]; then
199         export resume=${RESUME}
200 else
201         export noresume
202 fi
203
204 depmod -a
205 maybe_break top
206
207 # export BOOT variable value for compcache,
208 # so we know if we run from casper
209 export BOOT
210
211 # Don't do log messages here to avoid confusing usplash
212 run_scripts /scripts/init-top
213
214 maybe_break modules
215 log_begin_msg "Loading essential drivers..."
216 load_modules
217 log_end_msg
218
219 maybe_break premount
220 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
221 run_scripts /scripts/init-premount
222 [ "$quiet" != "y" ] && log_end_msg
223
224 maybe_break mount
225 log_begin_msg "Mounting root file system..."
226 . /scripts/${BOOT}
227 parse_numeric ${ROOT}
228 mountroot
229 log_end_msg
230
231 maybe_break bottom
232 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
233 run_scripts /scripts/init-bottom
234 [ "$quiet" != "y" ] && log_end_msg
235
236 # Move virtual filesystems over to the real filesystem
237 mount -n -o move /sys ${rootmnt}/sys
238 mount -n -o move /proc ${rootmnt}/proc
239
240 # Check init bootarg
241 if [ -n "${init}" ] && [ ! -x "${rootmnt}${init}" ]; then
242         echo "Target filesystem doesn't have ${init}."
243         init=
244 fi
245
246 # Search for valid init
247 if [ -z "${init}" ] ; then
248         for init in /sbin/init /etc/init /bin/init /bin/sh; do
249                 if [ ! -x "${rootmnt}${init}" ]; then
250                         continue
251                 fi
252                 break
253         done
254 fi
255
256 # No init on rootmount
257 if [ ! -x "${rootmnt}${init}" ]; then
258         panic "No init found. Try passing init= bootarg."
259 fi
260
261 # Confuses /etc/init.d/rc
262 if [ -n ${debug} ]; then
263         unset debug
264 fi
265
266 # because of some reasons, I dont understand, resolv.conf is not being set
267 # that is why I am copying this manually into actual filesystem. -- pravin
268 cp /etc/resolv.conf /root/etc/resolv.conf
269
270
271 # Chain to real filesystem
272 maybe_break init
273 exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console 2>&1
274 panic "Could not execute run-init."