Since RAID 1 is a simple mirror, you can ignore the RAID issue and instead search for the LUKS header directly. If no partitioning was involved, it should be somewhere around the start of the drive. Maybe with a few hundred MiB offset since mdadm uses quite generous data offsets.
The following command searches the first 1 GiB of the drive:
# hexdump -C -n 1G /dev/sdx | grep LUKS
08100000 4c 55 4b 53 ba be 00 02 00 00 00 00 00 00 40 00 |LUKS..........@.|
In this example, there is a potential LUKS header at offset 0x8100000 (129 MiB).
Create a (read-only) loop device at this offset and see if it works…
# losetup --find --show --read-only --offset $((0x8100000)) /dev/sdx
/dev/loop2
# cryptsetup luksOpen /dev/loop2 lukstest
Enter passphrase:
# mount -o loop,ro /dev/mapper/lukstest /mnt/somewhere
If that works, you could try to recover while keeping the data in-place. But I recommend you make a full backup copy first anyways.
Would it be possible to rewrite the partition data and restart the raid?
In theory, you'd have to
- create two loop devices(*), offset 1 MiB (future partition offset)
- run above hexdump command again on the loop device to determine correct offset (should be -1 MiB compared to bare drive),
- using those loop devices, re-create RAID using the correct offset and adapt mdadm.conf accordingly,
cryptsetup openthe raid,- shrink the filesystem a little to make room for GPT backup header at end of disk,
- unmount the filesystem (if mounted),
cryptsetup closeluks,mdadm --stopthe raid,losetup -ddetach the loop devices, - create a partition offset 1 MiB on both drives
At this point you should have drives with partitions, raid on the partitions, luks on the raid, filesystem inside luks.
However, this is the optimal case, and it will only work this way if I understood your situation correctly. There's plenty of ways how this can go completely wrong.
(*)
The hoop-jumping with loop devices is necessary because you have to shrink the filesystem first before you can create partitions without corrupting the end of device. And you can only shrink the filesystem if your RAID is running (if it runs off both drives and has to preserve consistency).
If you created partitions directly instead, probably nothing terrible would happen (or it already happened anyway) but it's technically not the correct way to go from bare disk to partitions in this scenario.