Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] recover LVM2 after erasing partition table
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
synss
Apprentice
Apprentice


Joined: 08 Mar 2006
Posts: 282
Location: Dijon > Berlin > Tokyo > Nürnberg > München

PostPosted: Tue Dec 18, 2007 8:59 am    Post subject: [SOLVED] recover LVM2 after erasing partition table Reply with quote

Ooops, I have been stupid I admit, but these things have to happen from time to time. I have been wanting to benchmark my LVM2 striped volume but I have used dd if=/dev/zero [EDITED] of=/dev/sda, I noticed pretty quickly and only gotten rid of the first 800M, I believe. My partition table used to look like

/dev/sda1 /boot ext2 64MB [EDITED]
/dev/sda2 / ext3 1G
/dev/sda3 LVM2
/dev/hda LVM2

/dev/sda3 and /dev/hda are in an LVM2 VG and contain /usr, /var, /var/tmp, /home, swap, a squashfs'ed backup from suse9 and a Debian base install + LVM support (that was meant for recovery).

I have just chrooted into the Debian system so that I get some working linux. And finally, I am connected to this computer via ssh from my OS X computer. Debian works right, I could mount --bind /dev into it form gentoo and it is connected to the internet; also mounted /proc from debian. I had just finished (obviously) to install Gentoo on this workstation, so it would not be a problem to download a stage and reinstall it, actually. The problem is:
Code:
sh-3.1# fdisk -l /dev/sda

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sda doesn't contain a valid partition table


And now, I am scared that I would lose everything on LVM as well...

One thing I might be able to do is to mount /home tar its content and scp it to the Mac and reinstall from scratch. Is there a solution other than backing up before there is power cut and starting anew? (Would be possible, though, and I am actually taring /home now).

One last thing is that I was logged in via screen so I can act in both the Debian chroot and what-used-to-be-gentoo.
_________________
Compress portage tree
Elog viewer
Autodetect swap


Last edited by synss on Wed Dec 19, 2007 6:56 am; edited 2 times in total
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Tue Dec 18, 2007 10:47 am    Post subject: Reply with quote

Why would you have 64GB for /boot, do you have like several thousands kernels to choose from or did you mean 64MB?

dd if=/dev/null of=/dev/sda doesn't do anything much, or did you mean if=/dev/zero? In that case, the area that you zeroed, is lost, and can not be rescued, not even by a data rescuing company or FBI, so you can forget about the data that resided on your boot and / partitions, and if you wrote more than the (I assume) 64MB+1G you can say good-bye to your LVM as well, at least, to the partition layout and the data that was actually overwritten.

testdisk and parted allow scanning for lost partitions (partition tables) and restoring them, maybe they will work for you.

If you know the exact partition size and layout (e.g. the exact commands you used to create this partition table in fdisk), you can also try to just manually restore the exact same layout by issuing the exact same commands. It may work.

If everything else fails, there are some forensics softwares that allow searching for useful data in raw stream, in app-forensics. However if the system is still running and you still have access to that data, make a backup of it while it's hot, and curse you for not making backups regularly. What do you do if your disk suddenly dies without warning (which is something any disk can do anytime), huh?

Also if the system is still running and the partition table was not re-read yet, it may be that your old partition layout can be obtained from /proc/partitions
Back to top
View user's profile Send private message
synss
Apprentice
Apprentice


Joined: 08 Mar 2006
Posts: 282
Location: Dijon > Berlin > Tokyo > Nürnberg > München

PostPosted: Tue Dec 18, 2007 11:25 am    Post subject: Reply with quote

Yes, sorry, I was a little excited...
You corrected well, it was a 64MB /boot. And dd if=/dev/zero of course. I have relatively recent backups for /home, too. So the best and possibly easiest solution is to reinstall... pain, :evil: but doable, though.

However,
Code:
sh-3.1# cat /proc/partitions
major minor  #blocks  name

   7     0      45912 loop0
   3     0  120060864 hda
   8     0  244198584 sda
   8     1      72261 sda1
   8     2    1004062 sda2
   8     3  243119677 sda3
 254     0    5242880 dm-0
 254     1    2097152 dm-1
 254     2    5242880 dm-2
 254     5   41943040 dm-5
 254     6    2097152 dm-6
 254     7    2936832 dm-7
 254     8   41943040 dm-8
 254     3    2097152 dm-3
   8    16   58605120 sdb
   8    17   58605088 sdb1

So maybe I can get the partition table back. And I am sure I did not overwrite over / (it was less than 1Gb, I noticed my mistake very quickly) so the LVM volumes should be fine.

Now, is the following scenario doable (that is a bit why I posted here):

From the Debian chroot:

I rewrite my partition table,
sync without rebooting (is it possible?)
reinstall Gentoo,
reconfigure the kernel (not very difficult)
dolilo
and reboot into Gentoo

That would be very nice, but I am not sure it works...

I know lvm keeps some stuff in /var, which I have put on LVM, hence it is safe, so?... if only the system is screwed, that would be fine with me.
_________________
Compress portage tree
Elog viewer
Autodetect swap
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Tue Dec 18, 2007 1:23 pm    Post subject: Reply with quote

1. Backup all the data you can still access (you tarred it already?)
2. Boot from Live CD or quit the chroot or something. I'd not access the disk while repartitioning it.
3. Restore the partition table and allow it to re-read the table. (sfdisk -R device)
4. Check if the partitions are correct with 'file -s /dev/partition' - if you found the correct entry points it should show something like '/dev/sda5: LVM2 (Linux Logical Volume Manager) , UUID: 123...'
5. Reboot (pray to the lilo god or install grub) and see if it still works.
6. If all else fails, repartition, reinstall and restore backup from 1.
Back to top
View user's profile Send private message
synss
Apprentice
Apprentice


Joined: 08 Mar 2006
Posts: 282
Location: Dijon > Berlin > Tokyo > Nürnberg > München

PostPosted: Wed Dec 19, 2007 7:04 am    Post subject: Reply with quote

I could recover my LVM2 volume:
    reboot from a Ubuntu CD
    rewrite the partition table
    sync disks
    get network
    sudo modprobe dm-mod && sudo aptitude install lvm2
    -> your points 3 and 4
    vgscan --mknodes
    vgchange -ay
    and e2fsck /dev/vg/*

The rest is reinstalling gentoo, so a bit time consuming ;) but I do not have to sit there...

All in all, it was not that bad. Good I have been fast enough on the ctr-C!

Thank you very much!
_________________
Compress portage tree
Elog viewer
Autodetect swap
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing 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