Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Software RAID on Linux with mdadm

By Kokil Thapa | Last reviewed: September 2026

When a single disk fails on a production server, everything on that volume can vanish unless you planned for redundancy. Software RAID on Linux with mdadm solves that problem without a dedicated RAID card. The kernel's Multiple Device (MD) driver mirrors or stripes block devices, and mdadm creates, monitors, and repairs those arrays. I've relied on this stack on Ubuntu servers that host Linux system administration workloads for Laravel apps, MySQL databases, and nightly backup volumes. This guide walks through RAID levels, setup commands, monitoring, disk replacement, and the mistakes that cause painful recoveries.

What is software RAID on Linux with mdadm?

Software RAID runs entirely in the Linux kernel and user-space tools. Hardware RAID offloads parity and mirroring to a controller with its own firmware and often proprietary management. Software RAID uses CPU cycles instead, but it costs nothing beyond the disks themselves and works on any server—from a VPS with extra volumes to bare-metal EC2 instances I maintain for production booking platforms.

The mdadm package (current stable releases ship version 4.x on Ubuntu 24.04 LTS) manages MD devices exposed as /dev/md0, /dev/md1, and so on. Each MD device is a virtual block layer sitting above member partitions such as /dev/sdb1 and /dev/sdc1. File systems, LVM physical volumes, or direct mounts sit on top of the MD device.

Software RAID Stack on Linux/dev/sdb1Disk 1/dev/sdc1Disk 2/dev/sdd1Disk 3/dev/sde1Disk 4/dev/md0 — mdadm managed arrayKernel MD driverLVM / ext4 / XFS file systemApplication data
Software RAID on Linux with mdadm sits between physical partitions and the file system or LVM layer.

Software RAID pairs naturally with LVM for flexible disk management. A common pattern places an MD RAID 1 array beneath LVM, then creates logical volumes for /, /var, and database storage. That separation lets you resize volumes without rebuilding the underlying mirror.

Software RAID vs hardware RAID

FactorSoftware RAID (mdadm)Hardware RAID
CostFree; uses existing disks and CPUController card, often Rs 15,000–50,000 (~USD 110–370)
PortabilityArray metadata on disks; move disks to any Linux boxLocked to controller firmware; rebuild may need identical hardware
PerformanceUses host CPU for parity (RAID 5/6)Dedicated processor; battery-backed cache helps writes
Managementmdadm, /proc/mdstat, standard Linux toolsVendor BIOS, CLI, or web UI (varies by brand)
Boot supportRequires initramfs with mdadm modulesController presents single logical disk; simpler boot path
Best fitCloud VMs, budget servers, DevOps-managed LinuxHigh-IOPS databases, large SAN-style deployments

For most small and mid-size web servers I operate, software RAID on Linux with mdadm is the practical default. Hardware RAID earns its place when you need battery-backed write cache and sub-millisecond latency guarantees on heavy database workloads.

Which RAID level should you choose for a Linux server?

Choosing the wrong RAID level is a common mistake. RAID 0 stripes data for speed but offers zero redundancy—lose one disk and you lose everything. RAID 1 mirrors two disks; you keep half the raw capacity but survive a single failure. RAID 5 stripes with distributed parity across three or more disks; you lose one disk's worth of capacity and tolerate one failure. RAID 6 adds a second parity block and tolerates two simultaneous failures. RAID 10 (1+0) mirrors then stripes pairs; it needs at least four disks and delivers strong read performance with one-disk fault tolerance per mirror pair.

Common mdadm RAID LevelsRAID 1 MirrorDisk ADisk B2 disks, 1 failure OKRAID 5 ParityD1D2P3+ disks, 1 failure OKRAID 10 StripeA1A2B1B24 disks, fast I/OProduction server recommendationsWeb app + MySQL: RAID 1 or RAID 10 on SSDBackup volume: RAID 5 on large HDDsBoot partition: RAID 1 with separate /boot
RAID 1, RAID 5, and RAID 10 are the most common mdadm layouts for Linux web and database servers.

