RAID-1, Part 1
Part 1 of this two-part series describes RAID, in which cases RAID-1 is useful, the RAID-1 installation requirements and how to install RAID-1 when you have an existing ext2 filesystem. Part 2 covers how to set up RAID-1 with an existing and a new swap partition, how to boot from a RAID-1 device, how to use a RAID-1 array to facilitate backing up a busy filesystem or a database that cannot be taken off line for long and how to set up monitoring scripts that will notify you of problems.
We wrote this article because we could not find a complete description of the setup process, and we wanted to document what we learned to make it easier for others to implement RAID-1. We learned how to implement RAID by reviewing the "Software-RAID HOWTO" and Usenet correspondence as well as through trial and error. This article includes information from the HOWTO and Usenet archives. Please read the HOWTO and the other resources called out in the references section for a lot more information about RAID.
This article focuses on RAID-1. There are five RAID levels: Linear mode, RAID-0, RAID-1, RAID-4 and RAID-5. RAID-1 maintains an exact mirror of the data on one disk on another disk. If one of the active RAID disks is removed (or fails), the data are still intact. If there are spare disks available, and if the system survived the crash, reconstruction of the mirror will begin immediately on one of the spare disks. If there is no spare disk, the system will continue to run on the remaining good disk, until you can obtain and install a replacement disk. RAID-1 is an effective, inexpensive way to help to ensure that your system stays up when you have a hard disk failure. One also could use a RAID-1 device to facilitate backing up a busy filesystem.
A RAID-1 device (e.g., /dev/md0) maintains an exact copy (mirror) of the files in a given partition (e.g. /dev/hda2) on a separate partition (e.g./dev/hdc2). The Linux RAID code mirrors partitions, not entire disks. The partitions that make up a RAID device set should be on separate hard disks. Write performance is slightly worse than on a single device, because identical copies of the data written must be sent to every disk in the array. The write is not complete until all disk writes are finished. Reading may be faster than without RAID-1, depending on the read-balancing strategy that is implemented. We did not benchmark our RAID setups. We are using RAID to provide data redundancy, not to improve disk performance.
We suffered a hard disk failure on our production web server a few months after we installed RAID-1 on the system. We noticed that a hard disk partition failed during a routine review of our system logs (the RAID code is truly transparent, we didn't notice the failure until three days after it happened). If we were not using RAID-1, we would have found out when the system crashed. We have about twelve staff members who work on the server and hundreds of users who access our web site on a daily basis. They would have lost time had server gone down. We replaced the failed disk during scheduled downtime. A second (identical) disk failed a few weeks later with similar results. This was a much better and less stressful outcome for all concerned. We have since set up scripts that monitor the status of the RAID devices and send e-mail alerts when there are problems.
There are three requirements for RAID-1: the kernel must support RAID-1, the RAID device driver must be compiled into the kernel or be available as a module and raidtools must be installed. Technically, you can use RAID with just one hard disk but most installations use more than one disk.
If /proc/mdstat exists, RAID support was compiled into the kernel. The Personalities listing indicates which RAID devices are available. For example:
more /proc/mdstat Personalities : [RAID1] read_ahead not set unused devices: <none>
indicates that the kernel supports RAID and the RAID-1 device driver is loaded (RAID-1 may have been compiled into the kernel or have been loaded as a module).
We've set up RAID-1 arrays on Red Hat 7.0, 7.1 and 7.2 and Debian potato using the 2.4.4, 2.4.9, 2.4.12 and 2.4.17 kernels that include RAID support, and the 2.2.16-22 kernel with the md driver 0.90.0 patch. If you are using a kernel that does not include RAID support, you may use the RAID-patches and raidtools found at people.redhat.com/mingo.
If you're using IDE for your RAID devices, you should install them on different controllers. SCSI RAID setups can get away with using the same bus, but they have a greater chance of a broken disk taking down the whole machine. And, consider using different manufacturers (or at least different lots) for the disks in your RAID array. Our initial array was created with two identical hard disks. The disks failed within a month of each other.
The partition that will be used for the RAID-1 array on the second disk should be about the same size as that on the first disk. It must be at least as large as the first disk's partition. If the second disk's partition is larger, the extra space will not be used by the RAID-1 device. The smallest partition determines the size of the RAID-1 device.
Free DevOps eBooks, Videos, and more!
Regardless of where you are in your DevOps process, Linux Journal can help!
We offer here the DEFINITIVE DevOps for Dummies, a mobile Application Development Primer, and advice & help from the expert sources like:
- Linux Journal
- Resurrecting the Armadillo
- High-Availability Storage with HA-LVM
- Real-Time Rogue Wireless Access Point Detection with the Raspberry Pi
- DNSMasq, the Pint-Sized Super Dæmon!
- Localhost DNS Cache
- March 2015 Issue of Linux Journal: System Administration
- Days Between Dates: the Counting
- The Usability of GNOME
- Linux for Astronomers
- You're the Boss with UBOS