Wednesday, January 03, 2007

Useful things when you've wiped you partition table

Doh! While trying to get my slax distro onto a USB key, I fucked up big time and dos formatted (mkfs.vfat) my hardrive (my head is still in the era where hard disks are hdX, not sdX).

gpart can try to guess where your partitions were but it doesn't know LVM2

LVM2 partitions have a sector which begins with "LABELONE" as documented in these slides (thanks to agk on #lvm!). I invoked the following script with ./ /dev/sda to get a list of all the sectors that contains that string.

#! /usr/bin/perl use strict; use warnings; my $buf; my $sector = 0; my $f = shift; open(F, $f) || die "couldn't open '$f', $!"; while(read(F, $buf, 512)) { if ($buf =~ /^LABELONE/) { print "sector = $sector\n"; } $sector++; } print "last sector was $sector\n";

Stuffing all those sector numbers into $ss and then doing

for s in $ss; do sudo perl -e 'open(F, "/dev/sda"); seek(F, shift()*512, 0); read(F, $buf, 512); print $buf' > sec.$s $s; done
gets me all the sectors in sec.XXX files. I can then
for s in $ss; do echo $s; echo; hexdump -c sec.$s; echo ;done|less
to take a look at them without trashing my console. The important thing to remember is that LABELONE will be followed by a secotr number. If it's 1 then this is sector 1 of the partition but really I'm looking for sector 0 so I need to subtract 1.

Post a Comment