2

Let me start out by giving you some general background information. My actual question is at the very bottom of this post.


Background, part 1: Journal replays vs. consistency checks.

Please assume that your Android device uses the ext4 filesystem for its internal storage, and the FAT32 filesystem for its removable MicroSD storage (if present).

On ext4, a "journal replay" is a partial filesystem check-and-repair operation which normally takes no more than few seconds. (Source.) The Android kernel does a journal replay whenever necessary. (Based on this source and this source.)

On ext4, a full filesystem consistency check takes longer. For an average Android device, it takes 12 seconds or so. (Based on this source.)

FAT32 is a non-journaling filesystem. So there are no journal replays. There are only consistency checks.


Background, part 2: It's probably a good idea for your OS to do periodic consistency checks. Here's why.

Microsoft program manager Kiran Bangalore writes that there are certain cases in which a filesystem can become corrupted. On a journaling filesystem such as ext4, such cases are exceedingly rare. On removable MicroSD cards, I suspect that such cases are not so rare.

The usual way to check for such corruption is to configure your OS to run a consistency-check tool every so often. Such tools include chkdsk, ScanDisk, Apple Disk Utility, fsck, and others.

Even on ext4 storage built into an Android device, periodic consistency checks are probably a good idea. The tune2fs manual page explains why:

Bad disk drives, cables, memory, and kernel bugs could all corrupt a filesystem without marking the filesystem dirty or in error. If you are using journaling on your filesystem, your filesystem will never be marked dirty, so it will not normally be checked. A filesystem error detected by the kernel [may] still force a [consistency check] on the next reboot, but it may already be too late to prevent data loss at that point.

(Note that, on Android, I think a filesystem error detected by the kernel will not lead to a consistency check on the next reboot. Android is strange that way.)


Background, part 3: Here's what other OSes do.

Windows

Windows Vista, and all later versions of Windows, include an NTFS self-healing feature. Kiran Bangalore therefore writes that, nowadays, Windows users no longer need to run periodic consistency checks anymore. He explains that the OS "will inform you when ... corruption is found".

Windows 10 Mobile

Windows 10 Mobile is probably the third-most-popular smartphone OS. I think it uses NTFS. So perhaps it also can do NTFS self-healing.

OS X

Mac OS X runs fsck_hfs -p during every boot. I don't know what this does. See the manual page.

Linux

It's true that some ext4 developers say that periodic ext4 consistency checks aren't particularly useful. But other ext4 developers say that these checks improve safety and reliability.

In practice, when a filesystem is marked in error, Linux runs a consistency check at the next reboot. At other times, modern Linux distributions don't do automatic periodic consistency checks, ever. Those who want them must schedule these checks themselves.

Android

Stock Android includes an ext4 consistency-check tool. As well, it includes a consistency-check tool which works on removable MicroSD cards of 32 GB or less (but may corrupt larger cards). Finally, your device may or may not also include fsck.exfat or exfatfsck, for running consistency checks on removable MicroSD cards of 64 GB or more.

But does the OS ever run any of these tools automatically?

iOS

The iOS filesystem is normally either HFSX or APFS, and fsck is included with the OS. I don't know whether or not iOS ever runs automatic consistency checks.


Here's my question.

Please consider the stock ROMs shipped with current Android devices.

Do such stock ROMs ever periodically run consistency checks, either on the internal storage device or (if applicable) on the removable MicroSD card?

(P.S. In cases where a device shuts down gracefully and has enough battery charge left, it's possible to run a consistency check at shutdown instead of at startup. But it takes some engineering effort to implement such functionality, and so operating system developers normally don't bother. I wonder what Android does.)

(P.P.S. I also wonder whether or not there exist any smartphones, running any OS, which do any routine periodic consistency checking. Again, please post comments below.)

2

Not-yet-released Android versions

There have been some recent improvements made to the Android source code.

The next maintenance release of stock Android will be either 7.2 or 8.0. In some future version of stock Android — either that maintenance release or a later release — Android will run the fsck -f -y command during every normal shutdown. This command forces a consistency check on the internal storage, no matter what. (Based on this source and this source.)

Hurrah! Considering that so few Android users ever do complete backups (e.g. Nandroid backups), I think that this may be a useful enhancement.

Unfortunately, I still don't know of any evidence that Android ever checks any removable MicroSD card.

The above answer is about stock Android. Still, I thank the CyanogenMod team and the LineageOS team for indirectly helping me to discover the above information.

Running checks yourself

The above paragraphs refer to versions of Android which haven't been released yet.

If you're running an earlier version of Android, you can run an internal-filesystem consistency check manually yourself if you so desire. You must unmount the filesystem first, so you must be in recovery mode. See here.

Checking your MicroSD card

If you have a removable MicroSD card, you should definitely check it on certain occasions, and also periodically. If you'd like more information, please see:

  • Hmm, what kind of influence will this have on shutdown/reboot speed? – Andy Yan Mar 27 '17 at 10:27
  • Reboots won't trigger any consistency check. Shutdowns will take perhaps 12 seconds longer. Overall reliability may be improved. – unforgettableid Mar 27 '17 at 10:54
  • Good to know, though as someone who flashes (and therefore does nandroid) on a monthly basis, I'm not quite the target of this change... – Andy Yan Mar 27 '17 at 11:08
  • Agreed. Yeah, backups are important. To quote Tetsujin: "Any data stored in less than three distinct locations ought to be considered temporary. The more important the data, the more important the multiplicity of backups." – unforgettableid Mar 27 '17 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.