LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 07-06-2013, 02:04 PM   #1
garden3
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Rep: Reputation: Disabled
Recovering encrypted LVM partitions


Windows (or more specifically, the Acer eRecovery tool) messed up my boot partition on my dual boot system (Windows 7 and Fedora 18). I have a Windows partition (sda1, sda2 and sda3) and LVM encrypted partitions (sda4), which include a home, boot (unencrypted), swap and root partition. (There is also a separate data partition that is also encrypted and was on sda5)

When I typed "ls", the answer was:
grub rescue> ls
(hd0) (hd0,msdos5) (hd0,msdos3) (hd0,msdos2) (hd0,msdos1)

When I typed lvdisplay, vgdisplay, or lvscan, the answer was: No volumes groups found.

Because I could not find or mount the encrypted LVM partitions anymore, I then started testdisk.

Before using testdisk, fdisk showed this output:

fdisk -l
Device --- Boot ---Start--- End--- Blocks--- Id ---System
/dev/sda1 ---2040 ---31459327--- 15728640 ---27--- Hidden--- NTFS ---WinRE *Windows*
/dev/sda2 ---*--- 31459328 ---31664127 ---102400--- 7--- HPFS/NTFS/exFAT *Windows Acer eRecovery*
/dev/sda3 ---31664128--- 502896639--- 235616256 ---7 ---HPFS/NTFS/exFAT *Windows main partition*
/dev/sda4 ---502896640 ---1465149167 ---401126264--- 5--- Extended *I believe the LVM partitions should be here*
/dev/sda5 ---614004736 ---1465147391--- 425571328 ---83 (this is just a data partition, no Operating System)
I then used testdisk, which showed this partition table:
fdisk -l
Device ---Boot ---Start--- End--- Blocks--- Id--- System
/dev/sda1 ---2040 ---31459327 ---15728640 ---27--- Hidden NTFS WinRE
/dev/sda2--- *--- 31459328 ---31664127 ---102400--- 7--- HPFS/NTFS/exFAT
/dev/sda3--- 31664128--- 502896639--- 235616256 ---7 ---HPFS/NTFS/exFAT
/dev/sda4--- 502898760 ---1465160129 ---481130685 ---f W95 Ext'd (LBA)
/dev/sda5 ---502900736 ---503924735--- 512000--- 83--- Linux
/dev/sda6 ---503926784 ---503930879 ---2048 ---83--- Linux
/dev/sda7--- 614004736--- 614008831 ---2048 ---83 ---Linux
(Testdisk seemed to have moved the sda5 data partition to sda7 and to put the sda 4 extended partition to sda4, sda5 and sda6.)

I then wrote this partition table to the MBR with testdisk.

As a result, I seem to have lost my original sda5 data partition, which I cannot open/decrypt anymore.
When I now run cryptsetup luksOpen on sda6 and on sda7, I can enter the password for the root partition of Fedora 18 at sda6 and the password for the data partition (which was before on sda5) on sda7. But I get the error message:Requested offset is beyond real size of device" and I cannot open the encrypted partitions.

Testdisk also showed this:
Disk /dev/sda 750 GB 698 GiB CHS 91202 255 63
The harddisk (750GB/698 GiB ) seems too small. (<2878GB/2680 GiB)
Check the harddisk size: HD jumpers settings, BIOS detection....

The following partitions can't be recovered:
Partition Start End Size in sectors
FAT16 <32M 241432 55 6 349921 45 32 1742875182
FAT32 LBA 264128 56 24 32533 15 8 954338727

Continue
892 GB
488 GB

HPFS NTFS 0 32 33 1958 64 26 31457280 PQSERVICE
HPFS NTFS 1958 64 27 1971 0 13 204800 SYSTEM RESERVED
HPFS NTFS 1971 0 14 31303 221 22 471232512 ACER
LINUX 31367 252 54 31368 62 54 4096 (this could be the Fedora livecd)
LINUX 38220 6 59 38220 71 59 4096 (this could be the Fedora livecd)

Current Partition structure
Partition Start End Size in sectors
1 * HPFS NTFS 0 32 33 1958 64 26 31457280 PQSERVICE
2 P HPFS NTFS 1958 64 27 1971 0 13 204800 SYSTEM RESERVED
3 P HPFS NTFS 1971 0 14 31303 221 22 471232512 ACER
4 E extended LBA 31304 0 1 91201 254 63 962261370
5 L Linux 31304 31 24 31367 220 21 1024000
X extended 31367 251 1 31368 62 54 4212
6 L Linux 31367 252 54 31368 62 54 4096
X extended 8220 5 1 38220 71 59 4217
7 L Linux 38220 6 59 38220 71 59 4096
Now my questions are:
1. Is it possible to revert the changes that testdisk did to the partition table, so I can at least open again the data partition (the original sda5 partition)?
2. Is it possible with testdisk that I recover the encrypted LVM partitions?
 
Old 07-07-2013, 06:33 AM   #2
cyberpatrol
Member
 
Registered: Dec 2012
Posts: 75

Rep: Reputation: Disabled
Quote:
Originally Posted by garden3 View Post
Now my questions are:
1. Is it possible to revert the changes that testdisk did to the partition table, so I can at least open again the data partition (the original sda5 partition)?
2. Is it possible with testdisk that I recover the encrypted LVM partitions?
To both questions: No.

Nevertheless, don't write anything else onto this disk!

How did you encrypt the LVM partitions? And have the encrypted LVM partitions (partially) been overwritten, too?
 
1 members found this post helpful.
Old 07-07-2013, 08:16 AM   #3
garden3
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
The setup of the encrypted LVM partitions was done automatically by the Fedora 18 installer.

The Acer eRecovery tool overwrote the MBR partition, I'm not sure if it also did damage to the other partitions in the short time before I shutdown the computer. I should not have done anything like this as I only clicked on exit, but since I was not able to mount or find anything, maybe it did.

So I cannot revert the changes testdisk did, even if I have the output from fdisk above?
 
Old 07-07-2013, 08:40 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
You can make the partitioning look like it did, but nothing can recover the sectors that testdisk overwrote when you told it to write out the new partitioning. The problem occurs only with extended partitions, and is due to the Extended Boot Record (aka secondary partition table) that precedes each logical drive in the extended partition. When testdisk wrote those EBRs ahead of what it believed were your logical drives, whatever data was previously in those sectors was permanently lost. If that happened to be some of the key data for one of your LUKS encrypted partitions, that partition is now unrecoverable.
 
1 members found this post helpful.
Old 07-07-2013, 08:54 AM   #5
cyberpatrol
Member
 
Registered: Dec 2012
Posts: 75

Rep: Reputation: Disabled
Well, as far as I know Fedora first creates a LUKS container and the LVM within this LUKS container. If this is the case, then there is a chance to get your data back, if the partitions themselves have not been overwritten.

The problem is there is no software that does it automagically.
 
1 members found this post helpful.
Old 07-07-2013, 09:22 AM   #6
garden3
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by cyberpatrol View Post
Well, as far as I know Fedora first creates a LUKS container and the LVM within this LUKS container. If this is the case, then there is a chance to get your data back, if the partitions themselves have not been overwritten.

The problem is there is no software that does it automagically.
Do you know how it could be done? I tried to mount and "cryptsetup luksOpen" most of what I saw under /dev/*.

As I wrote above, "cryptsetup luksOpen" seems at least to recognize the password for sda6 and sda7, but there is an error that the "Requested offset is beyond real size of device". And the LVM commands I tried said that no volume groups were found.

Last edited by garden3; 07-07-2013 at 09:31 AM.
 
Old 07-07-2013, 11:36 AM   #7
garden3
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
I have added some more output about this here http://pastebin.com/C3vuUZE8

Using testdisk, I could access the boot partition. The relevant configuration files were overwritten, but I think "vmlinux" and other files could still be seen.

Could I use testdisk to write a new partition table, so that I can at least recover the original encrypted partition sda5, which is not a LVM volume?
 
Old 07-07-2013, 07:27 PM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
If cryptsetup recognizes the password, then you have the correct starting points. You just adjust the endpoints to make sda6 and sda7 as large as possible. Make sda6 end at sector 614004735, which is just before the start of sda7. Make sda7 extend to sector 1465149167, which is the end of the disk.

Last edited by rknichols; 07-07-2013 at 07:30 PM.
 
1 members found this post helpful.
Old 07-08-2013, 11:57 AM   #9
garden3
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Wow, thanks. I have recovered the data partition (originally partition sda5, or sda7 in your last post).

Now I still need to recover the LVM partitions, if it is at all possible.

Last edited by garden3; 07-08-2013 at 06:01 PM.
 
Old 07-08-2013, 06:05 PM   #10
garden3
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
When I try to add another partition (for the encrypted LVM volumes) with fdisk, I get the error: Value out of range.

I'm trying to add this partition
/dev/sdaX ---502,896,640 ---614,004,735 ---401,126,264---

At the moment, my partition table looks like this
sda1 2048------ 31459327 ------15728640 7
sda2 31459328 ------31664127 ------102400 7
sda3 31664128 ------502,896,639 ------235616256 7
sda4 502,898,760 ------1465160129------ 481130685 f W95 Extednd LBA
sda5 502,900,736 ------503924735------ 512000 83
sda6 503926784 ------503930879 ------2048 83 linux
sda7 614004736------ 1465149167 ------ 425572216 83 linux
 
Old 07-09-2013, 03:48 AM   #11
garden3
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
I deleted the other partitions in the partition table and then created the partition for the extended encrypted LVM partition.

/dev/sda4 ---502,896,640 (I also tried 502900736 and 503926784) ---614,004,735 ---401,126,264--- 5--

But when trying to run cryptsetup on it, it tells me it's not a valid LUKS device.

Do you know what could be wrong?

Last edited by garden3; 07-09-2013 at 03:52 AM.
 
Old 07-09-2013, 10:14 AM   #12
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by garden3 View Post
I deleted the other partitions in the partition table and then created the partition for the extended encrypted LVM partition.

/dev/sda4 ---502,896,640 (I also tried 502900736 and 503926784) ---614,004,735 ---401,126,264--- 5--

But when trying to run cryptsetup on it, it tells me it's not a valid LUKS device.
Of course not. 502896640 is nothing like the correct starting point. 502900736 is close, but now you are trying to create a primary partition (sda4) to access the area that was formerly a logical drive (sda5). The actual start of data for a logical drive is offset to allow space for the Extended Boot Record I mentioned previously plus padding to align the start of data correctly. It looks like your disk was previously partitioned with 1-Megabyte (2048 sectors) alignment, so try 502902784 (502900736+2048).

I hope you are not still trying this on your original disk with no backup copy. You are really playing with fire here, and could very easily lose your encrypted data permanently.

[EDIT] But how was your LVM set up? Is this partition an encrypted container with an LVM physical volume within it? Or, was this an LVM physical volume with one or more encrypted logical volumes in it? If the latter, then after creating the partition with the correct starting point, you would need to get LVM to recognize the physical volume. If you make the partition type 8E (Linux LVM), the kernel should pick up the volume automatically. Otherwise, you might need to run pvscan, which will scan all disks for LVM physical volumes.

Last edited by rknichols; 07-09-2013 at 10:31 AM. Reason: Add paragraph about LVM
 
1 members found this post helpful.
Old 07-09-2013, 11:29 AM   #13
garden3
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
I am not sure how the LVM was set up, Fedora was doing the setup automtically. Cyberpatrol wrote above: "Well, as far as I know Fedora first creates a LUKS container and the LVM within this LUKS container. If this is the case, then there is a chance to get your data back, if the partitions themselves have not been overwritten."

I am using fdisk to create and delete the partitions. Should I be creating an extended or primary partition with fdisk?

I'm doing this on the original disk. I risk losing three weeks of my home folder data, which is annoying but maybe also a lesson (to make more frequent backups), and backing up the whole HDD (750 GB) so that it can be reused is not so straightforward.

Do you know if the end-of-partition number (-614,004,735 -) is correct, or should I also try other values?

Last edited by garden3; 07-09-2013 at 12:11 PM.
 
Old 07-09-2013, 02:17 PM   #14
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
It's safer to work with primary partitions, since that way the only writes are to the primary partition table in the MBR.

As long as the partition is at least of sufficient size to hold the LVM / LUKS structures, the exact endpoint doesn't matter.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shrink partition (LVM encrypted PVs + encrypted LVs) gedaj Linux - Newbie 2 05-22-2013 03:44 AM
Resizable encrypted LVM requiring just one password on boot (encrypted volume group)? Nyyr Linux - Software 9 01-24-2013 05:52 AM
Please help with recovering an encrypted partition Ironicus Linux - General 1 01-02-2013 01:53 PM
Problem recovering encrypted partitions lupe *BSD 1 01-17-2012 04:52 PM
[SOLVED] Recovering grub after Windows installation. Encrypted partitions and LVM. 1937 Debian 6 11-04-2010 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration