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