SHARE
TWEET

Untitled

a guest Nov 17th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Call with `sudo bash DEBUG=1 ./crypt-fix.sh` for verbose output
  3. [ -n "$DEBUG"] && set -x
  4. # Prompt user for device from /dev/sd* /dev/nvme* /dev/mmc* prefixes?
  5. # For /dev/sda probably sda1 is EFI and sda2 is boot and sda3 is encrypted
  6. DEVICE=/dev/nvme0n1
  7. EFIPATH="${DEVICE}p1"
  8. BOOTPATH="${DEVICE}p2"
  9. CRYPTPATH="${DEVICE}p5"
  10. TARGETPATH=/mnt
  11. # Need root for mounting stuff
  12. if ! (( $EUID == 0 )); then echo "Please run with `sudo $0`"; fi
  13.  
  14. clear_mounts () {
  15. # Clears mounts in case of interrupt or upon exit to allow running script multiple times
  16. umount $TARGETPATH/boot/efi
  17. umount $TARGETPATH/boot
  18. umount $TARGETPATH/proc
  19. umount $TARGETPATH/dev
  20. umount $TARGETPATH
  21. vgchange -an
  22. cryptsetup close temp_name
  23. cryptsetup close $CRYPTNAME
  24. set +x
  25. }
  26. trap clear_mounts INT EXIT
  27.  
  28. cryptsetup open $CRYPTPATH temp_name
  29. vgchange -ay
  30. # Can't get this until LVM devices are scanned above
  31. ROOTPATH=$(ls /dev/mapper/* | grep root)
  32. ROOTPATH=ubu-root
  33. # Make sure nothing else is mounted on our $TARGETPATH
  34. umount $TARGETPATH
  35. wait
  36. mount $ROOTPATH $TARGETPATH
  37. # Find the name that is required for `update-initramfs` to properly update things
  38. CRYPTNAME=$(cat $TARGETPATH/etc/crypttab | awk '{ print $1 }')
  39. umount $TARGETPATH
  40. vgchange -an
  41. cryptsetup close temp_name
  42. # This proper name is required for `update-initramfs` to properly update things
  43. cryptsetup open $CRYPTPATH $CRYPTNAME
  44. wait
  45. vgchange -ay
  46. ROOTPATH=$(ls /dev/mapper/* | grep root)
  47. ROOTPATH=ubu-root
  48. mount $ROOTPATH $TARGETPATH
  49. mount $BOOTPATH $TARGETPATH/boot
  50. mount $EFIPATH $TARGETPATH/boot/efi
  51. mount -t proc proc $TARGETPATH/proc
  52. mount -o bind /dev $TARGETPATH/dev
  53. # Have also seen people mounting dev/pts and run and sys, they don't appear to be necessary
  54.  
  55. chroot $TARGETPATH update-initramfs -c -k all
  56. echo "Completed crypt-fix, try rebooting and you should get prompted for your passphrase after grub"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top