5 # script to initialize /dev by using udev.
7 # Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
9 # Released under the GPL v2 only.
11 # This needs to be run at the earliest possible point in the boot
14 # Based on the udev init.d script
16 # Thanks go out to the Gentoo developers for proving
17 # that this is possible to do.
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...
23 # default value, if no config present.
26 udev_db="/dev/.udevdb"
29 # don't use udev if sysfs is not mounted.
30 [ -d $sysfs_dir/class ] || exit 1
31 [ -r /proc/mounts ] || exit 1
32 [ -x /sbin/udev ] || exit 1
33 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
35 . /etc/rc.d/init.d/functions
40 MAKEDEV="/sbin/MAKEDEV"
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
49 [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
50 [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
52 if [ -x $MAKEDEV ]; then
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;
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;
62 [ -a /dev/MAKEDEV ] || ln -sf "$MAKEDEV" /dev/MAKEDEV;
63 cp -a /etc/udev/devices/* /dev/ >/dev/null 2>&1 || :
68 if [ -x /sbin/pidof ]; then
69 pid=`/sbin/pidof -x udevd`
70 [ -n "$pid" ] && kill $pid
74 # we cannot use /usr/bin/find here
80 if [ -d "$f" -a ! -L "$f" ]; then
81 if [ "$f" != "${f%%$what}" ];then
82 # make sure we are at the path end
83 # we have no dirname and basename
85 [ "${rest##*/}" = "$rest" ] && found="$found $f"
87 found="$found $(find_d $f $what)"
93 # we cannot use /usr/bin/find here
99 if [ -d "$f" -a ! -L "$f" ]; then
100 found="$found $(find_f $f $what)"
101 elif [ -e "$f" ]; then
102 [ "$where/" = "${f%$what}" ] && found="$found $f"
105 [ -n "$found" ] && echo "$found"
108 # call hotplug with the scsi devices
110 HOTPLUG="/sbin/udevsend"
112 scsi_hosts=$(find_d /sys/devices host\*)
115 for host in $scsi_hosts; do
116 [ -d $host ] || continue
117 devs=$(find_f $host type)
119 [ -f $dev ] || continue
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
130 if [ ! -d /proc/ide ]; then
133 for i in /proc/ide/*/media; do
152 /sbin/modprobe $module
158 case "$(uname -r)" in
159 2.[012345].*) return 1 ;;
164 set_hotplug_handler() {
165 echo /sbin/udevsend > /proc/sys/kernel/hotplug
173 if ! supported_kernel; then
174 echo "udev requires a kernel >= 2.6.x, not started."
178 # mount the tmpfs on ${udev_root%/}, if not already done
179 LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
180 if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
181 PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
182 mount --move $udev_root/pts "$PTSDIR"
184 if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
185 SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
186 mount --move $udev_root/shm "$SHMDIR"
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
195 if [ -n "$SHMDIR" ]; then
196 mount --move "$SHMDIR" $udev_root/shm
206 kill_udevd > "$udev_root/null" 2>&1
208 scsi_replay > "$udev_root/null" 2>&1
212 ide_scan > "$udev_root/null" 2>&1
214 # Starting the hotplug events dispatcher
220 # Setting default hotplug handler
223 # Synthesizing the initial hotplug events
224 /sbin/${UDEV_STARTER}
226 # wait for the udev/udevd childs to finish
227 while [ "$(grep -c -E '^Name:[[:space:]]*udevd?$' /proc/[0-9]*/status)" -gt 1 ]; do
229 udevd_timeout=$(($udevd_timeout - 1))
230 if [ $udevd_timeout -eq 0 ]; then
235 # Start workaround for broken Linux input subsystem
236 /sbin/udev_input_coldplug start
239 [ $ret -eq 0 ] && ok || fail