Creating RAID-1 with GPT on FreeBSD

Table of Contents

  • Preparing the system for GPT
  • Creating GPT partition tables
  • Restoring the data from backups
  • Migrating from MBR to GPT
  • Creating a software RAID-1 for your system

General Information

In this handbook we will see how you can create a software RAID-1 with GPT on a FreeBSD host.

This setup has been tested and is working properly under FreeBSD 8.0.

In the following handbook we will see how to setup a freshly installed FreeBSD 8.0 system with RAID-1 support and GPT.

You can also use this guide in order to migrate your MBR to GPT.

One more thing to add about this documentation is that we are going to create mirror of the partitions instead of the whole disks.

NOTE: In this documentation we will see how to create a RAID-1 on a FreeBSD host. During the implementation of the RAID-1 we will be creating mirror for the partitions, instead of the whole disks.

Some of you may be wondering what is the benefit of this approach, so here is a short list of pros and cons when using this approach.

Pros for creating mirror of the partitions, instead of the whole disks:

  • Able to mirror different in size disks
  • Can still create mirror for identical disks
  • Able to dual-boot between different OS

Cons for creating mirror of the partitions, instead of the whole disks:

  • In case of a disk failure you need to manually create all the partitions on the newly inserted disk(s)

NOTE: Starting from FreeBSD 8.2 gpart(8) now supports two additional options - backup and restore, which makes it very easy to recover your partitions when needed.

So to summarize this again - in this handbook we will show you a different approach of creating a RAID-1 on a FreeBSD host for partitions only and also how you can migrate from MBR to GPT.

Requirements

  • root access
  • 2 or more physical disks in order to create a RAID-1

Preparing the system for GPT

There are a lot of different approaches you can use in order to get FreeBSD booting from a GPT partition table. Currently sysinstall does not have support to create GPT scheme on your disks, so we will have to do this manually.

With the above being said, lets go into the real stuff..

Make a fresh FreeBSD install

The first method demonstrates how we can make a fresh FreeBSD install with RAID-1 and GPT.

NOTE: During the installation we will refer to the first disk as ad4 and the second disk as ad6.

Install FreeBSD 8.0 or later. Make partitions only on the first disk.

When you reach the Disklabel Editor menu, create the following partitions on the first slice of the first disk. We won't be touching the second disk at all during the installation of the system.

Create the following partitions - root, swap, usr, tmp and var. Each of these partitions is of the following sizes: root - 1GB, swap - 1GB, tmp - 1G, usr - 4GB and var - 1G.

NOTE: The reason that I've chosen these sizes for the partitions is that these partitions are actually going to be temporary and used only during the installation. Later in this document we will be re-creating the disk partition scheme.

So after I've created my partitions on the first disk, the layout is as follows:

  1. Part      Mount     Size    Newfs
  2. -----     -----     ----    -----
  3. ad4s1a    /       1024MB    UFS2
  4. ad4s1b    swap    1024MB    SWAP
  5. ad4s1d    /var    1024MB    UFS2+S
  6. ad4s1e    /tmp    1024MB    UFS2+S
  7. ad4s1f    /usr    4096MB    UFS2+S

Perform a Minimal install and go throught the post-install configuration steps.

Creating backups

Now that you have installed FreeBSD, boot into your freshly installed system and create backups of the partitions you have. We will restore their contents later when we create the GPT disk scheme.

You may want to use an external USB disk to store the backups or copy the backups on some other machine once you are done with them. In the following example I'm using an external USB disk to store the backups - da0.

So let's go ahead and create those backups.

Create a filesystem on the USB disk, if you haven't done this already.

  1. # newfs -O2 -U /dev/da0

Now mount the USB disk:

  1. # mkdir -p /mnt/usb
  2. # mount /dev/da0 /mnt/usb

Now make a backup of each partition you have - root, var, tmp, usr.

  1. # dump -0aL -f /mnt/usb/root.dump /
  2. # dump -0aL -f /mnt/usb/tmp.dump /tmp
  3. # dump -0aL -f /mnt/usb/var.dump /var
  4. # dump -0aL -f /mnt/usb/usr.dump /usr

If you do not have a USB disk, you may want to copy over the backups to another machine using OpenSSH. To do this just create the backups this way:

  1. # dump -0aL -f - / | ssh user@host dd of=/path/to/dumps/root.dump
  2. # dump -0aL -f - /tmp | ssh user@host dd of=/path/to/dumps/tmp.dump
  3. # dump -0aL -f - /var | ssh user@host dd of=/path/to/dumps/var.dump
  4. # dump -0aL -f - /usr | ssh user@host dd of=/path/to/dumps/usr.dump

Once ready with the backups, unmount the USB disk if you have used one:

  1. # umount /mnt/usb

Now we can continue to the next step - creating the GPT disk scheme.

Tags: