Advertisement
Guest User

init

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