On production Laravel hosts I maintain, RAID 1 on two NVMe drives covers the operating system and application code. Database data either sits on a separate RAID 10 set or on cloud block storage with its own redundancy. RAID 5 makes sense for bulk backup storage where cost per terabyte matters more than write latency.

  • RAID 1: Two disks, 50% usable capacity, simplest recovery path.
  • RAID 5: Three or more disks, good read speed, slow rebuilds on large drives.
  • RAID 6: Safer during rebuild windows when another disk might fail.
  • RAID 10: Best random I/O for databases; needs four disks minimum.

Match your RAID choice to recovery time objectives. A 4 TB RAID 5 rebuild can take many hours. During that window the array runs in degraded mode. Plan automated database backups on Linux regardless of RAID level—RAID is not a backup strategy.

How do you create a RAID array with mdadm on Ubuntu?

Start with identical disk sizes when possible. Mixed capacities work, but the array sizes itself to the smallest member. Use GPT partition tables and mark RAID partitions with type FD (Linux RAID) so tools recognise them instantly.

Install mdadm and prepare disks

sudo apt update
sudo apt install mdadm
lsblk -o NAME,SIZE,TYPE,FSTYPE
sudo parted /dev/sdb --script mklabel gpt mkpart primary 1MiB 100%
sudo parted /dev/sdc --script mklabel gpt mkpart primary 1MiB 100%
sudo parted /dev/sdb set 1 raid on
sudo parted /dev/sdc set 1 raid on

Verify partition types before proceeding. A wrong partition flag causes mdadm to reject members or GRUB to miss boot partitions. On servers where I deploy alongside domain and hosting setup, I document disk serial numbers in the runbook before touching partitions.

Create a RAID 1 mirror array

sudo mdadm --create /dev/md0 \
  --level=1 \
  --raid-devices=2 \
  /dev/sdb1 /dev/sdc1

cat /proc/mdstat
sudo mkfs.ext4 /dev/md0
sudo mkdir -p /mnt/raid
sudo mount /dev/md0 /mnt/raid

The --create command writes superblock metadata to each member. That metadata lets mdadm reassemble the array after reboot. Without saving the array definition, your server may boot with degraded or missing arrays.

Persist the array across reboots

  1. Capture the array layout: sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
  2. Update the initramfs so early boot can assemble RAID: sudo update-initramfs -u
  3. Add a /etc/fstab entry using the MD UUID, not /dev/md0
  4. Test with a controlled reboot during a maintenance window
sudo blkid /dev/md0
# Add to /etc/fstab:
# UUID=abc123-def456  /data  ext4  defaults,nofail  0  2

Using UUIDs in fstab prevents mount failures when device names shift after adding disks. This behaviour mirrors the guidance in articles on Linux file permissions and ACLs—predictable, explicit configuration beats assumptions about device order.

mdadm Array Creation WorkflowInstall mdadmapt installPartition disksGPT type FDmdadm --createDefine levelFormat FSmkfs.ext4Save mdadm.conf + update-initramfsCritical for boot persistenceAdd UUID entry to /etc/fstabReboot and verify /proc/mdstatProduction ready array
Creating software RAID on Linux with mdadm requires persisting configuration before the first production reboot.

Create RAID 5 for bulk storage

sudo mdadm --create /dev/md1 \
  --level=5 \
  --raid-devices=4 \
  /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1

RAID 5 creation triggers an initial parity calculation. Monitor progress with watch cat /proc/mdstat. Heavy I/O during sync slows the process. Schedule creation during low-traffic hours and read about log rotation and disk space management before filling the array with application logs.

How do you monitor and recover a failed mdadm RAID disk?

Monitoring is where many teams fail. They build the array once and forget it until a disk dies at 2 AM. Set up proactive alerts before that happens.

Check array health

cat /proc/mdstat
sudo mdadm --detail /dev/md0
sudo smartctl -a /dev/sdb

The State line in mdadm --detail output should read clean. A degraded state means a member is missing or failed. The Rebuild Status section shows progress when a replacement disk is syncing. Integrate these checks into your existing Linux server monitoring with Netdata and alerts pipeline, or schedule them via cron jobs.

Replace a failed disk

  1. Identify the failed member: sudo mdadm --detail /dev/md0
  2. Mark it failed if not already: sudo mdadm --manage /dev/md0 --fail /dev/sdb1
  3. Remove it from the array: sudo mdadm --manage /dev/md0 --remove /dev/sdb1
  4. Physically replace the disk, partition the new drive identically
  5. Add the new member: sudo mdadm --manage /dev/md0 --add /dev/sdb1
  6. Watch rebuild: watch cat /proc/mdstat

During rebuild the array operates in degraded mode. Another disk failure on RAID 1 means total data loss. On RAID 5, a second failure during rebuild destroys the array. Replace failed disks immediately. Keep hot spares only if your hardware supports automatic insertion.

mdadm Failure Recovery SequenceDisk failure detected/proc/mdstat shows [U_]Array runs degradedNo redundancy until fixedFail and remove diskmdadm --manage --failInsert and partitionMatch partition layoutRebuild completeState: clean [UU]
Software RAID on Linux with mdadm recovery follows a strict fail-remove-add-rebuild sequence to restore redundancy.

Email alerts from mdadm ship via the MAILADDR directive in /etc/mdadm/mdadm.conf. On modern systems I prefer hooking into systemd-managed monitoring services that page on SMART errors before the disk fully dies. Predictive failure beats emergency rebuilds every time.

Simulate failure safely in staging

sudo mdadm --manage /dev/md0 --fail /dev/sdc1 --remove /dev/sdc1
sudo mdadm --manage /dev/md0 --add /dev/sdc1

Never run failure simulation on production without a verified backup and a maintenance window. Document every step in your runbook. Teams that practice recovery in staging fix real incidents in minutes instead of hours.

How do you boot Linux from a software RAID array?

Booting from software RAID on Linux with mdadm adds complexity because GRUB and the initramfs must understand MD devices. Ubuntu and Debian handle most cases automatically when you install with RAID selected in the installer. Manual setups need extra care.

Separate /boot for RAID 1

GRUB historically struggled with RAID 5 and RAID 6 boot partitions. The safe pattern mirrors both /boot and root on RAID 1 while keeping /boot on a small ext4 partition. Install GRUB to both member disks:

sudo grub-install /dev/sdb
sudo grub-install /dev/sdc
sudo update-grub

If the primary boot disk fails, the BIOS or UEFI firmware can boot from the secondary disk. Verify both disks appear in your firmware boot order. On sister sites I maintain with Deployer 7 pipelines, boot-disk documentation lives next to deployment notes so any engineer can recover without guessing.

Initramfs requirements

The initramfs must include mdadm, required kernel modules, and the assembled array definition. After any change to RAID layout, always run:

sudo update-initramfs -u

A missing or stale initramfs produces the dreaded busybox shell on boot. The kernel cannot find the root file system because the MD array never assembled. Keep a rescue ISO or serial console access available before your first RAID boot test.

Reference the official kernel documentation at docs.kernel.org/admin-guide/md.html for MD driver internals. The Debian wiki RAID page at wiki.debian.org/RAID covers distribution-specific installer paths. Ubuntu's mdadm man page remains the authoritative command reference.

Grow an existing array

When you add disks to expand capacity, mdadm supports growing certain levels online. For RAID 1, add a member then grow:

sudo mdadm --manage /dev/md0 --add /dev/sdd1
sudo mdadm --grow /dev/md0 --raid-devices=3
sudo resize2fs /dev/md0

Back up before any grow operation. Growing triggers a resync that stresses all member disks. Combine this with Linux performance tuning with sysctl if I/O contention affects application response times during the sync.

Key Takeaways

  • Software RAID on Linux with mdadm provides disk redundancy without proprietary hardware—ideal for budget servers and cloud VMs.
  • Choose RAID 1 or RAID 10 for boot and database volumes; use RAID 5 for bulk backup storage where cost per terabyte matters.
  • Always save /etc/mdadm/mdadm.conf and run update-initramfs -u before rebooting a new array.
  • Monitor /proc/mdstat and SMART data proactively—RAID protects against disk failure, not data corruption or accidental deletion.
  • Practice disk replacement in staging so production recovery takes minutes, not hours.
  • Keep independent backups via tools and scripts described in your support and maintenance runbooks.

People Also Ask

Can you use software RAID on Linux with mdadm in the cloud?

