Magellan Linux

Contents of /trunk/initscripts/sysvinit/rc/rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 428 - (show annotations) (download)
Sun Mar 4 13:24:34 2007 UTC (17 years, 2 months ago) by niro
Original Path: trunk/magellan-initscripts/etc/rc.d/init.d/rc
File size: 9739 byte(s)
new features for udev-106-r1; added support for empty /dev trees

1 #!/bin/bash
2 # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.13 2007-03-04 13:24:34 niro Exp $
3
4 source /etc/sysconfig/rc
5 source $rc_functions
6
7 # get mage version
8 MAGEVER="$(< /etc/mageversion)"
9
10 # source kernel config if exists
11 [ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel
12
13 udev_version()
14 {
15 local version=0
16
17 if [[ -x /sbin/udev ]]
18 then
19 version=$(/sbin/udev -V)
20 # We need it without a leading '0', else bash do the wrong thing
21 version=${version##0}
22 # Older udev's will print nothing
23 [[ -z ${version} ]] && version=0
24 fi
25
26 echo "${version}"
27 }
28
29 populate_udev()
30 {
31 local opts
32
33 # tell modprobe.sh to be verbose to $CONSOLE
34 echo CONSOLE=${CONSOLE} > /dev/.udev_populate
35
36 # populate /dev with devices already found by the kernel
37 if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -gt "2614" ]
38 then
39 echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..."
40 [[ $(udev_version) -ge "96" ]] && opts="--attr-match=dev"
41 /sbin/udevtrigger ${opts}
42 evaluate_retval
43 else
44 echo -e ${COLOREDSTAR}" Populating /dev with existing devices with udevstart ..."
45 /sbin/udevstart
46 evaluate_retval
47 fi
48
49 # loop until everything is finished
50 echo -e ${COLOREDSTAR}" Letting udev process events ..."
51 /sbin/udevsettle --timeout=60
52 evaluate_retval
53
54 rm -f /dev/.udev_populate
55 return 0
56 }
57
58 seed_dev()
59 {
60 # seed /dev with some things that we know we need
61 echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..."
62 (
63 [ ! -c /dev/console ] && mknod /dev/console c 5 1
64 [ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1
65 [ ! -c /dev/null ] && mknod /dev/null c 1 3
66
67 # copy over any persistant things
68 if [[ -d /lib/udev/devices ]]
69 then
70 cp --preserve=all --recursive --update /lib/udev/devices/* /dev
71 fi
72
73 # not provided by sysfs but needed
74 ln -snf /proc/self/fd /dev/fd
75 ln -snf fd/0 /dev/stdin
76 ln -snf fd/1 /dev/stdout
77 ln -snf fd/2 /dev/stderr
78 [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core
79
80 # create problematic directories
81 mkdir -p /dev/{pts,shm}
82 )
83 evaluate_retval
84 }
85
86 trap "" INT QUIT TSTP
87
88 [ "$1" != "" ] && runlevel=$1
89
90 if [[ $runlevel = sysinit ]]
91 then
92 echo
93 echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"
94 echo -e "Copyright 2001-2007 Niels Rogalla; http://magellan-linux.net"
95 echo
96
97 # mount proc filesystem, needed for bootsplash;
98 # no use of '/etc/rc.d/init.d/mountproc' anymore
99 if [ ! -e /proc/mounts ]
100 then
101 echo -e ${COLOREDSTAR}"Mounting proc file system ..."
102 mount -n /proc
103 evaluate_retval
104 fi
105
106 # set default verbose level for kernel messages
107 [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3
108 echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk
109
110 # mount sys file system before udev or devfs (kernel-2.6)
111 if [[ $(kernel_major_version) = 2.6 ]]
112 then
113 if [ -d /sys ]
114 then
115 echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."
116 mount -n -t sysfs sysfs /sys
117 evaluate_retval
118 else
119 echo -e ${COLORED}"Fatal: mountpoint /sys missing ..."
120 echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)."
121 echo -e ${COLYELLOW}"It's essential for a 2.6 kernel."
122 fi
123 fi
124
125 ## load devfs ##
126 # load devfs only with a 2.4 kernel or its really wanted with a 2.6
127 if [[ $(kernel_major_version) = 2.4 ]] || [[ ${RC_USED_DEV} = devfs ]]
128 then
129 # start devfsd daemon, needed for bootsplash;
130 # no use of '/etc/rc.d/init.d/devfs' anymore
131 # check if devfs was mounted by the kernel,
132 # if not mount it (mbuild_livecd needs this one)
133 if [ ! -e /dev/.devfsd ]
134 then
135 echo -e ${COLOREDSTAR}"Mounting devfs file system ..."
136 mount -n -t devfs devfs /dev
137 evaluate_retval
138 fi
139
140 if [ -e /dev/.devfsd ]
141 then
142 echo -e ${COLOREDSTAR}"Starting devfsd ..."
143 ## directory /lib/dev-state !must! exists ##
144 /sbin/devfsd /dev &> /dev/null
145 evaluate_retval
146 else
147 echo -e ${COLRED}"No devfs filesystem found ..."
148 echo -e ${COLYELLOW}"Your Kernel doesn't support the devfs filesystem."
149 echo -e ${COLYELLOW}"Devfs is necessary to run Magellan-Linux."
150 echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel."
151 echo
152 echo -e ${COLYELLOW}"Press any key to shutdown the system safely ..."
153 read
154 $rc_base/init.d/halt
155 fi
156 fi
157
158 #### load udev ####
159 # load udev only with a 2.6 kernel
160 if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]]
161 then
162 # check if /dev/console exists outside tmpfs
163 [ -c /dev/console ] ; need_redirect=$?
164
165 # create a ramdisk for populating udev
166 echo -e ${COLOREDSTAR}"Mounting udev at /dev ..."
167 # many video drivers needed exec access
168 fstype=ramfs
169 # tmpfs was suggested by Greg Kroah-Hartman
170 kernel_supports_fs tmpfs && fstype=tmpfs
171 mount -n -t ${fstype} udev /dev -o exec,nosuid,mode=0755
172 evaluate_retval
173
174 # if a device tarball exists load it and if it is activated
175 echo -e ${COLOREDSTAR}"Configurating system to use udev ..."
176 if [[ ${RC_DEVICE_TARBALL} = yes ]]
177 then
178 echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..."
179 tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev
180 evaluate_retval
181 fi
182
183 # other eeded device nodes with udev
184 seed_dev
185
186 if [ -e /proc/sys/kernel/hotplug ]
187 then
188 if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -gt "2614" ]
189 then
190 echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..."
191 echo "" > /proc/sys/kernel/hotplug
192 evaluate_retval
193 else
194 echo -e ${COLOREDSTAR}" Setting /sbin/udevsend as hotplug agent ..."
195 echo "/sbin/udevsend" > /proc/sys/kernel/hotplug
196 evaluate_retval
197 fi
198 else
199 echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !"
200 print_status failure
201 fi
202
203 echo -e ${COLOREDSTAR}" Starting udevd daemon ..."
204 if [ ${need_redirect} -eq 1 ]
205 then
206 # we need to open fds 0 1 2
207 /sbin/udevd --daemon </dev/console >/dev/console 2>/dev/console
208 else
209 /sbin/udevd --daemon
210 fi
211 evaluate_retval
212
213 populate_udev
214
215 # create nodes that udev can't
216 echo -e ${COLOREDSTAR}" Finializing udev configuration ..."
217 [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null
218 [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
219 [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null
220 print_status success
221
222 # same thing as /dev/.devfsd
223 touch /dev/.udev
224 fi
225
226 ## load devpts ##
227 # devfs/udev with 2.6 has no ptys, so devpts is also needed
228 if [[ $(kernel_major_version) = 2.6 ]]
229 then
230 # check if we really have devpts support
231 if kernel_supports_fs devpts
232 then
233 # /dev/pts maybe not exists.
234 # We only create this directory only if devfs was mounted,
235 # or it will fail as / is still mounted readonly
236 # udev has this dir already, only a sanity check for devfs
237 if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs
238 then
239 mkdir -p /dev/pts &> /dev/null || \
240 echo "Could not create /dev/pts !"
241 fi
242
243 # now mount devpts
244 if [ -d /dev/pts ]
245 then
246 echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..."
247 mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts
248 evaluate_retval
249 fi
250 else
251 # devpts is not supported, give a warning
252 echo -e ${COLRED}"No devpts filesystem found ..."
253 echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem."
254 echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts,"
255 echo -e ${COLYELLOW}"or no pty's are available."
256 echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel."
257 echo
258 echo -e ${COLYELLOW}"Press any key to continue ..."
259 read
260 fi
261 fi
262
263 ### services state dir ###
264 echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..."
265 mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k
266 evaluate_retval
267
268 # load bootsplash
269 splash "rc_init" "${runlevel}"
270 fi
271
272
273 if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]]
274 then
275 # load bootsplash
276 splash "rc_init" "${runlevel}"
277
278 # if requested save devices to a device tarball before halt
279 # only for kernels >=2.6 *and* udev
280 # make shure that udev is mounted but *not* devfs --> /dev/.devfsd
281 if [[ ${RC_DEVICE_TARBALL} = yes ]] && \
282 [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ]
283 then
284 echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."
285 ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null )
286 mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2
287 evaluate_retval
288 fi
289 fi
290
291
292 if [ "$runlevel" = "" ]
293 then
294 echo "Usage: $0 <runlevel>" >&2
295 exit 1
296 fi
297
298
299 previous=$PREVLEVEL
300 [ "$previous" = "" ] && previous=N
301
302 if [ ! -d $rc_base/rc$runlevel.d ]
303 then
304 echo "$rc_base/rc$runlevel.d does not exist"
305 exit 1
306 fi
307
308 if [ "$previous" != "N" ]
309 then
310 for i in $(ls -v $rc_base/rc$runlevel.d/K* 2> /dev/null)
311 do
312
313 check_script_status
314
315 suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]}
316 prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
317 sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix
318
319 if [ "$runlevel" != "0" ] && [ "$runlevel" != "6" ]
320 then
321 if [ ! -f $prev_start ] && [ ! -f $sysinit_start ]
322 then
323 $WARNING
324 echo "$i can't be executed because it was"
325 echo "not started in the previous runlevel ($previous)"
326 $NORMAL
327 continue
328 fi
329 fi
330
331 $i stop
332 error_value=$?
333
334 if [ "$error_value" != "0" ]
335 then
336 print_error_msg
337 fi
338 done
339 fi
340
341 for i in $( ls -v $rc_base/rc$runlevel.d/S* 2> /dev/null)
342 do
343 if [ "$previous" != "N" ]
344 then
345 suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]}
346 stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix
347 prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
348
349 [ -f $prev_start ] && [ ! -f $stop ] && continue
350 fi
351
352 check_script_status
353
354 $i start
355 error_value=$?
356
357 if [ "$error_value" != "0" ]
358 then
359 print_error_msg
360 fi
361 done

Properties

Name Value
svn:executable *