Solution for screen tearing in X11

burned televison

Burned out by Tina Rataj-Berard

I often see online people complaining that we have to get rid of X11 and start using Wayland because Wayland fixes the screen tearing on Linux desktop. I scratch my head as there have been solutions for screen tearing on X11 for years. I want to show you a simple solution to tackle screen tearing, but it depends which GPU your machine has.

Intel and newer AMD cards

Intel and AMD has made it really simple!  Basically just enable the TearFree option with this line in your X11 configuration:

Option "TearFree" "true"

I recommend to create a new configuration file in /etc/X11/xorg.conf.d/ for example 20-intel.conf or 20-amd.conf. The file could look like this:

# If Intel:
# /etc/X11/xorg.conf.d/20-intel.conf
Section "Device"
    Identifier  "Intel Graphics"
    Driver      "intel"
    Option      "TearFree" "true"
EndSection

# Or if AMD:
# /etc/X11/xorg.conf.d/20-amd.conf
Section "Device"
    Identifier  "AMD"
    Driver      "amdgpu"
    Option      "TearFree" "true"
EndSection

Then reboot (or just restart your X server) to apply these settings. On AMD this works on newer cards which use the new AMDGPU driver.

Older AMD cards

This is for older AMD cards which use the Radeon driver. The line in the X11 configuration looks similar:

Option "TearFree" "on"

Include this to the configuration file in /etc/X11/xorg.conf.d/:

# etc/X11/xorg.conf.d/20-radeon.conf
Section "Device"
    Identifier  "Radeon"
    Driver      "radeon"
    Option      "TearFree" "on"
EndSection

Then reboot or restart your X server.

NVIDIA cards

On NVIDIA running with the proprietary drivers I would recommend using the nvidia-settings tool instead of editing the X11 configuration files yourself. The nvidia-settings application gives you nice graphical user interface to manage all the settings you need. Using the application, first click “X Server Display Configuration” from the menu on the left and then click the “Advanced…” button:

Then click the checkboxes for “Force Composition Pipeline” and “Force Full Composition Pipeline:

Then click the button “Save to X Configuration File” and restart your X server to apply the new settings.

If all else fails

Above solutions should work 98% of the time (that number was pulled out of my arse), but I’ve heard that for some people they don’t. Also if you’re running NVIDIA hardware with the free Nouveau drivers, the above won’t work. Then the last solution is to run an external compositor. If you’re desktop environment doesn’t offer you proper one (disable that one before running this one), I would recommend using compton. Compton should be available from your distributions repository and it has quite many options to choose from. From my experience these options work fine:

compton -b --vsync opengl-swc --backend glx

Compton won’t perform as well as solutions mentioned before should. It is worth trying is nothing else works. Compton doesn’t require you to restart your X server and the changes should apply immediately.

SSD tips and tweaks

Hard drive

Endangered technic. photo by Patrick Lindenberg

SSD work fine out of the box and most optimisations aren’t really necessary, but I think these are useful if you want to increase the life-time of your brand new SSD.

Swap on SSD

If you have enough RAM that you don’t need swap (and you don’t need to hibernate instead of suspend) it might be good idea to disable swap completely. To do this, we can just comment out the line for swap partition in /etc/fstab'(example on my machine):

UUID=a495548e-1d7e-464b-8072-bdc43d07d3a5 none swap sw 0 0

Just add “#” in the beginning of the line:

#UUID=a495548e-1d7e-464b-8072-bdc43d07d3a5 none swap sw 0 0

If you don’t have too much RAM or you need to hibernate your machine, better action is just to reduce the swappiness. This way the swap is used only when necessary. Add this line to your /etc/sysctl.conf:

vm.swappiness=1

Root directory on SSD

This is where you will notice the most benefit over spinning disk. This is where you can reduce writes as well as on root directory you probably won’t need access time logging (some applications might need it on home directory) which would just create a lot of unneeded writes. Let’s edit out /etc/fstab again and add ‘noatime’ flag to line for our root directory:

