["solved"] Re: harddisk failed strangely, badly need to recover data

Jerry McAllister jerrymc at msu.edu
Tue May 8 15:50:46 UTC 2007


On Tue, May 08, 2007 at 09:27:56PM +0800, Zhang Weiwu wrote:

> Actually this is not solved. I have discovered that it will not be easy
> to solve this problem and decided to accept the lose of data, that's how
> it "solved"/
> 
> Basically the accident took place because one line in /etc/fstab was
> wrong.
> 
> in /etc/fstab /dev/ad6s1c is used as swap, when FreeBSD boots, it
> use /dev/ad6s1c as swap, destroying data blocks around these sectors.
> 
> [root at exupery /var/backups]# disklabel /dev/ad6s1
> # /dev/ad6s1:
> 8 partitions:
> #        size   offset    fstype   [fsize bsize bps/cpg]
>   c: 312576642        0    unused        0     0         # "raw" part, don't edit
>   d: 312576642        0    4.2BSD     2048 16384 28552 
> 
> So in this case the 'c' partition as far as I can understand should not
> be used for any purpose. I didn't intentionally create 'c' partition,
> nor can I see this partition in Disk Label Editor of sysinstall. I don't
> know why it's there.

There is always a c: partition.   Note that it is marked 'unused' in
the fstype column.   That is the way it should be.  The c: partition
is how the system keeps track of the whole slice regardless of the
other partitions - and as such needs to be left alone.  I think sysinstall
just leaves it out of the display to reduce confusion for newbies.
But, it is really there and bsdlabel (disklabel in old systems) shows it.

If you used sysinstall and it assigned 'c:' to some data or swap partition
in the slice, then something bad happened that should never happen.  If
you can reproduce it, then you should report it as a serious bug using
sendpr.

Something is definitely wrong if your /etc/fstab  lists ad6s1c as
a swap partition.  If you did that, you will have to undo it and 
create a different partition for swap.   'b:' is commonly the identifier
used for swap.   If sysinstall did it, try to reproduce the error
and make a Problem Report.

> 
> Zhang Weiwu
> 
> On Tue, 2007-05-08 at 16:42 +0800, Zhang Weiwu wrote:
> > Dear list. I added a 160 GB harddisk to the FreeBSD server several days
> > ago. I have setup only one slice on it (/dev/ad6s1) and it has two
> > partitions on it.
> > 
> > /dev/ad6s1c is used as swap
> > /dev/ad6s1d is used as /var

Well, that means you or something did something wrong.  As indicated
above, 'c:' should not be used here.    If you divided the s1 slice
in to two partitions with one being assigned to swap, then you 
should see three partitions indicated in a bsdlabel display.
They should be 'c:' which refers to the entire slice, plus the
partition you created for swap and the other partition you created.
Likely those two would be either 'a:' and 'b:'  or 'b:' and 'd:'
with either a or d being the data partition and b being the swap.

First thing to do is get that line that specifiec partition 'c:' 
as swap.    Then, I don't know if you will be able to recover
anything from d: or not.   If the swapper wrote over it already - 
which it looks like it did - then just start over with the building
of that disk.   It looks like no filesystem as created by newfs is
on the d: partition which could possibly be the result of the swapper
overwriting the slice - eg c: partition.

Once you have reproduced the error and made the Problem Report, then
I would suggest manually recreating the disk system.

First, use dd to wipe out the mess.
     dd if=/dev/zero of=/dev/ad6 bs=512 count=28780514

Then fdisk the drive and create one slice.
     fdisk -I ad6

Initialize a base label in the slice
     bsdlabel -w ad6s1

Now, edit the slice label and make your two partitions.
     bsdlabel -e ad6s1

You will be put in to an edit session - probably 'vi' depending on
which editor is your default.   Ignore anything above the line that
says '8 partitions'
Below that you should have one line with the c: info looking something like:

> 8 partitions:
> #      size    offset  fstype   [fsize bsize bps/cpg]
>  c: 312576642      0    unused      0     0         # "raw" part, don't edit

Duplicate that line so there are three of them.
Edit the first one so it is called  'b:' and replace 'unused' with 'swap'  
and make the size you want to use for swap on this disk.

Then edit the third line so it is 'd:' and make it contain all
of the remainder of the slice and have reasonable fsize, bsize and bps/cpg.
I think if you leave them blank, the system will calculate reasonable
values for fsize, bsize and bps/cpg, but I haven't tried it that way.

It will look something like:

8 partitions:
#        size   offset    fstype  [fsize bsize bps/cpg]
 b:   2097152        0      swap
 c: 312576642        0    unused       0     0         # "raw" part, don't edit
 d:         *        *    4.2BSD    2048 16384     8


 (By using the '*' for size and offset the system will calculate offset
  for you (which, in this case would be 2097152) and make the size the
  rest of the usable space in the slice) 

Then, write and exit the editor.

Modify your /etc/fstab to add that extra swap partition as the /dev/ad6s1b  
partition  and  add that /dev/ad6s1d  partition with a mount point and 
appropriate values in the fstype, Options, Dump and Pass# columns - 
something like this:

/dev/ad6s1b          none        swap    sw           0       0
/dev/ad6s1d          /var        ufs     rw           2       2

Make sure the mount point ( '/var' in your example, ) has been created.

Then either reboot or  enter   'mount -a'   and  'swapon -a'

It should all work then,  except, of course, whatever you had tried
to put in /var before would all be gone (it is now anyway) so you will
have to recreate that stuff.    That probably can just be the
directory structure unless you had created some databases.


> > 
> > Today I decided to reboot the FreeBSD server because I messed up nfs
> > settings. After restart /var/ failed to mount. I was brought to a shell
> > where I am suggested to do fsck manually. fsck manually couldn't help
> > either:
> > 
> >         [root at exupery /home/zhangweiwu]# fsck /dev/ad6s1d
> >         ** /dev/ad6s1d
> >         Cannot find file system superblock
> >         
> >         LOOK FOR ALTERNATE SUPERBLOCKS? [yn] y
> >         
> >         32 is not a file system superblock
> >         28780512 is not a file system superblock
> >         57560992 is not a file system superblock
> >         86341472 is not a file system superblock
> >         115121952 is not a file system superblock
> >         143902432 is not a file system superblock
> >         172682912 is not a file system superblock
> >         201463392 is not a file system superblock
> >         230243872 is not a file system superblock
> >         259024352 is not a file system superblock
> >         287804832 is not a file system superblock
> >         SEARCH FOR ALTERNATE SUPER-BLOCK FAILED. YOU MUST USE THE
> >         -b OPTION TO FSCK TO SPECIFY THE LOCATION OF AN ALTERNATE
> >         SUPER-BLOCK TO SUPPLY NEEDED INFORMATION; SEE fsck(8).
> > 
> > I tried to fix it by do inga harddisk bad-sector checking for the
> > beginning 1GB of the harddisk (result is successful, no bad sector in
> > the beginning 1GB). The data on the harddisk is not modified/erased
> > during checking

I don't think this is bad sector.   It is the swapper overwriting
the filesystem superblocks.   It is because c: was used for swap.

Mostly, none of what you say below will work is the swapper overwrote 
things though you might be able to get some data back by poking through 
things manually.    It will probably actually be easier to recreate 
the data than go through that long and tedious process.

Good luck,

////jerry

> > 
> > Use 'dd if=/dev/ad6 bs=32k | hd -v | grep "19 01 54 19"' to locate the
> > super block and do some calculation to get the superblock sector number
> > (following an Internet article) and pass it to fsck_ufs like this:
> > 'fsck_ufs -b 12032 /dev/ad6s1d'. Under a lot of time pressure I
> > confirmed twice with 'y' for the following questions of whether or not
> > to set some values to default without fully understanding the questions,
> > later seeing more questions I stopped fsck by Ctrl+C.
> > 
> > Before running fsck I tried to backup the first 100MB data of /dev/ad6
> > using dd which should help me recover even if I destroyed superblock
> > of /dev/ad6s1d. Later I realized I have by mistake only backed up the
> > beginning 4.0MB of /dev/ad6
> > 
> > Is it possible now for me to recover the data in /var/
> > (especially /var/backups)? Thanks a lot in advance!
> > 
> > P.S. I am being really unlucky because this harddisk is mostly used for
> > backup purpose and thus is not backed up (who back up the back-up
> > harddisk?) and when I today failed to mount this harddisk, 0.5 hour
> > later the server being backed up by it has got an accident and need the
> > backup data to recover. 
> > 
> > _______________________________________________
> > freebsd-questions at freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> > To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
> -- 
> Zhang Weiwu
> Real Softservice
> http://www.realss.com
> +86 592 2091112
> 
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"


More information about the freebsd-questions mailing list