init_script.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/mnt/busybox sh
  2. BUSYBOX=/mnt/busybox
  3. freeze() {
  4. echo "an error occurred while executing '''$@''', freezing..." >&2
  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. do_or_freeze $BUSYBOX mknod -m 666 /dev/ttyS0 c 4 64
  22. do_or_freeze $BUSYBOX mknod -m 666 /dev/ttyS1 c 4 65
  23. echo -n -e "deploying busybox... " >&2
  24. do_or_freeze $BUSYBOX mkdir -p /bin
  25. do_or_freeze $BUSYBOX --install -s /bin
  26. export PATH="/bin"
  27. echo ok >&2
  28. do_or_freeze mkdir -p /etc /root /proc
  29. do_or_freeze mount -t procfs proc proc
  30. cat > /etc/passwd <<EOF
  31. root:x:0:0:root:/root:/mnt/busybox sh
  32. EOF
  33. cat > /etc/group <<EOF
  34. root:x:0:root
  35. EOF
  36. cat > /etc/profile <<EOF
  37. export PATH=/bin
  38. EOF
  39. cat > /root/.profile <<EOF
  40. export HOME=/root
  41. alias ll="ls -l "
  42. alias la="ls -la "
  43. EOF
  44. exec /mnt/init /bin/sh -c 'exec sh -l < /dev/ttyS0 > /dev/ttyS0 2> /dev/ttyS0'