Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

452 Commits   2 Branches   1 Tag
     5         kx #!/bin/sh
     5         kx # This is a script to initialize udev, which populates the /dev
     5         kx # directory with device nodes, scans for devices, loads the
     5         kx # appropriate kernel modules, and configures the devices.
     5         kx 
     5         kx PATH="/sbin:/bin"
     5         kx 
     5         kx check_mounted() {
     5         kx   grep -E -q "^[^[:space:]]+ $1 $2" /proc/mounts
     5         kx   return $?
     5         kx }
     5         kx 
     5         kx mount_devpts() {
     5         kx   if ! check_mounted /dev/pts devpts ; then
     5         kx     mkdir /dev/pts 2> /dev/null
     5         kx     mount -n -o mode=0620,gid=5 -t devpts devpts /dev/pts
     5         kx   fi
     5         kx }
     5         kx 
     5         kx mount_devshm() {
     5         kx   if ! check_mounted /dev/shm tmpfs ; then
     5         kx     mkdir /dev/shm 2> /dev/null
     5         kx     mount /dev/shm
     5         kx   fi
     5         kx }
     5         kx 
     5         kx case "$1" in
     5         kx   start)
     5         kx     # Sanity check #1, udev requires that the kernel support tmpfs:
     5         kx     if ! grep -wq tmpfs /proc/filesystems ; then
     5         kx       echo "Sorry, but you need tmpfs support in the kernel to use udev."
     5         kx       echo
     5         kx       echo "FATAL:  Refusing to run /etc/rc.d/rc.udev."
     5         kx       exit 1
     5         kx     fi
     5         kx 
     5         kx     # Sanity check #2, make sure that a 2.6.x kernel is new enough:
     5         kx     if [ "$(uname -r | cut -f 1,2 -d .)" = "2.6" ]; then
     5         kx       if [ "$(uname -r | cut -f 3 -d . | sed 's/[^[:digit:]].*//')" -lt "32" ]; then
     5         kx         echo "Sorry, but you need a 2.6.32+ kernel to use this udev."
     5         kx         echo "Your kernel version is only $(uname -r)."
     5         kx         echo
     5         kx         echo "FATAL:  Refusing to run /etc/rc.d/rc.udev."
     5         kx         exit 1
     5         kx       fi
     5         kx     fi
     5         kx 
     5         kx     # Sanity check #3, make sure the udev package was not removed.  If udevd
     5         kx     # is not there, this will also shut off this script to prevent further
     5         kx     # problems:
     5         kx     if [ ! -x /sbin/udevd ]; then
     5         kx       chmod 0644 /etc/rc.d/rc.udev
     5         kx       echo "No udevd daemon found."
     5         kx       echo "Turning off udev:  chmod 644 /etc/rc.d/rc.udev"
     5         kx       echo "FATAL:  Refusing to run /etc/rc.d/rc.udev."
     5         kx       exit 1
     5         kx     fi
     5         kx 
     5         kx     # Disable hotplug helper since udevd listens to netlink:
     5         kx     if [ -e /proc/sys/kernel/hotplug ]; then
     5         kx       echo "" > /proc/sys/kernel/hotplug
     5         kx     fi
     5         kx 
     5         kx     if grep -qw devtmpfs /proc/filesystems ; then
     5         kx       if ! check_mounted /dev devtmpfs ; then
     5         kx         # umount shm if needed
     5         kx         check_mounted /dev/shm tmpfs && umount -l /dev/shm
     5         kx 
     5         kx         # Umount pts if needed, we will remount it later:
     5         kx         check_mounted /dev/pts devpts && umount -l /dev/pts
     5         kx 
     5         kx         # Mount tmpfs on /dev:
     5         kx         mount -n -t devtmpfs -o size=8M devtmpfs /dev
     5         kx       fi
     5         kx     else
     5         kx       # Mount tmpfs on /dev:
     5         kx       if ! check_mounted /dev tmpfs ; then
     5         kx         # umount shm if needed
     5         kx         check_mounted /dev/shm tmpfs && umount -l /dev/shm
     5         kx 
     5         kx         # Umount pts if needed, we will remount it later:
     5         kx         check_mounted /dev/pts devpts && umount -l /dev/pts
     5         kx 
     5         kx         # Mount tmpfs on /dev:
     5         kx         # the -n is because we don't want /dev umounted when
     5         kx         # someone (rc.[06]) calls umount -a
     5         kx         mount -n -o mode=0755 -t tmpfs -o size=8M tmpfs /dev
     5         kx       fi
     5         kx     fi
     5         kx 
     5         kx     # Mount devpts
     5         kx     mount_devpts
     5         kx     mount_devshm
     5         kx 
     5         kx     if ! /sbin/pidof udevd 1>/dev/null 2>/dev/null; then # start udevd
     5         kx       echo "Creating static nodes in /dev."
     5         kx       kmod static-nodes -f tmpfiles --output /run/static-nodes
     5         kx       grep "^d\ " /run/static-nodes | while read line ; do
     5         kx         mkdir -p -m $(echo $line | cut -f 3 -d ' ') $(echo $line | cut -f 2 -d ' ')
     5         kx       done
     5         kx       grep -v "^d\ " /run/static-nodes | while read line ; do
     5         kx         mknod -m $(echo $line | cut -f 3 -d ' ') \
     5         kx         $(echo $line | cut -f 2 -d ' ') \
     5         kx         $(echo $line | cut -b1 ) \
     5         kx         $(echo $line | cut -f 7 -d ' ' | cut -f 1 -d :) \
     5         kx         $(echo $line | cut -f 7 -d ' ' | cut -f 2 -d :) 2> /dev/null
     5         kx       done
     5         kx       rm -f /run/static-nodes
     5         kx       # Add any system defined additional device nodes:
     5         kx       cp --preserve=all --recursive --update /lib/udev/devices/* /dev 2> /dev/null
     5         kx       # Add any locally defined additional device nodes:
     5         kx       cp --preserve=all --recursive --update /etc/udev/devices/* /dev 2> /dev/null
     5         kx       echo "Starting udevd:  /sbin/udevd --daemon"
     5         kx       /sbin/udevd --daemon
     5         kx       # Since udev is just now being started we want to use add events:
     5         kx       echo "Triggering udev events:  /sbin/udevadm trigger --action=add"
     5         kx       # Call udevtrigger and udevsettle to do the device configuration:
     5         kx       /sbin/udevadm trigger --type=subsystems --action=add
     5         kx       /sbin/udevadm trigger --type=devices --action=add
     5         kx     else # trigger changes for already running udevd
     5         kx       # If the persistent network rules file does not exist, trigger an add event:
     5         kx       if [ ! -r /etc/udev/rules.d/70-persistent-net.rules ]; then
     5         kx         # Test that we can actually write to the directory first:
     5         kx         if touch /etc/udev/rules.d/testfile 2> /dev/null ; then
     5         kx           rm -f /etc/udev/rules.d/testfile
     5         kx           # This should add persistent net rules:
     5         kx           echo "Triggering udev to write persistent rules to /etc/udev/rules.d/"
     5         kx           /sbin/udevadm trigger --type=devices --action=add
     5         kx           sleep 3
     5         kx           # Create the files if they don't exist at this point.
     5         kx           # If a machine does not have a network device or an optical
     5         kx           # device, we don't want to waste time trying to generate
     5         kx           # rules at every boot.
     5         kx           # To force another attempt, delete the file(s).
     5         kx           touch /etc/udev/rules.d/70-persistent-net.rules
     5         kx         fi
     5         kx       fi
     5         kx       # Update the hardware database index (/etc/udev/hwdb.bin), if possible:
     5         kx       if touch /etc/udev/testfile 2> /dev/null ; then
     5         kx         rm -f /etc/udev/testfile
     5         kx         echo "Updating hardware database index:  /sbin/udevadm hwdb --update"
     5         kx         /sbin/udevadm hwdb --update
     5         kx       fi
     5         kx       # Since udevd is running, most of the time we only need change events:
     5         kx       echo "Triggering udev events:  /sbin/udevadm trigger --action=change"
     5         kx       /sbin/udevadm trigger --type=subsystems --action=change
     5         kx       /sbin/udevadm trigger --type=devices --action=change
     5         kx     fi
     5         kx     /sbin/udevadm settle --timeout=120
     5         kx     ;;
     5         kx   stop)
     5         kx     echo "Stopping udevd is STRONGLY discouraged and not supported."
     5         kx     echo "If you are sure you want to do this, use 'force-stop' instead."
     5         kx     ;;
     5         kx   force-stop)
     5         kx     echo "Stopping udevd"
     5         kx     udevadm control --exit
     5         kx     killall udevd 2>/dev/null
     5         kx     ;;
     5         kx   restart)
     5         kx     echo "Restarting udevd is STRONGLY discouraged and not supported."
     5         kx     echo "If you are sure you want to do this, use 'force-restart' instead."
     5         kx     ;;
     5         kx   force-restart)
     5         kx     echo "Restarting udevd"
     5         kx     udevadm control --exit
     5         kx     sleep 3
     5         kx     udevd --daemon
     5         kx     ;;
     5         kx   reload)
     5         kx     echo "Reloading udev rules"
     5         kx     udevadm control --reload
     5         kx     ;;
     5         kx   force-reload)
     5         kx     echo "Updating all available device nodes in /dev"
     5         kx     udevadm control --reload
     5         kx     rm -rf /dev/.udev /dev/disk
     5         kx     cp --preserve=all --recursive --update /lib/udev/devices/* /dev 2> /dev/null
     5         kx     ;;
     5         kx 
     5         kx   *)
     5         kx     echo "Usage: $0 {start|stop|restart|reload|force-reload}"
     5         kx     exit 1
     5         kx     ;;
     5         kx esac