LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-28-2019, 07:51 AM   #16
GTrax
Member
 
Registered: Oct 2005
Location: UK
Distribution: Mint
Posts: 258

Original Poster
Rep: Reputation: 37

It was the "dirty bit"!
I used the fsck command to check the fileysystem. For me, it is the first time I have tried this.

If your USB flash drive suddenly becomes read-only..
Suspect that there is a corrupt or broken file somewhere on it. It is the signal that the USB flash drive has "suffered an event". It need not be broken, but it may have copied onto it somewhere, a file that is (broken). Mine happened to come from a Windows system, and it had something called "broken chains".

It need not be a Windows file, but most users opt to use a Windows/MSDOS type filesystem on flash sticks, usually FAT32 if it it is a stick bigger than 4GB. It allows to move files between Linux and Windows machines. I have no idea what a Windows machine does if one plugs in an ext4 formatted stick.

If a whole folder was copied, with files in sub-folders, it can happen that there are broken chains in fragmented files.

If the drive was removed while the copy was only locally cached, it can cause broken chains in a FAT32 system. Even if enough time has passed for the copy to complete - it does not mean the cache cooperated. "Safely Remove" is what you need, but this still does not guarantee the flash drive dirty bit will stay OK.

All the later symptoms of repeatedly reverting to read-only seem to be because of the "dirty bit" flag

The drive can be temporarily set to read-write, and under limited forced conditions, be written to, but as soon as it is seen in normal operation, the "dirty bit" flag will turn it back into read-only.

In the following fix-it example, the flash drive is /dev/sdb1 and has name B3AB-8FAD

Repair the filesystem with sudo fsck
Code:
$ sudo fsck -V /dev/sdb1
fsck from util-linux 2.31.1
[/sbin/fsck.vfat (1) -- /dev/sdb1] fsck.vfat /dev/sdb1
fsck.fat 4.1 (2017-01-24)
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
1) Remove dirty bit
2) No action
? 1
/untitled folder/<the_broken_filename>
 Start does point to root directory. Deleting dir. 
Reclaimed 256 unused clusters (4194304 bytes).
Free cluster summary wrong (1758355 vs. really 1758611)
1) Correct
2) Don't correct
? 1
Perform changes ? (y/n) y
/dev/sdb1: 3093 files, 117424/1876035 clusters
..lets one correct the dirty bit flag. It finds messed up folder, and allows to delete the directory and reclaim unused clusters.

We are not done yet. The fix leaves some loose ends, and the filesystem is still read-only. Use sudo fsck again.
Code:
$ sudo fsck -V /dev/sdb1
fsck from util-linux 2.31.1
[/sbin/fsck.vfat (1) -- /dev/sdb1] fsck.vfat /dev/sdb1 
fsck.fat 4.1 (2017-01-24)
Orphaned long file name part "<the_broken_filename>"
1: Delete.
2: Leave it.
? 1
Perform changes ? (y/n) y
/dev/sdb1: 3092 files, 117424/1876035 clusters
It allows to correct the free cluster summary.
Keep going one last time - to check it reports clean.
Code:
$ sudo fsck -V /dev/sdb1
fsck from util-linux 2.31.1
[/sbin/fsck.vfat (1) -- /dev/sdb1] fsck.vfat /dev/sdb1 
fsck.fat 4.1 (2017-01-24)
/dev/sdb1: 3092 files, 117424/1876035 clusters
It may be fixed, but it is still flagged read-only. So finally use the remount again to force it to be mounted as read-write.
Code:
$ sudo mount -o remount,rw /media/<username>/B3AB-8FAD
$ /home/<username># mount | grep /dev/sdb1
/dev/sdb1 on /media/<username>/B3AB-8FAD type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)
From this point on, the USB flash drive should work again normally.

Very strange that the "dirty" Windows file was easily copied off the USB while in "dirty" read-only state, and it seemed OK, but I trashed it anyway.

I am hoping this can be marked "SOLVED", but I leave it here for a bit.
My thanks to all for their suggestions.

Last edited by GTrax; 04-28-2019 at 10:59 AM.
 
2 members found this post helpful.
Old 04-28-2019, 10:18 AM   #17
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Salix
Posts: 6,243

Rep: Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364
I was going to ask why no-one had thought of fsck! It's a standard Linux procedure to mark a device as read-only if the filing system looks suspicious, to prevent possible corruption.

My own experience, using CentOS and Salix, was that I only once had a USB stick suffer that fate. The first couple of times I used fsck, then I reformated it, then I ditched it. But my sticks are all ext2 format and I don't have Windows.
 
Old 04-28-2019, 10:56 AM   #18
GTrax
Member
 
Registered: Oct 2005
Location: UK
Distribution: Mint
Posts: 258

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by DavidMcCann View Post
I was going to ask why no-one had thought of fsck! It's a standard Linux procedure to mark a device as read-only if the filing system looks suspicious, to prevent possible corruption.
Hi David
I entirely agree. You would have thought that out of the very many postings, suggestions, "solutions" that seemed OK at the time, but turned out to be somewhat short-lived, that by now, someone would have explained why it happens, and how to use fsck to fix it. Maybe they did, but it would be in the middle of a lot of misguided noise, and I never found it. It seems similar situations happen in Windows-Windows transfers, and with a lot of variable advice on what to do.

For Windows users
There have to be equivalent commands. DISKPART can reset the read-only flag, but you need chkdsk to repair the messed up chains. There are arguments chkdsk C: /f /r /x
/f allow to fix any errors it finds.
/r tells it to locate bad sectors and recover any readable information. (This may result in a blizzard of default named files, all from recovered clusters, that may have to be stitched together later - or abandoned.
/x forces the drive to be dismounted before the fix gets under way.
That is the best I can do, because I am on shakey ground anyway, and more so when it comes to Windows systems. I am sure some search keywords will help.

As a user, and not a programmer, a command line adventure involving fsck gives me a case of nerves, and what I put in the posting was, in fact, the first time I have ever used it. What I posted seems to work, and tentatively, I am going to mark this phenomenon "SOLVED"

Last edited by GTrax; 04-28-2019 at 11:45 AM.
 
Old 04-29-2019, 11:27 AM   #19
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Salix
Posts: 6,243

Rep: Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364
Quote:
Originally Posted by GTrax View Post
As a user, and not a programmer, a command line adventure involving fsck gives me a case of nerves…
That's a sensible instinct! Luckily the tool has the -N option that doesn't actually do anything, just reporting what fsck would do if you let it.
 
  


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
LXer: Tor becomes extra secure as .onion becomes Special-Use Domain Name LXer Syndicated Linux News 0 09-14-2015 07:00 PM
USB drive becomes read-only again and again dominik81 Linux - Hardware 17 11-17-2010 11:38 PM
USB external hard disk becomes read only after running for a while. itsakc Linux - Hardware 2 12-28-2009 06:13 PM
When backspace becomes ^[[D and up arrow becomes ^[[A simonb Linux - Software 1 12-21-2008 01:04 AM
Mounted read-write Fat32 partition suddenly becomes read-only?? hohead Linux - General 8 04-05-2007 12:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration