LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices

Reply
 
Search this Thread
Old 11-29-2007, 05:36 AM   #1
dominik81
Member
 
Registered: Sep 2003
Location: Germany
Distribution: Ubuntu 7.10
Posts: 54

Rep: Reputation: 15
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.
 
Old 11-29-2007, 09:23 AM   #2
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,441

Rep: Reputation: 70
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.
 
Old 11-29-2007, 02:51 PM   #3
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,173

Rep: Reputation: 47
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.
 
Old 11-30-2007, 10:03 AM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
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.
 
Old 12-03-2007, 06:23 AM   #5
dominik81
Member
 
Registered: Sep 2003
Location: Germany
Distribution: Ubuntu 7.10
Posts: 54

Original Poster
Rep: Reputation: 15
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)
 
Old 12-03-2007, 09:16 AM   #6
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,441

Rep: Reputation: 70
Quote:
Originally Posted by dominik81 View Post
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?
 
Old 12-03-2007, 04:09 PM   #7
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
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.
 
Old 12-03-2007, 04:14 PM   #8
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
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.
 
Old 01-15-2008, 07:58 AM   #9
dominik81
Member
 
Registered: Sep 2003
Location: Germany
Distribution: Ubuntu 7.10
Posts: 54

Original Poster
Rep: Reputation: 15
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
 
Old 01-15-2008, 08:07 AM   #10
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
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.
 
Old 01-15-2008, 10:10 AM   #11
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,441

Rep: Reputation: 70
In that 40 seconds though, if you run mount you still see it mounted, right?
 
Old 01-15-2008, 01:44 PM   #12
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
@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
 
Old 01-15-2008, 01:50 PM   #13
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,441

Rep: Reputation: 70
Yea, I don't always trust GUIs so I always check with the mount command as well
 
Old 01-15-2008, 02:49 PM   #14
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,173

Rep: Reputation: 47
Quote:
Originally Posted by shadowsnipes View Post
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. 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.
 
Old 11-17-2010, 01:10 AM   #15
crashpoint_zero
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Rep: Reputation: 1
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
USB drive Read/Write - NTFS sp149 Linux - General 7 11-14-2007 04:11 PM
USB flash drive (Pen drive) mounts read only prabhatsoni Linux - Hardware 24 07-02-2007 01:28 PM
usb flash drive always read-only flihp Linux - Hardware 2 11-12-2005 05:14 PM
How to Read USB drive in RH9 omeryasin Linux - Newbie 4 10-28-2005 10:59 PM
read usb drive in redhat 9.0 ? wlaw Linux - Newbie 1 06-21-2004 06:50 AM


All times are GMT -5. The time now is 03:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration