Android: Flashing LineageOS, MicroG and Magisk

For a great video on this topic see: https://www.youtube.com/watch?v=WSNGK9gmdpg

Highly recommended to watch the video before proceeding.

Install ADB

ADB install files for linux can be found here: https://dl.google.com/android/repository/platform-tools-latest-linux.zip

Install adb, either through a package manager or by downloading the folder and adding it to your path.

I placed it in a ~/.local/share/platform-tools and added export PATH="$XDG_DATA_HOME/platform-tools:$PATH"

XDG_DATA_HOME environment variables is set to ~/.local/share conventionally.

Download Custom ROM

A prepatched ROM with LineageOS and microG services can be found here: https://lineage.microg.org/

This is the recommended ROM in addition to the NanoDroid Bromite Webview replacement, for the regular webview which is less secure, supposedly.

Base LineageOS can be downloaded from here: https://download.lineageos.org/

NanoDroid apks can be downloaded from here: https://downloads.nanolx.org/NanoDroid/Stable/

Patch the boot.img file with Magisk

To have super user access to the phone, rooting software must be installed. This is obviously useful for having more control over the phone, but is also useful for allowing services such as F-droid and the Aurora store to automatically install updates. It is recommended to use Magisk, the apk can be grabbed from here: https://github.com/topjohnwu/Magisk

You need to install the apk to the phone prior to reflashing as the app is used to patch the ROM boot.img file which will allow super user priviledges.

Download the desired ROM zip file, extract the boot.img file and transfer to the phone. For stock images it will be within the AP zip folder.

Within the Magisk app on the Magisk panel, select install. If your phone is encrypted make sure to check the preserve encryption option. Then select the boot.img file when prompted to and proceed. A newly patched boot.img will be created in the downloads folder. Transfer it back to the pc and repackage the patched boot.img into the zip folder.

This process of patching the boot.img file and manually flashing will be required whenever the phone needs to be updated.

The phone apparently cannot be updated normally now.

Install TWRP

This is a tool for recovering your device and allows the installation of custom ROMs. There are many tutorials on how to do this elsewhere.

Wipe device

Boot into TWRP by turning off the device and holding Power + Volume Up + Home.

After booting into TWRP, press Wipe -> Advanced Wipe. Check System, Data, Cache and Dalvik / ART Cache. Swipe to wipe.

You can also wipe internal storage as well if you so choose. Do not reboot after wiping.

Add custom ROM files to the phone

It should be possible to use the system file explorer to copy files across. However, it can also be incredibly slow for some unknown reason. If this is the case then adb will need to be used.

If experiencing problems, make sure that under the “Mount” menu that MTP is enabled. This can be toggled using the bottom right button. Also make sure that the “Mount system partition read-only” option is unchecked.

When using adb, the following command will show if a device is successfully connected:

adb devices
List of devices attached
numbers_and_letters         recovery

Files can then be copied to the device using:

adb push <file1> <file2> /sdcard/

Installing the custom ROM

Install custom ROM zip folder first from the install menu and then any additional zip folders.

Done

Reboot the phone and the process should now be complete.