Before You Start
- Dedicated servers: mdadm combines physical disks. The virtual disks of a cloud server already sit on the provider's storage, so a mirror of two of them adds little.
- Creating an array destroys what is on the member disks: identify them with
lsblk -f, by size and serial number, and back up anything on them. There is no undo. - RAID is not a backup: a deleted file is deleted on both disks. See RAID levels explained.
Step 1: Install mdadm and Find the Disks
sudo apt install mdadm # Debian, Ubuntu
sudo dnf install mdadm # AlmaLinux, Rocky Linux
lsblk -o NAME,SIZE,TYPE,SERIAL,MOUNTPOINTSThe examples use two empty disks of the same size, /dev/sdb and /dev/sdc. Device names can change between boots; check them again before each step.
Step 2: Partition Both Disks
sudo parted /dev/sdb --script mklabel gpt mkpart raid 0% 100% set 1 raid on
sudo parted /dev/sdc --script mklabel gpt mkpart raid 0% 100% set 1 raid onmdadm can also use whole disks, but partitions make the layout clear to every tool and a replacement easier. Details are in how to partition a disk.
Step 3: Create the RAID 1 Array
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1This erases what is on both partitions. mdadm uses metadata version 1.2 by default and, for RAID 1, prints a note that the array may not be suitable as a boot device, then asks whether to continue. For a data array, answer yes. The mirror starts syncing at once, and you can use it during the sync.
Step 4: Watch the Array
cat /proc/mdstat
sudo mdadm --detail /dev/md0In /proc/mdstat, [UU] means both members are up; an underscore, as in [U_], marks a missing one. A progress bar shows the sync. mdadm --detail lists the state, each member, and any failed device.
Step 5: File System and Mount
sudo mkfs.ext4 /dev/md0
sudo mkdir -p /srv/data
sudo blkid /dev/md0Add the file system's UUID to /etc/fstab with nofail and the mount point /srv/data, as in /etc/fstab explained, then mount it with sudo mount -a.
Step 6: Save the Array Definition
On Debian and Ubuntu:
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -uOn AlmaLinux and Rocky Linux:
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf
sudo dracut -fWithout this, the array may come back after a reboot under another name, such as md127. Check the file afterward so each array appears once.
Replace a Failed Disk
Keep this order: mark the disk failed, remove it from the array, replace it, partition the new disk, then add it. Here /dev/sdb failed and /dev/sdc is the healthy disk:
sudo mdadm --manage /dev/md0 --fail /dev/sdb1
sudo mdadm --manage /dev/md0 --remove /dev/sdb1
lsblk -o NAME,SIZE,SERIAL,MOUNTPOINTSNote the failed disk's serial number so the right drive is pulled. After the swap, run lsblk again: the new disk has no partitions and must be at least as large as the old one, and its name may differ. In the next step the healthy disk /dev/sdc is the source and the new disk /dev/sdb is the target: sgdisk copies the table of the disk named first onto the disk named after --replicate=, overwriting that one. Swapping the two names would wipe the table of the healthy disk.
lsblk -o NAME,SIZE,SERIAL,TYPE
sudo sgdisk /dev/sdc --replicate=/dev/sdb
sudo sgdisk -G /dev/sdb
lsblk /dev/sdb /dev/sdc
sudo mdadm --manage /dev/md0 --add /dev/sdb1
cat /proc/mdstat-G gives the copy its own GUIDs, as the sgdisk manual advises. sgdisk is in the gdisk package. If the array holds the system, also install the boot loader on the new disk. The rebuild runs in the background.
Alerts
A mirror with one dead disk works until the second one fails, so you need to hear about the first. Set the MAILADDR line in mdadm.conf; if the file already has one, change it rather than add a second:
MAILADDR YOUR_EMAILThe mdadm monitor service sends mail when an array degrades; it needs a working mail setup, as in how to send email from the Linux command line. Test it with sudo mdadm --monitor --scan --test --oneshot. Check the disks themselves with smartctl.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations