]>
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" |
d35df3ca | 26 | udevd_timeout=8 |
940e3565 | 27 | |
05149ed5 | 28 | # don't use udev if sysfs is not mounted. |
dda87135 | 29 | [ -d $sysfs_dir/class ] || exit 1 |
05149ed5 AM |
30 | [ -r /proc/mounts ] || exit 1 |
31 | [ -x /sbin/udev ] || exit 1 | |
32 | [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf | |
33 | ||
401263e1 | 34 | . /etc/rc.d/init.d/functions |
05149ed5 AM |
35 | |
36 | prog=udev | |
05149ed5 AM |
37 | bin=/sbin/udev |
38 | udevd=/sbin/udevd | |
05149ed5 AM |
39 | |
40 | make_extra_nodes () { | |
ba060a4b | 41 | grep '^[^#]' /etc/udev/links.conf | \ |
42 | while read type name arg1; do | |
43 | [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue | |
44 | case "$type" in | |
45 | L) ln -s $arg1 $udev_root/$name ;; | |
46 | D) mkdir -p $udev_root/$name ;; | |
ba060a4b | 47 | *) echo "links.conf: unparseable line ($type $name $arg1)" ;; |
48 | esac | |
49 | done | |
44abfb53 | 50 | cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || : |
05149ed5 AM |
51 | } |
52 | ||
d8394a8d AM |
53 | kill_udevd() { |
54 | if [ -x /sbin/pidof ]; then | |
55 | pid=`/sbin/pidof -x udevd` | |
56 | [ -n "$pid" ] && kill $pid | |
57 | fi | |
58 | } | |
59 | ||
294ac9d6 | 60 | supported_kernel() { |
de6b464e | 61 | if [ -f "/sys/class/tty/console/uevent" ]; then |
684be8e9 | 62 | 2.[012345].*) return 1 ;; |
294ac9d6 | 63 | esac |
64 | return 0 | |
65 | } | |
66 | ||
67 | set_hotplug_handler() { | |
de6b464e | 68 | echo "" > /proc/sys/kernel/hotplug |
294ac9d6 | 69 | } |
de6b464e | 70 | return 0 |
05149ed5 | 71 | export ACTION=add |
6ba94d68 AM |
72 | prog=udev |
73 | ret=0 | |
90d90678 AM |
74 | show "Starting udev" |
75 | busy | |
294ac9d6 | 76 | |
684be8e9 | 77 | if ! supported_kernel; then |
90d90678 | 78 | fail |
684be8e9 | 79 | fi |
120a2def AM |
80 | # mount the tmpfs on ${udev_root%/}, if not already done |
81 | LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && { | |
de6b464e | 82 | if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then |
83 | PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX) | |
84853a2e ER |
84 | mount --move $udev_root/pts "$PTSDIR" |
85 | fi | |
86 | if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then | |
5cccdef0 | 87 | SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX) |
84853a2e ER |
88 | mount --move $udev_root/shm "$SHMDIR" |
89 | fi | |
90 | mount -n -o mode=0755 -t tmpfs none "$udev_root" | |
91 | mkdir -m 0755 $udev_root/pts | |
92 | mkdir -m 0755 $udev_root/shm | |
93 | if [ -n "$PTSDIR" ]; then | |
94 | mount --move "$PTSDIR" $udev_root/pts | |
95 | rmdir "$PTSDIR" | |
96 | fi | |
97 | if [ -n "$SHMDIR" ]; then | |
98 | mount --move "$SHMDIR" $udev_root/shm | |
99 | rmdir "$SHMDIR" | |
100 | fi | |
101 | ||
102 | ret=$(( $ret + $? )) | |
6ba94d68 | 103 | } |
120a2def | 104 | |
120a2def | 105 | kill_udevd > "$udev_root/null" 2>&1 |
ec7c0939 | 106 | |
de6b464e | 107 | if [ -f "/sys/class/tty/console/uevent" ]; then |
108 | # Start udevd daemon | |
109 | udevd -d | |
110 | ||
111 | # Making extra nodes | |
112 | make_extra_nodes | |
113 | ||
114 | # Setting default hotplug handler | |
115 | set_hotplug_handler | |
116 | else | |
117 | echo "udev requires a kernel >= 2.6.15, not started." | |
118 | exit 0 | |
119 | fi | |
120a2def | 120 | ret=$(( $ret + $? )) |
6ba94d68 | 121 | [ $ret -eq 0 ] && ok || fail |
05149ed5 | 122 | exit 0 |