init 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. # Copyright (C) 2006 OpenWrt.org
  3. INITRAMFS=1
  4. . /etc/preinit
  5. set_state init
  6. echo "- init -"
  7. # if we have no root parameter, just go to running from ramfs
  8. [ -z $rootfs ] && {
  9. export NOMOUNT="No Root"
  10. exec /sbin/init
  11. }
  12. #if we have a failsafe boot selected, dont bother
  13. #trying to find or wait for a root mount point
  14. [ -z "$FAILSAFE" ] || {
  15. exec /bin/busybox init
  16. }
  17. # Load the modules we have in initramfs, this should
  18. # make the media accessible, but, it may take some time
  19. . /etc/functions.sh
  20. load_modules /etc/modules /etc/modules.d/*
  21. #wait 10 seconds for the disc to show up
  22. #usb stick typically takes 4 to 6 seconds
  23. #till it's readable
  24. #it's quite possible the disc never shows up
  25. #if we netbooted this kernel
  26. COUNTER=0
  27. while [ $COUNTER -lt 10 ]; do
  28. sleep 1
  29. [ -e $rootfs ] && let COUNTER=10;
  30. let COUNTER=COUNTER+1
  31. done
  32. [ -e $rootfs ] || {
  33. export FAILSAFE="NoDisc"
  34. exec /bin/busybox init
  35. }
  36. # now we'll try mount it, again with a timeout
  37. # This will fail if the inserted stick is formatted
  38. # in a manner we dont understand
  39. COUNTER=0
  40. while [ $COUNTER -lt 10 ]; do
  41. sleep 1
  42. mount $rootfs /mnt
  43. [ $? -eq "0" ] && let COUNTER=100;
  44. let COUNTER=COUNTER+1
  45. done
  46. [ $? -ne "0" ] && {
  47. export FAILSAFE="MountFail"
  48. exec /bin/busybox init
  49. }
  50. #It mounted, lets look for a postinit file, again, give it time
  51. #I've seen this take 6 seconds to actually complete
  52. COUNTER=0
  53. while [ $COUNTER -lt 10 ]; do
  54. sleep 1
  55. [ -e /mnt/etc/banner ] && let COUNTER=10;
  56. let COUNTER=COUNTER+1
  57. done
  58. [ -e /mnt/etc/banner ] || {
  59. export FAILSAFE="No Openwrt FS"
  60. exec /bin/busybox init
  61. }
  62. unset rootfs
  63. mount -o move /proc /mnt/proc
  64. mount -o move /dev /mnt/dev
  65. mount -o move /dev/pts /mnt/dev/pts
  66. mount -o move /tmp /mnt/tmp
  67. mount -o move /sys /mnt/sys
  68. mount none /tmp -t tmpfs
  69. killall -q hotplug2
  70. exec switch_root -c /dev/console /mnt /sbin/init
  71. set_state done