]>
Commit | Line | Data |
---|---|---|
05149ed5 AM |
1 | #!/bin/sh |
2 | # | |
3 | # start_udev | |
4 | # | |
5 | # script to initialize /dev by using udev. | |
6 | # | |
7 | # Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com> | |
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... | |
940e3565 ER |
22 | |
23 | # default value, if no config present. | |
24 | udev_root="/dev/" | |
b44e0a3d | 25 | sysfs_dir="/sys" |
01129224 | 26 | udev_db="/dev/.udevdb" |
d35df3ca | 27 | udevd_timeout=8 |
940e3565 | 28 | |
05149ed5 | 29 | # don't use udev if sysfs is not mounted. |
dda87135 | 30 | [ -d $sysfs_dir/class ] || exit 1 |
05149ed5 AM |
31 | [ -r /proc/mounts ] || exit 1 |
32 | [ -x /sbin/udev ] || exit 1 | |
33 | [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf | |
34 | ||
401263e1 | 35 | . /etc/rc.d/init.d/functions |
05149ed5 AM |
36 | |
37 | prog=udev | |
05149ed5 AM |
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 | ||
120a2def AM |
49 | [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts |
50 | [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm | |
05149ed5 AM |
51 | |
52 | if [ -x $MAKEDEV ]; then | |
53 | $MAKEDEV -x $( | |
05149ed5 AM |
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; | |
6ba94d68 AM |
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; | |
d8394a8d | 59 | for i in 0 1 2 3; do echo lp$i; echo parport$i;done; |
6ba94d68 | 60 | echo net/tun ppp console null zero; |
05149ed5 | 61 | ); |
bf62c441 | 62 | [ -a /dev/MAKEDEV ] || ln -sf "$MAKEDEV" /dev/MAKEDEV; |
6ba94d68 | 63 | cp -a /etc/udev/devices/* /dev/ >/dev/null 2>&1 || : |
05149ed5 AM |
64 | fi |
65 | } | |
66 | ||
d8394a8d AM |
67 | kill_udevd() { |
68 | if [ -x /sbin/pidof ]; then | |
69 | pid=`/sbin/pidof -x udevd` | |
70 | [ -n "$pid" ] && kill $pid | |
71 | fi | |
72 | } | |
73 | ||
6ba94d68 AM |
74 | # we cannot use /usr/bin/find here |
75 | find_d () { | |
84853a2e ER |
76 | where=$1 |
77 | what=$2 | |
78 | found="" | |
79 | for f in $where/*; do | |
80 | if [ -d "$f" -a ! -L "$f" ]; then | |
6ba94d68 | 81 | if [ "$f" != "${f%%$what}" ];then |
84853a2e ER |
82 | # make sure we are at the path end |
83 | # we have no dirname and basename | |
6ba94d68 AM |
84 | rest="${f#*$what}" |
85 | [ "${rest##*/}" = "$rest" ] && found="$found $f" | |
86 | fi | |
84853a2e ER |
87 | found="$found $(find_d $f $what)" |
88 | fi | |
89 | done | |
90 | echo "$found" | |
05149ed5 AM |
91 | } |
92 | ||
6ba94d68 AM |
93 | # we cannot use /usr/bin/find here |
94 | find_f () { | |
95 | where=$1 | |
96 | what=$2 | |
97 | found="" | |
98 | for f in $where/*; do | |
99 | if [ -d "$f" -a ! -L "$f" ]; then | |
100 | found="$found $(find_f $f $what)" | |
101 | elif [ -e "$f" ]; then | |
120a2def | 102 | [ "$where/" = "${f%$what}" ] && found="$found $f" |
6ba94d68 AM |
103 | fi |
104 | done | |
120a2def | 105 | [ -n "$found" ] && echo "$found" |
05149ed5 | 106 | } |
05149ed5 | 107 | |
6ba94d68 AM |
108 | # call hotplug with the scsi devices |
109 | scsi_replay () { | |
84853a2e | 110 | HOTPLUG="/sbin/udevsend" |
6ba94d68 | 111 | |
84853a2e ER |
112 | scsi_hosts=$(find_d /sys/devices host\*) |
113 | SEQNUM=1 | |
6ba94d68 | 114 | |
84853a2e ER |
115 | for host in $scsi_hosts; do |
116 | [ -d $host ] || continue | |
117 | devs=$(find_f $host type) | |
118 | for dev in $devs;do | |
119 | [ -f $dev ] || continue | |
120a2def | 120 | DEVPATH=${dev%/type} |
84853a2e ER |
121 | DEVPATH=${DEVPATH#/sys} |
122 | /bin/env -i DEVPATH="$DEVPATH" SUBSYSTEM=scsi_device ACTION=add $HOTPLUG scsi_device | |
123 | /bin/env -i DEVPATH="$DEVPATH" ACTION=add SUBSYSTEM=scsi $HOTPLUG scsi | |
124 | done | |
125 | done | |
126 | return 0 | |
6ba94d68 | 127 | } |
05149ed5 | 128 | |
d8394a8d AM |
129 | ide_scan() { |
130 | if [ ! -d /proc/ide ]; then | |
131 | return 1 | |
132 | fi | |
133 | for i in /proc/ide/*/media; do | |
134 | read media < "$i" | |
135 | case "$media" in | |
136 | disk) | |
137 | module=ide-disk | |
138 | ;; | |
139 | cdrom) | |
140 | module=ide-cd | |
141 | ;; | |
142 | tape) | |
143 | module=ide-tape | |
144 | ;; | |
145 | floppy) | |
146 | module=ide-floppy | |
147 | ;; | |
148 | *) | |
149 | module=ide-generic | |
150 | ;; | |
151 | esac | |
152 | /sbin/modprobe $module | |
153 | done | |
154 | return 0 | |
155 | } | |
156 | ||
294ac9d6 | 157 | supported_kernel() { |
158 | case "$(uname -r)" in | |
684be8e9 | 159 | 2.[012345].*) return 1 ;; |
294ac9d6 | 160 | esac |
161 | return 0 | |
162 | } | |
163 | ||
164 | set_hotplug_handler() { | |
165 | echo /sbin/udevsend > /proc/sys/kernel/hotplug | |
166 | } | |
167 | ||
05149ed5 | 168 | export ACTION=add |
6ba94d68 AM |
169 | prog=udev |
170 | ret=0 | |
171 | nls "Starting udev" | |
294ac9d6 | 172 | |
684be8e9 | 173 | if ! supported_kernel; then |
174 | echo "udev requires a kernel >= 2.6.x, not started." | |
175 | exit 0 | |
176 | fi | |
120a2def AM |
177 | |
178 | # mount the tmpfs on ${udev_root%/}, if not already done | |
179 | LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && { | |
84853a2e | 180 | if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then |
5cccdef0 | 181 | PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX) |
84853a2e ER |
182 | mount --move $udev_root/pts "$PTSDIR" |
183 | fi | |
184 | if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then | |
5cccdef0 | 185 | SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX) |
84853a2e ER |
186 | mount --move $udev_root/shm "$SHMDIR" |
187 | fi | |
188 | mount -n -o mode=0755 -t tmpfs none "$udev_root" | |
189 | mkdir -m 0755 $udev_root/pts | |
190 | mkdir -m 0755 $udev_root/shm | |
191 | if [ -n "$PTSDIR" ]; then | |
192 | mount --move "$PTSDIR" $udev_root/pts | |
193 | rmdir "$PTSDIR" | |
194 | fi | |
195 | if [ -n "$SHMDIR" ]; then | |
196 | mount --move "$SHMDIR" $udev_root/shm | |
197 | rmdir "$SHMDIR" | |
198 | fi | |
199 | ||
200 | ret=$(( $ret + $? )) | |
6ba94d68 | 201 | } |
120a2def | 202 | |
01129224 | 203 | rm -fr "$udev_db" |
ec7c0939 | 204 | |
ec7c0939 | 205 | |
120a2def | 206 | kill_udevd > "$udev_root/null" 2>&1 |
ec7c0939 | 207 | |
120a2def | 208 | scsi_replay > "$udev_root/null" 2>&1 |
ec7c0939 | 209 | |
120a2def | 210 | ret=$(( $ret + $? )) |
ec7c0939 | 211 | |
120a2def | 212 | ide_scan > "$udev_root/null" 2>&1 |
ec7c0939 | 213 | |
d35df3ca | 214 | # Starting the hotplug events dispatcher |
215 | /sbin/udevd --daemon | |
216 | ||
217 | # Making extra nodes | |
218 | make_extra_nodes | |
219 | ||
220 | # Setting default hotplug handler | |
294ac9d6 | 221 | set_hotplug_handler |
ec7c0939 | 222 | |
d35df3ca | 223 | # Synthesizing the initial hotplug events |
b06b7ca8 | 224 | /sbin/${UDEV_STARTER} |
ec7c0939 | 225 | |
d35df3ca | 226 | # wait for the udev/udevd childs to finish |
b06b7ca8 | 227 | while [ "$(grep -c -E '^Name:[[:space:]]*udevd?$' /proc/[0-9]*/status)" -gt 1 ]; do |
d35df3ca | 228 | sleep 1 |
229 | udevd_timeout=$(($udevd_timeout - 1)) | |
230 | if [ $udevd_timeout -eq 0 ]; then | |
231 | break | |
232 | fi | |
233 | done | |
ec7c0939 | 234 | |
d35df3ca | 235 | # Start workaround for broken Linux input subsystem |
b8861549 | 236 | /sbin/udev_input_coldplug start |
237 | ||
120a2def | 238 | ret=$(( $ret + $? )) |
6ba94d68 | 239 | [ $ret -eq 0 ] && ok || fail |
05149ed5 | 240 | exit 0 |