Modifying your Android device by rooting and flashing custom software can significantly enhance its capabilities, but it also carries risks. This guide provides a comprehensive overview of the process, updated for accuracy and clarity.

Rooting an Android phone involves gaining "superuser" privileges, allowing you to access and modify parts of the system that are normally restricted. This enables you to install custom software, remove bloatware, and customize your device beyond what's typically possible.

At a fundamental level, Android devices have a storage space (disk) divided into several partitions. One partition holds the Android system files, while others store app data, recovery environments, and the bootloader.

Disclaimer: Modifying your device as described in this guide carries inherent risks. Improper steps can lead to data loss or even render your device unusable (bricking). Proceed with caution and ensure you understand each step. You are solely responsible for any damage that may occur to your device.


The Android Modification Workflow

By following these steps carefully and researching specific requirements for your device, you can successfully modify your Android phone and enjoy the benefits of custom software.

The process of rooting and flashing custom software generally follows these steps:

  1. Preparation: Gather necessary files and set up your computer.
  2. Enable USB Debugging: Allow your computer to communicate with your phone.
  3. Install USB Drivers: Ensure your computer recognizes your device.
  4. Set up Fastboot & ADB: Install command-line tools for device interaction.
  5. Backup Your Data: Crucial for preventing data loss.
  6. Unlock Bootloader: Essential for flashing custom software.
  7. Install Custom Recovery: Replace the stock recovery with an enhanced version.
  8. Boot into Recovery: Access the custom recovery environment.
  9. Backup Existing ROM (Nandroid Backup): Create a complete system backup.
  10. Wipe Data Partitions: Prepare your device for a clean installation.
  11. Install Custom ROM: Flash a modified version of Android.
  12. Install External Kernel (Optional): Flash a custom kernel for performance/battery enhancements.
  13. Install GApps (Optional): Install Google Play Services and other Google apps if not included in the ROM.
  14. Restore Data: Restore your applications and user data.

Step 0: Preparing to Modify Your Phone

This guide is primarily geared towards Windows users.

  • Mac Users: Instructions are very similar. Install packages the same way. All ADB/Fastboot commands may need to start with adb-mac (no quotes) rather than adb (no quotes), or potentially ./adb depending on your setup.
  • Linux Users: Due to the vast amount of Linux distributions, instructions for setting up ADB/Fastboot will vary. Once set up, all commands will typically begin with ./adb (no quotes) or ./fastboot (no quotes).

Step 1: Download All Necessary Files

Before starting, gather all the files compatible with your specific device and ensuring they are compatible with each other. This includes:

  • Custom Recovery: Such as TWRP (Team Win Recovery Project) or ClockworkMod (CWM). TWRP is generally more recommended due to its modern interface and features.
  • Custom ROM: The modified Android operating system you want to install.
  • Custom Kernel (Optional): If you wish to use a kernel different from the one included in your ROM.
  • Google Apps (GApps) (Optional): A package containing Google Play Services and other Google applications if the custom ROM does not include them.

Important Considerations:

  • Device Compatibility: Always download files specifically designed for your phone model. Installing incompatible files can lead to a bricked device.
  • ROM/Kernel/GApps Compatibility: Ensure the ROM, kernel (if applicable), and GApps package are compatible with each other and the specific Android version you are targeting. Check the developer's notes or ROM threads for this information.

Recommended File Renaming for Simplicity:

  • Recovery image: recovery.img
  • Superuser package (for rooting): SU.zip (often included with custom ROMs or flashed separately like Magisk)
  • Custom ROM: update.zip (or a more descriptive name like rom_version_date.zip)
  • Custom Kernel: kernel.zip
  • Google Apps: gapps.zip

Step 2: Enable USB Debugging

USB Debugging allows your computer to send commands to your Android device.

  1. Open the Settings app on your device.
  2. Navigate to "About phone." (On some devices, this might be under "More" or "General.")
  3. Scroll down to "Build Number" and tap it 7 times rapidly.
  4. You'll see a message like "You are now a developer!" or "Developer mode has been enabled."
  5. Go back to the main Settings menu. You'll now see a "Developer options" sub-menu at the bottom of the screen; tap on it.
  6. Find the "USB Debugging" checkbox or toggle and enable it.
  7. Connect your device (while it's still on) to your PC, preferably using a USB 2.0 port for better compatibility.
  8. When reconnecting, your device may prompt for additional confirmation: "The computer's RSA key fingerprint is '*******'. Always allow from this computer?" Select "Always allow from this computer" and tap "OK."

As soon as you enable debugging mode, your PC might detect a new USB device and attempt to install drivers automatically through Windows Update. If successful, you might be able to skip the next step (Step 3).


Step 3: Installing USB Drivers

Correct USB drivers are crucial for your computer to communicate with your phone in both normal and fastboot modes.

Automatic Installation (Preferred):

  • After enabling USB Debugging and connecting your device, Windows might automatically install the necessary "Android ADB Interface" driver. Check your Device Manager for successful installation.

Manual Installation (If automatic fails):

  1. Open Device Manager on your PC (Search for it in the Start menu or navigate via Control Panel > Device Manager).
  2. Connect your device to the PC.
  3. Look for your Android device in Device Manager. It might appear with a yellow exclamation mark or under "Other devices."
  4. Right-click the Android device and select "Update Driver" or "Install Driver."
  5. Choose "Browse my computer for driver software."
  6. Select "Let me pick from a list of available drivers on my computer."
  7. Scroll down and select "Android Bootloader Interface" or a similar Android device driver (e.g., specific to your device vendor like "Samsung Android ADB Interface"). If you downloaded a specific driver, select "Have Disk" and browse to the android_winusb.inf file within the driver package.
  8. Ignore any warnings about unsigned drivers and proceed with the installation.

Troubleshooting Driver Issues:

  • PDAnet Drivers: If the above methods don't work, consider installing PDAnet, which often includes universal ADB drivers. Uninstall any previously attempted driver installations before trying PDAnet.
  • Device-Specific Drivers: Many manufacturers provide their own USB drivers. Search for "[Your Device Name] USB Drivers" online.
  • Reboot: After installing new drivers, it's often necessary to reboot your computer for the changes to take effect.
  • Toggle USB Debugging/MTP: Try enabling and then disabling "USB debugging" and "MTP Storage Mode" on your phone to prompt driver detection.
  • Multiple Phones: If you've connected multiple Android phones to your PC, driver conflicts can occur. Ensure you are updating or selecting the correct driver specifically for the device you are currently working with.

Step 4: Set up Fastboot & ADB

ADB (Android Debug Bridge) and Fastboot are command-line tools provided by Google that allow you to communicate with your Android device from your computer. They are primarily distributed as part of Android Studio or Standalone SDK Platform Tools.

Installation (Windows - Recommended):

The easiest way to install these tools system-wide is to use a simplified installer:

  • ADB Installer 1.4.3 (or later): Search for "ADB Installer 1.4.3 XDA" to find the latest version. This small program quickly installs both ADB and Fastboot files on your PC (system-wide) along with proper drivers.

After Installation:

To use ADB and Fastboot, you generally need to open a command window (Command Prompt or PowerShell) in the directory where adb.exe and fastboot.exe are located. If you used a system-wide installer, you can open a command window from any location.

Testing ADB Connectivity:

  1. With your phone powered on, unlocked, and connected to your computer with USB Debugging enabled, open a command window.
  2. Type the command: adb devices
  3. You should see an output similar to:
    List of devices attached
    XXXXXXXX…… device
    
    (Where "XXXXXXXX" is your phone's unique ID.)
  4. If you see "waiting for device" or "no device found," it indicates a driver issue. Revisit Step 3: Installing USB Drivers.
  5. For a comprehensive list of ADB commands, search for "ADB commands list."

Understanding Fastboot:

Fastboot is a more powerful tool than ADB, used for flashing images to specific partitions (like recovery, boot, or system) and interacting with the bootloader. It only works when your device is in bootloader/fastboot mode.

Booting into Fastboot Mode:

There are two primary ways to enter fastboot mode:

  1. Using ADB (if your phone is on and connected): Open a command window and type: adb reboot bootloader
  2. Using Device-Specific Key Combinations:
    • Power off your device completely.
    • Hold down a specific combination of physical buttons (e.g., Volume Down + Power button, or Volume Up + Volume Down + Power button) until you see the fastboot screen (often with a rabbit or Android logo and text indicating "Fastboot Mode").
    • If you're unsure of your device's combination, search online for "how to fastboot [your device name]."

Testing Fastboot Connectivity:

  1. Once your device is in fastboot mode, connect it to your PC.
  2. Open a command window and type: fastboot devices
  3. You should see an output similar to:
    XXXXXXXX…… fastboot
    
    (Where "XXXXXXXX" is your phone's unique ID.)
  4. If you see "waiting for device" or "no device found," or if Device Manager shows a yellow exclamation mark, it means fastboot drivers are not properly installed. Revisit Step 3: Installing USB Drivers.
  5. For a comprehensive list of Fastboot commands, search for "Fastboot commands list."

Exiting Fastboot Mode:

  • From the command window, type: fastboot continue or fastboot reboot
  • Alternatively, you can usually hold down the power button for an extended period (10-15 seconds) to force a reboot.

Step 5: Backup Your Data

Important: Unlocking the bootloader (Step 6) will perform a factory reset on most devices, erasing all data from your internal storage. It is absolutely critical to back up your data before proceeding.

Recommended Backup Methods:

  1. PC Transfer: Manually copy all important photos, videos, documents, and other files from your phone's internal storage to your computer.
  2. Cloud Services: Ensure your contacts, calendars, and other synchronized data are backed up to your Google account or other cloud services.
  3. SMS/Call Log Backup Apps: Use a third-party app (e.g., SMS Backup & Restore from the Play Store) to back up your text messages and call logs to your cloud storage or SD card.
  4. Titanium Backup (Requires Root - For later restoration): While you don't have root yet, once you do, Titanium Backup is an excellent tool for backing up apps and their data. Do NOT attempt to restore system apps or data from a different ROM with Titanium Backup as this can cause instability.

Step 6: Unlock Your Bootloader

The bootloader is a low-level program that initializes your device's hardware and starts the operating system. Manufacturers typically "lock" the bootloader to prevent unauthorized modifications. Unlocking it is necessary to flash custom recovery and ROMs.

Unlocking Methods Vary Wildly by Device.

  • Generic Fastboot Unlock (Common for many devices):
    1. Boot your device into Fastboot Mode (refer to Step 4).
    2. Connect your device to your PC.
    3. Open a command window.
    4. Type the command: fastboot oem unlock
    5. Your phone's screen may display a confirmation prompt. Use the volume keys to navigate and the power button to select "Yes" or "Unlock the bootloader."
    6. The device will then perform a factory reset and reboot. This can take several minutes.
  • Manufacturer-Specific Methods: Many manufacturers (e.g., Motorola, HTC, Sony, Xiaomi) require you to obtain an unlock key from their developer websites. This usually involves registering your device and receiving a unique code that you then use with a fastboot oem unlock [code] command.
  • Exploits/Tools: Some devices, especially those with encrypted bootloaders or carrier-locked models, may require specific exploits or third-party tools to unlock. Research extensively for your specific device model.

Time & Cost:

  • Time: Unlocking the bootloader itself typically takes a few seconds to a few minutes after initiating the command. The research to find the correct method can vary from minutes to several hours, depending on your device's popularity and manufacturer policy.
  • Cost: Generally, unlocking the bootloader using standard methods is free. Some paid third-party tools might exist for specific, difficult-to-unlock devices, but these should be approached with caution.

Step 7: Install a Custom Recovery

A custom recovery (like TWRP) replaces the stock recovery, offering advanced features such as flashing unsigned zips (custom ROMs, kernels, GApps), creating full system backups (Nandroid backups), and wiping partitions.

  1. Copy Recovery Image: Place the recovery.img file (which you renamed in Step 1) into your Fastboot folder on your PC.
  2. Boot into Fastboot Mode: Ensure your device is in Fastboot Mode and connected to your PC (refer to Step 4).
  3. Flash the Recovery: Open a command window in your Fastboot directory and type: fastboot flash recovery recovery.img
    • This command flashes the recovery image to your device's recovery partition.
  4. Reboot (Optional but Recommended to Test): After flashing, you can immediately test the new recovery.
    • Type: fastboot reboot (This will reboot your device into the normal OS).
    • Or: fastboot reboot recovery (This will immediately boot into the newly flashed recovery).

Step 8: Booting into Recovery

Accessing the custom recovery environment:

  1. Power off your phone completely.
  2. Use Device-Specific Key Combination: Hold down the specific combination of physical buttons (often Volume Up + Power, or Volume Down + Power, or a combination of all three) that your hardware vendor specifies to boot into recovery mode. This combination is typically different from the fastboot combination.
  3. Using ADB (if your phone is on and connected with ADB enabled): adb reboot recovery

Once in recovery mode, you should see the custom recovery's interface (e.g., TWRP's touch-enabled menu). If you see a green Android with an open chest and an exclamation mark, or no menu at all, it indicates the custom recovery was not flashed correctly or your device is booting into the stock recovery. In this case, re-verify your steps from Step 7.


Get Root Privileges (Magisk)

"Root" provides superuser access to your device's file system. The most common and recommended method for gaining root access today is via Magisk. Magisk is a "systemless" root solution, meaning it modifies the boot image without altering the system partition, making it easier to receive OTA updates and pass Google's SafetyNet checks (which are used by some apps to detect rooted devices).

Installation Process (General):

  1. Download Magisk: Download the latest Magisk .zip file from the official Magisk GitHub repository to your phone's internal storage or SD card.
  2. Boot into Custom Recovery (TWRP): Refer to Step 8.
  3. Flash Magisk: In TWRP, tap "Install," navigate to the downloaded Magisk .zip file, and swipe to confirm flashing.
  4. Reboot: After flashing, tap "Reboot System."
  5. Install Magisk App: Once your phone boots, install the Magisk app (it might be automatically installed after flashing the zip, or you may need to manually install the MagiskManager.apk if it's not present).
  6. Verify Root: Open the Magisk app. It should indicate that your device is rooted. You can also use a "Root Checker" app from the Play Store.

Time & Cost:

  • Time: Flashing Magisk takes a few minutes.
  • Cost: Free.

Step 9: Backup Your Existing ROM (Nandroid Backup)

Before flashing a new custom ROM, it's highly recommended to create a Nandroid backup. This is a complete snapshot of your current system, allowing you to revert to your previous state if something goes wrong or if you simply don't like the new ROM.

  1. Boot into Custom Recovery (TWRP): Refer to Step 8.
  2. Initiate Backup:
    • In TWRP, tap "Backup."
    • Select the partitions you want to back up. At a minimum, select "Boot," "System," "Data," and "EFS" (EFS contains crucial device-specific information like IMEI). You can also select "Cache" and "Dalvik/ART Cache."
    • Choose a storage location (internal storage or external SD card). An external SD card is safer as a full wipe won't erase it.
    • Swipe to start the backup process.
  3. Patience: The Nandroid backup can take a significant amount of time (10-30 minutes or more), depending on your device's storage size and data. Wait for it to complete.
  4. Storage: Nandroid backups are stored in a TWRP (or clockworkmod) folder on your chosen storage. They can be quite large. Always have at least one recent backup on your device. You can transfer older backups to your PC to save space on your phone, but ensure you keep a recent one on your device.

Step 10: Wipe Data Partitions

To ensure a clean installation and prevent issues with the new ROM, it's generally best to perform a full wipe of data and cache partitions. This is often referred to as a "clean flash."

  1. Boot into Custom Recovery (TWRP): Refer to Step 8.
  2. Initiate Wipe:
    • In TWRP, tap "Wipe."
    • Tap "Advanced Wipe."
    • Select "Dalvik / ART Cache," "Cache," and "Data."
    • Do NOT select "Internal Storage" or "System" unless you intend to completely format your internal storage or are specifically instructed by the ROM developer (e.g., if switching major Android versions). Wiping "Internal Storage" will erase your downloaded ROM files if they are not on an SD card.
    • Swipe to wipe.
  3. Factory Reset (Optional, but often included in wipe): Some ROM instructions may simply tell you to perform a "Factory Reset" from the main wipe menu. This typically wipes Data, Cache, and Dalvik/ART Cache.

Time: Wiping typically takes a few seconds to a few minutes.


Step 11: Flashing a Custom ROM

This is the core step where you install the new custom Android operating system onto your device.

Critical Rule: NEVER INSTALL A ROM THAT IS NOT MEANT FOR YOUR SPECIFIC PHONE MODEL. This is the number one cause of bricked devices. Always double-check the ROM's compatibility with your device.

  1. Transfer ROM: Ensure the downloaded custom ROM .zip file is on your device's internal storage or external SD card.
  2. Boot into Custom Recovery (TWRP): Refer to Step 8.
  3. Install ROM:
    • In TWRP, tap "Install."
    • Navigate to the location where you saved the ROM .zip file.
    • Tap on the ROM .zip file.
    • Optional: Add more zips (e.g., GApps, custom kernel) if you want to flash them immediately after the ROM.
    • Swipe to confirm flashing.
  4. Wait for Completion: The flashing process can take several minutes.
  5. Wipe Dalvik/ART Cache (Recommended): After the ROM flashes, it's good practice to wipe the Dalvik/ART Cache again (from TWRP's "Wipe" > "Advanced Wipe" menu) to prevent boot loops.
  6. Reboot System: Once the flashing is complete, tap "Reboot System."

First Boot: The first boot into a new custom ROM will take significantly longer than usual (5-15 minutes or more). This is normal as the system is setting itself up. Do not interrupt this process.


Step 12: Install External Kernel (Optional)

If you've downloaded a custom kernel specifically for your ROM and device, you can flash it after the ROM.

  1. Transfer Kernel: Ensure the custom kernel .zip file is on your device's internal storage or external SD card.
  2. Boot into Custom Recovery (TWRP): Refer to Step 8.
  3. Install Kernel:
    • In TWRP, tap "Install."
    • Navigate to the custom kernel .zip file.
    • Tap on the kernel .zip file.
    • Swipe to confirm flashing.
  4. Wipe Dalvik/ART Cache: After flashing, wipe Dalvik/ART Cache.
  5. Reboot System.

Time: Flashing a kernel takes a few seconds to a minute.


Step 13: Install GApps (Optional)

Many custom ROMs, especially AOSP (Android Open Source Project) based ones, do not include Google Play Services or other Google applications due to licensing restrictions. You'll need to flash a GApps package separately if you want these services.

Important Considerations:

  • GApps Package Compatibility: Download a GApps package compatible with:
    • Your device's architecture (e.g., ARM, ARM64, x86).
    • The Android version of your custom ROM.
    • The specific GApps variant you desire (e.g., Pico for minimal, Nano, Micro, Stock for full suite).
  • Flash GApps Immediately After ROM: It's generally best to flash GApps right after flashing the custom ROM, before the first boot into the new ROM. Flashing GApps later can cause issues.
  1. Transfer GApps: Ensure the GApps .zip file is on your device's internal storage or external SD card.
  2. Boot into Custom Recovery (TWRP): Refer to Step 8.
  3. Install GApps:
    • In TWRP, tap "Install."
    • Navigate to the GApps .zip file.
    • Tap on the GApps .zip file.
    • Swipe to confirm flashing.
  4. Wipe Dalvik/ART Cache: After flashing, wipe Dalvik/ART Cache.
  5. Reboot System.

Time: Flashing GApps takes a few minutes.


Step 14: Restore Your Data

After your new custom ROM has booted up, you can now restore your applications and user data.

  • Google Account Sync: Your contacts, calendar, and app data (for apps configured to sync) will automatically restore once you log into your Google account.
  • Titanium Backup (for user apps and data):
    1. Install Titanium Backup from the Google Play Store (or sideload the APK if needed).
    2. Open Titanium Backup. It will request Superuser permissions (grant them via Magisk if prompted).
    3. Tap "Menu" > "Batch."
    4. Select "Restore missing apps + data" or "Restore all apps + data."
    5. Crucial Warning: Only restore "user applications" and their data. DO NOT restore system applications or system data from Titanium Backup, as this can cause instability, crashes, or boot loops on your new ROM. This is the most common cause of issues after flashing a new ROM.
    6. Let the process complete. This can take significant time depending on the number of apps.
  • SMS/Call Log/Contact Restoration: Use the previously used backup app (e.g., SMS Backup & Restore) to restore your messages and call logs. If you backed up contacts manually, import them via the Contacts app: Menu > Import/Export > Import from storage.
  • App-Specific Login: For apps like Facebook, Google+, etc., you may need to log in and re-sync contacts/data within those specific applications.

Important Notes on Maintenance and Troubleshooting

  • OTA Updates: Once you are on a custom ROM, you will generally not receive official Over-The-Air (OTA) updates from your device manufacturer. You will need to manually download and flash new versions of your custom ROM.
  • Nandroid Backup Management: Nandroid backups consume significant storage. Periodically delete older, irrelevant backups from TWRP's "Backup and Restore" > "Delete" menu to free up space. Always keep at least one recent, working Nandroid backup.
  • Overclocking/CPU Tweaking Software: If you were using overclocking or CPU tweaking apps on your previous ROM, do not restore their data with Titanium Backup. Reinstall them cleanly after your new ROM is set up.
  • Troubleshooting Boot Loops: If your device gets stuck in a boot loop after flashing:
    1. Boot into Custom Recovery (TWRP).
    2. Perform a "Wipe Dalvik/ART Cache" and "Wipe Cache."
    3. If that doesn't work, perform a full "Wipe Data/Factory Reset" (remember this erases everything, so ensure your backups are safe).
    4. If still stuck, restore your most recent Nandroid backup (from TWRP's "Restore" menu).



References:

http://androiding.how/how-to-install-twrp-recovery-via-fastboot/
http://forum.xda-developers.com/showthread.php?t=442480
http://forum.xda-developers.com/showpost.php?p=9987685

https://tektab.com/2015/10/31/android-bootloaderfastboot-mode-and-recovery-mode-explained/
http://www.theandroidsoul.com/how-to-install-adb-and-fastboot-with-drivers-on-windows-quickest-setup-75174/
https://tektab.com/2015/04/03/how-to-work-with-tools-like-adb-and-fastboot-on-your-android-device-installations-of-drivers-and-tools/
http://www.teamandroid.com/2012/07/30/how-to-set-up-adb-fastboot-with-android-sdk/3/
http://forum.xda-developers.com/nexus-4/help/guide-ultimate-nexus-4-root-guide-t2018179
http://nvisionapp.com/android-modding-for-dummies/
http://forum.xda-developers.com/showthread.php?t=2344474