linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/File system/raid

kb/filesystem ── File system ── advanced

RAID: software RAID with mdadm

RAID combines several [[block-devices]] into one logical device for redundancy or speed. On Linux you use `mdadm`. Hardware RAID is a separate story.

view as markdownaka: mdadm, software-raid, md-raid

RAID levels

LevelWhat it doesExample from 4 disks of 1 TBProtection
0 (stripe)Parallelize I/O4 TBNONE; one disk dies = everything lost
1 (mirror)Full copies1 TB (mirror)Survives N-1 disk failures
5Striping + parity3 TBSurvives 1 disk failure
6Striping + 2 parity2 TBSurvives 2 disk failures
10Stripe of mirrors2 TBOne failure per mirror

RAID 0 is not RAID in the sense of reliability. It is just a stripe for speed.

Creating an array

bash
# RAID 1 (mirror) from two disks
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
cat /proc/mdstat                           # build progress
sudo mdadm --detail /dev/md0               # full details
# Create the filesystem
sudo mkfs.ext4 /dev/md0
sudo mount /dev/md0 /mnt/raid
# Save the config so the array assembles after a reboot
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u                   # debian/ubuntu

Array state

bash
cat /proc/mdstat

▸typically looks like:

#   md0 : active raid1 sdb1[0] sdc1[1]
#         976630464 blocks super 1.2 [2/2] [UU]

▸[UU] = both disks "Up"; [U_] = one disk dropped out

▸"resync" / "recovery" with progress = a rebuild is running

sudo mdadm --detail /dev/md0

▸State: clean / degraded / resyncing

The /proc/mdstat file is the main source of truth. A healthcheck just parses it for the presence of [U_].

Disk failure

bash
# Simulate a failure
sudo mdadm /dev/md0 --fail /dev/sdc1
# Remove it from the array
sudo mdadm /dev/md0 --remove /dev/sdc1
# Replace with a new disk (same size!)
sudo mdadm /dev/md0 --add /dev/sdd1
# The array starts the rebuild automatically. Watch it:
watch -n 1 cat /proc/mdstat

While the rebuild runs the array is degraded, and one more failure means everything is gone. On large RAID 5/6 arrays the rebuild can take days. That is where RAID 5 gets its reputation as "dangerous" for disks over 2 TB.

Spare disk

bash
sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 \
  --spare-devices=1 /dev/sd{b,c,d}1 /dev/sde1

A spare waits in the pool. When any active disk fails, mdadm starts the rebuild onto it automatically. This shrinks the window of vulnerability sharply.

The stack: RAID + LVM + filesystem

A standard server setup:

/dev/sd[bcd]1  ←  RAID 5 → /dev/md0  ←  LVM PV → vg-data → lv-web → ext4 → /mnt/web

Each layer adds its own thing:

  • RAID gives you reliability
  • LVM gives you flexible sizing and snapshots
  • the filesystem holds the actual files

Hardware vs software

  • Hardware RAID (a controller on PCI): the OS sees a ready-made "disk". Pros: a battery-backed write cache, the CPU is offloaded. Cons: vendor lock-in (if the controller dies you need an identical one); firmware bugs.
  • Software RAID (mdadm): runs on any hardware, is portable, and the OS sees and controls it. Cons: it uses CPU and RAM; there is no native battery-backed cache.

For most cases software RAID + a UPS is the better choice: it is portable, debuggable, and has no vendor lock-in.

ZFS and btrfs as an alternative

zfs and btrfs have built-in RAID (RAID-Z, btrfs raid). They keep data checksums and therefore detect bit rot on read better (md RAID trusts that "the disk said OK"). The downside is they are more complex, and btrfs RAID 5/6 has historically been buggy.

§ команды

bash
cat /proc/mdstat

State of all md arrays. The main monitoring command

bash
sudo mdadm --detail /dev/md0

Full details: state, devices, last sync, errors

bash
sudo mdadm --create /dev/md0 -l 1 -n 2 /dev/sdb1 /dev/sdc1

Create a RAID 1 (mirror) from two disks

bash
sudo mdadm /dev/md0 --add /dev/sde1

Add a new disk to the array (for replacement or rebuild)

bash
echo check | sudo tee /sys/block/md0/md/sync_action

Start scrubbing: walk every block and check consistency

§ см. также

  • block-devicesBlock devices: disks in LinuxA block device is read and written in fixed-size blocks (usually 512B or 4K). Disks, SSDs, and NVMe drives are all block devices in `/dev/`.
  • lvmLVM: Logical Volume ManagerLVM is a layer between [[block-devices]] and the filesystem: it pools disks and carves out logical volumes of any size that you can grow, snapshot, and migrate live.
  • btrfsbtrfs: copy-on-write, subvolumes, and snapshotsbtrfs is a copy-on-write filesystem with subvolumes, O(1) snapshots, native RAID 0/1/10, and data checksums. RAID 5/6 is problematic. COW fragmentation hurts databases and VM images, so turn it off for them.
  • filesystemsFilesystems: ext4, xfs, btrfs, zfsext4 is the reliable default. xfs handles large files and parallel I/O. btrfs and zfs give you snapshots, checksums, and built-in RAID, but they are more complex.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies