122

I have a USB which is write protected:

dmesg | tail

[10098.126089] sd 7:0:0:0: [sdb] Write Protect is on
[10098.126098] sd 7:0:0:0: [sdb] Mode Sense: 23 00 80 00
[10098.126779] sd 7:0:0:0: [sdb] No Caching mode page present
[10098.126788] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[10098.131418] sd 7:0:0:0: [sdb] No Caching mode page present
[10098.131425] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[10098.133335]  sdb: sdb1
[10098.135509] sd 7:0:0:0: [sdb] No Caching mode page present
[10098.135515] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[10098.135521] sd 7:0:0:0: [sdb] Attached SCSI removable disk

How can I turn the write protection off?

What I've tried

  1. Checked if it has a hardware switch - no
  2. Tried to format it on windows and on Linux (via terminal too)
  3. Tried fdisk | chmod
  4. Tried to fix this with several tools from Ubuntu software center
  5. Used Google and have seen about 10,000 discussions about this problem but they were never solved

Additional information

fsck -n /dev/sdb1

fsck from util-linux 2.19.1
dosfsck 3.0.9, 31 Jan 2010, FAT32, LFN
There are differences between boot sector and its backup.
Differences: (offset:original/backup)
  65:01/00
  Not automatically fixing this.
Free cluster summary wrong (968250 vs. really 911911)
  Auto-correcting.
Leaving file system unchanged.
/dev/sdb1: 50 files, 93653/1005564 clusters

fdisk -l

   Device  boot.   Start        End      Blocks   Id  System
/dev/sdb1            32     8060927     4030448    b  W95 FAT32

umount /dev/sdb1

mkfs -t vfat /dev/sdb1

mkfs.vfat 3.0.9 (31 Jan 2010)
mkfs.vfat: unable to open /dev/sdb1
Zanna
  • 72,312
noob
  • 1,266

9 Answers9

108

To turn off disk device`s write protect, we use the low level system utility hdparm like this:

sudo apt-get install hdparm    
sudo hdparm -r0 /dev/sdb

where we asume that /dev/sdb is the Physical disk device we're working on. If the device has partitions that are mounted as read-only, you should re-mount 'em as read-write in order to write data to them.

Hope that helps.

Owl
  • 634
46

After researching your question it appears that this is a not-too-uncommon problem with certain brands of USB flash drives (some older Samsung, a Kingston model) that would essentially just "crap out" for no known reason. People had tried opening them and jumping two leads (maybe from a flaky switch?) to no avail. If you still have this drive and it's still in warranty I'd return it and get a replacement.

I hate to break the bad news to you =\ but it appears you're out of luck in this situation as everything I've read points to hardware failure.

Edit 05/27/2016: I experienced an issue personally with a flash drive flaking out on me recently. In my case, this was a Corsair Flash Voyager 128GB that started slowing down pretty drastically on me. While it didn't show the symptoms noted here, it occasionally would not mount and showed up as a "Silicon Power" device. This was a result of the drive having accrued a large amount of bad sectors and dropping into diagnostic/programming mode. Since this is one of my more popular answers and this also falls into the category of "failing flash drives," I figured I'd include it here for reference.

Update 2: Regarding that Corsair Flash Voyager, I sent mine in for an RMA, only to have my second one fail on me in the same fashion. The problem actually turned out to be mechanical. The sliding mechanism seems to put a small amount of pressure on the PCB. Ordinarily, this wouldn't have caused an issue in the normal life span of the device. But for this particular model, it seems to have had weak solder joints that the pressure from the sliding action exacerbated -- leading to oxidation in the cracked joint and eventual failure. Rather than doing yet another RMA, I took matters into my own hands. I opened the case, shaved some of the plastic casing away to give the PCB some wiggle room and then reflowed the NAND chip to repair the broken solder joints. It's working great to this day!

Chuck R
  • 5,038
31

None of these answers provided so far are correct.

To actually make it work, you can override the detection of the USB disk announcing its read-only with a USB quirks setting. Here's how it works.

  1. Plug in the USB device and do an lsusb, example:

    $ lsusb
    Bus 002 Device 012: ID 0781:5583 SanDisk Corp. 
    
  2. Take note of those two codes after ID and between the colon (they're called the idVendor and idProduct). Unplug the USB device.

  3. Remove the usb_storage kernel module (assuming it's compiled as a module)

    $ sudo modprobe -r $(lsmod | sed -n 's:,: :g ; s,^usb_storage[ 0-9]*,,p') usb_storage
    
  4. Now we will put the module back in using a quirks mode setting to override the detection of the device's write-only flag.

    From source/drivers/usb/storage/usb.c#L572 taken from v4.19 you can see that the quirks mode setting we're looking for is w. Here's how we'll reload the kernel module:

    $ sudo modprobe usb_storage quirks=0781:5583:w
    

    Replace the numbers between the colons with the ones your saw in step (1) from above.

  5. Plug the USB storage device back in. We can now confirm with dmesg that this worked:

    Before: broken write only

    And after: working read/write

    Also after issuing a mount command you'll see:

    /dev/sdb1 on /usb type ext4 (rw,relatime)
    

Now go get your stuff off that disk immediately, it's failing.

zx485
  • 2,865
26

using fdisk -l locate the drive, ie: /dev/sdc1

now

umount /dev/sdc1

Finally, reformat the flash-drive

sudo mkfs -t vfat /dev/sdc1

I found this quick and easy. Be sure to UNMOUNT the drive before trying to format.

Ringtail
  • 16,285
25

Angel's answer is good, but the actual commands weren't so easy for me. This is what worked : Plug in the card (mine is an SD card with a manual write-protect switch on it, but the switch is off and it is writable on a Windows machine). Ubuntu mounted it automatically on /media/andrew/6AB0-1FD91, and dmesg showed the partition to be /dev/sdb1.

Unmount it, and make it writeable

sudo umount /dev/sdb1
sudo hdparm -r0 /dev/sdb

Create a new mount point and mount it there (my userID from /etc/passwd is 1000)

sudo mkdir /media/andrew/temp
sudo mount -o uid=1000 /dev/sdb1 /media/andrew/temp

it'll still complain that it's read-only. I don't know why I had to change this flag before AND after mounting, but that's the only way it worked for me. Set it to writeable again, and remount it at the same place

sudo hdparm -r0 /dev/sdb1
sudo mount -o remount,rw /dev/sdb1

Now I can write to the disk as my normal user. I'm being very careful with it in case it is actually failing, but those commands allowed me to finish what I was doing.

5

This happens when the ISO file was burned to usb using the DD command or any of the "standard" tools.

If it's created like this, there's no way to make it writable.

The way to do it is to burn the ISO using some tool such as unetbootin (linux) or Roofus (Windows).

4

Well, this is a bit of a bummer.

I tried everything here & elsewhere & nothing worked.

Formatted it on a friend's Windows laptop-- works fine now. FFS!

Sigh....(wondering now if I might've been able to fix it in my Win 7 VM on my Mint desktop instead?).

0

I tried the procedure from @kristopolous above but it didn't help me.

What did help me was using ddrescue (the package is called gddrescue) to make an image of the flash drive. Then I could mount the image read-write, do an fsck on the partition, unmount it, and use gparted to copy that partition to another flash drive.

-2

Insert memory stick and start gparted. Select it via the button at top right. It should be obvious if you are inspecting your memory stick (Size is a good clue). Select Partition--> unmount.

Select 'Device' at top, then 'Create Partition Table' and take the default, which is msdos.

Now you should be able to create a new partition and format it f32. If you can't, it's probably bust.

HTH

Vic
  • 418