]> git.pld-linux.org Git - packages/systemd.git/blame - start_udev
up to 246.1
[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 40
8495ab1b
JR
41create_static_nodes() {
42 /sbin/kmod static-nodes --format=tmpfiles | \
43 while read type file mode uid gid age dev ; do
44 case $type in
45 d|D)
46 mkdir -p --mode=$mode $file
47 ;;
48 *)
49 oldIFS=$IFS
50 IFS=":"
51 set -- $dev
52 maj=$1
53 min=$2
54 IFS=$oldIFS
55 mknod --mode=$mode $file $type $maj $min
56 ;;
57 esac
58 [ $uid = "-" ] || chown $uid $file
59 [ $gid = "-" ] || chgrp $gid $file
60 done
61}
62
63make_extra_nodes() {
ba060a4b 64 grep '^[^#]' /etc/udev/links.conf | \
65 while read type name arg1; do
7e0b6014
ER
66 [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
67 case "$type" in
68 L) ln -s $arg1 $udev_root/$name ;;
69 D) mkdir -p $udev_root/$name ;;
70 M) mknod -m 600 /dev/$name $arg1 ;;
71 *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
72 esac
ba060a4b 73 done
584c4247
AM
74 [ -d /lib/udev/devices ] && cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
75 [ -d /lib64/udev/devices ] && cp -a /lib64/udev/devices/* /dev/ >/dev/null 2>&1 || :
05149ed5
AM
76}
77
d8394a8d
AM
78kill_udevd() {
79 if [ -x /sbin/pidof ]; then
7e0b6014 80 pid=$(/sbin/pidof -x udevd)
d8394a8d
AM
81 [ -n "$pid" ] && kill $pid
82 fi
83}
84
294ac9d6 85set_hotplug_handler() {
7e0b6014 86 echo "" > /proc/sys/kernel/hotplug
294ac9d6 87}
15874c6e 88
bdd7aa53
ER
89# find subdirs mounted under $udev_root
90get_dev_mounts() {
91 awk -vudev_root="$udev_root/" '
92 BEGIN {
93 len = length(udev_root);
94 }
95
96 substr($2, 1, len) == udev_root {
97 print substr($2, len + 1)
98 }' /proc/mounts
99}
100
f7cd1a07
ER
101show "Starting udev"; busy
102
05149ed5 103export ACTION=add
6ba94d68
AM
104prog=udev
105ret=0
294ac9d6 106
12bbae40
ER
107# mount the devtmpfs on $udev_root, if not already done
108awk "\$2 == \"$udev_root\" && \$3 == \"devtmpfs\" { exit 1 }" /proc/mounts && {
3397b77e
ER
109 submounts=$(get_dev_mounts)
110
111 if [ "$submounts" ]; then
112 # mount to temporary location to be able to move submounts
113 # this needs writable TMPDIR:-/tmp, so it won't work in early boot
114 # but fix is simple: use initramfs instead of romfs
115 devdir=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
116 else
117 devdir=$udev_root
118 fi
bdd7aa53
ER
119 mount -n -o mode=0755 -t devtmpfs devtmpfs "$devdir"
120 ret=$(( $ret + $? ))
7e0b6014 121
bdd7aa53 122 # relocate submounts
3397b77e 123 for dir in $submounts; do
bdd7aa53
ER
124 mount -n --move $udev_root/$dir $devdir/$dir
125 ret=$(( $ret + $? ))
126 done
0d219f5b 127
3397b77e
ER
128 if [ "$submounts" ]; then
129 mount -n --move $devdir $udev_root
130 rmdir $devdir
131 fi
6ba94d68 132}
120a2def 133
120a2def 134kill_udevd > "$udev_root/null" 2>&1
ec7c0939 135
8495ab1b
JR
136# Create required static device nodes for the current kernel
137create_static_nodes
138
7e0b6014 139# Start udevd daemon
f7cd1a07
ER
140$udevd --daemon; rc=$?
141test $rc -eq 0 && ok || fail
142ret=$(( $ret + $rc ))
7e0b6014
ER
143
144# Making extra nodes
f7cd1a07
ER
145show "Setup extra nodes"; busy
146make_extra_nodes; rc=$?
147test $rc -eq 0 && ok || fail
148ret=$(( $ret + $rc ))
855c97b3 149
8135e00e 150if [ -f /sys/class/tty/console/uevent ]; then
7e0b6014 151 # Setting default hotplug handler
855c97b3 152 set_hotplug_handler
153 ret=$(( $ret + $? ))
154
d95b8af3 155 # retrigger all events
8135e00e 156 show "Retrigger subsystems events"; busy
f7cd1a07
ER
157 /sbin/udevadm trigger --type=subsystems --action=add; rc=$?
158 test $rc -eq 0 && ok || fail
159 ret=$(( $ret + $rc ))
160
8135e00e 161 show "Retrigger devices events"; busy
f7cd1a07
ER
162 /sbin/udevadm trigger --type=devices --action=add; rc=$?
163 test $rc -eq 0 && ok || fail
164 ret=$(( $ret + $rc ))
7e0b6014 165
d95b8af3 166 # wait for the events to finish
f7cd1a07
ER
167 show "udevadm settle"; busy
168 /sbin/udevadm settle; rc=$?
169 test $rc -eq 0 && ok || fail
170 ret=$(( $ret + $rc ))
de6b464e 171else
855c97b3 172 echo "Kernel too old for this udev version"
de6b464e 173fi
d95b8af3 174
f7cd1a07 175exit $ret
This page took 0.120281 seconds and 4 git commands to generate.