Skip to main content.

RAID in FreeBSD and OpenBSD


Live demo in BSD Now Episode 036 | Originally written by TJ for | Last updated: 2014/05/07

NOTE: the author/maintainer of the tutorial(s) is no longer with the show, so the information below may be outdated or incorrect.

Data integrity is a complex, multi-step process. Local backups, offsite backups and fault tolerance all play key roles in keeping your files safe. The easiest way to keep your data safe from hard drive failure is by using RAID. There are different levels of RAID, each with their own different goals and caveats. This tutorial will be showing RAID1, or "mirrored" drives. By installing your OS onto a RAID1 array, you can withstand a single hard drive dying. The system will even keep running normally after a drive has died, but at that point you need to look into replacing the failed drive and rebuilding the array. OpenBSD's bioctl command also has options for other RAID levels. For FreeBSD, you'd want to check the gstripe and graid commands.


FreeBSD has two filesystems you can choose from: UFS and ZFS. As of 10.0, the installer supports an easy ZFS installation method that's capable of doing RAID1. This section of the tutorial is focused only on UFS, which is a more manual and involved process. Boot up the installer and go through the prompts until you get to the following screen:

We'll choose "shell" here and set up the array manually. This is assuming you have a machine capable of booting from GPT and you have two drives in the system. In my case "ada0" and "ada1" were the device names. The gpart command is the main tool we'll be using.

# gpart create -s gpt ada0
# gpart add -s 64k -t freebsd-boot -l ada0boot ada0
# gpart add -t freebsd-ufs -l ada0root ada0
# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0

Repeat for the second drive.

# gpart create -s gpt ada1
# gpart add -s 64k -t freebsd-boot -l ada1boot ada1
# gpart add -t freebsd-ufs -l ada1root ada1
# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada1

Now we'll load the kernel module and actually create the mirror with gmirror.

# kldload geom_mirror
# gmirror label boot /dev/gpt/ada0boot /dev/gpt/ada1boot
# gmirror label root /dev/gpt/ada0root /dev/gpt/ada1root

Format the new mirror so we can actually install the OS to it. We'll mount it at /mnt so bsdinstall will recognize it after we're done.

# newfs -U /dev/mirror/root
# mount /dev/mirror/root /mnt

We need an /etc/fstab as well, so let's go ahead and create that.

# echo '/dev/mirror/root / ufs rw,noatime 1 1' > /tmp/bsdinstall_etc/fstab
# exit

The installer should start untarring the files to the new RAID1 array and do most of the work for you. Choose "yes" when asked "would you like to open a shell in the new system to make any final manual modifications?"

# echo 'geom_mirror_load="YES"' >> /boot/loader.conf
# exit

If you forget this step, your new system won't boot. Reboot into the new installation and check the status like so:

# gmirror status

       Name    Status  Components
mirror/boot  COMPLETE  ada0p1 (ACTIVE)
                       ada1p1 (ACTIVE)
mirror/root  COMPLETE  ada0p2 (ACTIVE)
                       ada1p2 (ACTIVE)

You're ready to go.


Setting up a mirror in OpenBSD is quite easy. Boot up the installer and go to shell mode.

Welcome to the OpenBSD/i386 5.5 installation program.
(I)nstall, (U)pgrade, (A)utoinstall or (S)hell? s

By default, OpenBSD will only make a /dev entry for the first drive. This is assuming you have two drives: wd0 and wd1. Let's create the /dev entry for wd1 and set a disk layout.

# cd /dev
# sh MAKEDEV wd1
# dd if=/dev/zero of=/dev/wd0c bs=1m count=1
# dd if=/dev/zero of=/dev/wd1c bs=1m count=1
# fdisk -iy wd0
# fdisk -iy wd1

Next we create the partitions on the disks.

# disklabel -E wd0
Label editor (enter '?' for help at any prompt)
> a a
offset: [64]
size: [20964761]
FS type: [4.2BSD] RAID

We can do it once for wd0 and then just import that same configuration into wd1 - pretty cool!

# disklabel wd0 > bsdnowiscool
# disklabel -R wd1 bsdnowiscool
# rm bsdnowiscool

Create the mirror like so:

# bioctl -c 1 -l wd0a,wd1a softraid0
# exit

In my case, the newly-created pseudo-device was called sd0. Go through the installer as normal, but be sure to choose that device instead of the regular hard drives.

Available disks are: wd0 wd1 sd0.
Which one is the root disk? (or 'done') [wd0] sd0

Reboot and check the status of your array in the new system:

# bioctl sd0                                                                   
Volume      Status               Size Device  
softraid0 0 Online         2146656256 sd0     RAID1 
          0 Online         2146656256 0:0.0   noencl <wd0a>
          1 Online         2146656256 0:1.0   noencl <wd1a>

Or just verify through dmesg.

# grep sd0 /var/run/dmesg.boot                                                 
sd0 at scsibus3 targ 1 lun 0: <OPENBSD, SR RAID 1, 005> SCSI2 0/direct fixed
sd0: 2047MB, 512 bytes/sector, 4192688 sectors
root on sd0a (fa6620cf9195850e.a) swap on sd0b dump on sd0b

That's it.

Latest News

New announcement


We understand that Michael Dexter, Brad Davis, and George Rosamond think there should be more real news....

Two Year Anniversary


We're quickly approaching our two-year anniversary, which will be on episode 105. To celebrate, we've created a unique t-shirt design, available for purchase until the end of August. Shirts will be shipped out around September 1st. Most of the proceeds will support the show, and specifically allow us to buy...

New discussion segment


We're thinking about adding a new segment to the show where we discuss a topic that the listeners suggest. It's meant to be informative like a tutorial, but more of a "free discussion" format. If you have any subjects you want us to explore, or even just a good name...

How did you get into BSD?


We've got a fun idea for the holidays this year: just like we ask during the interviews, we want to hear how all the viewers and listeners first got into BSD. Email us your story, either written or a video version, and we'll read and play some of them for...

Episode 258: OS Foundations


Direct Download:MP3 AudioVideo This episode was brought to you by Headlines FreeBSD Foundation Update, July 2018 MESSAGE FROM THE EXECUTIVE DIRECTOR We’re in the middle of summer here, in Boulder, CO. While the days are typically hot, they can also be quite unpredictable. Thanks to the Rocky Mountains, waking up to 50-degree (~10...

Episode 257: Great NetBSD 8


Direct Download:MP3 AudioVideo This episode was brought to you by Headlines NetBSD v8.0 Released The NetBSD Project is pleased to announce NetBSD 8.0, the sixteenth major release of the NetBSD operating system. This release brings stability improvements, hundreds of bug fixes, and many new features. Some highlights of the...

Episode 2^8: Because Computers


Direct Download:MP3 AudioVideo This episode was brought to you by Win Celebrate our 256th episode with us. You can win a Mogics Power Bagel (not sponsored). To enter, go find the 4 episodes we did in December of 2017. In the opening, find the 4 letters in the bookshelf behind me. They...

Episode 255: What are you pointing at


Direct Download:MP3 AudioVideo This episode was brought to you by Headlines What ZFS block pointers are and what's in them I've mentioned ZFS block pointers in the past; for example, when I wrote about some details of ZFS DVAs, I said that DVAs are embedded in block pointers. But I've never really...