How to fix read-only usb drive?

53,787

Solution 1

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.

Solution 2

Simple solution: plug the flash drive into a computer that operates on Windows. Windows will detect the error and instruct you to scan and repair it. The drive will then work on Ubuntu in the usual way.

Share:
53,787

Related videos on Youtube

godot
Author by

godot

Updated on September 18, 2022

Comments

  • godot
    godot over 1 year

    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?

    • Rinzwind
      Rinzwind over 6 years
      1. where did the USB come from: some USBs -are- read only. Often when those are commercial those USB are hardware locked. 2. Some USB have a hardware lock on the outside.
    • godot
      godot over 6 years
      this usb was worked normally and once it became read-only. I think during monting or unmounting
    • Katu
      Katu over 6 years
      Can you add the output of dmesg when you insert the USB?
    • godot
      godot over 6 years
      what is dmesg??
    • sudodus
      sudodus over 6 years
      Maybe the tips in the following link will help, askubuntu.com/questions/144852/…
    • Robert Riedl
      Robert Riedl over 6 years
      USB drives can be fickle... best to try @sudodus linked answer
    • hatterman
      hatterman about 6 years
      At a command promt type "mount". Where is the USB driver mounted ? (example /media/myname/mountpoint). What are the permissions of /media/myname/mountpoint ? Is the mountpoint owned by root ?
    • David Foerster
      David Foerster about 6 years
      Could you please edit your question to include the output of dmesg | tail -n 100 shortly after connecting the USB storage? Also cat /sys/block/sd?/ro (replace ? with the appropriate device name letter) allows you to check if the storage itself or only the file system thereon is read-only.
    • EsmaeelE
      EsmaeelE over 3 years
  • hatterman
    hatterman about 6 years
    If there is nothing on the drive you need to keep, use "gparted" to create a new filesystem on the drive, create a new partition and format it to your format of choice (I guess you want fat32 ?). If it mounts read only, you need to change the permissions of the mount point.
  • user68186
    user68186 almost 5 years
    Nice answer! Some screenshots will make it wonderful.
  • Marcos Pereira de Sousa
    Marcos Pereira de Sousa over 2 years
    Great Kevin; Thanks.