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 $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.20 2008-03-22 19:58:58 niro Exp $ |
3 |
|
|
4 |
source /etc/sysconfig/rc |
source /etc/sysconfig/rc |
5 |
source $rc_functions |
source $rc_functions |
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 |
# this works only for 2.6.15 kernels and greater |
udev_version() |
|
trigger_events() |
|
14 |
{ |
{ |
15 |
local list="" |
local version=0 |
16 |
local i |
|
17 |
local first |
if [[ -x /sbin/udev ]] |
18 |
local last |
then |
19 |
local default |
version=$(/sbin/udev -V) |
20 |
|
# We need it without a leading '0', else bash do the wrong thing |
21 |
# if you want real hotplug (with all modules being loaded for all |
version=${version##0} |
22 |
# devices in the system), uncomment out the next line. |
# Older udev's will print nothing |
23 |
#list="$list $(echo /sys/bus/*/devices/*/uevent)" |
[[ -z ${version} ]] && version=0 |
24 |
list="${list} $(echo /sys/class/*/*/uevent)" |
elif [[ -x /sbin/udevd ]] |
25 |
list="${list} $(echo /sys/block/*/uevent /sys/block/*/*/uevent)" |
then |
26 |
for i in ${list} |
version=$(/sbin/udevd --version) |
27 |
do |
version=${version##0} |
28 |
case "${i}" in |
[[ -z ${version} ]] && version=0 |
29 |
*/device/uevent) |
fi |
30 |
# skip followed device symlinks |
|
31 |
continue |
echo "${version}" |
|
;; |
|
|
*/class/mem/*|*/class/tty/*) |
|
|
first="${first} ${i}" |
|
|
;; |
|
|
*/block/md*) |
|
|
last="${last} ${i}" |
|
|
;; |
|
|
*/*) |
|
|
default="${default} ${i}" |
|
|
;; |
|
|
esac |
|
|
done |
|
|
|
|
|
# trigger the sorted events |
|
|
for i in ${first} ${default} ${last} |
|
|
do |
|
|
echo "add" > "${i}" |
|
|
done |
|
32 |
} |
} |
33 |
|
|
34 |
populate_udev() { |
populate_udev() |
35 |
local loop |
{ |
36 |
|
local opts |
37 |
|
|
38 |
|
# tell modprobe.sh to be verbose to $CONSOLE |
39 |
|
echo CONSOLE=${CONSOLE} > /dev/.udev_populate |
40 |
|
|
41 |
# populate /dev with devices already found by the kernel |
# populate /dev with devices already found by the kernel |
42 |
if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ] |
echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." |
43 |
|
if [[ ${RC_COLDPLUG} = yes ]] |
44 |
then |
then |
45 |
echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." |
/sbin/udevtrigger |
|
trigger_events |
|
|
evaluate_retval |
|
46 |
else |
else |
47 |
echo -e ${COLOREDSTAR}" Populating /dev with existing devices with udevstart ..." |
# do not run any init-scripts |
48 |
/sbin/udevstart |
/sbin/udevadm control --env do_not_run_plug_service=1 |
49 |
evaluate_retval |
|
50 |
|
# only create device nodes |
51 |
|
/sbin/udevtrigger --attr-match=dev |
52 |
|
|
53 |
|
# run persistent-net stuff |
54 |
|
/sbin/udevtrigger --subsystem-match=net |
55 |
fi |
fi |
56 |
|
evaluate_retval |
57 |
|
|
58 |
# loop until everything is finished |
# loop until everything is finished |
|
# there's gotta be a better way... |
|
59 |
echo -e ${COLOREDSTAR}" Letting udev process events ..." |
echo -e ${COLOREDSTAR}" Letting udev process events ..." |
60 |
loop=0 |
/sbin/udevsettle --timeout=60 |
|
while test -d /dev/.udev/queue |
|
|
do |
|
|
sleep 0.1; |
|
|
test "${loop}" -gt 300 && break |
|
|
loop=$((${loop} + 1)) |
|
|
done |
|
61 |
evaluate_retval |
evaluate_retval |
62 |
|
|
63 |
|
# unset this variable |
64 |
|
udevadm control --env do_not_run_plug_service= |
65 |
|
|
66 |
|
rm -f /dev/.udev_populate |
67 |
return 0 |
return 0 |
68 |
} |
} |
69 |
|
|
70 |
seed_dev() { |
seed_dev() |
71 |
|
{ |
72 |
# seed /dev with some things that we know we need |
# seed /dev with some things that we know we need |
73 |
echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." |
echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." |
74 |
( |
( |
75 |
|
[ ! -c /dev/console ] && mknod /dev/console c 5 1 |
76 |
|
[ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1 |
77 |
|
[ ! -c /dev/null ] && mknod /dev/null c 1 3 |
78 |
|
|
79 |
# copy over any persistant things |
# copy over any persistant things |
80 |
cp --preserve=all --recursive --update /lib/udev/devices/* /dev |
if [[ -d /lib/udev/devices ]] |
81 |
|
then |
82 |
|
cp -RPp /lib/udev/devices/* /dev 2>/dev/null |
83 |
|
fi |
84 |
|
|
85 |
# not provided by sysfs but needed |
# not provided by sysfs but needed |
86 |
ln -snf /proc/self/fd /dev/fd |
ln -snf /proc/self/fd /dev/fd |
87 |
ln -snf fd/0 /dev/stdin |
ln -snf fd/0 /dev/stdin |
88 |
ln -snf fd/1 /dev/stdout |
ln -snf fd/1 /dev/stdout |
89 |
ln -snf fd/2 /dev/stderr |
ln -snf fd/2 /dev/stderr |
90 |
[[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core |
[[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core |
91 |
|
|
92 |
# create problematic directories |
# create problematic directories |
93 |
mkdir -p /dev/{pts,shm} |
mkdir -p /dev/pts /dev/shm |
94 |
) |
) |
95 |
evaluate_retval |
evaluate_retval |
96 |
} |
} |
97 |
|
|
|
# # some needed functions functions |
|
|
# populate_udev() { |
|
|
# /sbin/udevstart |
|
|
# |
|
|
# # not provided by sysfs but needed |
|
|
# ln -snf /proc/self/fd /dev/fd |
|
|
# ln -snf fd/0 /dev/stdin |
|
|
# ln -snf fd/1 /dev/stdout |
|
|
# ln -snf fd/2 /dev/stderr |
|
|
# ln -snf /proc/kcore /dev/core |
|
|
# ln -snf /proc/asound/oss/sndstat /dev/sndstat |
|
|
# |
|
|
# # create problematic directories |
|
|
# mkdir -p /dev/{pts,shm} |
|
|
# |
|
|
# # same as /dev/.devfsd |
|
|
# touch /dev/.udev |
|
|
# |
|
|
# return 0 |
|
|
# } |
|
|
|
|
98 |
trap "" INT QUIT TSTP |
trap "" INT QUIT TSTP |
99 |
|
|
100 |
[ "$1" != "" ] && runlevel=$1 |
[ "$1" != "" ] && runlevel=$1 |
103 |
then |
then |
104 |
echo |
echo |
105 |
echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" |
echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" |
106 |
echo -e "Copyright 2001-2005 Niels Rogalla; http://magellan-linux.net" |
echo -e "Copyright 2001-2008 Niels Rogalla; http://magellan-linux.net" |
107 |
echo |
echo |
108 |
|
|
109 |
# mount proc filesystem, needed for bootsplash; |
# mount proc filesystem, needed for bootsplash; |
119 |
[ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
[ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
120 |
echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk |
echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk |
121 |
|
|
122 |
# mount sys file system before udev or devfs (kernel-2.6) |
# mount sys file system before udev |
123 |
if [[ $(kernel_major_version) = 2.6 ]] |
if [ -d /sys ] |
124 |
then |
then |
125 |
if [ -d /sys ] |
echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." |
126 |
then |
mount -n -t sysfs sysfs /sys |
127 |
echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." |
evaluate_retval |
128 |
mount -n -t sysfs sysfs /sys |
else |
129 |
evaluate_retval |
echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." |
130 |
else |
echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)." |
131 |
echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." |
echo -e ${COLYELLOW}"It's essential for a 2.6 kernel." |
|
echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)." |
|
|
echo -e ${COLYELLOW}"It's essential for a 2.6 kernel." |
|
|
fi |
|
132 |
fi |
fi |
133 |
|
|
|
## load devfs ## |
|
|
# load devfs only with a 2.4 kernel or its really wanted with a 2.6 |
|
|
if [[ $(kernel_major_version) = 2.4 ]] || [[ ${RC_USED_DEV} = devfs ]] |
|
|
then |
|
|
# start devfsd daemon, needed for bootsplash; |
|
|
# no use of '/etc/rc.d/init.d/devfs' anymore |
|
|
# check if devfs was mounted by the kernel, |
|
|
# if not mount it (mbuild_livecd needs this one) |
|
|
if [ ! -e /dev/.devfsd ] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}"Mounting devfs file system ..." |
|
|
mount -n -t devfs devfs /dev |
|
|
evaluate_retval |
|
|
fi |
|
|
|
|
|
if [ -e /dev/.devfsd ] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}"Starting devfsd ..." |
|
|
## directory /lib/dev-state !must! exists ## |
|
|
/sbin/devfsd /dev &> /dev/null |
|
|
evaluate_retval |
|
|
else |
|
|
echo -e ${COLRED}"No devfs filesystem found ..." |
|
|
echo -e ${COLYELLOW}"Your Kernel doesn't support the devfs filesystem." |
|
|
echo -e ${COLYELLOW}"Devfs is necessary to run Magellan-Linux." |
|
|
echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." |
|
|
echo |
|
|
echo -e ${COLYELLOW}"Press any key to shutdown the system safely ..." |
|
|
read |
|
|
$rc_base/init.d/halt |
|
|
fi |
|
|
fi |
|
134 |
|
|
135 |
#### load udev #### |
#### load udev #### |
136 |
# load udev only with a 2.6 kernel |
# check if /dev/console exists outside tmpfs |
137 |
if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]] |
[ -c /dev/console ] ; need_redirect=$? |
|
then |
|
|
# create a ramdisk for populating udev |
|
|
echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." |
|
|
# tmpfs was suggested by Greg Kroah-Hartman |
|
|
# many video drivers needed exec access |
|
|
mount -n -t ramfs udev /dev -o exec,nosuid,mode=0755 |
|
|
evaluate_retval |
|
138 |
|
|
139 |
# if a device tarball exists load it and if it is activated |
# create a ramdisk for populating udev |
140 |
echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." |
141 |
if [[ ${RC_DEVICE_TARBALL} = yes ]] |
# many video drivers needed exec access |
142 |
then |
fstype=ramfs |
143 |
echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." |
# tmpfs was suggested by Greg Kroah-Hartman |
144 |
tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev |
kernel_supports_fs tmpfs && fstype=tmpfs |
145 |
evaluate_retval |
mount -n -t ${fstype} udev /dev -o exec,nosuid,mode=0755,size=10M |
146 |
fi |
evaluate_retval |
147 |
|
|
148 |
# other eeded device nodes with udev |
# if a device tarball exists load it and if it is activated |
149 |
seed_dev |
echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
150 |
|
if [[ ${RC_DEVICE_TARBALL} = yes ]] |
151 |
|
then |
152 |
|
echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." |
153 |
|
tar -jxpf /lib/udev/state/devices.tar.bz2 -C /dev |
154 |
|
evaluate_retval |
155 |
|
fi |
156 |
|
|
157 |
if [ -e /proc/sys/kernel/hotplug ] |
# other eeded device nodes with udev |
158 |
then |
seed_dev |
|
if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." |
|
|
echo "" > /proc/sys/kernel/hotplug |
|
|
evaluate_retval |
|
|
elif [[ $(udev_version) -ge "48" ]] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}" Setting /sbin/udevsend as hotplug agent ..." |
|
|
echo "/sbin/udevsend" > /proc/sys/kernel/hotplug |
|
|
evaluate_retval |
|
|
elif [[ -x /sbin/hotplug ]] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}" Using /sbin/hotplug as hotplug agent ..." |
|
|
print_status success |
|
|
else |
|
|
echo -e ${COLOREDSTAR}" Setting /sbin/udev as hotplug agent ..." |
|
|
echo "/sbin/udev" > /proc/sys/kernel/hotplug |
|
|
evaluate_retval |
|
|
fi |
|
|
else |
|
|
echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" |
|
|
print_status failure |
|
|
fi |
|
159 |
|
|
160 |
echo -e ${COLOREDSTAR}" Starting udevd daemon ..." |
if [ -e /proc/sys/kernel/hotplug ] |
161 |
/sbin/udevd --daemon |
then |
162 |
|
echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." |
163 |
|
echo "" > /proc/sys/kernel/hotplug |
164 |
evaluate_retval |
evaluate_retval |
165 |
|
else |
166 |
|
echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" |
167 |
|
print_status failure |
168 |
|
fi |
169 |
|
|
170 |
populate_udev |
echo -e ${COLOREDSTAR}" Starting udevd daemon ..." |
171 |
|
if [ ${need_redirect} -eq 1 ] |
172 |
|
then |
173 |
|
# we need to open fds 0 1 2 |
174 |
|
/sbin/udevd --daemon </dev/console >/dev/console 2>/dev/console |
175 |
|
else |
176 |
|
/sbin/udevd --daemon |
177 |
|
fi |
178 |
|
evaluate_retval |
179 |
|
|
180 |
# create nodes that udev can't |
# write root_link rule |
181 |
echo -e ${COLOREDSTAR}" Finializing udev configuration ..." |
/lib/udev/write_root_link_rule |
182 |
[[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null |
# populate udev device nodes |
183 |
[[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null |
populate_udev |
184 |
[[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null |
|
185 |
print_status success |
# create nodes that udev can't |
186 |
|
echo -e ${COLOREDSTAR}" Finializing udev configuration ..." |
187 |
|
[[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null |
188 |
|
[[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null |
189 |
|
[[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null |
190 |
|
print_status success |
191 |
|
|
192 |
|
# same thing as /dev/.devfsd |
193 |
|
touch /dev/.udev |
194 |
|
## end udev ## |
195 |
|
|
|
# same thing as /dev/.devfsd |
|
|
touch /dev/.udev |
|
|
fi |
|
196 |
|
|
197 |
## load devpts ## |
## load devpts ## |
198 |
# 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 |
199 |
if [[ $(kernel_major_version) = 2.6 ]] |
# check if we really have devpts support |
200 |
|
if kernel_supports_fs devpts |
201 |
then |
then |
202 |
# check if we really have devpts support |
# /dev/pts maybe not exists. |
203 |
if kernel_supports_fs devpts |
# We only create this directory only if devfs was mounted, |
204 |
|
# or it will fail as / is still mounted readonly |
205 |
|
# udev has this dir already, only a sanity check for devfs |
206 |
|
if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs |
207 |
|
then |
208 |
|
mkdir -p /dev/pts &> /dev/null || \ |
209 |
|
echo "Could not create /dev/pts !" |
210 |
|
fi |
211 |
|
|
212 |
|
# now mount devpts |
213 |
|
if [ -d /dev/pts ] |
214 |
then |
then |
215 |
# /dev/pts maybe not exists. |
echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." |
216 |
# We only create this directory only if devfs was mounted, |
mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts |
217 |
# or it will fail as / is still mounted readonly |
evaluate_retval |
|
# udev has this dir already, only a sanity check for devfs |
|
|
if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs |
|
|
then |
|
|
mkdir -p /dev/pts &> /dev/null || \ |
|
|
echo "Could not create /dev/pts !" |
|
|
fi |
|
|
|
|
|
# now mount devpts |
|
|
if [ -d /dev/pts ] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." |
|
|
mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts |
|
|
evaluate_retval |
|
|
fi |
|
|
else |
|
|
# devpts is not supported, give a warning |
|
|
echo -e ${COLRED}"No devpts filesystem found ..." |
|
|
echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem." |
|
|
echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts," |
|
|
echo -e ${COLYELLOW}"or no pty's are available." |
|
|
echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." |
|
|
echo |
|
|
echo -e ${COLYELLOW}"Press any key to continue ..." |
|
|
read |
|
218 |
fi |
fi |
219 |
|
else |
220 |
|
# devpts is not supported, give a warning |
221 |
|
echo -e ${COLRED}"No devpts filesystem found ..." |
222 |
|
echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem." |
223 |
|
echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts," |
224 |
|
echo -e ${COLYELLOW}"or no pty's are available." |
225 |
|
echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." |
226 |
|
echo |
227 |
|
echo -e ${COLYELLOW}"Press any key to continue ..." |
228 |
|
read |
229 |
|
fi |
230 |
|
## end devpts ## |
231 |
|
|
232 |
|
|
233 |
|
## load usbfs ## |
234 |
|
if kernel_supports_fs usbfs |
235 |
|
then |
236 |
|
echo -e ${COLOREDSTAR}"Mounting usbfs at /proc/bus/usb ..." |
237 |
|
mount -n -t usbfs usbfs /proc/bus/usb |
238 |
|
evaluate_retval |
239 |
fi |
fi |
240 |
|
## end usbfs ## |
241 |
|
|
242 |
### services state dir ### |
## services state dir ## |
243 |
echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..." |
echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..." |
244 |
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 |
245 |
evaluate_retval |
evaluate_retval |
262 |
then |
then |
263 |
echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." |
echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." |
264 |
( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) |
( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) |
265 |
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 |
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev/state/devices.tar.bz2 |
266 |
evaluate_retval |
evaluate_retval |
267 |
fi |
fi |
268 |
fi |
fi |