Debian Codegraph @

setup/files/misc/start_udev.drbl

raw
1 #!/bin/bash
2 #
3 # start_udev
4 #
5 # script to initialize /dev by using udev.
6 #
7 # Copyright (C) 2004 Greg Kroah-Hartman <[email protected]>
8 #
9 # Released under the GPL v2 only.
10 #
11 # This needs to be run at the earliest possible point in the boot
12 # process.
13 #
14 # Based on the udev init.d script
15 #
16 # Thanks go out to the Gentoo developers for proving
17 # that this is possible to do.
18 #
19 # Yes, it's very verbose, feel free to turn off all of the echo calls,
20 # they were there to make me feel better that everything was working
21 # properly during development...
22 #
23 # don't use udev if sysfs is not mounted.
24
25 sysfs_dir=/sys
26 TZ=/etc/localtime
27 export TZ
28
29 [ -d $sysfs_dir/class ] || exit 1
30 [ -r /proc/mounts ] || exit 1
31 [ -x /sbin/udev ] || exit 1
32 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
33
34
35 . /etc/init.d/functions
36
37 prog=udev
38 bin=/sbin/udev
39 udevd=/sbin/udevd
40 MAKEDEV="/sbin/MAKEDEV"
41
42 make_extra_nodes () {
43 ln -snf /proc/self/fd $udev_root/fd
44 ln -snf /proc/self/fd/0 $udev_root/stdin
45 ln -snf /proc/self/fd/1 $udev_root/stdout
46 ln -snf /proc/self/fd/2 $udev_root/stderr
47 ln -snf /proc/kcore $udev_root/core
48
49 [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
50 [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
51
52 if [ -x $MAKEDEV ]; then
53 $MAKEDEV -x $(
54 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
55 echo cpu/$i/microcode;
56 done;
57 for i in 1 2 3 4 5 6; do echo tty$i;done;
58 for i in 0 1 2 3 4 5 6 7; do echo loop$i; done;
59 for i in 0 1 2 3; do echo lp$i; echo parport$i;done;
60 echo net/tun ppp console null zero;
61 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 \
62 16 17 18 19 20 21 22 23 24 25 26 27 28 29 \
63 30 31; do echo md$i;done;
64 );
65 [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV;
66 cp -a /etc/udev/devices/* /dev/ >/dev/null 2>&1 || :
67 fi
68 }
69
70 # we cannot use /usr/bin/find here
71 find_d () {
72 where=$1
73 what=$2
74 found=""
75 for f in $where/*; do
76 if [ -d "$f" -a ! -L "$f" ]; then
77 if [ "$f" != "${f%%$what}" ];then
78 # make sure we are at the path end
79 # we have no dirname and basename
80 rest="${f#*$what}"
81 [ "${rest##*/}" = "$rest" ] && found="$found $f"
82 fi
83 found="$found $(find_d $f $what)"
84 fi
85 done
86 echo "$found"
87 }
88
89
90 # we cannot use /usr/bin/find here
91 find_f () {
92 where=$1
93 what=$2
94 found=""
95 for f in $where/*; do
96 if [ -d "$f" -a ! -L "$f" ]; then
97 found="$found $(find_f $f $what)"
98 elif [ -e "$f" ]; then
99 [ "$where/" = "${f%$what}" ] && found="$found $f"
100 fi
101 done
102 [ -n "$found" ] && echo "$found"
103 }
104
105 kill_udevd() {
106 if [ -x /sbin/pidof ]; then
107 pid=`/sbin/pidof -x udevd`
108 [ -n "$pid" ] && kill $pid
109 fi
110 }
111
112
113 # call hotplug with the scsi devices
114 scsi_replay () {
115 HOTPLUG=$(cat /proc/sys/kernel/hotplug)
116 [ -z "$HOTPLUG" ] && return 1
117
118 scsi_hosts=$(find_d /sys/devices host\*)
119 SEQNUM=1
120
121 for host in $scsi_hosts;do
122 [ -d $host ] || continue
123 devs=$(find_f $host type)
124 for dev in $devs;do
125 [ -f $dev ] || continue
126 export SEQNUM
127 DEVPATH=${dev%/type}
128 DEVPATH=${DEVPATH#/sys}
129 export DEVPATH
130 export ACTION=add
131 $HOTPLUG scsi_device
132 SEQNUM=$[$SEQNUM + 1]
133 $HOTPLUG scsi
134 SEQNUM=$[$SEQNUM + 1]
135 done
136 done
137 return 0
138 }
139
140 ide_scan() {
141 if [ ! -d /proc/ide ]; then
142 return 1
143 fi
144 for i in /proc/ide/*/media; do
145 read media < "$i"
146 case "$media" in
147 disk)
148 module=ide-disk
149 ;;
150 cdrom)
151 module=ide-cd
152 ;;
153 tape)
154 module=ide-tape
155 ;;
156 floppy)
157 module=ide-floppy
158 ;;
159 *)
160 module=ide-generic
161 ;;
162 esac
163 /sbin/modprobe $module
164 done
165 return 0
166 }
167
168
169 export ACTION=add
170 export UDEV_NO_SLEEP=1
171 prog=udev
172 ret=0
173 STRING=$"Starting $prog: "
174 # propagate $udev_root from /sys
175 echo -n "$STRING "
176
177 # mount the tmpfs on ${udev_root%/}, if not already done
178 LANG=C grep -F -q "none ${udev_root%/} " /proc/mounts || {
179 if LANG=C grep -F -q "none ${udev_root%/}/pts " /proc/mounts; then
180 PTSDIR=$(mktemp -d)
181 mount --move /dev/pts "$PTSDIR"
182 fi
183 if LANG=C grep -F -q "none ${udev_root%/}/shm " /proc/mounts; then
184 SHMDIR=$(mktemp -d)
185 mount --move /dev/shm "$SHMDIR"
186 fi
187 mount -n -o mode=0755 -t tmpfs none "$udev_root"
188 mkdir -m 0755 $udev_root/pts
189 mkdir -m 0755 $udev_root/shm
190 if [ -n "$PTSDIR" ]; then
191 mount --move "$PTSDIR" /dev/pts
192 rmdir "$PTSDIR"
193 fi
194 if [ -n "$SHMDIR" ]; then
195 mount --move "$SHMDIR" /dev/shm
196 rmdir "$SHMDIR"
197 fi
198
199 ret=$[$ret + $?]
200 }
201
202 rm -f $udev_root/.udev.tdb
203 make_extra_nodes
204 kill_udevd >/dev/null 2>&1
205 scsi_replay >/dev/null 2>&1
206 ret=$[$ret + $?]
207 kill_udevd >/dev/null 2>&1
208 ide_scan >/dev/null 2>&1
209 /sbin/udevstart </dev/null >/dev/null 2>&1
210 ret=$[$ret + $?]
211 [ $ret -eq 0 ] && success $"$STRING" || failure $"$STRING"
212 echo
213 exit 0