How to Set Up RAID 5 or RAID 10 on Debian 12 Bookworm

Learn how to set up RAID 5 or RAID 10 on Debian 12 Bookworm.

RAID (Redundant Array of Independent Disks) is a storage technology that combines multiple disk drives into a single logical unit to improve data redundancy and performance. Among various RAID levels, RAID 5 and RAID 10 are popular choices for users seeking a balance between performance, fault tolerance, and storage efficiency.

In this guide, we’ll walk through the process of setting up RAID 5 and RAID 10 on a Debian 12 Bookworm system using mdadm, a powerful and flexible tool for managing software RAID arrays in Linux.


Table of Contents


Understanding RAID 5 and RAID 10

RAID 5

RAID 5 requires at least three disks and uses striping with distributed parity. It offers:

  • Good read performance
  • Fault tolerance (can survive one disk failure)
  • Efficient use of disk space

RAID 10 (1+0)

RAID 10 requires at least four disks and combines mirroring and striping. It offers:

  • Excellent read/write performance
  • Higher fault tolerance (can survive multiple disk failures, depending on which disks fail)
  • 50% storage efficiency (as half of the total space is used for mirroring)

Choose RAID 5 if you want more usable space and decent fault tolerance. Choose RAID 10 if performance and redundancy are your top priorities.


Prerequisites

  • A Debian 12 Bookworm system
  • At least 3 physical or virtual disks for RAID 5, 4 for RAID 10
  • Root or sudo privileges
  • Data backup: This process will erase all data on the selected drives

Let’s assume your target devices are /dev/sd[b-e] (adjust according to your setup).


Installing mdadm

Begin by updating your system and installing the necessary tool:

sudo apt update
sudo apt install mdadm

During installation, you may be prompted to configure mdadm. Accept the defaults or define your preferences, and continue.


Partitioning the Disks

It’s recommended to create a single partition on each disk that will be part of the RAID array:

for disk in b c d e; do
  sudo parted /dev/sd$disk --script mklabel gpt
  sudo parted /dev/sd$disk --script mkpart primary 0% 100%
done

This will create GPT partition tables and a single partition on each disk (e.g., /dev/sdb1, /dev/sdc1, etc.).


Creating the RAID Array

Creating RAID 5

If you’re setting up RAID 5 with 3 or more drives:

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

Add more devices if needed. You’ll see output confirming the creation of the array.

Creating RAID 10

For RAID 10 with 4 disks:

sudo mdadm --create --verbose /dev/md0 --level=10 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

RAID 10 requires an even number of devices. You can increase performance with more disks in pairs.


Formatting the RAID Array

Once the array is created, format it with a filesystem such as ext4:

sudo mkfs.ext4 /dev/md0

You can also use xfs, btrfs, or ext3, depending on your use case.


Mounting the RAID Array

Create a mount point and mount the new filesystem:

sudo mkdir -p /mnt/raid
sudo mount /dev/md0 /mnt/raid

Verify the mount:

df -h /mnt/raid

You should see /dev/md0 mounted with the appropriate capacity.


Making the RAID Array Persistent

To ensure the array assembles at boot and mounts correctly, follow these steps:

1. Save RAID configuration

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

Update the initramfs:

sudo update-initramfs -u

2. Add entry to /etc/fstab

Find the UUID of the array:

sudo blkid /dev/md0

You’ll see something like:

/dev/md0: UUID="1234abcd-5678-efgh-9101-ijklmnopqrst" TYPE="ext4"

Edit /etc/fstab:

sudo nano /etc/fstab

Add the following line:

UUID=1234abcd-5678-efgh-9101-ijklmnopqrst /mnt/raid ext4 defaults,nofail,discard 0 0

This will auto-mount the array on boot.


Monitoring and Managing RAID

You can check the status of your RAID array using:

cat /proc/mdstat

Detailed information:

sudo mdadm --detail /dev/md0

To simulate a failure, mark a device as failed:

sudo mdadm --fail /dev/md0 /dev/sdd1

Remove it from the array:

sudo mdadm --remove /dev/md0 /dev/sdd1

Then add a replacement:

sudo mdadm --add /dev/md0 /dev/sdf1

RAID will begin rebuilding the array automatically.


Tips and Considerations

  • SMART monitoring: Consider enabling S.M.A.R.T. monitoring for your drives with smartmontools.
  • Email notifications: Configure mdadm to alert you in case of a failure.
  • Backups: RAID is not a substitute for backups. Always maintain off-site or cloud backups.
  • Performance testing: Use tools like fio or hdparm to benchmark RAID performance.
  • LVM integration: You can layer LVM on top of RAID for advanced volume management.

Conclusion

Setting up RAID 5 or RAID 10 on Debian 12 Bookworm is a straightforward process with mdadm, giving you a reliable and flexible software RAID solution. RAID 5 is great when you want efficient disk use with redundancy, while RAID 10 offers top-notch performance and fault tolerance.

Whether you’re managing a home lab, small office server, or even a production environment, proper RAID configuration can go a long way in improving data reliability and performance. Just remember to monitor your RAID array regularly and always keep backups—because even RAID can’t save you from accidental deletion or file system corruption.