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