Yes. AWS, DigitalOcean, and other providers attach multiple block volumes to a single VM. Partition each volume, create an mdadm array, and mount it like bare metal. The redundancy protects against single-volume failure, not availability-zone outages. Combine RAID with cross-zone backups for full coverage.

Does mdadm work with SSD and NVMe drives?

mdadm works with any block device, including NVMe namespaces and SSDs. Enable periodic TRIM on SSD-backed arrays with fstrim scheduled via systemd timer or cron. Monitor wear indicators through SMART attributes. RAID 10 on NVMe delivers excellent random I/O for MySQL and PostgreSQL workloads.

What happens if you forget to update mdadm.conf?

The array may fail to assemble at boot. The kernel sees member partitions with RAID superblocks but lacks the assembly rules. You land in initramfs recovery or face an unbootable system. Boot from rescue media, run mdadm --assemble --scan, fix the config, update initramfs, and reboot.

Is software RAID slower than hardware RAID?

For RAID 1 and RAID 10 on modern CPUs, the difference is often negligible for web workloads. RAID 5 and RAID 6 parity calculation consumes CPU cycles that a hardware controller offloads. On a typical Laravel or WordPress server, network and database query time dominate latency—not MD driver overhead.

Build reliable storage into your server architecture

Software RAID on Linux with mdadm is a proven, portable way to keep production data available when disks fail. The setup takes an afternoon. The payoff lasts years—if you monitor arrays, persist configuration correctly, and maintain backups independent of RAID. I've seen unmonitored mirrors fail silently until the second disk died and took the business offline.

If you need help designing storage for a new deployment or recovering a degraded array on an existing server, review the Linux system administration services I offer or browse the production server portfolio for examples of maintained infrastructure. For quick server-side calculations during planning, the password generator and other online tools sit alongside deeper guides on diagnosing high CPU and memory usage and essential Ubuntu commands. Contact us to discuss RAID planning for your next enterprise application deployment.

Frequently Asked Questions

Software RAID runs in the Linux kernel MD driver plus the mdadm utility. It combines block devices into redundant virtual disks like /dev/md0 without a dedicated RAID controller card.

Software RAID is free beyond the disks and host CPU. Hardware RAID controllers typically cost Rs 15,000–50,000 (~USD 110–370), plus proprietary management overhead.

No. RAID protects against disk failure, not data corruption, accidental deletion, or site-wide outages. Maintain independent backups regardless of RAID level.

Software RAID uses the kernel MD driver and mdadm, costs nothing beyond disks, stores metadata on disks for portability, and uses host CPU for parity on RAID 5 and RAID 6. Hardware RAID offloads work to a controller with firmware, often includes battery-backed write cache, and locks you to vendor tools and sometimes identical hardware for rebuilds. For most small and mid-size web servers hosting Laravel apps, MySQL, and backups, mdadm is the practical default. Hardware RAID earns its place when you need sub-millisecond latency guarantees on heavy database workloads.

Match the level to your recovery needs and disk count. RAID 0 stripes for speed with zero redundancy—avoid it for production data. RAID 1 mirrors two disks at 50% usable capacity and offers the simplest recovery path, ideal for OS and application code on Laravel hosts. RAID 5 suits bulk backup storage where cost per terabyte matters, tolerating one failure across three or more disks. RAID 6 adds a second parity block for two simultaneous failures. RAID 10 needs at least four disks and delivers strong random I/O for MySQL or PostgreSQL, with one-disk fault tolerance per mirror pair.

Install mdadm, partition identical disks with GPT, and mark partitions as type FD (Linux RAID). Create the array with mdadm --create specifying --level=1, --raid-devices=2, and member partitions such as /dev/sdb1 and /dev/sdc1. Verify progress in /proc/mdstat, then format and mount the MD device. Before any production reboot, capture the layout with mdadm --detail --scan into /etc/mdadm/mdadm.conf and run update-initramfs -u. Document disk serial numbers in your runbook before touching partitions, especially on servers where you also handle domain and hosting setup.

