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);

blkid_free_probe(pr);
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).

6 comments:

  1. Looks like nice improvements.

    But I think the 'no' prefix on -t option is a bit ambigous - Someone (like me) could interpret the command as "erase ext2 and ext3 signatures but not for ext4". And what about "-t ext2,noext3,ext4" or something like that?
    Maybe it'd better off adding another option for it.

    Just my two cents..
    Namhyung Kim

    ReplyDelete
  2. I'd like to keep the option compatible with mount(8) and findmnt(8).

    -t ext2,noext3,ext4 ... works as expected, it means erase ext2, ext3, but ext4.

    The 'no' is interpreted as global (for all items in the list) only if used at begin of the list, otherwise it's interpreted per-item. See man mount(8).

    ReplyDelete
  3. sorry...

    -t ext2,noext3,ext4 ... works as expected, it means erase ext2, ext4, but don't touch ext3.

    ReplyDelete
  4. What is the idea behind erasing certain information not? I suspect it is not safe to asume the data in that noxxx format is actually still untouched if you remove places for random structures of other filesystems (for example if you remove all ext2 blocks, a ext3 will surely not work as well?).

    ReplyDelete
  5. Good point -- extN was only example (probably bad example;-).

    The -t noxxx is mostly designed for things like RAID vs. swap-area, or obsolete partition tables, etc.

    ReplyDelete
  6. Note that you will never see ext2,ext3 and etx4 on the same device -- wipefs in util-linux 2.22 will be able to erase signatures from more devices, so then

    wipefs -t ext2,noext4 /dev/sda{1,2,3,4}

    makes sense.

    ReplyDelete