init 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/ash
  2. sh
  3. udevd_running=0
  4. mount_handler=default_mount_handler
  5. init=/sbin/init
  6. rd_logmask=0
  7. . /init_functions
  8. mount -t proc proc /proc -o nosuid,noexec,nodev
  9. mount -t sysfs sys /sys -o nosuid,noexec,nodev
  10. mount -t devtmpfs dev /dev -o mode=0755,nosuid
  11. mount -t tmpfs run /run -o nosuid,nodev,mode=0755
  12. mkdir -m755 /run/initramfs
  13. # parse the kernel command line
  14. echo "Ls proc"
  15. ls -l /proc/
  16. echo "USER=$USER"
  17. sleep 2
  18. echo "---($(id -u))---"
  19. sleep 2
  20. parse_cmdline </proc/cmdline
  21. # setup logging as early as possible
  22. rdlogger_start
  23. for d in ${disablehooks//,/ }; do
  24. [ -e "/hooks/$d" ] && chmod 644 "/hooks/$d"
  25. done
  26. . /config
  27. run_hookfunctions 'run_earlyhook' 'early hook' $EARLYHOOKS
  28. if [ -n "$earlymodules$MODULES" ]; then
  29. modprobe -qab ${earlymodules//,/ } $MODULES
  30. fi
  31. run_hookfunctions 'run_hook' 'hook' $HOOKS
  32. # honor the old behavior of break=y as a synonym for break=premount
  33. if [ "${break}" = "y" ] || [ "${break}" = "premount" ]; then
  34. echo ":: Pre-mount break requested, type 'exit' to resume operation"
  35. launch_interactive_shell
  36. fi
  37. rootdev=$(resolve_device "$root") && root=$rootdev
  38. unset rootdev
  39. fsck_root
  40. # Mount root at /new_root
  41. "$mount_handler" /new_root
  42. run_hookfunctions 'run_latehook' 'late hook' $LATEHOOKS
  43. run_hookfunctions 'run_cleanuphook' 'cleanup hook' $CLEANUPHOOKS
  44. if [ "$(stat -c %D /)" = "$(stat -c %D /new_root)" ]; then
  45. # Nothing got mounted on /new_root. This is the end, we don't know what to do anymore
  46. # We fall back into a shell, but the shell has now PID 1
  47. # This way, manual recovery is still possible.
  48. err "Failed to mount the real root device."
  49. echo "Bailing out, you are on your own. Good luck."
  50. echo
  51. launch_interactive_shell --exec
  52. elif [ ! -x "/new_root${init}" ]; then
  53. # Successfully mounted /new_root, but ${init} is missing
  54. # The same logic as above applies
  55. err "Root device mounted successfully, but ${init} does not exist."
  56. echo "Bailing out, you are on your own. Good luck."
  57. echo
  58. launch_interactive_shell --exec
  59. fi
  60. if [ "${break}" = "postmount" ]; then
  61. echo ":: Post-mount break requested, type 'exit' to resume operation"
  62. launch_interactive_shell
  63. fi
  64. # this should always be the last thing we do before the switch_root.
  65. rdlogger_stop
  66. cat /proc/cmdline
  67. exec env -i \
  68. "TERM=$TERM" \
  69. /usr/bin/switch_root /new_root $init "$@"
  70. # vim: set ft=sh ts=4 sw=4 et: