Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jun 2010 18:06:29 +1000 (EST)
From:      Ian Smith <smithi@nimnet.asn.au>
To:        Zhengtao Cui <zcui@gmx.com>
Cc:        Polytropon <freebsd@edvax.de>, freebsd-questions@freebsd.org, Xihong Yin <xyin@gmx.com>
Subject:   Re: detached a mounted ufs filesystem
Message-ID:  <20100615162911.N96036@sola.nimnet.asn.au>
In-Reply-To: <alpine.BSF.2.00.1006141958320.1302@qryy.zlubzr.jrfgryy.pbz>
References:  <20100613095242.3DF3110656F6@hub.freebsd.org> <20100614045646.H27982@sola.nimnet.asn.au> <alpine.BSF.2.00.1006141958320.1302@qryy.zlubzr.jrfgryy.pbz>

next in thread | previous in thread | raw e-mail | index | archive | help
I'm a little confused by your using two different names, so you might 
get two copies of this ..

On Mon, 14 Jun 2010, Zhengtao Cui wrote:

 > # bsdlabel /dev/da0s1
 > 
 > says
 > 
 > bsdlabel: unable to get correct path for /dev/da0s1: No such file or
 > directory.

Ok, there's no label on da0s1, as suspected.  And from your other reply 
to Polytropon, there's sure no label for 'dangerously dedicated' da0a:

 : 'fsck_ufs /dev/da0a' gives me the same result as /dev/da0.
 :
 : The 'newfs -N /dev/da0a' prints a very long list of numbers such as
 :
 : 160, 376512, 752864, 1129216, 1505568, 1881920, 2258272, 2634624, 3010976,
 : 3387328, 3763680, 4140032, 4516384, 4892736, 5269088, 5645440, 6021792,
 : 6398144, 6774496, 7150848, 7527200, 7903552, 8279904, 8656256, 9032608,
 : 9408960, 9785312, 10161664, 10538016, 10914368, 11290720, 11667072, 12043424, ......
 :
 : And I tried 'fsck_ffs -b 160 /dev/da0a', it says
 :
 : Alternate super block location: 160
 : ** /dev/da0a160 is not a file system superblock
 : 
 : Using /dev/da0 or other numbers in the list gives me the same results.

I hope you're using -d and/or -n switches to fsck_ffs as advised; you 
don't want to write to this disk until you're sure it's likely correct.

 > How do I make a fresh label if I have only 'c' and 'd' partitions?

See below; first you want to make sure you have a good backup of *at 
least* the first couple of tracks, so you can restore that if need be.

 > How do I dd the first 126 sectors to a file?

I suggest carefully reading dd(1) ('man 1 dd'), at least the relevant 
bits for copying whole sectors (ignoring block, ascii etc modes).  The 
default block/sector size is 512 but specifying it makes it clearer:

# dd bs=512 count=126 if=/dev/da0 of=/somepath/backup_da0_126sectors 

That said, it would be far better if you can temporarily spare the 
114GB space, to backup an image of the whole disk:

# dd bs=512 if=/dev/da0 conv=sync,noerror of=/somepath/backup_of_da0

If you can do that, you can use that image with bsdlabel -f file to play 
with the image first, only writing to the real disk when all looks good.

Or alternatively, if you get it wrong on the real disk, you could just 
dd back to da0 from the file (as above, but swapping if= and of=)

Now, bsdlabel.  Carefully read man bsdlabel, and if possible practice 
saving and editing some labels from a good disk but with the -n switch, 
so no changes are made; this will report what bsdlabel would do without 
the -n switch and report any problems found with the layout you specify.  

If you are not comfortable with vi (I'm not), you could set your shell's 
EDITOR variable to ee (or another) first.  I do this in my /root/.cshrc 
with 'setenv EDITOR ee'

All of that said, to stress being as careful as possible, the examples 
given in bsdlabel(8) are exactly what you need for da0s1 .. if you use 
the -f <file> switch you can do it all with your saved image instead:

=======
           bsdlabel -w /dev/da0s1

     Create a label for da0s1.

           bsdlabel -e da0s1

     Read the label for da0s1, edit it, and install the result.

           bsdlabel -e -n da0s1

     Read the on-disk label for da0s1, edit it, and display what the new label
     would be (in sectors).  It does not install the new label either in-core
     or on-disk.

           bsdlabel -w da0s1

     Write a default label on da0s1.  Use another bsdlabel -e command to edit
     the partitioning and file system information.

           bsdlabel -R da0s1 savedlabel

     Restore the on-disk and in-core label for da0s1 from information in
     savedlabel.

           bsdlabel -R -n da0s1 label_layout

     Display what the label would be for da0s1 using the partition layout in
     label_layout.  This is useful for determining how much space would be
     allotted for various partitions with a labeling scheme using %-based or *
     partition sizes.
=======

If the 'd' partition was the only one on this disk, as seems likely, 
then your label format should wind up looking like this, on your data:

# /dev/da0s1:
8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  c: 234436482       0    unused        0     0         # "raw" part, don't edit
  d: 234436482       0    4.2BSD

Please take care.  Personally, I always use sysinstall(8) or sade(8) to 
slice and label disks, so if my advice re this is incorrect, hopefully 
someone will chime in with something more correct, or perhaps easier.

cheers, Ian

[Leaving the tail quoted, for reference to the data, not my opinions :]

 > On Mon, 14 Jun 2010, Ian Smith wrote:
 > 
 > > In freebsd-questions Digest, Vol 314, Issue 13, Message: 22
 > > On Sat, 12 Jun 2010 22:38:15 -0400 "Xihong Yin" <xyin@gmx.com> wrote:
 > > 
 > > > 'fdisk /dev/da0' output is
 > > >
 > > > ******* Working on device /dev/da0 *******
 > > > parameters extracted from in-core disklabel are:
 > > > cylinders=14593 heads=255 sectors/track=63 (16065 blks/cyl)
 > > >
 > > > Figures below won't work with BIOS for partitions not in cyl 1
 > > > parameters to be used for BIOS calculations are:
 > > > cylinders=14593 heads=255 sectors/track=63 (16065 blks/cyl)
 > > >
 > > > Media sector size is 512
 > > > Warning: BIOS sector numbering starts with sector 1
 > > > Information from DOS bootblock is:
 > > > The data for partition 1 is:
 > > > sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
 > > >  start 63, size 234436482 (114470 Meg), flag 80 (active)
 > > >  beg: cyl 0/ head 1/ sector 1;
 > > >  end: cyl 1023/ head 254/ sector 63
 > > 
 > > Ok, the DOS partition table looks likely intact; it says you have one
 > > slice ad0s1 occupying the entire disk _after_ the first 63 sectors.
 > > 
 > > Checking .. 14593 * 255 * 63 = 234436545 sectors, less
 > > DOS partition 1 (FreeBSD s1) = 234436482 sectors equals 63 sectors,
 > > being all of cylinder 0, head 0; slices start on cylinder boundaries.
 > > 
 > > > The data for partition 2 is:
 > > > <UNUSED>
 > > > The data for partition 3 is:
 > > > <UNUSED>
 > > > The data for partition 4 is:
 > > > <UNUSED>
 > > >
 > > > I tried 'fsck_ufs /dev/da0', it says
 > > >
 > > > ** /dev/da0
 > > > Cannot find file system superblock
 > > > ioctl (GCINFO): Inappropriate ioctl for device
 > > > fsck_ufs: /dev/da0: can't read disk label
 > > 
 > > Yes, as it should.  You haven't lost your MBR & partition table, but it
 > > appears you may have lost the bsdlabel at the beginning of slice 1; this
 > > is likely why FreeBSD only finds /dev/da0 and (perhaps) /dev/da0a ..
 > > 
 > > In the absence of a label on slice 1 (listing FreeBSD partitions c, the
 > > whole slice, and one or more of a, b, d - h) the system seems to assume
 > > this is a 'dangerously dedicated' disk, with no slices, covering the
 > > whole disk - but still with no label.  I think the system is probably
 > > assuming wrongly here, from a missing or damaged label.
 > > 
 > > Polytropon's advice to dd the whole drive to somewhere is excellent if
 > > you have 114GB spare somewhere - but if you don't, at least dd the first
 > > 126 or so sectors to a file in case of further disasters.
 > > 
 > > > I forget what layout the disk has. Normally I used /dev/da0s1d to mount
 > > the disk.
 > > >
 > > > What the next step should I do?
 > > 
 > > First, to see if there's any meaningful label there, try just:
 > > 
 > > # bsdlabel /dev/da0s1
 > > 
 > > If that disk just had a single 'd' partition, as sounds maybe likely?,
 > > and it doesn't show up with the above command, then you may get away
 > > with just making a fresh label for the whole slice, with just 'c' and
 > > 'd' partitions, both of size 234436482 sectors.
 > > 
 > > I'm not the best person to advise on the right bsdlabel command, so I
 > > won't speculate (possibly mis-advising you) on that.  If you had other
 > > partitions than just 'd' in that slice then working out the boundaries
 > > and sizes will be a lot more complex, but if just one it looks fixable.
 > > 
 > > Of course, if the label at the beginning of slice 1 was clobbered, so
 > > may have been other data, but with a new label you might be able to
 > > recover it with 'fsck da0s1d' if the filesystem is more or less intact.
 > > 
 > > It's always worth keeping a copy of the output of bsdlabel for every
 > > FreeBSD slice somewhere safe (like on paper!) for times such as these.
 > > 
 > > cheers, Ian



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