From owner-freebsd-questions Sun Dec 25 17:09:30 1994 Return-Path: questions-owner Received: (from root@localhost) by freefall.cdrom.com (8.6.9/8.6.6) id RAA20249 for questions-outgoing; Sun, 25 Dec 1994 17:09:30 -0800 Received: from hda.com (hda.com [199.232.40.182]) by freefall.cdrom.com (8.6.9/8.6.6) with ESMTP id BAA20236 for ; Mon, 26 Dec 1994 01:09:22 GMT Received: (dufault@localhost) by hda.com (8.6.9/8.3) id UAA03355; Sun, 25 Dec 1994 20:10:38 -0500 From: Peter Dufault Message-Id: <199412260110.UAA03355@hda.com> Subject: Re: HELP!! Boot block/disklabel wiped To: alan@math.ucsb.edu (Alan D. Trombla) Date: Sun, 25 Dec 1994 20:10:38 -0500 (EST) Cc: questions@freebsd.org In-Reply-To: <19941225173505.AAA6921@emile.math.ucsb.edu> from "Alan D. Trombla" at Dec 25, 94 09:35:05 am X-Mailer: ELM [version 2.4 PL24] Content-Type: text Content-Length: 3240 Sender: questions-owner@freebsd.org Precedence: bulk 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 #include #include #include #include #include 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