[Nexus 5 Android Development] cadbomb:
I wanted to share an experience I had tonight, and I'm not sure why it happened, nor do I probably have the logs for it, but it managed to break my /data partition. I ran into the "Error mounting /data!" and "E: Unable to mount /data" issues after a hung flash of a new ROM (Purity). Not entirely sure why, as I was forced to hard-reboot after about 30 minutes of waiting on the "Writing system..." portion of the installation.

So I thought, well, let me boot to another recovery. So I booted to fastboot and flashed TWRP. Well, TWRP wanted a password to decrypt... Since I know I've never encrypted my data partition, I know I have a real problem. I tried fastboot to the latest CWM, same issue with mounting /data. So I go back to Philz since nothing is able to mount or format /data or dalvik.

Long story short, after a couple hours of tinkering (surprised at the lack of documented guidance information on this topic) and no backups of nearly 700 pictures and several GB of other data (yeah, I know... But I don't like sharing everything with Google :eek:), I managed to repair my /data partition and mount it manually in ADB. I've seen this issue reported a few times, and in most cases people do a full reflash of the stock firmware to rebuild the partitions. This was simply not an option for me, as I needed to recover my data. I come from a very technical background in Windows as a technical lead in my company (and I still don't make regular backups of my data :silly:), with some tinkering in MacOS and Linux - mainly Arch.

Long story short, I wanted to post the steps I took to recover, just in case this might help someone else down the road. YMMV, but this worked for me!

1. Make sure you have the ADB drivers installed for your OS. If you don't know how to do this, please search!

2. Boot into FASTBOOT on your phone. In a command prompt/terminal, browse to the location of your fastboot exectuable/binary. Enter 'fastboot flash recovery <philz_recovery.img>' (Since I used Philz for this purpose, I am not certain that other recoveries will work directly with ADB. Please use Philz recovery for the purpose of this guide.)

3. Boot into Philz recovery and ensure you are able to see the device in ADB. (Browse to the location of the ADB executable/binary and use the 'adb devices' command. You should see '<serialnumber> recovery' reported. If not, double check your driver installation!)

4. Enter 'adb shell' to access the root shell from the command prompt/terminal. You should now be at a '~#' screen. From here you have full access to the Android terminal as SU. Let's try to repair...

5. The 'mount' command is what I used to determine the location of the partitions. I referenced the /cache partition that automounted in recovery to determine this location. The partition containing /data, /data/media (sdcard) and the dalvik cache is: /dev/block/platform/msm_sdcc.1/by-name/userdata.

6. Attempts to mount the partition will fail (or they did for me) with "invalid arguments" or something similar. What we need to do is run a filesystem check. This is accomplished by running the following command: e2fsck /dev/block/platform/msm_sdcc.1/by-name/userdata

(you will want to press (y) or hit [Enter] to repair each item as it lists them.)

7. Once the process is complete, you can attempt to mount your partition. This is accomplished by typing the command: mount /dev/block/platform/msm_sdcc.1/by-name/userdata /data

8. You can now browse your /data partition through the shell. This is a read-only mount, as no options are specified. To mount R/W, please enter 'mount -?' in the shell.

Apologies for the brevity. It's 2:30am for me, and I've gotta get up for work in a few hours! This is probably a more advance-level guide, so for you newbs out there, please use with caution. I AM NOT RESPONSIBLE FOR WHAT ISSUES YOU MAY ENCOUNTER WITH THIS METHOD!!! Now that that's out of the way, if anybody feels like taking the time to clean this up a little, by all means, please do.

I highly recommend using this for data recovery purposes only. There's no telling what kind of errors you may encounter if you try to flash a new ROM after cleaning a dirty partition. You can do this by exiting the shell with 'exit' and using 'adb pull /data/media/0 <backup_folder_path_on_your_pc>' to copy all of your SDCARD data so you can perform a complete wipe.

I hope this is able to help someone. I'm going to bed now. Have a good night/morning!