Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 394 - (show annotations) (download)
Tue Oct 31 09:10:45 2006 UTC (17 years, 6 months ago) by niro
File size: 9241 byte(s)
updated udev functions to use this with udev >=96

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

Properties

Name Value
svn:executable *