modules 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. # Begin $RC_BASE/init.d/modules
  3. ### BEGIN INIT INFO
  4. # Provides: modules
  5. # Required-Start: mountvirtfs sysctl
  6. # Should-Start:
  7. # Required-Stop:
  8. # Should-Stop:
  9. # Default-Start: S
  10. # Default-Stop:
  11. # Short-Description: Loads required modules.
  12. # Description: Loads modules listed in /etc/default/modules.
  13. # X-LFS-Provided-By: LFS
  14. ### END INIT INFO
  15. . /lib/lsb/init-functions
  16. # Assure that the kernel has module support.
  17. [ -e /proc/ksyms -o -e /proc/modules ] || exit 0
  18. case "${1}" in
  19. start)
  20. # Exit if there's no modules file or there are no
  21. # valid entries
  22. [ -r /etc/default/modules ] &&
  23. egrep -qv '^($|#)' /etc/default/modules ||
  24. exit 0
  25. # If proc is mounted, find the current kernel
  26. # message level
  27. if [ -f /proc/sys/kernel/printk ]; then
  28. prev_msg=`cat /proc/sys/kernel/printk | \
  29. sed 'l 1' | sed -n '2~0p' | \
  30. sed 's/\\\//'`
  31. else
  32. prev_msg="6"
  33. fi
  34. # Now set the message level to 1 so not to make too
  35. # much noise when loading modules
  36. dmesg -n 1
  37. # Only try to load modules if the user has actually given us
  38. # some modules to load.
  39. if egrep -qv '^(#|$)' /etc/default/modules 2>/dev/null
  40. then
  41. # Read in the configuration file.
  42. exec 9>&0 < /etc/default/modules
  43. message="${INFO}Loading modules:"
  44. while read module args
  45. do
  46. # Ignore comments and blank lines.
  47. case "${module}" in
  48. ""|\#*) continue ;;
  49. esac
  50. # Attempt to load the module, making
  51. # sure to pass any arguments provided.
  52. modprobe ${module} ${args} > /dev/null
  53. # Print the module name if successful,
  54. # otherwise take note.
  55. if [ ${?} -eq 0 ]; then
  56. message="${message}${NORMAL} ${module}"
  57. else
  58. failedmod="${failedmod} ${module}"
  59. fi
  60. done
  61. # Print a message about successfully loaded
  62. # modules on the correct line.
  63. log_success_msg "${message}"
  64. # Print a failure message with a list of any
  65. # modules that may have failed to load.
  66. if [ "${failedmod}" ]; then
  67. log_failure_msg "${FAILURE}Failed to load modules:${failedmod}"
  68. fi
  69. exec 0>&9 9>&-
  70. fi
  71. # Set the kernel message level back to it's previous value.
  72. dmesg -n "${prev_msg}"
  73. ;;
  74. *)
  75. echo "Usage: ${0} {start}"
  76. exit 1
  77. ;;
  78. esac
  79. # End $RC_BASE/init.d/modules