Skip to main content.

RAID in FreeBSD and OpenBSD

2014-05-07

Live demo in BSD Now Episode 036 | Originally written by TJ for bsdnow.tv | 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

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.


OpenBSD

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

2017-05-25

Hi, Mr. Dexter. Also, we understand that Brad Davis thinks there should be more real news....

Two Year Anniversary

2015-08-08

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

2015-01-17

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?

2014-11-26

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 220: Opening ZFS in 2017

2017-11-15

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines The First PS4 Kernel Exploit: Adieu The First PS4 Kernel Exploit: Adieu Plenty of time has passed since we first demonstrated Linux running on the PS4. Now we will step back a bit and explain how we managed to jump...

Episode 219: We love the ARC

2017-11-08

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines Papers We Love: ARC: A Self-Tuning, Low Overhead Replacement Cache Ever wondered how the ZFS ARC (Adaptive Replacement Cache) works? How about if Bryan Cantrill presented the original paper on its design? Today is that day. Slides It starts by looking back at a fundamental paper...

Episode 218: A KRACK in the WiFi

2017-11-01

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines FreeBSD 10.4-RELEASE Available FreeBSD 10.4-RELEASE is out. The FreeBSD Project dedicates the FreeBSD 10.4-RELEASE to the memory of Andrey A. Chernov. Some of the highlights: 10.4-RELEASE is the first FreeBSD release to feature full support for eMMC storage, including eMMC partitions, TRIM...

Episode 217: Your questions, part II

2017-10-25

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines OpenBSD 6.2 Released OpenBSD continues their six month release cadence with the release of 6.2, the 44th release On a disappointing note, the song for 6.2 will not be released until December Highlights: Improved hardware support on modern platforms including ARM64/ARMv7 and octeon,...