Install LineageOS 20 for MicroG on Motorola G7 or Sony Xperia XZ2

This post outlines the procedure we follow for flashing the custom ROM LineageOS for MicroG onto the Motorola Moto G7 and the Sony Xperia XZ2 mobile phones, using a Windows computer.

LineageOS for MicroG is a customised version of LineageOS that includes MicroG – an open source and privacy focused version of Google Apps, that is also much lighter on resources.  The installation process for LineageOS and LineageOS for MicroG is essentially identical, so the definitive documentation for this installation is the LineageOS website (select a phone type to see the builds and guides):

  • For the Motorola Moto G7, our process is based on the LineageOS Moto G7 guide
  • For the Sony Xperia XZ2, our process is based on the LineageOS Xperia XZ2 guide

 

Cautions

Be aware that flashing a phone requires you do many things in a precise order.  Making one mistake can cause your phone to go into a boot loop, or even be permanently bricked (apparently).  I’ve messed up when flashing phones more than once and never bricked one, but you should assume that it can happen if you don’t follow instructions precisely.

I have used this procedure to flash the phones listed above from their OEM Android to LineageOS for MicroG and have upgraded LineageOS for MicroG to a later version on these phones with this procedure.

If you have a different phone or haven’t done this type of thing before, I suggest this procedure only be used as a guide, and you fully read the appropriate installation instructions at LineageOS for your device.

 

Why Use LineageOS for MicroG?

Three are many sites that will explain the benefits of flashing supported phones with privacy-focused implementations of Android such as GrapheneOS, DivestOS, or LineageOS.  We use LineageOS for MicroG as it has a good balance between privacy, usability (MicroG gives us most Google functionality, without the Google proprietary code) and support for a good range of devices.

 

Download files needed to install LineageOS on your phone

Before upgrading from your phone’s OEM software to LineageOS for MicroG, check first that you can download the following files:

  1. ADB and Fastboot executables for Windows (if you don’t already have them) from Google.
  2. Drivers to allow your computer to recognise your phone when it is booted into Fastboot mode.
    • Get Motorola Fastboot drivers for Windows 64-bit or Mac
    • Get Sony Xperia XZ2 fastboot drivers for Windows 7+, drivers for other Sony phones are found here.  Note that Sony drivers are not signed so you will need to reboot Windows with advanced options and disable driver signing to install these drivers.  After the drivers are installed, you can boot Windows normally.
  3. The copy-partitions-20220613-signed.zip file from here.
  4. Download the latest LineageOS recovery partition image (~64Mb boot.img) and LineageOS system image (>800Mb).  There may be other files on the server for the latest build, but these are the only two that we need.
    • The LineageOS for MicroG files for the Motorola Moto G7 can be found here.
    • The LineageOS for MicroG files for the Sony Xperia XZ2 can be found here.

 

Preparing for the Android Upgrade

  1. Read through the instructions at least once before actually following them, so as to avoid any problems due to any missed steps!
  2. Make sure your computer has ADB and Fastboot. Setup instructions can be found here.
  3. Find and install the fastboot drivers you downloaded for your phone on your computer.
  4. Enable USB debugging on your phone.
  5. Make sure that your model is actually listed in the “Supported models” section here (exact match required!)
  6. Boot your device with the stock OS at least once and check every functionality.
  7. For the Sony Xperia XZ2, the LineageOS guide requires that you upgrade (or downgrade) your OEM software to Android 10.  Check the LineageOS site guide for your device to see if there are any specific requirements for your phone.
  8. Copy everything you need from this phone before the upgrade, as both unlocking the bootloader and installing LineageOS will wipe all your user data, files and media.

 

Unlocking the bootloader on your Android phone

Android phones are sold with a locked bootloader.  This is a security feature that prevents non-OEM software from being installed on the phone.  The bootloader needs to be unlocked before we can install a third party OS on the phone, such as LineageOS for MicroG.

Follow this process, if your phone's bootloader is not already unlocked.

Note – Unlocking the bootloader will invalidate the warranty on your phone and delete all data on your phone, including stored images, media etc.

  1. Connect the device to your PC via USB.
  2. On the computer, open a command prompt (on Windows) or terminal (on Linux or macOS) window, and type: adb reboot bootloader.  You can also boot into fastboot mode via a key combination: With the device powered off, hold Volume Down + Power.
  3. Once the device is in fastboot mode, verify your PC finds it by typing: fastboot devices
  4. We need to get a code from the manufacturer of your phone to unlock the bootloader:
    • For a Motorola phone, follow the instructions at Motorola Support to unlock your bootloader.  The unlock process requires registering on the Motorola support website, reading a whole bunch of warnings and waiting for the unlock code to be emailed to you
    • For a Sony phone, follow the instructions
  5. Follow the instructions at Motorola Support to unlock your bootloader.  The unlock process requires registering on the Motorola support website, reading a whole bunch of warnings and waiting for the unlock code to be emailed to you.  But if your bootloader is unlockable, it’s worth it!
  6. Unlocking the bootloader effectively factory resets the phone, so  you will need to re-enable USB debugging to continue.

 

