I am officially smarter than the Internet

Posted: Fri, 20 December 2013 | permalink | 3 Comments

Yes, the title is just a scootch self-aggrandising, but I’m rather chuffed with myself at the moment, so please forgive me.

It all started with my phone (a regular Samsung Galaxy S3) suddenly refusing to boot, stuck at the initial splash screen (“Samsung Galaxy SIII GT-I9300”). After turning it off and on again a few times (I know my basic problem-solving strategies) and clearing the cache, I decided to start looking deeper. In contrast to pretty much every other Android debugging experience ever, I almost immediately found a useful error message in the recovery system:

E:Failed to mount /efs (Invalid Argument)

“Excellent!”, thought I. “An error message. Google will tell me how to fix this!”

Nope. The combined wisdom of the Internet, distilled from a great many poorly-spelled forum posts, unhelpful blog posts, and thoroughly pointless articles, was simple: “You’re screwed. Send it back for service.”

I tried that. Suffice it to say that I will never, ever buy anything from Kogan ever again. I have learnt my lesson. Trying to deal with their support people was an exercise in frustration, and ultimately fruitless.

In the end, I decided I’d have some fun trying to fix it myself – after all, it’s a failure at the base Linux level. I know a thing or two about troubleshooting Linux, if I do say so myself. If I really couldn’t fix it, I’d just go buy a new phone.

It turned out be relatively simple. Here’s the condensed version of my notes, in case someone wants to follow in my footsteps. If you’d like expansion, feel free to e-mail me. Note that these instructions are specifically for my Galaxy S3 (GT-I9300), but should work with some degree of adaptation on pretty much any Android phone, as far as I can determine, within the limits of the phone’s willingness to flash a custom recovery.

  1. Using heimdall, flash the TeamWin recovery onto your phone (drop into “download mode” first – hold VolDown+Home+Power):

    heimdall flash --recovery twrp.img
  2. Boot into recovery (VolUp+Home+Power), select “Advanced -> Terminal”, and take an image of the EFS partition onto the external SD card you should have already in the phone:

    dd if=/dev/block/mmcblk0p3 of=/external_sd/efs.img
  3. Shutdown the phone, mount the SD card on your computer, then turn your EFS partition image into a loopback device and fsck it:

    sudo losetup -f .../efs.img
    sudo fsck -f /dev/loop0

    With a bit of luck, the partition won’t be a complete write-off and you’ll be able to salvage the contents of the files, if not the exact filesystem structure.

    Incidentally, if the filesystem was completely stuffed, you could get someone else’s EFS partition and change the IMEI and MAC addresses and you’d probably be golden, but that would quite possibly be illegal or something, so don’t do that.

  4. Now comes the fun part – putting the filesystem back together. After fscking, mount the image somewhere on your computer:

    mount /dev/loop0 /mnt

    In my case, I had about a dozen files living in lost+found, and I figured that wasn’t a positive outcome. I did try, just in case, writing the fsck’d filesystem image back to the phone, in the hope that it just needed to mount the filesystem to boot, but no dice.

    Instead, I had to find out where these lost soul^Wfiles were supposed to live. Luckily, a colleague of mine also has an S3 (the ever-so-slightly-different GT-I9300T), and he was kind enough to let me take a copy of his EFS partition, and use that as a file location template. Using a combination of file sizes, permissions/ownerships, and inode numbers (I knew the -i option to ls would come in handy someday!), I was able to put all the lost files back where they should be.

  5. Unmount all those EFS filesystems, losetup -d /dev/loop0, and put the fixed up EFS partition image back onto your SD card for the return trip to the phone.

  6. Now, with a filesystem image that looks reasonable, it’s time to write it back onto the phone and see what happens. Copy it onto the SD card, boot up into recovery again, get a shell, and a bit more dd:

    dd if=/external_sd/efs.img of=/dev/block/mmcblk0p3
  7. With a bit of luck, your phone may just boot back up now. In my case, I’d done so many other things to my phone trying to get it back up and running (including flashing custom ROMs and what have you) that I needed to flash Cyanogen, boot it, and wait at the boot screen for about 15 minutes (I shit you not, 15 minutes of “Gah is my phone going to work?!?”) before it came up and lo! I had a working phone again. And about 27 SMSes. Sigh, back to work…

So, yeah, neener-neener to the collected wisdom of the ‘tubes. I fixed my EFS partition, and in the great, grand scheme of things, it wasn’t even all that difficult. For any phone which (a) allows you to flash a custom recovery and (b) you can find another of the same model to play with, EFS corruption doesn’t necessarily mean a fight with tech support.

Incidentally, if you happen to have an S3 exhibiting this problem, but you’re not comfortable fiddling with it, I’m happy to put your EFS back together again if you pay shipping both ways. It’s about a 5 minute job now I know how to do it. E-mail me.


From: Ross
2013-12-20 10:00

Basically, Android’s “just another embedded system”. First rule of reflash, grab a backup, preferably of a working system, so in lieu of another identical/similar phone, do the EFS dump thing, and leave it somewhere handy (laptop, cloud drive, whatever) This even avoids the need to rebuild the partition, just flash the backup. One of the main reasons to root a phone, in my opinion.

From: Daniel Moerner
2013-12-21 03:36

This guide is a labor of love, thanks for sharing it. I hope I never have to dig through inode numbers to fix my own phone…

From: Matt Palmer
2013-12-22 08:20

Hi Ross, Daniel, thanks for your comments.

Ross: The problem in my case is that I hadn’t actually reflashed anything when it all went pear-shaped. Hence, I never had any reason to backup any part of the system – and even if I had, I had no idea that this EFS partition existed. In fact, one of the problems I had trying to get service was that everyone assumed that I’d been playing with custom ROMs, when in fact the phone was running the stock firmware.

Daniel: Thanks for the kind words. It wasn’t how I would have wanted to spend my time, but it was certainly an educational experience, and there’s no denying I rather enjoy technological puzzles of this sort.

Post a comment

All comments are held for moderation; markdown formatting accepted.

This is a honeypot form. Do not use this form unless you want to get your IP address blacklisted. Use the second form below for comments.
Name: (required)
E-mail: (required, not published)
Website: (optional)
Name: (required)
E-mail: (required, not published)
Website: (optional)