chiark / gitweb /
[PATCH] Minor POSIX-fixes for udev
[elogind.git] / extras / 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
24 . /etc/udev/udev.conf
25
26 prog=udev
27 sysfs_dir=/sys
28 bin=/sbin/udev
29 udevd=/sbin/udevd
30
31 run_udev () {
32         export ACTION=add
33         export UDEV_NO_SLEEP=1
34
35         # handle block devices and their partitions
36         for i in ${sysfs_dir}/block/*; do
37                 # add each drive
38                 export DEVPATH=${i#${sysfs_dir}}
39                 echo "$DEVPATH"
40                 $bin block
41
42                 # add each partition, on each device
43                 for j in $i/*; do
44                         if [ -f $j/dev ]; then
45                                 export DEVPATH=${j#${sysfs_dir}}
46                                 echo "$DEVPATH"
47                                 $bin block
48                         fi
49                 done
50         done
51         # all other device classes
52         for i in ${sysfs_dir}/class/*; do
53                 for j in $i/*; do
54                         if [ -f $j/dev ]; then
55                                 export DEVPATH=${j#${sysfs_dir}}
56                                 CLASS=`echo ${i#${sysfs_dir}} | \
57                                         cut --delimiter='/' --fields=3-`
58                                 echo "$DEVPATH"
59                                 $bin $CLASS
60                         fi
61                 done
62         done
63         return 0
64 }
65
66 make_extra_nodes () {
67         # there are a few things that sysfs does not export for us.
68         # these things go here (and remember to remove them in 
69         # remove_extra_nodes()
70         #
71         # Thanks to Gentoo for the initial list of these.
72         ln -snf /proc/self/fd $udev_root/fd
73         ln -snf /proc/self/fd/0 $udev_root/stdin
74         ln -snf /proc/self/fd/1 $udev_root/stdout
75         ln -snf /proc/self/fd/2 $udev_root/stderr
76         ln -snf /proc/kcore $udev_root/core
77
78         mkdir $udev_root/pts
79         mkdir $udev_root/shm
80 }
81
82 # don't use udev if sysfs is not mounted.
83 if [ ! -d $sysfs_dir/block ]; then
84         exit 1
85 fi
86
87 echo "mounting... ramfs at $udev_root"
88 mount -n -t ramfs none $udev_root
89
90 # propogate /udev from /sys
91 echo "Creating initial udev device nodes:"
92
93 # You can use the shell scripts above by calling run_udev or execute udevstart
94 # which does the same thing, but much faster by not using shell.  
95 #  only comment out one of the following lines.
96 #run_udev
97 /sbin/udevstart
98
99 echo "making extra nodes"
100 make_extra_nodes
101
102 echo "udev startup is finished!"
103 exit 0