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.
Adding gmirror to an existing installation24 June 2008
I will use the box as a workstation for developing FreshPorts, writing articles
for FreeBSD Diary, and everyday use. The box has plenty of spare cycles and
extra disk space. I will put that to good use by creating several jails on it.
The various jails will perform these functions:
Downloading database backups and test loading them (FreshPorts, BSDCan, etc)
That may not sound like much, but there will be at least 8 jails on this server.
Bacula regression testing will be against both MySQL and PostgreSQL and several
versions of each of those databases.
Today I will be adding RAID-1 to this server. Software RAID. I will make use
of the FreeBSD gmirror
FreeBSD is already installed
On this system, FreeBSD is already installed. Usually,
one sets up gmirror when installing the base system. In this case,
I will boot from a FreeBSD 7.0-RELEASE LIVE CD and use that to setup
the RAID-1 cluster.
Identify the HDD
When setting up gmirror, you will tell it to use one HDD as the master.
The other will be a slave. These are not the correct technological terms,
but they will do for my purposes. The critical part of this process is
making sure that you select the correct HDD for the master. If not, you will
lose your installed system.
My cunning plan to correctly identify the HDD was simple. Boot from the HDD
and create a distinctly unique filename in the root directory. Then boot
from the live CD, mount the HDD, and find the file. Simple. What could go
Starting the live CD
The ISO image I downloaded was 7.0-RELEASE-amd64-livefs.iso. The livefs part
is the key. You boot this like any other CD. From the main menu, select
Fixit, then CDROM/DVD. You should then see a Fixit#
Find the right HDD
Using dmesg I found I had two HDD mounted, ad4 and ad6. Let's try
mounting them and see what I can find:
Fixit# mount /dev/ad4s1 /mnt
Fixit# ls /mnt
NOTE: that's not the actual directory listing output. It is made up.
The key is that odd looking file name. It identifies the HDD that
I do not wish to keep. All data on this HDD can be lost.
Therefore, I know that ad4 is the slave HDD.
Now let's try the other HDD and see what it contains:
Again, this is not a copy/paste. It may not represent exactly what I saw.
The key point: there is no special file. I know that ad6 is the master HDD
to use in the gmirror solution.
Setting up the mirror/duplex
I have before me, a copy of The Best of FreeBSD Basics by Dru Lavigne.
I used the section Using Software RAID-1 With FreeBSD. This is not
the first time I've used this documentation. I previously upgraded my
gateway/firewall box to use gmirror.
The first step is to create a mirror/duplex. It is critical that you specify
the drive that you wish to mirror, i.e. the master drive. In my case, as
found above, that drive is /dev/ad6.
Fixit# gmirror label -v -b round-robin gm0 /dev/ad6
Metadata value stored on /dev/ad6
This created gm0 and uses /dev/ad6 as the master for this mirror.
At this stage, the data has not yet been mirrored. All we have done is
specify that we want to mirror.
Mount the main HDD for editing
I will now mount /dev/ad6s1 so I can alter a few files.
Fixit# mount /dev/ad6s1 /mnt
Start gmirror at boot
The following line was added to /mnt/boot/loader.conf to ensure gmirror
started at boot time:
Instead of mounting /dev/ad6* at the next boot, we want to mount /dev/mirror/gm0.
This is how FreeBSD will access your HDD, not directly, but through the mirror.
This is similarly to how hardware RAID works; the RAID cards presents a device
to the OS, and the OS accesses that device, e.g. twed0.
I will now alter /mnt/etc/fstab. I will change all
ad6 references to mirror/gm0
I then rebooted the system. However, it booted from ad4 instead of ad6.
That's a problem. It needs to boot from ad6. I was able to fix this in
the BIOS. But not before playing around and trying to find a solution
from the boot loader prompt. I found this would work:
After getting the system booted from the correct HDD, things went much smoother.
So far, we have set up the mirror and specified the source for the mirror. Now we
want to add the other half of the mirror into the system. That other drive is
/dev/ad4. I used this command: