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