[Defy General] SkUrRiEr:
Potential fix for low battery => failure to boot issue

(posting this here as I'm a nooooooob, I'd really love this to be in the developer thread for the ROM, but I'm too new.)

I recently recovered my phone from a low battery related failure to boot where it hit the bootup animation and was "stuck" there - i.e. it wouldn't proceed past that.

These instructions will most likely

not

work for you, and are intended for people who know what they're doing. I cannot be responsible if you destroy your phone's data using this, erase all your backups and have to wipe it completely to recover.

PLEASE READ ALL THE INSTRUCTIONS BEFORE ATTEMPTING THIS WITH YOUR PHONE. FOLLOWING THESE INSTRUCTIONS IS DANGEROUS. YOU HAVE BEEN WARNED.

I'm posting these here for that one person who does this and ends up with a working phone. If you don't know what you're doing, are confused at any point, or feel concerned about what you're doing, DO NOT DO THIS, just wipe your /data directory and start over. It's a

much

better option. Really.

Firstly, if you just want to wipe your phone and start over:

Load the custom recovery through the boot loader (down when the indicator light goes blue, select custom recovery)

Wipe /data

Reboot

I'd recommend wiping /system and re-installing your ROM and Gapps after this, but that's up to you. (See the first set of steps below)

If you're going to do the entire thing, and likely spend at least a day on this, then follow

all

the procedures below.

= = = = = = = = = = =

Wipe /system and re-install your ROM:

Firstly, we're going to ensure that the files in /system aren't at fault.

Load up the boot loader

Share the SD card over USB

Connect the phone to your computer

Copy the build of CM10 you're using to the phone

Copy whichever build of Gapps you're using to the phone

Safely remove the SD card from your computer

Boot into custom recovery

Wipe /system

only

Install CM10 build

Install Gapps

Wipe /cache and the Dalvik cache

Reboot phone

If the app optimisation screen doesn't appear, then you have problems more serious than these instructions can solve. Your only solution will be to wipe /data and start over.

If your phone boots now, pat yourself on the back and go tell your friends how awesome you are.

If it gets stuck at "starting apps" and you don't want to continue this, wipe /data and start over.

If you want to continue:

Start adb logcat (see information below)

Check that it's not booting (again, see below)

If it's definitely not booting, pop the battery and continue below.

= = = = = = = = = = =

Slow and painful /data recovery:

This is going to take all day, generally be a pain, require a lot of thought and effort on your part and make you wish you'd never let your phone's battery run down in the first place. (I'm properly paranoid now.) It is also, by design, not going to recover

everything

, but it should get you something that is almost what you had.

Firstly:

Make sure your phone is fully charged.

Make sure you have a brand new, fresh backup of your /data partition.

Make sure you can get the debug messages on your computer. I.e. install adb, ensure that it detects your phone and you can use "adb logcat" to view debug messages.

Make sure you can get into the boot loader (press down when the Motorola logo is displayed and the indicator light is _blue_

Make sure you can get into custom recovery through the boot loader (find and test the "custom recovery" option in the boot loader)

Make sure you can read and write to /data on your computer. You will probably need a working Linux install which can access a USB port. I recommend Linux Mint or Fedora. (check writing by creating a file called something like "tmp.x" which won't be used by Android. Don't overwrite an existing file.)

Double check that it's fully charged.

(ADB help: Just leaving your phone plugged in didn't work for me, I found that keeping it unplugged while it booted then plugging it in as soon as the boot animation started was the most reliable way to make it work.)

About logcatting your phone. This is more a way to speed up the process than a required part of the procedure. If your phone is booting properly, you'll see lots of varied messages about all kinds of stuff. If it's "stuck" like mine was, you'll see a "memory usage" message from Dalvik every so often, and

nothing else

. I concluded that if I waited for ~10-20 iterations of this and

nothing else

and the numbers didn't change, the phone was "stuck" and I would pop the battery and try again.

Warning:

If you randomly delete or change files in /data without knowing what you're doing and having a backup, you

will

break things and your phone will

not work properly

.

Before we start, we need some data:

The number of apps installed on your phone. You noted that above. This is to ensure that your user profile data is "safe" - i.e. if there are missing apps, then something has gone wrong.

A list of all the files and directories in the top level of /data

The list of files and directories can be retrieved by:

Booting your phone

Loading the bootloader

Sharing /data over USB

Mounting it on your computer

Noting all the file and directory names

I wrote the list so it looks like this:

[ ] filename.ext
[ ] filename.ext
[ ] directoryname

When I fixed my phone, it was the sync settings in /data/system which were corrupted. Deleting the contents of the /data/system/sync directory fixed my phone, however I lost all my sync settings and it took a while (10s of minutes) for all of the sync options to be re-populated. I'd recommend that you try deleting that directory as your first attempt at the procedure below and if that doesn't work, continue onwards.

We're going to assume that there is a small number of corrupt files on your phone, and these files are causing it not to boot.

How we're going to find those files is to do a binary search through the files and directories in /data with the goal of finding ever smaller sets of files and directories which, when deleted, allow your phone to boot.

There are a lot of directories and files which have "no" effect on the system, things like caches, logs, panics, tombstones, hardware configuration, etc. and these are either only written to (by default) or are automatically replaced if they go missing. If you see any files or directories which look like they might be this, try using those files in one of your first passes, just to get them out of the way.

There are also some directories which are essential, e.g. app, user, etc. We will try not to delete these unless there is _no_ other choice - deleting "user" in particular can cause it to boot properly, but without any user info, which means that you won't actually have any of your settings or apps when it boots.

Each time we delete files or get a result, we're going to record what happened and which files were involved. Good organisation will make this work well, if you're disorganised here, you'll probably miss that one file which is breaking your phone.

The way I recorded the result was to mark each file with a "P" when I'd deleted it and was checking whether that fixed it, a "X" if deleting it had no effect (i.e. it still wouldn't boot), and a "?" if it booted but was not "right", or "!!!!" if deleting it allowed the phone to boot "right". (I continued at this point because I wanted to ensure that I lost as little data as possible by deleting the smallest number of files possible.)

I describe "right" as:

The expected number of apps are optimised

The phone boots to the lock / home screen

These screens are exactly how you remember them looking

Note

: Even if your phone boots properly and everything looks correct, it may not connect to your mobile network if you had to change the baseband at any point. Setting the baseband back to how you had it before will fix this. (e.g. my phone believes it's in Italy, so I need to set it to Australia/Optus to connect to the mobile network here.)

I chose which set of files to delete by choosing approximately half of the unmarked files or if there were no remaining unmarked files, half of the files where deleting them caused the phone not to boot "right".

You should aim to have all files in a directory except a couple marked as not fixing it before you continue into subdirectories.

My first pass looked only at files and directories in the top level of /data. I was able to narrow the problem down to a single directory ("system") in /data, however it wouldn't boot "right", so I produced a list of files in that directory and started all over again. I was then able to narrow it down to the "sync" directory in /system. I determined that deleting the contents of that directory was enough to allow the phone to boot. I lost my sync settings, and it took ~10-20 minutes for the sync data to be re-populated, but it was worth it for a working phone.

The procedure is this:

Boot to custom recovery

Resore the backup of your /data partition

Wipe /cache and the Dalvik cache

Reboot into the boot loader

Share /data over USB

Connect the phone to your computer

Delete a carefully selected set of files (procedure above)

Record which files you deleted (essential)

Safely remove the phone from your computer

Reboot

Check whether it booted properly (either wait or use adb logcat as described above)

Record whether it booted "right" or not (essential)

Reboot or pop the battery depending on whether it made it into Android proper.

This took me all day, even with the heavily streamlined procedure above, and I was able to recover my phone to approximately 99% of what I had before it broke. I sincerely hope I never have to have to do this again.