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.
28 # don't use udev if sysfs is not mounted.
29 [ -d $sysfs_dir/class ] || exit 1
30 [ -r /proc/mounts ] || exit 1
31 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
33 . /etc/rc.d/init.d/functions
38 # trim traling slash, code expects it not to be there
39 udev_root=${udev_root%/}
41 create_static_nodes() {
42 /sbin/kmod static-nodes --format=tmpfiles | \
43 while read type file mode uid gid age dev ; do
46 mkdir -p --mode=$mode $file
55 mknod --mode=$mode $file $type $maj $min
58 [ $uid = "-" ] || chown $uid $file
59 [ $gid = "-" ] || chgrp $gid $file
64 grep '^[^#]' /etc/udev/links.conf | \
65 while read type name arg1; do
66 [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
68 L) ln -s $arg1 $udev_root/$name ;;
69 D) mkdir -p $udev_root/$name ;;
70 M) mknod -m 600 /dev/$name $arg1 ;;
71 *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
74 [ -d /lib/udev/devices ] && cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
75 [ -d /lib64/udev/devices ] && cp -a /lib64/udev/devices/* /dev/ >/dev/null 2>&1 || :
79 if [ -x /sbin/pidof ]; then
80 pid=$(/sbin/pidof -x udevd)
81 [ -n "$pid" ] && kill $pid
85 set_hotplug_handler() {
86 echo "" > /proc/sys/kernel/hotplug
89 # find subdirs mounted under $udev_root
91 awk -vudev_root="$udev_root/" '
93 len = length(udev_root);
96 substr($2, 1, len) == udev_root {
97 print substr($2, len + 1)
101 show "Starting udev"; busy
107 # mount the devtmpfs on $udev_root, if not already done
108 awk "\$2 == \"$udev_root\" && \$3 == \"devtmpfs\" { exit 1 }" /proc/mounts && {
109 submounts=$(get_dev_mounts)
111 if [ "$submounts" ]; then
112 # mount to temporary location to be able to move submounts
113 # this needs writable TMPDIR:-/tmp, so it won't work in early boot
114 # but fix is simple: use initramfs instead of romfs
115 devdir=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
119 mount -n -o mode=0755 -t devtmpfs devtmpfs "$devdir"
123 for dir in $submounts; do
124 mount -n --move $udev_root/$dir $devdir/$dir
128 if [ "$submounts" ]; then
129 mount -n --move $devdir $udev_root
134 kill_udevd > "$udev_root/null" 2>&1
136 # Create required static device nodes for the current kernel
140 $udevd --daemon; rc=$?
141 test $rc -eq 0 && ok || fail
142 ret=$(( $ret + $rc ))
145 show "Setup extra nodes"; busy
146 make_extra_nodes; rc=$?
147 test $rc -eq 0 && ok || fail
148 ret=$(( $ret + $rc ))
150 if [ -f /sys/class/tty/console/uevent ]; then
151 # Setting default hotplug handler
155 # retrigger all events
156 show "Retrigger subsystems events"; busy
157 /sbin/udevadm trigger --type=subsystems --action=add; rc=$?
158 test $rc -eq 0 && ok || fail
159 ret=$(( $ret + $rc ))
161 show "Retrigger devices events"; busy
162 /sbin/udevadm trigger --type=devices --action=add; rc=$?
163 test $rc -eq 0 && ok || fail
164 ret=$(( $ret + $rc ))
166 # wait for the events to finish
167 show "udevadm settle"; busy
168 /sbin/udevadm settle; rc=$?
169 test $rc -eq 0 && ok || fail
170 ret=$(( $ret + $rc ))
172 echo "Kernel too old for this udev version"