1 |
#!/bin/bash |
#!/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 |
source /etc/sysconfig/rc |
5 |
source $rc_functions |
source $rc_functions |
|
source /etc/mageversion |
|
6 |
|
|
7 |
|
# get mage version |
8 |
|
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 |
udev_version() |
14 |
populate_udev() { |
{ |
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 |
/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 |
#not provided by sysfs but needed |
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 |
ln -snf /proc/self/fd /dev/fd |
110 |
ln -snf fd/0 /dev/stdin |
ln -snf fd/0 /dev/stdin |
111 |
ln -snf fd/1 /dev/stdout |
ln -snf fd/1 /dev/stdout |
112 |
ln -snf fd/2 /dev/stderr |
ln -snf fd/2 /dev/stderr |
113 |
ln -snf /proc/kcore /dev/core |
[[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core |
114 |
ln -snf /proc/asound/oss/sndstat /dev/sndstat |
|
115 |
|
# create problematic directories |
|
#create problematic directories |
|
116 |
mkdir -p /dev/{pts,shm} |
mkdir -p /dev/{pts,shm} |
117 |
|
) |
118 |
#same as /dev/.devfsd |
evaluate_retval |
|
touch /dev/.udev |
|
|
|
|
|
return 0 |
|
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 |
trap "" INT QUIT TSTP |
143 |
|
|
144 |
[ "$1" != "" ] && runlevel=$1 |
[ "$1" != "" ] && runlevel=$1 |
145 |
|
|
146 |
if [ "$runlevel" = "sysinit" ] |
if [[ $runlevel = sysinit ]] |
147 |
then |
then |
148 |
echo |
echo |
149 |
echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" |
echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" |
150 |
echo -e "\"I'm not a Gentoo-System, I'm a pure LFS\"" |
echo -e "Copyright 2001-2005 Niels Rogalla; http://magellan-linux.net" |
151 |
echo |
echo |
152 |
|
|
153 |
#mount proc filesystem, needed for bootsplash; |
# mount proc filesystem, needed for bootsplash; |
154 |
#no use of '/etc/rc.d/init.d/mountproc' anymore |
# no use of '/etc/rc.d/init.d/mountproc' anymore |
155 |
if [ ! -e /proc/mounts ] |
if [ ! -e /proc/mounts ] |
156 |
then |
then |
157 |
echo -e ${COLOREDSTAR}"Mounting proc file system ..." |
echo -e ${COLOREDSTAR}"Mounting proc file system ..." |
159 |
evaluate_retval |
evaluate_retval |
160 |
fi |
fi |
161 |
|
|
162 |
#set default verbose level for kernel messages |
# set default verbose level for kernel messages |
163 |
[ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
[ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
164 |
echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk |
echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk |
165 |
|
|
166 |
#mount sys file system before udev or devfs (kernel-2.6) |
# mount sys file system before udev or devfs (kernel-2.6) |
167 |
if [ "$(kernel_major_version)" == "2.6" ] |
if [[ $(kernel_major_version) = 2.6 ]] |
168 |
then |
then |
169 |
if [ -d /sys ] |
if [ -d /sys ] |
170 |
then |
then |
171 |
echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." |
echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." |
172 |
mount -t sysfs none /sys |
mount -n -t sysfs sysfs /sys |
173 |
evaluate_retval |
evaluate_retval |
174 |
else |
else |
175 |
echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." |
echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." |
179 |
fi |
fi |
180 |
|
|
181 |
## load devfs ## |
## load devfs ## |
182 |
#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 |
183 |
if [ "$(kernel_major_version)" == "2.4" -o "${RC_USED_DEV}" == "devfs" ] |
if [[ $(kernel_major_version) = 2.4 ]] || [[ ${RC_USED_DEV} = devfs ]] |
184 |
then |
then |
185 |
# start devfsd daemon, needed for bootsplash; |
# start devfsd daemon, needed for bootsplash; |
186 |
# no use of '/etc/rc.d/init.d/devfs' anymore |
# no use of '/etc/rc.d/init.d/devfs' anymore |
189 |
if [ ! -e /dev/.devfsd ] |
if [ ! -e /dev/.devfsd ] |
190 |
then |
then |
191 |
echo -e ${COLOREDSTAR}"Mounting devfs file system ..." |
echo -e ${COLOREDSTAR}"Mounting devfs file system ..." |
192 |
mount -t devfs devfs /dev |
mount -n -t devfs devfs /dev |
193 |
evaluate_retval |
evaluate_retval |
194 |
fi |
fi |
195 |
|
|
|
|
|
196 |
if [ -e /dev/.devfsd ] |
if [ -e /dev/.devfsd ] |
197 |
then |
then |
198 |
echo -e ${COLOREDSTAR}"Starting devfsd ..." |
echo -e ${COLOREDSTAR}"Starting devfsd ..." |
209 |
read |
read |
210 |
$rc_base/init.d/halt |
$rc_base/init.d/halt |
211 |
fi |
fi |
|
|
|
212 |
fi |
fi |
213 |
|
|
214 |
#### load udev #### |
#### load udev #### |
215 |
#load udev only with a 2.6 kernel |
# load udev only with a 2.6 kernel |
216 |
if [ "$(kernel_major_version)" == "2.6" -a "${RC_USED_DEV}" == "udev" ] |
if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]] |
217 |
then |
then |
218 |
# #first at all unmount devfs if this was loaded by the kernel |
# create a ramdisk for populating udev |
219 |
# DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)" |
echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." |
220 |
# if [ "${DEVFS_MOUNTED}" == "devfs" ] |
# tmpfs was suggested by Greg Kroah-Hartman |
221 |
# then |
# many video drivers needed exec access |
222 |
# 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 |
|
223 |
evaluate_retval |
evaluate_retval |
224 |
|
|
225 |
#if a device tarball exists load it and if it is activated |
# if a device tarball exists load it and if it is activated |
226 |
echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
227 |
if [ "${RC_DEVICE_TARBALL}" = "yes" ] |
if [[ ${RC_DEVICE_TARBALL} = yes ]] |
228 |
then |
then |
229 |
echo -e ${COLOREDSTAR}" Populating /dev with with device nodes ..." |
echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." |
230 |
tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev |
tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev |
231 |
evaluate_retval |
evaluate_retval |
232 |
fi |
fi |
233 |
|
|
234 |
#now load udev |
# other eeded device nodes with udev |
235 |
populate_udev |
seed_dev |
236 |
|
|
237 |
#if hotplug support exists in the kernel use it to manage udev |
if [ -e /proc/sys/kernel/hotplug ] |
|
if [ -e /proc/sys/kernel/hotplug -a -x /sbin/hotplug ] |
|
238 |
then |
then |
239 |
echo -e ${COLOREDSTAR}" Using /sbin/hotplug for udev management ..." |
if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ] |
240 |
|
then |
241 |
elif [ -e /proc/sys/kernel/hotplug ] |
echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." |
242 |
then |
echo "" > /proc/sys/kernel/hotplug |
243 |
echo -e ${COLOREDSTAR}" Setting /sbin/udev as hotplug agent ..." |
evaluate_retval |
244 |
echo "/sbin/udev" > /proc/sys/kernel/hotplug |
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 |
else |
259 |
echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" |
echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" |
260 |
|
print_status failure |
261 |
fi |
fi |
262 |
|
|
263 |
|
echo -e ${COLOREDSTAR}" Starting udevd daemon ..." |
264 |
|
/sbin/udevd --daemon |
265 |
evaluate_retval |
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 |
fi |
279 |
|
|
|
|
|
280 |
## load devpts ## |
## load devpts ## |
281 |
# 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 |
282 |
if [ $(kernel_major_version) == 2.6 ] |
if [[ $(kernel_major_version) = 2.6 ]] |
283 |
then |
then |
284 |
# check if we really have devpts support |
# check if we really have devpts support |
285 |
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 ] |
|
286 |
then |
then |
287 |
# /dev/pts maybe not exists. |
# /dev/pts maybe not exists. |
288 |
# We only create this directory only if devfs was mounted, |
# We only create this directory only if devfs was mounted, |
289 |
# or it will fail as / is still mounted readonly |
# or it will fail as / is still mounted readonly |
290 |
if [ ! -d "/dev/pts" \ |
# udev has this dir already, only a sanity check for devfs |
291 |
-a -e "/dev/.devfsd" \ |
if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs |
|
-a "${DEVFS_MOUNTED}" == "devfs" ] |
|
292 |
then |
then |
293 |
mkdir -p /dev/pts &> /dev/null || \ |
mkdir -p /dev/pts &> /dev/null || \ |
294 |
echo "Could not create /dev/pts !" |
echo "Could not create /dev/pts !" |
295 |
fi |
fi |
296 |
|
|
297 |
#now mount devpts |
# now mount devpts |
298 |
if [ -d /dev/pts ] |
if [ -d /dev/pts ] |
299 |
then |
then |
300 |
echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." |
echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." |
301 |
mount -n -t devpts -o gid=4,mode=0620 none /dev/pts |
mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts |
302 |
evaluate_retval |
evaluate_retval |
303 |
fi |
fi |
304 |
else |
else |
319 |
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 |
320 |
evaluate_retval |
evaluate_retval |
321 |
|
|
322 |
#load bootsplash |
# load bootsplash |
323 |
splash "rc_init" "${runlevel}" |
splash "rc_init" "${runlevel}" |
324 |
fi |
fi |
325 |
|
|
326 |
|
|
327 |
|
if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]] |
|
if [ "$runlevel" == "0" ] |
|
328 |
then |
then |
329 |
|
# load bootsplash |
|
#load bootsplash |
|
330 |
splash "rc_init" "${runlevel}" |
splash "rc_init" "${runlevel}" |
331 |
|
|
|
|
|
332 |
# if requested save devices to a device tarball before halt |
# if requested save devices to a device tarball before halt |
333 |
# only for kernels >=2.6 *and* udev |
# only for kernels >=2.6 *and* udev |
334 |
# make shure that udev is mounted but *not* devfs --> /dev/.devfsd |
# make shure that udev is mounted but *not* devfs --> /dev/.devfsd |
335 |
if [ "${RC_DEVICE_TARBALL}" = "yes" \ |
if [[ ${RC_DEVICE_TARBALL} = yes ]] && \ |
336 |
-a -e /dev/.udev \ |
[ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ] |
|
-a ! -e /dev/.devfsd \ |
|
|
-a ! -e /.bootdev ] |
|
337 |
then |
then |
338 |
echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." |
echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." |
339 |
cd /dev |
( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) |
|
tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null |
|
340 |
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 |
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 |
341 |
evaluate_retval |
evaluate_retval |
342 |
fi |
fi |
343 |
fi |
fi |
344 |
|
|
|
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 |
|
345 |
|
|
346 |
if [ "$runlevel" = "" ] |
if [ "$runlevel" = "" ] |
347 |
then |
then |
349 |
exit 1 |
exit 1 |
350 |
fi |
fi |
351 |
|
|
352 |
|
|
353 |
previous=$PREVLEVEL |
previous=$PREVLEVEL |
354 |
[ "$previous" = "" ] && previous=N |
[ "$previous" = "" ] && previous=N |
355 |
|
|