I found no way to remove a mdraid from a server with one command.
I can stop it via mdadm --stop /dev/md0
But the superblock is still in the devices.
mdadm --zero-superblock DEVICE
needs every device (like /dev/sdb1)
I know that I can do mdadm --detail /dev/md0
and then I see the devices.
I could write a fragile script to fetch the /dev/sd... strings from the output of mdadm --detail /dev/md0
, but I would like to avoid this.
Is there a one-liner to remove the superblock from all devices of a mdraid?
I would like to avoid to parse the output of mdadm --detail
, since this feels fragile.
If you know the array component devices, you can simply issue something as
mdadm --zero-superblock /dev/sd[abcd]
to remove the superblock from multiple devices with a single command.
Please note that
mdadm
checks for superblock before zeroing anything, so specifyingsd*
in the command above should only touch component disks, without writing anything to the others. However, I strongly suggest against doing that: any issues in the superblock detection routing, or using--force
, are going to overwrite good data on non-component disks (causing data loss). From the man page:For the reason above, if you don't know the array component devices I suggest listing them via
blkid -t TYPE="linux_raid_member" -o device
and then zeroing the specific disks with
mdadm --zero-superblock
. This can be scripted with a single-line bash command:As always, triple-check any such commands to avoid data loss.
EDIT: to discover the array component devices without resorting to parsing of
mdadm --detail
output, you can uselsblk
. For example, on a test array created vialoop
devices:There isn't a single command (
mdadm …
) that will remove the superblock from all devices of a mdraid. However, it's fairly straightforward to write a script that then becomes a one-liner:Example usage, assuming the script is called
mdzero
and it's in the PATH, etc. and the unwanted RAID device is/dev/md1
:Unless you enter a (capital) "Y" in response to the "Stop and erase?" question - or the command is being run non-interactively - the tool will quit at that point. Essentially, you've got 20+ lines of sanity checking to ensure that the active
mdadm --zero-superblock
command is only run if and where absolutely intendedYou can use
blkid
to do this with a little bit of manipulation.First, get the raid array you care for.
Convert the UUID Into a a proper UUID format and you can use
blkid
to pull out all disk members.If you just want to blast all mdadm raid arrays you dont need to collect any other identifier:
To blast everything using this method you can even use
wipefs
. That could look something like..Of course, this will zero all raid arrays of all disks without caring about the particular raid array in question. I added a
-n
to prevent people being careless with their copy/paste!