Set Up RAID Linux: Step-by-Step Guide
In this article
Setting up RAID on Linux lets you combine multiple drives into one logical volume for redundancy or performance. This guide covers the most common types—RAID 1 (mirroring) and RAID 0 (striping)—using the standard mdadm tool. You’ll need at least two drives (for RAID 0 or 1) and root access. The steps assume a fresh set of drives or drives you’re willing to erase.
What You'll Need
- A Linux system with root or sudo access.
- Two or more physical drives (internal or external) that you’re prepared to wipe.
- The
mdadmpackage installed (most distros include it; if not, install it via your package manager). - Optional: a spare drive for a hot spare or for testing.
Step-by-Step
- Identify your drives. Run
lsblkorfdisk -lto list all block devices. Note the device names (e.g.,/dev/sdb,/dev/sdc). Make sure you pick the correct drives—this process will erase them. - Install mdadm if needed. On Debian/Ubuntu:
sudo apt install mdadm. On RHEL/Fedora:sudo dnf install mdadm. On Arch:sudo pacman -S mdadm. - Create the RAID array. Use
mdadmto create the array. For RAID 1 (mirroring) with two drives:sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc. For RAID 0 (striping): replace--level=1with--level=0. For RAID 5 (with parity) you need at least 3 drives:--level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd. The array will start building; you can check progress withcat /proc/mdstat. - Create a filesystem. Once the array is active (it may take a while for RAID 5/6 to sync), format it. For example, ext4:
sudo mkfs.ext4 /dev/md0. You can use any filesystem you prefer (xfs, btrfs, etc.). - Mount the array. Create a mount point, e.g.,
sudo mkdir /mnt/raid, then mount:sudo mount /dev/md0 /mnt/raid. - Make the mount permanent. Get the array’s UUID with
sudo blkid /dev/md0. Edit/etc/fstaband add a line like:UUID=your-uuid /mnt/raid ext4 defaults,nofail 0 2. Thenofailoption prevents boot issues if the array isn’t ready. - Save the RAID configuration. Run
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf. Then update the initramfs so the array is recognized at boot: on Debian/Ubuntu,sudo update-initramfs -u; on RHEL/Fedora,sudo dracut --force. - Reboot and verify. Reboot the system. After boot, check that the array is active with
cat /proc/mdstatand that the mount point is accessible.
Common Mistakes
- Choosing the wrong drives—accidentally wiping a drive that contains data. Always double-check device names with
lsblkbefore creating the array. - Forgetting to save the mdadm configuration, which can cause the array to fail to assemble at boot.
- Using drives of different sizes in a RAID 0 or 5; the array will be limited to the smallest drive’s size, wasting space on larger ones.
- Not adding
nofailto the fstab entry, which can prevent the system from booting if the array is missing or slow to appear. - Creating a RAID 0 for critical data without understanding that a single drive failure destroys everything.
Tips
- Use identical drives for best performance and capacity utilization.
- For RAID 1, consider adding a hot spare:
sudo mdadm --add /dev/md0 /dev/sddafter creation. - Monitor array health regularly with
cat /proc/mdstatand set up email alerts via mdadm’s monitoring (seeman mdadm). - If you’re using SSDs, enable TRIM support by adding
discardto the mount options in/etc/fstab. - Test your recovery plan: remove a drive from a RAID 1 and see if the system still boots and data is intact.
Troubleshooting
Array doesn’t assemble at boot. If you see errors, check dmesg | grep md for clues. Run sudo mdadm --assemble --scan manually to see if the array can be assembled. If it fails, ensure the drives are connected and the mdadm.conf is correct.
One drive fails. Replace the failed drive with a new one of at least the same size, then run sudo mdadm --add /dev/md0 /dev/sdX to rebuild the array. For RAID 1, the system should keep running with the remaining drive.
Filesystem errors after a crash. Run sudo fsck /dev/md0 to check and repair the filesystem. Always unmount the array first if possible.
Performance is slow. Check if the array is still resyncing (cat /proc/mdstat). If not, verify that your drives are not the bottleneck and that the RAID level matches your needs.
Can’t mount the array. Check dmesg for errors. Ensure the device node exists (ls -l /dev/md0). If not, try sudo mdadm --assemble --scan again.
Frequently Asked Questions
What RAID level should I use for home use?
RAID 1 (mirroring) is the most common for home use because it provides redundancy with only two drives. RAID 5 offers more usable space but requires at least three drives and has rebuild complexities.
Can I convert an existing single drive to RAID without losing data?
It’s possible but risky and complex. You’d need to back up the data, create the RAID array, and restore. There’s no safe in-place conversion.
Does RAID replace backups?
No. RAID protects against drive failure, not against accidental deletion, malware, or disasters. Always keep separate backups.
How do I check if my RAID is healthy?
Run cat /proc/mdstat to see the status. For a more detailed view, use sudo mdadm --detail /dev/md0.
Can I use USB drives for RAID?
Technically yes, but USB connections can drop and cause array failures. It’s not recommended for a permanent setup.
What happens if I move the RAID drives to another Linux system?
As long as the drives are intact and mdadm is installed, you can assemble the array with sudo mdadm --assemble --scan. The configuration may need to be re-saved on the new system.