The Problem
When trying to re-add a device to a raid, you get the following message:
# mdadm /dev/md2 --add /dev/sda1 mdadm: Cannot open /dev/sda1: Device or resource busy
Whereas the mdstat command indicates that the device is inactive.
# cat /proc/mdstat Personalities : md2 : inactive sda1[0](S) 292928154 blocks super 1.2 unused devices: [none]
mdadm fail to create software raid device with Device or resource busy error message.
The solution
Pre-checks
Before we proceed, make sure that if partitions were part of any active FS.
mdadm --detail /dev/md2 mdadm: md device /dev/md2 does not appear to be active. mdadm --detail --scan >> /etc/mdadm.conf mdadm: md device /dev/md2 does not appear to be active. # ls -l /etc/mdadm.conf -rw-r--r-- 1 root bin 0 Sep 18 21:17 /etc/mdadm.conf # cat /etc/mdadm.conf
The cause of issue
The cause of this issue can be that the device-mapper-multipath ( or other device-mapper modules ) has control over this device, therefore mdadm cannot access it. The command “dmsetup table” will show that this devices is controlled by the device-mapper ( see “man dmsetup” for more detailed information )
# dmsetup table
Workaround
As a workaround you can remove the device from the device-mapper table with the below command.
# dmsetup remove [device id]
Permanent solution
As a solution you can either start your server without certain device-mapper modules, for example dmraid you can add “nodmraid” to the kernel command line in /etc/grub.conf as shown below.
title Enterprise Linux Enterprise Linux Server (2.6.32-100.24.1.el5) root (hd0,0) kernel /vmlinuz-2.6.32-100.24.1.el5 ro root=/dev/vg00/lv00 console=tty0 nodmraid initrd /initrd-2.6.32-100.24.1.el5.img
or if device-mapper-multipath has control over this device you can add it to the blacklist section in /etc/multipath.conf
# vi /etc/multipath.conf blacklist { wwid [your world-wide-id for this device] }
Reload the multipathd for changes to take effect:
# service multipathd reload # multipath -v2
Make sure multipath does not create maps for these devices in ‘multipath -ll’.
# multipath -ll
The device-mapper should not take control at boot time.
Verify
Once you have performed the steps mentioned above, you should be ableto create the software RAID. To verify:
# mdadm /dev/md2 --add /dev/sda1