Annotation of /trunk/initscripts/sysvinit/rc/rc
Parent Directory | Revision Log
Revision 428 -
(hide annotations)
(download)
Sun Mar 4 13:24:34 2007 UTC (17 years, 3 months ago) by niro
Original Path: trunk/magellan-initscripts/etc/rc.d/init.d/rc
File size: 9739 byte(s)
Sun Mar 4 13:24:34 2007 UTC (17 years, 3 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 | niro | 2 | #!/bin/bash |
2 | niro | 428 | # $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 | niro | 2 | |
4 | source /etc/sysconfig/rc | ||
5 | source $rc_functions | ||
6 | |||
7 | niro | 50 | # get mage version |
8 | MAGEVER="$(< /etc/mageversion)" | ||
9 | niro | 2 | |
10 | niro | 150 | # source kernel config if exists |
11 | niro | 2 | [ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel |
12 | |||
13 | niro | 319 | 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 | niro | 394 | local opts |
32 | niro | 318 | |
33 | niro | 428 | # tell modprobe.sh to be verbose to $CONSOLE |
34 | echo CONSOLE=${CONSOLE} > /dev/.udev_populate | ||
35 | |||
36 | niro | 318 | # populate /dev with devices already found by the kernel |
37 | niro | 376 | if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -gt "2614" ] |
38 | niro | 318 | then |
39 | echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." | ||
40 | niro | 394 | [[ $(udev_version) -ge "96" ]] && opts="--attr-match=dev" |
41 | /sbin/udevtrigger ${opts} | ||
42 | niro | 318 | evaluate_retval |
43 | else | ||
44 | echo -e ${COLOREDSTAR}" Populating /dev with existing devices with udevstart ..." | ||
45 | niro | 2 | /sbin/udevstart |
46 | niro | 318 | evaluate_retval |
47 | fi | ||
48 | niro | 2 | |
49 | niro | 318 | # loop until everything is finished |
50 | echo -e ${COLOREDSTAR}" Letting udev process events ..." | ||
51 | niro | 394 | /sbin/udevsettle --timeout=60 |
52 | niro | 318 | evaluate_retval |
53 | |||
54 | niro | 428 | rm -f /dev/.udev_populate |
55 | niro | 318 | return 0 |
56 | } | ||
57 | |||
58 | niro | 319 | seed_dev() |
59 | { | ||
60 | niro | 318 | # seed /dev with some things that we know we need |
61 | echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." | ||
62 | ( | ||
63 | niro | 428 | [ ! -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 | niro | 318 | # copy over any persistant things |
68 | niro | 394 | if [[ -d /lib/udev/devices ]] |
69 | then | ||
70 | cp --preserve=all --recursive --update /lib/udev/devices/* /dev | ||
71 | fi | ||
72 | niro | 428 | |
73 | niro | 150 | # not provided by sysfs but needed |
74 | niro | 2 | 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 | niro | 318 | [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core |
79 | |||
80 | niro | 150 | # create problematic directories |
81 | niro | 2 | mkdir -p /dev/{pts,shm} |
82 | niro | 318 | ) |
83 | evaluate_retval | ||
84 | } | ||
85 | niro | 2 | |
86 | trap "" INT QUIT TSTP | ||
87 | |||
88 | [ "$1" != "" ] && runlevel=$1 | ||
89 | |||
90 | niro | 150 | if [[ $runlevel = sysinit ]] |
91 | niro | 2 | then |
92 | echo | ||
93 | echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" | ||
94 | niro | 425 | echo -e "Copyright 2001-2007 Niels Rogalla; http://magellan-linux.net" |
95 | niro | 2 | echo |
96 | |||
97 | niro | 150 | # mount proc filesystem, needed for bootsplash; |
98 | # no use of '/etc/rc.d/init.d/mountproc' anymore | ||
99 | niro | 2 | 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 | niro | 150 | # set default verbose level for kernel messages |
107 | niro | 2 | [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
108 | echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk | ||
109 | |||
110 | niro | 150 | # mount sys file system before udev or devfs (kernel-2.6) |
111 | if [[ $(kernel_major_version) = 2.6 ]] | ||
112 | niro | 2 | then |
113 | if [ -d /sys ] | ||
114 | then | ||
115 | echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." | ||
116 | niro | 150 | mount -n -t sysfs sysfs /sys |
117 | niro | 2 | 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 | niro | 150 | # 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 | niro | 2 | 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 | niro | 150 | mount -n -t devfs devfs /dev |
137 | niro | 2 | 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 | niro | 150 | # load udev only with a 2.6 kernel |
160 | if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]] | ||
161 | niro | 2 | then |
162 | niro | 428 | # check if /dev/console exists outside tmpfs |
163 | [ -c /dev/console ] ; need_redirect=$? | ||
164 | |||
165 | niro | 150 | # create a ramdisk for populating udev |
166 | echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." | ||
167 | niro | 394 | # many video drivers needed exec access |
168 | fstype=ramfs | ||
169 | niro | 150 | # tmpfs was suggested by Greg Kroah-Hartman |
170 | niro | 395 | kernel_supports_fs tmpfs && fstype=tmpfs |
171 | niro | 394 | mount -n -t ${fstype} udev /dev -o exec,nosuid,mode=0755 |
172 | niro | 2 | evaluate_retval |
173 | |||
174 | niro | 150 | # if a device tarball exists load it and if it is activated |
175 | niro | 2 | echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
176 | niro | 150 | if [[ ${RC_DEVICE_TARBALL} = yes ]] |
177 | niro | 2 | then |
178 | niro | 318 | echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." |
179 | niro | 2 | tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev |
180 | evaluate_retval | ||
181 | fi | ||
182 | |||
183 | niro | 318 | # other eeded device nodes with udev |
184 | seed_dev | ||
185 | niro | 2 | |
186 | niro | 318 | if [ -e /proc/sys/kernel/hotplug ] |
187 | niro | 2 | then |
188 | niro | 376 | if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -gt "2614" ] |
189 | niro | 318 | then |
190 | echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." | ||
191 | echo "" > /proc/sys/kernel/hotplug | ||
192 | evaluate_retval | ||
193 | niro | 394 | else |
194 | niro | 318 | echo -e ${COLOREDSTAR}" Setting /sbin/udevsend as hotplug agent ..." |
195 | echo "/sbin/udevsend" > /proc/sys/kernel/hotplug | ||
196 | evaluate_retval | ||
197 | fi | ||
198 | niro | 2 | else |
199 | echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" | ||
200 | niro | 318 | print_status failure |
201 | niro | 2 | fi |
202 | niro | 318 | |
203 | echo -e ${COLOREDSTAR}" Starting udevd daemon ..." | ||
204 | niro | 428 | 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 | niro | 2 | evaluate_retval |
212 | niro | 318 | |
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 | niro | 2 | fi |
225 | |||
226 | ## load devpts ## | ||
227 | # devfs/udev with 2.6 has no ptys, so devpts is also needed | ||
228 | niro | 150 | if [[ $(kernel_major_version) = 2.6 ]] |
229 | niro | 2 | then |
230 | # check if we really have devpts support | ||
231 | niro | 150 | if kernel_supports_fs devpts |
232 | niro | 2 | 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 | niro | 150 | # 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 | niro | 2 | then |
239 | mkdir -p /dev/pts &> /dev/null || \ | ||
240 | echo "Could not create /dev/pts !" | ||
241 | fi | ||
242 | niro | 71 | |
243 | niro | 150 | # now mount devpts |
244 | niro | 2 | if [ -d /dev/pts ] |
245 | then | ||
246 | echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." | ||
247 | niro | 150 | mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts |
248 | niro | 2 | 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 | niro | 150 | # load bootsplash |
269 | niro | 2 | splash "rc_init" "${runlevel}" |
270 | fi | ||
271 | |||
272 | |||
273 | niro | 150 | if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]] |
274 | niro | 2 | then |
275 | niro | 150 | # load bootsplash |
276 | niro | 2 | 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 | niro | 150 | if [[ ${RC_DEVICE_TARBALL} = yes ]] && \ |
282 | [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ] | ||
283 | niro | 2 | then |
284 | echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." | ||
285 | niro | 150 | ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) |
286 | niro | 2 | 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 | niro | 150 | |
299 | niro | 2 | 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 | * |