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