Mounting LUKS-encrypted disks by UUID
I have a machine with two external storage disks attached to it - one an SSD, and one an HDD.
Both are LUKS-encrypted.
On a reboot of the machine, I want them unlocked and mounted to specific mount points.
They are not consistent with their /dev partition names: sometimes one is /dev/sdb, sometimes it is the other one.
So mount them via uuid instead.
Use blkid
to identify the disk’s UUID. This is different to the “Disk identifier”.
Then unlock using /dev/disk/by-uuid/$UUID
rather than /dev/$partition_name
:
#!/bin/bash
/usr/sbin/cryptsetup luksOpen /dev/disk/by-uuid/include-your-uuid-from-blkid-here name-of-mapper --key-file=/path/to/keyfile
/usr/bin/mount /dev/mapper/name-of-mapper /your/chosen/mount/point
You may also like:
- Unlocking a LUKS-encrypted partition via ssh on Debian 12 Bookworm
- Updating the LUKS key derivation function on Debian
- Making my ThinkPad LED flash 'decoded.legal' in morse code
- Triggering a remote lamp automatically when I am on a call
- Disabling my ThinkPad's internal camera on boot
- Snikket, a self-contained XMPP distribution
- GSConnect (KDE Connect), WireGuard, and Debian 12 Bookworm
- NetworkManager: automatically switch between Ethernet and Wi-Fi
- Fixing sogo's 'incorrect string value' error
- Backing up to a USB stick automatically via udev
- Fixing espanso incomplete text replacement
- Automating actions in Nautilus (GNOME's file manager) with scripts
- Jabra Evolve2 40 and Debian Linux
- Debian on a £190 Lenovo ThinkPad X1 Yoga Gen 2
- Enabling Webauthn in Firefox via snap