]> git.pld-linux.org Git - packages/systemd.git/blame - start_udev
- rel 2
[packages/systemd.git] / start_udev
CommitLineData
05149ed5
AM
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#
7e0b6014 11# This needs to be run at the earliest possible point in the boot
05149ed5
AM
12# process.
13#
14# Based on the udev init.d script
15#
7e0b6014 16# Thanks go out to the Gentoo developers for proving
05149ed5
AM
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...
940e3565
ER
22
23# default value, if no config present.
12bbae40 24udev_root="/dev"
b44e0a3d 25sysfs_dir="/sys"
d35df3ca 26udevd_timeout=8
940e3565 27
05149ed5 28# don't use udev if sysfs is not mounted.
dda87135 29[ -d $sysfs_dir/class ] || exit 1
05149ed5 30[ -r /proc/mounts ] || exit 1
05149ed5
AM
31[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
32
401263e1 33. /etc/rc.d/init.d/functions
05149ed5
AM
34
35prog=udev
05149ed5 36bin=/sbin/udev
ab4c8ae1 37udevd=/lib/udev/udevd
0d3aa7d6
ER
38# trim traling slash, code expects it not to be there
39udev_root=${udev_root%/}
05149ed5
AM
40
41make_extra_nodes () {
ba060a4b 42 grep '^[^#]' /etc/udev/links.conf | \
43 while read type name arg1; do
7e0b6014
ER
44 [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
45 case "$type" in
46 L) ln -s $arg1 $udev_root/$name ;;
47 D) mkdir -p $udev_root/$name ;;
48 M) mknod -m 600 /dev/$name $arg1 ;;
49 *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
50 esac
ba060a4b 51 done
584c4247
AM
52 [ -d /lib/udev/devices ] && cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
53 [ -d /lib64/udev/devices ] && cp -a /lib64/udev/devices/* /dev/ >/dev/null 2>&1 || :
05149ed5
AM
54}
55
d8394a8d
AM
56kill_udevd() {
57 if [ -x /sbin/pidof ]; then
7e0b6014 58 pid=$(/sbin/pidof -x udevd)
d8394a8d
AM
59 [ -n "$pid" ] && kill $pid
60 fi
61}
62
294ac9d6 63set_hotplug_handler() {
7e0b6014 64 echo "" > /proc/sys/kernel/hotplug
294ac9d6 65}
15874c6e 66
bdd7aa53
ER
67# find subdirs mounted under $udev_root
68get_dev_mounts() {
69 awk -vudev_root="$udev_root/" '
70 BEGIN {
71 len = length(udev_root);
72 }
73
74 substr($2, 1, len) == udev_root {
75 print substr($2, len + 1)
76 }' /proc/mounts
77}
78
05149ed5 79export ACTION=add
6ba94d68
AM
80prog=udev
81ret=0
90d90678
AM
82show "Starting udev"
83busy
294ac9d6 84
12bbae40
ER
85# mount the devtmpfs on $udev_root, if not already done
86awk "\$2 == \"$udev_root\" && \$3 == \"devtmpfs\" { exit 1 }" /proc/mounts && {
3397b77e
ER
87 submounts=$(get_dev_mounts)
88
89 if [ "$submounts" ]; then
90 # mount to temporary location to be able to move submounts
91 # this needs writable TMPDIR:-/tmp, so it won't work in early boot
92 # but fix is simple: use initramfs instead of romfs
93 devdir=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
94 else
95 devdir=$udev_root
96 fi
bdd7aa53
ER
97 mount -n -o mode=0755 -t devtmpfs devtmpfs "$devdir"
98 ret=$(( $ret + $? ))
7e0b6014 99
bdd7aa53 100 # relocate submounts
3397b77e 101 for dir in $submounts; do
bdd7aa53
ER
102 mount -n --move $udev_root/$dir $devdir/$dir
103 ret=$(( $ret + $? ))
104 done
0d219f5b 105
3397b77e
ER
106 if [ "$submounts" ]; then
107 mount -n --move $devdir $udev_root
108 rmdir $devdir
109 fi
6ba94d68 110}
120a2def 111
120a2def 112kill_udevd > "$udev_root/null" 2>&1
ec7c0939 113
7e0b6014
ER
114# Start udevd daemon
115$udevd --daemon
116ret=$(( $ret + $? ))
117
118# Making extra nodes
119make_extra_nodes
120ret=$(( $ret + $? ))
855c97b3 121
7e0b6014
ER
122if [ -f "/sys/class/tty/console/uevent" ]; then
123 # Setting default hotplug handler
855c97b3 124 set_hotplug_handler
125 ret=$(( $ret + $? ))
126
d95b8af3 127 # retrigger all events
7e0b6014 128 # Udev finds it's own way of making this dir
c5ffe681 129 # and making it by hand makes udevsettle
130 # work forever
131 #mkdir -p /dev/.udev/queue
7e0b6014 132 udevadm trigger
15874c6e 133 ret=$(( $ret + $? ))
7e0b6014 134
d95b8af3 135 # wait for the events to finish
7e0b6014 136 udevadm settle
15874c6e 137 ret=$(( $ret + $? ))
de6b464e 138else
855c97b3 139 echo "Kernel too old for this udev version"
de6b464e 140fi
d95b8af3 141
120a2def 142ret=$(( $ret + $? ))
6ba94d68 143[ $ret -eq 0 ] && ok || fail
05149ed5 144exit 0
This page took 0.078619 seconds and 4 git commands to generate.