]> code.delx.au - monosys/commitdiff
reboot-no-passphrase use disk id instead of uuid
authorJames Bunton <jamesbunton@delx.net.au>
Fri, 22 Feb 2019 03:03:30 +0000 (14:03 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Fri, 22 Feb 2019 03:03:30 +0000 (14:03 +1100)
bin/reboot-no-passphrase [new file with mode: 0755]
etc/systemd/system/disable-crypto_keyfile@.service

diff --git a/bin/reboot-no-passphrase b/bin/reboot-no-passphrase
new file mode 100755 (executable)
index 0000000..0f9b56d
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+# When using the Arch Linux mkinitcpio encrypt if the file /crypto_keyfile.bin
+# exists in the initramfs then it will be used to attempt unlocking.
+# 1. dd if=/dev/urandom of=/crypto_keyfile.bin bs=1 count=512
+# 2. Add /crypto_keyfile.bin to FILES in /etc/mkinitcpio.conf
+# 3. mkinitcpio -p linux
+# 4. Enable the disable-crypto_keyfiles@<root-disk-id>.service
+# 5. Run this script when you want to reboot without a passphrase
+
+
+crypto_keyfile="/crypto_keyfile.bin"
+reboot_cmd="${1:-sudo reboot}"
+
+if [ ! -f "$crypto_keyfile" ]; then
+    echo "Failed to find $crypto_keyfile"
+    exit 1
+fi
+
+found_devices=""
+for disk_id in $(ls /etc/systemd/system/basic.target.wants/disable-crypto_keyfile@*.service | cut -d'@' -f2 | cut -d. -f1); do
+    found=1
+    found_devices="${found_devices} /dev/disk/by-id/${disk_id}"
+done
+
+if [ -z "$found_devices" ]; then
+    echo "Failed to find your encrypted device. You must have disable-crypto_keyfile@.service enabled."
+    exit 1
+fi
+
+echo -n "Enter password for devices: "
+read -r -s pw
+echo ""
+for device_filename in $found_devices; do
+    echo "Adding key to $device_filename"
+    sudo cryptsetup luksAddKey "$device_filename" "$crypto_keyfile" --key-slot 7 <<EOF
+${pw}
+EOF
+done
+
+$reboot_cmd
index 19dd58f67ee0b737f3cd67283c4cfde3d84974e7..e5f58add77b8a7ddd32f44f75c09ad8d3d744891 100644 (file)
@@ -4,7 +4,7 @@ After=basic.target
 
 [Service]
 Type=oneshot
-ExecStart=/bin/cryptsetup luksRemoveKey /dev/disk/by-uuid/%i /crypto_keyfile.bin --key-slot 7
+ExecStart=/bin/cryptsetup luksRemoveKey /dev/disk/by-id/%i /crypto_keyfile.bin --key-slot 7
 SuccessExitStatus=2
 
 [Install]