RAID and Disk Encryption #
The softraid(4) subsystem works by emulating a scsibus(4) with sd(4) devices made by combining a number of OpenBSD disklabel(8) partitions into a virtual disk with the desired RAID level. This virtual disk is treated as any other disk, first partitioned with fdisk (on fdisk platforms) and then disklabels are created as usual. Note that only RAID0, RAID1, RAID5 and crypto are fully supported at the moment.
RAID 1 (Mirroring) #
This section covers installing OpenBSD to a mirrored pair of hard drives, and assumes familiarity with the installation process. Disk setup may vary from platform to platform, and booting from softraid devices isn’t supported on all of them. It’s currently only possible to boot from RAID1 and crypto volumes on i386, amd64 and sparc64. Before using the install script, you will drop to a shell and set up a softraid(4) device.
The install kernel only has the /dev entries for one wd(4) device and one sd(4) device on boot, so you will need to manually create more disk devices if your desired softraid setup requires them. For example, if you need to support a second and third sd(4) device for a mirrored setup, you could do the following from the shell prompt:
Welcome to the OpenBSD/amd64 X.X installation program.
(I)nstall, (U)pgrade, (A)utoinstall or (S)hell? s
# cd /dev
# sh MAKEDEV sd1 sd2
You now have full support for the sd0, sd1 and sd2 devices.
Next, we’ll initialize the disks with fdisk(8) and create RAID partitions with disklabel(8).
If you’re booting from MBR, do:
# fdisk -iy sd0
# fdisk -iy sd1
If you use GPT for UEFI booting, do:
# fdisk -iy -g -b 960 sd0
# fdisk -iy -g -b 960 sd1
Create the partition layout on the first device:
# disklabel -E sd0
Label editor (enter '?' for help at any prompt)
> a a
offset: [64]
size: [39825135] *
FS type: [4.2BSD] RAID
> w
> q
No label changes.
Copy the partition layout to the second device:
# disklabel sd0 > layout
# disklabel -R sd1 layout
# rm layout
Assemble the mirror with the bioctl(8) command:
# bioctl -c 1 -l sd0a,sd1a softraid0
scsibus1 at softraid0: 1 targets
sd2 at scsibus2 targ 0 lun 0: <OPENBSD, SR RAID 1, 005> SCSI2 0/direct fixed
sd2: 10244MB, 512 bytes/sec, 20980362 sec total
This shows that we now have a new SCSI bus and a new disk, sd2. This volume will be automatically detected and assembled when the system boots. Even if you create multiple RAID arrays, the device name will always be softraid0. There won’t be a softraid1 or anything else.
Because the new device probably has a lot of garbage where you expect a master boot record and disklabel, zeroing the first chunk of it is highly recommended. Be very careful with this command; issuing it on the wrong device could lead to a very bad day. This assumes that the new softraid device was created as sd2.
# dd if=/dev/zero of=/dev/rsd2c bs=1m count=1
You are now ready to install OpenBSD on your system. Perform the install as normal by invoking “install” or “exit” at the boot media console. Create all the partitions on your new softraid disk (sd2 in our example here) that should be there, rather than on sd0 or sd1 (the non-RAID disks). To check on the status of your mirror, issue the following command:
# bioctl sd2
A nightly cron job to check the status might be a good idea.
Rebuilding RAID 1 #
When a drive failure happens, you will replace the failed drive, create the RAID and other disklabel partitions, then rebuild the mirror. Assuming your RAID volume is sd2 and you are replacing the failed device with sd1m, the following commands should work:
# bioctl -R /dev/sd1m sd2
This can also be performed in single user mode or from the install kernel.