Print View

Migrate FreeBSD From One Harddrive To Another
Created: 10/23/2006


General Information

This guide will explain how you can move your FreeBSD installation from one hard disk drive to another.  I have done this many times using the dump/restore utility.  Before you begin, be sure you have read this document carefully.

Requirements

  1. Root Access or Sudo Rights.
  2. A List of Your Old and new Hardrive Information like /dev/ad* /dev/da* /dev/sd* and so on this can be checked by doing cat /var/log/messages and read the disctypes that come along.

Configuration

Let's assume that our FreeBSD installation is on a 4 gigabyte drive (ide master ad0) and we would like to move it to a new 20 gig drive.

What you need to do is remove the old hard disk, install the new [20G] drive as an ide master and perform a minimal clean install of FreeBSD, setting up the partitions exactly how you want them.  Be se sure to set the drive as bootable and boot from it one time as a test.

Next, put your old [4G] drive back in the system as an ide master and the new [20G] drive in as an ide slave.  Boot the system on your old installation in single user mode.

To boot in single user mode press 4 at the 10 second countdown.

At the (#) prompt type:
#
#
#
#
#
fsck -p
mount -u /
mount -a
swapon -a
adjkerntz -i
Next, make sure you have the device files made so you can mount the partitions on the slave drive.
#
#
#
#
cd /dev
./MAKEDEV ad1s1a
./MAKEDEV ad1s1e
./MAKEDEV ad1s1f
Now make mount points for the new drive's partitions:
#
#
#
#
mkdir /backup
mkdir /backup/root
mkdir /backup/usr
mkdir /backup/var
Lastly, I use a shell script to do the following:
  1. create new filesystems (newfs the drive)
  2. mount the partitions
  3. dump the data from my old drive, and restore it to my new one
  4. unmount the new drives partitions
  5. enable softupdates on the new drive (optional)
Here is the script I use:
#!/bin/sh
newfs /dev/ad1s1a
newfs /dev/ad1s1e
newfs /dev/ad1s1f

mount /dev/ad1s1a /backup/root
mount /dev/ad1s1e /backup/var
mount /dev/ad1s1f /backup/usr

( dump -0f - / ) | ( cd /backup/root ; restore -rf - )
( dump -0f - /var ) | ( cd /backup/var ; restore -rf - )
( dump -0f - /usr ) | ( cd /backup/usr ; restore -rf - )

umount /backup/root
umount /backup/var
umount /backup/usr

tunefs -n enable /dev/ad1s1a
tunefs -n enable /dev/ad1s1e
tunefs -n enable /dev/ad1s1f

#end
It will probably take several hours to perform the dump/restore, so be patient.  Once the data has been dumped and restored to the new drive, all you have to do is remove your old drive and put it in a safe place, set the new drive to a master and reboot.  Your system will now boot your old FreeBSD installation on your new hard disk.

Author: ShadowBumble
ShadowBumble at hotmail dot com



6 Comments

Posted by rhyous on March 06, 2007 at 5:22:04 pm EET

I followed this guide and it worked.

I was replacing an IDE drive with a SATA drive.  So my new drive detected as /dev/ad4 even when it was the only drive and my IDE drive detected as /dev/ad0.

The only step missing in this document was that I needed to replace all instances of ad0 with ad4 in /etc/fstab.

The other thing I noticed is that for /, /var, /usr, only /var and /usr have soft-updates enabled on a default install.  Is there a reason to enable soft-updates for /?


Posted by rhyous on March 09, 2007 at 1:07:36 am EET

I also found that the tunefs commands are not needed.  Newfs can set soft-updates with the -U parameter.

newfs /dev/ad1s1a
newfs -U /dev/ad1s1e
newfs -U /dev/ad1s1f


Posted by ShadowBumble on March 22, 2007 at 9:23:45 am EET

I eddited the Guide with a little info that ofcourse you need to change all example names into the drive paths of you own harddrives this divers from which type and disc your using.


Posted by yourmother on April 19, 2007 at 6:25:30 pm EEST

Seems like a lot of extra work [and it may be justified, by I'm just missing it].

Why not just hook up the new drive, and then:

- make new mount point on the original drive with /mnt as the root of the tree [for example, if you have /, /var, /usr and /home as mount points, you would create /mnt/var, /mnt/usr, /mnt/home as new mount points on the old drive.]

- run sysinstall, create new FS on drive [be sure to set slice to bootable] and create partitions on the new drive according to the new plan [make a mountpoint of /, but change it to /mnt, then create partitions of /mnt/var, /mnt/usr, /mnt/home, all of equal or greater size than the originals].

- "Write" the changes to the new drive in sysinstall.  Exist sysinstall, perform the dump/restore as above [newfs and everything has already been done].

- Edit /mnt/etc/fstab so that all mount points are appropriate for how you will be using the new drive [i.e., changing it from ad1 to ad0]

- turn machine off, set new drive up as master [or whatever is appropriate], and reboot.


Posted by rhyous on May 08, 2007 at 10:19:32 am EEST

That way works too.  You should email the author the steps, and I am sure he would add/change the content for simplicity.  If not, write up you own version of the guide.


Posted by ShadowBumble on May 16, 2007 at 10:35:07 am EEST

There are multiple ways to migrate and existing BSD installation to a new/bigger hard drive.
The way described by yourmother is also a very good and workable way, maybe simpler but the way i describe contains more info , maybe easier to follow for users doing it the first time or not too good familiar with BSD.

Eitherway thanks yourmother for the information it  can  be contained as additional or informational on my guide.


Copyright 2003 - 2010 BSD Guides.  All rights reserved.

About | Terms of Use | Privacy | Contact