[SOLVED] fail: deleted crypt-luks /dev/sda5 > how to regain access to (encrypted) data?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Reading all physical volumes. This may take a while...
After a heep of such messages the output looks as follows
Code:
ALERT! /dev/disk/by-uuid/[long-number] does not exist
Check cryptopts=source= bootarg: cat /proc/cmdline
or missing modules, devices: cat /proc/modules;
ls /dev -r Dropping to a shell.
Will skip /dev/disk/by-uuid/[long-number] if you can't fix
Code:
BusyBox v1.22.1 (Debian 1:1.22.0-19+b3) built-in shell (ash)
Enter 'help' for a list of built-in commands.
(initramfs)
Further Infos
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
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.
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.
Thanks already for pointing me in the right direction. Testdisk gave me that output. Now I don't know where to start and end resizing. But I will read into it as soon as I have time.
Code:
Testdisk
Linux 0 32 31 31 26 57 497664 Ext2 blocksize=1024 Large file Sparse supberblock 254MB/243MiB Can‘t open filesystem. Filesystem seems damaged
Linux 0 32 31 31 26 59 497664 Ext2 blocksize=1024 Large file Sparse supberblock 254MB/243MiB GRUB Data
Linux* 31 59 29 31 124 29 4096 LUKS1 (Data size unkown), 2097 KB / 2048 KiB Can‘t open filesystem. Filesystem seems damaged
For all three: Structure okay
Last edited by Josomeister; 06-16-2019 at 06:40 AM.
Testdisk Start Start Start End End End Size in Sectors Sentence below Filetable
Linux 0 32 31 31 26 57 497664 Ext2 blocksize=1024 Large file Sparse supberblock 254MB/243MiB Can‘t open filesystem. Filesystem seems damaged
Linux 0 32 31 31 26 59 497664 Ext2 blocksize=1024 Large file Sparse supberblock 254MB/243MiB GRUB Data
Linux* 31 59 29 31 124 29 4096 LUKS1 (Data size unkown), 2097 KB / 2048 KiB Can‘t open filesystem. Filesystem seems damaged
For all three: Structure okay
What version of testdisk is this? Is that actual cut and pasted testdisk output?
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.
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
Last edited by Josomeister; 06-16-2019 at 07:19 AM.
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
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.
That will leave partition 1 and the extended partition as they are now, and create partition 5 starting where testdisk found the LUKS container and extending to the end of the disk.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.