4
# Required-Start: mountkernfs
5
# Required-Stop: umountroot
8
# Short-Description: Start systemd-udevd, populate /dev and load drivers.
13
DAEMON="/lib/systemd/systemd-udevd"
14
DESC="hotplug events dispatcher"
15
PIDFILE="/run/udev.pid"
16
CTRLFILE="/run/udev/control"
17
OMITDIR="/run/sendsigs.omit.d"
19
# we need to unmount /dev/pts/ and remount it later over the devtmpfs
21
if mountpoint -q /dev/pts/; then
22
umount -n -l /dev/pts/
25
if mountpoint -q /dev/shm/; then
26
umount -n -l /dev/shm/
30
# mount a devtmpfs over /dev, if somebody did not already do it
32
if grep -E -q "^[^[:space:]]+ /dev devtmpfs" /proc/mounts; then
33
mount -n -o remount,nosuid,size=$tmpfs_size,mode=0755 -t devtmpfs devtmpfs /dev
37
if ! mount -n -o nosuid,size=$tmpfs_size,mode=0755 -t devtmpfs devtmpfs /dev; then
38
log_failure_msg "udev requires devtmpfs support, not started"
45
create_dev_makedev() {
46
if [ -e /sbin/MAKEDEV ]; then
47
ln -sf /sbin/MAKEDEV /dev/MAKEDEV
49
ln -sf /bin/true /dev/MAKEDEV
53
# shell version of /usr/bin/tty
55
[ -x /bin/readlink ] || return 0
56
[ -e /proc/self/fd/0 ] || return 0
57
readlink --silent /proc/self/fd/0 || true
60
warn_if_interactive() {
61
if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then
66
if [ -z "$TTY" -o "$TTY" = "/dev/console" -o "$TTY" = "/dev/null" ]; then
70
printf "\n\n\nIt has been detected that the command\n\n\t$0 $*\n\n"
71
printf "has been run from an interactive shell.\n"
72
printf "It will probably not do what you expect, so this script will wait\n"
73
printf "60 seconds before continuing. Press ^C to stop it.\n"
74
printf "RUNNING THIS COMMAND IS HIGHLY DISCOURAGED!\n\n\n\n"
79
[ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
80
[ -x /bin/kmod ] || return 0
82
/bin/kmod static-nodes --format=tmpfiles --output=/proc/self/fd/1 | \
83
while read type name mode uid gid age arg; do
84
[ -e $name ] && continue
86
c|b|c!|b!) mknod -m $mode $name $type $(echo $arg | sed 's/:/ /') ;;
88
*) echo "unparseable line ($type $name $mode $uid $gid $age $arg)" >&2 ;;
91
if [ -x /sbin/restorecon ]; then
92
/sbin/restorecon $name
98
##############################################################################
101
[ -x $DAEMON ] || exit 0
106
if [ -e /etc/udev/udev.conf ]; then
107
. /etc/udev/udev.conf
110
. /lib/lsb/init-functions
112
if [ ! -e /proc/filesystems ]; then
113
log_failure_msg "udev requires a mounted procfs, not started"
117
if ! grep -q '[[:space:]]devtmpfs$' /proc/filesystems; then
118
log_failure_msg "udev requires devtmpfs support, not started"
122
if [ ! -d /sys/class/ ]; then
123
log_failure_msg "udev requires a mounted sysfs, not started"
127
if [ ! -w /sys ]; then
128
log_warning_msg "udev does not support containers, not started"
132
if [ "$(stat -c %d/%i /)" != "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then
133
# the devicenumber/inode pair of / is not the same as that of /sbin/init's
134
# root, so we *are* in a chroot.
135
log_warning_msg "A chroot environment has been detected, udev not started."
139
if [ -d /sys/class/mem/null -a ! -L /sys/class/mem/null ] || \
140
[ -e /sys/block -a ! -e /sys/class/block ]; then
141
log_warning_msg "CONFIG_SYSFS_DEPRECATED must not be selected"
142
log_warning_msg "Booting will continue in 30 seconds but many things will be broken"
146
# When modifying this script, do not forget that between the time that the
147
# new /dev has been mounted and udevadm trigger has been run there will be
148
# no /dev/null. This also means that you cannot use the "&" shell command.
152
if [ ! -e "/run/udev/" ]; then
156
if [ -w /sys/kernel/uevent_helper ]; then
157
echo > /sys/kernel/uevent_helper
160
if ! mountpoint -q /dev/; then
163
[ -d /proc/1 ] || mount -n /proc
168
# clean up parts of the database created by the initramfs udev
169
udevadm info --cleanup-db
171
# set the SELinux context for devices created in the initramfs
172
[ -x /sbin/restorecon ] && /sbin/restorecon -R /dev
174
log_daemon_msg "Starting $DESC" "$NAME"
175
if start-stop-daemon --start --name $NAME --user root --quiet \
176
--pidfile $PIDFILE --exec $DAEMON --background --make-pidfile \
178
# prevents udevd to be killed by sendsigs (see #791944)
180
ln -sf $PIDFILE $OMITDIR/$NAME
184
log_warning_msg "Waiting 15 seconds and trying to continue anyway"
188
log_action_begin_msg "Synthesizing the initial hotplug events (subsystems)"
189
if udevadm trigger --type=subsystems --action=add; then
190
log_action_end_msg $?
192
log_action_end_msg $?
194
log_action_begin_msg "Synthesizing the initial hotplug events (devices)"
195
if udevadm trigger --type=devices --action=add; then
196
log_action_end_msg $?
198
log_action_end_msg $?
203
# wait for the systemd-udevd childs to finish
204
log_action_begin_msg "Waiting for /dev to be fully populated"
205
if udevadm settle; then
208
log_action_end_msg 0 'timeout'
213
log_daemon_msg "Stopping $DESC" "$NAME"
214
if start-stop-daemon --stop --name $NAME --user root --quiet \
215
--pidfile $PIDFILE --remove-pidfile --oknodo --retry 5; then
216
# prevents cryptsetup/dmsetup hangs (see #791944)
225
log_daemon_msg "Stopping $DESC" "$NAME"
226
if start-stop-daemon --stop --name $NAME --user root --quiet \
227
--pidfile $PIDFILE --remove-pidfile --oknodo --retry 5; then
228
# prevents cryptsetup/dmsetup hangs (see #791944)
232
log_end_msg $? || true
235
log_daemon_msg "Starting $DESC" "$NAME"
236
if start-stop-daemon --start --name $NAME --user root --quiet \
237
--pidfile $PIDFILE --exec $DAEMON --background --make-pidfile \
239
# prevents udevd to be killed by sendsigs (see #791944)
241
ln -sf $PIDFILE $OMITDIR/$NAME
249
udevadm control --reload-rules
253
status_of_proc $DAEMON $NAME && exit 0 || exit $?
257
echo "Usage: /etc/init.d/udev {start|stop|restart|reload|force-reload|status}" >&2