micsoftvn

Auto Unlock Crypt LVM

Feb 22nd, 2021
1,020
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. dd if=/dev/urandom of=/boot/keyfile bs=1024 count=4
  3. chmod 0400 /boot/keyfile
  4. cryptsetup -v luksAddKey /dev/sda3 /boot/keyfile
  5. ls -l /dev/disk/by-uuid/
  6.  
  7. root@quangva-Vostro-3459:/home/quangva# ls -l /dev/disk/by-uuid/
  8. total 0
  9. lrwxrwxrwx 1 root root 10 Thg 1  8 14:35 26D4-3645 -> ../../sda1
  10. lrwxrwxrwx 1 root root 10 Thg 1  8 14:35 4c4f6b87-66c1-495b-9dfd-a5eff8ffd032 -> ../../dm-1
  11. lrwxrwxrwx 1 root root 10 Thg 1  8 14:35 7c229c4a-d978-446f-ae1c-ad3e28ce30df -> ../../sda2
  12. lrwxrwxrwx 1 root root 10 Thg 1  8 14:35 87b0cbb3-907c-4ea6-a3a5-0731c72c478b -> ../../sda3
  13. lrwxrwxrwx 1 root root 10 Thg 1  8 14:35 88d8ded4-03e4-4e74-89ba-9ea9d560309d -> ../../dm-2
  14.  
  15. vi /etc/crypttab
  16.  
  17. sda3_crypt UUID=87b0cbb3-907c-4ea6-a3a5-0731c72c478b none luks,discard
  18.  
  19. sda3_crypt UUID=87b0cbb3-907c-4ea6-a3a5-0731c72c478b /dev/disk/by-uuid/7c229c4a-d978-446f-ae1c-ad3e28ce30df:/keyfile luks,keyscript=/lib/cryptsetup/scripts/passdev
  20.  
  21. update-initramfs -u
  22.  
  23. mkinitramfs -o /boot/initrd.img-$(uname -r) $(uname -r)
RAW Paste Data