42

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.

Is there any tool or app for checking SD cards for drive errors and fixing the same from within the android itself?

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

  • Have you tried with a terminal app, doing a su and running the /system/bin/fsck.exfat? – Izzy Jan 31 '13 at 15:58
  • @Izzy Gives me No such file or directory – Irfan Jan 31 '13 at 16:06
  • Check different locations, maybe it's in /system/xbin instead? Try cding into the directory, and ls fsc* to check what's available. Must be somewhere :) – Izzy Jan 31 '13 at 16:11
  • 1
    Exactly. Busybox tries to be as slim as possible. Try aunt Google with "man mount", works fine :) And see my answer below. If something's unclear, comment there (or see me in chat -- though I won't be available there for the next few hours, there are still other knowing members to help you out :) – Izzy Jan 31 '13 at 16:39
  • 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. – Code Bling Jul 8 '15 at 4:46
17

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.

  • 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*. – eldarerathis Jan 31 '13 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 '13 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 '13 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? – Organic Marble Dec 26 '16 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 '16 at 20:50
3

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
  • Thank you for posting this answer, it helped me tremendously. From the accepted answer I didn't know how to fix a vfat filesystem. Upvoted. – Organic Marble Dec 27 '16 at 20:42
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.

  • Thanks for the upvote on this long-forgotten answer. Should probably be a comment, but I probably didn't have the reputation for that at the time. I'll leave this here for now until the comment gets upvoted and is visible. – Code Bling Jul 8 '15 at 4:49
  • I've upvoted your comment. – unforgettableid Nov 27 '15 at 16:37
  • @unforgettableid Thanks, just want to make sure that everyone knows about this risk. It really sucks to lose data. – Code Bling Nov 27 '15 at 17:17
  • OK, so now that the comment has been upvoted, you can delete this answer. :) – unforgettableid May 30 '16 at 18:50
  • @unforgettableid will leave both for now, for visibility – Code Bling Jun 6 '16 at 23:06
1

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

https://play.google.com/store/apps/details?id=com.sylkat.AParted&hl=en

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: http://forum.xda-developers.com/showpost.php?p=57027579&postcount=20

  • What do you mean by "depending on your ROM"? – unforgettableid Nov 27 '15 at 16:37
  • 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 '15 at 17:59
  • Once I've rebooted, how can I know whether or not fsck actually ran or not? – unforgettableid Dec 14 '15 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. – unforgettableid Jun 3 '16 at 15:00
  • 2
    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. – unforgettableid Jun 3 '16 at 15:00

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