Untitled - Posted on November Wed 18th 8:50 PM (Never Expires) - Format: text
  1.                 #!/bin/sh -e
  2. ### BEGIN INIT INFO
  3. # Provides:          udev
  4. # Required-Start:    mountkernfs
  5. # Required-Stop:
  6. # Default-Start:     S
  7. # Default-Stop:
  8. # Short-Description: Start udevd, populate /dev and load drivers.
  9. ### END INIT INFO
  10.  
  11. # we need to unmount /dev/pts/ and remount it later over the tmpfs
  12. unmount_devpts() {
  13.   if mountpoint -q /dev/pts/; then
  14.     umount -n -l /dev/pts/
  15.   fi
  16.  
  17.   if mountpoint -q /dev/shm/; then
  18.     umount -n -l /dev/shm/
  19.   fi
  20. }
  21.  
  22. # mount a tmpfs over /dev, if somebody did not already do it
  23. mount_tmpfs() {
  24.   if grep -E -q "^[^[:space:]]+ /dev tmpfs" /proc/mounts; then
  25.     return
  26.   fi
  27.  
  28.   # /dev/.static/dev/ is used by MAKEDEV to access the real /dev/ directory.
  29.   # /lib/udev/devices/ is recycled as a temporary mount point.
  30.   if [ -z "$no_static_dev" ]; then
  31.     mount -n --bind /dev /lib/udev/devices
  32.   fi
  33.  
  34.   if ! mount -n -o size=$tmpfs_size,mode=0755 -t tmpfs tmpfs /dev; then
  35.     if [ -z "$no_static_dev" ]; then
  36.       umount -n /lib/udev/devices
  37.     fi
  38.     log_failure_msg "udev requires tmpfs support, not started."
  39.     log_end_msg 1
  40.   fi
  41.   # relabel the new tmpfs accordingly
  42.   [ -x /sbin/restorecon ] && /sbin/restorecon /dev
  43.  
  44.   if [ -z "$no_static_dev" ]; then
  45.     mkdir -p /dev/.static/dev
  46.     chmod 700 /dev/.static/
  47.     mount -n --move /lib/udev/devices /dev/.static/dev
  48.   fi
  49. }
  50.  
  51. create_dev_makedev() {
  52.   if [ -e /sbin/MAKEDEV ]; then
  53.     ln -sf /sbin/MAKEDEV /dev/MAKEDEV
  54.   else
  55.     ln -sf /bin/true /dev/MAKEDEV
  56.   fi
  57. }
  58.  
  59. # I hate this hack.  -- Md
  60. make_extra_nodes() {
  61.   if [ "$(echo /lib/udev/devices/*)" != "/lib/udev/devices/*" ]; then
  62.     cp --archive --update /lib/udev/devices/* /dev/
  63.   fi
  64.  
  65.   [ -e /etc/udev/links.conf ] || return 0
  66.   grep '^[^#]' /etc/udev/links.conf | \
  67.   while read type name arg1; do
  68.     [ "$type" -a "$name" -a ! -e "/dev/$name" -a ! -L "/dev/$name" ] ||continue
  69.     case "$type" in
  70.       L) ln -s $arg1 /dev/$name ;;
  71.       D) mkdir -p /dev/$name ;;
  72.       M) mknod -m 600 /dev/$name $arg1 ;;
  73.       *) log_warning_msg "links.conf: unparseable line ($type $name $arg1)" ;;
  74.     esac
  75.     if [ -x /sbin/restorecon ]; then
  76.       /sbin/restorecon /dev/$name
  77.     fi
  78.   done
  79. }
  80.  
  81. supported_kernel() {
  82.   case "$(uname -r)" in
  83.     2.[012345].*|2.6.[0-9]|2.6.[0-9][!0-9]*) return 1 ;;
  84.     2.6.1[0-4]|2.6.1[0-4][!0-9]*) return 1 ;;
  85.   esac
  86.   return 0
  87. }
  88.  
  89. load_input_modules() {
  90.   case "$(uname -r)" in
  91.     2.6.1[0-5]|2.6.1[0-5][!0-9]*) ;; # <= 2.6.15
  92.     *) return 0
  93.   esac
  94.  
  95.   for module in mousedev evdev joydev; do
  96.     modprobe -q $module || true
  97.   done
  98. }
  99.  
  100. # shell version of /usr/bin/tty
  101. my_tty() {
  102.   [ -x /bin/readlink ] || return 0
  103.   [ -e /proc/self/fd/0 ] || return 0
  104.   readlink --silent /proc/self/fd/0 || true
  105. }
  106.  
  107. warn_if_interactive() {
  108.   if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then
  109.     return
  110.   fi
  111.  
  112.   TTY=$(my_tty)
  113.   if [ -z "$TTY" -o "$TTY" = "/dev/console" -o "$TTY" = "/dev/null" ]; then
  114.     return
  115.   fi
  116.  
  117.   printf "\n\n\nIt has been detected that the command\n\n\t$0 $*\n\n"
  118.   printf "has been run from an interactive shell.\n"
  119.   printf "It will probably not do what you expect, so this script will wait\n"
  120.   printf "60 seconds before continuing. Press ^C to stop it.\n"
  121.   printf "RUNNING THIS COMMAND IS HIGHLY DISCOURAGED!\n\n\n\n"
  122.   sleep 60
  123. }
  124.  
  125. ##############################################################################
  126.  
  127. [ -x /sbin/udevd ] || exit 0
  128.  
  129. PATH="/sbin:/bin"
  130.  
  131. # defaults
  132. tmpfs_size="10M"
  133. udev_root="/dev"
  134.  
  135. if [ -e /etc/udev/udev.conf ]; then
  136.   . /etc/udev/udev.conf
  137. fi
  138.  
  139. . /lib/lsb/init-functions
  140.  
  141. if ! supported_kernel; then
  142.   log_failure_msg "udev requires a kernel >= 2.6.15, not started."
  143.   log_end_msg 1
  144. fi
  145.  
  146. if [ ! -e /proc/filesystems ]; then
  147.   log_failure_msg "udev requires a mounted procfs, not started."
  148.   log_end_msg 1
  149. fi
  150.  
  151. if ! grep -q '[[:space:]]tmpfs$' /proc/filesystems; then
  152.   log_failure_msg "udev requires tmpfs support, not started."
  153.   log_end_msg 1
  154. fi
  155.  
  156. if [ ! -d /sys/class/ ]; then
  157.   log_failure_msg "udev requires a mounted sysfs, not started."
  158.   log_end_msg 1
  159. fi
  160.  
  161. if [ ! -e /proc/sys/kernel/hotplug ]; then
  162.   log_failure_msg "udev requires hotplug support, not started."
  163.   log_end_msg 1
  164. fi
  165.  
  166. ##############################################################################
  167.  
  168. # this is experimental and may not work well
  169. if [ "$UDEV_DISABLED" = "yes" ]; then
  170.   udev_root=/etc/udev/.dev
  171.   UDEV_ROOT=$udev_root
  172. fi
  173.  
  174. udev_root=${udev_root%/}
  175.  
  176. if [ "$udev_root" != "/dev" ]; then
  177.   log_warning_msg "udev_root != /dev/"
  178.  
  179. case "$1" in
  180.     start)
  181.     if [ -e "$udev_root/.udev/" ]; then
  182.         if mountpoint -q $udev_root/; then
  183.             log_failure_msg "udev is already active on $udev_root."
  184.             log_end_msg 1
  185.         else
  186.             log_warning_msg ".udev/ already exists on the static $udev_root!"
  187.         fi
  188.     fi
  189.  
  190.     echo > /proc/sys/kernel/hotplug
  191.  
  192.     mount -n -o size=$tmpfs_size,mode=0755 -t tmpfs tmpfs $udev_root
  193.     mkdir -p $udev_root/.udev/db/
  194.  
  195.     log_daemon_msg "Starting the hotplug events dispatcher" "udevd"
  196.     if udevd --daemon; then
  197.         log_end_msg $?
  198.     else
  199.         log_end_msg $?
  200.     fi
  201.  
  202.     log_action_begin_msg "Synthesizing initial hotplug events"
  203.     if udevtrigger; then
  204.         log_action_end_msg $?
  205.     else
  206.         log_action_end_msg $?
  207.     fi
  208.  
  209.     load_input_modules
  210.  
  211.     ;;
  212.     stop)
  213.     log_daemon_msg "Stopping the hotplug events dispatcher" "udevd"
  214.     if start-stop-daemon --stop --name udevd --quiet --oknodo --retry 5; then
  215.         log_end_msg $?
  216.     else
  217.         log_end_msg $?
  218.     fi
  219.  
  220.     log_action_begin_msg "Unmounting $udev_root"
  221.     # unmounting with -l should never fail
  222.     if umount -n -l $udev_root; then
  223.         log_action_end_msg $?
  224.     else
  225.         log_action_end_msg $?
  226.     fi
  227.     ;;
  228.  
  229.     restart)
  230.     $0 stop
  231.     $0 start
  232.     ;;
  233.  
  234.     reload|force-reload)
  235.     udevcontrol reload_rules
  236.     ;;
  237.  
  238.     *)
  239.     echo "Usage: /etc/init.d/udev {start|stop|restart|reload|force-reload}"
  240.     exit 1
  241.     ;;
  242. esac
  243.  
  244.   exit 0
  245. fi # udev_root != /dev
  246.  
  247. ##############################################################################
  248.  
  249. # When modifying this script, do not forget that between the time that
  250. # the new /dev has been mounted and udevtrigger has been run there will be
  251. # no /dev/null. This also means that you cannot use the "&" shell command.
  252.  
  253. case "$1" in
  254.     start)
  255.     if [ -e "$udev_root/.udev/" ]; then
  256.         if mountpoint -q $udev_root/; then
  257.             TMPFS_MOUNTED=1
  258.         else
  259.             log_warning_msg ".udev/ already exists on the static $udev_root!"
  260.         fi
  261.     else
  262.         warn_if_interactive
  263.     fi
  264.  
  265.     echo > /proc/sys/kernel/hotplug
  266.  
  267.     if [ -z "$TMPFS_MOUNTED" ]; then
  268.         unmount_devpts
  269.         mount_tmpfs
  270.         [ -d /proc/1 ] || mount -n /proc
  271.     else
  272.         # set the SELinux context for devices created in the initramfs
  273.         [ -x /sbin/restorecon ] && /sbin/restorecon -R /dev
  274.     fi
  275.  
  276.     # /dev/null must be created before udevd is started
  277.     make_extra_nodes
  278.  
  279.     # if this directory is not present /dev will not be updated by udev
  280.     mkdir -p /dev/.udev/db/
  281.  
  282.     log_daemon_msg "Starting the hotplug events dispatcher" "udevd"
  283.     if udevd --daemon; then
  284.         log_end_msg $?
  285.     else
  286.         log_end_msg $?
  287.     fi
  288.  
  289.     mkdir -p /dev/.udev/queue/
  290.  
  291.     log_action_begin_msg "Synthesizing the initial hotplug events"
  292.     if udevtrigger; then
  293.         log_action_end_msg $?
  294.     else
  295.         log_action_end_msg $?
  296.     fi
  297.  
  298.     load_input_modules
  299.     create_dev_makedev
  300.  
  301.     # wait for the udevd childs to finish
  302.     log_action_begin_msg "Waiting for /dev to be fully populated"
  303.     if udevsettle; then
  304.         log_action_end_msg 0
  305.     else
  306.         log_action_end_msg 0 'timeout'
  307.     fi
  308.     ;;
  309.  
  310.     stop)
  311.     log_daemon_msg "Stopping the hotplug events dispatcher" "udevd"
  312.     if start-stop-daemon --stop --name udevd --quiet --oknodo --retry 5; then
  313.         log_end_msg $?
  314.     else
  315.         log_end_msg $?
  316.     fi
  317.     ;;
  318.  
  319.     restart)
  320.     log_daemon_msg "Stopping the hotplug events dispatcher" "udevd"
  321.     if start-stop-daemon --stop --name udevd --quiet --oknodo --retry 5; then
  322.         log_end_msg $?
  323.     else
  324.         log_end_msg $? || true
  325.     fi
  326.  
  327.     log_daemon_msg "Starting the hotplug events dispatcher" "udevd"
  328.     if udevd --daemon; then
  329.         log_end_msg $?
  330.     else
  331.         log_end_msg $?
  332.     fi
  333.     ;;
  334.  
  335.     reload|force-reload)
  336.     udevcontrol reload_rules
  337.     ;;
  338.  
  339.     *)
  340.     echo "Usage: /etc/init.d/udev {start|stop|restart|reload|force-reload}"
  341.     exit 1
  342.     ;;
  343. esac
  344.  
  345. exit 0

New Paste

Paste Options

Recent Pastes

47 hours ago

Untitled

2 days ago

Untitled

3 days ago

Untitled

4 days ago

Untitled

5 days ago

Untitled

5 days ago

Untitled

6 days ago

Untitled

10 days ago

FREQUENTLY ASKED

10 days ago

Untitled

10 days ago

akai