Sunday, October 2, 2016

USB flash drives and md5sum

I always thought it was interesting how USB flash drives would read differently if they had sectors that hadn't been written yet.

For instance, here's a flash drive that I was testing:

knoppix@Microknoppix:~$ time dd if=/dev/sdc | md5sum
1972744+0 records in
1972744+0 records out
1010044928 bytes (1.0 GB) copied, 75.2915 s, 13.4 MB/s
e7ef4e43591086d1f484ac8ae0167ad8 -

real 1m15.670s
user 0m5.747s
sys 0m6.820s
knoppix@Microknoppix:~$ time dd if=/dev/sdc | md5sum
1972744+0 records in
1972744+0 records out
4d1ec5b4d17d364db0dc7f1b361271e7 -
1010044928 bytes (1.0 GB) copied, 74.0257 s, 13.6 MB/s

real 1m20.292s
user 0m5.860s
sys 0m6.737s
knoppix@Microknoppix:~$

Somehow that just doesn't seem right, to give different results. I suppose I could initialize it by writing zeros to every sector before using it.

so let's make a zero file that fills up all the available space:

knoppix@Microknoppix:~$ ls /media/sdc
knoppix@Microknoppix:~$ time dd if=/dev/zero of=/media/sdc/ZEROFILE
dd: writing to ‘/media/sdc/ZEROFILE’: No space left on device
1972225+0 records in
1972224+0 records out
1009778688 bytes (1.0 GB) copied, 10.447 s, 96.7 MB/s

real 0m10.456s
user 0m1.550s
sys 0m7.897s
knoppix@Microknoppix:~$ sync
knoppix@Microknoppix:~$ umount /dev/sdc


and let's check if that fixes our different md5sums:


knoppix@Microknoppix:~$ time dd if=/dev/sdc | md5sum
1972744+0 records in
1972744+0 records out
1010044928 bytes (1.0 GB) copied2029b6aa4ebbd3c5da36631b1273ef41 -
, 60.7487 s, 16.6 MB/s

real 1m0.780s
user 0m5.677s
sys 0m7.080s
knoppix@Microknoppix:~$ time dd if=/dev/sdc | md5sum
1972744+0 records in
1972744+0 records out
2029b6aa4ebbd3c5da36631b1273ef41 -
1010044928 bytes (1.0 GB) copied, 65.335 s, 15.5 MB/s

real 1m8.571s
user 0m5.597s
sys 0m6.947s

and yes, now the md5sums match.

No comments:

Post a Comment