After creating any array, run mdadm --detail --scan and append the output to /etc/mdadm/mdadm.conf. Then run update-initramfs -u so early boot includes mdadm, required kernel modules, and the assembled array definition. Add fstab entries using the MD device UUID from blkid, not /dev/md0, because device names can shift when disks are added. Test with a controlled reboot during a maintenance window. Skipping these steps is a common cause of degraded or missing arrays after restart, and on manual setups can leave you in an initramfs recovery shell.

The array may fail to assemble at boot. The kernel sees member partitions with RAID superblocks but lacks assembly rules, so the MD device never forms and the root file system cannot mount. You may land in an initramfs busybox shell or face an unbootable system. Recovery involves booting from rescue media, running mdadm --assemble --scan, fixing /etc/mdadm/mdadm.conf, running update-initramfs -u, and rebooting. This is why persisting configuration before the first production reboot is non-negotiable when setting up software RAID on Linux with mdadm.

Yes. Providers such as AWS and DigitalOcean attach multiple block volumes to a single VM. Partition each volume, mark them as Linux RAID, create an mdadm array, and mount it like bare metal. Redundancy protects against single-volume failure within that instance, not an entire availability-zone outage. Combine RAID with cross-zone or off-site backups for full coverage. I've used this pattern on bare-metal EC2 instances hosting production booking platforms where portability and zero controller cost matter more than hardware RAID firmware.

mdadm works with any block device, including SSDs and NVMe namespaces. Enable periodic TRIM on SSD-backed arrays via fstrim scheduled through a systemd timer or cron. Monitor wear through SMART attributes using tools like smartctl alongside /proc/mdstat checks. RAID 10 on NVMe delivers excellent random I/O for MySQL and PostgreSQL workloads. On production Laravel hosts I maintain, RAID 1 on two NVMe drives covers the operating system and application code, while database data may sit on a separate RAID 10 set or cloud block storage with its own redundancy.

For RAID 1 and RAID 10 on modern CPUs, the difference is often negligible for web workloads. RAID 5 and RAID 6 parity calculation consumes host CPU cycles that a hardware controller offloads, and battery-backed cache helps heavy write workloads. On a typical Laravel or WordPress server, network latency and database query time dominate—not MD driver overhead. Hardware RAID earns its place when you need dedicated processors and sub-millisecond latency guarantees on high-IOPS database deployments, not for most budget servers and cloud VMs managed through standard Linux tools.

Check /proc/mdstat and run mdadm --detail on each MD device—the State line should read clean, not degraded. Use smartctl against member disks to catch SMART errors before full failure. Integrate these checks into your existing monitoring pipeline via Netdata alerts or cron jobs. The MAILADDR directive in /etc/mdadm/mdadm.conf enables email alerts, though I prefer systemd-managed monitoring that pages on predictive SMART failures. Many teams build arrays once and forget them until a disk dies at 2 AM—proactive alerts prevent that painful scenario.

Follow the strict fail-remove-add-rebuild sequence. Identify the failed member with mdadm --detail, mark it failed if needed with mdadm --manage --fail, then remove it with --remove. Physically replace the disk, partition the new drive identically with the Linux RAID flag, and add it with --manage --add. Monitor rebuild progress via /proc/mdstat. During rebuild the array runs degraded—another failure on RAID 1 means total data loss, and on RAID 5 a second failure destroys the array. Replace failed disks immediately. Practice this sequence in staging so production recovery takes minutes, not hours.

GRUB and initramfs must understand MD devices. The safe pattern mirrors both /boot and root on RAID 1 using a small ext4 /boot partition—GRUB historically struggled with RAID 5 and RAID 6 boot partitions. Install GRUB to both member disks with grub-install on each, then update-grub. Ensure initramfs includes mdadm and array definitions by running update-initramfs -u after any layout change. Verify both disks appear in firmware boot order so the secondary disk boots if the primary fails. Keep a rescue ISO or serial console access before your first RAID boot test.

For RAID 1, add a new member with mdadm --manage --add, then grow the array with mdadm --grow --raid-devices set to the new count, and finally run resize2fs on the file system atop the MD device. Back up before any grow operation—growing triggers a resync that stresses all member disks and can affect application response times during sync. Schedule the operation during low-traffic hours. mdadm supports growing certain levels online, but treat every capacity expansion as a maintenance event requiring verified backups and documented steps in your runbook.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: