chiark / gitweb /
[PATCH] add start_udev init script.
[elogind.git] / extras / start_udev
1 #! /bin/bash
2 #
3 # start_udev
4 #
5 # script to initialize /dev by using udev.
6 #
7 # This needs to be run at the earliest possible point in the boot 
8 # process.
9 #
10 # Based on the udev init.d script
11 #
12
13 . /etc/udev/udev.conf
14
15 prog=udev
16 sysfs_dir=/sys
17 bin=/sbin/udev
18 udevd=/sbin/udevd
19
20 run_udev () {
21         # handle block devices and their partitions
22         for i in ${sysfs_dir}/block/*; do
23                 # add each drive
24                 export DEVPATH=${i#${sysfs_dir}}
25                 echo "$DEVPATH"
26                 $bin block
27
28                 # add each partition, on each device
29                 for j in $i/*; do
30                         if [ -f $j/dev ]; then
31                                 export DEVPATH=${j#${sysfs_dir}}
32                                 echo "$DEVPATH"
33                                 $bin block
34                         fi
35                 done
36         done
37         # all other device classes
38         for i in ${sysfs_dir}/class/*; do
39                 for j in $i/*; do
40                         if [ -f $j/dev ]; then
41                                 export DEVPATH=${j#${sysfs_dir}}
42                                 CLASS=`echo ${i#${sysfs_dir}} | \
43                                         cut --delimiter='/' --fields=3-`
44                                 echo "$DEVPATH"
45                                 $bin $CLASS
46                         fi
47                 done
48         done
49         return 0
50 }
51
52 make_extra_nodes () {
53         # there are a few things that sysfs does not export for us.
54         # these things go here (and remember to remove them in 
55         # remove_extra_nodes()
56         #
57         # Thanks to Gentoo for the initial list of these.
58         ln -snf /proc/self/fd $udev_root/fd
59         ln -snf /proc/self/fd/0 $udev_root/stdin
60         ln -snf /proc/self/fd/1 $udev_root/stdout
61         ln -snf /proc/self/fd/2 $udev_root/stderr
62         ln -snf /proc/kcore $udev_root/core
63
64         mkdir $udev_root/pts
65         mkdir $udev_root/shm
66 }
67
68 # don't use udev if sysfs is not mounted.
69 if [ ! -d $sysfs_dir/block ]; then
70         exit 1
71 fi
72
73 echo "mounting... ramfs at $udev_root"
74 mount -n -t ramfs none $udev_root
75
76 # We want to start udevd ourselves if it isn't already running.  This
77 # lets udevd run at a sane nice level...
78 echo "starting udevd"
79 $udevd &
80
81 # propogate /udev from /sys
82 export ACTION=add
83 export UDEV_NO_SLEEP=1
84 echo "Creating initial udev device nodes:"
85 run_udev
86
87 echo "making extra nodes"
88 make_extra_nodes
89
90 echo "udev startup is finished!"
91 exit 0