How can I completely erase all data on a (micro) SD card?
Your guessing about dd
is right. You can wipe the SD card out by the following command (let's assume, that your SD card is /dev/sdd
):
Do not interrupt this command or it could possibly brick the SD card.
$ sudo dd if=/dev/zero of=/dev/sdd bs=8192
Note: If this command does not complete successfully and you have to abort it, then most likely it is recoverable with disk partition recovery programs covered in other posts.
It can take some time depending on size and speed of SD card. If you are convinced, that CIA would like to recover your files, then overwrite the SD card with urandom
instead of zero
:
$ sudo dd if=/dev/urandom of=/dev/sdd bs=8192
dd
command from above examples will erase whole SD card, leaving it without any partitions, even with no partition table. So you will need to recreate partition on SD card. You can do this by any partitioning tool like cfdisk
, parted
(my recommendation) or gparted
.
And one more thing: be extremely careful when calling dd
command. A typo in of=
argument value can cause disaster.
What are you trying to achieve?
(A.) Remove all current partitions, to re-use the card:
To erase partitions and/or re-format a (micro) SD card, just use gnome-disk-utility (aka 'Disks').
OR
(B.) Erase any current (or previous) content on the card, so it can NOT be recovered:
To securely erase the card, you need to EITHER physically destroy the card (render into sub-2mm² particles) OR use a utility (from the vendor) to trigger the secure-erase function.
Multiple writes (of random data), or reformatting will NOT necessarily remove the data.
If you just made a new partition, there shouldn't be any actual files on it. That 30MB is probably just the filesystem itself. The partition needs a few different tables and whatnot to actually keep track of files.
You can double check that there really isn't anything on it by looking for hidden files with ls -alph
from the command line or be enabling hidden files in the "View" menu of Nautilus.
Depending on exactly how you invoke the commands, it is likely that using shred
or dd
would indeed overwrite the partition table and/or filesystem.
You can shred the files before removing them:
find /media/user/SD32/ -type f -exec shred -v -f -n0 -z -u {} \;
shred
params mean: Verbose, force deletion of non-writable files, don't write random bytes (speeds up), write zeroes (much faster), truncate and delete the file after writing zeros.
This will get rid of data in a way that they wouldn't be recovered by apps like photorec
.
See https://unix.stackexchange.com/questions/27027/how-do-i-recursively-shred-an-entire-directory-tree