Setting up gmirror on a live server remotely.
March 30, 2009 | 11:16 pmI’ve previously discussed how to recover from a disk failure in gmirror. It’s probably a good idea to describe how to set up a new mirror from scratch.
Rather handily this can be done on a live system, remotely via ssh in the space of a few minutes. One reboot is required but other than that the process is seamless.
My existing install is on disk ad4 and the ’spare’ disk I want to mirror this existing installation to is ad6.
Both are 160 gig SATA disks.
Login in as root however way you see fit.
Before we can configure the new mirror we need to disable a safety feature of GEOM :
# sysctl kern.geom.debugflags=16
kern.geom.debugflags: 0 -> 16
This allows us to perform operations on a mounted, and in use disk. This is just set for the current session and will be reset to normal when we reboot - which we’ll be doing shortly.
Whilst we’re doing housekeeping, lets enable gmirror at boot :
# echo geom_mirror_load="YES" >> /boot/loader.conf
You should probably check your loader.conf first. On a fresh system its empty and the above command is safe, however you probably want to have a quick glance over it and backup your existing one as a precaution if it contains existing settings.
Lets create our new mirror - with one command :
# gmirror label -v -b round-robin gm0 /dev/ad4
Metadata value stored on /dev/ad4
And we’re done! We now have a gmirror device but with only one member - the existing disk.
There are a number of different balance algorithms to choose from, the gmirror man page steps in :
load, prefer,round-robin,split
Finding out information on how these actually perform under the hood (beyond the superficial explanation in the man page) is quite tricky. And indeed most information leads to the fact that they don’t really behave as hoped and you’re better off sticking with round-robin which does what it says and gives marginally the best performance.
If you want to test with your specific work load / pattern you can change this anytime you like :
gmirror configure -b load gm0
Now we have a mirror device, and have enabled the drivers to be loaded on boot - we need to tell our system to mount from it next boot. So we need to edit /etc/fstab. Take a backup of your existing one now!
What happens next depends on your specific install. In general you need to add /dev/mirror/ to each entry and you need to change your hard disk device to be gm0 (or whatever you chose in the above to call your mirror device).
So I had a previous entry :
/dev/ad4s1a / ufs rw 1 1
Which now becomes :
/dev/mirror/gm0s1a / ufs rw 1 1
Repeat for each mount point that contains reference to your existing disk. Make sure you get this right, any errors here means you won’t be booting back up without difficulty!
Once you’re happy - reboot!
Cross your fingers.
Wait anxiously.
Nervously fidget.
And you’re back! Log in and do a quick df, hopefully you should see something akin to :
/dev/mirror/gm0s1a 507630 141610 325410 30% /
Looking good so far. Lets check the mirror is up :
# gmirror status
Name Status Components
mirror/gm0 COMPLETE ad4
ok, so far so good. We’re up and running on our new mirror device. But it still only has one member. We need to add our second, ad6, disk.
#gmirror insert gm0 /dev/ad6
And we’re done! You’re now mirrored - your mirror is currently degraded :
# gmirror status
Name Status Components
mirror/gm0 DEGRADED ad4
ad6 (70%)
But will soon become complete when the new disk finished sync’ing.
# gmirror status
Name Status Components
mirror/gm0 COMPLETE ad4
ad6
And we’re done.
There are some caveats that should be mentioned.
I’ve run this config in anger in production for years now and never had problems - but there is a more complicated procedure to configure gmirror :
http://people.freebsd.org/~rse/mirror/
This takes into account the differening gemoetries of your two disks and avoids any problem with data going where it shouldn’t.
gmirror also seems to be a performance dog, especially when compared to Linux software RAID. Which is unfortunate.
http://www.freebsdwiki.net/index.php/RAID,_performance_tests
But it’s ease of use lets me put up with that. Although hopefully we will see improvements over the next few versions of FreeBSD.





