Install a custom Android ROM
Some important facts
- Please read the whole article before doing anything.
- Your battery charge should be at least >50% before starting the installation.
- You should know how to use a terminal in Linux.
- Every device may need some tweaks and startpaging aka. googeling{:target="_blank"}.
- If you find any mistakes in this article please send me an email.
Use at your own risk
We cannot be blamed in case you brick the phone nor in case you lose any important data file in the process.
Install adb
- Ubuntu/ Kali Linux:
$ sudo apt-get install adb
$ sudo apt-get install fastboot
- Arch Linux
$ sudo pacman -Syy android-tools
Other tools
- If you have a Samsung device you also need to install Heimdall{:target="_blank"}
- Ubuntu/ Kali Linux
$ sudo apt-get install heimdall-flash
- Arch Linux
$ sudo pacman -Syy heimdall
- Ubuntu/ Kali Linux
Backup
- Backup your data before doing anything. If you want to use the terminal to backup your photos etc. you can use adb:
- First you need to allow USB Debugging. To do this go to Settings -> About and scroll down to Build number and press it several times until you become developer. Then go to Settings -> Developer options and enable USB debugging (Android debugging).
- Now you can connect your phone via USB cable to your computer. If you run
$ adb devices
you should see that one device is connected. Then run$ adb shell
to get a shell on you Android phone and look for files you want to backup. You can exit the shell with$ exit
. In your computer terminal you can run$ adb pull <remote> <local>
to copy files from your phone to your local computer.- Your probably find your files in /storage/self/primary
Download LineageOS or another custom Android ROM
- Take a look at Settings -> About -> Device model to see what ROM you have to download.
- LineageOS{:target="_blank"}
- LineageOS - Verifying Build Authenticity{:target="_blank"}
- CopperheadOS{:target="_blank"}
- CopperheadOS - Verifying Build Authenticity{:target="_blank"}
- LineageOS{:target="_blank"}
Install Custom Recovery without root
- Download the specific custom recovery image for your device at TWRP{:target="_blank"}
- To verify the image take a look at their FAQ{:target="_blank"}
- Boot in bootloader mode by running
$ adb reboot bootloader
- alternative you can power off your device and press a device specific key combo to start the bootloader
- for Nexus devices this should be: volume down + power button
- for Samsung devices this should be: volume down + home button + power button
- alternative you can power off your device and press a device specific key combo to start the bootloader
- Flash the custom recovery:
- Non Samsung:
- First unlock the bootloader with
$ sudo fastboot oem unlock
and then reboot it. You have to re-enable USB debugging. - Then flash the revocery image with
$ sudo fastboot flash recovery twrp.img
- First unlock the bootloader with
- Samsung:
$ heimdall flash --RECOVERY twrp.img --no-reboot
- Non Samsung:
- Now power off your device and then boot in recovery mode. Again you need to press a device specific key combo to enter custom recovery.
- for Nexus devices this should be: volume up + power button, alternative you can choose in the bootloader mode to restart in recovery mode.
- for Samsung devices this should be: volume up + home button + power button.
- Many devices will remove custom recovery if the system is booted and not directly custom recovery. You may have to reinstall the custom recovery. If you have a custom ROM installed, custom recovery won’t be removed anymore.
Install custom ROM - Option 1
- All steps below are done while being in custom recovery.
- First we need to push the zip file, we have downloaded a few steps earlier, to our phone. We use adb to do it. With
$ adb push <local> <remote>
you can upload it to your USB connected phone. Upload it to your internal storage by using:$ adb push ROM.zip /sdcard
- Select Wipe and confirm the factory reset process, alternative you can also wipe your internal storage by using Advanced Wipe.
- Select install and choose the custom ROM, the zip file we have just uploaded and confirm the installation process.
- Reboot system. TWRP may ask you to install itself as an app but you can deny it.
Install custom ROM - Option 2
- This way is a bit faster.
- While being in custom recovery go to Advanced -> ADB Sideload. Check Wipe Dalvik Cache, Wipe Cache and then swipe to start the sideload. Then go to your computer and run
$ adb sideload <local>
with<local>
being the custom ROM zip file. - Wait until TWRP says it is finished. The percentage on the computer terminal may be inacurrate. There may be a message that no ROM was installed but you can ignore it, the ROM should have been installed.
- Reboot system. TWRP may ask you to install itself as an app but you can deny it.
Updates
To update your phone you can follow the same steps. Download the new ROM.zip and use Option 2 to sideload your new ROM to your phone. I recommend doing this way because I had some problems with updating LineageOS with the Updater that can be found under Settings -> About phone -> LineageOS updates.
Useful adb commands
- Settings -> Developer Options -> Enable USB Debugging
- Useful commands:
1$ adb devices
2$ adb connect <host>[:<port>]
3$ adb push <local> <remote>
4$ adb pull <remote> <local>
5$ adb shell
Encrypt your phone
- In Android the encryption password is tied to your password you use to unlock your screen. This hampers us to use a good encryption password. But you can choose a simple pin to unlock your screen and change your encryption password to a much better one using adb.
- Enable USB Debugging and Root access via adb in developer options. Connect your phone to your computer. We need to enter the root shell by first running
$ adb root
and then$ adb shell
. But first you need to allow root access via adb shell by checking Settings -> Developer options -> Root access -> ADB only. - In the adb shell you can now change your encryption password without changing you pin to unlock your screen with the following command:
# vdc cryptfs changepw password "currentpasswd" "newpasswd"
- And you can verify the password with:
# vdc cryptfs verifypw "yourpass"
- If you have entered the correct password there should be a
0
at the end of the output otherwise1
.
Troubleshooting
- adb has no permissions when trying to sideload a new ROM version
1$ adb devices 2List of devices attached 302c438ce0ede8404 no permissions; see [http://developer.android.com/tools/device.html]
- Shutdown the adb server with
$ sudo adb kill-server
and then restart it with$ sudo adb start-server
. - Also enable USB debbuging as shown in the Backup section.
- Settings -> Developer options and enable USB debugging (Android debugging)
- Attach your phone to your computer and connect to it with
$ sudo adb shell
. A window should pop up on your phone, allow the connection and exit the shell. - Now you can reboot in recovery mode and sideload your new ROM version.
- Shutdown the adb server with
- fastboot has no permissions
- If
$ fastboot devices
returns with an no permissions message try to run fastboot as root.
- If
Have a 🩷 - Donate for free Open Source Software
- If you appreciate their work and would like to support future development please make a donation for the software you use.
- LineageOS{:target="_blank"}
- TWRP{:target="_blank"}
- CopperheadOS{:target="_blank"}
- Heimdall{:target="_blank"}