This article should have been published already last month, unfortunately the draft was left forgotten for a while in my mailbox.
As some may remember I published two articles on how to setup GEOM disk mirroring on alpha and sparc earlier this year. These articles were originally based upon Ralf Engelschalls disk mirroring howto.
I had installed GEOM disk mirrors on various occasions since then, though I always felt that converting to a GEOM mirror like that involved too much work.
So I went on to find a better and faster way to achieve the task and I found one.
But be warned first: it is faster after all, even less error prone IMHO, but still dangerous if you are not very careful. Foremost you must consider that this procedure involves single user mode so local access (serial terminal for doing this remotely) is a must!
The instructions assume that you have two hard disks identical in size which are /dev/ad0 and /dev/ad1. Apply the instructions to fit your own system.
#1 Reboot into Single User Mode
#2 fsck and mount / fs read/write
First run an fsck on your root filesystem:
#fsck -p /
Then mount it with read/write access:
#mount -w /
#3 Edit /etc/fstab
First change your /etc/fstab. Replace all your single disk slices by the geom provider. The example shows a disk with a single root and swap slices.
# Device Mountpoint FStype Options Dump Pass# /dev/ad0s1b none swap sw 0 0 /dev/ad0s1a / ufs rw 1 1
Change it to look similar to this:
# Device Mountpoint FStype Options Dump Pass# /dev/mirror/gm0s1b none swap sw 0 0 /dev/mirror/gm0s1a / ufs rw 1 1
#4 Enable GEOM MIRROR kernel module
Edit your /boot/loader.conf and add the following line:
#5 Enable Crash Dumps (optional, but recommended)
If you want to enable crash dumps to your GEOM provider you should add this line to your /etc/rc.early:
gmirror configure -b prefer gm0
And this should go to your /etc/rc.local:
gmirror configure -b split gm0
Have a look at gmirror(8) to understand what this means exactly.
#6 mount / fs read-only
Sync and mount your root file system read-only. This is very important to complete successfully. This is also why you must do this in single user mode.
#sync && sync
#mount -r /
#7 Initialize GEOM provider
First you must raise the GEOM debug flags:
This will allow to initialize a GEOM provider even if it is locked by the kernel.
#gmirror label -v -b split gm0 ad0
Now it’s best to press the reset button (yes, you heard right!). This is absolutely safe as long as your root fs is in read-only mode.
Do not try to invoke reboot / shutdown as this will lead to a kernel panic. By labelling the GEOM provider you have taken away the underlaying device from the kernel.
Doing so will cause the machine to reboot after the panic, the reset button may be the better choice however.
Your system should now boot from the GEOM consumer gm0 with your /dev/ad0 as the first provider.
It does not actually matter if you boot into multi-user or single-user mode. In either case you must add the second hard drisk to the GEOM mirror.
#gmirror insert gm0 ad1
This will cause your /dev/ad1 to be synced against /dev/ad0. Your dmesg should print something like this when starting:
Aug 19 11:26:37 localhost kernel: GEOM_MIRROR: Device gm0: rebuilding provider ad1
And something like this when finished:
Aug 19 12:34:17 localhost kernel: GEOM_MIRROR: Device gm0: rebuilding provider ad1 finished.
Congratulations: your GEOM mirror is now up and running!
These instructions were originally put together when trying to upgrade my PC-BSD to a GEOM mirror. They have been verified at least a dozen times since then in the lab.