Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Dec 1994 20:10:38 -0500 (EST)
From:      Peter Dufault <dufault@hda.com>
To:        alan@math.ucsb.edu (Alan D. Trombla)
Cc:        questions@freebsd.org
Subject:   Re: HELP!! Boot block/disklabel wiped
Message-ID:  <199412260110.UAA03355@hda.com>
In-Reply-To: <19941225173505.AAA6921@emile.math.ucsb.edu> from "Alan D. Trombla" at Dec 25, 94 09:35:05 am

next in thread | previous in thread | raw e-mail | index | archive | help
Alan D. Trombla writes:
> 
(...)
> How can I reconstruct a disklabel? Is the disklabel/partition info 
> stashed in some other well-known location on disk?  Do superblocks
> know about there own partition?  Other partitions?  How can I locate a
> superblock --- do they have some kind of magic cookie that I could
> scan for?

Here is a program that might help you.  I wrote it when I accidentally
trashed my disk label on a two partition drive and couldn't bear the
thought of hours of spinning tapes to get it back.  Two lessons - be
careful when labeling disks and print out your labels (or at least store
them on other drives).

As long as your label is fairly simple you should be able to find the
partitions.  Look for "hits" 16 blocks apart.  Here is the label
on one of my drives:

> 8 partitions:
> #        size   offset    fstype   [fsize bsize   cpg]
>   a:    65536        0    4.2BSD     1024  8192    16   # (Cyl.    0 - 31)
>   b:    65536    65536      swap                        # (Cyl.   32 - 63)
>   c:   586764        0    unused        0     0         # (Cyl.    0 - 286)
>   d:   586764        0    unused        0     0         # (Cyl.    0 - 286)
>   e:   455692   131072    4.2BSD     1024  8192    16   # (Cyl.   64 - 286)

And here is some of the output from findfs.  This is around the two
partitions starting at 0 and 131072.

Each "hit" is a superblock:

> hda.com# ./findfs /dev/rsd0c 0 100
> Checked block 0
> !!! Hit at 16 !!!
> 16
> !!! Hit at 32 !!!
> 32
> hda.com# ./findfs /dev/rsd0c 131000 132000
> Checked block 131072
> !!! Hit at 131088 !!!
> 131088
> !!! Hit at 131104 !!!
> 131104
> hda.com# 

Note that the first superblock "hit" will be 16 blocks beyond the
start of the partition and there will always be an alternate
superblock (another hit) 16 later.  That is a good signature for
the start of a partition.  This only works for 512 byte sectors.

++++Start of findfs.c:

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <ufs/ffs/fs.h>

#include <errno.h>

char buff[8192];

int check(int fid, int block)
{
	struct fs *fs;

	if (lseek(fid, (off_t)block * 512, SEEK_SET) == -1)
	{
		perror("lseek");
		exit(-1);
	}

	if (read(fid, buff, sizeof(buff)) != sizeof(buff))
	{
		perror("read");
		exit(-1);
	}

	fs = (struct fs *)buff;

	if (fs->fs_magic == FS_MAGIC)
	{
		fprintf(stderr, "!!! Hit at %d !!!\n", block);
		printf("%d\n", block);
		fflush(stdout);
		return 1;
	}

	return 0;
}

main(int argc, char *argv[])
{
	FILE *f;
	int block, start, end;
	int fid;

	if (argc != 4)
	{
		fprintf(stderr, "usage: %s device start_block end_block.\n",
		 argv[0]);
		exit(-1);
	}

	f = fopen(argv[1], "r");
	if (f == 0)
	{
		perror(argv[1]);
		exit(errno);
	}

	sscanf(argv[2], "%d", &start);
	sscanf(argv[3], "%d", &end);

	fid = fileno(f);

	for (block = start; block <= end;block++)
	{
		check(fid, block);
		if ((block % 4096) == 0)
			fprintf(stderr, "Checked block %d\n", block);
	}
}

----End of findfs.c.

Peter


-- 
Peter Dufault               Real Time Machine Control and Simulation
HD Associates, Inc.         Voice: 508 433 6936
dufault@hda.com             Fax:   508 433 5267
++++ New e-mail address.  E-mail problems? Tell hdslip@iii.net



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199412260110.UAA03355>