[linux-lvm] Lost partition table --> Lost 4th PV partition on disk - how to find the partition bounderies

gklima at cosy.sbg.ac.at gklima at cosy.sbg.ac.at
Mon Oct 30 21:49:44 UTC 2006

> /dev/hda4 : start= 51277968, size=144093600, Id=8e

I now found the correct starting sector: 51271920

The main clue I needed was the magic /^.{24}LVM2/, thanks for that!

and a friend of me who rewrote your code in python:

code by Michael Gschwanter:
import re,sys

isLVM = re.compile("^.{24}LVM2") # This is how the Sector should look like

if __name__=="__main__":
	args = sys.argv
	device = args[1]
	startSector = int(args[2])
	howMuch = int(args[3])
	endSector = startSector + howMuch
	print "Searching for LVM2 on %s. From Sector %d to

	dev = file(device,"r") # Read only, just for Security
	dev.seek(startSector * 512)
	t = 0
	while t < howMuch:
		sectorData = dev.read(512)
		m = isLVM.search(sectorData)
		if m:
			print "We found the Start sector of the pv at %d\n"%(startSector+t)
		t = t + 1


Usage:  ./findlvm.py  /dev/<deindevice>   startSector  maximumSectorsToTry

just used the output sector minus one!

Great thanks to all who tried and helped to save my data!!!


More information about the linux-lvm mailing list