UUID=bbc3a677-386a-40cb-b89c-fdf2ceb97cab / ext4 noatime,errors=remount-ro 0 1

Deadline I/O scheduler

By default Linux uses the CFQ I/O scheduler which is desirable for spinning disks, but it isn’t optimal for SSDs. For SSDs I would recommend using the Deadline scheduler. First find out which disk on your machine is SSD:

$ grep . /sys/block/sd?/queue/rotational
/sys/block/sda/queue/rotational:1
/sys/block/sdb/queue/rotational:1
/sys/block/sdc/queue/rotational:1
/sys/block/sdd/queue/rotational:0

Look at the number at the end of the line. This shows the /dev/sdd is SSD on my machine as “rotational is false”. Find out the current scheduler on this disk:

$ cat /sys/block/sdd/queue/scheduler
noop deadline [cfq]

Oh okay! Let’s set it to deadline by adding this line to /etc/sysfs.conf

block/sdd/queue/scheduler = deadline

It should apply on next reboot. To set the scheduler without rebooting (this change will reset unless you set the scheduler in /etc/sysfs.conf):

# echo deadline > /sys/block/$YOURDRIVE/queue/scheduler

Now it should look like this:

$ cat /sys/block/sdd/queue/scheduler 
noop [deadline] cfq

TRIM

There are several ways to do TRIM on Linux, but some of them (discard option fstab) might damage your SSD if it has buggy firmware. Using fstrim should generally be safe on all SSDs. To set fstrim to TRIM your SSD regularly first save this script:

#!/bin/sh
fstrim -v /

to /etc/cron.daily/trim or /etc/cron.weekly/trim depending whether you want TRIM done daily or weekly. On my machine it is done weekly, but if it isn’t often enough for you – do it daily.

Free your Android from Google

Google analytics phone

Google analytics phone photo by Edho Pratama

UPDATE 2018-01: This is somewhat outdated as microG has released their own fork of LineageOS. See details below.

microG has released their own fork of LineageOS which can be accessed here! This makes microG easier to handle as now you don’t have to apply signature spoofing to your ROM each time you reboot your device. This fork of LineageOS can be installed same way upstream LineageOS is. Now you have microG and F-Droid preinstalled and ready to go!


Many people try to avoid Google products and services for different reasons. Even people who like Android, use iOS or something else instead because of this. But you can actually run Android without Google’s proprietary software. Okay, how do we do this? We are going to install these on your device:

  • TeamWin Recovery
  • LineageOS
  • F-Droid
  • Yalp Store
  • microG

We are going to need these on your computer:

  • ADB and fastboot
  • Java Runtime Environment
  • Python

If you do not need proprietary apps (like Whatsapp or Instagram) on your phone, Yalp Store and microG are not needed.

Let’s begin

Pretty much every Android device has Google apps installed by factory default, and removing them from the stock ROM is quite troublesome, even though possible. To make things easy (and most likely more free) we are going to install LineageOS your device. LineageOS is based on Cyanogenmod which you have probably heard of and does not include Google apps for legal reason, but that’s what we want. Fetch a ROM zip file for your device from the LineageOS download site. Also download the su addon zip file if needed, as LineageOS doesn’t provide root access without it.

Flashing the LineageOS ROM requires a recovery software. For this purpose we are getting the TeamWin Recovery. Find the .img file for your device from their website.

Flash it!

CautionFlashing images on your device will overwrite data and in wrong hands can brick your device. Steps in this guide work on my Nexus 5X and should work identically in other Nexus devices too, but some things might be different on your non-Nexus device (for example Odin and Heimdall for Samsung devices). Backing up your data is strongly recommended before continuing.

Enable Developer options and unlock bootloader

On vanilla noncustomized Android, like on Nexus devices, you can enable Developer options by tapping the Build number row in About phone section in your Settings app until you get a message on screen saying that you have enabled your developer options.

Under the Developer options you should be able to toggle OEM unlocking on to allow the bootloader to be unlocked. In the Developer options also enable ADB by turning Android debugging on. After you have done that, let’s try connecting your device:

$ adb devices

This should print:

List of devices attached 
01105e0bf43020b8 device

If similar output was printed, we know we have adb connection. Let’s reboot to bootloader:

$ adb reboot bootloader

When the device has booted to bootloader, we can open the locking the bootloader (this will wipe all your user data on the device):

$ fastboot oem unlock

Your device should ask if you are sure you want to unlock the bootloader. Once this is done:

$ fastboot reboot

Flash the recovery

Let’s get back to the bootloader:

$ adb reboot bootloader

In the bootloader we will flash the previously downloaded .img file for TWRP recovery

$ fastboot flash recovery twrp.img

Flash the LineageOS

Reboot to your new recovery mode:

$ fastboot reboot recovery

To flash the LinegeOS, we need to copy it over to your device somewhere convenient:

$ adb push lineage-signed.zip /sdcard/

If you downloaded the su .zip file, copy it using the same command.

TWRP has really nice touch interface, which you can easily use to install your actual OS rom to your device. It’s generally recommended to wipe data on the device before flashing the rom.

After wiping, pressing the Install button opens a file browser, where you have to select the .zip file for LineageOS. It should be in the directory that opens up first, if you copied it to /sdcard/. After the LineageOS .zip you can select the su .zip file to make it flash after LineageOS. After flashing TWRP gives you an option to reboot to your freshly flashed system.

If everything went right, you are now using LineageOS! Now you can setup your device again, as all the old data and apps are gone.

How do you live without the Play Store?

For this purpose we have F-Droid, where you can find all the most important free and open source apps for Android. Most of the basic needs are already filled by LineageOS like a web browser and an email app. Download F-Droid from the F-Droid website and install the app on your device. This requires that you have enabled Unknown sources in the security settings.

F-Droid only includes free and open source apps. If this is all you need, you have a ready to use your device!

But if you need Whatsapp or Instagram or any other non-free proprietary apps, you can install the Yalp Store from F-Droid. Think of Yalp Store as unofficial Google Play Store which you can use to get all your (possibly proprietary) apps you cannot find on F-Droid.

Tingle and microG

As you install proprietary apps in Yalp Store you will notice that many apps depend on Google Play Services package. microG provides the Google Play Services API for these apps without installing the actual Google Play Services package. microG does use Google servers to work even if microG itself is free software. To trick apps to use microG instead of the real Google package, we have to apply some signature spoofing using Tingle.

Download Tingle using the Github .zip archive or clone the git repository. From the Developer options on your device give root access to adb, connect your device to USB again and run Tingle:

$ python3 main.py

And select the first option so Tingle will handle your device through adb. When Tingle has run successfully, reboot your device. As your hands are still on the keyboard, you can reboot using this command

$ adb reboot

If your device doesn’t boot after running Tingle (it should boot longer than usual though), your device might not be supported by Tingle. Fortunately the changes Tingle made can be reverted easily using the command Tingle printed once you boot to recovery mode.

After this you can install microG from F-Droid. You should install these apps:

  • microG Services Core
  • microG Services Framework Proxy (if you need Google Cloud Messaging for push notifications)
  • FakeStore
  • microG DroidGuard Helper (if you need Google SafetyNet)
  • Your favourite NlpBackend, I recommend MozillaNlpBackend (if you need location service)

Now you shoud have microG settings in your app drawer. There you can apply the settings you need. After that you should reboot your device.

Got it!

Now you device is ready to use! If you installed Yalp Store and microG, your device is still connecting to the Google servers, but the connection is at least in your control. Also your battery life should improve!

If you skipped installing Yalp Store and microG, your Android experience is now completely degoogled. Yay!