Wednesday, November 25, 2009

wipefs(8)

This new command from util-linux-ng-2.17 is user friendly solution for people who have block devices with more valid filesystem signatures.

It's usually mkfs bug when old signatures are not removed from the device. The situation when you have more signatures on the device could be pretty dangerous. For example you can call swapon(8) for a wrong device and lost your data (see fedora bug #473514).

The libblkid was fixed few months ago and it does not return ambivalent information now. All devices with more signatures are ignored (well, there is exception for RAIDs, volume managers and some special filesystems like iso9660 and UDF). The blkid(8) command returns:

# blkid -p /dev/loop0
/dev/loop0: ambivalent result (probably more filesystems on the device)

Now imagine that you have data on the device, what next?

Use dd(1) and hexdump(1)... well that's joke :-) Use wipefs(8) and remove old (unwanted) filesystem signature.

The command without any option lists details about all detected filesystems:

# wipefs /dev/loop0
offset type
----------------------------------------------------------------
0xff6 swap [other]
UUID: da6c54ea-77d9-470a-82f1-e793fd5d9131

0x36 vfat [filesystem]
UUID: 497F-3013

Now remove unwanted swap signature:

# wipefs --offset 0xff6 /dev/loop0
10 bytes [53 57 41 50 53 50 41 43 45 32] erased at offset 0xff6 (swap)

The wipefs(8) command does not erase whole filesystem superblock or so. It removes magic strings only. Now the device is useful for blkid(8):

# blkid -p /dev/loop0
/dev/loop0: SEC_TYPE="msdos" UUID="497F-3013" VERSION="FAT12" TYPE="vfat" USAGE="filesystem"

The other change in util-linux-ng-2.17 is that detailed information about ambivalent probing results are reported to udevd ($ID_FS_AMBIVALEN variable) so it will be possible to notify users by UI (e.g. Palimpsest).