For future panic-stricken folks funneled here by a search engine: You are neither the first nor last person to own-goal. Be kind to yourself.
Also, if something similar happens to you and you have no backup, and no header-backup, first make sure you've actually overwritten the LUKS header instead of just thinking you have.
In particular, if you use an encrypted partition, the LUKS header is (as you would guess) located at the start of the partition, not the start of the device. So if you just overwrote the start of your block device and erased your partition table (perhaps with a dd mishap? ask me how I know...), your partition may not show up, but it's still there, just as long as you haven't written into the partition (first partition is usually location at 1MB=1024KB). If that's the case, recreating the partition table is all that's needed.
As always, when disaster strikes - first make an image of your disk and experiment on it, so you don't end up making a bad situation worse.
To check if the header is still there, open the block device in a hex-editor and look for the primary and/or secondary LUKS headers
#define MAGIC_1ST "LUKS\xba\xbe"
#define MAGIC_2ND "SKUL\xba\xbe"
If either is there you just got very lucky.
To restore the partition table some people suggest testdisk
, but in my case cfdisk
was enough to recreate the partition table, and undo the damage. Luckily, I overwrote only the first 30k of the drive, and LUKS was installed on the first (and only) partition. Which also made it easy to recreate the partition table.
Also, if you're reading this - backup your LUKS header now with
sudo cryptsetup luksHeaderBackup --header-backup-file BACKUP_FILENAME DEVICE