Welcome to Chucktips Hardware HELP WITH DEAD OS Installing FreeBSD Miscellaneous
 add article

HOWTO: Move FreeBSD to a new hard disk
Miscellaneous Posted by Jason on Sunday November 04, @10:13AM
from the old-data-new-drive dept.
This article 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.

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 the [spacebar] at the 10 second countdown.

boot -s
Press [enter] for the default shell.

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:

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


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.

Note: You can download the drivecopy shell script by clicking on the drivecopy.tar filename located on the right sidebar of this page. Issue the command tar xvf drivecopy.tar to untar the file.

You may need to modify the drivecopy shell script if you are using custom partitions. If you had selected the standard FreeBSD partitions at install, this file will work without modification.

To learn more about dump, restore and other unix commands, please read the man pages:

man dump
man restore
man tar
man mount
man adjkerntz

<  |  >


Related Links
  • Articles on Miscellaneous
  • Also by Jason
  • Contact author

    Lilliput Mini USB Computer Monitor

    If you have ever wanted to learn about Cisco Routers, check out my new book "Cisco Routers for the Small Business" - it's Cisco CLI for the Regular Guy!

  • Sponsors

    File Attachment
  • Click to download attachment drivecopy.tar
    10KB (10240 bytes)

  • The Fine Print: The following comments are owned by whoever posted them.
    ( Add a Reply )

    Over 10 comments listed. Printing out index only.
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Vince on Thursday December 12, @02:16PM
    I wanted to thank you for this. It was very helpful in enabling me to backup my FreeBSD firewall server that I run Ipfilter on. The only hangup I ran into was that for some reason the files in my /var slice didn't all transfer over to the new hard drive. So what I did was transfer them over via the 'cpio' command and the new harddrive then booted up perfectly.
    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by atlus on Monday March 24, @09:24PM
    Very thanks for the method. It is good for freebsd 4.5,4.6 and 4.7, Does it apply for 5.0 ,please? When I do it , it shows some permissions message. Thanks. Atlus
    [ Add a Reply to this ]
    Hint for beginners: use the script provided
    by nik on Tuesday April 29, @08:46PM


    I too would like to say thanks for posting this info. I had been planning to carry out the procedure for several weeks when the drive I was planning to replace started to die this morning.

    Fortunately the drive problems appear to be heat related, so I was able to get some error-free operation from it after freezing it and carefully wrapping it in an ice-pack.

    I then began the procedure. I made the mistake of re-writing my own version of based on a printout of this page. Because I was unfamiliar with the dump command, and because of the font in the printout, I didn't have enough spaces (and therefore not enough arguments). After checking the man page for dump and the downloadable script, I was able to get it to work. It was a little bit of stress I could have done without though.

    Once again, thanks for this useful information.

    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by John on Wednesday May 07, @01:03PM
    Thanks ! Great information, Works on FreeBsd 4.8, you have to add the /tmp mount point and that bumps /usr to 'g'
    I had just tried the g4u utility only to discover I had many slightly smaller drives I could build systems on. Using this method I was able to load my build onto the smaller drive no problem. Some notes I found:

    g4u (ghost 4 unix)
    Pro's - very easy to use, Fast.
    Con's - Won't work on a smaller drive. If drive is larger you end up with unpartitioned space which you then have to setup.

    Dump and Restore
    Pro's - Drive size won't matter as long as the new drive can hold the source. This is the best write-up on the process I've seen.
    Con's - Takes longer. An understanding of how your drives are detected/labeled is required. many more commands required so watch the typing.
    For the search engines :)
    How do I clone ghost duplicate replicate a hard drive hdd disk
    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Dmitry Chubatov on Thursday June 05, @12:23AM
    Hi. Great thanks! Works fine.
    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Alwyn on Wednesday July 09, @03:34PM

    Thanks for the info. Very useful, and worked as you described.

    The only problem I had was that /tmp on the new drive did not have to correct permissions, which caused some processes to fail (e.g. mySQL). A chmod 1777 /tmp sorted that out though, and it works a treat!


    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Jennifer Zhao on Tuesday August 26, @07:55PM
    Hi,Jason and everyone

    I have been using this for a couple of months to do full backup once a week. It worked very fine till yesterday.

    Last night, As usual,I started ./ to backup my FreeBSD4.3 server (Disk1) on another HDD(Disk2). Disk2 has been used successfully as backup for more than 10 times with same procedure of ./
    So it seemed the start up going smoothly, then I left the server room.
    This morning, when I came to check the server and backup. (which was supposed to have finished). And I surprised to find all those horrible error messages on the console screen:

    ***start to quote error message
    ad0s2e: had error reading fsbn 97103692 of 3473456-3473467(ad0s2 bn 97103692; cn 6044 fn 108 sn 28) status=59 error=40
    cannot read: BLK 3473456
    **end of error message quote
    So I had to force to suspend the backup process by pressing Ctrl+Z.
    Then I tried to reboot Disk1. I had problem during the booting process.

    **start to quote error message
    chflags: not found
    chown: not found
    cd: can't cd to /var/run
    cd: can't cd to /var/spool/lock
    /etc/rc: cann't create /var/run/dmesg.boot directory nonexistent
    cd: can't cd to /var/run
    /etc/rc: cannot ceate
    /var/run/clean_var:dirctory nonexitent.
    Enter full path of shell or return for /bin/sh
    **end of error message quote
    Then I tried my luck to boot Disk2.Unfortunately, it showed the same errors as Disk2 during booting.

    Can anybody tells me what I can do to recover those two HDD, Disk1 and Disk2?

    Your any advice will be highly appreciated.

    P.S. The attached is my,which had worked fine for the previous backup processes except yesterday. So I do not think anything wrong with the itself. There must be something wrong with my yesterday's backup process, though I can not find out what it is.
    Click to download attachment
    1KB (1074 bytes)

    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Pete on Monday October 06, @06:24PM
    I have done a clean, minimal install. I boot to it and I get a screen full of the number '40'. I am assuming I am not suppose to have this problem?
    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Anatoliy on Sunday February 08, @07:08PM
    Worked very nicely! Great howto!

    One thing though, I had to change ad1s1f to ad1s1g, but I guess it depends how one set's up his partitions. Mine were set up automaticaly at install time.

    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by John Campbell on Tuesday October 19, @10:01PM
    This worked great and really was well done. My only addition would be that you need to make sure you are on the same controller while doing this, or you will need to update /backup/root/etc/fstab.

    I needed to install a new IDE controller at the same time as my old one could not boot the new drive. So, I had to change ad0 to ad5 after the restore.

    thanks again!
    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Ed Hurst on Wednesday October 27, @02:26PM
    And how would we do this under 5.x, since the MAKEDEV script is no longer there?
    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by gm0neylove on Wednesday October 05, @01:41PM
    Great HOWTO. Many thanks for writing this.
    It worked quite well. Had to mash a few things into palce to get it all to work for me, but those were my fault.
    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Nafanya on Sunday August 20, @12:39PM
    Thanks for HOWTO. It helped me for many times.
    [ Add a Reply to this ]
    Re: HOWTO: Move FreeBSD to a new hard disk
    by Dan Phillips on Tuesday August 29, @04:35AM
    That worked nicely. Thanks. Some notes that people might find useful:

    * I had to change "e" to "d" in the script. On my system, /var is on the d partition, not e. That's how the disklabel program on the installation CD sets things up if you press "A" for auto.

    * I removed "tunefs -n enable /dev/ad1s1a" because by default the installer doesn't enable soft-updates on /, and I presumed there must have been a good reason for that.

    * in console mode, you can use the scroll lock key (with the arrow keys) to scroll up to check for errors. The script won't abort on errors.

    * dump gave a warning about the file system not being mounted read-only. I don't think that was anything, but my paranoia made me stop the script and remount the three file systems as read-only before restarting:

    mount -u -r /
    mount -u -r /var
    mount -u -r /usr
    [ Add a Reply to this ]
    The Fine Print: The following comments are owned by whoever posted them.
    ( Article Reply )

    "You never know how many friends you have until you own a Condo on the beach." -- Jason's Postulate

    Powered by Zope  Powered by Apache  Squishdot Powered
    All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest ©2001 Jason Neumann.
    [ main | post article | search ]