init 971 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. # This script replaces the default busybox init process to avoid having that
  3. # process staying alive and sleeping in the background, (uselessly) consuming
  4. # precious memory.
  5. # Mount procfs and sysfs
  6. /bin/mount -t proc proc /proc
  7. /bin/mount -t sysfs sysfs /sys
  8. # When the kernel is directly booted, devtmpfs is not automatically mounted.
  9. # Manually mount it if needed.
  10. devmnt=$(mount | grep -c devtmpfs)
  11. if [ "${devmnt}" -eq 0 ]; then
  12. /bin/mount -t devtmpfs devtmpfs /dev
  13. fi
  14. # Use the /dev/console device node from devtmpfs if possible to not
  15. # confuse glibc's ttyname_r().
  16. # This may fail (E.G. booted with console=), and errors from exec will
  17. # terminate the shell, so use a subshell for the test
  18. if (exec 0</dev/console) 2>/dev/null; then
  19. exec 0</dev/console
  20. exec 1>/dev/console
  21. exec 2>/dev/console
  22. fi
  23. # Clear memory to reduce page fragmentation
  24. echo 3 > /proc/sys/vm/drop_caches
  25. # Finally, let's start an interactive shell
  26. exec /bin/sh