[Nexus 5 General] Alex WS:
Hi everyone,

First of all - apologies if this is in the wrong forum. First time I post something, so not too sure if this is the right place.

I've been struggling with my Nexus 5 for the past 3 days after I attempted a factory reset. After trying everything I could find, I managed to combine some strategies from different threads, and got some help from a friend who is a linux specialist. As it has been REALLY HARD for me to fix this, I thought I would post the solution in case anyone is seeing the same issue.

Summary of my issue:

I attempted a factory reset to cleanup the phone. That was really all I intended to do.

The factory reset got stuck on "erasing". After 30 minutes waiting, I forced the phone to reboot. Then everything went downhill.

My Nexus 5 started bootlooping. It wouldn't even get in recovery mode.

I've flashed ClockWorkMod Recovery, and tried to format everything and start again. The processes to wipe partitions would fail.

Flashing stock also failed, as things would hang on "erasing cache".

I found references on multiple threads about things to try - from flashing other ROMs, to formatting the file system manually, and basically trying every step of a flashing a stock installation manually.

The bottom line is everything would hang because the system could not mount the /data partition.

When I tried to use "e2fsck" to check /userdata partition, it would give me an error about the file system being corrupted, and suggesting to use a different superblock.

Some threads here in XDA suggested to use CWM and TWRP to format the partition, as that would usually fix the problem. It didn't work in my case.

The system would basically hang when trying to format /data, with any method I tried.

When using the "dmesg" command, I would also see lots of errors with superblocks when trying to mount "/data".

I considered it could be a hardware issue, but I was not seeing problems with the other partitions (/cache, /system, /recovery, and so on).

Solution:

I fixed the problem by removing the partition, recreating it with "ext2" file system, then upgrading to "ext4" manually, and finally flashing the system images again WITHOUT flashing userdata.

Every time I flash "userdata", the partition just gets corrupted.

This is the step by step on how I did it:

1) Start the phone on bootloader by holding power button + volume down. Flash CWM recovery through fastboot.

Download CWM recovery from here: https://clockworkmod.com/rommanager

I'm using windows, so I opened a command prompt on the "Android SDK\platform-tools" folder.

run: "fastboot flash recovery <CWM_Recovery_Folder>\recovery-clockwork-6.0.4.5-hammerhead.img"

2) Reboot in recovery mode, so that it would load ADB. In the command prompt I ran "adb shell" so I could use the linux tools

Use "parted /dev/block/mmcblk0" to open the parted tool for the mmc block.

Use command "print" to list all partitions. You should see something like this:

3) Remove the existing data partition by running command "rm 28" .

4) Recreate the partition and the file system with "mkpartfs". I didn't use all parameters at once, but just informed the proper values as requested by the tool:

5) The partition should now be recreated as "ext2" file system. I've set the partition name with:

If you print again, you should see the new partition as ext2 file system:

6) Upgrade the FS from ext2 to ext4 by using make_ext4fs:

make_ext4fs -l 29236371456 -b 4096 -g 32768 -i 8192 -I 256 -j 32768 -L msdos -a /data /dev/block/mmcblk0p28

Now here is the interesting part. When I tried to run "flash-all" from the google stock image, this is what I would see when it ran the format script on the userdata partition:

When I manually ran the make_ext4fs, the only difference was I added a label "msdos" and this was the result:

Almost the same thing, but with a difference in "Inodes per group": stock script shows 8192, and running manually it shows 48.

I have no idea why is that. Honestly I know very little about linux and its file systems, so I don't know what that means.

After I did this, I was FINALLY able to mount the "/data" partition.

8) Checked the file system with e2fsck. It now worked fine:

~ # e2fsck /dev/block/mmcblk0p28

e2fsck /dev/block/mmcblk0p28

e2fsck 1.41.14 (22-Dec-2010)

msdos: clean, 11/10464 files, 45158/7137786 blocks

~ #

9) Manually flash google stock system, cache, boot, and bootloader.

I was using this image: hammerhead-ktu84p-factory-35ea0277.tgz

I uncompressed this to a folder, and also uncompressed the image-hammerhead-ktu84p.zip.

So I ran:

fastboot flash system system.img

fastboot flash cache cache.img

fastboot flash boot boot.img

After this, I rebooted the system and it loaded, after loooooong 3 days reading through everything I could on XDA!

These were some of the threads that helped me in one way or another to get to this solution:

http://xdaforums.com/showpost.php?p=26285877&postcount=12

http://xdaforums.com/google-nexus-5/help/help-nexus-5-bricked-clearing-cache-t2564509

http://xdaforums.com/google-nexus-5/help/stuck-erasing-doing-factory-reset-t2530342

http://xdaforums.com/google-nexus-5/orig-development/nexus-5-f2fs-t2668486

http://xdaforums.com/google-nexus-5/general/howto-repairing-corrupted-data-partition-t2577447

http://xdaforums.com/showthread.php?t=1441928

http://xdaforums.com/google-nexus-5/help/help-nexus-5-bricked-clearing-cache-t2564509

http://xdaforums.com/google-nexus-5/help/help-stuck-bootloop-t2515338

http://xdaforums.com/google-nexus-5/help/stuck-google-logo-recovery-mode-t2898337

I really hope no one else had the same "luck" as I did, since this problem has been a nightmare.

But in case you unfortunately do... hope this helps!