This guide covers installing the latest version of lineage OS on a fresh Moto G5s. In my experience, the documentation for going through all the steps required to install lineageOS on a given device are scattered, outdated, and typically require a lot of hard-to-meet conditions (like unlocked bootloader and rooted phone). This guide covers all the steps and issues I came accross when installing lineageOS on my new G5s, including rooting and unlocking the bootloader, and installing a custom recovery image.
Note that as of writing this there currently isn’t an official release of LineageOS for this device. However, the unofficial builds are often updated and, in my experience, very stable which makes me think that it’s not far from being listed on the official lineage OS site. The only issues I’ve had is that camera is a bit janky when opened within whatsapp… but this is an issue I’ve also had in the official lineage release one the Samsung Galaxy S6, so I assume this is more of a whatsapp issue. After going through this guide I’d recomend installing the lineage updater app from the play store. Check the updater app every few days; as soon as an offical stable release comes, it’ll start being listed in this app where you can automatically download and flash it.
First off, lets get everything we need in place. Below are lists of requirements we need to get this working and should only take a few minutes to get ready.
- ADB command line tools. Installing this developer toolset will let you upload files to your phone and flash ROMs you download. I’m using linux in this guide, so note that on windows you likely have to install a few additional drivers (listed on the download link). Beyond that, all steps should be the same.
TWRP image. Codename of our device: montata. Version of TWRP to get: 3.2.3-0. TWRP will replace your phones default recovery program. This will allow you to install new software (and operating systems) without any external tools. With TWRP, you can simply download an image, enter recovery mode, then flash a different OS on your device. Just like Lineage, there is currently no official release for the G5s yet. I’ve tested the image linked here and it performed just fine for the steps in this guide.
Latest unofficial release of LineageOS. Do make sure to check the official lineage site to see if an official release has been published since writing this. If the links don’t work, just try googling “LineageOS montana”, where montana is the device code for the G5s.
Go for trustworthy links from the
xda-developersas this is where all the builds are posted when they are released and seems quite reliable in my experience.
- gapps. Lineage OS doesnt come with any google apps like the playstore, which is quite essential. Do remedy this, we’ll have to download and install gapps ourselves from the link. To get the correct version, we need to know what version of android we’re planning to use in addition to what kind of chipset the phone has. We’re installing lineageOS version 14.1, which is based on android version 7.1.2 (Nougat). Using this info, [download] the version of gapps corresponding to ARM and Android: 7.1. I’m downloading the stock version of Gapps, but you can choose which ever suits your needs.
Note: I tried this later on using the micro variant, but then I had no keyboard as gboard was not installed and for some reason the Lineage default keyboard would not activate. To be on the safe side, I reccomend taking the stock variant of gapps.
- SuperUser. This is for rooting lineage OS after you’ve installed it. You should select the version for 14.1 and arm (not to be confused with arm64!). This may not be necessary for you, but since we’ll be crawling around in TWRP anyways, now would be a conveniant time to root your phone.
On your phone, you’ll have to do a few steps to allow us to flash the ROM later.
Enter developer mode. In your settings, navagate to where your Build Number is displayed. This is usually in the (about phone) section of the settings. Tap on Build Number seven times, then you will see a message indicating developer mode has been activated (unless you have done this before, then don’t worry about this step).
Now in your settings, there will be an additional Developer Options sub menu. Go here, and select Unlock OEM, which allows us to replace the recovery tool, and Enable USB debugging. USB debugging will allow us to control the phone via the ADB toolset you installed.
Now we’ll start. First, we need to unlock the bootloader which will give us permission to flash a new recovery tool. To do this, we need to be in fastboot mode. Before we proceed, we’ll verify that your USB connections are working then go into fastboot.
Connect to your phone via ADB
With your phone on, check that USB debugging is activated in phone. When you plug in the USB to your computer you should see notifications like in the following images.
- Now lets check if ADB can communicate with the phone.
Open a terminal (or the cmd app on windows) and change your directory to where your
adbbinary in installed. On Ubuntu, I had to use this command:
These commands will look slightly different on windows.
- Next, run ADB and see if it can see your phone with the following command:
Problem signs you want watch out for here is if no devices are listed, or if there are udev error messages (only on linux). Otherwise… you should one or more devices listed here and you can proceed as normal.
- Finally, now that we have verified our USB connections are working, reboot into fastboot via ADB using the following command:
Your phone will now restart into fastboot mode. If you run into the error in the image below, check the screen of your phone as there is likely a prompt asking you to verify the USB permissions. When you are in fastboot mode, you’ll see something like the image below. Notice the line oem_locked. In the next steps, we’ll change this to unlocked.
Get OEM unlock key from device
To unlock the bootloader, we’ll have to get a unique key form our phone, then use this to register on the Motorola website to recieve the mathcing unlock key we’ll use to unlock the bootloader.
First, check that you have permissions for communicating with the device.
Just because USB debugging works when your phone is on, this does not mean fastboot will also work the same. Run
./fastboot devicesand check to see if the device is listed. When I tried this, I got the following error: If you have the error, the simple solution is to just run both
sudo(this is only on linux). From now on, you’ll see me prepending
sudoto these commands in the rest of the guide. If you don’t suffer from this issue, I would recomend not using
sudounless you have to.
- Now enter the command:
sudo ./fastboot oem get_unlock_data
You should get a key like the image below.
- Take your unlock data and follow the instructions here to get the key you need to unlock your device. Note that you’ll have to register a developer account with motorola to get to this page as they will email you the key you need. It only took a few seconds for me to get the resulting key via email.
Unlock bootloader with new OEM key
Finally, unlock your bootloader with the following command (you’re phone should still be in fastboot mode) and of course replace
[OEM_UNLOCK_KEY] with your actual key value recieved via email:
sudo ./fastboot oem unlock [OEM_UNLOCK_KEY]
You’ll note that the output tells you to rerun the command.
Go ahead and enter the command a second time to get the following result. You will also notice the message
flashing_unlocked on your fastboot screen, like below.
Flash TWRP using Fastboot
Okay, our bootloader is unlocked… that means we can now install our custom recovery ROM: TWRP.
- Lets flash the TWRP image to our phone.
Enter the following command with the appropriate location of where you download TWRP to (out terminal is still in the same directory where
adbwas located in the previous steps):
sudo ./fastboot flash recovery ~/Downloads/twrp-montana-220.127.116.11.img
You’ll see an output like below if it flashed sucesfully.
- Now, on your phone while still in fastboot mode, select
RECOVRY MODEwith the volume keys and press power to select it. When I entered TWRP the first time, it asked me for a finger pattern to unlock. I tried the phone pattern, but this didnt work… but then I pressed cancel and I was able to continue as normal within TWRP. Make sure to stay in TWRP for the next section when we install lineageOS. If you leave and reboot, your phone will likely replace TWRP with the origional bootloader (I know by trial and error). I’m not sure why this happens, but I assume its related to actions in the stock ROMs boot process. If you mess this up, just re-flash TWRP and continue from this point.
Install lineage OS
- We installed ADB on a laptop so we can interface with our phone.
- We used ADB to unlock the bootloader of our device.
- We then flashed the TWRP custom recovery.
Now we’re finally at the important step of installing lineageOS. Flashing images is very quick as you’ve noticed, so we’ll also flash gapps and SuperSU while we’re doing this.
Install lineageOS, gapps, and root phone
- First, lets wipe our system in recovery mode. In TWRP, go to wipe > Advanced Wipe and select:
Then swipe to clear it. This lets us do a clean flash, (as opposed to a dirty flash)
I ran into some quite annoying bugs after installing LineageOS when I tried skipping this step previously.
- While we’re still in recovery mode (i.e. TWRP), lets use
adbto load the files to the phone. Unlike earlier, I no longer have to use
sudohere. The recovery enviroment (TWRP) and the fastboot environment have different permissions, so its not surprising that one works slightly different than the other, at least on linux machines. To load the files, use the commands:
$ ./adb push ~/Downloads/open_gapps-arm64-7.1-stock-20180901.zip / $ ./adb push ~/Downloads/lineage-14.1-20180820-UNOFFICIAL-montana.zip / $ ./adb push ~/Downloads/addonsu-14.1-arm-signed.zip /
The command works like
adb push [location_of_file_to_push] [destination_on_device]. The
/at the end of our commands just tells
adbto drop those files at the root of the phones file system, so we dont have to waste time searching around for it in TWRP.
If you are getting errors like
insufficient permissions from this devicewhen pushing files through adb, try running
sudo ./adb kill-serverto reset adb then retry the above commands with
sudoprepended to them. This allowed me to get around the permissions errors that many seem to have.
In TWRP, select
installand select the lineage OS file we just dropped on your phone (the image shows installing gapps, but it will look the same for lineageOS).
Now do the same with the Gapps package SuperSU. During the last install (SuperSU), select
Wipe cache/dalvikfrom the install options. I’m not sure this is necessary, but this seems to solve issues sometimes.
Now select reboot from TWRP. Before rebooting, it may prompt you to install the TWRP app, swipe to confirm this. Not sure why I need this… but I have a feeling having the TWRP app will be useful down the road.
Now when your phone restarts, you should log into lineageOS for the first time. Proceed as you would on any other new phone to set up you accounts. Since we installed gapps, you should have the google play store included in your lineage OS install.
The steps listed here are exactly what I had to do to get lineageOS installed. Note that different versions of TWRP, SuperSU, and possibly updates of your stock android system may cause some additional issues, so please take into consideration the date this guide was written when following along.
Updated on: 2018-10-17