7

I have a 4GB USB drive and I wrote an iso file to it. Now I want to delete the data on it. Is there any way to take the space back?

I used Linux to burn the iso file following these instructions.

At that time, I thought it would be just like using Pendrive Linux to write the iso so I could format the USB disk if I wanted to get storage back but I was wrong. It was like burning an iso file to CD/DVD, meaning that data was burned but cannot be deleted, now I've lost 3GB of storage.

How can I restore the Flash disk to being a normal storage device?

Kevin Panko
  • 7,466

3 Answers3

8

The term 'burning' does not apply to USB flash storage. Even if some people still call it 'burning' when you write ISO images, that does not matter at all. The USB stick's memory stores the ISO image's contents in exactly the same way that it would store regular files – that is, they can be erased and overwritten with something else.

The only difference here is that the ISO image was written on top of the partition & filesystem information that the OS would use to decide how much space is available. So instead of a 4 GB partition covering the entire flash memory, the OS now sees the partitions that were in the ISO image – that is, a ~1 GB partition with Linux, and 3 GB of "unused" space.

On Linux, you could use any partitioning tool (like the graphical GParted) to just erase all existing partitions and create a full-sized one again, then format that partition with FAT32 as usual.

Unfortunately Windows likes to discriminate against removable disks and USB sticks, but it's still possible to erase the partition information using dd for Windows`, and Windows would just ask to "format" the USB stick afterwards. This command would nuke the first megabyte, which should really be enough to make the OS think the entire disk is unpartitioned.

dd.exe --filter=removable if=/dev/zero of=\\?\Device\Harddisk?\Partition0 bs=1M count=1

Of course, run dd.exe --list first, and replace Harddisk? with the exact name of your USB stick. (Be careful to not erase your system disk's partition table, even though --filter=removable should prevent that.)

grawity
  • 501,077
1

It is so because, instead of detecting usb flash drive, it detect it as usb hard drive having multiple partitions.

whole usb will be /dev/sdb

Partitions will be like /dev/sdb1 /dev/sdb2 /dev/sdb3 and so on....

So you need to delete the whole patition and make single partitions.

do the folllowing:-

  sudo fdisk /dev/sdb

Now press d to delete parition

    Command (m for help):d

delete all partitions.

Now you can create new partitions by fdisk or any other utility without any error as partitions have been removed.

1

When you write an ISO image to a USB flash drive with dd, you overwrite several things on the device, including the partition table. It's often possible to repartition them with a simple partitioner, but you should ensure that the partitioner checks the size of the actual disk, rather than believing the partition table, as some partitioners do. Doing this may be somewhat complex in some cases.

The easiest way to avoid that complexity, in my opinion, is to wipe the USB flash disk's partition entirely:

dd if=/dev/zero of=/dev/sd[letter] bs=1M count=1

WARNING: double-check that the [letter] part in the above is the letter for your actual USB flash drive that you want to reformat. Do this on your computer's main storage device, and you will lose data.

After you've done this, you can recreate the partitions on your flash drive and reformat them. Your partitioner may complain that the flash drive has no partition table on it; this is normal (the dd command that you just ran wiped it) and you should ignore it.