4

A drive with 2 partitions - the first partition is plain ext4, second one is encrypted LUKS. The partition table has been overwritten. I've found the beginning of the second partition, which I need to recover, thusly:

#hexdump -s 400000m -C /dev/sdc | grep LUKS
61d3dec850 79 c8 81 6d e5 4c 55 4b 53 40 49 aa 29 df de d7 |y..m.LUKS@I.)...|

then:

#losetup -o 0x61d3dec850 -r -f /dev/sdc
#losetup -a
/dev/loop0: [0005]:477209 (/dev/sdc), offset 420166420560

Ok so far, then this problem pops up:

#cryptsetup luksOpen /dev/loop0 luksrecover
Device /dev/loop0 is not a valid LUKS device.

Please advice how to proceed. Is it wrong offset? Should I seek for the magic number 0xEF53 identifying ext4 as adviced here https://unix.stackexchange.com/questions/103919/how-do-i-find-the-offset-of-an-ext4-filesystem ?

Mind you it's a 1TB drive so please I need an advice that does not force to scan the entire drive ( hours and hours) all over again if possible, such as testdisk which seems have no option to start at a specified offset to save time on scanning.

P.S. This was close , but not quite: https://unix.stackexchange.com/questions/177070/lvm-encrypted-partition-without-partition-table

2
  • You think the first partition was ~ 400 GB? Where are your backups? What's wrong with waiting three hours for testdisk? Jan 6, 2015 at 22:57
  • Yes, I recall approximate size of the partitions. Testdisk took so long to scan 7% of it that I calculated it would take 14 hours to finish and having no such luxury had to abort. This is the back up drive :).
    – hexedone
    Jan 7, 2015 at 1:14

1 Answer 1

4

The first obvious problem is you're looking in the wrong place. That's not a LUKS header.

The LUKS partition header starts with the six bytes, defined as L, U, K, S, followed by 0xBA, 0xBE. As you can clearly see, two of those six bytes aren't present there.

What you're looking for is pretty obvious:

00000000  4c 55 4b 53 ba be 00 01  61 65 73 00 00 00 00 00  |LUKS....aes.....|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  78 74 73 2d 70 6c 61 69  |........xts-plai|
00000030  6e 36 34 00 00 00 00 00  00 00 00 00 00 00 00 00  |n64.............|
00000040  00 00 00 00 00 00 00 00  73 68 61 31 00 00 00 00  |........sha1....|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 10 00 00 00 00 20  |............... |

You'll need to look elsewhere on the disk. Perhaps you need to back up a bit? Or forward. Or just let testdisk do its thing; if there's a valid LUKS header on the disk anywhere it should find it eventually.

1
  • That has been my suspicion too. I recall experimenting with cryptsetup on this drive prior to the final partitioning and encryption, could it be the remnants of that? I'll keep seeking for more LUKS hits.Thanx for answering so fast btw .
    – hexedone
    Jan 7, 2015 at 1:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .