Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Nov 2007 17:36:15 -0500
From:      Jerry McAllister <jerrymc@msu.edu>
To:        Sean Murphy <smurphy@calarts.edu>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Help Failing Disk Problem
Message-ID:  <20071105223615.GA63855@gizmo.acns.msu.edu>
In-Reply-To: <472F74A9.9090400@calarts.edu>
References:  <472F74A9.9090400@calarts.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Nov 05, 2007 at 11:53:13AM -0800, Sean Murphy wrote:

> I have a FreeBSD 6.2 Release box with a single ide that has user data 
> and the FreeBSD OS on a hard disk that is failing.  I need advice on the 
> best way to clone the entire disk (or at least the data) onto a larger 
> ide disk drive, then pull the failing disk and replace it with the 
> clone.  What is the best way in FreeBSD to do that?

If you can get the new disk physically installed and recognized and
running before the old disk completely fails, then it should be no
problem.   Build the file systems on the new disk as you want them,
then use dump/retore to move the data.   The dump/restore needs to
be done one filesystem at a time.   

NOTE: For best results, this should all be done in single user mode
      with no other thing running to avoid changes in files confusing
      things.   It will work in full multi user mode, but you may get
      some files in indeterminate condition if they happen to change
      during the copy process.

Either use sysinstall  (/usr/sbin/sysinstall) to slice and partition
the new drive and build file systems on it or do it yourself with
  fdisk, bsdlabel and newfs.    

Since you are using a larger drive, think out the sizes you want
for the partitions on the new drive.   I am guessing from the way
you talk here, that the system is not dual booted with some other OS.

Given that presumption:
  (This is right out of the bsdlabel man page, by the way.  I just
   changed numbers and device names to fit the situation)

NOTE: The dd-s below are just to make sure the label areas and such
      are wiped clean in case the manufacturer made some presumptions
      and wrote something there.   They might not really be needed, but
      won't hurt anything and take just a moment.

Create one large slice, marked bootable for FreeBSD:
  dd if=/dev/zero of=/dev/ad1 bs=512 count=1024
  fdisk -BI da0

Write a basic label and boot record on the slice:
  dd if=/dev/zero of=/dev/ad1s1 bs=512 count=1024
  bsdlabel -w -B ad1s1

Partition the slice by using the edit function of bsdlabel:
  bsdlabel -e ad1s1

This will put you in an edit screen with the beginnings of partition
information.   Ignore anything it might have before the lines that read:
  # /dev/ad1s1:
  8 partitions:
  #      size   offset    fstype   [fsize bsize bps/cpg]

After that you will see a list of partitions.  There should only be
one 'c' partition listed.   Do not change that line, but copy it 
enough times to have one for each partition you want.  Lets say you
want root, swap, /tmp, /usr, /var and /home.   Then make it 
something like:

 # /dev/ad1s1:
 8 partitions:
 #      size   offset    fstype   [fsize bsize bps/cpg]
 a:   524288        0    4.2BSD    2048 16384 32776
 b:  2572288        *      swap
 c: 78316875        0    unused       0     0        # "raw" part, don't edit
 d:  1048576        *    4.2BSD    2048 16384     8
 e:  4194304        *    4.2BSD    2048 16384 28552
 f:  6291456        *    4.2BSD    2048 16384 28552
 g:        *        *    4.2BSD    2048 16384 28552

Then just :wq out of the edit session and your label is nicely written.

Using the stars for offset and final size tells bsdlabel to calculate
the offsets for you and make the last partition take up all the 
remaining available space.   The first partition should have the
offset specified as '0'.    The numbers I have here are in 512 byte blocks
and give the following sizes.    Choose your own according to your needs.

 a:   256  MB    I mount as /
 b:  1256  MB    is swap
 d:   512  MB    I mount as /tmp
 e:  2048  MB    I mount as /usr
 f:  3072  MB    I mount as /var
 g:  Remainder MB  I mount as /home 

Once that is finished, then you need to run new fs on each partition
except the one for swap (b).   eg.  newfs a, d, e, f, g
Generally, unless you need extra inodes for a lot of small files
or expect only unusually large files, you can just take the defaults
for newfs.   so:

  newfs /dev/ad1s1a
  newfs /dev/ad1s1d
  newfs /dev/ad1s1e
  newfs /dev/ad1s1f
  newfs /dev/ad1s1g

Now you need to make mount points for and mount each partition.
Something like:

  mkdir /newroot
  mount /dev/ad1s1a /newroot
  mkdir /newusr
  mount /dev/ad1s1e /newusr
  mkdir /newvar
  mount /dev/ad1s1f /newvar
  mkdir /newhome
  mount /dev/ad1s1g /newhome

You don't usually need to copy /tmp to the new disk, though you
can do that if you want as well.

Then do the dump/restore-s

  cd /newroot
  dump 0af - / | restore -rf - 

  cd /newusr
  dump 0af - /usr | restore -rf -

  cd /newvar 
  dump 0af - /var | restore -rf -

  cd /newhome
  dump 0af - /home | restore -rf -

At the end of each dump it might ask you if you want to
set permissions on .   just answer no.   I don't think it does
that with the restore -r, but if it does, then answer no.

After all this, you should be able to just physically switch
the disks and boot on the new one.

////jerry


> 
> Thanks
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"



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