Recover partition table for Linux LVM2

How to use TestDisk to recover lost partition
Forum rules
When asking for technical support:
- Search for posts on the same topic before posting a new question.
- Give clear, specific information in the title of your post.
- Include as many details as you can, MOST POSTS WILL GET ONLY ONE OR TWO ANSWERS.
- Post a follow up with a "Thank you" or "This worked!"
- When you learn something, use that knowledge to HELP ANOTHER USER LATER.
Before posting, please read https://www.cgsecurity.org/testdisk.pdf
Message
Author
kiper
Posts: 6
Joined: 31 May 2012, 21:43

Recover partition table for Linux LVM2

#1 Post by kiper »

Hi everyone :)

I have a "big" problem -because it has never happened to me something like that-. After a power outage the partition where I mounted /home did not can be mounted. I have a disk partitioned with two lvm, one for /var (40 GB), and the other for /home (30 GB). I added a whole disk (300 GB) as a physical volume for my /home logical volume, and I partitioned the disk as Primary and with the ID for Linux LVM, wich is 8e. It was created as /dev/sdd1.

The problem is that

Code: Select all

fdisk -l
can't create the partition table for

Code: Select all

dev/sdd1
. Furthermore, it says that /dev/sdd doesn't contain a partition. I run TestDisk in order to find this "lost" partition. I select the hard disk, Intel partition table, Analyse and it doesn't find any partition on this disk. So I did the same process but this time selecting None partition table and TestDisk does find a partition, the lost one, but I can't do anything to recover it from there. I tried to add a partition, but it simply doesn't create it.

I'm not an expert, so apologize my poor description, but I place below the log file and some pictures:

This is the log file:

Code: Select all


Thu May 31 20:49:53 2012
Command line: TestDisk

TestDisk 6.11, Data Recovery Utility, April 2009
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org
OS: Linux, kernel 2.6.38-8-generic (#42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011)
Compiler: GCC 4.5 - Oct 17 2010 20:12:36
ext2fs lib: 1.41.14, ntfs lib: 10:0:0, reiserfs lib: none, ewf lib: none
Warning: can't get size for Disk /dev/mapper/control - 0 B - CHS 1 1 1, sector size=512
/dev/sr0 is not an ATA disk
Hard disk list
Disk /dev/sda - 72 GB / 67 GiB - CHS 8855 255 63, sector size=512 - COMPAQ BD07289BB8
Disk /dev/sdb - 72 GB / 67 GiB - CHS 8855 255 63, sector size=512 - COMPAQ BD07289BB8
Disk /dev/sdc - 72 GB / 67 GiB - CHS 8855 255 63, sector size=512 - COMPAQ BD07289BB8
Disk /dev/sdd - 300 GB / 279 GiB - CHS 36472 255 63, sector size=512 - COMPAQ BD30088279
Disk /dev/sr0 - 718 MB / 685 MiB - CHS 351023 1 1 (RO), sector size=2048 - TSSTcorp CD-ROM TS-H192C

Partition table type (auto): None
Disk /dev/sdd - 300 GB / 279 GiB - COMPAQ BD30088279
Partition table type: Intel

Analyse Disk /dev/sdd - 300 GB / 279 GiB - CHS 36472 255 63
Current partition structure:

Partition sector doesn't have the endmark 0xAA55
Ask the user for vista mode
Allow partial last cylinder : No
search_vista_part: 0

search_part()
Disk /dev/sdd - 300 GB / 279 GiB - CHS 36472 255 63

Results

interface_write()
 
No partition found or selected for recovery

search_part()
Disk /dev/sdd - 300 GB / 279 GiB - CHS 36472 255 63

Results

interface_write()
 
No partition found or selected for recovery
This is the image that shows what TestDisk says to me when I search the partition by None partition table:
Image

This is what TestDisk shows when I search the partition by Intel partition table:
Image

I hope you can give some guidance in order to solve this problem.

Greetings :D

User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Recover partition table for Linux LVM2

#2 Post by remy »

It's normal that there is no partition table in a disk you add in a LVM. Consider LVM like another way to partition, but not with classic MBR.

Please give results :
  • sudo sfdisk -luS

Code: Select all

sudo vgdisplay
sudo pvdisplay
sudo lvdisplay

kiper
Posts: 6
Joined: 31 May 2012, 21:43

Re: Recover partition table for Linux LVM2

#3 Post by kiper »

Hi, Remy! Thank you for your prompt response ;)

