USB drive becomes read-only again and again
Hi!
I'm having trouble with a MicroSD USB drive. Or rather with the MicroSD card itself I guess. I'm running Ubuntu 7.10. The card is formatted as FAT16 (and it's out of the question to use anything else). Reading from it and writing to it works fine up to a certain point. Then suddenly I only get read access any more no matter what I do. Plugging it in and out or remounting doesn't change a thing. It only works again once I reformat. That's pretty annoying because I have to copy all the data back to it each time. Is there any way to fix this without reformatting? Btw read/write is still working in Windows. |
How are you mounting it? Please show some logs (syslog, messages) at the time when you mount it and try to write to it.
If your adapter is working correctly it should simply work like any other USB flash drive. |
How much stuff are you getting written to it before it becomes read-only? FAT16 has a limit to the number of files/folders that can exist on the root of a disk. The limit is 512, based on names 13 characters and smaller. So if you use long filenames more than 13 characters long the limit can easily become 256 or fewer.
|
Linux usually remounts a drive as read-only if the drive is showing a lot of I/O errors.
Take a look at your logs and see if this is the case here. You could have a flaky drive, or a flaky USB controller, or a bad cable. |
Ok, this is snippet from my syslog file. So it looks like some clusters aren't alright. Is there a way to repair them instead of reformating each time? And how can I find out what triggers the problem?
I think I can rule out the possibility of writing too many/too long files. It's only one file with 8+3 characters. Code:
Dec 3 13:02:42 yoda kernel: [ 7389.272971] usb 2-2: new high speed USB device using ehci_hcd and address 5 |
Quote:
More than likely the error is there and this means you have a hardware problem. If the error is really only in Linux that makes it seem like there is a driver problem, but I seriously doubt Linux would have trouble with a flash drive. What mount options are you using? |
Looks to me like the error is in the FAT file system. I will point out that Windows is notorious for ignoring errors in its filesystems unless those errors rise to the level of keeping Windows from working.
So this could be a case of Linux keeping you out of trouble that Windows would cheerfully get you into...dunno, not sure. You need to google that error message, but it looks to me like you are out of File allocation table space, or else the bounds of your FAT table are messed up. I suggest you run chkdsk on this flash drive from Windows and let it clean things up. I suppose there is a Linux tool to check and repair FAT, but I don't use FAT (except in my flash drives) so I don't know. Generally, I just plug my flash drives into an XP system if they need maintenance. |
edit. Yes, there is a linux tool. Command is dosfsck.
edit on edit. Oops. Meant for that edit to go into the previous post. Typed in the wrong window. |
Thanks a lot, dosfsck seems to be doing the trick. :) Looks like the files are sometimes not written completely.
Code:
$ dosfsck -a /dev/sda1 |
Quote:
I have a lot of RAM, which linux uses for disk & memory card cache. Sometimes when I ask to "Safely Remove" a USB stick, it may take up to 40 seconds to finish writing the cache to the external device. |
In that 40 seconds though, if you run mount you still see it mounted, right?
|
@shadowsnipes:
Yes, if I run mount it is still mounted while the cache is written, but some of the GUIs (Eg my KDE 3.5.2) "Safely Remove" the desktop icon before the cache has been written. So I have learned to look at the little flashing light on the USB stick, or manually check with mount that it has indeed been unmounted before I unplug it. No problems since :) |
Yea, I don't always trust GUIs so I always check with the mount command as well
|
Quote:
|
The above thread was very useful as I am facing the same problem and am running dosfsck to repair my USB drive. Thanks. I googled for what it tries to fix to understand the output and ran it with -v option, but didn't get much information. Can anyone elaborate on what:
File size is 111 bytes, cluster chain length is 0 bytes. Truncating file to 0 bytes. and Contains a free cluster (5523521). Assuming EOF. signifies? Does the USB hard drive have an internal table which keeps track of the clusters used and if the table entries are not in sync with the data on the disk, at that time these errors are detected? |
Excuse me, I have no experience with OS on USB sticks; may I safely conclude from this thread that linux installed on a flash memory drive (live-usb) can be configured to write on the stick as well?
For example to configure a web browser from the USB to store cookies on the stick, Vi editor to use /tmp on a stick, or any other application which will need /tmp ? I know it can write to a RAM disk file system, of course, just like a distro on live-cd. But can it write on the stick ? |
Quote:
This was an old thread, but anyway - If I understand correctly those messages simply indicate lost cluster(s) recovered by dosfsck - the type of error caused by write failures, power hiccups, software glitches, etc. The same thing scandisk in DOS/Win fixes without showing such messages. Your messages might be related to a file taking up 111 bytes when the FAT says it should be 0, or an incomplete write. The same problem as the OP, eh? There are a few possible causes: 1) The number of files/folders on the root of the disk. FAT16 and FAT 32 have limits that can easily be exceeded by today's standards. 2) Power fluctuation on the usb root hub or disk drive. Have you tried testing it on other computers? 3) Corrupt FAT. Maybe dosfsck can't detect or fix this. Wipe and reformat the drive/partition, maybe? 4) Bad sectors where the disk it trying to write. SMART has been good at reassigning bad sectors to avoid problems, but sometimes it runs out of space for reassignment. The badblocks command in linux can scan for bad sectors. Get a copy of the Window$ utility HDDScan and run it with Admin privelege to get a SMART report. High and increasing values for reallocation_sector_count, reallocation_event_count and current_pending_sector_count could indicate pending drive failure. http://hddscan.com/ USB hard drives and flash drives still use allocation tables for FAT-formatted partitions, or journals for NTFS, to track cluster usage and assignment. USB hard drives are actually internal drives mounted in a box. Anything that applies to internal drives also applies to USB hard drives: partitioning, mechanics, etc. Flash drives, though, also use FAT tables or journals, but the technology is more sensitive, has longer write delays, and more prone to data loss during any of the previously-mentioned situations. Hope this helps |
Thanks Dracolich. This was useful info. Will check out hddscan and badblocks. Hddscan look quite interesting and would be a good tool to know more.
|
All times are GMT -5. The time now is 03:57 AM. |