init 996 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. if [ "x${ROOT}" = "x" ]; then
  20. echo abcd
  21. exec /sbin/init
  22. fi
  23. mount -t sysfs sysfs /sys
  24. mdev -s
  25. mkdir /dev/pts
  26. mkdir /dev/shm
  27. mount -t devpts devpts /dev/pts
  28. mount -t tmpfs tmpfs /dev/shm
  29. mount -t tmpfs tmpfs /tmp
  30. mount -t tmpfs tmpfs /run
  31. export ROOT
  32. mkdir /rootfs
  33. if [ $ROOT == "/dev/nfs" ] && [ "x${NFSROOT}" != "x" ];then
  34. /sbin/ifup -a
  35. mount -t nfs -o nolock $NFSROOT /rootfs
  36. else
  37. mount $ROOT /rootfs/
  38. if [ ! -e /rootfs/dev/console ]; then
  39. /bin/mknod /rootfs/dev/console c 5 1
  40. fi
  41. fi
  42. mount -n -o move /proc /rootfs/proc
  43. mount -n -o move /sys /rootfs/sys
  44. mount -n -o move /run /rootfs/run
  45. mount -n -o move /tmp /rootfs/tmp
  46. mount -n -o move /dev/shm /rootfs/dev/shm
  47. mount -n -o move /dev/pts /rootfs/dev/pts
  48. exec chroot /rootfs $init 3