gmirror - 1, 2, 3.
gmirror is one of the ways in which you can setup software RAID under FreeBSD systems. It’s shit simple, but I don’t do it often enough to keep it fresh. I’m putting this here so I can refer back to it when I need it.
db# dmesg |grep ad
FreeBSD is a registered trademark of The FreeBSD Foundation.
uhub0:
uhub1:
nfe0: Ethernet address: 00:e0:81:72:06:51
bge0:
bge0: Ethernet address: 00:e0:81:72:06:50
ukbd0:
ums0:
ad4: 114473MB
ad6: 114473MB
ad8: 476940MB
ad10: 476940MB
Trying to mount root from ufs:/dev/ad4s1a
That was to see where my drives are. I booted from ad4. ad4 and ad6 are two of the same drive so they will be my mirror.
Next, I need to get the system to allow me to muck with the drive that is currently in use.
db# sysctl kern.geom.debugflags=16
kern.geom.debugflags: 0 -> 16
After that I begin the real work. I’m going to load the gmirror driver, create the mirror and then add the second drive.
db# gmirror load
db# gmirror label -v -b round-robin gm0 /dev/ad4
Metadata value stored on /dev/ad4.
Done.
db# gmirror insert gm0 ad6
All that looks good, but I’d like this to function on a reboot. In order for that to happen, I need to tell the boot loader to get ready, and point fstab toward the gmirror device rather than either of the specific hard drives.
db# echo geom_mirror_load=\”YES\” >> /boot/loader.conf
db# sed s%ad4%mirror/gm0% /etc/fstab > /tmp/fstab
Now, I check my work.
db# cat /tmp/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0s1b none swap sw 0 0
/dev/mirror/gm0s1a / ufs rw 1 1
/dev/mirror/gm0s1e /tmp ufs rw 2 2
/dev/mirror/gm0s1f /usr ufs rw 2 2
/dev/mirror/gm0s1d /var ufs rw 2 2
/dev/acd0 /cdrom cd9660 ro,noauto 0 0
Looks good. Let’s make it happen.
db# mv /tmp/fstab /etc/fstab
Now, for the moment of truth.
db# reboot
After logging in:
db# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/mirror/gm0s1a 4.8G 197M 4.3G 4% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/mirror/gm0s1e 1.9G 12K 1.8G 0% /tmp
/dev/mirror/gm0s1f 54G 1.3G 48G 3% /usr
/dev/mirror/gm0s1d 44G 372K 40G 0% /var
db# swapinfo
Device 1K-blocks Used Avail Capacity
/dev/mirror/gm0s1b 4194304 0 4194304 0%
Sweet. That wasn’t hard, right?
The following is JUST the steps I took without any output.
sysctl kern.geom.debugflags=16
gmirror load
gmirror label -v -b round-robin gm0 /dev/ad4
gmirror insert gm0 ad6
echo geom_mirror_load=\”YES\” >> /boot/loader.conf
sed s%ad4%mirror/gm0% /etc/fstab > /tmp/fstab
mv /tmp/fstab /etc/fstab
reboot
There you have it. Plain and simple. Next comes my ZFS games.