This the output for sudo fsdisk -luS:

Code: Select all

Disk /dev/sda: 8855 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sda1          2048   5859327    5857280  82  Linux swap / Solaris
/dev/sda2   *   5859328 142262271  136402944  83  Linux
/dev/sda3             0         -          0   0  Empty
/dev/sda4             0         -          0   0  Empty

Disk /dev/sdb: 8855 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdb1          2048 142262271  142260224  8e  Linux LVM
/dev/sdb2             0         -          0   0  Empty
/dev/sdb3             0         -          0   0  Empty
/dev/sdb4             0         -          0   0  Empty

Disk /dev/sdc: 8855 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdc1            63 142255574  142255512  8e  Linux LVM
/dev/sdc2             0         -          0   0  Empty
/dev/sdc3             0         -          0   0  Empty
/dev/sdc4             0         -          0   0  Empty

Disk /dev/sdd: 36472 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
 /dev/sdd: unrecognized partition table type
No partitions found
Output of sudo vgdisplay:

Code: Select all

 --- Volume group ---
  VG Name               gruporespaldos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               67.83 GiB
  PE Size               4.00 MiB
  Total PE              17365
  Alloc PE / Size       17365 / 67.83 GiB
  Free  PE / Size       0 / 0   
  VG UUID               FQj6H2-M4jm-4aHW-jcw4-Ujlp-FYW8-2ZAMA7
   
  --- Volume group ---
  VG Name               grupoprincipal
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  17
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               347.23 GiB
  PE Size               4.00 MiB
  Total PE              88890
  Alloc PE / Size       88889 / 347.22 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               BUZ3Pu-o7c1-Ofv8-JiGc-xhmx-7RzR-UjeFMo
Output of sudo pvdisplay:

Code: Select all

root@samnh:/# sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               gruporespaldos
  PV Size               67.83 GiB / not usable 716.00 KiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              17365
  Free PE               0
  Allocated PE          17365
  PV UUID               HkShVm-IHWC-bLrt-GuKE-aJdR-weNL-lbWAsj
   
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               grupoprincipal
  PV Size               67.83 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              17365
  Free PE               0
  Allocated PE          17365
  PV UUID               pnqq7s-IKD7-IiiO-3ZKK-ROxm-e98d-P6dRGM
   
  --- Physical volume ---
  PV Name               /dev/sdd
  VG Name               grupoprincipal
  PV Size               279.40 GiB / not usable 2.29 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              71525
  Free PE               1
  Allocated PE          71524
  PV UUID               KrJhaF-RcXj-Kt6F-12JU-WVxy-lJA0-kg4mnK
Output of sudo lvdisplay:

Code: Select all

 --- Logical volume ---
  LV Name                /dev/gruporespaldos/volumenlogicorespaldos
  VG Name                gruporespaldos
  LV UUID                Ii33yZ-bMIp-ov4P-8eGh-xNIr-r0Jl-FQ0n2u
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                67.83 GiB
  Current LE             17365
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           251:0
   
  --- Logical volume ---
  LV Name                /dev/grupoprincipal/volumenlogicovar
  VG Name                grupoprincipal
  LV UUID                D9EHYd-CrNw-Z0O5-16Is-CSeY-GLRp-42vepo
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                37.25 GiB
  Current LE             9536
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           251:1
   
  --- Logical volume ---
  LV Name                /dev/grupoprincipal/volumenlogicohome
  VG Name                grupoprincipal
  LV UUID                BgKO19-kp41-C0vJ-2p1z-nKtT-0UBi-Av8n1Y
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                309.97 GiB
  Current LE             79353
  Segments               4
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           251:2
My disk /dev/sdd is part of the LV /dev/grupoprincipal/volumenlogicohome.

Any other output you need I'll post it.

I have a question:
If I add a new partition, overwriting the current on /dev/sdd, ¿could I lose my data? My data in /home use about 20 GB, and the partition destinated for /home on the first disk, /dev/sdb1, has 30 GB available. My theory is: all my data is stored on the first partition, so if I create a new partition on the disk /dev/sdd, which is a physical volume of /home LV, and then resize the LV, I should have no problem, is that correct?

Thank you.

User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Recover partition table for Linux LVM2

#4 Post by remy »

