Software RAID in FreeBSD

Introduction

FreeBSD provides a helpful tool to manage software RAID with ATA deivces. This tool provides features such as hot swapping ATA RAID devices, which was previously unheard of. This functionality and features will be elaborated here, but caution should be taken as software RAID IS NOT an adequate replacement for hardware RAID.

The Tool

atacontrol is the command to issue to manage your ata devices, channels, and arrays.

Create an Array (RAID1) / Mirror

To create a FreeBSD software RAID1 / Mirror array using disks ad0 and ad1, execute the following command:

atacontrol create RAID1 ad0 ad1

From that point on, any new data written to the two disks will be mirrored and accessible through device ar0. You will received a confirmation prompt stating array created on [device name].

Example RAID Setup

Be sure the drives are probed as ad4 and ad6 for the purpose of this example and that they are on different ATA channels. ad4 and ad5 will likely be different for you.

ad4: 76324MB [155072/16/63] at ata2-master SATA150
ad6: 76324MB [155072/16/63] at ata3-master SATA150

* If they ATA devices do not probe correctly, check the BIOS settings and hard drive jumpers.
* Either perform a minimal install of FreeBSD to do this, or use a FreeBSD livefs disc:
* Reboot from the installed OS if using a minimal install and login as root
* Run the command “atacontrol create RAID1 ad4 ad6” to create the raid set
* Reboot and reinstall the OS, choosing ar0 as the drive, which should probe like:

ad4: 76324MB [155072/16/63] at ata2-master SATA150
ad6: 76324MB [155072/16/63] at ata3-master SATA150
ar0: 76324MB [9730/255/63] status: READY subdisks:
disk0 READY on ad4 at ata2-master
disk1 READY on ad6 at ata3-master

DO NOT USED ad4 AND ad6 DIRECTLY. These devices are now accessible in through the RAID array ar0. DO NOT DO ANYTHING WITH THE TWO DEVICES.

Dynamically Replace Device on Array

To replace a hard drive on the ATA RAID array without turning off the machine, you can simply turn off the channel the hard drive is connected to, and disconnect and replace the drive. This can only work if the array is spread across multiple channels since turning off a channel will disable all drives on that channel. To do this, execute the following:

atacontrol detach ata#

To find the channel you with to disconnect, you can use atacontrol list to list all the ata channels and devices attached on each channel.

Steps to Replace Failed Disk

The following command will be executed to performed the necessary steps in replacing a bad or failed disk on the array

To check the status of an array.

atacontrol status ar0

To detach ad4 channel if failed. (use ata3 for ad6). The disks in the chassis are hotswappable (not 100%, but appears to work), so it can be pulled once detached.

atacontrol detach ata2

To reattach ad4 channel once replaced.

atacontrol attach ata2

To add the replaced ad4 as a spare on the RAID set ar0.

atacontrol addspare ar0 ad4

To rebuild the mirror.

atacontrol rebuild ar0

Utility parameters options

The following expresses some usages of the utility:

atacontrol args

atacontrol attach channel
atacontrol detach channel
atacontrol reinit channel
atacontrol create type [interleave] disk0 … diskN
atacontrol delete raid
atacontrol rebuild raid
atacontrol status raid
atacontrol mode channel [mastermode slavemode]
atacontrol info channel
atacontrol cap channel device
atacontrol enclosure channel device
atacontrol list

The atacontrol utility can cause severe system crashes and loss of data if used improperly. Please exercise caution when using this command! In other words, know what you’re doing when performing operations with this utility.

The channel argument is the number of the ATA channel on which to operate. The following commands are supported:

attach – Attach an ATA channel. Devices on the channel are probed and attached as is done on boot.

detach – Detach an ATA channel. Devices on the channel are removed from the kernel, and all outstanding transfers etc. are returned back to the system marked as failed.

reinit – Reinitialize an ATA channel. Both devices on the channel are reset and initialized to the parameters the ATA driver has stored internally. Devices that have gone bad and no longer respond to the probe, or devices that have physically been removed, are removed from the kernel. Likewise are devices that show up during a reset, probed and attached.

create – Create a type ATA RAID. The type can be RAID0 (stripe), RAID1 (mirror), RAID0+1 or SPAN (JBOD). In case the RAID has a RAID0 component, the interleave must be specified in number of sectors. The RAID will be created of the individual disks named disk0 … diskN.

Although the ATA driver allows for creating an ATA RAID on disks with any controller, there are restrictions. It is only possible to boot on an array if it is either located on a “real” ATA RAID controller like the Promise or Highpoint controllers, or if the RAID declared is of RAID1 or SPAN type; in case of a SPAN, the partition to boot must reside on the first disk in the SPAN.

delete – Delete a RAID array on a RAID capable ATA controller.

rebuild – Rebuild a RAID1 array on a RAID capable ATA controller.

status – Get the status of an ATA RAID.

mode – Without the two mode arguments, the current transfer modes of both devices are printed. If the mode arguments are given, the ATA driver is asked to change the transfer modes to those given.

The ATA driver will reject modes that are not supported by the hardware. Modes are given like “PIO3”, “udma2”, ”udma100”, case does not matter. If one of the devices mode should not be changed, use a nonexisting mode as argument (i.e. ”XXX”), and the mode will remain unchanged.

Currently supported modes are: BIOSDMA, PIO0 (alias BIOSPIO), PIO1, PIO2, PIO3, PIO4, WDMA2, UDMA2 (alias UDMA33), UDMA4 (alias UDMA66), UDMA5 (alias UDMA100) and UDMA6 (alias UDMA133).

info – Show info about the attached devices on the channel. The device name and manufacture/version strings are shown.

cap – Show detailed info about the device on channel device where device is 0 for master and 1 for slave.

enclosure – Show detailed info about the enclosure on channel device where device is 0 for master and 1 for slave. Fan RPM speed, enclosure temperature, 5V and 12V levels are shown.

list – Show info about all attached devices on all active controllers.

Miscellaneous Examples

To see the devices’ current access modes, use the command line:

atacontrol mode 0

which results in the modes of the devices being displayed as a string like this:
Master = WDMA2
Slave = PIO4

This means that ata0-master is in DMA mode, ata0-slave is in PIO mode, and so forth. You can set the mode with atacontrol and a string like the above, for example:

atacontrol mode 0 PIO4 PIO4

The new modes are set as soon as the atacontrol command returns.

The atacontrol utility first appeared in FreeBSD 4.6.

Leave a Reply