Install
Arch Linux
with
KDE Plasma
on a
Lenovo X220 Tablet


This is a guide to install Arch Linux with KDE Plasma on a Lenovo X220 Tablet laptop.

Using the stylus in GIMP, with pressure sensitivity. Here's a higher-resolution version of the video.

The video showcases the laptop in tablet mode, using some of the customizations this guide describes:

Especially the first half of this guide contains instructions that can also be found in the excellent ArchWiki entry. A few steps in this guide here are simpler than in the ArchWiki since they only have to work on this specific laptop, not on any other machine.

In the second half, we'll go beyond what's covered in the ArchWiki and configure the laptop's tablet mode.

Table of Contents

Write Installation Image to USB Drive

For this step, you'll either use the operating system currently running on your Lenovo X220 Tablet or a different computer.

Download the Arch Linux ISO file from here, preferably via BitTorrent.

After plugging in a USB drive, make sure it's not mounted. If you're already running Linux, you can unmount with umount /run/media/$USER/*. Then, with lsblk -fs find out the name of your USB drive device, it starts with "sd". Historically, this stood for "SCSI disk" but also refers to USB drives nowadays. Assuming your drive is "sdb", write the ISO image to the USB drive using dd:

dd bs=4M if=path/to/archlinux.iso of=/dev/sdb status=progress oflag=sync
The option oflag=sync causes dd to use synchronized I/O for data and metadata: Each time a block of 4 MiB is written, the data from the operating system's caches is flushed to the USB drive. If dd is not available on your system, have a look here for other ways to get the ISO image on a USB drive.

Boot the Live USB Drive

Plug the USB you just used into your Lenovo and, if available, also an Ethernet cable to get internet access. Press F12 immediately after powering up the Lenovo. In the boot menu provided by the BIOS, select the USB drive with Arch Linux on it. After booting Arch Linux, you're logged in automatically as root.
Select boot media in BIOS to start Arch Linux
Select your USB drive in the BIOS.
Boot Arch Linux from live USB
Let's boot Arch Linux from the USB drive.

Connect to the Internet

If you had an Ethernet cable plugged in while booting, you should already be connected to the internet. Make sure by running ping archlinux.org. If you've plugged in an Ethernet cable after booting, you can configure network access (including getting an IP address) by running dhcpcd.

In case you want to connect wirelessly to a network, first find out the name of your WLAN interface by running ip link. It's called wlan0 or wlp3s0 for example. Assuming your interface is wlan0, your network's SSID is myRouter, and your password is verySecretPassword, this is how you'd connect to the network:
wpa_passphrase myRouter verySecretPassword | wpa_supplicant -B -i wlan0 -c /dev/stdin; dhcpcd wlan0
To verify you're connected to the internet, check if you get responses when running ping archlinux.org.

Set the Time

Your computer's clock might be incorrect. Check by running date or timedatectl status. Since we have internet access now, we can make use of the Network Time Protocol to synchronize the time on your computer with servers that provide the current time:
timedatectl set-ntp true
After running timedatectl status, you should see that the time on your laptop is accurate and the value of "NTP service" is "active".

Partition the Disk, Format the Partition

If you want to back up preexisting data on the Lenovo's disk, now's the last chance. After completing this section, data on your disk will be much harder to extract or lost entirely.

fdisk -l should show the laptop's disk at /dev/sda. Partition it by calling fdisk /dev/sda and following these steps:
  1. Create a new DOS partition table with o.
  2. Create a new partition with n, select p to make the partition a primary one.
  3. Select partition number 1, that's the default.
  4. Select 2048 as the partition's first sector (also the default). A sector in our case is 512 bytes.
  5. In the next step, fdisk uses the last sector of the disk as the partition's last sector per default. You can keep that default or have a smaller partition by entering "+80G", for example, to create a partition with 80 GiB.
  6. Finally, write the changes to disk with w.

This creates a partition at /dev/sda1, which you can verify with fdisk -l.

In the first step in fdisk you selected to create a DOS partition table. This means fdisk wrote the Master Boot Record (MBR) to the first 512 bytes of the disk. The MBR contains the location of the partitions on the disk (we only have one partition). As we'll see in the section on GRUB, the MBR will also contain a little bit of code that loads parts of the GRUB bootloader, whose task it is to boot our operating system.

Now that we have a partition on the disk, we can format the partition with the ext4 file system:
mkfs.ext4 /dev/sda1

To convince yourself that the partition now has an ext4 file system, call lsblk -fs and check the value of FSTYPE for /dev/sda1.

Having a formatted partition on the laptop's disk enables us to store files on it. But we also have to make the partition accessible to the operating system that runs from our USB drive. We do so by mounting the partition:
mount /dev/sda1 /mnt
To automatically mount the partition when booting, we'll generate a file system table (abbreviated "fstab"):
genfstab -U /mnt >> /mnt/etc/fstab

Install Packages

Open the file /etc/pacman.d/mirrorlist with vi or nano and put a server's URL which is close to you at the top. The first server per default is in Melbourne, Australia which, depending on where you are in the world, might incur significant lag when downloading packages.

I use the following server, which happens to also work with HTTPS:
Server = https://packages.oth-regensburg.de/archlinux/$repo/os/$arch
We'll download and install a couple of packages, including KDE Plasma, onto the partition we formatted and then mounted at mnt in the previous step:
pacstrap /mnt base base-devel linux linux-firmware grub plasma vi sddm sudo networkmanager man packagekit-qt5 konsole
Some short explanations for a few of these packages: We'll see the reason for the other packages in the next steps.

Set up Your System

For the following steps, you need to set the root of your filesystem to the previously created partition /dev/sda1 which we mounted at /mnt. Do this with arch-chroot /mnt.

Install GRUB as the Bootloader

After powering on your laptop, there are couple of steps necessary till you can log in to Arch Linux. Some of these steps are handled by the GRUB bootloader. Fortunately, getting GRUB ready is done in only two commands:
grub-install --target=i386-pc /dev/sda && grub-mkconfig -o /boot/grub/grub.cfg

Don't let the i386 part throw you off: Your operating system is 64-bit.

Overview of How Arch Linux Boots with GRUB

This section provides a cursory explanation of how the boot process works with GRUB on the X220 Tablet. If you're only interested in getting Arch Linux running and have already installed the bootloader in the previous step, you can safely skip this section and continue here.

The command grub-install writes code and files to a couple of places:
  1. boot.img: This is code written to the master boot record (MBR). The MBR is a region taking up the first 512 bytes of our disk /dev/sda. The job of boot.img is to load core.img.
  2. core.img: more code that comes after the MBR but before our partition /dev/sda1 which starts at sector 2048. We've set the partition's start sector when creating it with fdisk. The job of core.img is to load the normal module at /boot/grub/i386-pc/normal.mod. Since core.img needs to work with file paths, it contains code to access file systems.
  3. the directory at /boot/grub/ which lives on our partition /dev/sda1. This directory contains the normal module. This module executes /boot/grub/grub.cfg which we created with grub-mkconfig.

The file /boot/grub/grub.cfg is a shell script that displays the available operating systems in a textual menu after powering up. Once you've selected an operating system, grub.cfg boots it. In our case, we only have one operating system, Arch Linux, whose kernel is a file at /boot/vmlinuz-linux.

GRUB's menu for starting Arch Linux, defined in /boot/grub/grub.cfg
GRUB's menu for starting Arch Linux, defined in /boot/grub/grub.cfg.
Assuming the BIOS chooses the /dev/sda drive as the boot device (you can change the boot device in the BIOS' boot menu), here is the chain of programs that start Arch Linux where the program on the left side of the arrow executes the one on the right:

BIOS → boot.imgcore.img/boot/grub/i386-pc/normal.mod/boot/grub/grub.cfg/boot/vmlinuz-linux

To get a better understanding of the boot process, this graphic shows the physical components of your laptop where those programs exist (not to scale):

Left: BIOS EEPROM chip L08. Right: GRUB in MBR and partitions on an Intel SSD 320 Series 160GB
Left: BIOS EEPROM chip L08.
Right: GRUB's files in the MBR, after the MBR, and on partitions on an Intel SSD 320 Series 160GB.

You can see that grub-install writes core.img into the gap between the MBR and the beginning of the partition /dev/sda1. This area is neither part of a partition nor formatted with a file system. Instead, grub-install writes core.img's location on the disk to the MBR.

Where exactly on the disk is core.img? I used this answer to find out on my disk it starts at byte 512, which is sector 1.

You can learn more about GRUB in its manual. For a look inside the MBR, check out this page.

The BIOS chip on the Lenovo X220 Tablet is the EEPROM labelled L08, soldered to the top left of the system board, next to the fan. Here are images of the X220's system board with the BIOS chip pointed out.

Reboot and Install Applications

After GRUB is installed, you can exit chroot with exit or pressing Ctrl+d. Unmount the partition with umount /mnt then reboot.

When the system has booted, SDDM should present you with a login screen. Log in with the password of your regular user. Once logged in, you can pick an image for your user in System SettingsUser Manager. To allow SDDM to show this image on the login screen, do

setfacl -m u:sddm:x ~/; setfacl -m u:sddm:r ~/.face.icon

This command uses access control lists to allow the user sddm to enter your home directory and then grants that user read rights to the file .face.icon.

SSDM's login screen showing user image. Starts KDE Plasma if credentials are correct
Logging in with SDDM, default theme.

You can install preferred applications via Discover or use a terminal emulator like Konsole to call pacman directly. Press Alt+Space to summon KRunner that lets you launch those programs by typing their names.

Here's the command I used in Konsole to install day-to-day applications (web browser, email client, image viewer, file browser, media player, PDF viewer, office suite, file archiver, image editing program, screenshot program) and NTFS support:
sudo pacman -Sy firefox thunderbird gwenview dolphin vlc okular libreoffice-still ark gimp spectacle ntfs-3g
Plasma also included software I didn't need: That's why I removed those packages and their dependencies:
sudo pacman -Rs plasma-thunderbolt plasma-vault

Installing Aura

Sometimes I want to use applications like informant or tllocalmgr that are not in the Arch Linux repositories but are hosted on the AUR. To make it easier to install and update those applications, I use Aura. Since Aura itself is on AUR and not in the Arch Linux repositories, here's how to install it:
sudo pacman -Sy git
git clone https://aur.archlinux.org/aura.git && cd aura
makepkg -cs
sudo pacman -U *.xz
After installing Aura this way, you can delete the repository in the aura directory.

Localization

Here's what I did to set the locale to Austrian on my system. I'm confident that changing the system to your locale will not be too different.
Regional settings to change system language and format: de_AT for Austrian German
Change the system language in Plasma: System SettingsRegional SettingsFormats.

Tablet Mode

With all those applications installed, you can use the X220 now as a regular laptop. We'll go one step further in the following sections and configure the X220's specialty: its tablet mode.

Rotate the Screen

I like to be able to rotate the screen when the laptop is in tablet mode. Since the laptop's keyboard is unreachable when in tablet mode, I decided to make use of the tablet buttons on the lower left of the screen:
The tablet buttons on the Lenovo X220 Tablet in the lower left of the screen
The tablet buttons on the Lenovo X220 Tablet's screen: power button, "Secure Attention Sequence" button, screen rotation button.
These are the tablet buttons:

The Script

Here's the script that flips the screen and also the screen inputs (I'll explain in a second):
#!/usr/bin/sh

# Get your display name with xrandr
display="LVDS-1"

# Names of screen inputs, from xinput
touch_input="Wacom ISDv4 E6 Finger"
stylus_input_tip="Wacom ISDv4 E6 Pen Pen (0)"
# The red button on the back of the stylus
stylus_input_eraser="Wacom ISDv4 E6 Pen Eraser (0)"

ctm="Coordinate Transformation Matrix"

# Turns coordinates on their heads
inversion_matrix="-1 0 1 0 -1 1 0 0 1"

# Leaves coordinates as they are
identity_matrix="1 0 0 0 1 0 0 0 1"

# The current screen rotation: One of "normal", "inverted", "left", "right"
cur_rotation=$(xrandr -q --verbose | grep "$display" | cut -d" " -f6)

echo "Let's rotate the screen"
echo "Current rotation is $cur_rotation"

if [ "$cur_rotation" = "normal" ]; then
    echo "Invert the screen and the inputs for touch and stylus"
    xinput set-prop "$stylus_input_tip" "$ctm" $inversion_matrix
    xinput set-prop "$stylus_input_eraser" "$ctm" $inversion_matrix
    xinput set-prop "$touch_input" "$ctm" $inversion_matrix

    xrandr -o inverted
else
    echo "Return the screen and the inputs to normal"
    xinput set-prop "$stylus_input_tip" "$ctm" $identity_matrix
    xinput set-prop "$stylus_input_eraser" "$ctm" $identity_matrix
    xinput set-prop "$touch_input" "$ctm" $identity_matrix

    xrandr -o normal
fi

The command xrandr -o inverted turns your screen output upside down. You might think that you're done after that, but as soon as you touch the screen, you'll notice that the cursor is off: If you touch the lower left of the screen, the cursor ends up in the upper right and vice versa. The reason for this is that while the screen output has been inverted, the screen input has not.

To fix touch input when the screen is inverted, you can set a coordinate transformation matrix for the input. This matrix will flip the coordinates of the point where you touched the screen, making the cursor appear where it's supposed to be: under your finger or stylus. As part of the solution, the following command flips the coordinates for touch input:
xinput set-prop "Wacom ISDv4 E6 Finger" "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1
There are three different screen inputs we want to flip for our X220 Tablet: finger touch, stylus touch front (the pointy end), and stylus touch back (the red eraser). In the script, we apply the inversion matrix to all three of them.

I've created a directory at ~/.local/scripts, put the script in there, and made it executable with

chmod +x ~/.local/scripts/flip_screen.sh

I recommend running the script directly via Bash to see if it works. When you call the script again, it will return the screen input and output to normal. If you intend to use that script on a different machine, you'll want to adapt the names of the screen inputs and outputs (the displays). Get them with xinput and xrandr, respectively.

The Shortcut

In Plasma's system settings, we add a shortcut to call this script when the screen rotation tablet button is pressed: Rotate windows tablet button

The chain of menu entries you'll traverse for this is:

System SettingsShortcutsCustom ShortcutsEditNewGlobal ShortcutCommand/URL

Creating a custom shortcut for flipping the screen in KDE Plasma
Creating a custom shortcut for flipping the screen in KDE Plasma.

Select the Trigger tab. After clicking the button saying "None", press the rightmost tablet button: Rotate windows tablet button

The button in the settings should say "Rotate Windows" now:
Define the trigger for flipping the screen
Define the trigger for flipping the screen.
In the Action tab of Custom Shortcuts, provide the path to our screen-flipping script:
~/.local/scripts/flip_screen.sh
When using the file browser, you can show hidden files and directories with Alt + ..

Right Click in Tablet Mode

While we're at it, let's define a second shortcut for making life easier in tablet mode: Simulate a right click with the mouse. This is convenient when using GIMP in tablet mode. You can use the stylus for drawing (see this section) and show the right click context menu by pressing the remaining tablet button:

We repurpose the Secure Attention Sequence tablet button, the one with the clockwise arrow, for right-clicking in tablet mode
We repurpose the "Secure Attention Sequence" tablet button for right-clicking in tablet mode.
You can simulate a right mouse click using xdotool, install it with
sudo pacman -Sy xdotool
With this shortcut in place, pressing that tablet button makes xdotool perform a right click at the cursor position.

Virtual Keyboard

When in tablet mode, we can use an on-screen keyboard to log in via SDDM or get past Plasma's lock screen:
sudo pacman -Sy qt5-virtualkeyboard
In System Settings, set SDDM's theme to Breeze. This is important since the default theme won't show a button to bring up the virtual keyboard.
Set SDDM's theme to Breeze to get a button that brings up the virtual keyboard
Set SDDM's theme to Breeze to get a button on the login screen that brings up a virtual keyboard.
Then, enable the virtual keyboard as an input method in SDDM:
sudoedit /etc/sddm.conf.d/virtualkbd.conf
Add this to the file:
[General]
InputMethod=qtvirtualkeyboard

When you log out, SDDM will show a button with a keyboard icon saying "Virtual Keyboard" on the lower left of the login screen. Pressing that button activates an on-screen keyboard for you to type your password.

Having the same theme, Plasma's lock screen and the SDDM login screen look very similar now, but SDDM is a program of its own.
qt5-virtualkeyboard on SDDM's login screen with Breeze theme
qt5-virtualkeyboard on the SDDM login screen with Breeze theme.
qt5-virtualkeyboard on the lock screen
qt5-virtualkeyboard on Plasma's lock screen.

Onboard

I haven't yet found a way to enable qt5-virtualkeyboard besides on SDDM and on Plasma's lock screen. Instead, I use Onboard:
sudo pacman -Sy onboard
Once you start Onboard, an icon Onboard icon in system tray appears in the tray on the lower right part of the screen. Clicking that icon brings up Onboard's virtual keyboard.
Onboard's virtual keyboard using the Ambiance theme
Onboard's virtual keyboard using the Ambiance theme.

To have Onboard started each time you log in, call Autostart with KRunner (Alt+Space) and select Onboard from the "Utilities" category.

You can configure the looks of Onboard's keyboard with "Onboard Settings". Also, you might find Onboard's snippets feature useful: You can enter custom text by pressing a single button on the virtual keyboard. Press the button with the three horizontal lines ≡ to go to the snippets menu.

Use the Stylus in GIMP

You can use the stylus to draw in GIMP. First, you want to make sure that GIMP recognizes the stylus by checking EditInput Devices. In my case, GIMP didn't recognize the stylus at first. Both device entries for the stylus were grayed out:

I could still use the stylus to draw, but the stylus would show up as the Core Pointer in the Device Status dialog. This way, I wasn't able to make the brush grow and shrink with the pressure I applied with the stylus to the screen.

It seems that GIMP recognizes the devices if you just draw with the stylus and also with its red backside, the eraser, and then restart GIMP. Afterwards, the stylus' two devices were not grayed out anymore in the menu at EditInput Devices. Make sure those devices are not grayed out, then set their mode from Disabled to Screen. This allows making use of the stylus' pressure sensitivity in GIMP.

Enable the devices of the stylus by setting their mode to Screen
Enable the devices of the stylus by setting their mode to Screen.

Assign Input Devices to GIMP Tools

If you have the checkbox "Share tool and tool options between input devices" in PreferencesInput Devices unchecked, you can assign different GIMP tools to your input devices. For example, you can use three physical devices to control three different GIMP drawing tools:
  1. the tip of the stylus draws using GIMP's paintbrush
  2. the red eraser at the back of the stylus is GIMP's eraser, naturally
  3. the regular Core Pointer, controlled with a mouse or a finger, performs a bucket fill
The Device Status dialog with three devices. The active device is the stylus, alias Wacom ISDv4 E6 Pen Pen (0).
The Device Status dialog with three devices. The active device is the stylus, alias Wacom ISDv4 E6 Pen Pen (0).

To change the GIMP tool associated with the input device, let's say for the stylus, make sure the stylus is the current input device by hovering over the image window in the center. Then, select a different tool from the toolbox or modify the tool using the Tool Options, the dialog with this icon: Onboard icon in system tray

By changing the pressure you apply with the stylus, you can vary various properties of the brush. I wanted to change the size of the brush: Applying little pressure with the stylus draws a fine line (small brush) and applying more pressure makes the line thicker (big brush). In GIMP, you can define this behavior with paint dynamics in the Tool Options.

Click on the big arrow 🢆 and select the "Pressure Size" dynamic:
Select a paint dynamic to make the size of the brush proportional to the pressure of the stylus
Select a paint dynamic to make the size of the brush proportional to the pressure of the stylus.

Where to Go from Here

If things went smoothly, your X220 Tablet should be ready for action now, with applications installed on top of a desktop environment, tablet mode configured, using the language of your choice.

Now you might want add an email account to Thunderbird or install an ad blocker for Firefox before browsing the web. Have fun with your machine!

Troubleshooting

No Touchpad and Pointing Stick after Suspend

Sometimes, after the laptop wakes up from sleep, the touchpad and the red pointing stick on the keyboard don't work, meaning you can't move your mouse. Moving the cursor by touching the screen still works, though.

Reloading the mouse kernel module with the "bare" protocol option fixed this, a solution I found here:
sudo rmmod psmouse; sudo modprobe psmouse proto=bare