#!/bin/bash # $Id$ udev_version() { local version=0 if [[ -x /sbin/udev ]] then version=$(/sbin/udev -V) elif [[ -x /sbin/udevd ]] then version=$(/sbin/udevd --version) elif [[ -x /lib/udev/udevd ]] then version=$(/lib/udev/udevd --version) elif [[ -x /usr/lib/systemd/systemd-udevd ]] then version=$(/usr/lib/systemd/systemd-udevd --version) fi # We need it without a leading '0', else bash do the wrong thing version=${version##0} # Older udev's will print nothing [[ -z ${version} ]] && version=0 echo "${version}" } populate_udev() { local opts # populate /dev with devices already found by the kernel rc_print " Populating /dev with existing devices through uevents ..." if [[ ${RC_COLDPLUG} = yes ]] then udevadm trigger else # do not run any init-scripts udevadm control --property=do_not_run_plug_service=1 udevadm trigger --type=subsystems --action=add udevadm trigger --type=devices --action=add fi evaluate_retval # unset this variable udevadm control --property=do_not_run_plug_service= return 0 } seed_dev() { # seed /dev with some things that we know we need rc_print " Seeding /dev with needed nodes ..." ( [ ! -c /dev/console ] && mknod -m 600 /dev/console c 5 1 [ ! -c /dev/tty1 ] && mknod -m 620 /dev/tty1 c 4 1 [ ! -c /dev/tty ] && mknod -m 666 /dev/tty c 5 0 [ ! -c /dev/null ] && mknod -m 666 /dev/null c 1 3 # create kmsg too, so udev can add its start-message to dmesg [ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11 # create problematic directories mkdir -p /dev/pts /dev/shm ) evaluate_retval } # main function start_devicemanager() { local udev_prefix="" local udev_daemon="" # get the right daemon and prefix for newer udev/systemd-udev installations if [ -x /sbin/udevd ] then udev_daemon="/sbin/udevd" udev_prefix="" elif [ -x /lib/udev/udevd ] then udev_daemon="/lib/udev/udevd" udev_prefix="" elif [ -x /usr/lib/systemd/systemd-udevd ] then udev_daemon="/usr/lib/systemd/systemd-udevd" udev_prefix="/usr" fi # check if /dev/console exists outside tmpfs [ -c /dev/console ] ; need_redirect=$? # create a ramdisk for populating udev if [[ -z $(grep '[[:space:]]/dev[[:space:]]' /proc/self/mountinfo) ]] then rc_print "Mounting udev at /dev ..." # many video drivers needed exec access fstype=ramfs # tmpfs was suggested by Greg Kroah-Hartman kernel_supports_fs tmpfs && fstype=tmpfs # mount devtmpfs if supported kernel_supports_fs devtmpfs && fstype=devtmpfs mount -n -t ${fstype} dev /dev -o exec,nosuid,mode=0755,size=10M evaluate_retval fi # if a device tarball exists load it but only if it is activated in the config rc_print "Configurating system to use udev ..." if [[ ${RC_DEVICE_TARBALL} = yes ]] then if [[ -f ${udev_prefix}/lib/udev/state/devices.tar.bz2 ]] then rc_print " Populating /dev with saved device nodes ..." tar -jxpf ${udev_prefix}/lib/udev/state/devices.tar.bz2 -C /dev evaluate_retval fi fi # other needed device nodes with udev seed_dev if [ -e /proc/sys/kernel/hotplug ] then rc_print " Using netlink for hotplug events ..." echo "" > /proc/sys/kernel/hotplug evaluate_retval else rc_print ${COLYELLOW}" Kernel was not compiled with hotplug support !" print_status failure fi # load unix domain sockets if built as module if [ -e /proc/modules ] then modprobe -q unix 2>/dev/null fi rc_print " Starting udevd daemon ..." if [ ${need_redirect} -eq 1 ] then # we need to open fds 0 1 2 start-stop-daemon --start --exec "${udev_daemon}" -- --daemon /dev/console 2>/dev/console else start-stop-daemon --start --exec "${udev_daemon}" -- --daemon fi evaluate_retval # write root_link rule if [ -x ${udev_prefix}/lib/udev/write_root_link_rule ] then ${udev_prefix}/lib/udev/write_root_link_rule fi # populate udev device nodes populate_udev # create nodes that udev can't rc_print " Finializing udev configuration ..." [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null print_status success # same thing as /dev/.devfsd touch /dev/.udev } stop_devicemanager() { local udev_daemon="" # get the right daemon and prefix for newer udev/systemd-udev installations if [ -x /sbin/udevd ] then udev_daemon="/sbin/udevd" elif [ -x /lib/udev/udevd ] then udev_daemon="/lib/udev/udevd" elif [ -x /usr/lib/systemd/systemd-udevd ] then udev_daemon="/usr/lib/systemd/systemd-udevd" fi rc_print "Stopping udevd daemon ..." start-stop-daemon --stop --exec "${udev_daemon}" evaluate_retval }