Xperia XA2

Rooting Xperia XA2 on Lineage OS

After a successful installation of Lineage OS on the phone, it's time to get it rooted. Lineage OS doesn't come with root by default, since it's not always desirable to have a rooted phone. However, if we want to change some major things and take back control of our devices, we will need root privileges.

DISCLAMER: I AM NOT RESPONSIBLE FOR ANY DAMAGE CAUSED TO YOU OR YOUR DEVICE. YOU ARE ON YOUR OWN (but feel free to ask anything in the comments).

But seriously, the process is not super difficult, just follow the instructions and you should be fine.

Rooting process

To avoid confusion, my bootloader is already unlocked. In case yours isn't – this won't work. However, I assume you have already unlocked it because you have Lineage OS intalled.

Donwload Magisk

Magisk is a fairly advanced open source tool for customizing Android, but also very simple to use with a modern app and many tutorials online. To mention some of the main features of Magisk from their GitHub page:

Only download Magisk from the official GitHub page: https://github.com/topjohnwu/Magisk. Any other sources may contain unwanted things like malware. Install (you have to enable installation from third party sources, on the newest Androids this is done on app-to-app basis).

Extract files from the newest image

Head over to https://download.lineageos.org/pioneer and download the latest signed zip build – the one that you used to install Lineage OS.

image-1630092593900.png

Compare the SHA256 signature from the website with the downloaded file. If you are on Windows, you can use simple powershell cmdlet Get-FileHash. You don't have to check the entire string, just some of the characters, since if the file was modified, the hash would be completely different.

Get-FileHash .\lineage-18.1-20210826-nightly-pioneer-signed.zip

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA256          DD82D969CA7898F3C42F7B2373F3C354E2733CED4DF94721E7D06472E6D665A0       D:\Exampledir\dir...

Download this utility: https://github.com/vm03/payload_dumper to extract boot.img from payload.bin located in the ZIP file you just downloaded. You need python and a couple of other dependencies, everything should be described on the GitHub page.

Extract the Lineage OS ZIP and place payload.bin to the root folder of payload_dumper

image-1630093384900.png

image-1630093402800.png

and run

python payload_dumper.py payload.bin

Output in the terminal should look something like this:

Processing boot partition............Done
Processing system partition.................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
.......................................................................Done
Processing vendor partition.................................................................................
............................................................................................................
............................................................................................................
............................................................................................................
....................Done

After it has finished, you should end up with three files located in the output folder

image-1630093714500.png

Copy the boot.img file to your Android device and open Magisk.

image-1630143585800.png

Patch the extracted image with Magisk

Next to Magisk, click Install

image-1630144454400.png

Select and Patch a file

image-1630144489900.png image-1630144529100.png

 

 

 

 

 

 

 

 

 

 

 

 

This will take a few seconds and after it has finished, there should be a new file called something like this:

image-1630144664800.png

Flash the patched image using ADB

First of all, download appropriate drivers and tools. You should only need these https://developer.android.com/studio/releases/platform-tools, but in case it doesn't work, look around the internet for more.

Copy this file from your phone back to your PC, ideally into the same folder as you ADB tools that you have just downloaded.

image-1630148421200.png

Device should now reboot into boot loader, make sure the USB cable is connected.

Now Shift+right click into the folder with ABD tools and your patched image file and open either Windows Terminal (if you have it installed) or regular PowerShell/cmd window.

image-1630150723400.png

Try running .\fastboot.exe devices. If you can't see any output, open Device Manager in Windows and look for something like this:

image-1630150650800.png

Right click it --> Update driver --> Browser my computer for drivers --> Let me pick from a list of available drivers on my computer --> List all devices --> Google Inc. --> Android Bootloader Interface

Now try running .\fastboot.exe devices again, you should get this:

>.\fastboot.exe devices
CQ3000952E      fastboot

Flash the patched image to your Android device (the name of the file might be different)

>.\fastboot flash boot magisk_patched-23000_eL6xq.img

Sending 'boot_b' (23069 KB)                        OKAY [  0.498s]
Writing 'boot_b'                                   OKAY [  0.180s]
Finished. Total time: 1.172s

Reboot the device

 .\fastboot reboot
Rebooting                                          OKAY [  0.000s]
Finished. Total time: 0.002s

After the reboot, open up Magisk and check if it is recognized as installed.

image-1630151735800.png

That's it! You now have a rooted Lineage OS device. What to do next? Everything you want. In case you need some tips, I have created a list of things that I do.

Things TODO after installation – settings, apps etc.

So you've just successfully installed Lineage OS on your phone, in this case Xperia XA2. I assume you have already went through the initial couple of screens and set basic things like Wi-Fi, unlock password, etc. Now you are staring at a clean Lineage OS, what to do next? I decided to write down some of the things that I do and you might want to do too. I say might because not everyone has the same priorities when using their mobile device, so take everything as you wish.

 

Customizing through basic settings

Enable dark mode

I am one of the dark mode users who describe light mode like this:

image-1630265429400.png

That's why the first thing I am going to do will be turning on dark mode in the system settings. Navigate to Settings --> Display --> Dark theme (on). Better, isn't it? Due to personal preference, this is completely optional.

image-1630265555100.png

image-1630265559500.png

Navigation buttons

Even though I'm not particulary fond of buttonless navigation, especially the latest Android implementation where you go back by swiping from the right or left side instead of the bottom right or left, which interfered less with other gestures, I still prefer having as much screen estate as possible. In order to turn on buttonless navigation:

 

 

App pinning & Screen lock

In case you need to share your device with someone for a moment, for example to let them search for something in a browser or any other case, consider enabling App pinning. With this feature enabled, open an app and long press its icon in the Recents screen (or app switcher, the screen where you can switch between apps). Once the app is pinned, you won't be able to leave the app, unless you Swipe up and hold. Afterwards you will be asked for your pattern or other kind of screen lock, depending on which one you've set.

 

 

Speaking about screen lock. If you are using a pattern, Lineage OS has a net couple of features around it. Go to:

Adjusting scaling

Maybe it's because I got used to a phone with a larger screen, but the 5.2" Xperia simply doesn't feel great with the default scaling, everything seems too big. You can change both the Display size and Font size. I recommend you try to combine both to see which best suits your eyes.

 

 

 

Installing F-Droid

image-1630265214300.png

image-1630265230500.png

 

 

 

 

 

 

Updating Lineage OS while keeping root working with Magisk

Decided it would be nice to document how to perform an update, because the releases appear fairly frequently and the process isn't exactly straightforward like clicking Download and Install button.

Perform update normally trough OTA

Navigate to Settings --> System --> Advanced --> Updater. Pick the newest update, download and install. After it has finished, reboot your device.

image-1630097882100.png

image-1630097896700.png

image-1630097917300.png

After reboot, open Magisk to check if you are still rooted. Most likely, you are not. Now how to fix it. The only way I found working is to basically repeat the whole root process again. In short:

These steps are decribed in more detail over here: https://selfhostedfuture.xyz/books/everything-nix-and-libre-software/page/rooting-xperia-xa2-on-lineage-os