5

How can I delete all data that is on stick?

For example I have this problem:

My stick has two partitions A (3.7 GB) and B (330 MB). How can I merge the two partitions in one and to delete all data that they contain?

I guess they have read-only properties... How can I force deleting them?

I see this in GParted:

Ionică Bizău
  • 9,373
  • 22
  • 82
  • 126

3 Answers3

8

How to erase / delete / blank or wipe a disk

I’m sure there are other methods, but the one I prefer to use is the one that uses dd to copy zeros, or random data in the file system I want to wipe.

So, run this command if you want to erase your… let’s say microSD card.

Suppose it is mounted on /dev/sdd1:

dd if=/dev/urandom of=/dev/sdd1

If you do not want to wait too much, you can fill the partition with zeros instead of random data:

dd if=/dev/zero of=/dev/sdd1

Both are secure, but IMHO the first one may be better, but of course I can be wrong.

Once again, be sure to double check, or better triple check on which partition you are going to apply this, you will not be warned by Linux, and the result can not be undone.

A good practice could be to first make an image of the disk and then wipe it. If you want to proceed that way, do this.

dd if=/dev/[partition-to-wipe] of=/tmp/backup.img

Then wipe it

dd if=/dev/urandom of=/dev/[partition-to-wipe]

You can then recover the data by doing

dd if=/tmp/backup.img of=/dev/[partition-to-wipe]

Info taken from this site.

Giacomo1968
  • 250
  • 5
  • 14
user123492
  • 553
  • 4
  • 8
  • I get: `dd: opening ‘/dev/sr1’: Read-only file system`. – Ionică Bizău Dec 16 '13 at 16:33
  • 1
    For `/dev/random` vs `/dev/zero`, see [here](http://stackoverflow.com/questions/11499409/dev-zero-or-dev-random-what-is-more-secure-and-why) - @Johnツ, you need to use the command with `sudo` in front. – Wilf Dec 16 '13 at 16:33
  • Urrr... Doesn't restoring the image restore anything that was removed by wiping it with `/dev/random` or `/dev/zero`? – Wilf Dec 16 '13 at 16:36
  • @wilf Nope. `/dev/zero` is just a place where data gets dumped and destroyed. If you reboot, nothing will be left, might even be before! – RPiAwesomeness Dec 16 '13 at 16:37
  • @RPiAwesomeness, I meant it backups the image byte for byte, wipe the USB stick, and then restores it... – Wilf Dec 16 '13 at 16:39
  • 1
    @wilf True. I think he just included that *in case* John ツ wants to restore the data in case he accidentally didn't want to wipe that stick. – RPiAwesomeness Dec 16 '13 at 16:44
  • Didn't think of that.... – Wilf Dec 16 '13 at 16:48
  • The question is about deleting all the partitions on a disk, this "answer" tells us how to erase the data inside one of those partitions. – Octopus Jan 20 '21 at 23:16
6

Just use GParted. GParted

Unmount all the partitions on the USB stick, and then delete them. You can then create partitions as you like. The is some documentation here if you need any.

This should effectively wipe any partitions. - remember to click this green button, or it won't do anything:

enter image description here


If you just want to wipe it, you could also find the device name in sudo fdisk -l in terminal, and then run:

sudo dd /dev/zero /dev/sdX1

Where sdX1 is the name and partition number of the device, which you can find in GParted or fdisk. This is not that necessary if you just use GParted, but you may need to use GParted afterwards to reformat it anyway... smiley

Wilf
  • 29,694
  • 16
  • 106
  • 164
  • Seems that the other partition is not visible... :-( How can I merge it? – Ionică Bizău Dec 16 '13 at 16:39
  • If is not visible, it is probably not there in the first place. Just delete everything, and some new partitions *(FAT32 is best if you want it to work with Windows as well)* - **Having copied anything you want off first** - :-) – Wilf Dec 16 '13 at 16:43
  • I can see it in Nautilus and access its files. After formatting the USB drive they are still there. – Ionică Bizău Dec 16 '13 at 16:44
  • Is this a common-or-garden USB stick? Wiping the partition table would get rid of everything as well. Note that you have to click the tick in GParted before it does anything... – Wilf Dec 16 '13 at 16:45
  • It contains a read-only partition... How can I delete or merge it? – Ionică Bizău Dec 16 '13 at 16:47
  • Did you format on another OS? Some filesystem types only mount as read only. But, deleting it in GParted should delete it. – Wilf Dec 16 '13 at 16:50
  • I received it from someone. That partition doesn't appear in GParted... – Ionică Bizău Dec 16 '13 at 16:52
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/12006/discussion-between-john--and-wilf) – Ionică Bizău Dec 16 '13 at 16:52
  • I believe the last command should be `sudo dd if=/dev/zero of=/dev/sda` – Garrett Nov 14 '18 at 07:49
1

Simple! Start up gparted via the terminal (Ctrl+Alt+T) and entering sudo gparted

terminal.

Once you do that gparted will start.

gparted starting

The USB stick should show in the disks area (upper-right-hand corner) as something like /dev/usb or /dev/sdb. Make sure the disk selected is the USB stick, the following steps will wipe ALL data on the selected disk.

  1. Go to Device>Create Partition Table This window will come up:

new partition window

click Apply . You may have to also start this process by clicking the check-mark button.

This will create a new partition table and will make the data unrecoverable by most people.

RPiAwesomeness
  • 9,723
  • 21
  • 71
  • 104