I describe here the fundamental steps in replacing my stock Android with a customized one.

Disclaimer: Here I present principles and steps I run on my particular case. You are responsible for all negative effects my occur to you.

The instructions are for LineageOS custom rom but they are similar for all custom ROMs.

What is an Android ROM

A custom Android ROM refers to a phone’s firmware, based on Google’s Android platform. Android is open source and therefore any developer can edit the code, recompile it, and re-release for a wide variety of devices.

Whenever stuck, you can get specific help on xda-developers

The basic advantages is freedom. a customized ROM are: posibility to update system more often, privacy control over the apps, benefit of the new features. removal of stock android bulkware and the option to install Google products only optional (through gapps open source project)

Prerequisites

Backup your data since the phone device will be completely reset.

Unlock Boot

Here is the most tricky part. Vendors are doing their best to prevent you doing it. Once you unlock it you are free to install whatever compatible OS you find.

About Phone > Version Tap 7-10 times on it.

On Android About > System > Build Number

Go back to Additional Settings:

Developer Options = On
OEM Locking = On
USB Debugging = On

Note on MIUI

MIUI is the stock Android for Xiaomi devices. They are stubborn on letting you go. Therefore you need to perform the following request.

Go to Mi Unlock status If you need to enter fastboot mode and flash your device, you can unlock it. You won’t be able to use ‘Find device’ after the phone is unlocked. Make sure you have a SIM inserted. Associate MI Account to your device. Download the unlock tool from website on a computer. https://unlock.update.miui.com

Roughly the steps are:

Root your phone: it depends on each model.

For example on Xiaomi devices you need to apply for it, wait 15 days before being granted the permission. If you have more than 1 devices you need to wait other 30 days for each one.

Root Xiaomi

The tool I used is MiUnlockTool - it is an unofficial tool which replicates the official one, but is written in Java and hence is cross-platform. It will work on linux and on mac. One notice: if you launch the tool using the included .sh script, it will require root privileges. But on my system, root is not required for fastboot. So I launched it directly as java -jar bin/MiUnlockTool.jar and it worked like a charm.

Alternatively you can run the script to trigger it in command line

Use credentials from miui account.

Download link Alternative link: xiaomitool.com/MiUnlockTool

Download the ROM package and sha256.

Check whether your phone model is supported. There are many custom ROMS. Lineage and AOSP Extended are one of the most reliable Android ROMs.

There are official and unofficial ROMs. Pick an official one. An example for Lineage: https://download.lineageos.org/beryllium, download the latest package and the sha256 checksum file.

Make no mistake. There is a myriad of phone models on the market. Pay attention also to the code name e.g Xiaomi Poco F1 is called beryllium. https://wiki.lineageos.org/devices/beryllium. Remember it as next time you’ll be sure phone model match.

Verify the whether the package is genuine.

Download the sha256 file in the same place with your android rom package.

Now run the command:

$ sha256sum lineage-17.1-20200720-nightly-beryllium-signed.zip
68e174acf231fb1569f04bbdfa93915f8feaa8010ffdaeccddba1fd2d62b4f6b  lineage-17.1-20200720-nightly-whyred-signed.zip

Other packages like those from Extended AOSP are signed with md5:

$ md5sum lineage-17.1-20200720-nightly-beryllium-signed.zip

Compare the output number with the number inside the text file you downloaded. It should be identical.

Read the instructions ahead twice before getting started: https://wiki.lineageos.org/devices/

Install adb and fastboot

The Android Debug Bridge (adb) is a development tool that is reponsible with communication between an Android device and a PC via USB cable or Wi-Fi connections.

Extract it somewhere - for example, ~/adb-fastboot.

Add them to the PATH in ~/.bash_profile:

if [ -d "$HOME/adb-fastboot/platform-tools" ] ; then
 export PATH="$HOME/adb-fastboot/platform-tools:$PATH"
fi

Log out and back in or run $ source ~/.profile. You can now run adb and fastboot from any place.

Set up udev rules

These udev rules refer to connectivity between Android and linux hardware. You may also need to set up udev rules: see this repository for more info.

Clone udev repository

git clone https://github.com/M0Rf30/android-udev-rules.git
cd android-udev-rules`

And follow the instructions in the repo file.

Restart in fastboot mode

To use the fastboot command you first need to put your device in fastboot mode:

$ adb reboot bootloader

You can achieve it also by pushing the same time Volume Up + Start or all buttons the same time.

Summarizing,

Backup, backup backup. Your data is your most valuable asset.

Make sure your computer has working adb and fastboot.

Enable USB debugging on your device.

Unlock the bootloader.

Download the version of the custom ROM that suits you.

The most common are Lineage OS or Extended AOSP.

There are many others its with official and unofficial version.

Now final steps, boot into fastboot mode (bootloader). Either hit simultaneosly on a key combination e.g. Volume Up + Power or

$ adb reboot bootloader

Now type

$ fastboot devices

Sometimes I run into

no permissions (user in plugdev group; are your udev rules wrong?); see [http://developer.android.com/tools/device.html]

so I add my user spokane to the group plugdev.

$ sudo usermod -aG plugdev spokane

I restart adb server:

$ adb kill-server
$ adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully

Now we talk. Again I reboot in

$ adb reboot bootloader
$ fastboot devices
no permissions (user in plugdev group; are your udev rules wrong?)

Again? Maybe sudo?

$ sudo fastboot devices
4489f10e	fastboot

Now we talk again.

Step 3 Install a custom recovery

All Android devices ship with a recovery environment preinstalled. This recovery software can be used to restore the device to factory default settings, update its operating system, and perform other diagnostic tasks.

The stock recovery is a minimal, limited system.

I replaced it with TWRP (teamwin): https://twrp.me/Devices/ Update: recently Lineage OS has released its own, I tried it it’s good but I prefer twrp.

Download the twrp package is compatible with your device. Mine was Poco F1. I downloaded twrp-3.4.0-0-beryllium.img and a genuinity key.

Flashing (replacing) mystock or other recovery with twrp:

$ sudo fastboot flash recovery twrp.img
target reported max download size of 536870912 bytes
sending 'recovery' (36324 KB)...
OKAY [  0.779s]
writing 'recovery'...
FAILED (remote: Anti-rollback check failed)
finished. total time: 0.794s

Troubleshooter’s notes:

Sometimes the recovery is persistent: Unzip the dummy flash (search for it on internet).

sudo fastboot flash antirbpass dummy.img 
fastboot format userdata

In conclusion, if you see no permissions fastboot while on Linux or macOS, try running fastboot as root.

Copying and installing the OS package

Boot into recovery

sudo fastboot boot twrp.img

or hit all 3 buttons at once (or DownButton + Power), depending on the phone.

To send anyfile to your phone device you simply use push subcommand:

adb push filename.zip /sdcard/

So I copy the main OS file.

adb push AospExtended-v7.3-whyred-20200718-1100-OFFICIAL.zip  /sdcard/

After full copy consider having the gapps package installed.

Why?

Google Apps (a.k.a. GApps) are the proprietary Google-branded applications that come pre-installed with most Android devices, such as Google Play Services, Play Store, Gmail, Maps, etc. Due to licensing restrictions, these apps do not come pre-installed with ROMs others than those from vendors that are part of the Open Handset Alliance and must be installed as a sideload package by the user themselves.You can read about: https://github.com/opengapps/opengapps/wiki.

You have to install it your own.

My architecture is ARM64 and I picked the minimum that has Digital Wellbeing installed: nano.

adb push open_gapps-arm64-9.0-nano-2020214.zip /sdcard/
adb push addonsu-15.1-arm64-signed.zip /sdcard/

Now from twrp:

Hit Advanced Wipe then cache and data.

(I would say this is optionally but the truth is I’m not sure).

I have skipped it once and installed fine only that the wifi didn’t worked correctly. Possible networked credentials could not be saved due to writing permissions.

!!! WARNING IT’S YOUR DATA !!! Hit Wipe Hit Format

Now hit on Install button and click on the each package.

Note: If you want any Google Apps on your device, you must follow this step before the first boot into Android!

(Optional): Root the device by installing the LineageOS su add-on (use the arm64 package) or using any other method you prefer. Once installation has finished, return to the main menu, tap Reboot, and then System

Reboot

From TWRP hit Reboot

Enjoy!