During the setup of RAID 1 for our server, I encountered an issue where the RAID array did not mount properly after a reboot. The key problem was related to the RAID device name, which affected how it was referenced in /etc/fstab.
- Understanding the Issue
After rebooting the system, I checked the RAID status using:
$cat /proc/mdstat
And received the following output:
Personalities : [raid1]
md127 : active raid1 sdb1[0] sdc1[1]
976630464 blocks super 1.2 [2/2] [UU]
However, when attempting to retrieve the UUID for auto-mounting:
$blkid | grep md0
It returned no output.
- Root Cause: Dynamic RAID Device Naming
The issue occurred because, after rebooting, the RAID array was detected as md127 instead of md0. This happens when the system automatically assigns a different RAID device name at boot. To verify this, run:
$lsblk
showed the RAID array as /dev/md127 instead of /dev/md0.
Solution: Persistent RAID Device Naming
To ensure the RAID array is always recognized correctly:
Stop and Reassemble RAID Array
- Stop and Reassemble RAID Array
$ sudo mdadm --stop /dev/md127
Now reassemble the device as md0 from md127:
sudo mdadm --assemble --name=md0 /dev/md0 /dev/sdb /dev/sdc
Now, check the new RAID status, and you will find the device name has been changed
- Update mdadm Configuration
Run the following command to record the correct RAID configuration:
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
Then, update the initramfs so the RAID array name is consistent at boot:
update-initramfs -u
- Use the Correct RAID Device Name in fstab
Now we can add the UUID in /etc/fstab
echo "UUID=$(blkid -s UUID -o value /dev/md0) /mnt/data ext4 defaults,nofail 0 0" | sudo tee -a /etc/fstab
After applying these changes, please reboot the server. Once the system is back up, confirm the RAID array is mounted correctly with the command “df -h”. The issue arose because RAID device names can change dynamically after reboot. By stopping and reassembling the RAID array, updating the mdadm.conf file and using UUID instead of the device name in /etc/fstab, we ensure that the RAID array consistently mounts at boot without manual intervention.