Providing practical examples since 1998

Things look quiet here. But I've been doing a lot of blogging at
dan.langille.org because I prefer WordPress now.
Not all my posts there are FreeBSD related.
I am in the midst of migrating The FreeBSD Diary over to WordPress
(and you can read about that here).
Once the migration is completed, I'll move the FreeBSD posts into the
new FreeBSD Diary website.

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:

backup the boot drive

install FreeBSD on a new boot drive

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:

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.

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.

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.

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

create a small freebsd partition on the target drive. I have 2MB on my first ide
drive.

disklabel it, using the -B option to add some boot blocks (boot0 and boot1)

newfs it

mount it e.g. /mnt

then use pax/tar/cpio to copy /boot to /mnt/boot

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.

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.

Shutdown system and add the drive that you want to be your new boot disk

Partition the New Boot Drive the way you want and mount it on /mnt. ie: /mnt,
/mnt/usr, /mnt/var, etc.

Now, you simply copy the filesystems with tar. The command to do this is:tar clf - -C / . | tar xpvf - -C /mnttar 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.

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.