fail: deleted crypt-luks /dev/sda5 > how to regain access to (encrypted) data?
Hello everyone. Yes a very stupid mistake.
Story behind I wanted to format a USB stick while I was stressed in time during a conference. sudo gparted and then - don't ask me which horse was riding me - I deleted all the partitions on /dev/sda (and not /dev/sdb) and pressed okay and okay again. After I got a kernel error message I was like "fuuuk" but the computer was still running so I though "uf lucky me the harddrive was not unmounted so it was protected from writing" an finished my thing and shutted down my computer before egs backing up my password-vault :). After I rebooted the shock: Error messages Code:
WARNING: Failed to connect to lvmetad. Falling back to device scanning. Code:
ALERT! /dev/disk/by-uuid/[long-number] does not exist Code:
BusyBox v1.22.1 (Debian 1:1.22.0-19+b3) built-in shell (ash) When I boot from a live-system I can still see and access /dev/sda1 ext2 (bootloader) and see but not access /dev/sda2 extended /dev/sda5 crypt-luks is not there anymore, this is probably the thing I deleted Similar issues Those two threads are somehow related I think, but I don't really understand it https://www.linuxquestions.org/quest...on-4175435883/ https://www.linuxquestions.org/quest...on-4175468395/ Hope you can help me P.s.: Backups yes, are a good thing. Sadly my last backup is quite old. So regular backups are even better, yes. |
The tool of choice for recovering partitions is testdisk, which can be found on System Rescue CD, GParted Live CD, and many other rescue CDs. It should be able to locate your missing LUKS partition easily.
The remaining problem is that there is no size information in the LUKS header, so testdisk cannot determine the partition size and always assumes the minimum possible size (just enough for the LUKS header). You will have to adjust the size of that partition manually. Just be sure to use a tool that simply resizes the partition and does not attempt to adjust or format the content. I suggest the "resizepart" command in the parted command. |
Quote:
Code:
Testdisk |
Quote:
That first partitions entry, the one marked "seems damaged", looks correct, though with an unusual starting sector (CHS 0:32:31 works out to sector 2046). That LUKS partition has a reasonable starting location aligned on the next MiB boundary after the end of partition 1. Creating that as a primary partition starting at sector 501760 and extending to the end of the disk would be easiest. If you really want that to continue to be logical partition 5, then you would have to create an extended partition starting at least 2 sectors before that and extending to the end of the disk. Many partitioning tools will refuse to let you do that. The only one I know of that will unconditionally let you do whatever you want is sfdisk. The output from "fdisk -l" for that disk would give me the information I would need to tell you what to give to sfdisk. |
Thanks for your response. I will give you the infos as soon as I have access again. But it is not the actual cut and pasted testdisk output but I wrote it down manually.
Version of testdisk: Don't know yet but I used the newest version of SystemRescue. In the meantime I was reading a bit on cgsecurity.org and watching some youtube videos on HardDisks, CHS... egs: https://www.youtube.com/watch?v=Cj8-WNjaGuM Now I have a theoretical question: CHS represents the logical (and not the physical) position of data represented with the three "address"-values Cylinder, Head and Sectors. However I don't get the difference between Cylinder and Head. As I understood it: Cylinders are the amount of disks in a hard disk and the heads are the amount of read/write devices and the heads can only move all together. Aren't therefore the cylinder value and the head value always the same as they correlate? Why is the head value given in CHS when all the heads are moving together? I have a lot of noob questions like that, so I would be glad if someone could point me out to a good tutorial on CHS etc |
Hey there
I have now the direct log after conducting a quick and a deep search. The file can be downloaded here https://workupload.com/file/fRJ6JPm5 I copy pasted it below as well. fdisk -l log below sfdisk -d /dev/sda* log below as well Code:
fdisk -l log Link to logfile Code:
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors sfdisk -d /dev/sda* log link to the logfile Code:
# partition table of /dev/sda |
Please don't use QUOTE tags except for quoting from another post. It changes formatting and makes it hard to include your text in a reply. Use CODE tags to preserve formatting.
All you should need to do is put the following text in a file and use this file as input to sfdisk. Code:
unit: sectors Code:
sfdisk /dev/sda </path/to/the/file |
it worked. thank you very much!
thanks for the feedback as well. I changed from quote to code. best |
Lucky fella - especially with luks header. If anything had written to that ... ugh.
Nice one (again) rknichols. |
All times are GMT -5. The time now is 10:30 PM. |