How to delete metadata left from LSI 3ware controller

We have many servers with hardware controllers like LSI 3Ware. From time to time disks degrade and we have to change it with another one. However we found a little problem when trying to use unwiped disk in LSI 3ware controller, which was previously used in another 3ware controller. The following error appears in the disk status – Unsupported_DCB.

LSI 3Ware stores the RAID information on the disks. The main advantage is that we can replace controller without having to reconfigure it. That information is stored on a section called Disk Control Block (DCB). There are two versions of DCB – on both of them the information is stored at the end of the disk. DCB appears to be 1024 LBAs long (1024 * 512 bytes per sector = 512KiB). Additionally in one of the versions there is a copy of the DCB as the first 1024 LBAs of the disk.

So we have to wipe that info before replacing disk from one controller to another. Here’s a simple script that do it for you:

LBAS=$(cat /sys/block/$DISK/size)
dd if=/dev/zero of=/dev/$DISK bs=512 count=1024
dd if=/dev/zero of=/dev/$DISK bs=512 seek=$(($LBAS-1024)) count=1024

Very Important!!! Please replace sdz with the device name. I advice you to triple check the disk before executing the script. I am not responsible if you delete another disk by mistake.