How to recover from a bootloop

Difficulty Level: Intermediate

When experimenting a lot with Android you have a a pretty high chance of getting a bootloop once, but also if you install an other rom and still use the dalvik-cache of the previous rom.
When you have a bootloop, you will notice that the boot process of your phone keeps looping and looping. And it will never stop until you fix the bootloop!
This guide will teach you the common ways of fixing a bootloop,  how to create a custom CWM Fix-Zip and how to use ADB to recover from a bootloop.

Chapters:
Chapter 1: Finding the cause of the bootloop
Chapter 2: Using a CWM ZIP as solution
Chapter 3: Using ADB as solution

Chapter 1: Finding the cause of the bootloop
Bootloops can occur pretty easily,  it’s mainly caused because system files interfering with each other which causes instability and/or crashes at the boot sequence.
Think of system apps that are compiled incorrectly, permissions that are not set correctly, files from other devices and even an init.d script, everything is possible.
To find the cause of a bootloop you have to think about what you did before getting the bootloop.
Choose one of the following reasons that caused the bootloop for you and try out its solution.

– After flashing a new rom

If you flash a new (base)rom on your device it may not automatically wipe your dalvik-cache, This means your old dalvik-cache will be used for the new system files which would result in a bootloop, to fix this problem:

1. Start your phone in CWM Recovery
2. Go to Advanced
3. Choose “Wipe dalvik-cache”
4. Now go to “Mounts & Storage”
5. Choose “Wipe /cache”
6. Reboot your phone

Note: by wiping  “/cache” and “dalvik-cache” you make sure it’s completely deleted, some roms use /data and some use /cache for the dalvik-cache

If the problems still exists after doing that, you could try to wipe your /data partition. before you do that first make a backup of your phone (in it’s current bootlooping state)

1. Start your phone in CWM Recovery
2. Now go to “Backup & Restore”
3. Choose “backup” (it may also be called “backup to internal/external
sdcard)

When that’s done you are free to wipe /data, you can achieve this by doing:

1. Now go to “Mounts & Storage”
2. Choose “Wipe /data”
3. Choose “Wipe /cache”
4. Reboot your phone

If the rom still doesn’t boot correctly it’s probably the rom which isn’t working, contact the rom creator then and try an other rom for the meanwhile.

– After restoring a system only backup

This one is actually the same as the above one, since only /system is restored (advanced restore) there is an incorrect dalvik-cache present which will cause the bootloop. perform the same steps as above to solve the problem.

– After installing a Mod / Theme or UOT Kitchen output

When you install a Mod / Theme or UOT Kitchen output and you get a bootloop, you know there is something wrong with the file that you are installing. This is mostly caused by an incorrect BaseROM of the mod/theme, but can also happen if the creator just didn’t create it properly.
Wiping dalvik-cache won’t be enough to fix this, you will need to open the zip on your computer and look at the files that are installed with the mod/theme. you can do this by looking into the system folder in the zip, there you can find the files that are being installed. for example:

You have installed an Extended Power Menu mod but it causes a bootloop, here is what you do:

1. Open the installation zip with Winrar (Extended Power Menu in this case)
2. Now look inside the “system” folder, in my case I found the framework folder inside the system folder
3. The framework folder contains: android.policy.jar & framework-res.apk, so these are the suspicious files.
4. What you simply do, is searching for the original files (from your (base)rom) and drag them into the framework folder (inside winrar)
5. Now it will ask for a compression level, choose “Store” and the archive will be done in seconds.
6. You will need to put the file on your external sdcard using the “Mount USB Storage” option in CWM under “Mounts & Storage”
7. Install the zip just as you did with the mod, you should now be bootloop free, if not reinstall the zip with a mounted /system (Mounts & Storage > Mount /system) (and you can optionally wipe /cache and /dalvik-cache, this will never harm any file/setting.

To acquire the files:
- If you have a custom rom installed, you can download the rom zip at the XDA-Developers rom page and get the needed files
- If you have a stock rom you should look in the forum of your device, and look for a tutorial on how to extract the base rom.

Note: Some CWM version will  mount your external sdcard only, if you don’t have an external sdcard then you will need to use “adb” as solution

– After setting wrong permissions

Android is very dependent on the right permissions, if you adjust file permissions incorrectly you could get a bootloop, giving a file to less permissions would break it, but also giving a file to much permissions would break it. most common permissions of system files are:

- 644 (RW-R-R) – (this is best known system permission, it exists in /system/app, /system/framework, /system/etc, /system/lib and allot of separate files)
- 755 (RWX-RX-RX) – (mainly used for /system/bin, only files that have to be executed are 755 or higher.)
- 777 (RWX-RWX-RWX) – (used for scripts inside /system/etc/init.d and busybox files)

An easy fix is performing the “Fix permissions” option in CWM under Advanced. be sure to mount the partitions before running the fix. Although this doesn’t cover all permissions. have a look at the CWM or ADB chapter to find the solution.

Chapter 2 Using a CWM ZIP as solution

Using the original cwm zip (of the mod)  is the easiest way, since the zip is already created for you, you only need to replace the files with the original rom files. Earlier in this tutorial you acquired the files from your rom.
Once you got the same files as present in the original CWM zip you can easily drag em into the archive, then choose “store” as compression level, easy as that.  Now finally you need to put it on your sdcard and install it.

Note: This tutorial explains “edify scripting”, which the Android Kitchen you can convert it easily to “amend scripting” if needed.

If you can’t get the file on your sdcard because you don’t have an external sdcard or you can’t reach your internal sdcard (which is very likely when you have a bootloop), you can use ADB to push the zip to your phone, read about how to use ADB in Chapter 3.

Commands for updater-script (located in CWMFIX.zip/META-INF/com/google/android/)

Mount & Install

To mount the system partition:
Note: This way it’s safe for all devices, it also requires the busybox binary to be present in the root of the zip file.

package_extract_file(“busybox”, “/tmp/busybox”);
set_perm(0, 0, 0777, “/tmp/busybox”);
run_program(“/tmp/busybox”, “mount”, “/system”);

To extract the system folder in your zip:
package_extract_dir(“system”, “/system”);

Setting Permissions

To set permissions of an individual file:
set_perm(0, 0, Mod, “File here”);

A working example:
set_perm(0, 0, 0644, “/system/build.prop”);

To set permissions of a directory:
set_perm(0, 0, Mod, “Dir here without a trailing slash”);

A working example:
set_perm(0, 0, 0755, “/system/etc”);

Setting Permissions Recursively

To set permissions to all files inside a directory (resursive):
set_perm_recursive(0, 0, 0755, Mod, “Dir here without a trailing slash”);

A working example:
set_perm_recursive(0, 0, 0755, 0777, “/system/etc/init.d”);

Chapter 3 Using ADB as solution

ADB can be used to access the phone while booting, be aware that some bootloops make it unable to use ADB since they do not go further then the manufacturer logo. (In new CWM versions it’s possible to use adb)
The only tricky part about using ADB with bootloops is that you have to do it on the right time, this is different from every device, but normally it’s after the manufacturer logo that the partitions get mounted.  The easiest way to enter your phone in this part is using a batch script that monitors the state of your device and connects directly when possible.

I use this script for example, called ondemand.bat (requires adb.exe and the 2 dlls)

Linux Version (ondemand.sh):

This script will wait for the device to become ready, when it’s ready it freeze the device, so the script has more time to push the file (instead of keep rebooting). Then it will push the specified cwmfix zip to your sdcard, and after that it will reboot in recovery so you can install the cwm fix you made. You can also make an batch script that pushes the files automatically to your phone, here is an example:

Linux version:

This script will wait for the device to become ready, when it’s ready it freeze the device, so the script has more time to push the file (instead of keep rebooting). Then it will push framework-res.apk and SystemUI.apk to the directory it belongs to, after that it changes the permissions of the files to RW-R-R (644) and then it will reboot.

Please note that on some devices the command “su -c” cannot be used after using the “stop” command, it gives an error then (Segmentation Fault).
What you can do to prevent this is adding “adb remount” just under the “adb wait-for-device” line, and remove the  “adb -d shell su -c “mount -o remount rw /system” line.
Save the script and run it again.

You are probably able to fix your bootloop with this guide, in some rare cases some other partitions could be damaged, then I advice you to install the stock rom (which is no .zip in most cases)
Once you master the fixing of bootloops you can fix your phone independently !