2

My friend gave me his 4 GB USB flash disk because he can't format or remove or copy anything to it. The drive is empty now. But I can't seem to fix the write-protection problem.

Windows can't format the disk and shows 'device is write-protected'. So I decided to tackle the problem from linux.

I can't fix the problem from linux either. The drive auto-mounts when inserted but I can't do anything with it because of the write-protection.

Output of dmesg | tail the moment I insert the flash disk:

$ dmesg | tail
[ 2753.654864] usb-storage 1-1.4:1.0: USB Mass Storage device detected
[ 2753.655207] scsi host4: usb-storage 1-1.4:1.0
[ 2754.668623] scsi 4:0:0:0: Direct-Access     Generic  Flash Disk       8.00 PQ: 0 ANSI: 4
[ 2754.671050] sd 4:0:0:0: [sdd] 8192000 512-byte logical blocks: (4.19 GB/3.91 GiB)
[ 2754.672208] sd 4:0:0:0: [sdd] Write Protect is off
[ 2754.672214] sd 4:0:0:0: [sdd] Mode Sense: 23 00 00 00
[ 2754.673417] sd 4:0:0:0: [sdd] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 2754.690210]  sdd: sdd1
[ 2754.694654] sd 4:0:0:0: [sdd] Attached SCSI removable disk
[ 2755.154487] FAT-fs (sdd1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

Then, I ran the gnome-disk-utility and tried to format the drive. 10-20 seconds later, I get

Error formatting volume
Error synchronizing after initial wipe: Timed out waiting for object (udisks-error-quark, 0)

Running dmesg | tail again gives:

$ dmesg | tail
[ 3157.475963] sd 4:0:0:0: [sdd] tag#0 CDB: opcode=0x2a 2a 00 00 00 08 00 00 00 08 00
[ 3157.475967] blk_update_request: critical target error, dev sdd, sector 2048
[ 3157.475977] Buffer I/O error on dev sdd1, logical block 0, lost async page write
[ 3157.477033] sd 4:0:0:0: [sdd] tag#0 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte=0x08
[ 3157.477039] sd 4:0:0:0: [sdd] tag#0 Sense Key : 0x7 [current] 
[ 3157.477044] sd 4:0:0:0: [sdd] tag#0 ASC=0x27 ASCQ=0x0 
[ 3157.477049] sd 4:0:0:0: [sdd] tag#0 CDB: opcode=0x2a 2a 00 00 00 08 00 00 00 08 00
[ 3157.477052] blk_update_request: critical target error, dev sdd, sector 2048
[ 3157.477058] Buffer I/O error on dev sdd1, logical block 0, lost async page write
[ 3157.549308] VFS: Dirty inode writeback failed for block device sdd1 (err=-5).

Tried checking the drive's partition using GParted and got

GParted 0.27.0 --enable-libparted-dmraid --enable-online-resize

Libparted 3.2

Check and repair file system (fat32) on /dev/sdd1  00:00:00    ( ERROR )

calibrate /dev/sdd1  00:00:00    ( SUCCESS )

path: /dev/sdd1 (partition)
start: 2048
end: 8191999
size: 8189952 (3.91 GiB)
check file system on /dev/sdd1 for errors and (if possible) fix them  00:00:00    ( ERROR )

fsck.fat -a -w -v /dev/sdd1  00:00:00    ( ERROR )

fsck.fat 4.0 (2016-05-06)
open: Read-only file system
libparted messages    ( INFO )

Unable to open /dev/sdd read-write (Read-only file system). /dev/sdd has been opened read-only.
Unable to open /dev/sdd read-write (Read-only file system). /dev/sdd has been opened read-only.

Now, demsg | tail shows

[ 3363.006200] sd 4:0:0:0: [sdd] Write Protect is on
[ 3363.006208] sd 4:0:0:0: [sdd] Mode Sense: 23 00 80 00
[ 3363.008312]  sdd: sdd1

I've tried using GParted to reformat the drive's one and only partition as FAT32 (Partition is already FAT32) and got a Libparted error:

Can't write to /dev/sdd, because it is opened read-only.

And then

GParted 0.27.0 --enable-libparted-dmraid --enable-online-resize

Libparted 3.2

Format /dev/sdd1 as fat32  00:01:32    ( ERROR )

calibrate /dev/sdd1  00:00:00    ( SUCCESS )

path: /dev/sdd1 (partition)
start: 2048
end: 8191999
size: 8189952 (3.91 GiB)
clear old file system signatures in /dev/sdd1  00:01:32    ( ERROR )

write 512.00 KiB of zeros at byte offset 0  00:01:32    ( ERROR )
libparted messages    ( INFO )

Unable to open /dev/sdd read-write (Read-only file system). /dev/sdd has been opened read-only.
Unable to open /dev/sdd read-write (Read-only file system). /dev/sdd has been opened read-only.
Unable to open /dev/sdd read-write (Read-only file system). /dev/sdd has been opened read-only.
Unable to open /dev/sdd read-write (Read-only file system). /dev/sdd has been opened read-only.
Unable to open /dev/sdd read-write (Read-only file system). /dev/sdd has been opened read-only.
Can't write to /dev/sdd, because it is opened read-only.
Can't write to /dev/sdd, because it is opened read-only.
Can't write to /dev/sdd, because it is opened read-only.

Also tried to delete the current partition and create a new one but got the same error.

The flash disk has no hardware switch on it. I've also tried using hdparm but it has no effect whatsoever:

$ sudo hdparm -r0 /dev/sdd

/dev/sdd:
 setting readonly to 0 (off)
 readonly      =  0 (off)

Some information about the flash disk:

$ sudo fdisk /dev/sdd
Welcome to fdisk (util-linux 2.28.2).                                                                                                   
Changes will remain in memory only, until you decide to write them.                                                                     
Be careful before using the write command.


Command (m for help): i

Selected partition 1
         Device: /dev/sdd1
           Boot: *
          Start: 2048
            End: 8191999
        Sectors: 8189952
      Cylinders: 508
           Size: 3.9G
             Id: c
           Type: W95 FAT32 (LBA)
    Start-C/H/S: 1023/255/63
      End-C/H/S: 1023/255/63
          Attrs: 80

Also, fsck gives me

$ sudo fsck /dev/sdd
fsck from util-linux 2.28.2
e2fsck 1.43.3 (04-Sep-2016)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
fsck.ext2: Bad magic number in super-block while trying to open /dev/sdd

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>
 or
    e2fsck -b 32768 <device>

/dev/sdd contains `DOS/MBR boot sector; partition 1 : ID=0xc, active, start-CHS (0x3ff,255,63), end-CHS (0x3ff,255,63), startsector 2048, 8189952 sectors' data

and

$ sudo fsck /dev/sdd1
fsck from util-linux 2.28.2
fsck.fat 4.0 (2016-05-06)
open: Read-only file system

When I did fsck just after reinserting the drive, I got

$ sudo fsck /dev/sdd1
fsck from util-linux 2.28.2
fsck.fat 4.0 (2016-05-06)
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
1) Remove dirty bit
2) No action
? 1
FATs differ but appear to be intact. Use which FAT ?
1) Use first FAT
2) Use second FAT
? 1
Free cluster summary wrong (1021716 vs. really 1021743)
1) Correct
2) Don't correct
? 1
Perform changes ? (y/n) y
/dev/sdd1: 1 files, 1/1021744 clusters

but that didn't seem to change anything.

So, how do I remove the write-protection (or read-only) from the USB flash disk?

  • 1
    Most likely your flash drive is damaged beyond repair. This question is frequently asked on superuser and a canonical answer for it can be found here. – n8te Dec 3 '16 at 4:10
  • Current Debian iso 9.4 burned on usb gives a partition in readonly where no known solution can unlock it. So it is not mandatory hardware. – Sandburg May 21 '18 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.