Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Apr 2007 16:28:07 -0400
From:      Jerry McAllister <jerrymc@msu.edu>
To:        Amarendra Godbole <amarendra.godbole@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Moving existing FreeBSD system to a new harddisk...
Message-ID:  <20070418202807.GB58583@gizmo.acns.msu.edu>
In-Reply-To: <294439d20704180628j8598a14v31f84d171ac47708@mail.gmail.com>
References:  <294439d20704180628j8598a14v31f84d171ac47708@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hello,

> Hi,
> 
> I have FreeBSD 6.2 installed on a Dell Latitude D400 laptop. The
> harddisk is 40G, with FreeBSD occupying about 25G, and remaining to
> Windows. I have received a replacement for this hard disk, which is a
> bigger capacity one - 80G. I have to move the existing FreeBSD system
> from the old to the new hard disk. I did find something here:
> http://www.freebsddiary.org/driveswap.php. Still, I'd like to hear
> someone's experience regarding the same. Thanks!

Are you able to install that new disk while the old one is still
in the machine and functional?   If so, do the following:

Let's assume the old disk is ad0 and the new one is ad1 and MS
occupies the first slice (called primary partition) of each disk.
So, FreeBSD then is currently in /dev/ad0s2 and you want to put 
it in /dev/ad1s2.   

First do the MS install on the new disk (if you intend to also dup it) 
and then use an appropriate utility to create room for the second 
slice (s2) on the drive.   You may actually be able to first let 
FreeBSD fdisk break up the drive in to the required slices before 
installing MS - I haven't tried that.  I don't know if MS will 
respect the slicing done by FreeBSD.  It definitely will not respect
the MBR that FreeBSD writes, so at the least, you need to do the
install work on MS first and FreeBSD second, regardless of how
the slicing is done.

Just a note here.   MS uses the term 'Primary Partition' for the
same thing that FreeBSD calls a 'slice'.   There can be up to 4 of
these major divisions.    MS and Linux allow you to replace one of
the primary partitions with an 'extended partition', generally in 
slice 4 in which you can create subdivisions, also called partitions, 
but that are not 'primary'.   FreeBSD allows the 4 primary divisions
called slices.   In FreeBSD you can subdivide any or each of the
slices in to 'partitions' which are designated by letters a..h (except
that 'c' is reserved, 'a' must be root if it is a boot device and 'b'
is traditionally used for swap).    It is easy to get the terms slice
and partition scrambled and they have even been switched around in
some of the man pages, though someone made a pass at cleaning it up
a little while ago.

Having said all that, now back to the story.

Lets assume you now have your new with MS on slice (primary partition) 1
and have created an unknown type slice (primary partition) on slice 2.
You might have managed that with fdisk or with Partition Magic or
whatever.

Use fdisk to mark that slice 2  (ad1s2) as FreeBSD type and bootable
and to write out the FreeBSD MBR to the drive.

Then use bsdlabel to edit the partition table for slice 2 and
create the partitions you need and write out the boot sector
for that slice.

     bsdlabel -w -B da0s1
     bsdlabel -e da0s1

The first will write the boot sector and a stock partition table.
The second will bring up an edit session that you can use to edit
the partition table and create the partitions you want.

Let's assume you want the following, a typical setup for a machine
with all source and ports tree loaded and running a very small database.
and this matches, except in size, your current structure on your old disk.

In real life, use partitions that reproduce your actual old disk structure.

  a:  root       384 MB   
  b:  swap       1 GB    
  c:  reserved   lists size of entire slice
  d:  /tmp       512 MB 
  e:  /usr       4 GB     
  f:  /var       4 GB    
  g:  /home      All remaining space in the slice.

ignore all the stuff above the comment line with head labels for
  #        size   offset    fstype   [fsize bsize bps/cpg] 
Edit the sizes in the columns as follows:

   a:   786432        0    4.2BSD     2048 16384 32776
   b:  2572288   786432      swap
   c: 83886080        0    unused        0     0      # "raw" part, don't edit
   d:  1048576        *    4.2BSD     2048 16384     8
   e:  8388608        *    4.2BSD     2048 16384 28552
   f:  8388608        *    4.2BSD     2048 16384 28552
   g:        *        *    4.2BSD     2048 16384 28552

You might sometime want to tinker with the numbers under fsize, bsize, etc
but mostly they can be left alone.   The large remainder partition my
benefit, but probably the others are just right.

I assumed a size for 'c:' at exactly 40 GB.  It won't be.  Just leave
it at whatever the system thinks it is.

Now write and exit the editor and your partitions are created.
Run newfs on each partition except swap.

  newfs /dev/ad1s2a

Probably all of the defaults are what you want, except for possibly
that large remainder slice if you happen to either use very large
files or need extra inodes.   You will only know that from experience
with your own situation so just go ahead and take the defaults and
if either you run out of space with a huge number of inodes left
unused or run out of inodes with disk space left unused, then you
will later want to dump everything and re-newfs the partition and
then restore it.

All of this slice and partition and even newfs stuff can be done
from within sysinstall.  It comes out to the same thing.  It just
takes care of writing the commands for you. 

Once you have the partitions nicely newfs-ed, then create mountpoints
for them and mount them.  I like to use convenient names such
as /newroot, /newusr, /newvar, /newhome.   I don't bother transfering
/tmp, but you could, I suppose.   

So,  I think the defaults will work here just fine.
  cd /
  mkdir /newroot
  mount /dev/ad1s2a /newroot
  mkdir /newusr
  mount /dev/ad1s2e /newusr
etc, etc.

Once things are mounted, use dump/restore to copy over the old system.
This is best done in single user mode, though it could be done up
in multi user.  You would just risk something being changed after
it was copied.

  cd /newroot
  dump 0af - / | restore -rf -
  cd /newusr
  dump 0af - /usr | restore -rf -
etc, etc.

Once the dump/restores are done,  make sure /etc/fstab on the new
disk will be correct.   It should already be, if you are truly
duplicating the old system on the larger disk.

Then, swap the disks so the new one is in first boot position and reboot.   

It should be just happy to run from there.

This all takes longer and is more difficult to type out the instructions
than it is to actually do it, so don't be intimidated.

Good luck,

////jerry

> 
> Best,
> Amarendra
> _______________________________________________
> 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?20070418202807.GB58583>