init 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/sh
  2. # Copyright (C) 2006 OpenWrt.org
  3. export PATH=/bin:/sbin:/usr/bin:/usr/sbin
  4. mount none /proc -t proc
  5. mount none /sys -t sysfs
  6. if grep devfs /proc/filesystems > /dev/null; then
  7. mount none /dev -t devfs
  8. elif [ -x /sbin/hotplug2 ]; then
  9. mount -t tmpfs tmpfs /dev -o size=512K
  10. mknod /dev/console c 5 1
  11. mkdir /dev/pts
  12. mkdir /dev/shm
  13. /sbin/hotplug2 --no-persistent --coldplug --max_children 1
  14. elif [ -x /sbin/udevd ]; then
  15. mount -n -t tmpfs -o mode=0755 udev /dev
  16. mkdir /dev/pts
  17. mkdir /dev/shm
  18. if [ -e /proc/sys/kernel/hotplug ]; then
  19. echo "" > /proc/sys/kernel/hotplug
  20. fi
  21. /sbin/udevd --daemon
  22. /sbin/udevtrigger
  23. /sbin/udevsettle
  24. fi
  25. mount none /dev/pts -t devpts
  26. # the root mount point can come from the kernel command line
  27. # or it can be overridden in the preinit.arch file
  28. [ -f /etc/preinit.arch ] && . /etc/preinit.arch
  29. # if we have no root parameter, just go to running from ramfs
  30. [ -z $rootfs ] && {
  31. export NOMOUNT="No Root"
  32. exec /sbin/init
  33. }
  34. #if we have a failsafe boot selected, dont bother
  35. #trying to find or wait for a root mount point
  36. [ -z "$FAILSAFE" ] || {
  37. exec /bin/busybox init
  38. }
  39. # Load the modules we have in initramfs, this should
  40. # make the media accessible, but, it may take some time
  41. . /etc/functions.sh
  42. load_modules /etc/modules /etc/modules.d/*
  43. #wait 10 seconds for the disc to show up
  44. #usb stick typically takes 4 to 6 seconds
  45. #till it's readable
  46. #it's quite possible the disc never shows up
  47. #if we netbooted this kernel
  48. COUNTER=0
  49. while [ $COUNTER -lt 10 ]; do
  50. sleep 1
  51. [ -e $rootfs ] && let COUNTER=10;
  52. let COUNTER=COUNTER+1
  53. done
  54. [ -e $rootfs ] || {
  55. export FAILSAFE="NoDisc"
  56. exec /bin/busybox init
  57. }
  58. # now we'll try mount it, again with a timeout
  59. # This will fail if the inserted stick is formatted
  60. # in a manner we dont understand
  61. COUNTER=0
  62. while [ $COUNTER -lt 10 ]; do
  63. sleep 1
  64. mount $rootfs /mnt
  65. [ $? -eq "0" ] && let COUNTER=100;
  66. let COUNTER=COUNTER+1
  67. done
  68. [ $? -ne "0" ] && {
  69. export FAILSAFE="MountFail"
  70. exec /bin/busybox init
  71. }
  72. #It mounted, lets look for a postinit file, again, give it time
  73. #I've seen this take 6 seconds to actually complete
  74. COUNTER=0
  75. while [ $COUNTER -lt 10 ]; do
  76. sleep 1
  77. [ -e /mnt/etc/banner ] && let COUNTER=10;
  78. let COUNTER=COUNTER+1
  79. done
  80. [ -e /mnt/etc/banner ] || {
  81. export FAILSAFE="No Openwrt FS"
  82. exec /bin/busybox init
  83. }
  84. unset rootfs
  85. mount -o move /proc /mnt/proc
  86. mount -o move /dev /mnt/dev
  87. mount -o move /dev/pts /mnt/dev/pts
  88. mount -o move /tmp /mnt/tmp
  89. mount -o move /sys /mnt/sys
  90. mount none /tmp -t tmpfs
  91. exec switch_root -c /dev/console /mnt /sbin/init