Say I used some thumbdrive on a public Windows computer and I copy some data to my Ubuntu computer with it. I cannot be completely sure that the Windows computer was clean, and it might have put something onto my thumbdrive. Is there a way to erase everything on a USB-Stick, even MBR viruses and that kind of off-filesystem stuff?
You can use old good Linux tool
To do so:
This should give you a clean USB. You need to create at least one partition to use the USB after this operation.
Creating partition on the empty disk
To create a new partition on it, You can use
That's it. You have now a new clean USB disk with a fat partition.
Note, you can also use the Disk-Utility program to create partition and Format it with Fat.
Now you are done with it.
Using new Disk-utility (12.10)
Ubuntu 12.10 is now equipped with a new Disk utility. It uses new
The script given above only erases the partition table and not the whole disk which is what the OP was requesting.
To erase everything off the disk and setting all bits to zero
Explaination of the extra options:
Removing "count=2048" removes limitation to 2048 bytes so dd can perform on entire disk.
bs=4Mb - bs is block size and so this will do the erase in 4Mb blocks, which is quicker than 1k.
iflag and oflag will try to disable buffering, which is not needed for a constant stream.
Then follow the instructions as outlined above to partition and format the disk.
To find the disk letter, open a terminal and run:
Then plug in the flash drive and the disk letter will be revealed!
Substitute the disk letter for X in /dev/sdX
This will blank all data on the disk!
Windows virus files in a pen drive are visible in Linux. Just delete all the files that you do not know of. Check all the folders to be sure. I have been using this technique successfully since a long time. This way, you can even retain your data.
If you want something utterly and irrecoverably gone,
You can find the path to the thumbdrive with
You can format the drive to ensure all data on it is nuked. See How to format a USB or external drive? for details on how to do this.
WARNING: this will erase all data on your drive! Be sure you won't be deleting anything important on your flash drive before trying this.