Basic Commands
- Checking status of drive/arrays, displaying all raids and basic information
# cat /proc/mdstat
- Detailed status of array
# mdadm --detail /dev/md2
- Creating raid device
# mdadm --create --verbose /dev/mdX --level=RAID5--raid-devices=2 /dev/sdj /dev/sdk
- Stoping raid device
# mdadm --stop /dev/md2
- Adding a drive:
# mdadm /dev/md2 -a /dev/sdm
- Marking a drive as failed (This will break things if your not careful)
# mdadm --manage --set-faulty /dev/md2 /dev/sdm
- Removing a drive:
# mdadm /dev/md2 -r /dev/sdm
- Forcing a full check of the raid:
# echo check >> /sys/block/mdX/md/sync_action
Troubleshooting and examples:
Growing a RAID5 array:
To expand your array, to have another drive in it.. you first should force a complete check of the drive so that it doesn’t fail while rebuilding.
# echo check >> /sys/block/mdX/md/sync_action
That will take a while. Then you add your new device.
# mdadm /dev/mdX -a /dev/sdx?
If you do a detailed listing of your raid, you will see it list that you now have a spare. To make the raid grow to include this spare.(Y is the number of devices you will have in the array now)
# mdadm --grow --raid-devices=Y /dev/mdX
This will take a while again as it rebuilds the array to include the new drive. Once this has finished you will want to resize the filesystem to have the new space. Make sure you unmount the drive first.
# fsck.ext3 /dev/mdX # resize2fs /dev/mdX
Changing failed disks in non-faulty state:
DO NOT run this on a raid0 or linear device or your data is toasted!, you will loose the information stored on the removed disks.
first, marked it as faulty
# mdadm --manage --set-faulty /dev/md0 /dev/sdk
remove it from the array
# mdadm -r /dev/md0 /dev/sdk
Clearing any previous raid info on a disk (eg. reusing a disk from another decommissioned raid array)
# mdadm --zero-superblock /dev/sdk
replace the disk with a new one with same model and same amount of space, you can replace the disk itself in the same bay as the faulty disks, it will have the same name (sdk) or adding another already added disk, it will have different naming (sdj, for example). It’s indifferent, after the next boot, mdadm will read the disk header and include it in the correspondant mdX RAID, independently current naming.
let’s add it…
# mdadm -a /dev/md0 /dev/sdj
Now wait, this will take a while again as it rebuilds the array to include the new drive.
in case the RAID5 was stopped, we must start it with the whole amount of disks,
# mdadm --create /dev/md0 -c 128 --level=5 --raid-devices=6 /dev/sd[ghijkl]
When creating a RAID5 array, mdadm will automatically create a degraded array with an extra spare drive. This is because building the spare into a degraded array is in general faster than resyncing the parity on a non-degraded, but not clean, array. This feature can be over-ridden with the –force option.
# mdadm --create /dev/md2 -c 128 --level=5 --force --raid-devices=6 /dev/sd[ghijkl]