You are not logged in.

#1 2020-06-09 12:48:51

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,932
Website

[NOT FIXABLE] Rescue LUKS partition after accidental repartitioning

I just made the dumbest mistake by copy-and-pasting a command for partitioning a USB device without checking the correct device path.
Thusly I accidentally created an empty partition table on my system's internal SSD. I noticed the mistake and directly recreated the correct partitions as they were before. I used fdisk in both cases. Partition format is GPT. The first partition on the disk is the EFI and /boot partition, the second one is a LUKS container for /. After a reboot, the EFI did not find an OS anymore, so I live booted. The first partition seems to be intact, but the LUKS container seems to have been corrupted. When I try to open it, I get an error. Here are the relevant links:
http://ix.io/2oIv
http://ix.io/2oIx
http://ix.io/2oIy

Can I salvage the LUKS volume?

Last edited by schard (2020-06-10 08:04:20)

Offline

#2 2020-06-09 14:57:24

mxfm
Member
Registered: 2015-10-23
Posts: 163

Re: [NOT FIXABLE] Rescue LUKS partition after accidental repartitioning

If you have no LUKS header backup there is no way to recover LUKS container.

Offline

#3 2020-06-09 17:01:03

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,932
Website

Re: [NOT FIXABLE] Rescue LUKS partition after accidental repartitioning

What makes you assume that the LUKS header has been overridden?

Offline

#4 2020-06-09 17:24:08

ua4000
Member
Registered: 2015-10-14
Posts: 402

Re: [NOT FIXABLE] Rescue LUKS partition after accidental repartitioning

Are you sure, you have created the luks partition with correct start/end sectors ?
Inspect it with sudo head /dev/sda2 - you should hopefully see something with "LUKS..."
Else: search the disk for the Luks start sector.

I don't use fdisk, I prefer parted from which I know I can modify the running system itself -  if I leave the partition at it orginal start/end sector.
I mention this, because I don't know if fdisk may write something else to the disk... e.g. tries to clear the previous filesystem start sector...

Offline

#5 2020-06-09 17:27:46

mxfm
Member
Registered: 2015-10-23
Posts: 163

Re: [NOT FIXABLE] Rescue LUKS partition after accidental repartitioning

schard wrote:

What makes you assume that the LUKS header has been overridden?

???

 Device /dev/sda2 is not a valid LUKS device.

This makes me think the LUKS header is corrupted (was overwritten by some data). Either 1) the copy-pasted script contained additional commands which touched partitions or 2) when you recreated partitions you somehow damaged LUKS header. Did you created filesystems on restored partitions?

After rereading your post - I think there is still a chance that LUKS header was not corrupted if partitions were recreated 'not exactly' as before. Your LUKS header can be alive if starting sector of partition was pointed some sectors foreward - in this case the LUKS header is somewhere in the end of previous partition.

TL;DR You can use disk editor utilities to find LUKS header signatures somewhere in the end and at the beginning of relevant partitions. However, I doubt you will find something if you are 100% sure that you recreated partitions exactly as before and additional has run mkfs.ext4 (or whatever).

Offline

#6 2020-06-10 06:07:42

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,932
Website

Re: [NOT FIXABLE] Rescue LUKS partition after accidental repartitioning

There was no formatting done. I just re-wrote the partition table, nothing else.
I'll try to scan for a possible LUKS header. Thank you both for the tip.

Last edited by schard (2020-06-10 06:09:05)

Offline

#7 2020-06-10 07:53:26

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,932
Website

Re: [NOT FIXABLE] Rescue LUKS partition after accidental repartitioning

The LUKS partition starts with

aesxts-plain64sha512 ■}

This looks like the end of a JSON-ish LUKS header.
But there seems to be a lot missing.
I think that it'll be wasted time trying to fix this.
I'll just reinstall and replay the backups.

Offline

#8 2020-06-10 08:34:53

mxfm
Member
Registered: 2015-10-23
Posts: 163

Re: [NOT FIXABLE] Rescue LUKS partition after accidental repartitioning

schard wrote:

The LUKS partition starts with

aesxts-plain64sha512 ■}

This looks like the end of a JSON-ish LUKS header.
But there seems to be a lot missing.
I think that it'll be wasted time trying to fix this.
I'll just reinstall and replay the backups.

It should start from 'LUKS' which is '4c' '55' '4b' '53'. The aes should start few bytes later like 'LUKS....aes.....' (this is LUKS1 header).

Offline

Board footer

Powered by FluxBB