Finding a partition...

Mark Suter mark at zwitterion.humbug.org.au
Sat Feb 26 22:03:23 EST 2000


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Folks,

The following script helped me recover my ext2 filesystems
after a misadventure with partitioning...  Here's what the
output looks like on a normal partition with an ext2 fs.

    # ./find_superblock_offsets.pl
       bytes  sectors   blocks
	1024        2        1
     8389632    16386     8193
    16778240    32770    16385
    25166848    49154    24577
    33555456    65538    32769

I used this to determine the offsets for my partition table.
Once the partition table had been restored, the filesystems
reappeared, none the worse for their journey in the void.

For all you people who use "/sbin/fdisk -l" to take a copy of
your partition table, I recommend you also note the output of
"/sbin/fdisk -lu" to record the sectors offsets as well, just
in case any of your partitions aren't on cylinder boundaries.

Yours sincerely,

- -- Mark John Suter | I know that you  believe  you understand
suter at humbug.org.au  | what you think I said, but I am not sure
Use GPG encryption   | you realise that what you  heard  is not
Ph: +61 4 1126 2316  | what I meant.                  anonymous

- ----------------------------- begin -----------------------------
#!/usr/bin/perl -w

use strict;

my $device = "/dev/hda1";

open OD, "/usr/bin/od --address-radix=d --format=x2 --width=2 $device |" or
    die "Unable to dump $device: $!\n";

printf("%8s %8s %8s\n", "bytes", "sectors", "blocks");

while (<OD>) {
    next unless /ef53/;

    # ef53 is the MAGIC for ext2, and it is 56 bytes in.
    my $offset = (split)[0] - 56;

    # Only report potential superblocks on sector boundaries.
    if (int($offset / 512) == $offset / 512) {
	printf("%8d %8d %8d\n", $offset, $offset / 512, $offset / 1024);
    }
}
- -----------------------------  end  -----------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: Public key available from Keyservers or http://www.uq.edu.au/~suter/

iD8DBQE4uJPx7EsZXfL+uzYRAoc0AJ4hzmx4ONROOz8O/WItI4Yvy4lpDgCfYqPW
TDJmBDGRKDDNj1bpcxtcqQc=
=6MM7
-----END PGP SIGNATURE-----




More information about the General mailing list