{{Warning|Installing a system with RAID is a complex process that may destroy data. Be sure to backup all data before proceeding.}}

{{Warning|Installing a system with RAID is a complex process that may destroy data. Be sure to backup all data before proceeding.}}

−

RAID does not provide a guarantee that your data is safe. If there is a fire, if your computer is stolen or if you have multiple hard drive failures, RAID will not protect your data. Therefore it is important to make backups (see [[Backup Programs]]). Whether you use tape drives, DVDs, CDROMs or another computer, keep an current copy of your data out of your computer (and preferably offsite). Get into the habit of making regular backups. You can also divide the data on your computer into current and archived directories. Then back up the current data frequently, and the archived data occasionally.

+

RAID does not guarantee that data is safe. A RAID will not protect data if there is a fire, the computer is stolen or multiple hard drives fail. Therefore it is important to make backups (see [[Backup Programs|List of backup software]]).

=== RAID level comparison ===

=== RAID level comparison ===

Line 50:

Line 50:

===Prepare the device===

===Prepare the device===

−

To prevent possible issues down the line, you should consider wiping your entire disk before setting up RAID. This should be repeated for each disk you will be using for RAID, these commands completely erase anything currently on the device!

+

{{Warning|These steps erase everything on a device, so type carefully.}}

−

{{Warning|These steps erase everything on the {{ic|/dev/disk-to-clean}} so type carefully}}

+

−

Erase any old RAID configuration info

+

To prevent possible issues each device in the RAID should be [[Securely wipe disk|securely wiped]]. Additionally, the following steps can be taken.

−

{{bc|1=# mdadm --zero-superblock /dev/disk-to-clean}}

+

−

Erase all partition-table data

+

Erase any old RAID configuration information on the device:

−

{{bc|1=# dd if=/dev/zero of=/dev/disk-to-clean bs=4096 count=1}}

+

{{bc|1=# mdadm --zero-superblock /dev/<drive>}}

−

Make sure kernel clears old entries

+

Verify that the kernel clears old entries:

{{bc|1=# partprobe -s}}

{{bc|1=# partprobe -s}}

−

Verify the entries in {{ic|/etc/fstab}} and {{ic|/etc/mdadm.conf}}

+

With a software RAID, disabling the hard disk cache will help prevent data loss during power loss, as long as you do not use a [[Wikipedia:Uninterruptible power supply|UPS]]. Repeat the command for each drive in the array. Note however, that this decreases performance.

−

+

{{bc|# hdparm -W 0 /dev/<drive>}}

−

With a software RAID, disabling the hard disk cache will help prevent data loss during power loss, as long as you do not use a [[Wikipedia:Uninterruptible power supply|UPS]]. Repeat the command for each drive in the array. Note however, that this decreases performance.

+

−

{{bc|# hdparm -W 0 /dev/path_to_disk}}

+

===Create the partition table===

===Create the partition table===

−

The RAID setup varies between different RAID-levels. If you know what RAID you want and already set up your hardware accordingly, you can proceed with formatting the disks you want in your array. It is also possible to create a RAID-array directly on the raw disks (without partitions), but not recommended because it can cause problems when swapping a failed disk.

+

It is recommended to format the disks you want in your array. It is also possible to create a RAID directly on the raw disks (without partitions), but not recommended because it can cause problems when swapping a failed disk.

−

+

−

When replacing a failed disk of a RAID-array, the new disk has to be exactly the same size as the failed disk or bigger — otherwise the array recreation process will not work. Even hard drives of the same manufacturer and model can have small size differences. By leaving a little space at the end of the disk unallocated one can compensate for the size differences between drives, which makes choosing a replacement drive model easier. Therefore, it is good practice to leave about 100 MB of unallocated space at the end of the disk.

+

−

Format one of the drives in the array with your favorite tool. For example,

+

When replacing a failed disk of a RAID, the new disk has to be exactly the same size as the failed disk or bigger — otherwise the array recreation process will not work. Even hard drives of the same manufacturer and model can have small size differences. By leaving a little space at the end of the disk unallocated one can compensate for the size differences between drives, which makes choosing a replacement drive model easier. Therefore, it is good practice to leave about 100 MB of unallocated space at the end of the disk.

−

{{bc|# cfdisk /dev/path_to_disk}}

+

−

{{Tip|Using GParted to create the partitions and align them to the cylinder will create optimized disk alignment. This can be achieved using the [http://gparted.sourceforge.net/livecd.php Gnome Partition Editor Live Media].}}

+

====Partition code====

====Partition code====

−

The two [[Wikipedia:Partition types|partition type]]s that are applicable to RAID devices are Non-FS data and Linux RAID auto. Non-FS data is recommended, as your array is not auto-assembled during boot. With Linux RAID auto one may run into trouble when booting from a live-cd or when installing the degraded RAID-array in a different system (maybe with other degraded RAID-arrays in worst case) as Linux will try to automatically assemble and resync the array which could render your data on the array unreadable if it fails.

+

The two [[Wikipedia:Partition types|partition type]]s that are applicable to RAID devices are Non-FS data and Linux RAID auto. Non-FS data is recommended, as your array is not auto-assembled during boot. With Linux RAID auto one may run into trouble when booting from a live-cd or when installing the degraded RAID in a different system (maybe with other degraded RAIDs in worst case) as Linux will try to automatically assemble and resync the array which could render your data on the array unreadable if it fails.

{{note|cfdisk and mkpart use a set of "filesystem types" to set the partition codes. Each type corresponds to a partition code (see [http://www.gnu.org/software/parted/manual/html_node/mkpart.html#mkpart Parted User's Manual]). It uses the {{ic|da}} type to denote Non-FS data and {{ic|fd}} for Linux RAID auto.}}

{{note|cfdisk and mkpart use a set of "filesystem types" to set the partition codes. Each type corresponds to a partition code (see [http://www.gnu.org/software/parted/manual/html_node/mkpart.html#mkpart Parted User's Manual]). It uses the {{ic|da}} type to denote Non-FS data and {{ic|fd}} for Linux RAID auto.}}

+

+

Once you have selected a partition type follow the [[Beginner's Guide]] to [[Beginner's Guide#Prepare the storage drive|prepare the storage drive]].

===Copy the partition table===

===Copy the partition table===

−

Once you have a properly partitioned and aligned disk you can copy the setup to any other disk.

+

Once you have a properly partitioned the disk copy the partition table to the other disks in the RAID.

The array is created under the virtual device {{ic|/dev/md/your_array}}, assembled and ready to use (in degraded mode). You can directly start using it while mdadm resyncs the array in the background. It can take a long time to restore parity, you can check the progress with:

+

+

The array is created under the virtual device {{ic|/dev/md/<array>}}, assembled and ready to use (in degraded mode). You can directly start using it while mdadm resyncs the array in the background. It can take a long time to restore parity. Check the progress with:

{{bc|$ cat /proc/mdstat}}

{{bc|$ cat /proc/mdstat}}

Line 132:

Line 122:

or write it to {{ic|rc.local}}.

or write it to {{ic|rc.local}}.

−

===Add to kernel image===

===Add to kernel image===

−

See [[mkinitcpio]] for more info.

+

Add {{ic|mdadm_udev}} to the [[Mkinitcpio#HOOKS|HOOKS]] section of the [[Mkinitcpio]] file before the {{ic|filesystems}} hook. This will add support for mdadm directly into the init image.

Add '''mdadm''' or '''mdadm_udev''' to the ''HOOKS='' section of the {{ic|/etc/mkinitcpio.conf}} file before the filesystems hook. This will add support for mdadm directly into the init image.

+

Add the {{ic|raid456}} module and the filesystem module created on the RAID (e.g. {{ic|ext4}}) to the [[Mkinitcpio#MODULES|MODULES]] section. This will build these modules into the kernel image. For example,

{{Note | Live CDs like [http://www.sysresccd.org/Main_Page SystemrescueCD] assemble the RAID arrays automatically at boot time if you used the partition type fd at the install of the array)}}

+

{{Note|Live CDs like [http://www.sysresccd.org/Main_Page SystemrescueCD] assemble the RAIDs automatically at boot time if you used the partition type {{ic|fd}} at the install of the array.}}

==Removing device, stop using the array==

==Removing device, stop using the array==

Line 277:

Line 260:

===Recovering from a broken or missing drive in the raid===

===Recovering from a broken or missing drive in the raid===

−

You might get the above mentioned error also when one of the drives breaks for whatever reason. In that case you will have to fore the raid to still turn on even with one disk short. Type this (change where needed):

+

You might get the above mentioned error also when one of the drives breaks for whatever reason. In that case you will have to force the raid to still turn on even with one disk short. Type this (change where needed):

# mdadm --manage /dev/md0 --run

# mdadm --manage /dev/md0 --run

Line 301:

Line 284:

{{ic|hdparm}} should '''NOT''' be used to benchmark a RAID, because it provides very inconsistent results.

{{ic|hdparm}} should '''NOT''' be used to benchmark a RAID, because it provides very inconsistent results.

Introduction

Template:Wikipedia
Redundant Array of Independent Disks (RAID) devices are virtual devices created from two or more real block devices. This allows multiple devices (typically disk drives or partitions thereof) to be combined into a single device to hold (for example) a single filesystem. RAID is designed to prevent data loss in the event of a hard disk failure. There are different levels of RAID.

Standard RAID levels

Uses striping to combine disks. Not really RAID in that it provides no redundancy. It does, however, provide a big speed benefit. This example will utilize RAID 0 for swap, on the assumption that a desktop system is being used, where the speed increase is worth the possibility of system crash if one of your drives fails. On a server, a RAID 1 or RAID 5 array is more appropriate. The size of a RAID 0 array block device is the size of the smallest component partition times the number of component partitions.

The most straightforward RAID level: straight mirroring. As with other RAID levels, it only makes sense if the partitions are on different physical disk drives. If one of those drives fails, the block device provided by the RAID array will continue to function as normal. The example will be using RAID 1 for everything except swap. Note that RAID 1 is the only option for the boot partition, because bootloaders (which read the boot partition) do not understand RAID, but a RAID 1 component partition can be read as a normal partition. The size of a RAID 1 array block device is the size of the smallest component partition.

Requires 3 or more physical drives, and provides the redundancy of RAID 1 combined with the speed and size benefits of RAID 0. RAID 5 uses striping, like RAID 0, but also stores parity blocks distributed across each member disk. In the event of a failed disk, these parity blocks are used to reconstruct the data on a replacement disk. RAID 5 can withstand the loss of one member disk.

Note: RAID 5 is a common choice due to its combination of speed and data redundancy. The caveat is that if 1 drive were to fail and before that drive was replaced another drive failed, all data will be lost. For excellent information regarding this, see the RAID5 Risks discussion thread on the Ubuntu forums. The best alternative to RAID5 when redundancy is crucial is RAID 10.

Nested RAID levels

Commonly referred to as RAID 10, is a nested RAID that combines two of the standard levels of RAID to gain performance and additional redundancy.

Redundancy

Warning: Installing a system with RAID is a complex process that may destroy data. Be sure to backup all data before proceeding.

RAID does not guarantee that data is safe. A RAID will not protect data if there is a fire, the computer is stolen or multiple hard drives fail. Therefore it is important to make backups (see List of backup software).

Installation

Prepare the device

To prevent possible issues each device in the RAID should be securely wiped. Additionally, the following steps can be taken.

Erase any old RAID configuration information on the device:

# mdadm --zero-superblock /dev/<drive>

Verify that the kernel clears old entries:

# partprobe -s

With a software RAID, disabling the hard disk cache will help prevent data loss during power loss, as long as you do not use a UPS. Repeat the command for each drive in the array. Note however, that this decreases performance.

# hdparm -W 0 /dev/<drive>

Create the partition table

It is recommended to format the disks you want in your array. It is also possible to create a RAID directly on the raw disks (without partitions), but not recommended because it can cause problems when swapping a failed disk.

When replacing a failed disk of a RAID, the new disk has to be exactly the same size as the failed disk or bigger — otherwise the array recreation process will not work. Even hard drives of the same manufacturer and model can have small size differences. By leaving a little space at the end of the disk unallocated one can compensate for the size differences between drives, which makes choosing a replacement drive model easier. Therefore, it is good practice to leave about 100 MB of unallocated space at the end of the disk.

Partition code

The two partition types that are applicable to RAID devices are Non-FS data and Linux RAID auto. Non-FS data is recommended, as your array is not auto-assembled during boot. With Linux RAID auto one may run into trouble when booting from a live-cd or when installing the degraded RAID in a different system (maybe with other degraded RAIDs in worst case) as Linux will try to automatically assemble and resync the array which could render your data on the array unreadable if it fails.

Note: cfdisk and mkpart use a set of "filesystem types" to set the partition codes. Each type corresponds to a partition code (see Parted User's Manual). It uses the da type to denote Non-FS data and fd for Linux RAID auto.

The array is created under the virtual device /dev/md/<array>, assembled and ready to use (in degraded mode). You can directly start using it while mdadm resyncs the array in the background. It can take a long time to restore parity. Check the progress with:

$ cat /proc/mdstat

Update configuration file

Since the installer builds the initrd using /etc/mdadm.conf in the target system, you should update the default configuration file. The default file can be overwritten using the redirection operator, because it only contains explanatory comments.

Redirect the contents of the metadata stored on the named devices to the configuration file:

# mdadm --examine --scan > /etc/mdadm.conf

Note: If you are updating your RAID configuration from within the Arch Installer by swapping to another TTY, you will need to ensure that you are writing to the correct mdadm.conf file:

# mdadm --examine --scan > /mnt/etc/mdadm.conf

Once the configuration file has been updated the array can be assembled using mdadm:

# mdadm --assemble --scan

Configure filesystem

The array can now be formatted like any other disk, just keep in mind that:

Mounting from a Live CD

Note: Live CDs like SystemrescueCD assemble the RAIDs automatically at boot time if you used the partition type fd at the install of the array.

Removing device, stop using the array

You can remove a device from the array after you mark it as faulty.

# mdadm --fail /dev/md0 /dev/sdxx

Then you can remove it from the array.

# mdadm -r /dev/md0 /dev/sdxx

Remove device permanently (for example in the case you want to use it individally from now on).
Issue the two commands described above then:

# mdadm --zero-superblock /dev/sdxx

After this you can use the disk as you did before creating the array.

Warning: If you reuse the removed disk without zeroing the superblock you will LOSE all your data next boot. (After mdadm will try to use it as the part of the raid array). DO NOT issue this command on linear or RAID0 arrays or you will LOSE all your data on the raid array.

Stop using an array:

Umount target array

Stop the array with: mdadm --stop /dev/md0

Repeat the three command described in the beginning of this section on each device.

Remove the corresponding line from /etc/mdadm.conf

Adding a device to the array

Adding new devices with mdadm can be done on a running system with the devices mounted.
Partition the new device /dev/sdx using the same layout as one of those already in the arrays /dev/sda.

First, add the new device as a Spare Device to all of the arrays. We will assume you have followed the guide and use separate arrays for /boot RAID 1 (/dev/md1), swap RAID 1 (/dev/md2) and root RAID 5 (/dev/md0).

Resize the LVM Physical Volume /dev/md0 (or e.g. /dev/mapper/cryptedlvm if using LUKS) to take up all the available space on the array. You can list them with the command "pvdisplay".

# pvresize /dev/md0

Resize the Logical Volume you wish to allocate the new space to. You can list them with "lvdisplay". Assuming you want to put it all to your /home volume:

# lvresize -l +100%FREE /dev/array/home

To resize the filesystem to allocate the new space use the appropriate tool. If using ext2 you can resize a mounted filesystem with ext2online. For ext3 you can use resize2fs or ext2resize but not while mounted.

You should check the filesystem before resizing.

# e2fsck -f /dev/array/home
# resize2fs /dev/array/home

Read the manuals for lvresize and resize2fs if you want to customize the sizes for the volumes.

Watch mdstat

Track IO with iotop

The iotop package lets you view the input/output stats for processes. Use this command to view the IO for raid threads.

iotop -a -p $(sed 's, , -p ,g' <<<`pgrep "_raid|_resync|jbd2"`)

Mailing on events

You need a smtp mail server (sendmail) or at least an email forwarder (ssmtp/msmtp). Be sure you have configured an email in /etc/mdadm.conf

# mdadm --monitor --scan --test

When it is ready you can enable the service

# systemctl enable mdadm.service

Troubleshooting

If you are getting error when you reboot about "invalid raid superblock magic" and you have additional hard drives other than the ones you installed to, check that your hard drive order is correct. During installation, your RAID devices may be hdd, hde and hdf, but during boot they may be hda, hdb and hdc. Adjust your kernel line accordingly. This is what happened to me anyway.

Start arrays read-only

When an md array is started, the superblock will be written, and resync may begin. To start read-only set the kernel module md_mod parameter start_ro. When this is set, new arrays get an 'auto-ro' mode, which disables all internal io (superblock updates, resync, recovery) and is automatically switched to 'rw' when the first write request arrives.

Note: The array can be set to true 'ro' mode using mdadm -r before the first write request, or resync can be started without a write using mdadm -w.

To set the parameter at boot, add md_mod.start_ro=1 to your kernel line.

Or set it at module load time from /etc/modprobe.d/ file or from directly from /sys/.

echo 1 > /sys/module/md_mod/parameters/start_ro

Recovering from a broken or missing drive in the raid

You might get the above mentioned error also when one of the drives breaks for whatever reason. In that case you will have to force the raid to still turn on even with one disk short. Type this (change where needed):

# mdadm --manage /dev/md0 --run

Now you should be able to mount it again with something like this (if you had it in fstab):

# mount /dev/md0

Now the raid should be working again and available to use, however with one disk short! So, to add that one disc partition it the way like described above in Prepare the device. Once that is done you can add the new disk to the raid by doing:

Benchmarking

There are several tools for benchmarking a RAID. The most notable improvement is the speed increase when multiple threads are reading from the same RAID volume.

Tiobench specifically benchmarks these performance improvements by measuring fully-threaded I/O on the disk.

Bonnie++ tests database type access to one or more files, and creation, reading, and deleting of small files which can simulate the usage of programs such as Squid, INN, or Maildir format e-mail. The enclosed ZCAV program tests the performance of different zones of a hard drive without writing any data to the disk.

hdparm should NOT be used to benchmark a RAID, because it provides very inconsistent results.