init 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. mount -t proc proc /proc
  3. ROOT=
  4. NFSROOT=
  5. export init=/sbin/init
  6. for x in $(cat /proc/cmdline); do
  7. case $x in
  8. init=*)
  9. init=${x#init=}
  10. ;;
  11. root=*)
  12. ROOT=${x#root=}
  13. ;;
  14. nfsroot=*)
  15. NFSROOT=${x#nfsroot=}
  16. ;;
  17. esac
  18. done
  19. mount -t sysfs sysfs /sys
  20. mount -t devtmpfs -o nosuid,mode=0755 devtmpfs /dev
  21. mkdir -p /dev/pts
  22. mkdir -p /dev/shm
  23. mount -t devpts devpts /dev/pts
  24. mount -t tmpfs tmpfs /dev/shm
  25. mount -t tmpfs tmpfs /tmp
  26. mount -t tmpfs tmpfs /run
  27. if [ "x${ROOT}" = "x" ]; then
  28. exec /sbin/init
  29. fi
  30. export ROOT
  31. mkdir /rootfs
  32. if [ $ROOT == "/dev/nfs" ] && [ "x${NFSROOT}" != "x" ];then
  33. /sbin/ifup -a
  34. mount -t nfs -o nolock $NFSROOT /rootfs
  35. else
  36. cnt=0
  37. while [ $cnt -lt 100 ]
  38. do
  39. if [ ! -e $ROOT ];then
  40. sleep 0.1
  41. else
  42. echo "find $ROOT: $cnt"
  43. break
  44. fi
  45. let cnt++
  46. done
  47. mount $ROOT /rootfs/
  48. if [ ! -e /rootfs/dev/console ]; then
  49. /bin/mknod /rootfs/dev/console c 5 1
  50. fi
  51. if [ ! -e /rootfs/dev/null ]; then
  52. /bin/mknod /rootfs/dev/null c 1 3
  53. fi
  54. fi
  55. mount -n -o move /proc /rootfs/proc
  56. mount -n -o move /sys /rootfs/sys
  57. mount -n -o move /run /rootfs/run
  58. mount -n -o move /tmp /rootfs/tmp
  59. mount -n -o move /dev /rootfs/dev
  60. mount -n -o move /dev/shm /rootfs/dev/shm
  61. mount -n -o move /dev/pts /rootfs/dev/pts
  62. exec run-init /rootfs "${init}" "$@" <"/rootfs/dev/console" >"/rootfs/dev/console" 2>&1
  63. echo "Something went badly wrong in the initramfs."