--- trunk/udev/udev.rc 2010/08/18 00:57:31 1087 +++ tags/udev-185-r1/udev.rc 2012/06/26 17:12:14 1814 @@ -1,5 +1,5 @@ #!/bin/bash -# $Header: /root/magellan-cvs/src/udev/udev.rc,v 1.2 2010-08-18 00:57:31 niro Exp $ +# $Id$ udev_version() { @@ -8,17 +8,22 @@ if [[ -x /sbin/udev ]] then version=$(/sbin/udev -V) - # 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 elif [[ -x /sbin/udevd ]] then version=$(/sbin/udevd --version) - version=${version##0} - [[ -z ${version} ]] && version=0 + elif [[ -x /lib/udev/udevd ]] + then + version=$(/lib/udev/udevd --version) + elif [[ -x /usr/lib/systemd/systemd-udevd ]] + then + version=$(/usr/lib/systemd/systemd-udev --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}" } @@ -30,29 +35,29 @@ echo CONSOLE=${CONSOLE} > /dev/.udev_populate # populate /dev with devices already found by the kernel - echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." + rc_print " Populating /dev with existing devices through uevents ..." if [[ ${RC_COLDPLUG} = yes ]] then - /sbin/udevadm trigger + udevadm trigger else # do not run any init-scripts - /sbin/udevadm control --env do_not_run_plug_service=1 + udevadm control --env do_not_run_plug_service=1 # only create device nodes - /sbin/udevadm trigger --attr-match=dev + udevadm trigger --attr-match=dev # run persistent-net stuff - /sbin/udevadm trigger --subsystem-match=net + udevadm trigger --subsystem-match=net fi evaluate_retval # loop until everything is finished - echo -e ${COLOREDSTAR}" Letting udev process events ..." - /sbin/udevadm settle --timeout=60 + rc_print " Letting udev process events ..." + udevadm settle --timeout=60 evaluate_retval # unset this variable - /sbin/udevadm control --env do_not_run_plug_service= + udevadm control --env do_not_run_plug_service= rm -f /dev/.udev_populate return 0 @@ -61,7 +66,7 @@ seed_dev() { # seed /dev with some things that we know we need - echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." + rc_print " Seeding /dev with needed nodes ..." ( [ ! -c /dev/console ] && mknod /dev/console c 5 1 [ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1 @@ -92,39 +97,63 @@ # 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 - echo -e ${COLOREDSTAR}"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} udev /dev -o exec,nosuid,mode=0755,size=10M - evaluate_retval + if [[ -z $(grep '[[:space:]]/dev[[:space:]]' /proc/mounts | cut -d ' ' -f2) ]] + 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 and if it is activated - echo -e ${COLOREDSTAR}"Configurating system to use udev ..." + # 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 - echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." - tar -jxpf /lib/udev/state/devices.tar.bz2 -C /dev - evaluate_retval + 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 eeded device nodes with udev + # other needed device nodes with udev seed_dev if [ -e /proc/sys/kernel/hotplug ] then - echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." + rc_print " Using netlink for hotplug events ..." echo "" > /proc/sys/kernel/hotplug evaluate_retval else - echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" + rc_print ${COLYELLOW}" Kernel was not compiled with hotplug support !" print_status failure fi @@ -134,23 +163,27 @@ modprobe -q unix 2>/dev/null fi - echo -e ${COLOREDSTAR}" Starting udevd daemon ..." + rc_print " Starting udevd daemon ..." if [ ${need_redirect} -eq 1 ] then # we need to open fds 0 1 2 - start-stop-daemon --start --exec /sbin/udevd -- --daemon /dev/console 2>/dev/console + start-stop-daemon --start --exec "${udev_daemon}" -- --daemon /dev/console 2>/dev/console else - start-stop-daemon --start --exec /sbin/udevd -- --daemon + start-stop-daemon --start --exec "${udev_daemon}" -- --daemon fi evaluate_retval # write root_link rule - /lib/udev/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 - echo -e ${COLOREDSTAR}" Finializing udev configuration ..." + 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 @@ -162,7 +195,21 @@ stop_devicemanager() { - echo -e ${COLOREDSTAR}"Stopping udevd daemon ..." - start-stop-daemon --stop --exec /sbin/udevd + 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 }