Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Mar 1996 19:00:19 +0100 (MET)
From:      "Christoph P. Kukulies" <kuku@gilberto.physik.rwth-aachen.de>
To:        imb@scgt.oz.au (michael butler)
Cc:        hackers@FreeBSD.org
Subject:   Re: Clobbered partititon table .. :-(
Message-ID:  <199603111800.TAA09773@gilberto.physik.rwth-aachen.de>
In-Reply-To: <199603111602.DAA12008@asstdc.scgt.oz.au>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> 
> How does one recover from the clobbered partition table that no longer
> exists after you try to install another drive with the 2.1 install disk ?
> 
> 	michael
> 

It happened to me, more than once. Once is ok, but twice is stupidity :-)
The program below (dirty hack) scans the disk for a FS_MAGIC.
Once found you can dd skip=n count=m if=/dev/rwd0 of=file
the disk to a file (provided you have enough space)
and do a
vnconfig /dev/vn0 file
mount /dev/vn0 /mnt

and recover the data.
You can even fsck /dev/vn0 first.
BTW, tar'ing a file from a vn device to a nfs mounted FS paniced
2.1 (reproducable). 



--Chris Christoph P. U. Kukulies kuku@gil.physik.rwth-aachen.de
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/param.h>
#define DKTYPENAMES
#include <sys/disklabel.h>
#include <ufs/ffs/fs.h>

/*
 */
#define DISKMAGIC       ((u_long) 0x82564557)   /* The disk magic number */

main(argc,argv)
  int argc;
  char **argv;
{
        int             i;
        char *dev;
    struct fs *f;
    struct disklabel *dl;
        struct stat     sb;
        off_t           lseek();
    off_t                       block=0;
        char            buf[2048];
        off_t           end;
        u_long         *l;
        off_t           offset = (off_t) 0;
        off_t           newoffset;
        int             ofd,fd, vd, n;
        if(argc==2)
                dev=argv[1];
    else
                dev="/dev/rwd0";
    printf("sizeof struct fs=%d\n",sizeof(struct fs));
    l = (u_long *) buf;
    f = (struct fs *) buf;
        dl = (struct disklabel *) buf;
        if ((fd = open(dev, O_RDONLY, 0)) == -1)
                fprintf(stderr,"error opening %s\n",dev),exit(1);
        if ((ofd = open("/mnt/dump", O_CREAT|O_WRONLY, 0666)) == -1)
                fprintf(stderr,"error opening %s\n","/mnt/dump"),exit(1);
        while(read(fd, buf, 2048)>0) {
      write(ofd,buf,2048);
          block+=2048;
/*        printf("\r%qd",block);fflush(stdout);*/
          if (*l == DISKMAGIC) {
                printf("\ndisklabel found at offset %qd (%qd MB/%qd)\n",
                       block-2048, (block-2048)/ (off_t) (1024), (block-2048) / 2048);
                printf("d_type=%d\n%s\nd_npartitions=%d\n", dl->d_type,
                       dl->d_typename,
                       dl->d_npartitions);
                for (i = 0; i < dl->d_npartitions; i++) {
                        printf("\t%d\t%d\t%d\t%s\n",
                               dl->d_partitions[i].p_size,
                               dl->d_partitions[i].p_offset,
                               dl->d_partitions[i].p_fsize,
                               fstypenames[dl->d_partitions[i].p_fstype]);
                }
      }
      if(f->fs_magic == FS_MAGIC )
             printf("fs at block # %qd last mounted on %s f->fs_ncyl=%ld
 (%d %d %d = %d)\n",(block-2048)/512,
                f->fs_fsmnt,
                        f->fs_ncyl,
                f->fs_ntrak,        /* tracks per cylinder */
                f->fs_nsect,            /* sectors per track */
                f->fs_spc , f->fs_spc*f->fs_ncyl                /* sectors per cylinder */);

  }
}




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