Using Software RAID-1 with FreeBSD
Pages: 1, 2
Booting into the Mirror/Duplex
If you watch your boot-up messages, you should see this in bold white text right after the disks are probed:
GEOM_MIRROR: Device gm0 created (id=2125638583). GEOM_MIRROR: Device gm0: provider ad0 detected. GEOM_MIRROR: Device gm0: provider ad0 activated. GEOM_MIRROR: Device gm0: provider mirror/gm0 launched. GEOM_MIRROR: Device gm0 already configured. Mounting root from ufs:/dev/mirror/gm0s1a
and the system will continue to boot. However, if you have a typo in /etc/fstab, the boot will stop at this point and wait for you to type something meaningful. In this example, I forgot to insert
mirror when I edited /etc/fstab, meaning
/dev/gm0s1a should have been
/dev/mirror/gm0s1a so that FreeBSD could find my root filesystem:
Mounting root from ufs:/dev/gm0s1a setrootbyname failed ffs_mountroot: can't find rootvp Root mount failed: 6 Manual root filesystem specification: <fstype>:<device> Mount <device> using filesystem <fstype> e.g. ufs:da0s1a ? List valid disk boot devices <empty line> Abort manual input mountroot>
Fortunately, that's not as scary as it looks. Start by listing your valid disk boot devices:
mountroot> ? List of GEOM managed disk devices: mirror/gm0s1f mirror/gm0s1e mirror/gm0s1d mirror/gm0s1c mirror/gm0s1b mirror/gm0s1a mirror/gm0s1 ad2s1 mirror/gm0 ad0s1 ad2 acd0 ad0 fd0
If you type in the correct location of the / filesystem, the system will continue to reboot:
mountroot> ufs:/dev/mirror/gm0s1a Mounting root from /dev/mirror/gm0s1a
After logging in, be sure to edit the offending line in /etc/fstab and try rebooting again. When you can boot up and log in successfully, verify that each partition on the mirror mounted successfully with:
% df -h Filesystem Size Used Avail Capacity Mounted on /dev/mirror/gm0s1a 248M 35M 193M 15% / devfs 1.0K 1.0K 0B 100% /dev /dev/mirror/gm0s1e 248M 12K 228M 0% /tmp /dev/mirror/gm0s1f 7.3G 99M 6.7G 1% /usr /dev/mirror/gm0s1d 248M 196K 228M 0% /var
df won't show your swap partition; you can verify it with:
% swapinfo Device 1K-blocks Used Avail Capacity /dev/mirror/gm0s1b 629544 0 629544 0%
Synchronizing the Mirror/Duplex
The only thing left to do is to synchronize the data on both hard drives. This will happen automatically as soon as you issue the command to insert the second drive into the mirror:
# gmirror insert gm0 /dev/ad2 GEOM_MIRROR: Device gm0: provider ad2 detected. GEOM_MIRROR: Device gm0: rebuilding provider ad2.
To see what's happening:
# gmirror list | more Geom name: gm0 State: DEGRADED Components: 2 Balance: round-robin Slice: 4096 Flags: NONE GenID: 0 SyncID: 1 ID: 2125638583 Providers: 1. Name: mirror/gm0 Mediasize: 10262568448 (9.6G) Sectorsize: 512 Mode: r6w5e2 Consumers: 1. Name: ad0 Mediasize: 10262568448 (9.6G) Sectorsize: 512 Mode: r1w1e1 State: ACTIVE Priority: 0 Flags: DIRTY GenID: 0 SyncID: 1 ID: 3986018406 2. Name: ad2 Mediasize: 10262568448 (9.6G) Sectorsize: 512 Mode: r1w1e1 State: SYNCHRONIZING Priority: 0 Flags: DIRTY, SYNCHRONIZING GenID: 0 SyncID: 1 Synchronized: 1% ID: 1946262342
SYNCHRONIZING on the
Flags line. It will take a while for these two drives to synchronize, as it is currently at 1 percent. I've seen times ranging from about 30 minutes for a 10GB drive to about two and a half hours for a 75GB drive. If you're curious, check the progress with:
# gmirror status Name Status Components mirror/gm0 DEGRADED ad0 ad2 (2%)
You'll see a status message in bold white text when the synchronization finishes:
GEOM_MIRROR: Device gm0: rebuilding provider ad2 finished. GEOM_MIRROR: Device gm0: provider ad2 activated.
If you repeat
gmirror list, you'll note that the
State has changed from
COMPLETE and the
Synchronized line is now gone. Don't worry if you see
DIRTY on the
Flags line, as it simply indicates that the system has written new data to the disk but hasn't mirrored it yet. If you were to wait a few seconds on a quiet disk, you would see the
Flags line change to
For the final test,
reboot the system.
This time your startup messages should include:
GEOM_MIRROR: Device gm0 created (id=2125638583). GEOM_MIRROR: Device gm0: provider ad0 detected. GEOM_MIRROR: Device gm0: provider ad2 detected. GEOM_MIRROR: Device gm0: provider ad0 activated. GEOM_MIRROR: Device gm0: provider ad2 activated. GEOM_MIRROR: Device gm0: provider mirror/gm0 launched. Mounting root from ufs:/dev/mirror/gm0s1a
GEOM utilities are works in progress, and the developers constantly add new features and updates to the man pages. It's well worth your while to keep your favorite version of FreeBSD up-to-date using
cvsup or to choose a newer release when deciding which version of FreeBSD to install.
If you wish to gather performance statistics on your mirror/duplex, try
gstat(8). A good read through
gmirror(8) is also in order, especially if you want an overview of the procedure for replacing a failed disk.
Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.
Read more FreeBSD Basics columns.
Return to theBSD DevCenter