Removing write protection on a usb drive
I have an usb flash-drive that is write protected since a system crash. In the dmesg, the device write protection is first off, then it is turned on. Here is the dmesg:
sd 2:0:0:0: [sdb] 60566016 512-byte logical blocks: (31.0 GB/28.9 GiB) sd 2:0:0:0: [sdb] Write Protect is off sd 2:0:0:0: [sdb] Mode Sense: 2b 00 00 08 sd 2:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA sdb: sdb1 sdb2 sdb3 sdb4 sd 2:0:0:0: [sdb] Write Protect is on sd 2:0:0:0: [sdb] Mode Sense: 2b 00 80 08 sd 2:0:0:0: [sdb] Attached SCSI removable disk EXT4-fs (sdb3): INFO: recovery required on readonly filesystem EXT4-fs (sdb3): write access unavailable, cannot proceed (try mounting with noload) /dev/sdb4: Can't open blockdev
/dev/sdb: multcount = 0 (off) readonly = 0 (off) readahead = 256 (on) geometry = 29573/64/32, sectors = 60566016, start = 0
I also ran badblocks on /deb/sdb, and it found no bad blocks. I tryed the command hdparm -r0 /dev/sdb with no success. No more success with hdparm security commands like:
hdparm --security-mode m --user-master m --security-unlock p /dev/sdb
SG_IO: bad/missing sense data, sb[]: 70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
/dev/sdb: ATA device, with non-removable media Standards: Likely used: 1 Configuration: Logical max current cylinders 0 0 heads 0 0 sectors/track 0 0 -- Logical/Physical Sector size: 512 bytes device size with M = 1024*1024: 0 MBytes device size with M = 1000*1000: 0 MBytes cache/buffer size = unknown Capabilities: IORDY not likely Cannot perform double-word IO R/W multiple sector transfer: not supported DMA: not supported PIO: pio0
USB Disk Read-only, cannot format — Turn off write-protection
I have a USB disk which does not allow me to format/mount/unmount or created partitions on it. Using dmesg | tail gives me the following result: I found this post on AskUbuntu and tried using the accepted answer. I get the following result, but it is still read-only: umount doesn’t work. Says umount: /dev/sdc: not mounted Any help on how to remove the write protection will be much appreciated.
Assuming this is a full size SD card in some card-reader have you tried to move the actual switch it has on the side? Or if it is missing putting some tape around the side where it used to be to make the reader think it is no longer write protected?
If there is no data on it, have you tried to make a partition table on it or just write something with dd if=/some/file of=/dev/sdc to see what happens?
5 Answers 5
AFAIK, this type of «protection» is automatically enabled on physical failure occurrences. This is basically a way for you to recover your data before something critical happens (fried disk).
So at one point in time, the firmware of the USB disk detected a failure.
Now, bugs happen. False positives too. But it could also be the beginning of the end for your disk (or even the end of the end if the command does not work).
HI man I’m have same problem like you and i’m follow this tutorial: link
A. First we need to delete the old partitions that remain on the USB key.
Open a terminal and type sudo su Type fdisk -l and note your USB drive letter. Type fdisk /dev/sdx (replacing x with your drive letter) Type d to proceed to delete a partition Type 1 to select the 1st partition and press enter Type d to proceed to delete another partition (fdisk should automatically select the second partition)
B. Next we need to create the new partition.
Type n to make a new partition Type p to make this partition primary and press enter Type 1 to make this the first partition and then press enter Press enter to accept the default first cylinder Press enter again to accept the default last cylinder Type w to write the new partition information to the USB key Type umount /dev/sdx1 (replacing x with your drive letter)
C. The last step is to create the fat filesystem.
Type mkfs.vfat -F 32 /dev/sdx1 (replacing x with your USB key drive letter)
USB turn write protection off
@micha — what kind of USB device is it — obviously you’ve checked if it has a hardware switch? any errors if you attempt to mount it? sudo mount /dev/sdb1 -v ?
micha, fair enough. Have you tried running efsck or used Ubuntu’s Disk Utility to check the health status of the flash disk? If it was working fine & then stopped working all of a sudden there could be a hardware malfunction.
@kingmilo e2fsck : Bad magic number in super-block while trying to open /dev/sdb1 SuperBlock is not readable.
@micha — very well, still doesn’t mean it’s not faulty though unfortunately. It’s common for storage devices to appear to work normally when in fact they are faulty, just at a different stage of faulty. I think with all the activity on this question you should ask for small donations to replace the drive, it would be easier 😜
8 Answers 8
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.
@OP I had the same as you, which is: sdxc card mounted read-only whatever the computer; hdparm -r shows «1 — on» then after unlocking with r0 : «0 — off» but mount read-only anyway. But mounting my SanDisk sd card in another adapter and I couuld mount it rw. It turns out two of my microSD-to-SD adapters have a broken pin between two connectors. And these two will mount read-only whatever I do. Kuddos to @Angel_Genchev he answer has the most command in it.
@lliseil It’s more than likely the reader’s write protect switch is being pressed upon by the card inserted into it, normally by the tab on the card but the switch (not the tab) can become bent and stuck on. you can fix the sdcard reader by cutting off the write-protect switch pins, the ones that make physical contact with the lock tab on the card. When the switch in the reader is open, write-protect is off, when it is closed (by being pressed upon the the tab on the card) write protect is on. Removing one or both of the switches metal arms will permanently disable write-protect on the reader.
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!