[Nexus 5 Q&A, Help & Troubleshooting] hongkongking:
Symptoms:

Phone stucks at boot animation screen (4 color balls rolling)

adb devices command shows device is represent.

adb logcat shows no fatal error, no obvious cause

kernel message shows no fatal error

Cause:

Content inside /data/system/sync is corrupted(?)

Fix:

Rename or remove folder /data/system/sync

Below is the full story and how I figure it out:

3 days ago when I woke up, i find that my phone was rebooting and the screen showing boot animation. After waiting a long time, I find that the phone was stuck on boot animation. I can use adb shell to connect the phone and adb logcat to retrieve the log. The log shows nothing special or fatal, just some minor errors.

My phone is rooted, unlooked and relocked bootloader, CWM Recovery 6.0.4.4

The apps I installed that have root access included, but not limited to:

Xposed Framework​

Android Tuner aka 3C Toolbox​

GravityBox​

iFont​

Xprivacy​

Greenify​

AFWall+​

BusyBox​

SuperSu​

com.avast.android.mobilesecurity​

com.avast.android.antitheft (Root install)​

After Googled a few hours, 99.9% of the result tell you factory reset your phone is the fix, and i am not satisfied with that. So I used CWM recovery to made a complete backup, and tinkering with the files and system.

At first I cleared cache and dalvik-cache in recovery as this is easiest, but no luck.

Then I suspect this might be a flash memory chip problem , so I boot into recovery, use adb shell to connect console, however, adb shows that device unauthorized, so I do a factory reset and reboot recovery, then adb shell again and success, and in recovery, restore /data backup. Then I use command

%path to android platform tools folder%> adb push adbkey.pub /data/misc adb/adb_keys

, then adb is authorized after reboots.

To check if the flash memory is okay, i used the command:

e2fsck -fv /dev/block/platform/msm_sdcc.1/by-name/persist
e2fsck -fv /dev/block/platform/msm_sdcc.1/by-name/cache
e2fsck -fv /dev/block/platform/msm_sdcc.1/by-name/userdata
e2fsck -fv /dev/block/platform/msm_sdcc.1/by-name/system

The result seems fine, and no signs of hardware failure.

After reading logcat, the system seems nearly finished the booting process, and stucked at end of System service, and never signal Boot_Completed. Using Android Device Monitor, system_process main thread is still running and doing something unknown.

At this point, i think kernel and /system should be normal.

Then I suspect that the apps i installed might be the cause, I renamed the folders like:

mv /data/data /data/data.old
mv /sdcard/Android /sdcard/Android.old
mv /data/app /data/app.old

to see if the OS can boot normally, but no luck.

I also renamed many other app folders and reboot, but none of this can solve the bootloop problem.

Then I renamed /data/system and reboot, from the logcat, i can see the system is regenerating the content inside the system, and I waited for a moment, the OS booted successfully with many "xxx process stopped" error message on the screen. So at this moment I realized that content in /data/system might be the root of all evil. As Home screen is not usable with a lot of process stopped messages, I used this command to start the apps i want.

adb shell monkey -p com.yourpackage.name -c android.intent.category.LAUNCHER 1

(Need to use some game points;) )

Next I used command

find /data/system -mtime -3

to find out which files were altered within last 3 days. I get a list of files and folder and then I rename the folders one by one and reboot. Finally, /data/system/sync folder is confirmed as the cause of the problem.

I restored the full backup in recovery, and renamed the /data/system/sync folder to /data/system/sync.old and reboot. Phone boots normally, everything seems fine.

I don't know what, why, how exactly causing the boot problem, but the problem is solved anyway. Hope this information can help someone.

I used 40+ hrs to figure it out, and another 2+ hrs to summarize and write this.

fxxk.:eek: