Friday, November 25, 2011

wipefs(8) improvements

I finally found time to improve the command wipefs(8). The most visible change is support for partition tables. You can use wipefs(8) to remove MBR as well as GPT and many others partition tables.

The another important change (well.. bugfix) is that "wipefs -a" really erases everything what is possible to detect by libblkid (blkid(8)).

Now it calls libblkid detection code also after magic string erasing to ensure that nothing is possible to found on the device. This is important for stuff like GPT where is backup table on another place or for filesystems like FAT where is more ways to detect the superblock.

The last important change is a new command line option "-t". Now you can specify filesystem, raid or partition table name. For example
       wipefs -a -t ext4
will erase 'ext4' only. The option is interpreted in the same way how -t for mount(8) or findmnt(8), so you can specify more filesystems and you can prefix all or selected filesystems by 'no' prefix, for example:
       wipefs -a -t noext4,ext3,ext2
all but ext4, ext3 and ext2 filesystems will be erased.

If you're filesystem tools (e.g. mkfs.type) developer then you should know that now libblkid contains a new function blkid_do_wipe():
blkid_probe pr = blkid_new_probe_from_filename("/dev/sda1");

blkid_probe_enable_superblock(pr, true);
blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC);

while (blkid_do_probe(pr) == 0)
blkid_do_wipe(pr, 0);

and all superblocks are undetectable...

By the way, it's also good idea to call wipefs -a from system installer to avoid some unexpected problems. I have seen many bug reports from people with mess on their disks (unexpected mix of partition table and raid superblocks, swap and LUKS or ReiserFS ...etc.).

The changes will be available in the next util-linux release 2.21 (beta planned next month).