]> git.pld-linux.org Git - packages/systemd.git/blame - start_udev
- external make_extra_nodes configuration (from mandriva/debian)
[packages/systemd.git] / start_udev
CommitLineData
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.
24udev_root="/dev/"
b44e0a3d 25sysfs_dir="/sys"
d35df3ca 26udevd_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
36prog=udev
05149ed5
AM
37bin=/sbin/udev
38udevd=/sbin/udevd
39MAKEDEV="/sbin/MAKEDEV"
40
41make_extra_nodes () {
ba060a4b 42 grep '^[^#]' /etc/udev/links.conf | \
43 while read type name arg1; do
44 [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
45 case "$type" in
46 L) ln -s $arg1 $udev_root/$name ;;
47 D) mkdir -p $udev_root/$name ;;
48 M) mknod --mode=600 $udev_root/$name $arg1 ;;
49 *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
50 esac
51 done
44abfb53 52 cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
05149ed5
AM
53}
54
d8394a8d
AM
55kill_udevd() {
56 if [ -x /sbin/pidof ]; then
57 pid=`/sbin/pidof -x udevd`
58 [ -n "$pid" ] && kill $pid
59 fi
60}
61
6ba94d68
AM
62# we cannot use /usr/bin/find here
63find_d () {
84853a2e
ER
64 where=$1
65 what=$2
66 found=""
67 for f in $where/*; do
68 if [ -d "$f" -a ! -L "$f" ]; then
6ba94d68 69 if [ "$f" != "${f%%$what}" ];then
84853a2e
ER
70 # make sure we are at the path end
71 # we have no dirname and basename
6ba94d68
AM
72 rest="${f#*$what}"
73 [ "${rest##*/}" = "$rest" ] && found="$found $f"
74 fi
84853a2e
ER
75 found="$found $(find_d $f $what)"
76 fi
77 done
78 echo "$found"
05149ed5
AM
79}
80
6ba94d68
AM
81# we cannot use /usr/bin/find here
82find_f () {
83 where=$1
84 what=$2
85 found=""
86 for f in $where/*; do
87 if [ -d "$f" -a ! -L "$f" ]; then
88 found="$found $(find_f $f $what)"
89 elif [ -e "$f" ]; then
120a2def 90 [ "$where/" = "${f%$what}" ] && found="$found $f"
6ba94d68
AM
91 fi
92 done
120a2def 93 [ -n "$found" ] && echo "$found"
05149ed5 94}
05149ed5 95
6ba94d68
AM
96# call hotplug with the scsi devices
97scsi_replay () {
84853a2e 98 HOTPLUG="/sbin/udevsend"
6ba94d68 99
84853a2e
ER
100 scsi_hosts=$(find_d /sys/devices host\*)
101 SEQNUM=1
6ba94d68 102
84853a2e
ER
103 for host in $scsi_hosts; do
104 [ -d $host ] || continue
105 devs=$(find_f $host type)
106 for dev in $devs;do
107 [ -f $dev ] || continue
120a2def 108 DEVPATH=${dev%/type}
84853a2e
ER
109 DEVPATH=${DEVPATH#/sys}
110 /bin/env -i DEVPATH="$DEVPATH" SUBSYSTEM=scsi_device ACTION=add $HOTPLUG scsi_device
111 /bin/env -i DEVPATH="$DEVPATH" ACTION=add SUBSYSTEM=scsi $HOTPLUG scsi
112 done
113 done
114 return 0
6ba94d68 115}
05149ed5 116
d8394a8d
AM
117ide_scan() {
118 if [ ! -d /proc/ide ]; then
119 return 1
120 fi
121 for i in /proc/ide/*/media; do
122 read media < "$i"
123 case "$media" in
124 disk)
125 module=ide-disk
126 ;;
127 cdrom)
128 module=ide-cd
129 ;;
130 tape)
131 module=ide-tape
132 ;;
133 floppy)
134 module=ide-floppy
135 ;;
136 *)
137 module=ide-generic
138 ;;
139 esac
140 /sbin/modprobe $module
141 done
142 return 0
143}
144
294ac9d6 145supported_kernel() {
146 case "$(uname -r)" in
684be8e9 147 2.[012345].*) return 1 ;;
294ac9d6 148 esac
149 return 0
150}
151
152set_hotplug_handler() {
153 echo /sbin/udevsend > /proc/sys/kernel/hotplug
154}
155
05149ed5 156export ACTION=add
6ba94d68
AM
157prog=udev
158ret=0
90d90678
AM
159show "Starting udev"
160busy
294ac9d6 161
684be8e9 162if ! supported_kernel; then
90d90678 163 fail
684be8e9 164 echo "udev requires a kernel >= 2.6.x, not started."
165 exit 0
166fi
120a2def
AM
167
168# mount the tmpfs on ${udev_root%/}, if not already done
169LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
84853a2e 170 if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
5cccdef0 171 PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
84853a2e
ER
172 mount --move $udev_root/pts "$PTSDIR"
173 fi
174 if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
5cccdef0 175 SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
84853a2e
ER
176 mount --move $udev_root/shm "$SHMDIR"
177 fi
178 mount -n -o mode=0755 -t tmpfs none "$udev_root"
179 mkdir -m 0755 $udev_root/pts
180 mkdir -m 0755 $udev_root/shm
181 if [ -n "$PTSDIR" ]; then
182 mount --move "$PTSDIR" $udev_root/pts
183 rmdir "$PTSDIR"
184 fi
185 if [ -n "$SHMDIR" ]; then
186 mount --move "$SHMDIR" $udev_root/shm
187 rmdir "$SHMDIR"
188 fi
189
190 ret=$(( $ret + $? ))
6ba94d68 191}
120a2def 192
ec7c0939 193
120a2def 194kill_udevd > "$udev_root/null" 2>&1
ec7c0939 195
120a2def 196scsi_replay > "$udev_root/null" 2>&1
ec7c0939 197
120a2def 198ret=$(( $ret + $? ))
ec7c0939 199
120a2def 200ide_scan > "$udev_root/null" 2>&1
ec7c0939 201
d35df3ca 202# Starting the hotplug events dispatcher
203/sbin/udevd --daemon
204
205# Making extra nodes
206make_extra_nodes
207
208# Setting default hotplug handler
294ac9d6 209set_hotplug_handler
ec7c0939 210
d35df3ca 211# Synthesizing the initial hotplug events
b06b7ca8 212/sbin/${UDEV_STARTER}
ec7c0939 213
c3ea7827 214# wait for /dev to be fully populated
215while [ -d /dev/.udev/queue/ ]; do
216 sleep 0.2
d35df3ca 217 udevd_timeout=$(($udevd_timeout - 1))
218 if [ $udevd_timeout -eq 0 ]; then
219 break
220 fi
221done
ec7c0939 222
d35df3ca 223# Start workaround for broken Linux input subsystem
f3702bb9 224/lib/udev/udev_input_coldplug start
b8861549 225
120a2def 226ret=$(( $ret + $? ))
6ba94d68 227[ $ret -eq 0 ] && ok || fail
05149ed5 228exit 0
This page took 0.085904 seconds and 4 git commands to generate.