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

We understand that Michael Dexter, Brad Davis, and George Rosamond think 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 251: Crypto HAMMER

2018-06-20

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines DragonflyBSD: Towards a HAMMER1 master/slave encrypted setup with LUKS I just wanted to share my experience with setting up DragonFly master/slave HAMMER1 PFS's on top of LUKS So after a long time using an Synology for my NFS needs, I...

Episode 250: BSDCan 2018 recap

2018-06-13

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines TrueOS to Focus on Core Operating System The TrueOS Project has some big plans in the works, and we want to take a minute and share them with you. Many have come to know TrueOS as the “graphical FreeBSD” that makes...

Episode 249: Router on a stick

2018-06-06

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines ZFS and DTrace update lands in NetBSD merge a new version of the CDDL dtrace and ZFS code. This changes the upstream vendor from OpenSolaris to FreeBSD, and this version is based on FreeBSD svn r315983. + r315983 is from...

Episode 248: Show me the Mooney

2018-05-30

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines DragonFlyBSD: release52 (w/stable HAMMER2, as default root) DragonflyBSD 5.2.1 was released on May 21, 2018 > Big Ticket items: > Meltdown and Spectre mitigation support Meltdown isolation and spectre mitigation support added. Meltdown mitigation is automatically enabled for all Intel cpus. Spectre mitigation must be enabled...