]>
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/" | |
25 | ||
05149ed5 | 26 | # don't use udev if sysfs is not mounted. |
dda87135 ER |
27 | sysfs_dir=/sys |
28 | [ -d $sysfs_dir/class ] || exit 1 | |
05149ed5 AM |
29 | [ -r /proc/mounts ] || exit 1 |
30 | [ -x /sbin/udev ] || exit 1 | |
31 | [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf | |
32 | ||
401263e1 | 33 | . /etc/rc.d/init.d/functions |
05149ed5 AM |
34 | |
35 | prog=udev | |
05149ed5 AM |
36 | bin=/sbin/udev |
37 | udevd=/sbin/udevd | |
38 | MAKEDEV="/sbin/MAKEDEV" | |
39 | ||
40 | make_extra_nodes () { | |
41 | ln -snf /proc/self/fd $udev_root/fd | |
42 | ln -snf /proc/self/fd/0 $udev_root/stdin | |
43 | ln -snf /proc/self/fd/1 $udev_root/stdout | |
44 | ln -snf /proc/self/fd/2 $udev_root/stderr | |
45 | ln -snf /proc/kcore $udev_root/core | |
46 | ||
47 | [ -d $udev_root/pts ] || (mkdir $udev_root/pts;chmod 0755 $udev_root/pts) | |
48 | [ -d $udev_root/shm ] || (mkdir $udev_root/shm;chmod 0755 $udev_root/shm) | |
49 | ||
50 | if [ -x $MAKEDEV ]; then | |
51 | $MAKEDEV -x $( | |
05149ed5 AM |
52 | for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do |
53 | echo cpu/$i/microcode; | |
54 | done; | |
6ba94d68 AM |
55 | for i in 1 2 3 4 5 6; do echo tty$i;done; |
56 | for i in 0 1 2 3 4 5 6 7; do echo loop$i; done; | |
d8394a8d | 57 | for i in 0 1 2 3; do echo lp$i; echo parport$i;done; |
6ba94d68 | 58 | echo net/tun ppp console null zero; |
05149ed5 AM |
59 | ); |
60 | [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV; | |
6ba94d68 | 61 | cp -a /etc/udev/devices/* /dev/ >/dev/null 2>&1 || : |
05149ed5 AM |
62 | fi |
63 | } | |
64 | ||
d8394a8d AM |
65 | kill_udevd() { |
66 | if [ -x /sbin/pidof ]; then | |
67 | pid=`/sbin/pidof -x udevd` | |
68 | [ -n "$pid" ] && kill $pid | |
69 | fi | |
70 | } | |
71 | ||
6ba94d68 AM |
72 | # we cannot use /usr/bin/find here |
73 | find_d () { | |
74 | where=$1 | |
75 | what=$2 | |
76 | found="" | |
77 | for f in $where/*; do | |
78 | if [ -d "$f" -a ! -L "$f" ]; then | |
79 | if [ "$f" != "${f%%$what}" ];then | |
80 | # make sure we are at the path end | |
81 | # we have no dirname and basename | |
82 | rest="${f#*$what}" | |
83 | [ "${rest##*/}" = "$rest" ] && found="$found $f" | |
84 | fi | |
85 | found="$found $(find_d $f $what)" | |
86 | fi | |
87 | done | |
88 | echo "$found" | |
05149ed5 AM |
89 | } |
90 | ||
6ba94d68 AM |
91 | # we cannot use /usr/bin/find here |
92 | find_f () { | |
93 | where=$1 | |
94 | what=$2 | |
95 | found="" | |
96 | for f in $where/*; do | |
97 | if [ -d "$f" -a ! -L "$f" ]; then | |
98 | found="$found $(find_f $f $what)" | |
99 | elif [ -e "$f" ]; then | |
100 | [ "$f" != "${f%$what}" ] && found="$found $f" | |
101 | fi | |
102 | done | |
103 | echo "$found" | |
05149ed5 | 104 | } |
05149ed5 | 105 | |
6ba94d68 AM |
106 | # call hotplug with the scsi devices |
107 | scsi_replay () { | |
108 | HOTPLUG=$(cat /proc/sys/kernel/hotplug) | |
109 | [ -z "$HOTPLUG" ] && return 1 | |
110 | ||
111 | scsi_hosts=$(find_d /sys/devices host\*) | |
112 | SEQNUM=1 | |
113 | ||
114 | for host in $scsi_hosts; do | |
115 | [ -d $host ] || continue | |
116 | devs=$(find_f $host type) | |
117 | for dev in $devs;do | |
118 | [ -f $dev ] || continue | |
119 | export SEQNUM | |
120 | DEVPATH=${dev%/type} | |
121 | DEVPATH=${DEVPATH#/sys} | |
122 | export DEVPATH | |
123 | export ACTION=add | |
124 | $HOTPLUG scsi_device | |
e993d7ee | 125 | SEQNUM=$(($SEQNUM + 1)) |
6ba94d68 | 126 | $HOTPLUG scsi |
e993d7ee | 127 | SEQNUM=$(($SEQNUM + 1)) |
6ba94d68 AM |
128 | done |
129 | done | |
130 | return 0 | |
131 | } | |
05149ed5 | 132 | |
d8394a8d AM |
133 | ide_scan() { |
134 | if [ ! -d /proc/ide ]; then | |
135 | return 1 | |
136 | fi | |
137 | for i in /proc/ide/*/media; do | |
138 | read media < "$i" | |
139 | case "$media" in | |
140 | disk) | |
141 | module=ide-disk | |
142 | ;; | |
143 | cdrom) | |
144 | module=ide-cd | |
145 | ;; | |
146 | tape) | |
147 | module=ide-tape | |
148 | ;; | |
149 | floppy) | |
150 | module=ide-floppy | |
151 | ;; | |
152 | *) | |
153 | module=ide-generic | |
154 | ;; | |
155 | esac | |
156 | /sbin/modprobe $module | |
157 | done | |
158 | return 0 | |
159 | } | |
160 | ||
05149ed5 AM |
161 | export ACTION=add |
162 | export UDEV_NO_SLEEP=1 | |
6ba94d68 AM |
163 | prog=udev |
164 | ret=0 | |
165 | nls "Starting udev" | |
05149ed5 | 166 | # propagate $udev_root from /sys |
6ba94d68 AM |
167 | grep -q "none ${udev_root%/} " /proc/mounts || { |
168 | mount -n -o mode=0755 -t tmpfs none "$udev_root" | |
169 | ret=$(($ret + $?)) | |
170 | } | |
940e3565 | 171 | rm -rf $udev_root/.udev.tdb |
6ba94d68 | 172 | make_extra_nodes |
d8394a8d | 173 | kill_udevd >/dev/null 2>&1 |
6ba94d68 AM |
174 | scsi_replay >/dev/null 2>&1 |
175 | ret=$(($ret + $?)) | |
d8394a8d AM |
176 | kill_udevd >/dev/null 2>&1 |
177 | ide_scan >/dev/null 2>&1 | |
6ba94d68 AM |
178 | /sbin/udevstart |
179 | ret=$(($ret + $?)) | |
180 | [ $ret -eq 0 ] && ok || fail | |
05149ed5 | 181 | exit 0 |