5

I have a usb flash memory which I can't do anything on it because its read only:

sudo fdisk -l

Device     Boot   Start     End   Sectors  Size Id Type
/dev/sdc1  *     2048    7864319 7862272  3.8G  b W95 FAT32

I've tried to fix file system with mkfs and I got this :

sudo mkfs.fat -F 32 /dev/sdc1

mkfs.fat 3.0.28 (2015-05-16)
mkfs.fat: unable to open /dev/sdc1: Read-only file system

How can I fix this?

PS: Let's assume the USB is not write-protected by design, such as with a manual switch.

PJ Brunet
  • 733
  • 8
  • 17
ali73
  • 151
  • 1
  • 1
  • 7
  • The command `mount` (probably as root) is the one to use to change mounted filesystem state, not `mkfs`. –  Dec 18 '17 at 19:35
  • 5
    Is this a sandisk usb? Some have a hardware 'safety lock' that locks the usb to read-only in the event of a usb power fluctuation. I had one that did this and had to be returned, though they replaced it FOC. – bu5hman Dec 18 '17 at 20:43
  • 1
    Is it plugged into a USB 3.0 socket (the blue kind)? I have a 4 GB flash drive that mounts as read-only when connected to USB 3.0, but I can write to it when I use the older USB sockets on the same computer (running Xubuntu 16.04). – Gaultheria Dec 18 '17 at 21:46
  • we have same distro but unfortunately my laptop does not have any USB 2.0 socket.I will try it on another laptop .Thanks – ali73 Dec 19 '17 at 07:31
  • That wasn't the problem... I tried all the things I knew on USB 2.0 port and it was the same result – ali73 Dec 20 '17 at 09:47
  • 2
    Have you read https://unix.stackexchange.com/questions/74090/linux-how-to-change-hdd-state-from-readonly-after-temporarly-crash is proposes `blockdev --setrw` or `hdparm -r 0` – Sandburg May 20 '18 at 20:26
  • Try according to the following link, [Postrequisites - restore the USB stick](https://help.ubuntu.com/community/Installation/FromUSBStick#Postrequisites_-_restore_the_USB_stick) – sudodus Oct 07 '18 at 07:47
  • @sudodus I'm afraid I don't have access to the flash memory anymore. – ali73 Oct 09 '18 at 05:05
  • You can analyze the problem, and if you are lucky, solve it with help from this link, [Can't format my usb drive. I have already tried with mkdosfs and gparted](https://askubuntu.com/questions/144852/cant-format-my-usb-drive-i-have-already-tried-with-mkdosfs-and-gparted/933035#933035) – sudodus Oct 09 '18 at 06:24
  • I recommend this is flagged as a "duplicate" instead of "off-topic" and go with @Sandburg 's comment... – PJ Brunet Nov 24 '20 at 04:12
  • @PJBrunet The originating user [doesn't have access to the hardware any longer](https://unix.stackexchange.com/questions/411647/fix-read-only-file-system-usb#comment866097_411647), and can therefore not verify that a solution works or not. The question was closed as "non-reproducable, problem went away by itself". – Kusalananda Nov 24 '20 at 09:11
  • Gaultheria nailed it, was stuck in usb 3 socket, as soon as i put into a usb 2, I could work with the files again. Strange behavior, glad I came across his comment – Lizardx Feb 15 '21 at 23:17

1 Answers1

3
  1. Make sure you are performing filesystem management actions with escalated privileges. Most systems do not let users modify filesystems.

  2. Ensure the device isn't already mounted. As root, execute lsblk and look for any filesystems using /dev/sdc1. If it is mounted you will have to unmount prior to formatting with mkfs.

  3. Make sure the device is not a read-only UFD. Though uncommon, these do exist ... usually as hand-outs from vendor booths with product sheets or other vendor info on them.

Quick walkthrough of steps

  1. Verify you are performing all tasks as root. Best way is to simply open a shell as root: In a terminal, execute sudo -i is usually the easiest way.
  2. Unmount the device with umount /dev/sdc1 (may give error info if it is not mounted, no worries if this happens)

VVV WARNING THIS WILL DESTROY ALL DATA ON THE DEVICE VVV

  1. Format the device mkfs.vfat /dev/sdc1 (you can force 32bit size if you wish, but mkfs will select whatever fits best for the size of the volume)

If this does not work, you may want to wipe the device, recreate the partition with fdisk, and try again:

wipefs -a /dev/sdc

Again, this will destroy any remaining data. You have been warned.

0xSheepdog
  • 2,742
  • 1
  • 20
  • 31
  • I unmount it before I use these commands. – ali73 Dec 18 '17 at 19:46
  • 11
    wipefs also invokes error read only file system – ali73 Dec 19 '17 at 07:28
  • 7
    `mkfs.vfat: unable to open /dev/mmcblk0: Read-only file system` still the same error – mirkobrankovic Apr 06 '19 at 14:26
  • 1
    How does this help one get write access to the filesystem? I mean sure, I can overwrite it, no problem. But there is a deep mystery as to why this DOS image I wrote to it only mounts readonly. – Bernd Wechner Nov 29 '19 at 04:25
  • This worked for me: I used the pendrive to create boottable linux installer – Nacho Apr 26 '20 at 18:29
  • See Gaultheria's comment abovel before you set off on any complicated route, just try to make sure it's not a usb 3 vs usb 2 issue, changing to a usb 2 port fixed the read only issue immediately for me. I'd add that as an answer because rule 1 is always try the simple thing before anything else, exclude that, than go to the complex stuff but this is closed. – Lizardx Feb 15 '21 at 23:20
  • Didn't work for me. The big problem, no matter what I do, I still see "read-only" warning. – Pranav Jul 03 '21 at 16:34