Johnny Matthews | Install LineageOS on Mi A2

Bored of the standard Android OS on your Xiaomi Mi A2? You might be interested in installing LineageOS, a free and open-source operating system for various devices based on the Android mobile platform. I created this post partly as a guide, and partly as a reminder for when I need to do this again in three months. This was written on 12th of July 2020.

Download images

Before we can install anything, we need to get the images that we’re going to throw onto our device.

  1. Download LineageOS installation .zip file.
  2. Download the LineageOS recovery .imgfile.

ADB and Fastboot

The Android Debug Bridge (ADB) is a command-line tool that lets you communicate with an Android device from a computer. Fastboot is a special diagnostic and engineering protocol that you can boot your Android device into. We’ll be using these two tools to erase everything on the device, and then install a custom rom.

  1. sudo apt install android-tools-adb android-tools-fastboot -y

  2. Check ADB and Fastboot versions to make sure they both got installed properly:

    adb --version
    
    > Android Debug Bridge version 1.0.39
    > Version 1:8.1.0+r23-5ubuntu2
    > Installed as /usr/lib/android-sdk/platform-tools/adb
    
    fastboot --version
    
    > fastboot version 1:8.1.0+r23-5ubuntu2
    > Installed as /usr/lib/android-sdk/platform-tools/fastboot
    

    ``

Developer mode and the bootloader

We need to enable developer mode on the device in order to turn on USB-debugging mode. The debugging mode allows our computer to talk to our phone through a USB cable.

  1. On the phone, go to Settings > System > About phone.
  2. Scroll down to Build number and click on it several times. Your phone will attempt to go into developer mode.
  3. Enter your pin/pattern if asked for it.
  4. Once it says You are now a developer close the app.
  5. Go to Settings > System > Advanced > Developer options.
  6. On this page enable USB debugging. You may have to enter your pin/pattern.
  7. On the same page, enable OEM unlocking. You may have to accept a warning about device protection features.

Now that we’ve got your phone ready, let’s test the connection to your computer.

  1. Plug your phone into your computer using a USB cable.

  2. A warning may pop up on your phone asking if you want to allow the computer to access your device over USB? Select Always all and then Allow.

  3. Reset your phone and boot into the bootloader by running this command:

    adb reboot bootloader
    

    ``

  4. Your device should reboot and show a little guy in a Russian looking hat.

OEM unlock

Now that we’re in the bootloader, we can start wiping and installing things. Again, this procedure will erase everything on the phone, so make sure stuff is backed up, and you’ve got a list of all the apps you want to download later.

  1. Check that Fastboot can see your phone:

    fastboot devices
    
    > 2ed7330 fastboot
    

    `

  2. Even though we unlocked the bootloader within the phone, we still need to unlock the full OEM features in order to access the full phone when installing our rom. Unlock the full features of the phone:

    fastboot oem unlock
    fastboot oem unlock_critical
    

    ``

    Running unlock_critical may result in a error saying you’ve already unlocked this, or something like that. That’s fine, it just means that the first unlock command did everything already.

Install recovery image

The recovery image is what pops up when you boot your phone into Recovery mode. The default recovery that comes with Android phones doesn’t do what we need, so we need to flash a custom recovery mode onto the phone. Luckily, LineageOS has a recovery image we can use.

You will likely have to change the file names of some of the files listed in these commands.

  1. Move to the directory where you downloaded the lineage-17.1-recovery.img file:

    cd ~/Downloads
    

    ``

  2. Flash the recovery image onto your phone:

    fastboot flash boot lineage-17.1-recovery.img
       
    > target reported max download size of 536870912 bytes
    > sending 'boot_b' (24517 KB)...
    > OKAY [  0.822s]
    > writing 'boot_b'...
    > OKAY [  0.190s]
    

    `

    If you device doesn’t respond, or the above command does absolutley nothing and just hangs, you have not have unlocked the bootloader fully. Exit the terminal, open a new one, and run fastboot oem unlock && fastboot oem unlock_critical, then try the above command again.

  3. Continue booting your phone to the homepage:

    fastboot continue
    

    ``

  4. Unlock your phone.

Install custom ROM

Now it’s time to install the custom rom.

  1. Reboot into recovery mode:

    adb reboot recovery
    

    ``

  2. The LineageOS recovery menu should now be shown on your phone. It might be very dim. You should be able to control this menu using the touch screen. If the touchscreen doesn’t do anything, use the volume keys to go up and down, and the power button to select an option.

  3. Select Factory Reset > Format data/factory reset > Format data. The recovery menu should output the following at the bottom of your screen:

    -- Wiping data...
    Formatting /data...
    Data wipe complete.
    

    ``

  4. Go back to the main menu.

  5. Select Apply Update > Apply from ADB.

  6. On your computer sideload the package using ADB:

    adb sideload lineage-17.1-jasmine_sprout-signed.zip
    
    > * daemon not running; starting now at tcp:5037
    > * daemon started successfully
    > serving: 'lineage-17.1-20200711-nightly-jasmine_sprout-signed.zip'  (~47%) 
    

    ``

    You phone outputs where things are up to:

    Finding update package...
    Opening update package...
    Verifiying update package...
    Update verification package too 48.9 s (result 0)
    Installing update...
    Step 1/2
    Step 2/2
    
    Install completed with status 0.
    
  7. Go back to the main menu.

  8. Select Reboot. Your phone should now boot into LineageOS.

Troubleshooting

Commands don’t do anything

This might have something to do with how your phone is connected to your computer. USB-C seems to be a bit flakey. I connected my phone to a USB-C hub using a USB-C to USB-A cable. That seemed to work.

Installing Open Apps (GApps)

Annoyingly, there’s currently no way to install GApps without rooting your phone.