1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.6 2006-01-03 18:03:21 niro Exp $ |
3 |
|
|
4 |
source /etc/sysconfig/rc |
source /etc/sysconfig/rc |
5 |
source $rc_functions |
source $rc_functions |
7 |
# get mage version |
# get mage version |
8 |
MAGEVER="$(< /etc/mageversion)" |
MAGEVER="$(< /etc/mageversion)" |
9 |
|
|
10 |
#source kernel config if exists |
# source kernel config if exists |
11 |
[ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel |
[ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel |
12 |
|
|
13 |
#some needed functions functions |
# this works only for 2.6.15 kernels and greater |
14 |
|
trigger_events() |
15 |
|
{ |
16 |
|
local list="" |
17 |
|
local i |
18 |
|
local first |
19 |
|
local last |
20 |
|
local default |
21 |
|
|
22 |
|
# if you want real hotplug (with all modules being loaded for all |
23 |
|
# devices in the system), uncomment out the next line. |
24 |
|
#list="$list $(echo /sys/bus/*/devices/*/uevent)" |
25 |
|
list="${list} $(echo /sys/class/*/*/uevent)" |
26 |
|
list="${list} $(echo /sys/block/*/uevent /sys/block/*/*/uevent)" |
27 |
|
for i in ${list} |
28 |
|
do |
29 |
|
case "${i}" in |
30 |
|
*/device/uevent) |
31 |
|
# skip followed device symlinks |
32 |
|
continue |
33 |
|
;; |
34 |
|
*/class/mem/*|*/class/tty/*) |
35 |
|
first="${first} ${i}" |
36 |
|
;; |
37 |
|
*/block/md*) |
38 |
|
last="${last} ${i}" |
39 |
|
;; |
40 |
|
*/*) |
41 |
|
default="${default} ${i}" |
42 |
|
;; |
43 |
|
esac |
44 |
|
done |
45 |
|
|
46 |
|
# trigger the sorted events |
47 |
|
for i in ${first} ${default} ${last} |
48 |
|
do |
49 |
|
echo "add" > "${i}" |
50 |
|
done |
51 |
|
} |
52 |
|
|
53 |
populate_udev() { |
populate_udev() { |
54 |
|
local loop |
55 |
|
|
56 |
|
# populate /dev with devices already found by the kernel |
57 |
|
if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ] |
58 |
|
then |
59 |
|
echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." |
60 |
|
trigger_events |
61 |
|
evaluate_retval |
62 |
|
else |
63 |
|
echo -e ${COLOREDSTAR}" Populating /dev with existing devices with udevstart ..." |
64 |
/sbin/udevstart |
/sbin/udevstart |
65 |
|
evaluate_retval |
66 |
|
fi |
67 |
|
|
68 |
#not provided by sysfs but needed |
# loop until everything is finished |
69 |
|
# there's gotta be a better way... |
70 |
|
echo -e ${COLOREDSTAR}" Letting udev process events ..." |
71 |
|
loop=0 |
72 |
|
while test -d /dev/.udev/queue |
73 |
|
do |
74 |
|
sleep 0.1; |
75 |
|
test "${loop}" -gt 300 && break |
76 |
|
loop=$((${loop} + 1)) |
77 |
|
done |
78 |
|
evaluate_retval |
79 |
|
|
80 |
|
return 0 |
81 |
|
} |
82 |
|
|
83 |
|
seed_dev() { |
84 |
|
# seed /dev with some things that we know we need |
85 |
|
echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." |
86 |
|
( |
87 |
|
# copy over any persistant things |
88 |
|
cp --preserve=all --recursive --update /lib/udev/devices/* /dev |
89 |
|
|
90 |
|
# not provided by sysfs but needed |
91 |
ln -snf /proc/self/fd /dev/fd |
ln -snf /proc/self/fd /dev/fd |
92 |
ln -snf fd/0 /dev/stdin |
ln -snf fd/0 /dev/stdin |
93 |
ln -snf fd/1 /dev/stdout |
ln -snf fd/1 /dev/stdout |
94 |
ln -snf fd/2 /dev/stderr |
ln -snf fd/2 /dev/stderr |
95 |
ln -snf /proc/kcore /dev/core |
[[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core |
96 |
ln -snf /proc/asound/oss/sndstat /dev/sndstat |
|
97 |
|
# create problematic directories |
|
#create problematic directories |
|
98 |
mkdir -p /dev/{pts,shm} |
mkdir -p /dev/{pts,shm} |
99 |
|
) |
100 |
#same as /dev/.devfsd |
evaluate_retval |
|
touch /dev/.udev |
|
|
|
|
|
return 0 |
|
101 |
} |
} |
102 |
|
|
103 |
|
# # some needed functions functions |
104 |
|
# populate_udev() { |
105 |
|
# /sbin/udevstart |
106 |
|
# |
107 |
|
# # not provided by sysfs but needed |
108 |
|
# ln -snf /proc/self/fd /dev/fd |
109 |
|
# ln -snf fd/0 /dev/stdin |
110 |
|
# ln -snf fd/1 /dev/stdout |
111 |
|
# ln -snf fd/2 /dev/stderr |
112 |
|
# ln -snf /proc/kcore /dev/core |
113 |
|
# ln -snf /proc/asound/oss/sndstat /dev/sndstat |
114 |
|
# |
115 |
|
# # create problematic directories |
116 |
|
# mkdir -p /dev/{pts,shm} |
117 |
|
# |
118 |
|
# # same as /dev/.devfsd |
119 |
|
# touch /dev/.udev |
120 |
|
# |
121 |
|
# return 0 |
122 |
|
# } |
123 |
|
|
124 |
trap "" INT QUIT TSTP |
trap "" INT QUIT TSTP |
125 |
|
|
126 |
[ "$1" != "" ] && runlevel=$1 |
[ "$1" != "" ] && runlevel=$1 |
127 |
|
|
128 |
if [ "$runlevel" = "sysinit" ] |
if [[ $runlevel = sysinit ]] |
129 |
then |
then |
130 |
echo |
echo |
131 |
echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" |
echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" |
132 |
echo -e "\"I'm not a Gentoo-System, I'm a pure LFS\"" |
echo -e "Copyright 2001-2005 Niels Rogalla; http://magellan-linux.net" |
133 |
echo |
echo |
134 |
|
|
135 |
#mount proc filesystem, needed for bootsplash; |
# mount proc filesystem, needed for bootsplash; |
136 |
#no use of '/etc/rc.d/init.d/mountproc' anymore |
# no use of '/etc/rc.d/init.d/mountproc' anymore |
137 |
if [ ! -e /proc/mounts ] |
if [ ! -e /proc/mounts ] |
138 |
then |
then |
139 |
echo -e ${COLOREDSTAR}"Mounting proc file system ..." |
echo -e ${COLOREDSTAR}"Mounting proc file system ..." |
141 |
evaluate_retval |
evaluate_retval |
142 |
fi |
fi |
143 |
|
|
144 |
#set default verbose level for kernel messages |
# set default verbose level for kernel messages |
145 |
[ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
[ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
146 |
echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk |
echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk |
147 |
|
|
148 |
#mount sys file system before udev or devfs (kernel-2.6) |
# mount sys file system before udev or devfs (kernel-2.6) |
149 |
if [ "$(kernel_major_version)" == "2.6" ] |
if [[ $(kernel_major_version) = 2.6 ]] |
150 |
then |
then |
151 |
if [ -d /sys ] |
if [ -d /sys ] |
152 |
then |
then |
153 |
echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." |
echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." |
154 |
mount -t sysfs none /sys |
mount -n -t sysfs sysfs /sys |
155 |
evaluate_retval |
evaluate_retval |
156 |
else |
else |
157 |
echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." |
echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." |
161 |
fi |
fi |
162 |
|
|
163 |
## load devfs ## |
## load devfs ## |
164 |
#load devfs only with a 2.4 kernel or its really wanted with a 2.6 |
# load devfs only with a 2.4 kernel or its really wanted with a 2.6 |
165 |
if [ "$(kernel_major_version)" == "2.4" -o "${RC_USED_DEV}" == "devfs" ] |
if [[ $(kernel_major_version) = 2.4 ]] || [[ ${RC_USED_DEV} = devfs ]] |
166 |
then |
then |
167 |
# start devfsd daemon, needed for bootsplash; |
# start devfsd daemon, needed for bootsplash; |
168 |
# no use of '/etc/rc.d/init.d/devfs' anymore |
# no use of '/etc/rc.d/init.d/devfs' anymore |
171 |
if [ ! -e /dev/.devfsd ] |
if [ ! -e /dev/.devfsd ] |
172 |
then |
then |
173 |
echo -e ${COLOREDSTAR}"Mounting devfs file system ..." |
echo -e ${COLOREDSTAR}"Mounting devfs file system ..." |
174 |
mount -t devfs devfs /dev |
mount -n -t devfs devfs /dev |
175 |
evaluate_retval |
evaluate_retval |
176 |
fi |
fi |
177 |
|
|
|
|
|
178 |
if [ -e /dev/.devfsd ] |
if [ -e /dev/.devfsd ] |
179 |
then |
then |
180 |
echo -e ${COLOREDSTAR}"Starting devfsd ..." |
echo -e ${COLOREDSTAR}"Starting devfsd ..." |
191 |
read |
read |
192 |
$rc_base/init.d/halt |
$rc_base/init.d/halt |
193 |
fi |
fi |
|
|
|
194 |
fi |
fi |
195 |
|
|
196 |
#### load udev #### |
#### load udev #### |
197 |
#load udev only with a 2.6 kernel |
# load udev only with a 2.6 kernel |
198 |
if [ "$(kernel_major_version)" == "2.6" -a "${RC_USED_DEV}" == "udev" ] |
if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]] |
199 |
then |
then |
200 |
# #first at all unmount devfs if this was loaded by the kernel |
# create a ramdisk for populating udev |
201 |
# DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)" |
echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." |
202 |
# if [ "${DEVFS_MOUNTED}" == "devfs" ] |
# tmpfs was suggested by Greg Kroah-Hartman |
203 |
# then |
# many video drivers needed exec access |
204 |
# umount -n /dev \ |
mount -n -t ramfs udev /dev -o exec,nosuid,mode=0755 |
|
# && echo "debug: unmounted devfs successfully" \ |
|
|
# || echo "debug: unmounting devfs failed" |
|
|
# fi |
|
|
|
|
|
#create a ramdisk for populating udev |
|
|
echo -e ${COLOREDSTAR}"Mounting ramfs at /dev ..." |
|
|
mount -n -t ramfs none /dev |
|
205 |
evaluate_retval |
evaluate_retval |
206 |
|
|
207 |
#if a device tarball exists load it and if it is activated |
# if a device tarball exists load it and if it is activated |
208 |
echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
209 |
if [ "${RC_DEVICE_TARBALL}" = "yes" ] |
if [[ ${RC_DEVICE_TARBALL} = yes ]] |
210 |
then |
then |
211 |
echo -e ${COLOREDSTAR}" Populating /dev with with device nodes ..." |
echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." |
212 |
tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev |
tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev |
213 |
evaluate_retval |
evaluate_retval |
214 |
fi |
fi |
215 |
|
|
216 |
#now load udev |
# other eeded device nodes with udev |
217 |
populate_udev |
seed_dev |
|
|
|
|
#if hotplug support exists in the kernel use it to manage udev |
|
|
if [ -e /proc/sys/kernel/hotplug -a -x /sbin/hotplug ] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}" Using /sbin/hotplug for udev management ..." |
|
218 |
|
|
219 |
elif [ -e /proc/sys/kernel/hotplug ] |
if [ -e /proc/sys/kernel/hotplug ] |
220 |
then |
then |
221 |
echo -e ${COLOREDSTAR}" Setting /sbin/udev as hotplug agent ..." |
if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ] |
222 |
echo "/sbin/udev" > /proc/sys/kernel/hotplug |
then |
223 |
|
echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." |
224 |
|
echo "" > /proc/sys/kernel/hotplug |
225 |
|
evaluate_retval |
226 |
|
elif [[ $(udev_version) -ge "48" ]] |
227 |
|
then |
228 |
|
echo -e ${COLOREDSTAR}" Setting /sbin/udevsend as hotplug agent ..." |
229 |
|
echo "/sbin/udevsend" > /proc/sys/kernel/hotplug |
230 |
|
evaluate_retval |
231 |
|
elif [[ -x /sbin/hotplug ]] |
232 |
|
then |
233 |
|
echo -e ${COLOREDSTAR}" Using /sbin/hotplug as hotplug agent ..." |
234 |
|
print_status success |
235 |
|
else |
236 |
|
echo -e ${COLOREDSTAR}" Setting /sbin/udev as hotplug agent ..." |
237 |
|
echo "/sbin/udev" > /proc/sys/kernel/hotplug |
238 |
|
evaluate_retval |
239 |
|
fi |
240 |
else |
else |
241 |
echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" |
echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" |
242 |
|
print_status failure |
243 |
fi |
fi |
244 |
|
|
245 |
|
echo -e ${COLOREDSTAR}" Starting udevd daemon ..." |
246 |
|
/sbin/udevd --daemon |
247 |
evaluate_retval |
evaluate_retval |
248 |
|
|
249 |
|
populate_udev |
250 |
|
|
251 |
|
# create nodes that udev can't |
252 |
|
echo -e ${COLOREDSTAR}" Finializing udev configuration ..." |
253 |
|
[[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null |
254 |
|
[[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null |
255 |
|
[[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null |
256 |
|
print_status success |
257 |
|
|
258 |
|
# same thing as /dev/.devfsd |
259 |
|
touch /dev/.udev |
260 |
fi |
fi |
261 |
|
|
|
|
|
262 |
## load devpts ## |
## load devpts ## |
263 |
# devfs/udev with 2.6 has no ptys, so devpts is also needed |
# devfs/udev with 2.6 has no ptys, so devpts is also needed |
264 |
if [ $(kernel_major_version) == 2.6 ] |
if [[ $(kernel_major_version) = 2.6 ]] |
265 |
then |
then |
266 |
# check if we really have devpts support |
# check if we really have devpts support |
267 |
DEVPTS_CHECK="$(cat /proc/filesystems | grep devpts | cut -d $'\t' -f2)" |
if kernel_supports_fs devpts |
|
DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)" |
|
|
if [ "${DEVPTS_CHECK}" == devpts ] |
|
268 |
then |
then |
269 |
# /dev/pts maybe not exists. |
# /dev/pts maybe not exists. |
270 |
# We only create this directory only if devfs was mounted, |
# We only create this directory only if devfs was mounted, |
271 |
# or it will fail as / is still mounted readonly |
# or it will fail as / is still mounted readonly |
272 |
if [ ! -d "/dev/pts" \ |
# udev has this dir already, only a sanity check for devfs |
273 |
-a -e "/dev/.devfsd" \ |
if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs |
|
-a "${DEVFS_MOUNTED}" == "devfs" ] |
|
274 |
then |
then |
275 |
mkdir -p /dev/pts &> /dev/null || \ |
mkdir -p /dev/pts &> /dev/null || \ |
276 |
echo "Could not create /dev/pts !" |
echo "Could not create /dev/pts !" |
277 |
fi |
fi |
278 |
|
|
279 |
#now mount devpts |
# now mount devpts |
280 |
if [ -d /dev/pts ] |
if [ -d /dev/pts ] |
281 |
then |
then |
282 |
echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." |
echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." |
283 |
mount -n -t devpts -o gid=4,mode=0620 none /dev/pts |
mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts |
284 |
evaluate_retval |
evaluate_retval |
285 |
fi |
fi |
286 |
else |
else |
301 |
mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k |
mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k |
302 |
evaluate_retval |
evaluate_retval |
303 |
|
|
304 |
#load bootsplash |
# load bootsplash |
305 |
splash "rc_init" "${runlevel}" |
splash "rc_init" "${runlevel}" |
306 |
fi |
fi |
307 |
|
|
308 |
|
|
309 |
|
if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]] |
|
if [ "$runlevel" == "0" ] |
|
310 |
then |
then |
311 |
|
# load bootsplash |
|
#load bootsplash |
|
312 |
splash "rc_init" "${runlevel}" |
splash "rc_init" "${runlevel}" |
313 |
|
|
|
|
|
314 |
# if requested save devices to a device tarball before halt |
# if requested save devices to a device tarball before halt |
315 |
# only for kernels >=2.6 *and* udev |
# only for kernels >=2.6 *and* udev |
316 |
# make shure that udev is mounted but *not* devfs --> /dev/.devfsd |
# make shure that udev is mounted but *not* devfs --> /dev/.devfsd |
317 |
if [ "${RC_DEVICE_TARBALL}" = "yes" \ |
if [[ ${RC_DEVICE_TARBALL} = yes ]] && \ |
318 |
-a -e /dev/.udev \ |
[ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ] |
|
-a ! -e /dev/.devfsd \ |
|
|
-a ! -e /.bootdev ] |
|
319 |
then |
then |
320 |
echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." |
echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." |
321 |
cd /dev |
( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) |
|
tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null |
|
322 |
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 |
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 |
323 |
evaluate_retval |
evaluate_retval |
324 |
fi |
fi |
325 |
fi |
fi |
326 |
|
|
|
if [ "$runlevel" == "6" ] |
|
|
then |
|
|
|
|
|
#load bootsplash |
|
|
splash "rc_init" "${runlevel}" |
|
|
|
|
|
# if requested save devices to a device tarball before halt |
|
|
# only for kernels >=2.6 *and* udev |
|
|
# make shure that udev is mounted but *not* devfs --> /dev/.devfsd |
|
|
if [ "${RC_DEVICE_TARBALL}" = "yes" \ |
|
|
-a -e /dev/.udev \ |
|
|
-a ! -e /dev/.devfsd \ |
|
|
-a ! -e /.bootdev ] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." |
|
|
cd /dev |
|
|
tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null |
|
|
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 |
|
|
cd .. |
|
|
evaluate_retval |
|
|
fi |
|
|
fi |
|
327 |
|
|
328 |
if [ "$runlevel" = "" ] |
if [ "$runlevel" = "" ] |
329 |
then |
then |
331 |
exit 1 |
exit 1 |
332 |
fi |
fi |
333 |
|
|
334 |
|
|
335 |
previous=$PREVLEVEL |
previous=$PREVLEVEL |
336 |
[ "$previous" = "" ] && previous=N |
[ "$previous" = "" ] && previous=N |
337 |
|
|