Ubuntu – How to fix read-only usb drive

read-onlyusbusb-drive

I have read-only usb drive and could not fix it. I have read some articles about it and tried to fix but I couldn't.

I unmounted drive and used dosfsck to check and repair MS-DOS filesystems, because it is FAT filesystem and run:

dosfsck -a /dev/sdb1

it gave the output:

fsck.fat 4.1 (2017-01-24) open: Read-only file system

So what can I do with it? Can I repair or it's time to throw it in a trash?

Best Answer

If the USB was once writable and is now no longer, this suggests 3 things in my mind:

  1. A hardware switch on the device has been toggled.

    If this is the case, the simple fix would be to find that hardware switch (they can be really subtle), and toggle it.

  2. An "unclean" unmount occurred, such as pulling the USB out of the slot before the OS finished writing data to it

    To save the life of devices, and to improve performance, writes to most storage mediums are buffered -- including USB drives. In essence, this means then unless you tell the operating system to eject/unmount the USB drive, you have no guarantee that all data has been written. Further, most filesystems have flags to indicate when they've been mounted and unmounted: always tell the OS you're going to remove the drive ("eject", "unmount", "turn off") before you pull it out of the slot.

    Consequently, if simply checking and fixing the filesystem does not work, then you could try the ham-fisted approach of copying your data temporarily somewhere else, reformatting your USB drive, and then copying your data back. By reformatting, you're completely overwriting what was there, so the OS/filesystem will have no recollection the USB drive/filesystem was readonly before the format.

    One detail on repairing the filesystem. Make sure it's not mounted first. Your set of commands implies it's mounted. So:

    sudo umount /dev/sdb1

    sudo dosfsck -a /dev/sdb1

  3. The USB disk itself is dying, and the embedded firmware is protecting you from losing any data.

    If the USB uses flash-based storage, it's possible that you have written to the device enough times that it is now unable to write anymore. Writing to flash-based is a destructive process, and each sector can only take so many rewrites. Many drives will "hide" this fact, by internally having much larger storage (say 16G of total write space), but only present to the OS as a smaller amount (say 2G). As each sector begins to wear out, the firmware will automatically move the data to a new unused sector. After too many writes, however, there will be no more usable storage, and smart firmware implementations will lock the drive to prevent data loss. At that point, your only option would be to copy the data to a new flash drive.

Related Question