Subject: I mangled my root drive's disklabel. I need advice!
To: None <netbsd-help@NetBSD.ORG>
From: Robert Kennedy <robert@Theory.Stanford.EDU>
List: netbsd-help
Date: 05/08/1998 09:08:28
Last night while installing a new disk on my i486 system running
NetBSD 1.2, I mangled the disklabel on one of my existing drives (by
typing "sd0" where I meant "sd1"). I believe it will be more
satisfying and possibly even quicker to repair the damage done to the
disklabel than it would be to restore the portions of the disk that I
had backed up.

The first minor issue is this: I thought
"disklabel -r -R sd0 saved_label"
was supposed to change only the label actually on the disk, not the
kernel's in-core copy. And yet this single command appeared to change
both the in-core and the on-disk copy.

More importantly, here's my really pressing question. I stopped the
machine essentially immediately after I wrote the incorrect disklabel
on the drive, so I am relatively sure that no damage has occurred to
the two filesystems on that drive. The only information I need to
reconstruct the disklabel is the partition boundaries for that drive,
which I didn't have written down or saved anywhere.

Does anyone out there know enough about filesystems, disk partitions,
etc., and their associated magic numbers and so forth that they could
explain to me how to figure out where the partition boundaries on that
disk were?

It was a bootable disk containing four DOS partitions, the first three
of which were unused, and the last one of which was a NetBSD
partition. The NetBSD partition looked like this:

a: 4.2BSD root
b: swap
c: whole disk, ununsed
d: whole disk, unused
e: 4.2BSD /usr

As I said, the only thing I don't know is the partition sizes and
offsets. I know approximately how big the partitions were, and I know
that the a, b, and e were contiguous with one another (no blank space
in between). Surely there is a way to look at raw sectors from the
disk and
(0) verify the start sector (probably 1) of the "a" partition;
(1) figure out the size of the root filesystem, and hence the size of
    the "a" partition, and hence the offset of the "b" partition; and
(2) search for the start of the "e" partition's filesystem and do the
    same things for it.

Can anyone help me with advice on how to do this? You can assume I
know essentially nothing other than what this message implies I know.

Huge thanks in advance!

	-- Robert Kennedy