slackware-current/source/a/udev/config/rc.d/rc.udev.new
Patrick J Volkerding b76270bf9e Slackware 13.1
Wed May 19 08:58:23 UTC 2010
Slackware 13.1 x86_64 stable is released!
Lots of thanks are due -- see the RELEASE_NOTES and the rest of the
ChangeLog for credits.  The ISOs are on their way to replication,
a 6 CD-ROM 32-bit set and a dual-sided 32-bit/64-bit x86/x86_64 DVD.
We are taking pre-orders now at store.slackware.com, and offering
a discount if you sign up for a subscription.  Consider picking up
a copy to help support the project.  Thanks again to the Slackware
community for testing, contributing, and generally holding us to a
high level of quality.  :-)
Enjoy!
2018-05-31 22:43:05 +02:00

169 lines
5.3 KiB
Bash

#!/bin/sh
# This is a script to initialize udev, which populates the /dev
# directory with device nodes, scans for devices, loads the
# appropriate kernel modules, and configures the devices.
PATH="/sbin:/bin"
OPT=""
. /etc/udev/udev.conf
# remove trailing slash from udev_root
UDEV_ROOT=$(echo "${udev_root}" |sed 's/\/*$//')
check_mounted() {
grep -E -q "^[^[:space:]]+ $1 $2" /proc/mounts
return $?
}
mount_devpts() {
if ! check_mounted $UDEV_ROOT/pts devpts ; then
mkdir $UDEV_ROOT/pts 2> /dev/null
mount -n -o mode=0620,gid=5 -t devpts devpts $UDEV_ROOT/pts
fi
}
case "$1" in
start)
# Sanity check #1, udev requires that the kernel support tmpfs:
if ! grep -wq tmpfs /proc/filesystems ; then
echo "Sorry, but you need tmpfs support in the kernel to use udev."
echo
echo "FATAL: Refusing to run /etc/rc.d/rc.udev."
exit 1
fi
# Sanity check #2, make sure that a 2.6.x kernel is new enough:
if [ "$(uname -r | cut -f 1,2 -d .)" = "2.6" ]; then
if [ "$(uname -r | cut -f 3 -d . | sed 's/[^[:digit:]].*//')" -lt "27" ]; then
echo "Sorry, but you need a 2.6.27+ kernel to use udev."
echo "Your kernel version is only $(uname -r)."
echo
echo "FATAL: Refusing to run /etc/rc.d/rc.udev."
exit 1
fi
fi
# Sanity check #3, make sure the udev package was not removed. If udevd
# is not there, this will also shut off this script to prevent further
# problems:
if [ ! -x /sbin/udevd ]; then
chmod 644 /etc/rc.d/rc.udev
echo "No udevd daemon found."
echo "Turning off udev: chmod 644 /etc/rc.d/rc.udev"
echo "FATAL: Refusing to run /etc/rc.d/rc.udev."
exit 1
fi
# Disable hotplug helper since udevd listens to netlink:
if [ -e /proc/sys/kernel/hotplug ]; then
echo "" > /proc/sys/kernel/hotplug
fi
if grep -qw devtmpfs /proc/filesystems ; then
if ! check_mounted $UDEV_ROOT devtmpfs ; then
# umount shm if needed
check_mounted $UDEV_ROOT/shm tmpfs && umount -l $UDEV_ROOT/shm
# Umount pts if needed, we will remount it later:
check_mounted $UDEV_ROOT/pts devpts && umount -l $UDEV_ROOT/pts
# Mount tmpfs on $UDEV_ROOT:
mount -n -t devtmpfs devtmpfs $UDEV_ROOT
fi
else
# Mount tmpfs on $UDEV_ROOT:
if ! check_mounted $UDEV_ROOT tmpfs ; then
# umount shm if needed
check_mounted $UDEV_ROOT/shm tmpfs && umount -l $UDEV_ROOT/shm
# Umount pts if needed, we will remount it later:
check_mounted $UDEV_ROOT/pts devpts && umount -l $UDEV_ROOT/pts
# Mount tmpfs on $UDEV_ROOT:
# the -n is because we don't want $UDEV_ROOT umounted when
# someone (rc.[06]) calls umount -a
mount -n -o mode=0755 -t tmpfs tmpfs $UDEV_ROOT
fi
fi
# Mount devpts
mount_devpts
# Start udevd.
/sbin/udevd --daemon 2>/dev/null
# If udevd was already running, then it will return !=0 exit code,
# so we'll try to re-run failed events
if [ $? != 0 ]; then
OPT="--type=failed $OPT"
( cd ${UDEV_ROOT}/.udev
for TMPFILE in tmp-rules-*.rules ; do
mv $TMPFILE /etc/udev/rules.d/${TMPFILE/tmp-rules--/} 2>/dev/null
done
)
else # udev is just now being started, so we'll do some initial setup:
# Set STARTUP=1 in the environment
/sbin/udevadm control --property=STARTUP=1
# Set OPT="--action=add" to generate add events on coldplug
OPT="--action=add"
# Add the static nodes to $UDEV_ROOT:
cp --preserve=all --recursive --remove-destination /lib/udev/devices/* $UDEV_ROOT
# Create rootdev rules
DEVICENUMBER=$( /bin/stat -c %d / )
MAJORNUMBER=$(($DEVICENUMBER / 256))
MINORNUMBER=$(($DEVICENUMBER % 256))
echo 'ACTION=="add|change", SUBSYSTEM=="block", ENV{MAJOR}=="'$MAJORNUMBER'", ENV{MINOR}=="'$MINORNUMBER'", SYMLINK+="root"' > /dev/.udev/rules.d/61-dev-root-link.rules
fi
echo "Triggering udev events: /sbin/udevadm trigger $OPT"
# Call udevtrigger and udevsettle to do the device configuration:
/sbin/udevadm trigger $OPT && /sbin/udevadm settle --timeout=120
# Unset STARTUP=1 in the environment
/sbin/udevadm control --property=STARTUP=
;;
stop)
echo "Stopping udevd is STRONGLY discouraged and not supported."
echo "If you are sure you want to do this, use 'force-stop' instead."
;;
force-stop)
echo "Stopping udevd"
if [ -e /proc/sys/kernel/hotplug ]; then
echo /sbin/hotplug > /proc/sys/kernel/hotplug
fi
killall udevd
;;
restart)
echo "Restarting udevd is STRONGLY discouraged and not supported."
echo "If you are sure you want to do this, use 'force-restart' instead."
;;
force-restart)
echo "Restarting udevd"
killall udevd
sleep 5
udevd --daemon
;;
reload)
echo "Reloading udev rules"
udevadm control --reload-rules
cp --preserve=all --recursive --update /lib/udev/devices/* $UDEV_ROOT
;;
force-reload)
echo "Updating all available device nodes in $UDEV_ROOT"
udevadm control --reload-rules
rm -rf $UDEV_ROOT/.udev $UDEV_ROOT/disk
cp --preserve=all --recursive --update /lib/udev/devices/* $UDEV_ROOT
;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload}"
exit 1
;;
esac