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.
The video showcases the laptop in tablet mode, using some of the customizations this guide describes:- Rotating the screen with a tablet button
- Drawing with the stylus in GIMP, making use of the stylus' pressure sensitivity
- Using a different brush when drawing with a finger
- Erasing with the back side of the stylus
- Right clicking with a tablet button
- Entering text with a virtual keyboard, inserting a custom text snippet
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
- Boot the Live USB Drive
- Connect to the Internet
- Set the Time
- Partition the Disk, Format the Partition
- Install Packages
- Set up Your System
- Install GRUB as the Bootloader
- Reboot and Install Applications
- Installing Aura
- Localization
- Tablet Mode
- Where to Go from Here
- Troubleshooting
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=syncThe 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.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
.
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 wlan0To 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 runningdate
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 trueAfter 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:
- Create a new DOS partition table with o.
- Create a new partition with n, select p to make the partition a primary one.
- Select partition number 1, that's the default.
- Select 2048 as the partition's first sector (also the default). A sector in our case is 512 bytes.
- 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.
- 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.
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
.
mount /dev/sda1 /mntTo automatically mount the partition when booting, we'll generate a file system table (abbreviated "fstab"):
mkdir /mnt/etc; genfstab -U /mnt >> /mnt/etc/fstab
Install Packages
Open the file /etc/pacman.d/mirrorlist
with vim
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.
Server = https://packages.oth-regensburg.de/archlinux/$repo/os/$archWe'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 konsoleSome short explanations for a few of these packages:
linux-firmware
contains closed source drivers. In case you're curious what happens if we don't installlinux-firmware
: The Wi-Fi interface such aswlp3s0
won't show up and you won't find an access point (your router) to connect to wirelessly.base-devel
provides developer tools likemake
for building software, for example with Aura. It also hassudoedit
which is helpful when you need to edit files owned by root.- PackageKit is a program that Discover uses to interact with pacman, Arch Linux' package manager.
- SDDM will provide a graphical login screen when starting your system.
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
.
- In the file
/etc/pacman.d/mirrorlist
put a server URL at the top whose location is close to you. Just like before on the live USB drive. - Define your time zone, for example:
ln -sf /usr/share/zoneinfo/Europe/Vienna /etc/localtime
- Synchronize the software clock with the hardware clock:
hwclock --systohc
- Set a password for root:
passwd
- Create a regular user:
useradd regularUser --create-home --groups wheel
- Set a password for the regular user:
passwd regularUser
. - Call
visudo
and uncomment this line:%wheel ALL=(ALL) ALL
. This allows members of group "wheel" to execute any command. To be able to runvisudo
, we needvi
which is the reason why we've installed it usingpacstrap
. - Make a couple of services start at boot:
systemctl enable NetworkManager sddm
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 commandgrub-install
writes code and files to a couple of places:
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 ofboot.img
is to loadcore.img
.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 withfdisk
. The job ofcore.img
is to load thenormal
module at/boot/grub/i386-pc/normal.mod
. Sincecore.img
needs to work with file paths, it contains code to access file systems.- the directory at
/boot/grub/
which lives on our partition/dev/sda1
. This directory contains thenormal
module. This module executes/boot/grub/grub.cfg
which we created withgrub-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
.
/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:
boot.img
→ core.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):
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 Settings → User 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
.
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-3gPlasma also included software I didn't need:
-
plasma-thunderbolt
is unnecessary since this laptop doesn't have a Thunderbolt or USB-C port. - I don't use Vault for storing secrets.
sudo pacman -Rs plasma-thunderbolt plasma-vault
Installing Aura
Sometimes I want to use applications like informant or youtube-viewer 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, see this on how to install Aura.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.- Edit
/etc/locale.gen
, uncommentingde_AT.UTF-8 UTF-8
, then generate the locale usingsudo locale-gen
. - Set the system language (you'll have to scroll down a bit if your language starts with a non-ASCII character): System Settings → Regional Settings → Formats
- Localize LibreOffice:
sudo pacman -S libreoffice-still-de
. Usepacman -Ss libreoffice-still-*
to find the package for your language. - Localize Thunderbird:
sudo pacman -S thunderbird-i18n-de
. Usepacman -Ss thunderbird-i18n-*
to find the package for your language. - Localize Firefox: Choose "Search for more languages..." in Firefox' preferences.
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: These are the tablet buttons:- The leftmost button with the dot in the middle is the laptop's second power button. It's slightly larger than the other two buttons.
- The center button with the arrow forming a clockwise circle is called the "Secure Attention Sequence" button on page 46 of the laptop's manual, it triggers the Ctrl+Alt+Del key combination on Windows. When pressed on Linux, this button creates an XF86TaskPane key event. You can confirm this by running
xev
and pressing the button. - The button to the right is the one we'll use to rotate the screen. From
xev
we know that it creates the XF86RotateWindows key event.
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.
xinput set-prop "Wacom ISDv4 E6 Finger" "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1There 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:
The chain of menu entries you'll traverse for this is:
Select the Trigger tab. After clicking the button saying "None", press the rightmost tablet button:
The button in the settings should say "Rotate Windows" now: In the Action tab of Custom Shortcuts, provide the path to our screen-flipping script:~/.local/scripts/flip_screen.shWhen 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:
You can simulate a right mouse click usingxdotool
, install it with
sudo pacman -Sy xdotool
- Create another Global Shortcut in Custom Shortcuts with a Command/URL target, just like for the screen-flipping script.
- In the Trigger tab, press the GUI button saying "None" and then the physical button. The GUI button should say "Task Panel" now.
- In the Action tab, add
xdotool click 3
.
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-virtualkeyboardIn 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. Then, enable the virtual keyboard as an input method in SDDM:
sudoedit /etc/sddm.conf.d/virtualkbd.confAdd 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.Onboard
I haven't yet found a way to enableqt5-virtualkeyboard
besides on SDDM and on Plasma's lock screen. Instead, I use Onboard:
sudo pacman -Sy onboardOnce you start Onboard, an icon appears in the tray on the lower right part of the screen. Clicking that icon brings up Onboard's virtual keyboard.
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 Edit → Input Devices. In my case, GIMP didn't recognize the stylus at first. Both device entries for the stylus were grayed out:- Wacom ISDv4 E6 Pen Eraser (0)
- Wacom ISDv4 E6 Pen Pen (0)
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 Edit → Input 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.
Assign Input Devices to GIMP Tools
If you have the checkbox "Share tool and tool options between input devices" in Preferences → Input 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:- the tip of the stylus draws using GIMP's paintbrush
- the red eraser at the back of the stylus is GIMP's eraser, naturally
- the regular Core Pointer, controlled with a mouse or a finger, performs a bucket fill
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:
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: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