Installing a custom recovery using Fastboot

With the bootloader unlocked, we can now replace the standard recovery partition on your phone with the LineageOS recovery environment, and then use this to sideload LineageOS.  I’ve often found that upgrading LineageOS to a new version failed because I didn’t first update to the latest recovery environment, so always flash the latest LineageOS recovery environment associated with your version of LineageOS.

  1. Copy the (latest) Recovery Partition file you downloaded toboot.img.
  2. Connect your device to your PC via USB if it isn’t already.
  3. If your device isn’t already in fastboot mode; on the computer, open a command prompt (on Windows) or terminal (on Linux or macOS) window, and type:adb reboot bootloaderor use the key combination on your phone.
  4. Once the device is in fastboot mode, verify your PC finds it by typing:fastboot devices
  5. Flash a recovery on your device by typing:fastboot flash boot boot.img.  If you get an error Image not signed or corrupt, don’t be discouraged.  Carry on, just in case it worked.
  6. Now reboot into recovery to verify the installation.  I didn’t find a way to reboot to the recovery partition on this phone from fastboot so I did it with the following command:fastboot boot boot.img

 

Ensuring all firmware partitions are consistent

In some cases, the inactive slot can be unpopulated or contain much older firmware than the active slot, leading to various issues including a potential hard-brick. We can ensure none of that will happen by copying the contents of the active slot to the inactive slot.

  1. Find the copy-partitions-20220613-signed.zip file that you previously downloaded from here. It should have a MD5 sum of 79f2f860830f023b7030c29bfbea7737 or a SHA-256 sum of 92f03b54dc029e9ca2d68858c14b649974838d73fdb006f9a07a503f2eddd2cd.
  2. Sideload the copy-partitions-20220613-signed.zip package:
    • On the device, select “Apply Update”, then “Apply from ADB” to begin sideload.
    • On the host machine, sideload the package using: adb sideload copy-partitions-20220613-signed.zip
  3. Now reboot to recovery by tapping “Advanced”, then “Reboot to recovery

 

Installing LineageOS from Recovery

We have now updated the recovery partition in your phone to the latest LineageOS version and copied it to the inactive slot to prevent any future problems.

  1. Your phone should now be rebooted into Recovery.  If you are not in recovery, reboot into recovery:
    • With the device powered off, hold Volume Down + Power, then select “Recovery mode” using Volume keys.
  2. Now tap Factory Reset, then Format data / factory reset and continue with the formatting process. This will remove encryption and delete all files stored in the internal storage, as well as format your cache partition (if you have one).
  3. Return to the main menu.
  4. Sideload the LineageOS .zip package – we are assuming for the purpose of this install that your LineageOS for MicroG system file (~760MB) is called filename.zip, although it obviously isn’t!
      • On your phone, select “Apply Update”, then “Apply from ADB” to begin sideload.
      • On your computer, sideload the package using: adb sideload filename.zip.
      • The sideload process for LineageOS can take 10 or more minutes.  When the install process gets to 47% on the computer, you need to watch the phone to see when the installation completes.
  5. When the installation of LineageOS has completed, you will see the Recovery Menu re-appear on your phone.  Select Reboot system now to load LineageOS for MicroG for the first time.

 

Configure MicroG

Although MicroG is already included in this OS, you need to configure it before installing apps, to have Google Play services available when the apps are installed.  No Google account is required to use the MicroG services.

In Settings / System / microG Settings:

  • run Self-Check.  Everything should be ticked except for maybe Permission to appear on top of other apps.
  • enable Google device registration – this must be done before enabling Cloud Messaging
  • enable Cloud Messaging – this must be done before installing apps that require Google Cloud Messaging (such as Signal Messenger)
  • Location Modules – tap Nominatim, then tap Mozilla Location Service.  A prompt to Allow Mozilla UnifiedNlp Backend to access this device’s location will appear – don’t select any of the 3 offered options.  Click on Allow in settings, tap Allow all the time, then back again.  Allow Mozilla UnifiedNlp Backend to make and manage phone calls.
  • You should be able to enable Mozilla Location Service now.

 

LineageOS for MicroG installed!

LineageOS for MicroG should now be installed.  This gives you a phone with access to the features of Google Play services but without any Google code, or the privacy concerns associated with it.

Anecdotally, I have also found every phone I’ve flashed with LineageOS to be noticeably faster than with the manufacturer’s version of Android, probably due to the lack of bloatware and MicroG being lighter than Google Apps.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *