mdadm is the standard Linux tool for creating and managing software RAID arrays. RAID provides redundancy and/or performance improvements across multiple disks. This guide creates a RAID 1 (mirror) array on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- Two or more additional block devices (e.g. /dev/sdb, /dev/sdc) of equal size
- A user with sudo privileges
Step 1 – Install mdadm
Install the RAID management tool:
sudo apt update
sudo apt install mdadm -y
Step 2 – Identify Available Disks
List available block devices:
lsblk
cat /proc/partitions
Step 3 – Create a RAID 1 Array
Create a mirrored array from /dev/sdb and /dev/sdc:
sudo mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdb /dev/sdc
Step 4 – Monitor Array Creation
Watch the synchronisation progress:
cat /proc/mdstat
sudo mdadm --detail /dev/md0
Step 5 – Create a Filesystem and Mount
Format and mount the RAID device:
sudo mkfs.ext4 -F /dev/md0
sudo mkdir /mnt/raid1
sudo mount /dev/md0 /mnt/raid1
Step 6 – Save the Configuration
Save the mdadm config and update initramfs:
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u
Step 7 – Add to /etc/fstab
Mount automatically on boot:
echo '/dev/md0 /mnt/raid1 ext4 defaults 0 2' | sudo tee -a /etc/fstab
Step 8 – Simulate a Disk Failure
Test RAID resilience by marking a disk as faulty:
sudo mdadm --manage /dev/md0 --fail /dev/sdc
cat /proc/mdstat
Replace the disk:
sudo mdadm --manage /dev/md0 --remove /dev/sdc
sudo mdadm --manage /dev/md0 --add /dev/sdc
Conclusion
Software RAID 1 is now configured on Ubuntu 24.04 LTS with mdadm. Your data is mirrored across two disks — if one fails, the server continues running with no data loss.