init_script.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/mnt/busybox sh
  2. BUSYBOX=/mnt/busybox
  3. freeze() {
  4. echo "an error occurred while executing '''$@''', freezing..." > /dev/console
  5. while true; do
  6. true
  7. done
  8. }
  9. do_or_freeze() {
  10. if $@; then
  11. return
  12. fi
  13. freeze $@
  14. }
  15. do_or_freeze $BUSYBOX mkdir -p /dev
  16. do_or_freeze $BUSYBOX mknod -m 666 /dev/console c 5 1
  17. do_or_freeze $BUSYBOX mknod -m 666 /dev/null c 1 3
  18. do_or_freeze $BUSYBOX mknod -m 666 /dev/zero c 1 5
  19. do_or_freeze $BUSYBOX mknod -m 666 /dev/sda b 8 0
  20. do_or_freeze $BUSYBOX mknod -m 666 /dev/sda1 b 8 1
  21. echo -n -e "deploying busybox... " > /dev/console
  22. do_or_freeze $BUSYBOX mkdir -p /bin
  23. do_or_freeze $BUSYBOX --install -s /bin
  24. export PATH="/bin"
  25. echo ok > /dev/console
  26. do_or_freeze mkdir -p /etc /root /proc
  27. do_or_freeze mount -t procfs proc proc
  28. cat > /etc/passwd <<EOF
  29. root:x:0:0:root:/root:/mnt/busybox sh
  30. EOF
  31. cat > /etc/group <<EOF
  32. root:x:0:root
  33. EOF
  34. cat > /etc/profile <<EOF
  35. export PATH=/bin
  36. EOF
  37. cat > /root/.profile <<EOF
  38. export HOME=/root
  39. alias ll="ls -l "
  40. alias la="ls -la "
  41. EOF
  42. exec /mnt/init /bin/sh -l \
  43. < /dev/console > /dev/console 2> /dev/console