51

Sometimes my SD card gets "corrupted" and this leads to many read/write errors. Usually, connecting the SD card to the windows 7 and selecting the "Error Checking" (Right click the drive > Tools > Error Checking) option finds the corruption and fixes it.

How do I check SD cards for drive errors and fix the same from within the android itself?

I'd also like to mention that I'm on rooted froyo with busybox installed.

1
  • 2
    If you repeatedly have errors on your SD card, you should make sure that it is really of the stated capacity using H2testw (link only in German, software in German and English. I believe this is the official home despite appearances to the contrary). Bad SD cards will automatically corrupt.
    – Codebling
    Jul 8, 2015 at 4:46

5 Answers 5

18

You can fix this with the help of root and a terminal emulator (e.g. Android Terminal Emulator (or, alternatively, using adb shell). The binary to do the job is called fsck, and usually located in either /system/xbin or /system/bin. Sometimes you need a special variant of it, which might e.g. be called fsck.exfat or the like. So first let's make sure we find the right binary:

cd /system/xbin
ls fsc*

If not found, repeat with /system/bin. I will assume here it was found in the first place, and is simply called fsck (adjust the following correspondingly if that's not the case).

As fsck comes from the "Linux core", we can consult its man page for the syntax. Though there might be some options not working on Android, the most basic ones should. See the linked man page for details (or run a Linux VM and use man fsck in case that page disappears) -- I will stick to the basics here:

First we need to find the device your SD card is bound to. If it's mounted, the mount command will assist us:

mount

That's it, basically: Check the output and see where your SD card sits. Usually this is something using vold, but it's different between devices. Output may include something like /dev/block/vold/179:17 on /mnt/storage/sdcard -- in that case, the first part of my quote is our device. In order to repair the "drive", you need to unmount it first. This can be done via the settings menu, or, as we're just in the terminal, by issuing

umount /dev/block/vold/179:17

Now we can go for the repair job. Basic syntax is:

fsck [options] [-t fstype] <filesystem> [fsoptions]

So we first try the simplest approach and hope fsck figures out everything itself:

fsck -C -r /dev/block/vold/179:17

Which basically means: Show progress (-C), and always ask the user to repair (-r) any errors on /dev/block/vold/179:17. If this does not work out, check with the linked man page for further options.

9
  • 4
    You can also save yourself the cd steps if you want by using ls /system/bin/fsc* and ls /system/xbin/fsc* from whatever your current working directory is. You could even combine the two into one command with ls /system/xbin/fsc* /system/bin/fsc*. Jan 31, 2013 at 16:52
  • 1
    No, I don't confuse things, what I wasn't aware of is that this question is actually about SD card. So yeah, I actually did confuse some things. Well strictly speaking, you can format your SD card as ext as well, so that might apply to people that does that.
    – Lie Ryan
    Nov 9, 2013 at 12:57
  • 1
    Point taken. Though the "average user" (or the one "in doubt") might better stick with FAT, at least for interoperability. At least until ExtFS is supported on the majority of OSs easily and by default without additional drivers required (guess Windows is and will remain a pitfall here, as usual).
    – Izzy
    Nov 9, 2013 at 13:08
  • 1
    Thanks for this answer, I think it is what I need. I got an error on the umount, do you have to be root? Dec 26, 2016 at 13:35
  • 1
    @OrganicMarble yes, of course – for all the above commands, or you don't get access to devices (everything starting with /dev) that way.
    – Izzy
    Dec 27, 2016 at 20:50
5

While other answers are correct (at least partially), just to add some extra notes. On recent Android releases you don't need to run filesystem check manually as vold handles this automatically. See When should I run a consistency check on my removable MicroSD card?

If you want to do this manually, you need a rooted device because it's not possible to access block devices on un-rooted devices. Also you need to un-mount the filesystem before checking for errors. Since Android 6 external SD card is mounted at /mnt/media_rw/[UUID] and then emulated on /mnt/runtime/[VIEW]/[UUID]. A VIEW is then bind-mounted to /storage/[UUID]. See details in How to save files to external SD card?.

After un-mounting SD card fully, run respective fsck.* binary on the block device. Usually init enumerates SD card block device as /dev/block/mmcblk1p* (p* denotes partition number, usually it's only 1) while vold creates another device node in /dev/block/vold/[MAJOR:MINOR]. You need to find the correct block device (may also check by mount | grep /mnt/media_rw before un-mounting filesystem).

For FAT[N] family of filesystems you can use fsck_msdos (or fsck.fat), and fsck.exfat for exFAT. If these aren't built with your ROM (exFAT was closed source until recently, so there could be license issues), you can use external binaries. Or build from (dosfstools or exfat) source code.

To run filesystem check:

~# fsck.exfat /dev/block/mmcblk1p1
2

thank for this, it saves my day :)

root@android:/ # mount | grep -i sdcard
/dev/block/nandk /mnt/sdcard vfat rw,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro 0 0

root@android:/ # /system/bin/fsck_msdos -y /dev/block/nandk
0
1

I've found an app called AParted on the market that can "repair some damaged sdcard and scan for bad blocks" etc.

0

If I'm not mistaken you can force Android to fsck both the internal and external storage on reboot by doing the following depending on your ROM.

run terminal app and type

su
touch /forcefsck

Then reboot.

If your phone is not rooted, this will definitely fail.

Source: XDA Forums - [Q]How to fsck /data or /system?

6
  • What do you mean by "depending on your ROM"? Nov 27, 2015 at 16:37
  • 1
    That trick might not work on all phones. different phones may fail to do anything. Also your phone needs to be rooted.
    – Trekeyus
    Nov 28, 2015 at 17:59
  • Once I've rebooted, how can I know whether or not fsck actually ran or not? Dec 14, 2015 at 8:12
  • 1
    -1. I have downvoted your post. Here's why: I've spent more time looking into the matter. Your suggested technique is probably 100% mistaken. It may deceive readers into thinking that it helps, but the technique actually does nothing. Jun 3, 2016 at 15:00
  • 3
    touch /forcefsck will only work on a device with an init script which checks for the presence of a /forcefsck file. I don't know of one single Android device which has such an init script. So, although your technique will likely work on Debian, Ubuntu, and Mint devices, I highly doubt that it will work on any Android device. If anyone ever finds even one single Android device with an init script which checks for /forcefsck, please let me know! Simply reply to this comment. Jun 3, 2016 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .