Software RAID with mdadm

mdadm (Multiple Device Admin) is the Linux kernel’s software RAID tool. It creates and manages RAID arrays using the kernel’s md (multiple device) driver. Software RAID with mdadm is production-grade — it is used in major cloud providers, storage appliances, and enterprise Linux deployments. Ubuntu ships mdadm in the default repositories.

Creating a RAID 1 mirror

# Install mdadm
sudo apt install -y mdadm

# Identify the disks to use
lsblk
sudo fdisk -l

# Create a RAID 1 array on two disks
# Use whole disks (recommended for clarity): /dev/sdb, /dev/sdc
sudo mdadm --create /dev/md0     --level=1     --raid-devices=2     /dev/sdb /dev/sdc

mdadm create output

mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
mdadm: Stopping resync of /dev/md0
mdadm: Syncing of /dev/md0 will continue in the background.
mdadm: array /dev/md0 is being synced, it will be available shortly.
# Monitor the initial sync progress
cat /proc/mdstat
# or
watch -n1 cat /proc/mdstat

# After sync: format and mount
sudo mkfs.ext4 /dev/md0
sudo mkdir -p /data
sudo mount /dev/md0 /data
echo "UUID=$(sudo blkid -s UUID -o value /dev/md0)  /data  ext4  defaults,noatime  0  2" | sudo tee -a /etc/fstab

Creating a RAID 10 array

# RAID 10 requires at least 4 disks
sudo mdadm --create /dev/md0     --level=10     --raid-devices=4     /dev/sdb /dev/sdc /dev/sdd /dev/sde

# Check capacity (RAID 10 = 50% of total)
sudo mdadm --detail /dev/md0 | grep "Array Size"

Monitoring RAID health

# Quick health check
cat /proc/mdstat

/proc/mdstat showing a healthy array

Personalities : [raid1]
md0 : active raid1 sdb[0] sdc[1]
      524224448 blocks super 1.2 [2/2] [UU]    ← [UU] = both disks active
                                               ← [U_] = one disk failed!
      bitmap: 1/4 pages [4KB], 65536KB chunk

unused devices: <none>
# Detailed array information
sudo mdadm --detail /dev/md0

# Check all arrays
sudo mdadm --detail --scan

# Enable email alerts for RAID events
sudo nano /etc/mdadm/mdadm.conf
# Set: MAILADDR admin@company.com
sudo systemctl restart mdmonitor

# Test that email alerting works
sudo mdadm --monitor --test /dev/md0

Simulating and recovering from a disk failure

# Simulate a disk failure (mark a disk as failed)
sudo mdadm /dev/md0 --fail /dev/sdc

# Check the degraded state
cat /proc/mdstat    # Should show [U_] for RAID 1

Degraded RAID 1 in /proc/mdstat

md0 : active raid1 sdb[0] sdc[1](F)
      524224448 blocks super 1.2 [2/1] [U_]    ← One disk failed
# Remove the failed disk
sudo mdadm /dev/md0 --remove /dev/sdc

# Physically replace the disk, then add the new disk to the array
# New disk is now /dev/sdc (same device name after replacement)
sudo mdadm /dev/md0 --add /dev/sdc

# Watch the rebuild
watch -n1 cat /proc/mdstat

Rebuild in progress

md0 : active raid1 sdc[2] sdb[0]
      524224448 blocks super 1.2 [2/1] [U_]
      [====>................]  recovery = 22.3% (116944896/524224448)
                               finish=28.7min speed=236864K/sec

Saving RAID configuration

# Save the RAID configuration (so it auto-assembles on boot)
sudo mdadm --detail --scan | sudo tee /etc/mdadm/mdadm.conf
sudo update-initramfs -u    # Update initramfs to include the config

# Verify the config was saved
cat /etc/mdadm/mdadm.conf

Conclusion

The standard mdadm RAID 1 setup for a data disk takes about 5 minutes to configure: install mdadm, mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc, format the resulting /dev/md0, mount it, and save the config with mdadm --detail --scan. Monitor health with cat /proc/mdstat and configure email alerts. Recovery from a disk failure is: fail, remove, replace disk, add new disk — the rebuild happens automatically in the background.

FAQ

Is Software RAID with mdadm important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support