Advertisement
Guest User

init busybox

a guest
Apr 26th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. #!/bin/busybox ash
  2. # Install busybox's applets as symlinks
  3. /bin/busybox --install -s
  4.  
  5. . /init_functions
  6.  
  7. msg ":: Loading Initramfs"
  8. /bin/mount -t proc proc /proc -o nosuid,noexec,nodev
  9. /bin/mount -t sysfs sys /sys -o nosuid,noexec,nodev
  10. if grep -q devtmpfs /proc/filesystems 2>/dev/null; then
  11. /bin/mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid
  12. else
  13. /bin/mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid
  14. # We don't have devtmpfs, so add the most important standard devices
  15. /bin/mknod /dev/null c 1 3
  16. /bin/mknod /dev/zero c 1 5
  17. /bin/mknod /dev/console c 5 1
  18. # /dev/mem is needed if we want to load uvesafb before triggering uevents
  19. /bin/mknod /dev/mem c 1 1
  20. fi
  21.  
  22. read CMDLINE </proc/cmdline
  23. export CMDLINE
  24.  
  25. export root=""
  26. export init=""
  27. echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
  28.  
  29. # set default mount handler
  30. mount_handler="default_mount_handler"
  31.  
  32. # if available, start udevd at this stage
  33. if [ -x /sbin/udevd ]; then
  34. msg ":: Starting udevd..."
  35. echo > /proc/sys/kernel/hotplug
  36. /sbin/udevd --daemon --resolve-names=never
  37. export udevd_running=1
  38. msg "done."
  39. else
  40. export udevd_running=0
  41. fi
  42.  
  43. for cmd in ${CMDLINE}; do
  44. case "${cmd}" in
  45. \#*) break ;; # ignore everything after a # in the commandline
  46. # The kernel passes those to the kernel on its own
  47. [0123456Ss]) ;;
  48. [0-9]*) ;;
  49. single) ;;
  50. rw) readwrite="yes" ;;
  51. ro) readwrite="no" ;;
  52. # only export stuff that does work with ash :)
  53. *=*) rhs="$(echo "${cmd}" | cut -d= -f2-)"
  54. cmd="$(echo "${cmd}" | cut -d= -f1 | sed 's|\.|_|g')"
  55. cmd="$(echo "${cmd}" | sed 's|-|_|g')=${rhs}"
  56. (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}"
  57. ;;
  58. *) cmd="$(echo "${cmd}" | sed 's|\.|_|g')"
  59. cmd="$(echo "${cmd}" | sed 's|-|_|g')"
  60. (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}=y"
  61. ;;
  62. esac
  63. done
  64.  
  65. if [ -n "${disablehooks}" ]; then
  66. for d in $(echo "${disablehooks}" | sed 's|,| |g'); do
  67. export "hook_${d}=disabled"
  68. done
  69. fi
  70.  
  71. if [ -n "${disablemodules}" ]; then
  72. for d in $(echo "${disablemodules}" | sed 's|,| |g'); do
  73. export "mod_${d}=disabled"
  74. done
  75. fi
  76.  
  77. if [ -n "${earlymodules}" ]; then
  78. for m in $(echo "${earlymodules}" | sed 's|,| |g'); do
  79. /sbin/modprobe -q ${m} > /dev/null 2>&1
  80. done
  81. fi
  82.  
  83. . /config
  84.  
  85. for m in ${MODULES}; do
  86. TST=""
  87. eval "TST=\$mod_${m}"
  88. if [ "${TST}" != "disabled" ]; then
  89. /sbin/modprobe -q ${m} > /dev/null 2>&1
  90. fi
  91. done
  92.  
  93. # If rootdelay is empty or not a non-negative integer, set it to 10
  94. if [ -z "${rootdelay}" ] || ! [ "${rootdelay}" -ge 0 ]; then
  95. export rootdelay=10
  96. fi
  97.  
  98. if [ -e "/hooks" ]; then
  99. for h in ${HOOKS}; do
  100. TST=""
  101. eval "TST=\$hook_${h}"
  102. if [ "${TST}" != "disabled" ]; then
  103. run_hook () { msg "${h}: no run function defined"; }
  104. if [ -e "/hooks/${h}" ]; then
  105. . /hooks/${h}
  106. msg ":: Running Hook [${h}]"
  107. run_hook
  108. fi
  109. fi
  110. done
  111. fi
  112.  
  113. if [ "${break}" = "y" ]; then
  114. echo ":: Break requested, type 'exit' to resume operation"
  115. launch_interactive_shell
  116. fi
  117.  
  118. if [ -f "/message" ]; then
  119. msg "$(cat /message)"
  120. fi
  121.  
  122. # Mount root at /new_root
  123. mkdir -p /new_root
  124. ${mount_handler} /new_root
  125.  
  126. [ -z "${init}" ] && init="/sbin/init"
  127. if [ "$(stat -c %D /)" = "$(stat -c %D /new_root)" ]; then
  128. # Nothing got mounted on /new_root. This is the end, we don't know what to do anymore
  129. # We fall back into a shell, but the shell has now PID 1
  130. # This way, manual recovery is still possible.
  131. err "Failed to mount the real root device."
  132. echo "Bailing out, you are on your own. Good luck."
  133. echo
  134. launch_interactive_shell --exec
  135. elif [ ! -x "/new_root${init}" ]; then
  136. # Successfully mounted /new_root, but ${init} is missing
  137. # The same logic as above applies
  138. err "Root device mounted successfully, but ${init} does not exist."
  139. echo "Bailing out, you are on your own. Good luck."
  140. echo
  141. launch_interactive_shell --exec
  142. fi
  143.  
  144. #Special handling if udev is running
  145. udevpid=$(/bin/pidof udevd)
  146. if [ -n "${udevpid}" ]; then
  147. # Settle pending uevents, then kill udev
  148. /sbin/udevadm settle
  149. /bin/kill ${udevpid} > /dev/null 2>&1
  150. while /bin/pidof udevd >/dev/null; do
  151. sleep 0.1
  152. done
  153. fi
  154.  
  155. mount --move /proc /new_root/proc
  156. mount --move /sys /new_root/sys
  157. mount --move /dev /new_root/dev
  158. exec /sbin/switch_root -c /dev/console /new_root ${init} "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement