Replacing Android with LineageOS
Fresh Breath of Life
Breathe new life into your old smartphone: The TWRP recovery image and the free Android offshoot LineageOS let you install the latest security updates every week.
Every mobile device needs its own Android build because of numerous drivers that are not available in the source code. The need to maintain every version of Android for every mobile device means that many manufacturers eventually stop supporting updates. Often, smartphones or tablets that still work perfectly can no longer be used without worry because the manufacturer has simply ceased to offer bug fixes and security updates.
The fact that many drivers for smartphone hardware are not available as source code makes it difficult to provide Android upgrades. The LineageOS project [1], the successor to the CyanogenMod project, which was discontinued in 2016, proves that it is not impossible to keep these devices up-to-date. Unpaid volunteers at LineageOS do the work that many manufacturers do not want to do: They combine current Android releases with the required device-specific drivers.
Dewy
The LineageOS project (Figure 1) provides Android systems with a fresh patch status every month for around 300 devices. The builds are released weekly, unless there is a problem during the build. The Devices page on the LineageOS Wiki [2] provides the details of whether a LineageOS build is available for your smartphone or tablet.
Practically all Android devices support a recovery mode that starts a small, specialized Android system to restore the main system in case of damage. Out of the box, recovery mode only installs the state intended by the manufacturer. Therefore, the first step towards installing an alternative OS such as LineageOS is to flash a manufacturer-independent recovery system. I prefer to use TWRP [3] as a recovery tool because, unlike the recovery system supplied by the LineageOS project, it creates backups of the existing system (Figure 2). TWRP (pronounced "twerp"), is a custom recovery tool for Android phones. TWRP replaces the recovery system provided by the hardare manufacturer, which then allows you to install an independent system such as LineageOS.
Unless you unlock the bootloader, you can't install another recovery system or a full system on the Android smartphone later (Figure 3). As of Android 6, you can enable the OEM unlock or Bootloader unlock item in the Android settings below Developer options | OEM unlock to unlock the bootloader.
If you do not see the Developer options menu item under System | Advanced, tap the Build number displayed at the end of the heading seven times in the About the phone settings category. You also need to enable the USB debugging option for flashing via USB.
However, this procedure does not remove locks set up separately by the manufacturer to prevent the installation of other software and rooting of the smartphone. Some manufacturers require you to register the device to unlock it, and then – after telling you that the warranty is now void – they hand over a code. Others refuse to unlock the device altogether. However, it is probably not possible, in the EU at least, to make the hardware warranty dependent on you not installing your own software. The LineageOS Wiki page for your device [2] also describes how to unlock the bootloader.
Once you have freed the bootloader, it is time to download the necessary software: First, you need the TWRP recovery image [4] for your device. On your Linux computer, install the Android tools (the Ubuntu packages are android-tools-adb and android-tools-fastboot, otherwise it's just android-tools) containing the Fastboot program as a counterpart to the bootloader on the Android device. Working from the PC, the tools load the recovery image into the partition assigned by the manufacturer's recovery routine. Finally, you need an image of the actual LineageOS system, which the recovery routine finally installs on the system partition after a backup.
Right Choice
Android builds – the final LineageOS as well as TWRP – only work on the device they were built for using the Android open source project and numerous proprietary drivers. To make sure you're installing the right image, you need to know the manufacturer's code name for the device. This will help you identify the right images on the LineageOS and TWRP download pages. The app Device ID [5] gives you the name on a running system (Figure 4).
Variants of a basic device type can exist in some cases; they are stated in the Device name line in the About phone tab in Android settings. Normally a build should support all variants, but it doesn't hurt to check the LineageOS wiki page for the device matching the codename to see if your model shows up under Supported models.
Once all the software components are in place, boot the Android device to the unlocked bootloader. Most Android devices (with the exception of Samsung, see the box "Installing TWRP on Samsung Devices") rely on Android's own Fastboot bootloader. The LineageOS wiki explains how to access the bootloader for each device. Usually, you can reach the bootloader by turning off the device and then turning it back on while holding down the Volume Down key.
Installing TWRP on Samsung Devices
Smartphones and tablets by Samsung do not use the Fastboot bootloader, which is otherwise common for Android. Samsung has developed its own Windows tool named Odin for flashing firmware. Fortunately, there is a free Linux port named Heimdall [6]; the popular Linux distributions have Heimdall packages.
Volume Up+Home+Power boots a powered-down device to Download mode, which expects data for flashing via USB. If heimdall print-pit
on the Linux console prints a series of messages and the device finally boots the normal system, then the communication via USB cable between PC and smartphone is working in Download mode.
After turning the device off again, you can switch back into Download mode using the key combination shown above. The command from Listing 1 installs the TWRP recovery image [4] for the model. Then immediately turn off the device by either removing the battery or pressing Volume Down+Power for eight to 10 seconds. Once the screen goes blank, release the keys immediately. On the powered-off device, press Home+Volume Up+Power to start recovery mode with TWRP. You will now be able to flash Lineage via the recovery option just as you would with other Android devices.
Listing 1
Flashing Samsung Devices
$ heimdall flash --RECOVERY twrp-version_number-Devicecode.img --no-reboot
Fastboot fields the data from the PC fastboot
command-line program and writes it to partitions on the mobile device. The prerequisite is a USB connection between the PC and smartphone. After plugging in the USB cable, first run adb devices
to test whether this connection with the bootloader launched as described and the console program works (Figure 5).
The command in Listing 2 installs the TWRP recovery system on the recovery partition. The percentage values displayed at the command line during the transfer often turn out to be not very meaningful. The main thing is that the operation completes without an error message.
Listing 2
Flashing the Image
$ fastboot flash recovery image_file
The factory-installed recovery system is now overwritten. The option to use it to return to the factory state of the smartphone is no longer available. Instead, you can now back up and restore the actual state of the system with TWRP.
Use the volume keys to select which system the currently active bootloader will start. The options START (normal system) and RECOVERY MODE are important. You can start the recovery that you need next right away or make sure the normal system is working to reassure yourself. In this case, turn off the device again and go back to the bootloader.
Data Manager
TWRP recovery comes with a clear graphical interface (Figure 2). First you need the Backup function to save the previous system, which has not yet been replaced by LineageOS. Later on, when you install the weekly LineageOS updates, it always makes sense to back up a version that you know will work up front. The backup only takes a few minutes on a newer device with a sufficiently fast SD card.
The backup screen opens, showing you the partitions System, Data (excl. storage), and Boot preselected for the backup. These settings are correct for a later restore of an entire system. In Select Storage, you now need to select the desired storage medium. The storage medium is usually not Internal Storage but an SD card.
Many users move the large backups to the PC immediately after they have been created. You will find the data on the storage medium below TWRP/BACKUPS/<
DEVICE ID>/
in a directory with a name that starts with the date and time and contains a system name such as lineage
. To restore a backup, restore this folder to the same location. The backups will then appear as a list in the TWRP Restore function. After selecting a backup, all you do to restore it is drag a slider to the right. If a file selector appears instead of the list of existing backups, use Select Storage to switch between Internal Storage and SD Card.
A file manager is available on the TWRP home screen after you select Advanced (Figure 6). You can access the home screen at any time via the button at the bottom of your screen. Using the file manager is not immediately intuitive: For example, it is important to know that the contents of the SD card can be found in /data/media/0/
, including the aforementioned TWRP/
folder. To delete a backup subfolder, open it and tap Select Current Folder bottom right. The file manager then displays the Delete option (line top right in Figure 6).
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.