Advertisement
siriusb

init

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