Format USB with bad partition table (read-only fs)

lagagne picture lagagne · Mar 26, 2017 · Viewed 8.3k times · Source

I have a USB drive that my Ubuntu machine can't format. I think the problem originated when I was using Rufus or UNetBootin inside a Windows VM and got a blue screen. There's no important data on there, I just want to be able to use it. It's probably not worth the trouble but I want to understand the problem in case it happens again. I tried all sorts of tools but none of them seems to be low-level enough to rewrite the partition table.

Here is the output of some of the tools I tried. As you can note, there is no sdb1 or any found partition because the table is unreadable. I can use a Windows host too if the only solution is by using some ".exe" but I'd rather use UNIX terminal tools if possible.

ls -l /dev/ | grep sdb
brw-rw----  1 root disk        8,  16 Mar 26 10:57 sdb

sudo hdparm -r0 /dev/sdb
/dev/sdb:
 setting readonly to 0 (off)
 readonly      =  0 (off)

sudo partprobe -s /dev/sdb
Warning: Unable to open /dev/sdb read-write (Read-only file system).  /dev/sdb has been opened read-only.
Warning: Unable to open /dev/sdb read-write (Read-only file system).  /dev/sdb has been opened read-only.
Warning: Unable to open /dev/sdb read-write (Read-only file system).  /dev/sdb has been opened read-only.
/dev/sdb: msdos partitions

sudo gparted /dev/sdb
libparted : 3.2
Unable to open /dev/sdb read-write (Read-only file system).  /dev/sdb has been opened read-only.
Unable to open /dev/sdb read-write (Read-only file system).  /dev/sdb has been opened read-only.
Unable to open /dev/sdb read-write (Read-only file system).  /dev/sdb has been opened read-only.
Unable to open /dev/sdb read-write (Read-only file system).  /dev/sdb has been opened read-only.
/dev/sdb: unrecognised disk label

sudo fdisk -l /dev/sdb
Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

sudo partx -l /dev/sdb
partx: /dev/sdb: failed to read partition table

sudo partx -d /dev/sdb
partx: specified range <1:0> does not make sense

sudo fsck.fat -n /dev/sdb
fsck.fat 3.0.28 (2015-05-16)
Logical sector size (65535 bytes) is not a multiple of the physical sector size.

sudo blkid -pi /dev/sdb
DEVNAME=/dev/sdb
MINIMUM_IO_SIZE=512
PHYSICAL_SECTOR_SIZE=512
LOGICAL_SECTOR_SIZE=512

sudo wipefs -a /dev/sdb
wipefs: error: /dev/sdb: probing initialization failed: Read-only file system

Answer

lagagne picture lagagne · Mar 26, 2017

Apparently the Startup Disk Creator on Ubuntu doesn't care what's on the drive at all. I suppose it always creates its own partition table. So I used it with an Ubuntu image, assuming it would fail and was greatly surprised. I then used GParted to have an empty FAT32 partition and now I can use my drive without any problem (except maybe with future formats). Oddly, GParted first thought my drive was 60GB and successfully created a partition table but failed creating a partition. After the error message, the size of the drive rightly showed 16GB so I created the partition successfully.