Magellan Linux

Contents of /trunk/magellan-initscripts/etc/rc.d/init.d/rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 319 - (show annotations) (download)
Tue Jan 3 18:07:43 2006 UTC (18 years, 4 months ago) by niro
File size: 10744 byte(s)
added missing udev_version function

1 #!/bin/bash
2 # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.7 2006-01-03 18:07:43 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 # this works only for 2.6.15 kernels and greater
30 trigger_events()
31 {
32 local list=""
33 local i
34 local first
35 local last
36 local default
37
38 # if you want real hotplug (with all modules being loaded for all
39 # devices in the system), uncomment out the next line.
40 #list="$list $(echo /sys/bus/*/devices/*/uevent)"
41 list="${list} $(echo /sys/class/*/*/uevent)"
42 list="${list} $(echo /sys/block/*/uevent /sys/block/*/*/uevent)"
43 for i in ${list}
44 do
45 case "${i}" in
46 */device/uevent)
47 # skip followed device symlinks
48 continue
49 ;;
50 */class/mem/*|*/class/tty/*)
51 first="${first} ${i}"
52 ;;
53 */block/md*)
54 last="${last} ${i}"
55 ;;
56 */*)
57 default="${default} ${i}"
58 ;;
59 esac
60 done
61
62 # trigger the sorted events
63 for i in ${first} ${default} ${last}
64 do
65 echo "add" > "${i}"
66 done
67 }
68
69 populate_udev()
70 {
71 local loop
72
73 # populate /dev with devices already found by the kernel
74 if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ]
75 then
76 echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..."
77 trigger_events
78 evaluate_retval
79 else
80 echo -e ${COLOREDSTAR}" Populating /dev with existing devices with udevstart ..."
81 /sbin/udevstart
82 evaluate_retval
83 fi
84
85 # loop until everything is finished
86 # there's gotta be a better way...
87 echo -e ${COLOREDSTAR}" Letting udev process events ..."
88 loop=0
89 while test -d /dev/.udev/queue
90 do
91 sleep 0.1;
92 test "${loop}" -gt 300 && break
93 loop=$((${loop} + 1))
94 done
95 evaluate_retval
96
97 return 0
98 }
99
100 seed_dev()
101 {
102 # seed /dev with some things that we know we need
103 echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..."
104 (
105 # copy over any persistant things
106 cp --preserve=all --recursive --update /lib/udev/devices/* /dev
107
108 # not provided by sysfs but needed
109 ln -snf /proc/self/fd /dev/fd
110 ln -snf fd/0 /dev/stdin
111 ln -snf fd/1 /dev/stdout
112 ln -snf fd/2 /dev/stderr
113 [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core
114
115 # create problematic directories
116 mkdir -p /dev/{pts,shm}
117 )
118 evaluate_retval
119 }
120
121 # # some needed functions functions
122 # populate_udev() {
123 # /sbin/udevstart
124 #
125 # # not provided by sysfs but needed
126 # ln -snf /proc/self/fd /dev/fd
127 # ln -snf fd/0 /dev/stdin
128 # ln -snf fd/1 /dev/stdout
129 # ln -snf fd/2 /dev/stderr
130 # ln -snf /proc/kcore /dev/core
131 # ln -snf /proc/asound/oss/sndstat /dev/sndstat
132 #
133 # # create problematic directories
134 # mkdir -p /dev/{pts,shm}
135 #
136 # # same as /dev/.devfsd
137 # touch /dev/.udev
138 #
139 # return 0
140 # }
141
142 trap "" INT QUIT TSTP
143
144 [ "$1" != "" ] && runlevel=$1
145
146 if [[ $runlevel = sysinit ]]
147 then
148 echo
149 echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"
150 echo -e "Copyright 2001-2005 Niels Rogalla; http://magellan-linux.net"
151 echo
152
153 # mount proc filesystem, needed for bootsplash;
154 # no use of '/etc/rc.d/init.d/mountproc' anymore
155 if [ ! -e /proc/mounts ]
156 then
157 echo -e ${COLOREDSTAR}"Mounting proc file system ..."
158 mount -n /proc
159 evaluate_retval
160 fi
161
162 # set default verbose level for kernel messages
163 [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3
164 echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk
165
166 # mount sys file system before udev or devfs (kernel-2.6)
167 if [[ $(kernel_major_version) = 2.6 ]]
168 then
169 if [ -d /sys ]
170 then
171 echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."
172 mount -n -t sysfs sysfs /sys
173 evaluate_retval
174 else
175 echo -e ${COLORED}"Fatal: mountpoint /sys missing ..."
176 echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)."
177 echo -e ${COLYELLOW}"It's essential for a 2.6 kernel."
178 fi
179 fi
180
181 ## load devfs ##
182 # load devfs only with a 2.4 kernel or its really wanted with a 2.6
183 if [[ $(kernel_major_version) = 2.4 ]] || [[ ${RC_USED_DEV} = devfs ]]
184 then
185 # start devfsd daemon, needed for bootsplash;
186 # no use of '/etc/rc.d/init.d/devfs' anymore
187 # check if devfs was mounted by the kernel,
188 # if not mount it (mbuild_livecd needs this one)
189 if [ ! -e /dev/.devfsd ]
190 then
191 echo -e ${COLOREDSTAR}"Mounting devfs file system ..."
192 mount -n -t devfs devfs /dev
193 evaluate_retval
194 fi
195
196 if [ -e /dev/.devfsd ]
197 then
198 echo -e ${COLOREDSTAR}"Starting devfsd ..."
199 ## directory /lib/dev-state !must! exists ##
200 /sbin/devfsd /dev &> /dev/null
201 evaluate_retval
202 else
203 echo -e ${COLRED}"No devfs filesystem found ..."
204 echo -e ${COLYELLOW}"Your Kernel doesn't support the devfs filesystem."
205 echo -e ${COLYELLOW}"Devfs is necessary to run Magellan-Linux."
206 echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel."
207 echo
208 echo -e ${COLYELLOW}"Press any key to shutdown the system safely ..."
209 read
210 $rc_base/init.d/halt
211 fi
212 fi
213
214 #### load udev ####
215 # load udev only with a 2.6 kernel
216 if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]]
217 then
218 # create a ramdisk for populating udev
219 echo -e ${COLOREDSTAR}"Mounting udev at /dev ..."
220 # tmpfs was suggested by Greg Kroah-Hartman
221 # many video drivers needed exec access
222 mount -n -t ramfs udev /dev -o exec,nosuid,mode=0755
223 evaluate_retval
224
225 # if a device tarball exists load it and if it is activated
226 echo -e ${COLOREDSTAR}"Configurating system to use udev ..."
227 if [[ ${RC_DEVICE_TARBALL} = yes ]]
228 then
229 echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..."
230 tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev
231 evaluate_retval
232 fi
233
234 # other eeded device nodes with udev
235 seed_dev
236
237 if [ -e /proc/sys/kernel/hotplug ]
238 then
239 if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ]
240 then
241 echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..."
242 echo "" > /proc/sys/kernel/hotplug
243 evaluate_retval
244 elif [[ $(udev_version) -ge "48" ]]
245 then
246 echo -e ${COLOREDSTAR}" Setting /sbin/udevsend as hotplug agent ..."
247 echo "/sbin/udevsend" > /proc/sys/kernel/hotplug
248 evaluate_retval
249 elif [[ -x /sbin/hotplug ]]
250 then
251 echo -e ${COLOREDSTAR}" Using /sbin/hotplug as hotplug agent ..."
252 print_status success
253 else
254 echo -e ${COLOREDSTAR}" Setting /sbin/udev as hotplug agent ..."
255 echo "/sbin/udev" > /proc/sys/kernel/hotplug
256 evaluate_retval
257 fi
258 else
259 echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !"
260 print_status failure
261 fi
262
263 echo -e ${COLOREDSTAR}" Starting udevd daemon ..."
264 /sbin/udevd --daemon
265 evaluate_retval
266
267 populate_udev
268
269 # create nodes that udev can't
270 echo -e ${COLOREDSTAR}" Finializing udev configuration ..."
271 [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null
272 [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
273 [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null
274 print_status success
275
276 # same thing as /dev/.devfsd
277 touch /dev/.udev
278 fi
279
280 ## load devpts ##
281 # devfs/udev with 2.6 has no ptys, so devpts is also needed
282 if [[ $(kernel_major_version) = 2.6 ]]
283 then
284 # check if we really have devpts support
285 if kernel_supports_fs devpts
286 then
287 # /dev/pts maybe not exists.
288 # We only create this directory only if devfs was mounted,
289 # or it will fail as / is still mounted readonly
290 # udev has this dir already, only a sanity check for devfs
291 if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs
292 then
293 mkdir -p /dev/pts &> /dev/null || \
294 echo "Could not create /dev/pts !"
295 fi
296
297 # now mount devpts
298 if [ -d /dev/pts ]
299 then
300 echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..."
301 mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts
302 evaluate_retval
303 fi
304 else
305 # devpts is not supported, give a warning
306 echo -e ${COLRED}"No devpts filesystem found ..."
307 echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem."
308 echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts,"
309 echo -e ${COLYELLOW}"or no pty's are available."
310 echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel."
311 echo
312 echo -e ${COLYELLOW}"Press any key to continue ..."
313 read
314 fi
315 fi
316
317 ### services state dir ###
318 echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..."
319 mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k
320 evaluate_retval
321
322 # load bootsplash
323 splash "rc_init" "${runlevel}"
324 fi
325
326
327 if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]]
328 then
329 # load bootsplash
330 splash "rc_init" "${runlevel}"
331
332 # if requested save devices to a device tarball before halt
333 # only for kernels >=2.6 *and* udev
334 # make shure that udev is mounted but *not* devfs --> /dev/.devfsd
335 if [[ ${RC_DEVICE_TARBALL} = yes ]] && \
336 [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ]
337 then
338 echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."
339 ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null )
340 mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2
341 evaluate_retval
342 fi
343 fi
344
345
346 if [ "$runlevel" = "" ]
347 then
348 echo "Usage: $0 <runlevel>" >&2
349 exit 1
350 fi
351
352
353 previous=$PREVLEVEL
354 [ "$previous" = "" ] && previous=N
355
356 if [ ! -d $rc_base/rc$runlevel.d ]
357 then
358 echo "$rc_base/rc$runlevel.d does not exist"
359 exit 1
360 fi
361
362 if [ "$previous" != "N" ]
363 then
364 for i in $(ls -v $rc_base/rc$runlevel.d/K* 2> /dev/null)
365 do
366
367 check_script_status
368
369 suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]}
370 prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
371 sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix
372
373 if [ "$runlevel" != "0" ] && [ "$runlevel" != "6" ]
374 then
375 if [ ! -f $prev_start ] && [ ! -f $sysinit_start ]
376 then
377 $WARNING
378 echo "$i can't be executed because it was"
379 echo "not started in the previous runlevel ($previous)"
380 $NORMAL
381 continue
382 fi
383 fi
384
385 $i stop
386 error_value=$?
387
388 if [ "$error_value" != "0" ]
389 then
390 print_error_msg
391 fi
392 done
393 fi
394
395 for i in $( ls -v $rc_base/rc$runlevel.d/S* 2> /dev/null)
396 do
397 if [ "$previous" != "N" ]
398 then
399 suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]}
400 stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix
401 prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
402
403 [ -f $prev_start ] && [ ! -f $stop ] && continue
404 fi
405
406 check_script_status
407
408 $i start
409 error_value=$?
410
411 if [ "$error_value" != "0" ]
412 then
413 print_error_msg
414 fi
415 done

Properties

Name Value
svn:executable *