Thinkpad X1 Extreme

Ubuntu 18.04 on Thinkpad X1 Extreme

My X1 Extreme shipped with a 1.09 BIOS version - with that BIOS version booting Linux is not really possible. Tried Ubuntu 18.04 and 18.10, also Pop! OS 18.04 and Pop! OS 18.10 - all got stuck during boot. Ubuntu just stopped booting with some weird ACPI errors. Pop! OS at least got a bit further, but then hang.

BIOS update

First, a BIOS update was necessary (also, a lot of web postings mention risk of bricking the machine when changing thunderbolt settings or switching discrete/hybrid graphics).
Here is what I've tried:

  1. Downloaded iso-image (BIOS version 1.19), burned it on CD and ran BIOS update via external DVD-drive attached to USB. Got to the point were the flashing starts, but then the software aborted with a message "ERROR: Process did not complete." (no reason, no explanation...).
  2. Made a bootable USB-stick with the iso image using El Torito (see instructions at http://positon.org/lenovo-thinkpad-bios-update-with-linux-and-usb). Same result, error during flashing of BIOS.

Thankfully, the error didn't break anything. The pragmatic approach was now to use Lenovo System Update (which only runs on Windows). So, installed Windows 10, downloaded Lenovo System Update, ran it and installed all driver updates including all firmware and BIOS patches.

Installing Linux

I have Windows on the first SSD (Windows installer created three partitions, the second holding the efi-bootloader). Linux goes to the second SSD. Given the good reviews I got from Pop! OS, I started installing Pop! OS 18.04 to test the hardware support.

According to the recommendations in the web, I first switched in the BIOS the Graphics to "Discrete Graphics" before installing. Boot method is UEFI, then legacy. During installation, I could not select the Windows boot/efi partition as target for /boot/efi (installer complained that the partition were too small). Had to create an own 512Mb partition for /boot/efi as first partition on the second SSD.
Installation went smoothly and graphics worked well right from the start (Pop! OS contains fairly new nvidia drivers precompiled in their kernel).

Problem was: there was no boot menu. Managed to adjust the bootloader timeout, so that the boot menu appears. But no Windows in the boot loader and I couldn't find a way to get Pop! OS to update its boot menu.

Ubuntu 18.04.2

Since Pop! OS is based on Ubuntu, I tried installing Ubuntu 18.04.2 LTS next (actually, the latest Ubuntu release, since 18.10 is already a few weeks older). Again, installation was done with discrete graphics selected, UEFI boot mode as default.
During the installation I chose "Something else" in the installation choice screen. Then I created a "/" root partition and swap partition (16 GB at end of disk) on the second m.2 SSD. The first disk (with Windows) I selected as target for the boot loader.
After the installation, everything looked nice. Actually, the nouveau drivers were being used and still the system ran stable without any problems. GRUB-bootmenu showed Linux and Windows and I could boot both OS.

Disabling Windows Quickstart

Having very fast SSDs there is no need for the fast boot feature. In Windows, I turned off Fast Boot (see instructions).

Installing propriatory nvidia drivers

When switching in BIOS from discrete to hybrid graphics, booting Ubuntu doesn't work anylonger (system hangs during boot).

Note: to avoid hangs when something is wrong with the graphics drivers, you can press 'e' in the GRUB menu and insert `nomodeset` after the `splash` option in the linux boot line. Then press CTRL+X to boot with just Intel drivers.

During installation boot with discrete graphics enabled. Start the live-system, setup network connection and then install with propriatory drivers and updates enabled during install.

After booting the newly installed system the first time, install the propriatory nvidia drivers. Since I had problems with the nvidia-390 driver, I suggest using the most recent one.

First add the repository for updated graphics drivers:

> sudo add-apt-repository ppa:graphics-drivers/ppa
> sudo apt-get update
Then, you can check which drivers match your system:
> ubuntu-drivers devices
gives on my machine:
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001C8Csv000017AAsd00002267bc03sc00i00
vendor   : NVIDIA Corporation
model    : GP107M [GeForce GTX 1050 Ti Mobile]
driver   : nvidia-driver-410 - third-party free
driver   : nvidia-driver-418 - third-party free recommended
driver   : nvidia-driver-396 - third-party free
driver   : nvidia-driver-415 - third-party free
driver   : nvidia-driver-390 - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

I installed the recommended driver:

> sudo apt install nvidia-driver-418
UPDATE: just installed the new version 430 of the driver - works perfectly so far.

Now I could boot Linux with either discrete or hybrid graphics in the BIOS settings. You can test if the driver is working correctly with:

> sudo nvidia-smi
which gives
Fri Mar 29 17:50:53 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.56       Driver Version: 418.56       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 105...  Off  | 00000000:01:00.0  On |                  N/A |
| N/A   47C    P8    N/A /  N/A |    673MiB /  4040MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      3302      G   /usr/lib/xorg/Xorg                           257MiB |
|    0      3445      G   /usr/bin/gnome-shell                         272MiB |
|    0      3649      G   /usr/bin/nextcloud                            11MiB |
|    0     16306      G   krusader                                       1MiB |
|    0     21161      G   ...quest-channel-token=6673354144912086020    48MiB |
|    0     24101      G   ...-token=E7C04B3E75389DAC2ACA4279685CC90F    78MiB |
+-----------------------------------------------------------------------------+

Improving battery life

On Windows the hybrid graphics/Optimus feature causes the desktop to use only intel graphics and thus get really long battery time.

On Linux, the desktop is using the NVidia card by default. When "hybrid graphics" in enabled in the BIOS, you can switch between intel and nvidia mode with the following commands:

> sudo prime-select intel
and back to NVidia with
> sudo prime-select nvidia
Current setting can be queried with
> sudo prime-select query

The change will get in effect after logout/login or sometimes after a reboot.

Note: I had trouble to use the HDMI port to connect an external screen, even when I rebooted after selecting nvidia PRIME drivers (when using GDM3 login manager). The only reliable way was to use
> sudo nvidia-settings
and switch between intel and NVidia drivers using the dialog. After logging out and logging back in (when switching from intel to NVidia) the HDMI port worked and the screen config could be changed with GNOME settings and the Special+P shortcut.

To avoid the problems mentioned above for gdm, you can install another display manager, for example lightdm.

> sudo apt install lightdm

After the installation you can select the login manager to use. Later, you can switch between login managers with:

> sudo dpkg-reconfigure gdm3
or
> sudo dpkg-reconfigure lightdm
.

With lightdm you can now quickly switch between intel and nvidia with the

> sudo prime-select <intel|nvidia>
command line.

Even more convenient is the use of the gnome extension Argos switcher (see below).

Battery Charging Thresholds (extend battery life)

The power utility tlp can be configured to start and stop charging at given percentages. If charge the battery to full every time, especially when working on a docking station, this may reduce battery life significantly. If instead you stop charging at, say 80%, the battery capacity will remain high for a longer time. If this is the case with the X1 Extreme battery, I can't really tell already now. But since the battery is built-in and takes some more effort to change, it is probably worth the effort.

Follow the steps on https://linrunner.de/tlp to install the tool, which comes down to:

> sudo add-apt-repository ppa:linrunner/tlp
> sudo apt install tlp acpi-call-dkms  

Note: The acpi-call-dkms package is needed for ThinkPad notebooks.

Next you need to configure the charge thresholds, for that edit the config file:

> sudo nano /etc/tlp.d/00-template.conf
and add two lines:
# 00-template.conf - Template for TLP drop-in customizations
# See full explanation: https://linrunner.de/en/tlp/docs/tlp-configuration.html
#
# PARAM="value"
START_CHARGE_THRESH_BAT0=75
STOP_CHARGE_THRESH_BAT0=80

Save the file and restart tlp with

> sudo tlp start
. If you now run the command
> sudo tlp-stat -s -b
you should see:

--- TLP 1.3.1 --------------------------------------------

+++ System Info
System         = LENOVO ThinkPad X1 Extreme 20MGS0EQ00
BIOS           = N2EET43W (1.25 )
Release        = Ubuntu 18.04.4 LTS
Kernel         = 5.4.0-42-generic #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020 x86_64
/proc/cmdline  = BOOT_IMAGE=/boot/vmlinuz-5.4.0-42-generic root=UUID=24d3b7f3-2f2e-4518-8fe4-bbbb9e812d42 ro quiet splash vt.handoff=1
Init system    = systemd v237
Boot mode      = UEFI

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 10:07:37,    104 sec(s) ago
Mode           = AC
Power source   = AC

+++ Battery Features: Charge Thresholds and Recalibrate
natacpi    = active (data, thresholds)
tpacpi-bat = active (recalibrate)
tp-smapi   = inactive (ThinkPad not supported)

+++ ThinkPad Battery Status: BAT0 (Main / Internal)
/sys/class/power_supply/BAT0/manufacturer                   = Celxpert
/sys/class/power_supply/BAT0/model_name                     = 01AY969
/sys/class/power_supply/BAT0/cycle_count                    =    173
/sys/class/power_supply/BAT0/energy_full_design             =  80400 [mWh]
/sys/class/power_supply/BAT0/energy_full                    =  68140 [mWh]
/sys/class/power_supply/BAT0/energy_now                     =  54190 [mWh]
/sys/class/power_supply/BAT0/power_now                      =      0 [mW]
/sys/class/power_supply/BAT0/status                         = Unknown (threshold may prevent charging)

/sys/class/power_supply/BAT0/charge_start_threshold         =     75 [%]
/sys/class/power_supply/BAT0/charge_stop_threshold          =     80 [%]
tpacpi-bat.BAT0.forceDischarge                              =      0

Charge                                                      =   79.5 [%]
Capacity                                                    =   84.8 [%]

The output shows nicely, how the charge threshold works. If you want to charge the battery to full, for example when you are about to embark to a longer journey into the wild without sockets, you simply run:

> sudo tlp fullcharge
and the battery will be charged to full.

Critical Battery Threshold and Action

To change what happens when battery is low and when this should happen, you need the gnome config editor. Install with:

> sudo apt install dconf-editor

Then run the dconf utility and navigate to: org -> gnome -> settings-daemon -> plugins -> power. There, you can modify the entries:

Since suspend doesn't work reliably with the ThinkPad thunderbold dock (firmware problem?), I suggest setting hibernation at 5%.

Other hardware

The built-in hardware of the X1 Extreme works otherwise as expected (except the fingerprint sensor). Other stuff needed a bit more work:

Logitech Unifying Receiver

The control software Solaar needs to be downloaded (Ubuntu package is broken). Download from https://pwr.github.io/Solaar, extract and run setup.py with sudo.

GNOME Configuration

GNOME Extensions

For productivity, you need the gnome extensions. First the shell extensions:

 sudo apt-get install chrome-gnome-shell

Then open Firefox, navigate to https://extensions.gnome.org and install the browser extension. You also need the following packages:

> sudo apt-get install gir1.2-gtop-2.0 gir1.2-networkmanager-1.0 gir1.2-clutter-1.0

I use the following extensions:

system-monitor notes

For the extension system-monitor a few things need to be done, first. To get the temperature display to work, you need the lm-sensors package:

> sudo apt install lm-sensors
Initialize with
> sudo sensors-detect
and test:
> sensors
Afterwards you can install the extension, which will, however, show 'NaN' for temperatures. This is fixed in the development version, so you need to get the most recent source from https://github.com/paradoxxxzero/gnome-shell-system-monitor-applet and install manually (download, extract, run make install in toplevel dir).

GNOME Shortcuts

Einstellungen->Geräte->Tastatur: - "Fenster wechseln" -> Tastenkombi "Alt+Tab" einstellen (und damit Tastenkombination für "Anwendung wechseln" ersetzen)

Software

Here are a few notes on the software that I use (mostly for myself).

General tools and utilities

> sudo apt install gdebi p7zip-full htop okular
Note: gdebi is a more complete deb-package installer (handles dependencies more robustly).

NextCloud

> sudo add-apt-repository ppa:nextcloud-devs/client
> sudo apt install nextcloud-client

Atom

> wget -O atom-amd64.deb https://atom.io/download/deb
> sudo gdebi atom-amd64.deb
Data migration: copy the ~/.atom directory

Thunderbird

Data migration: copy the ~/.thunderbird directory and copy ~/.gnupg for all the pgp/SMIME keys.

Lyx/Latex

First tex and helper tools:

> sudo apt install texlive-full jabref texmaker

Lyx is not taken from official repo, but instead downloaded here: https://wiki.lyx.org/LyX/LyXOnUbuntu.

> sudo add-apt-repository ppa:lyx-devel/release
>sudo apt install lyx

imagemagick security fix

There is a nasty problem with imagemagick that results in two distinct errors in Lyx and pdflatex: when inserting a pdf image into a Lyx document, you get the error that it cannot show the pdf. When you build the Lyx file via pdflatex, you get a pdftex error. Both are related to a security measure introduced in imagemagick.

To fix this, you need to edit the file

/etc/ImageMagick-6/policy.xml
so that the following lines are commented out:
  <!-- disable ghostscript format types -->
  <!-- <policy domain="coder" rights="none" pattern="PS" /> -->
  <!-- <policy domain="coder" rights="read | write" pattern="EPS" /> -->
  <!-- <policy domain="coder" rights="read | write" pattern="PDF" /> -->
  <policy domain="coder" rights="none" pattern="XPS" />
  <!-- <policy domain="coder" rights="read | write" pattern="LABEL" /> -->

AsciiDoctor and AsciDocFX

Copy `AsciidocFX.png` icon file to
/path/to/AsciidocFX/AsciidocFX.png
and create desktop file with content:
[Desktop Entry]
Name=AsciidocFX
Exec=/path/to/AsciidocFX/AsciidocFX
Icon=/path/to/AsciidocFX/AsciidocFX.png
Shell=true
Terminal=false
Type=Application
Categories=Office;WordProcessor;Publishing;
StartupNotify=true
save at
~/.local/share/applications/AsciidocFX.desktop
and change permissions to +x.

Gimp + Graphics software

> sudo apt install gimp inkscape
The screenshot-tool shutter is installed via package-repository:
> sudo add-apt-repository ppa:shutter/ppa
> sudo apt update && sudo apt install shutter

Webbrowser

Opera, download deb from https://www.opera.com/de/download and install.

File management

I use krusader:

> sudo apt install krusader keepassx kompare \
    kio-extras kwalletmanager

Start Krusader and run initial config (note: icons are missing).
Install icon theme:

> sudo apt install breeze-icon-theme-rcc
Copy icon file:
> cp /usr/share/icons/breeze/breeze-icons.rcc ~/.local/share/krusader/icontheme.rcc

Restart Krusader, and icons are in place.

Settings:
Allgemein -> Terminal:

> gnome-terminal --working-directory %d --name %t
Allgemein -> Betrachter/Editor:
> /usr/bin/gedit
Benutzeraktionen -> Terminal für Benutzeraktionen:
> gnome-terminal --working-directory %d --name %t -e
Desktop Icon, create file ~/.local/share/applications/krusader.desktop with content:
[Desktop Entry]
Name=Krusader
GenericName=File Manager
Exec=krusader
Icon=krusader_user
Terminal=false
Type=Application
Categories=Qt;Utility;

Software Development

>  sudo apt install qt5-default cmake subversion git \
    meld kompare libqt5svg5 libqt5svg5-dev libqt5serialport5 libqt5serialport5-dev

Up-to-date Qt version

Open source version of Qt5 from https://www.qt.io/download-qt-installer

SmartSVN and SmartGIT

Download from Webpages: https://www.smartsvn.com and https://www.syntevo.com/smartgit/download.

For SmartSVN 9.1 you need the following fix:

Note: Edit smartsvn.sh. There you will find a line nearly at the bottom
export LD_LIBRARY_PATH=${_SUBVERSION_LIBRARY_PATH}:${LD_LIBRARY_PATH} 
Please uncomment this line by adding a leading #.

After starting SmartSVN, edit preferences and in Authentication -> SSH section select "Use system SSH" so that you can use your ssh-agent keys.

WingIDE and Python

Python 3 and PyQt5:
>  sudo apt install python3 python3-pyqt5
Download WingIDE personal from https://wingware.com/downloads/wing-personal.