Another boot drive swap method

Swapping boot drives around

The NZ FreeBSD User Group was given a
box which was destined to become the cvsup and www mirror.  The first thing I did was
swap the two 500MB drives out and put in three 1GB drives.  This articles documents
how I did that.

You may wish to first read about a couple of other methods as supplied by other readers.

Overview

The following steps will be performed:

  1. backup the boot drive
  2. install FreeBSD on a new boot drive
  3. restore the old boot drive over the new boot drive.

This procedure assumes you have enough disk space for the backup.  I’m sure there
must be an easier way to do this.  If you know, please let us know your comments.   This
article also assumes you know how to add a new drive to a box, set up the
primary/secondary stuff (if using IDE) or set device IDs (if using SCSI).  The main
thing this article shows you is how I backed up and restored the boot drive.

The backup

For this exercise, I had three drives.  You could get away with just two.  I
mounted the spare drive in /mnt.

mkdir /mnt
mount /dev/da1s1e /mnt

The first step was to backup each file system on the boot drive.  This is slightly
more complex that I first thought.  If you look at the existing mount points, you’ll
see what I mean:

# mount
/dev/da0s1a on / (local, writes: sync 14 async 215)
/dev/da0s1f on /usr (local, writes: sync 3 async 95)
/dev/da0s1e on /var (local, writes: sync 91 async 237)
procfs on /proc (local)

In this example, you’ll see three mount points we must deal with: /, /usr,
and /var.  Each mount point represents a different file system.  I
decided to backup each separately.  I’m not sure why.  But I did.  I used
the tar command for this.

tar cvlf /mnt/root.tar /
tar cvlf /mnt/var.tar /var
tar cvlf /mnt/usr.tar /usr

Here is a brief explanation of each option:

  • p – same permissions – essential to a successful backup (not used above, but used below)
  • c – creates a new archive
  • v – lists the files as they go into the tarball
  • l – don’t cross mount points (backs up only one file system)
  • f – specifies that the next argument is the output tarball

Then I did a "shutdown -h now" and powered off the box once the
shutdown was complete (see the console messages for this).

Create a new boot drive

I removed the existing boot drive from the box and installed a new blank drive in it’s
place.  Then I went through the normal FreeBSD install process for that drive.  
Actually, it wasn’t a normal install as I need a custom kernel for this box because the
GENERIC kernel won’t work.  See Installing 3.2-release [the
hard way]
for details on that.  Otherwise, the install was pretty much the same
as Installing FreeBSD to replace Windows 95.

Then I
did a "shutdown -h now" and powered off the box once the shutdown was
complete (see the console messages for this).

Restoring the old to the new

The next step was to reinstall the original boot drive but retain the new boot drive.
  You must be careful to avoid conflicts.  In my case, I merely changed the SCSI
ID on the new boot drive from 0 to 2.

I mounted the spare drive:

mount /dev/da1s1e /mnt

I mounted the new boot drive.  You’ll remember that we had three file system to
backup.  So that requires three mount points.

mkdir /newboot
mount /dev/da2s1a /newboot
mount /dev/da2s1f /newboot/usr
mount /dev/da2s1e /newboot/var

Then I started restoring from /mnt to drive to the new boot drive:

tar xvpf /mnt/root.tar -C /newboot
tar xvpf /mnt/usr.tar -C /newboot
tar xvpf /mnt/var.tar -C /newboot

The -C option tells tar to change to the /newboot
directory before untar’ing any files.

Then I did a "shutdown -h now" and powered off the box once the
shutdown was complete (see the console messages for this).

Out with the old and in with the new

After shutting down the machine, I swapped the SCSI IDs of the new and old boot
drives.   The old one became 2 and the new one became 0.  I powered on the
machine, and it booted up straight away.  No problems.

Wait!  All my permissions are gone!

If you find that the permissions on your files are messed.  Perhaps everything is
either root or wheel.  Well, you probably haven’t restored your users from the tar
file.  Try that.

Other methods

People have responded to my query regarding easier ways to do these things.  
Thanks to those that have helped.

Duncan Barclay <dmlb@ragnet.demon.co.uk> supplied this information.  Thanks.

All you need to do to use another drive as a boot drive is the following:

  1. create a small freebsd partition on the target drive.  I have 2MB on my first ide
    drive.
  2. disklabel it, using the -B option to add some boot blocks (boot0 and boot1)
  3. newfs it
  4. mount it e.g. /mnt
  5. then use pax/tar/cpio to copy /boot to /mnt/boot
  6. edit /mnt/boot/loader.conf.local to have
    currdev=disk<n>s1a root_disk_unit=<m>
    where <n> is the BIOS disk number, and <m> is the scsi id number if you are
    booting from a scsi disk.
  7. reboot!

This is the scheme Duncan uses to have FreeBSD booted from his scsi drives in a mixed
ide/scsi setup.

Dean <madscientist@thegrid.net> supplied this.  Cheers.

  1. Shutdown system and add the drive that you want to be your new boot disk
  2. Partition the New Boot Drive the way you want and mount it on /mnt. ie: /mnt,
    /mnt/usr, /mnt/var, etc.
  3. Now, you simply copy the filesystems with tar. The command to do this is:
    tar clf - -C /    . | tar xpvf - -C /mnt
    tar clf - -C /usr . | tar xpvf - -C /mnt/usr
    etc
    using a dash as the filename causes tar to read/write from/to stdin/stdout. Not quite sure
    why you need the dot
    at the end of the first tar command, but that’s what they say in the man page.  I use
    it without the -p option and it
    seems to work fine, but again, the man page suggests you use it.
  4. Power off the machine, swap the scsi id’s and boot up.

No re-install required. You also don’t have to make sure you have enough space lying
around to hold the tarball.

Hope that helps,
Dean

Was this efficient?

I’m sure there are simpler ways of doing this.  For example, I think I could have
done this with a single tarball.  And I think I could have created a boot drive
without actually having to install FreeBSD on the new drive.  If you know of an
easier way, please add your comments.

Leave a Comment

Scroll to Top