Check that an array is healthy
A healthy array shows State : clean and Failed Devices : 0. Any
degraded, (F) or _ in the square brackets means a disk must be
replaced: mdadm.
RAID combines disks into one device that keeps working after one of them fails (except RAID 0).
cat /proc/mdstat
every array: [UU] or [U_]
sudo mdadm --detail /dev/md0
State: clean, degraded, recovering
lsblk
disks and the array on top (raid1)
sudo dmesg | grep md/raid
when and which disk dropped out
RAID (redundant array of independent disks) combines several disks into one block device. Data is spread over the disks so that one failure does not stop the work: the system reads and writes through the remaining ones. The exception is RAID 0: it keeps no spare copies.
On Linux the kernel builds the array (the md driver) and mdadm
manages it. The array shows up as /dev/md0; you create a file system
(filesystems) or an LVM volume on it, just like on a plain
disk. A hardware RAID controller does the same internally and shows the
system one ready-made disk; then /proc/mdstat is empty and you check the
state with the controller's own tool.
N is the number of disks in the array, all of the same size.
| Level | Minimum disks | Survives the failure of | Usable space | How it works |
|---|---|---|---|---|
| RAID 0 | 2 | no disk | N disks | stripe: blocks go to each disk in turn |
| RAID 1 | 2 | N − 1 disks | 1 disk | mirror: every disk holds a full copy |
| RAID 5 | 3 | 1 disk | N − 1 disks | stripe plus parity that rebuilds any one disk |
| RAID 6 | 4 | 2 disks | N − 2 disks | stripe plus two parities |
| RAID 10 | 4 | 1 disk in each pair | N / 2 disks | stripe over mirrored pairs |
RAID 10 on four disks survives two failures if they are in different pairs and loses data if both disks of one pair fail. RAID 5 writes slower than a mirror: every write recalculates parity.
RAID 1 writes every block to all disks of the array and reads from any of them. Two 256 MiB disks give a 255 MiB array: part of the space holds the superblock — mdadm's record of the array members at the start of each disk.
A degraded array works but has lost part of its redundancy: one or more disks dropped out. The data is intact and available, writes go to the remaining disks. One more failure beyond what the level survives loses data: for a two-disk RAID 1 that is the failure of the last disk.
[2/1] — the array should have two disks, one is working. [U_] is the
same by slot: the first slot is filled (U, up), the second is empty.
(F) marks a failed (faulty) disk. The kernel log at that moment:
mdadm --detail prints State : clean, degraded or active, degraded
(active means the array was written to recently). How to read every
field — mdadm.
After a disk is replaced the kernel copies onto the new disk everything
that belongs there — a rebuild. In /proc/mdstat it shows as
recovery = N% with an estimate finish= and a rate speed=. Checking
the copies right after an array is created is called resync and looks
the same; the array already works meanwhile.
A rebuild reads every block of the surviving disks. On the lab machine an
array of 256 MiB images rebuilds in seconds, a multi-terabyte disk takes
hours, and the array stays degraded all that time. The rate is bounded by
/proc/sys/dev/raid/speed_limit_min and speed_limit_max (KiB/s, 1000
and 200000 on the lab machine).
A hot spare is a disk in the array without a slot of its own:
/proc/mdstat marks it (S), mdadm --detail says spare. When a
working disk fails, the kernel takes the spare and starts a rebuild
without waiting for a person. A disk added to a healthy array becomes a
spare.
RAID protects against one thing: a disk failure. A deleted file, mkfs on
the wrong device, a database corrupted by an application, ransomware — the
array writes all of it to every copy at once. Only a copy kept elsewhere
helps there: restic, rsync, tar.
A healthy array shows State : clean and Failed Devices : 0. Any
degraded, (F) or _ in the square brackets means a disk must be
replaced: mdadm.
An array can be built from any block devices, including loop devices — files attached as disks:
Loop devices are not attached again after a reboot, and an array of them does not assemble by itself: the service that attaches the images does it, or you do it by hand — mdadm.
The array is degraded, the data is still intact. Find the disk that
dropped out ((F) in /proc/mdstat, faulty or removed in
mdadm --detail), remove it from the array and add a working one —
mdadm. Until the rebuild finishes the array has no
protection.
That is expected on large disks: the kernel reads the surviving disks in
full. The estimate is finish= in /proc/mdstat. Under load the rebuild
slows down, but not below speed_limit_min. Do not power the machine off
while it runs.
The failure is reported by mdmonitor — the mdadm service that mails the
address in MAILADDR of /etc/mdadm/mdadm.conf. Without a mail service
the message never leaves: on the lab machine the journal keeps
DegradedArray and sendmail: not found. So a check of /proc/mdstat
goes into monitoring. More — mdadm.
While the array is degraded or rebuilding there is no redundancy. Disks of the same batch and age often fail one after another, and a rebuild loads the surviving disk harder than usual. Replace the disk right away and keep a fresh copy of the data outside the array.
RAID 0 keeps no copies: the failure of any disk loses the whole array, and the more disks, the more likely that is. Use it only for data you can afford to lose.
mdadm.conf./dev/md0.Found an inaccuracy? Report an error in the article