Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Recover LVM from a corrupted MBR
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
UX.MAN
n00b
n00b


Joined: 09 Mar 2013
Posts: 52

PostPosted: Mon Jul 21, 2014 2:16 pm    Post subject: Recover LVM from a corrupted MBR Reply with quote

Hi people,

I know this is not the right place to post this, but I have the expectation that you might help me out with this issue.
I have an LVM set on a 1 TB HDD that got corrupted. I has trying to install a distro called Manjaro to replace the Debian system I had; Manjaro installer has support for LVM, so I trusted I could instruct the installer to activate the PV and mount my storage LV to use it on the new system; I had 2 additional LV, one for the / filesystem and another one for swap. I instructed the installer to format the root and swap LV's as ext4, and after awhile the installer failed to mount them. I tried then to activate the PV's but it didn't find any, so I assume that the MBR or LVM got corrupted. I was able to make a backup of the MBR and got the LVM metadata:

http://pastebin.com/LHm1T2D6

I know there is a way to restore this data, but if the MBR is corrupted, how should I restore it?

NOTE: You will only find the original LVM with only the storage LV, which is the only one I care to restore.
Back to top
View user's profile Send private message
UX.MAN
n00b
n00b


Joined: 09 Mar 2013
Posts: 52

PostPosted: Mon Jul 21, 2014 3:31 pm    Post subject: Reply with quote

One extra detail, the HDD did not contain any DOS partition table, just the LVM VG.
Back to top
View user's profile Send private message
szatox
Guru
Guru


Joined: 27 Aug 2013
Posts: 391

PostPosted: Mon Jul 21, 2014 6:06 pm    Post subject: Reply with quote

Describe your drive's setup. If there was no partition table on HDD with LVM on it, you couldn't boot from it. So, was there some other device that failed?
What stopped working?
You might need a reinstall, or simply fix some tiny problem and carry on. Either way, don't write anything to that disk with LVM, if I get you right it's easy to fix, but we need more details to find actually a good solution.

If you're fine with ANY solution though, running any liveCD with lvm support should do the trick.
If volumes are invisible, run 'vgchange -ay' to activate them
Back to top
View user's profile Send private message
UX.MAN
n00b
n00b


Joined: 09 Mar 2013
Posts: 52

PostPosted: Mon Jul 21, 2014 6:17 pm    Post subject: Reply with quote

Yes, you are correct. There was no DOS partition table on the disk, just the LVM's volume groups. The boot filesystem and MBR boot code was stored on a separate disk, which is working. I don't know what the installer did (maybe I could ask the Manjaro's developers) but after it failed vgchange can't activate the volume group. I tryed to search for the physical volume with pvscan -v but it couln't find it either. So it looks like it's all screwed.
I don't care about booting the system itself (I could run a LiveCD), but I do want to retrive the data that's in the disk.


Last edited by UX.MAN on Mon Jul 21, 2014 7:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
szatox
Guru
Guru


Joined: 27 Aug 2013
Posts: 391

PostPosted: Mon Jul 21, 2014 6:24 pm    Post subject: Reply with quote

Ehm.... and system itself (installed on the other disk, one you used to boot from) works, right?
What does
'fdisk -l /dev/<disk with lvm>' show?

It seems you simply wiped that HDD. At this point solution might be "restore from backup" :roll:
Back to top
View user's profile Send private message
UX.MAN
n00b
n00b


Joined: 09 Mar 2013
Posts: 52

PostPosted: Mon Jul 21, 2014 6:31 pm    Post subject: Reply with quote

I was waiting for you to say that the next step would be restore from backup :lol:
Well, the other "system" is nothing but a single msdos partition formated as ext4 and the /boot filesystem, nothing else. /dev filesystem was in the root volume group on the other disk.
Back to top
View user's profile Send private message
UX.MAN
n00b
n00b


Joined: 09 Mar 2013
Posts: 52

PostPosted: Mon Jul 21, 2014 6:49 pm    Post subject: Reply with quote

Here's the fdisk -l output:

# fdisk -l /dev/sdb

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Back to top
View user's profile Send private message
UX.MAN
n00b
n00b


Joined: 09 Mar 2013
Posts: 52

PostPosted: Mon Jul 21, 2014 7:29 pm    Post subject: Reply with quote

NOTE: I didn't really wipe the disk. Something was changed whithin the first 512 bytes of the disk. I was able to restore some files using photorec, but I didn't want to use that method since the files will be all messed up.
Back to top
View user's profile Send private message
szatox
Guru
Guru


Joined: 27 Aug 2013
Posts: 391

PostPosted: Tue Jul 22, 2014 8:15 pm    Post subject: Reply with quote

Well, really have no idea.
fdisk shows no partitions at all, so you seem to be right that you haven't wiped it (installer would damage it creating partitions), but I'm afraid lvm device stack is too complex to play games like "configure it with the same settings and it will work".

I don't know how powerfull 'pvscan' is, perhaps it could recover from damaged first sector. You can give it a try, even though I wouldn't get to excited about it.

As a side note, it seems to be a good idea to at least use vgcfgbackup vgcfgrestore commands to backup metadata. I'm going to do it right now.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 32098
Location: 56N 3W

PostPosted: Tue Jul 22, 2014 9:31 pm    Post subject: Reply with quote

UX.MAN,

Let me summarise.
You have LVM on a bare disk and the LVM metadata is in a mess, so you can't read anything. The PV is a single drive.
The PV contains one or more LV. Exactly how many?

Have you ever used lvextend on any of these LVs?
The right answer is no. That means that each filesystem is in one contiguous piece of the drive.
In turn, that implies that if we can find the filesystem starts, then mount -o ro,offset= might work.

It will be useful to run testdisk an the drive and see if it finds anything.
Do not let it create a partition table for you. Just report what it finds, if anything.

I don't intend to suggest in place recovery but copying the data off might get be possible.

extent_size = 8192 Thats 8Mb chunks in each unit allocated to a LV

pe_start = 2048 (need to find out what that is)
pe_count = 238467 the number of 8Mb units in the PV

pv0-storage is in one piece.
segment_count = 1
Code:
start_extent = 0
extent_count = 238467
thats its start. The size is in 8Mb units.

If we knew what pe_start = 2048 meant, we have enough info to feed to mount ...
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2458
Location: Germany

PostPosted: Wed Jul 23, 2014 8:30 pm    Post subject: Reply with quote

If its linear and unfragmented, testdisk should find it and create a traditional partition for it.

Of course that's only if restoring with the VG data you got didn't work.

pe_start 2048 should be the 1MiB offset for LVM metadata. Just try with 1MiB or 2MiB, it's definitely some kind of MiB alignment by default.

In theory even creating a new PV / VG / LV with 100% size should just give you access to your data, at least that's how I read the cfg you posted, just one big LV for everything.
_________________
Linux-User @ VServer (Debian), Desktop (Gentoo), Netbook (Ubuntu), Router (OpenWRT), PDA (Cacko), Smartphone (Android)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum