| 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...
|
|---|
| 22 | #
|
|---|
| 23 | # don't use udev if sysfs is not mounted.
|
|---|
| 24 |
|
|---|
| 25 | sysfs_dir=/sys
|
|---|
| 26 |
|
|---|
| 27 | export TZ=/etc/localtime
|
|---|
| 28 |
|
|---|
| 29 | [ -d $sysfs_dir/class ] || exit 1
|
|---|
| 30 | [ -r /proc/mounts ] || exit 1
|
|---|
| 31 | [ -x /sbin/udevd ] || exit 1
|
|---|
| 32 | [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
|
|---|
| 33 | udev_root=${udev_root-/dev}
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | . /etc/init.d/functions
|
|---|
| 37 |
|
|---|
| 38 | umask 0022
|
|---|
| 39 |
|
|---|
| 40 | prog=udev
|
|---|
| 41 | bin=/sbin/udev
|
|---|
| 42 | udevd=/sbin/udevd
|
|---|
| 43 | MAKEDEV="/sbin/MAKEDEV"
|
|---|
| 44 |
|
|---|
| 45 | xargs_simple () {
|
|---|
| 46 | if [ "$1" = "-n" ]; then
|
|---|
| 47 | shift
|
|---|
| 48 | MAXNR="$1"
|
|---|
| 49 | shift
|
|---|
| 50 | else
|
|---|
| 51 | MAXNR=100
|
|---|
| 52 | fi
|
|---|
| 53 | NR=$MAXNR
|
|---|
| 54 | ARGS=""
|
|---|
| 55 | [ -z "$1" ] && set echo
|
|---|
| 56 |
|
|---|
| 57 | while read line; do
|
|---|
| 58 | if [ $NR -gt 0 ]; then
|
|---|
| 59 | ARGS="$ARGS $line"
|
|---|
| 60 | NR=$[$NR - 1]
|
|---|
| 61 | else
|
|---|
| 62 | "$@" $ARGS
|
|---|
| 63 | NR=$MAXNR
|
|---|
| 64 | ARGS="$line"
|
|---|
| 65 | fi
|
|---|
| 66 | done
|
|---|
| 67 | if [ -n "$ARGS" ]; then
|
|---|
| 68 | "$@" $ARGS
|
|---|
| 69 | fi
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | make_extra_nodes () {
|
|---|
| 73 | ln -snf /proc/self/fd $udev_root/fd
|
|---|
| 74 | ln -snf /proc/self/fd/0 $udev_root/stdin
|
|---|
| 75 | ln -snf /proc/self/fd/1 $udev_root/stdout
|
|---|
| 76 | ln -snf /proc/self/fd/2 $udev_root/stderr
|
|---|
| 77 | ln -snf /proc/kcore $udev_root/core
|
|---|
| 78 |
|
|---|
| 79 | [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
|
|---|
| 80 | [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
|
|---|
| 81 | [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV;
|
|---|
| 82 |
|
|---|
| 83 | if [ -x $MAKEDEV ]; then
|
|---|
| 84 | for i in /etc/udev/makedev.d/*.nodes; do
|
|---|
| 85 | if [ -f "$i" ]; then
|
|---|
| 86 | cat "$i" | sed -e 's,#.*,,g' | \
|
|---|
| 87 | xargs_simple -n 100 $MAKEDEV -x
|
|---|
| 88 | fi
|
|---|
| 89 | done
|
|---|
| 90 | fi
|
|---|
| 91 | for devdir in /etc/udev/devices /lib/udev/devices; do
|
|---|
| 92 | [ -d "$devdir" ] || continue
|
|---|
| 93 | pushd $devdir &> "$udev_root/null"
|
|---|
| 94 | set *
|
|---|
| 95 | if [ "$1" != "*" ]; then
|
|---|
| 96 | cp -ar "$@" $udev_root/
|
|---|
| 97 | pushd "$udev_root" &> "$udev_root/null"
|
|---|
| 98 | [ -x /sbin/restorecon ] && /sbin/restorecon "$@"
|
|---|
| 99 | popd &> "$udev_root/null"
|
|---|
| 100 | fi
|
|---|
| 101 | popd &> "$udev_root/null"
|
|---|
| 102 | done
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | kill_udevd() {
|
|---|
| 106 | if [ -x /sbin/pidof ]; then
|
|---|
| 107 | pid=`/sbin/pidof -x udevd`
|
|---|
| 108 | [ -n "$pid" ] && kill $pid
|
|---|
| 109 | fi
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | wait_for_queue() {
|
|---|
| 114 | local timeout=${1:-0}
|
|---|
| 115 | local ret=0
|
|---|
| 116 | if [ $timeout -gt 0 ]; then
|
|---|
| 117 | /sbin/udevsettle --timeout=$timeout
|
|---|
| 118 | else
|
|---|
| 119 | /sbin/udevsettle
|
|---|
| 120 | fi
|
|---|
| 121 | ret=$?
|
|---|
| 122 | if [ $ret -ne 0 ]; then
|
|---|
| 123 | echo -n "Wait timeout. Will continue in the background."
|
|---|
| 124 | fi
|
|---|
| 125 | return $ret;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | export ACTION=add
|
|---|
| 129 | prog=udev
|
|---|
| 130 | ret=0
|
|---|
| 131 | STRING=$"Starting $prog: "
|
|---|
| 132 | # propagate $udev_root from /sys
|
|---|
| 133 | echo -n "$STRING"
|
|---|
| 134 |
|
|---|
| 135 | # mount the tmpfs on ${udev_root%/}, if not already done
|
|---|
| 136 | LANG=C awk "\$2 == \"${udev_root%/}\" && ( \$3 == \"devtmpfs\" || \$3 == \"tmpfs\" ) { exit 1 }" /proc/mounts && {
|
|---|
| 137 | if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
|
|---|
| 138 | PTSDIR=$(mktemp -d)
|
|---|
| 139 | mount --move $udev_root/pts "$PTSDIR"
|
|---|
| 140 | fi
|
|---|
| 141 | if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
|
|---|
| 142 | SHMDIR=$(mktemp -d)
|
|---|
| 143 | mount --move $udev_root/shm "$SHMDIR"
|
|---|
| 144 | fi
|
|---|
| 145 | # First try to mount a devtmpfs on $udev_root
|
|---|
| 146 | mount -n -o mode=0755 -t devtmpfs none "$udev_root" 2>/dev/null \
|
|---|
| 147 | || mount -n -o mode=0755 -t tmpfs none "$udev_root"
|
|---|
| 148 | mkdir -m 0755 $udev_root/pts
|
|---|
| 149 | mkdir -m 0755 $udev_root/shm
|
|---|
| 150 | if [ -n "$PTSDIR" ]; then
|
|---|
| 151 | mount --move "$PTSDIR" $udev_root/pts
|
|---|
| 152 | rmdir "$PTSDIR"
|
|---|
| 153 | fi
|
|---|
| 154 | if [ -n "$SHMDIR" ]; then
|
|---|
| 155 | mount --move "$SHMDIR" $udev_root/shm
|
|---|
| 156 | rmdir "$SHMDIR"
|
|---|
| 157 | fi
|
|---|
| 158 |
|
|---|
| 159 | ret=$[$ret + $?]
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | # returns OK if $1 contains $2
|
|---|
| 163 | strstr() {
|
|---|
| 164 | [ "${1#*$2*}" = "$1" ] && return 1
|
|---|
| 165 | return 0
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | getval() {
|
|---|
| 169 | what=$1
|
|---|
| 170 | shift
|
|---|
| 171 | for arg; do
|
|---|
| 172 | if strstr "$arg" "$what="; then
|
|---|
| 173 | val=${arg#${what}=*}
|
|---|
| 174 | echo $val
|
|---|
| 175 | return 0
|
|---|
| 176 | fi
|
|---|
| 177 | done
|
|---|
| 178 | return 1
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 | make_extra_nodes
|
|---|
| 183 |
|
|---|
| 184 | kill_udevd > "$udev_root/null" 2>&1
|
|---|
| 185 |
|
|---|
| 186 | rm -fr /dev/.udev > "$udev_root/null" 2>&1
|
|---|
| 187 |
|
|---|
| 188 | cmdline=$(cat /proc/cmdline)
|
|---|
| 189 |
|
|---|
| 190 | if [ -f "/sys/class/tty/console/uevent" ]; then
|
|---|
| 191 | # trigger the sorted events
|
|---|
| 192 | echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
|
|---|
| 193 | if strstr "$cmdline" modprobedebug; then
|
|---|
| 194 | touch /dev/.modprobe_debug
|
|---|
| 195 | else
|
|---|
| 196 | rm -f /dev/.modprobe_debug
|
|---|
| 197 | fi
|
|---|
| 198 | /sbin/udevd -d
|
|---|
| 199 | ret=$[$ret + $?]
|
|---|
| 200 | if strstr "$cmdline" udevdebug; then
|
|---|
| 201 | /sbin/udevcontrol log_priority=debug
|
|---|
| 202 | fi
|
|---|
| 203 | /sbin/udevtrigger
|
|---|
| 204 | ret=$[$ret + $?]
|
|---|
| 205 | wait_for_queue $(getval udevtimeout $cmdline)
|
|---|
| 206 | ret=$[$ret + $?]
|
|---|
| 207 | else
|
|---|
| 208 | echo -n " kernel too old for this udev version "
|
|---|
| 209 | /sbin/udevd -d
|
|---|
| 210 | ret=10
|
|---|
| 211 | fi
|
|---|
| 212 |
|
|---|
| 213 | ret=$[$ret + $?]
|
|---|
| 214 | [ $ret -eq 0 ] && success $"$STRING" || failure $"$STRING"
|
|---|
| 215 | echo
|
|---|
| 216 | exit 0
|
|---|