This page is for Dedicated Servers on which you have root access. Many of them keep their system on a software RAID 1: two disks hold the same data, so the server keeps running when one of them fails. That only helps if you notice the failure and get the disk replaced before the second one fails too. This page shows how to check the RAID, how to get an alert when a disk fails, and what to do after a disk has been replaced. We tested every step on Ubuntu 26.04 LTS with a test RAID 1 on two spare disks of a dedicated server; run the commands as root.
How to create a RAID: How to Create Software RAID on a Dedicated Server.
1. Is My RAID Healthy?
cat /proc/mdstat
Each array is one block, for example:
md5 : active raid1 sda5[0] sdb5[1]
3897447232 blocks super 1.2 [2/2] [UU]
[2/2] [UU] means: two of two disks work, both are Up. More details for one array:
mdadm --detail /dev/md5
A healthy array shows State : clean and lists both disks as active sync.
Sometimes an array shows a line such as [=>....] check = 5.4% … finish=437.4min. That is not a fault: Ubuntu compares the two disks of each array once a month (the timer mdcheck_start), and a big array takes some hours. For example, the check of a 3.6 TB array is planned for about 6 to 7 hours.
2. What a Failed Disk Looks Like
After one disk fails, /proc/mdstat shows, for example:
md9 : active raid1 sdd1[1](F) sdc1[0]
2094080 blocks super 1.2 [2/1] [U_]
[2/1] [U_]: only one of the two disks works;(F)marks the failed one.mdadm --detailshowsState : clean, degradedand the disk asfaulty.- The kernel log (
journalctl -k) saysDisk failure on sdd1, disabling device. Operation continuing on 1 devices.
The server keeps running and the data is intact. But there is no copy left, so act now.
3. Get an Alert When a Disk Fails
The RAID monitor mdmonitor only works when it knows where to send alerts. After the installation it may not be running at all; its log then says No mail address or alert command - not monitoring. Check yours with systemctl status mdmonitor.
On a server freshly installed with Debian 13 and software RAID 1, the installer may have written MAILADDR root at the end of the last ARRAY line instead of on a line of its own. mdmonitor then fails with bad uuid and No mail address or alert command - not monitoring, and the root array runs as md127 instead of the md4 named in the file. Open /etc/mdadm/mdadm.conf with nano, move MAILADDR root to a new line and save. Then:
systemctl restart mdmonitorupdate-initramfs -u
mdmonitor is then active, and after the next restart the root array is md4 again; the server starts normally. MAILADDR root sends alerts to the local user root, which a new server cannot deliver: set your own address as in step 4.
The simplest alert is a small script of your own that mdadm runs for every event. Create /usr/local/sbin/raid-alert:
#!/bin/sh # called by mdadm: $1 = event, $2 = array, $3 = disk echo "$(date -Is) $1 $2 $3" >> /var/log/raid-alert.log
Make it executable with chmod 755 /usr/local/sbin/raid-alert. Instead of the log line, it can send you a message, for example with curl to the address of a chat service you use. Then open /etc/mdadm/mdadm.conf with nano and add a new line at the end:
PROGRAM /usr/local/sbin/raid-alert
The last line of mdadm.conf may have no line break. A quick echo ... >> /etc/mdadm/mdadm.conf then glues the new text to the last ARRAY line, and mdadm reports ARRAY line /dev/md5 has no identity information. Use nano, check that PROGRAM is on a line of its own, and keep a copy of the file before you change it.
Send a test alert and start the monitor:
mdadm --monitor --scan --oneshot --test systemctl restart mdmonitor
The log gets one TestMessage line per array, and systemctl is-active mdmonitor answers active. A real disk failure writes a line such as Fail /dev/md9 /dev/sdd1 within seconds.
4. Alerts by E-mail
mdadm can also send the alert as an e-mail. Your server then needs a way to send mail; the simplest is msmtp, which sends through an ordinary e-mail account, for example the one of your e-mail provider. You need its SMTP server, port, user name and password; your provider lists them in its help pages.
apt install msmtp msmtp-mta
Create /etc/msmtprc with nano, with your own details:
defaults auth on tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile /var/log/msmtp.log account alerts host smtp.example.com port 465 tls_starttls off from server@example.com user server@example.com password your-mailbox-password account default : alerts
For port 587, write port 587 and tls_starttls on instead. The file holds a password, so let only root read it:
chmod 600 /etc/msmtprc
Then add two lines to /etc/mdadm/mdadm.conf, again with nano and each on a line of its own: where the alerts go, and from which address:
MAILADDR you@example.com MAILFROM server@example.com
Send one test e-mail for one array and look at the log of msmtp:
mdadm --monitor --oneshot --test /dev/md2 tail /var/log/msmtp.log systemctl restart mdmonitor
When it works, the log ends with smtpstatus=250 and exitcode=EX_OK, and the e-mail arrives. msmtp-mta also lets other programs on the server send mail through this account, for example cron with MAILTO=you@example.com in the crontab.
5. After a Disk Was Replaced
Our support replaces a failed disk in your dedicated server. Tell them which one has failed: lsblk -d -o NAME,SIZE,SERIAL lists the serial numbers. Before the replacement, take the failed partitions out of every array, for example for sdb:
mdadm /dev/md5 --fail /dev/sdb5 --remove /dev/sdb5
Repeat this for each array that uses the disk (cat /proc/mdstat shows them). After the replacement, the new disk is empty. Copy the partition layout from the healthy disk to the new one, then give the new disk its own IDs. Mind the order: the healthy disk comes first, the new disk after -R:
sgdisk /dev/sda -R /dev/sdb sgdisk -G /dev/sdb
On Debian, sgdisk is not installed by default: apt install gdisk.
Then add each new partition to its array:
mdadm /dev/md5 --add /dev/sdb5
The array copies the data to the new disk; cat /proc/mdstat shows the progress, for example recovery = 25.3%. With 2 GB it takes a few seconds; with several terabytes it can take many hours. When all arrays show [UU] again, the RAID is complete.
Copying the partition layout in the wrong direction erases the healthy disk. Look at cat /proc/mdstat and lsblk before every command. If the server boots from both disks, the new disk also needs the boot loader; ask our support if you are not sure.
Good to Know
- The disks and their health (SMART): What Hardware Is in Your Linux Server? Processor, Memory, Disks and Network.
- RAID is not a backup: a deleted file is deleted on both disks. Keep backups elsewhere: Automatic Encrypted Backups of Your Server to Another Server With restic.