init 1.8 KB

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