You are wrong for two things :
- Your sdd disk is not part of the LV. The disk is a PV (Physical Volume) wich is part of the VG (Volume Group). This VG is splitted in thouthands of LE that are allocated to one or more LV (Logical Volume). Here, it's only one LV. So, thinking that sdd is art of your home LV is not totaly wrong, but really simplistic and quite not true.
-You are probably, perhaps, certainly right when saying that your data should be all located on sdb1 PV. But where is the proof ? And your LV will be detected as corrupted if one ore more PV is missing, and it will be harder to recover data.

I can't understand where is you problem at that point. You have all your PV, VG and LV. What did you loose ?

You first have to check your filesystem in this LV, and try to mount :

Code: Select all

sudo e2fsck -n /dev/mapper/grupoprincipal-volumenlogicohome
Do not forget -n there. It's only to diagnose and I don't want filesystem to be modified.

kiper
Posts: 6
Joined: 31 May 2012, 21:43

Re: Recover partition table for Linux LVM2

#5 Post by kiper »

Thank you, Remy, for clarifying my concepts.

This the output for sudo e2fsck -n /dev/mapper/grupoprincipal-volumenlogicohome:

Code: Select all

e2fsck 1.41.11 (14-Mar-2010)
The filesystem size (according to the superblock) is 98980864 blocks
The physical size of the device is 81257472 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort? no

/dev/mapper/grupoprincipal-volumenlogicohome contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Error reading block 81263643 (Invalid argument) while reading inode and block bitmaps.  Ignore error? no

e2fsck: Can't read an block bitmap while retrying to read bitmaps for /dev/mapper/grupoprincipal-volumenlogicohome
e2fsck: aborted
My problem is that Ubuntu Server (my OS) doesn't able to mount my /home partition (my LV) because it found an error when is starting:

Code: Select all

The filesystem size (according to the superblock) is 98 900 064 blocks
The physical size of the device is 81 257 472 blocks
Either the superblock or the partition table is likely to be corrupt!
/dev/mapper/grupoprincipal-volumenlogicohome: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY
Yes! It seems that is all right, but I can't see my data when I go to /home. I tried with fsck -v /dev/mapper/grupoprincipal-volumenlogicohome but without any result.

This is the output:

Code: Select all

root@samnh:/# fsck -v /dev/mapper/grupoprincipal-volumenlogicohome
fsck from util-linux-ng 2.17.2
e2fsck 1.41.11 (14-Mar-2010)
The filesystem size (according to the superblock) is 98980864 blocks
The physical size of the device is 81257472 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? no

/dev/mapper/grupoprincipal-volumenlogicohome contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Error reading block 81263643 (Invalid argument) while reading inode and block bitmaps.  Ignore error<y>?
...?
...?
...?
and so on...
The question is repeated many times as there are blocks. I pushed the y button of my keyboard all the weekend with a plastic piece, but the next Monday when I checked the result, nothing had happened.

Do you think my data was lost?


...And when I run mount this is the output:

Code: Select all

root@samnh:/# mount /dev/mapper/grupoprincipal-volumenlogicohome 
mount: wrong fs type, bad option, bad superblock on /dev/mapper/grupoprincipal-volumenlogicohome,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

root@samnh:/# dmesg | tail
[  675.587287] tg3: eth0: Link is down.
[  684.389323] tg3: eth0: Link is up at 100 Mbps, full duplex.
[  684.389327] tg3: eth0: Flow control is on for TX and on for RX.
[ 6322.290059] hub 5-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
[ 6322.302657] usb 5-1: USB disconnect, address 2
[ 6322.740027] usb 5-1: new low speed USB device using uhci_hcd and address 3
[ 6322.921499] usb 5-1: configuration #1 chosen from 1 choice
[ 6322.937612] input: Logitech Logitech USB Optical Mouse as /devices/pci0000:00/0000:00:1d.3/usb5/5-1/5-1:1.0/input/input5
[ 6322.937821] generic-usb 0003:046D:C018.0002: input,hidraw0: USB HID v1.11 Mouse [Logitech Logitech USB Optical Mouse] on usb-0000:00:1d.3-1/input0
[24208.161779] EXT4-fs (dm-2): bad geometry: block count 98980864 exceeds size of device (81257472 blocks)


User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Recover partition table for Linux LVM2

#6 Post by remy »

