zeroing out part of an SDcard

Chris Murphy lists at colorremedies.com
Sat Aug 23 18:06:18 UTC 2014


Nice.

http://www.spinics.net/lists/linux-btrfs/msg36918.html

No special tool needed. e.g. I just tested this with Gnome Disks, with the default "don't overwrite with zeros (quick format)" option, using btrfs. All of, and only that chosen partition, was completely erased in about 2 seconds. Every sector returns FF's [1] other than btrfs superblocks.

I did a strace on mkfs.xfs, mkfs.ext4, and mkfs.vfat -F32; but did not test this in Gnome Disks. The strace reveals that both xfs and ext4 use BLKDISCARD, while vfat does not. xfs and ext4 further makes use of:

ioctl(3, BLKDISCARDZEROES, 0)           = 0

I'm not sure what this does. Maybe it causes erased blocks to deterministically return zeros instead of FF's?

Anyway, it looks like SD cards are in effect "trimmed" by formatting them ext4, xfs or btrfs, as long as the tool being used is using the fs's mkfs command, and also doesn't pass a nodiscard option.

I didn't test mkfs.ntfs or mkfs.hfs, but like vfat if any of them aren't calling BLKDISCARD it's probably a valid feature request for their upstream. Meanwhile a workaround is to use mkfs.btrfs with no options, and then wipefs -a that same partition, and then format with the preferred filesystem.


Chris Murphy



[1]
[root at twenty1 chris]# dd if=/dev/mmcblk0p2 bs=1M skip=313 | hexdump -C
00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|


More information about the users mailing list