How to root Xperia X from Linux


I was tired of aggressive and annoying ads on my smartphone, especially Youtube ads pissed me of most. To completely disable ads i decided to root my phone. Basically «rooting» a phone gives you super privileges in Android OS. You can modify any system files or install any apps that require root. For me modifying /etc/hosts and blacklisting ad servers there was most important.

My phone is Sony Xperia X model F5121 with one sim card. So Sony allows you to unlock bootloader and then you can flash any kernel/recovery you want there so that can unlock super privileges.

Get unlock key from Sony

First go to https://developer.sony.com/develop/open-devices/get-started/unlock-bootloader/ follow instructions and get your device unlock key.

Here i duplicate instructions just in case. To be able to unlock your Xperia X, prepare it by following these steps:

  1. Go into Settings > About phone and tap seven times on Build number to enable developer options.
  2. From Settings, go into Developer options and enable OEM unlocking.
  3. In your device, open the dialer and enter *#*#7378423#*#* to access the service menu.
  4. Tap Service info > Configuration > Rooting Status. If Bootloader unlock allowed says Yes, then you can continue with the next step. If it says No, or if the status is missing, your device cannot be unlocked.

Copy your unlock code and move on to the next steps.

Install and download dependencies

I run Debian/Ubuntu on my PCs so i decided to use that system for rooting phone and not go with any Windows tools. Install adb and fastboot. Optionally if you have microSD card with extfat formatting install exfat-fuse and exfat-utils.

sudo apt-get -y install android-tools-fastboot android-tools-adb

Ensure that you made full phone backup as following steps will delete your data.

Download files:

  • twrp-3.2.1-20180505-suzu.img
  • Magisk-v16.0.zip
  • KERNEL_F5121_34.4.A.2.85_CLEAN.img
  • DRM-Fix_System_Mode.zip

From https://mega.nz/#F!GJ4mHT7J!Le99gKHmKIwrkzKcDj0jIg or from tar gz file.

Root device

As you have already unlocked developer options in previous step, enable there USB Debugging.

Connect your phone to PC, authorize PC in phone when asked and run commands below. Ensure that you run all your commands as root. I usually use sudo -Es to switch to superprivileged mode.

adb devices

to verify that your device is determined prperly. Once connected switch device to Trasfer files mode and copy there to SD card or Internal Storage Magisk-v16.0.zip and DRM-Fix_System_Mode.zip. Those files will be used later in recovery.

Now reboot your phone into bootloader mode, unlock bootloader and flash recovery and kernel.

Rebooting device into bootloader mode:

adb reboot bootloader

Phone screen should be dark and you should see blue led indicator.

Now check your phone with fastboot.

fastboot devices

Your phone should appear in device list, let’s continue with OEM bootloader unlocking. Copy unlocking code from unlock step in the first part of article.

fastboot oem unlock 0x<your-unlock-code>

Now flash kernel and twrp recovery.

fastboot flash boot KERNEL_F5121_34.4.A.2.85_CLEAN.img
fastboot flash recovery twrp-3.2.1-20180505-suzu.img

Once you flash and saw messages like

target reported max download size of 536870912 bytes
sending 'recovery' (22400 KB)...
OKAY [  0.705s]
writing 'recovery'...
OKAY [  0.279s]
finished. total time: 0.984s

it means everything was written correctly and you can boot into recovery now.

If you see message like

FAILED (remote: Command not allowed)

it means that your bootloader was not unlocked, please check if you correctly completed all above steps.

Now boot phone into recovery mode. Unplug it from PC, poweroff, hold down power button and volume down at the same moment. You should see twrp screen. Use menus to install DRM-Fix_System_Mode.zip and then Magisk.zip from SD card or internal storage. Order of installation matters, first install DRM and then magisk.

Clear cache/delvik cache and and switch-off device. DO NOT PROMPT INSTALL TWRP.

After a while switch on device, first reboot may take a while and you may face bootloop.

Optionally install magisk_5.X.apk. Now you have root.

To unblock ads I used AdAway APK. You can download it from F-Droid or use APK from archive downloaded from my website.

Enjoy ad free phone.

Credits

https://forum.xda-developers.com/xperia-x/how-to/root-xperia-x-f5122-android-n-34-2-2-47-t3594502
https://consumingtech.com/root-install-custom-recovery-sony-xperia-x-performance/

comments powered by Disqus