Tip of the day :
e2fsck -y /dev/mapper ... will avaoid to loose your week-end.

If it can't repair the filesystem, try to locate another superblock (with testdisk advanced menu, not analyse menu) and try to mount and/or repair providing info on this superblock to mount or to e2fsck.

You may also try to list files within testdisk ("P" key) and copy from testdisk, to another destination (longer but sometimes usefull)

kiper
Posts: 6
Joined: 31 May 2012, 21:43

Re: Recover partition table for Linux LVM2

#7 Post by kiper »

I did execute it but it did not repair the filesystem.

I found the backups for the superblocks and I did this:

Code: Select all

ubuntu@ubuntu:~$ e2fsck -b 32678 /dev/sdd
e2fsck 1.41.11 (14-Mar-2010)
e2fsck: Device or resource busy while trying to open /dev/sdd
Filesystem mounted or opened exclusively by another program?
In the Ubuntu forum I read that Slax, UNIX distribution, could help to solve this, but I'm confused because I don't know exactly where is my way to solve this. My dev/sdd disk lost the partition table and my LV volumenlogicohome can't to be initialized. I've tried with TestDisk but it doesn't find my partition as Intel, but as None, but I can rewrite it.

I was trying to remove the PV with the corrupted disk (/dev/sdd) but I can't because I don't have space enough to run pvmove. I want to force removing the PV, resize and reduce my LV, but I have not found a way to do this.

I can't list the files of the partition because it just shows a single partition, typed as Linux LVM, but doesn't show the two logical partition, /var and /home.

I'm so lost, sorry.

User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Recover partition table for Linux LVM2

#8 Post by remy »

I don't know why you tell your LV is not active : /dev/mapper/grupoprincipal-volumenlogicohome is there, but filesystem is corrupted. Your problem is not related to partition table with sdd, but with filesystem embedded in your LV-home.

The message tells the filesystem is busy : either you didn't finished another fsck, or it was mounted. Try to unmount, and retry e2fsck -y -b 32768...

Or reboot and try again this e2fsck as first command.

I don't know why you think slax will help you better than another gnu/linux distribution. e2fsck is still e2fsck, and lvm2 is still lvm2.

Don't know if I asked before, but may you send me your disks if you can't manage to rebuild datas ? Perhap I would have better results... If it's possible and you want it, ask by PM for more information.

kiper
Posts: 6
Joined: 31 May 2012, 21:43

Re: Recover partition table for Linux LVM2

#9 Post by kiper »

Maybe my problem is that I can't explain myself as I should because I don't speak English as my first Language, I'm mexican :D

The LV is active, is there, but I can't have access to my data on /home (my LV) because the PV dev/sdd partition table, allocated for LV /home, is corrupted, since fdisk -l can't create the partition table for it. Is there a way to force removing a PV, understanding that my data may be lost?

I'm going to try reboot and e2fsck as first command, thank you, it's so helpful.

Where are you from, Remy? Maybe I wouldn't be able to send my drives long distances because I need to solve this matter as soon as possible.

If I can't solve this I'm afraid I will reset the server configuration, lose my data and rebuild. There is time, what is missing is life :lol:

User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Recover partition table for Linux LVM2

#10 Post by remy »

I'm from France... too far from Mexique, I bet.

I'll try to explain with my own bad english, the LVM structure from PV to files.

1/ PV = Physical Volume = 1 disk. You add PVs in a VG
2/ VG = Volume Group = assembly of PV to create a biggest virtual hardware. You split VG in LV.
3/ LV = Logical volume = Part of the VG. Like a partition on a single drive.

From that, you can see that disk format (and MBR) is independant with LVM structure and filesystems... You can add non formatted media in a LVM...

4/ Filesystem : You create a filesystem in a LV. Generally speaking it's a bad idea to format a LV (format = create a partition structure) but it's possible. Never seen that, only for testing purpose.

5/ Files : in your filesystem, accessible when it's mounted, on a mountpoint.

You can there understand that your problem is about filesystem corruption, not about LVM corruption.
Your LV /dev/mapper/grupoprincipal-volumenlogicohome is present and active. So, nothing related with disk problems or partition table of sdd.
Your data are not accessible in /home because the filesystem embedded in your LV is not mounted on /home (it's only the mountpoint).
To mount, it has to be clean, but it's corrupted.
To repair you may use e2fsck, and then mount.

Locked