LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   USB drive becomes read-only again and again (https://www.linuxquestions.org/questions/linux-hardware-18/usb-drive-becomes-read-only-again-and-again-603214/)

dominik81 11-29-2007 05:36 AM

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.

shadowsnipes 11-29-2007 09:23 AM

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.

dracolich 11-29-2007 02:51 PM

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.

jiml8 11-30-2007 10:03 AM

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.

dominik81 12-03-2007 06:23 AM

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
Dec  3 13:02:42 yoda kernel: [ 7389.411019] usb 2-2: configuration #1 chosen from 1 choice
Dec  3 13:02:42 yoda kernel: [ 7389.411508] scsi6 : SCSI emulation for USB Mass Storage devices
Dec  3 13:02:42 yoda kernel: [ 7389.411610] usb-storage: device found at 5
Dec  3 13:02:42 yoda kernel: [ 7389.411612] usb-storage: waiting for device to settle before scanning
Dec  3 13:02:42 yoda NetworkManager: <debug> [1196683362.290456] nm_hal_device_added(): New device added (hal udi is '/org/freedesktop/Hal/devices/usb_de
vice_5e3_715_000000009407').
Dec  3 13:02:42 yoda NetworkManager: <debug> [1196683362.349048] nm_hal_device_added(): New device added (hal udi is '/org/freedesktop/Hal/devices/usb_de
vice_5e3_715_000000009407_if0').
Dec  3 13:02:42 yoda NetworkManager: <debug> [1196683362.552286] nm_hal_device_added(): New device added (hal udi is '/org/freedesktop/Hal/devices/usb_de
vice_5e3_715_000000009407_usbraw').
Dec  3 13:02:47 yoda kernel: [ 7394.405273] usb-storage: device scan complete
Dec  3 13:02:47 yoda kernel: [ 7394.407513] scsi 6:0:0:0: Direct-Access    Generic  STORAGE DEVICE  9407 PQ: 0 ANSI: 0
Dec  3 13:02:47 yoda kernel: [ 7394.489855] sd 6:0:0:0: [sda] 1939456 512-byte hardware sectors (993 MB)
Dec  3 13:02:47 yoda kernel: [ 7394.492573] sd 6:0:0:0: [sda] Write Protect is off
Dec  3 13:02:47 yoda kernel: [ 7394.492579] sd 6:0:0:0: [sda] Mode Sense: 03 00 00 00
Dec  3 13:02:47 yoda kernel: [ 7394.492581] sd 6:0:0:0: [sda] Assuming drive cache: write through
Dec  3 13:02:47 yoda kernel: [ 7394.498864] sd 6:0:0:0: [sda] 1939456 512-byte hardware sectors (993 MB)
Dec  3 13:02:47 yoda kernel: [ 7394.501567] sd 6:0:0:0: [sda] Write Protect is off
Dec  3 13:02:47 yoda kernel: [ 7394.501572] sd 6:0:0:0: [sda] Mode Sense: 03 00 00 00
Dec  3 13:02:47 yoda kernel: [ 7394.501575] sd 6:0:0:0: [sda] Assuming drive cache: write through
Dec  3 13:02:47 yoda kernel: [ 7394.501579]  sda: sda1
Dec  3 13:02:47 yoda kernel: [ 7394.504266] sd 6:0:0:0: [sda] Attached SCSI removable disk
Dec  3 13:02:47 yoda kernel: [ 7394.504298] sd 6:0:0:0: Attached scsi generic sg0 type 0
Dec  3 13:02:47 yoda NetworkManager: <debug> [1196683367.443276] nm_hal_device_added(): New device added (hal udi is '/org/freedesktop/Hal/devices/usb_de
vice_5e3_715_000000009407_if0_scsi_host').
Dec  3 13:02:47 yoda NetworkManager: <debug> [1196683367.446374] nm_hal_device_added(): New device added (hal udi is '/org/freedesktop/Hal/devices/usb_de
vice_5e3_715_000000009407_if0_scsi_host_scsi_device_lun0').
Dec  3 13:02:47 yoda NetworkManager: <debug> [1196683367.471321] nm_hal_device_added(): New device added (hal udi is '/org/freedesktop/Hal/devices/usb_de
vice_5e3_715_000000009407_if0_scsi_host_scsi_device_lun0_scsi_generic').
Dec  3 13:02:47 yoda NetworkManager: <debug> [1196683367.550512] nm_hal_device_added(): New device added (hal udi is '/org/freedesktop/Hal/devices/storag
e_serial_Generic_STORAGE_DEVICE_000000009407_0_0').
Dec  3 13:02:47 yoda NetworkManager: <debug> [1196683367.675216] nm_hal_device_added(): New device added (hal udi is '/org/freedesktop/Hal/devices/volume
_uuid_474E_ACED').
Dec  3 13:02:48 yoda hald: mounted /dev/sda1 on behalf of uid 1000
Dec  3 13:02:56 yoda kernel: [ 7403.350725] FAT: Filesystem panic (dev sda1)
Dec  3 13:02:56 yoda kernel: [ 7403.350731]    fat_free_clusters: deleting FAT entry beyond EOF

Dec  3 13:02:56 yoda kernel: [ 7403.350734]    File system has been set read-only
Dec  3 13:05:01 yoda /USR/SBIN/CRON[7726]: (root) CMD (  if [ -d /var/lock/mrtg ]; then if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then env LANG=C
 /usr/bin/mrtg /etc/mrtg.cfg >> /var/log/mrtg/mrtg.log 2>&1; fi else mkdir /var/lock/mrtg; fi)
Dec  3 13:10:01 yoda /USR/SBIN/CRON[7816]: (root) CMD (  if [ -d /var/lock/mrtg ]; then if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then env LANG=C
 /usr/bin/mrtg /etc/mrtg.cfg >> /var/log/mrtg/mrtg.log 2>&1; fi else mkdir /var/lock/mrtg; fi)


shadowsnipes 12-03-2007 09:16 AM

Quote:

Originally Posted by dominik81 (Post 2974295)
Hi!
Btw read/write is still working in Windows.

I'm wondering if the error is also present in Windows, but the OS happily keeps on writing to the drive. Perhaps this is worth a look (check the logs in the Computer Management Console).

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?

jiml8 12-03-2007 04:09 PM

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.

jiml8 12-03-2007 04:14 PM

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.

dominik81 01-15-2008 07:58 AM

Thanks a lot, dosfsck seems to be doing the trick. :) Looks like the files are sometimes not written completely.

Code:

$ dosfsck -a /dev/sda1
dosfsck 2.11, 12 Mar 2005, FAT32, LFN
FATs differ but appear to be intact. Using first FAT.
/filename.bin
  Contains a free cluster (14885). Assuming EOF.
/filename.bin
  File size is 1733184 bytes, cluster chain length is 0 bytes.
  Truncating file to 0 bytes.
/.Trash-dominik
  Contains a free cluster (15100). Assuming EOF.
Reclaimed 227 unused clusters (3719168 bytes) in 16 chains.
Performing changes.
/dev/sda1: 1149 files, 58482/60225 clusters


tredegar 01-15-2008 08:07 AM

Quote:

Looks like the files are sometimes not written completely.
This can happen if you do not wait long enough after unmounting or "Safely Removing" the drive / card before you physically remove it.
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.

shadowsnipes 01-15-2008 10:10 AM

In that 40 seconds though, if you run mount you still see it mounted, right?

tredegar 01-15-2008 01:44 PM

@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 :)

shadowsnipes 01-15-2008 01:50 PM

Yea, I don't always trust GUIs so I always check with the mount command as well

dracolich 01-15-2008 02:49 PM

Quote:

Originally Posted by shadowsnipes (Post 3023566)
Yea, I don't always trust GUIs so I always check with the mount command as well

Same here. I always use the mount/umount commands to handle mine. I wouldn't even know if I have a gui tool for it 'cause I've never been interested enough to find out. :D If I issue the umount command on a disk that still has to write the cache, the prompt doesn't return until it's finished. That's when I know it's safe to remove. Watching the LED works, too, if you don't forget to watch it. However, I've seen serveral that don't have an LED indicator. IMO, that's poor design.

crashpoint_zero 11-17-2010 01:10 AM

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?

CMartin 11-17-2010 03:03 AM

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 ?

dracolich 11-17-2010 08:44 AM

Quote:

Originally Posted by crashpoint_zero (Post 4161539)
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?

Hi and welcome to LQ!
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

crashpoint_zero 11-17-2010 11:38 PM

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.