While repartitioning or installing OS on a disk which was already used in a software RAID array may show an error “disk contains BIOS metadata error” occasionally. Normally this can be fixed by doing a wipe the first and last sectors of a disk using dd. Also, the inbuilt raid command “dmraid” provides a command to clear the metadata. I have tried this in a live environment but most of the time, it fails to assemble or find the existing array. For your reference, see the command below.
dmraid -r -E /dev/sdX
Wipe the first and last sectors of a disk using dd
We will see how to Wipe the first and last sectors of a disk using dd further. We will have to find the disk block information. The partition size can be determined using the “-s” parameter with the fdisk command or from the file /proc/partitions.
Get the disk block information. You may get this from /proc/partitions or using command fdisk -s
[email protected]:~# cat /proc/partitions |grep -i sda 8 0 244198584 sda 8 1 244197376 sda1 [email protected]:~fdisk -s /dev/sda 244198584
Next, we will erase the first 1024 bytes from the beginning of the disk using the “dd” command.
dd if=/dev/zero of=/dev/sdb bs=1k count=1
This will wipe out 1024 bytes from the beginning of the disk partition.
To wipe or erase the last 1024 bytes from the end of the disk:
dd if=/dev/zero of=dev/sdb bs=1k seek=244198582
244198582 is the value of the last disk sector subtracted by 2 to find the block from which the deletion should start.
Once this is completed, the disk is ready for the reuse. We will not see the initial error when reinstalling the OS or re-adding to an array.
We can simply wrap up everything in a one lione-liner, which will remove both the first and last 1024 bytes of your disk.
dd if=/dev/zero of=/dev/sdb bs=1k count=1; dd if=/dev/zero of=/dev/sdb bs=1k seek=$((`fdisk -s /dev/sdb` - 2))
That concludes the article. Suggestions and comments are always welcome.