]> git.pld-linux.org Git - packages/systemd.git/blob - start_udev
e511184e784adad072fb27a6ce6f1fdd1da63fd5
[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 # default value, if no config present.
24 udev_root="/dev/"
25 sysfs_dir="/sys"
26 udev_db="/dev/.udevdb"
27
28 # don't use udev if sysfs is not mounted.
29 [ -d $sysfs_dir/class ] || exit 1
30 [ -r /proc/mounts ] || exit 1
31 [ -x /sbin/udev ] || exit 1
32 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
33
34 . /etc/rc.d/init.d/functions
35
36 prog=udev
37 bin=/sbin/udev
38 udevd=/sbin/udevd
39 MAKEDEV="/sbin/MAKEDEV"
40
41 make_extra_nodes () {
42         ln -snf /proc/self/fd $udev_root/fd
43         ln -snf /proc/self/fd/0 $udev_root/stdin
44         ln -snf /proc/self/fd/1 $udev_root/stdout
45         ln -snf /proc/self/fd/2 $udev_root/stderr
46         ln -snf /proc/kcore $udev_root/core
47
48         [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
49         [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
50         [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV
51
52         if [ -x $MAKEDEV ]; then
53                 $MAKEDEV -x $( 
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;
56                         done;
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;
61                 );
62                 [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV;
63                 cp -a /etc/udev/devices/* /dev/ >/dev/null 2>&1 || :
64         fi
65 }
66
67 kill_udevd() {
68         if [ -x /sbin/pidof ]; then
69                 pid=`/sbin/pidof -x udevd`
70                 [ -n "$pid" ] && kill $pid
71         fi
72 }
73
74 # we cannot use /usr/bin/find here
75 find_d () {
76         where=$1
77         what=$2
78         found=""
79         for f in $where/*; do
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
84                                 rest="${f#*$what}"
85                                 [ "${rest##*/}" = "$rest" ] && found="$found $f"
86                         fi
87                         found="$found $(find_d $f $what)"
88                 fi
89         done
90         echo "$found"
91 }
92
93 # we cannot use /usr/bin/find here
94 find_f () {
95         where=$1
96         what=$2
97         found=""
98         for f in $where/*; do
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"
103                 fi
104         done
105         [ -n "$found" ] && echo "$found"
106 }
107
108 # call hotplug with the scsi devices
109 scsi_replay () {
110         HOTPLUG="/sbin/udevsend"
111
112         scsi_hosts=$(find_d /sys/devices host\*)
113         SEQNUM=1
114
115         for host in $scsi_hosts; do
116                 [ -d $host ] || continue
117                 devs=$(find_f $host type)
118                 for dev in $devs;do
119                         [ -f $dev ] || continue
120                         DEVPATH=${dev%/type}
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
124                 done
125         done
126         return 0
127 }
128
129 ide_scan() {
130         if [ ! -d /proc/ide ]; then
131                 return 1
132         fi
133         for i in /proc/ide/*/media; do
134                 read media < "$i"
135                 case "$media" in
136                         disk)
137                                 module=ide-disk
138                         ;;
139                         cdrom)
140                                 module=ide-cd
141                         ;;
142                         tape)
143                                 module=ide-tape
144                         ;;
145                         floppy)
146                                 module=ide-floppy
147                         ;;
148                         *)
149                                 module=ide-generic
150                         ;;
151                 esac
152                 /sbin/modprobe $module
153         done
154         return 0
155 }
156
157 export ACTION=add
158 prog=udev
159 ret=0
160 nls "Starting udev"
161
162 # mount the tmpfs on ${udev_root%/}, if not already done
163 LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
164         if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
165                 PTSDIR=$(mktemp -d)
166                 mount --move $udev_root/pts "$PTSDIR"
167         fi
168         if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
169                 SHMDIR=$(mktemp -d)
170                 mount --move $udev_root/shm "$SHMDIR"
171         fi
172         mount -n -o mode=0755 -t tmpfs none "$udev_root"
173         mkdir -m 0755 $udev_root/pts
174         mkdir -m 0755 $udev_root/shm
175         if [ -n "$PTSDIR" ]; then
176                 mount --move "$PTSDIR" $udev_root/pts
177                 rmdir "$PTSDIR"
178         fi
179         if [ -n "$SHMDIR" ]; then
180                 mount --move "$SHMDIR" $udev_root/shm
181                 rmdir "$SHMDIR"
182         fi
183
184         ret=$(( $ret + $? ))
185 }
186
187 rm -fr "$udev_db"
188 make_extra_nodes
189 kill_udevd > "$udev_root/null" 2>&1
190 scsi_replay > "$udev_root/null" 2>&1
191 ret=$(( $ret + $? ))
192 ide_scan > "$udev_root/null" 2>&1
193 /sbin/udevstart 
194 ret=$(( $ret + $? ))
195 [ $ret -eq 0 ] && ok || fail
196 exit 0
This page took 0.031874 seconds and 2 git commands to generate.