30

I just got a micro sd card that I plan on using with the Raspberry Pi.

I used the KDE partition manager to delete the original partition on the card and to write a new 12GiB ext4 partition. After doing this, the card still says that 6% of it, 30.02 MiB, is being used.

Basically, I want to completely wipe of the card of all contents so as to prepare it for a new OS. Would a command like shred or dd do the trick or would that destroy the partition as well?

david6
  • 14,528
  • 5
  • 38
  • 46
firephyz96
  • 411
  • 1
  • 5
  • 4

5 Answers5

37

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

Note that the dd command from these examples will erase entire SD card, including the partition table. After using dd, you will need to recreate partitions on the SD card. You can do this by writing your Raspberry Pi disk image (which will already have the partitions set up), or with 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.

Peter
  • 3
8

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.

david6
  • 14,528
  • 5
  • 38
  • 46
5

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.

TheSchwa
  • 3,860
4

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

0

I never really understood the reason to use dd. It's a 'read blocks, write blocks, read blocks, write blocks' method, but, since we're talking about entire hard drives or partitions that we want to stream to from start to end, we can simply stream a contiguous list of zeroes to the device.

If you use pv you can use a progress bar, but the buffer might fill up, so you can also use a maximum speed.

  • Without progress buffer:

    cat /dev/zero > /dev/sdX
    
  • With a progress bar at max speed (filling up the buffer):

    pv -pteIrab /dev/zero > /dev/sdX
    
  • With a speed limit of 50 MiB/sec:

    pv -pteIrab -L 50M /dev/zero > /dev/sdX
    

If you use a single > with pv, the progress bar will work correctly. If you use >> (concat), it will not.

(This also applies to writing images to USB devices, like a live ISO, just use cat filename > /dev/sdX. But this is never recommended, and off topic, but I wanted to mention it anyway.)

drumfire
  • 101