152

I have been unable to format/delete the partitions on my Sandisk Cruzer Force 32 GB USB Drive. I get the following error when deleting any of the partitions on it.

`Error deleting partition /dev/sdd2: Command-line `parted --script "/dev/sdd" "rm 2"' exited with non-zero exit status 1: Warning: The driver descriptor says the physical block size is 2048 bytes, but Linux says it is 512 bytes.
(udisks-error-quark, 0)

Is there any way I can completely format all of my drive and turn it into one large partition? I haven't found a solution to this particular error here yet, so I thought I'd actually ASK for once

Braiam
  • 67,791
  • 32
  • 179
  • 269
Nectar
  • 1,969
  • I have been using Disks. GParted does not seem to detect/display my USB Drive. – Nectar Sep 18 '15 at 16:07
  • 4
    Have you tried wiping it clean first with dd if=/dev/zero of=/dev/sdd bs=2048? MAKE SURE YOU USE /dev/sdd ONLY IF THAT'S WHAT IT IS! – Daniel Sep 18 '15 at 16:51
  • 1
    Brilliant, that worked perfectly. I'll remember those commands :) – Nectar Sep 18 '15 at 17:10
  • @Daniel By the way, 5 years later and I now use dd all the time, thank you for your answer and introduction to a very powerful tool. – Nectar Feb 13 '20 at 20:10

6 Answers6

213

The problem you are describing was caused by a low-level device tool (like dd) writing blocks at the wrong size directly onto the device.

To fix this, you need to re-write the device blocks to the appropriate size. This can be done with dd. Double check your output device before running the command

sudo dd if=/dev/zero of=/dev/sdd bs=2048 count=32

Once the dd command is done, you should be able to access your device through gparted.

gooseberry
  • 2,307
  • 1
  • 13
  • 6
  • It sounded so right, but still didn't work for me :( Is there any way to just fix it? – Eric Fossum Mar 11 '16 at 23:10
  • Check the error reported by gparted. The example above assumes the device size was 2048 as per OP. Your device might have a different byte size. – gooseberry Mar 13 '16 at 12:46
  • 8
    I was able to fix this error without re-writing the whole device, I just added count=32 at the end of the command and then ran dd. Much faster this way ;-) – That Brazilian Guy Apr 20 '16 at 18:43
  • Thanks @ThatBrazilianGuy, I updated the answer to reflect your input. – gooseberry Jun 10 '16 at 19:38
  • @ThatBrazilianGuy what's the meaning of count=32? – wsdzbm Aug 11 '16 at 19:53
  • 5
    @Lee It will only write 32 blocks (in this case, 32 blocks of 2048 bytes, or 68 KB), instead of writing each and every byte on the device. I believe just overwriting the partition table, or equivalent area at the beginning of the device would suffice. I specified 32 blocks just to be sure. – That Brazilian Guy Aug 11 '16 at 19:59
  • So to be clear, bs should be the reported physical block size, not what "Linux says"? – MicrosoftFree Oct 30 '16 at 05:44
  • My device was 8GB then I changed to count=8 and it works fine now. Thanks @gooseberry – Huseyin Nov 21 '16 at 07:53
  • 1
    Worked but i had to reboot my computer to make it work after using the command line. – Danyl Bekhoucha Apr 12 '17 at 15:44
  • 2
    @gooseberry I don’t think “writing blocks at the wrong size” is possible. The only difference should be speed (and in case of flash memory, wear). The command probably works, but the explanation doesn’t seem right. – Martin Jan 06 '18 at 15:34
  • This takes too long. Why must deleting a partition require overwriting the whole drive with zeros? – Lonnie Best Aug 15 '18 at 20:45
  • This overwrites the partition table, it does work, after finishing running this command you should take the USB out and plug it again. WARNING make sure the of= is correct or you can completely ruin your system otherwise, triple check! – D.Snap Dec 15 '22 at 07:10
33

You Can always try using fdisk

Open a terminal (Ctl+ALt+t) and type

sudo fdisk /dev/sdy

where /dev/sdy = The device file for your flash drive. Once you get fdisk open, type p to list the partition table, Once you know where it is located you can use d # to delete it. (# = The partition; ExAMPLE d 1, d 2) w writes the partition table back to the disk and q quits, m for help)

If fdisk fails, Then I would use dd (Be careful using this it got it didn't get its nickname for no reason)

sudo dd if=/dev/zero of=/dev/sdy bs=512 count=1

Of course /dev/sdy should be replaced with the actual device for your flash drive, will do that for you. You can increase the count= number to write zeros to more of the disk, or omit it entirely to overwrite the entire disk. Needless to say, if you do this, you irretrievably lose any files that may have been stored on the disk.

DnrDevil
  • 1,488
26
wipefs -a /dev/your-device

it will erase all partition in your disk

muru
  • 197,895
  • 55
  • 485
  • 740
MaySirus
  • 401
  • 4
  • 3
6

This issue has something to do with UEFI based bootable disks. I frequently create bootable USB disk, then I need it for storage but can't delete the partition.

This one command below zaps the partition table so I can do whatever next I want with the USB disk.

sudo sgdisk --zap-all /dev/???

Replace ??? with the appropriate identifier (e.g., sdc) corresponding to the USB disk to be cleared. It can be found out by -

sudo parted -l

or

sudo fdisk -l

or

using the disk utility.

Sri
  • 1,662
  • 2
  • 20
  • 39
4

dd is powerful but dangerous

dd is a very powerful but also very dangerous tool. It works well to wipe the first part of a USB drive in order to remove any data, that might confuse the tool that you want to use. But dd does what you tell it to do without questions, so if you tell it to wipe your family pictures ... and a minor typing error is enough to overwrite another drive instead of the USB drive, that you intended to overwrite.

Yes, you can use dd, if you know what you are doing, but please check and double-check, that the command line with dd is correct.

mkusb wraps a safety belt around dd

mkusb provides a graphical user interface with checkpoints to help you identify the target drive and double-check that you are wiping the correct drive.

There are menu options to wipe the first megabyte (actually mibibyte), which is usually enough, or the whole drive, which is a slow process, and useful only in special cases, for example when a pendrive is getting slow (for example less than half of the original speed.)

enter image description here

See these links for details how to install and use mkusb version 12 alias mkusb-dus.

help.ubuntu.com/community/mkusb

mkUSB-quick-start-manual.pdf

sudodus
  • 46,324
  • 5
  • 88
  • 152
2

Use fdisk command to delete the partition and create again.

Run command:

sudo fdisk /dev/sdxY  

(In my case, partition is 'sdb1' - replace with the correct name)

Command (m for help): d to delete the partition, choose 1 or 2.

Type w to save and exit.

Now eject the usb and connect again to check changes.

Zanna
  • 70,465
jazeb007
  • 191