spacepaste

  1.  
  2. #!/bin/busybox sh
  3. rescue_shell() {
  4. printf '\e[1;31m' # bold red foreground
  5. printf "$1 Dropping you to a shell."
  6. printf "\e[00m\n" # normal colour foreground
  7. # load the keymap
  8. [ -f /keymap ] && loadkmap < /keymap
  9. exec setsid cttyhack /bin/sh
  10. }
  11. # initialise
  12. mount -t proc none /proc || rescue_shell "mount /proc failed."
  13. mount -t sysfs none /sys || rescue_shell "mount /sys failed."
  14. mount -t devtmpfs none /dev || rescue_shell "mount /dev failed."
  15. # set hardcoded default values
  16. crypt_root=""
  17. root=""
  18. resume=""
  19. mount_ro_rw='ro'
  20. # parse kernel command line
  21. for p in $(cat /proc/cmdline); do
  22. case "${p}" in
  23. # crypt_root=*)
  24. # crypt_root="${p#*=}"
  25. # ;;
  26. root=*)
  27. root="${p#*=}"
  28. ;;
  29. resume=*)
  30. resume="${p#*=}"
  31. ;;
  32. ro|rw)
  33. mount_ro_rw="${p}"
  34. ;;
  35. esac
  36. done
  37. # # decrypt
  38. # # convert UUID or LABEL to device node
  39. # crypt_root="$(findfs "${crypt_root}")"
  40. # # decryption is first tried using the key file /crypto_key.bin
  41. # # if this fails, prompt for a password
  42. # cryptsetup open "${crypt_root}" lvm --type luks --key-file /crypto_key.bin || \
  43. # cryptsetup open "${crypt_root}" lvm --type luks || \
  44. # rescue_shell "Decryption failed."
  45. # activate lvm
  46. # create /dev/mapper/control
  47. lvm vgscan --mknodes || rescue_shell "vgscan failed."
  48. # activate all LVM volumes
  49. lvm vgchange --sysinit -a ly || rescure_shell "vgchange failed."
  50. # create device nodes for the volumes
  51. lvm vgscan --mknodes || rescue_shell "vgscan failed."
  52. # mount the real root
  53. # convert UUID or LABEL to device node
  54. root="$(findfs "${root}")"
  55. mount -o "${mount_ro_rw}" "${root}" /mnt/root || rescue_shell "mount ${root} failed."
  56. # enable resume from hibernate
  57. if [ -n "${resume}" ]; then
  58. # copy the major:minor of the swap block device into /sys/power/resume
  59. printf '%u:%u\n' $(stat -L -c '0x%t 0x%T' "${resume}") > /sys/power/resume || \
  60. rescue_shell "Activating resume failed."
  61. fi
  62. # clean up
  63. umount /proc
  64. umount /sys
  65. umount /dev
  66. # boot the real system
  67. exec switch_root /mnt/root /sbin/init
  68.