]> git.pld-linux.org Git - packages/systemd.git/blame - start_udev
- add tmpfs compatibility for older kernels
[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#
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...
940e3565
ER
22
23# default value, if no config present.
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
05149ed5
AM
38
39make_extra_nodes () {
ba060a4b 40 grep '^[^#]' /etc/udev/links.conf | \
41 while read type name arg1; do
42 [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
43 case "$type" in
44 L) ln -s $arg1 $udev_root/$name ;;
45 D) mkdir -p $udev_root/$name ;;
15874c6e 46 M) mknod -m 600 /dev/$name $arg1 ;;
ba060a4b 47 *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
48 esac
49 done
584c4247
AM
50 [ -d /lib/udev/devices ] && cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
51 [ -d /lib64/udev/devices ] && cp -a /lib64/udev/devices/* /dev/ >/dev/null 2>&1 || :
05149ed5
AM
52}
53
d8394a8d
AM
54kill_udevd() {
55 if [ -x /sbin/pidof ]; then
56 pid=`/sbin/pidof -x udevd`
57 [ -n "$pid" ] && kill $pid
58 fi
59}
60
294ac9d6 61set_hotplug_handler() {
de6b464e 62 echo "" > /proc/sys/kernel/hotplug
294ac9d6 63}
15874c6e 64
05149ed5 65export ACTION=add
6ba94d68
AM
66prog=udev
67ret=0
90d90678
AM
68show "Starting udev"
69busy
294ac9d6 70
b7a23670
JR
71# mount the devtmpfs (tmpfs on older kernels) on ${udev_root%/}, if not already done
72LANG=C awk "\$2 == \"${udev_root%/}\" && ( \$3 == \"tmpfs\" || \$3 == \"devtmpfs\" ) { exit 1 }" /proc/mounts && {
de6b464e 73 if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
74 PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
84853a2e
ER
75 mount --move $udev_root/pts "$PTSDIR"
76 fi
77 if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
5cccdef0 78 SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
84853a2e
ER
79 mount --move $udev_root/shm "$SHMDIR"
80 fi
b7a23670
JR
81 if grep -qs devtmpfs /proc/filesystems; then
82 mount -n -o mode=0755 -t devtmpfs devtmpfs "$udev_root"
83 else
84 mount -n -o mode=0755 -t tmpfs none "$udev_root"
85 fi
84853a2e
ER
86 mkdir -m 0755 $udev_root/pts
87 mkdir -m 0755 $udev_root/shm
88 if [ -n "$PTSDIR" ]; then
89 mount --move "$PTSDIR" $udev_root/pts
90 rmdir "$PTSDIR"
91 fi
92 if [ -n "$SHMDIR" ]; then
93 mount --move "$SHMDIR" $udev_root/shm
94 rmdir "$SHMDIR"
95 fi
96
97 ret=$(( $ret + $? ))
6ba94d68 98}
120a2def 99
120a2def 100kill_udevd > "$udev_root/null" 2>&1
ec7c0939 101
de6b464e 102 # Start udevd daemon
ab4c8ae1 103 $udevd --daemon
15874c6e 104 ret=$(( $ret + $? ))
de6b464e 105
15874c6e 106 # Making extra nodes
107 make_extra_nodes
108 ret=$(( $ret + $? ))
d95b8af3 109
855c97b3 110if [ -f "/sys/class/tty/console/uevent" ]; then
111
112 # Setting default hotplug handler
113 set_hotplug_handler
114 ret=$(( $ret + $? ))
115
d95b8af3 116 # retrigger all events
c5ffe681 117 # Udev find's it's own way of making this dir
118 # and making it by hand makes udevsettle
119 # work forever
120 #mkdir -p /dev/.udev/queue
ebe93507 121 udevadm trigger
15874c6e 122 ret=$(( $ret + $? ))
123
d95b8af3 124 # wait for the events to finish
ebe93507 125 udevadm settle
15874c6e 126 ret=$(( $ret + $? ))
de6b464e 127else
855c97b3 128 echo "Kernel too old for this udev version"
de6b464e 129fi
d95b8af3 130
120a2def 131ret=$(( $ret + $? ))
6ba94d68 132[ $ret -eq 0 ] && ok || fail
05149ed5 133exit 0
This page took 0.108186 seconds and 4 git commands to generate.