Unexpected file corruption

garyn

Member
Joined
Jan 12, 2026
Messages
94
Reaction score
82
Credits
886
I have many USB / SD cards in / from my camera, phone, dash cam, tablet and security system. Sometimes I inadvertently unplug one without unmounting it and it's caused file corruption on the memory card that was connected via either a usb cable or card reader or by a power glitch from Florida's sometimes unstable power grid.

I "thought" that reading a device should not affect file system integrity but it seems as if I'm incorrect?
 


I have many USB / SD cards in / from my camera, phone, dash cam, tablet and security system. Sometimes I inadvertently unplug one without unmounting it and it's caused file corruption on the memory card that was connected via either a usb cable or card reader or by a power glitch from Florida's sometimes unstable power grid.

I "thought" that reading a device should not affect file system integrity but it seems as if I'm incorrect?


Even when reading files the system might be writing data to the card through background processes like file metadata, i.e. "last modified", "last accessed" ect, timestamps of sorts. Sometimes they're writing an automated hidden file for thumbnail caches ect for indexing.

So while generally safe to unplug if not actively writing, in the off chance you do so while it's actively doing one of these background tasks you end up with data corruption.
 
I suppose mounting a filesystem as read-only would prevent such background writes, but then you also couldn't, for instance, remove unwanted files either.

When you mention "corruption", I automatically think you're starting a political discussion. :)
 
I have cards that as far as Linux is concerned is static that were written on other devices I have to wonder why I'd "need" metadata, i.e. "last modified", "last accessed" ect, timestamps of sorts. Sometimes they're writing an automated hidden file for thumbnail caches
for files Linux did not create, and will not be modified? I'd Waayyy prefer no accidental corruption.
 
Removing a device safely saves many problems and I don't want problems.
1779327776506.gif
 
Loss of power and/or accidental removal can cause file corruption on any OS, and does regularly. Often the cause of file corruption is PEBKAC.
 
Having a good UPS is superb advice (all my computers, router, LAN switches, etc. run off a UPS).

However, nobody has mentioned entering the sync terminal command. That flushes all unwritten data to your drives. At that point it's safe to remove it.

There was a recent discussion here about sync.

Type man sync in a terminal.
 
Last edited:


Follow Linux.org

Members online


Top