Alpine Linux on the GPD Pocket 2

2019-02-18

A few days ago, I acquired a GPD pocket 2. Shortly after this, I managed to get Alpine Linux 3.9 installed on it. There really doesn't seem to be any information about this online (I could very well be the only person in the world to have attempted this), so I thought I'd share some setup notes.

Anyone who has ever tried to install Linux on a laptop knows it is always a bit of a gamble. Since both Alpine Linux and the Pocket are very specialized, my expectations were very low going into this. Fortunately, the GPD Pocket 2 seems to be a very Linux-friendly bit of hardware. Things seem to work just fine.

Summary

I will go into more detail later, but here's the TL;DR of it all.

The list below is what I got working. An asterisk (*) indicates that some tweaks were needed. The console gets honorable mention because of a partial fix.

Motivations

Why Alpine Linux? Why the GPD pocket? If you don't care about my decisions here, feel free to move along.

Why Alpine Linux?

I really enjoy Alpine Linux because of how lightweight it is. Most Linux distributions have a lot of bloat that I often find myself uninstalling. The install disk is about 100 megabytes. While not the smallest Linux distribution, it's pretty darn small for an actively maintained distro in 2019. There are also other cool things I like about it, like their simple package manager and init system, as well as them using the musl standard C library.

Why the GPD Pocket?

I really like the Pocket because of how physically small and lightweight it is. I travel a fair bit these days, so the weight and size of something is important to me. The GPD with its leather case clocks in at a little over a pound. To put that into perspective, that's about half the weight of my 10-inch chromebook, a third of the weight of a surface pro 4 with a case, and about fifth the weight of my hefty 5.5 pound macbook pro with shell casing. The form factor is between that of a large phone and 7-inch tablet... it's actually small enough to fit in my pocket!

Main Install Notes

Keep in mind that this is not meant to be a tutorial. More of a loose guide based on my experiences. Everything is roughly chronological, though this is not always the case.

Initial Installation

I downloaded the latest version of Alpine Linux (x86-64), which at the time of writing is at version 3.9.

On Linux, I did the usual dd trick. Nothing fancy here.

Plug it in, and boot into Alpine Linux (IIRC I used f12 to start it)

The GPD will register as a portrait display, causing the console to be rotated. I tried some solutions online, and have been unable to rotate the console. My hack for this was to physically rotate the screen and use a tablet stand and an external keyboard. Luckily, the lid will open 180 degrees and allow it to be flattened.

The rest of the install was pretty normal. WIFI drivers work out of the box. Choose a "sys" install. I opted to install it on everything. I would not know how to dual boot (sorry, I haven't needed to do that in a long time).

Post-install Networking

WIFI connections needed to be started manually after a reboot.

I did this with:

 /etc/init.d/wpa_supplicant start

I personally disable networking at boot for a faster boot time, so I have a little script that I run as root.

Setting Up Graphics

Use the standard setup-xorg-base script to install everything that you need. Highly recommend this. I didn't do this on the first go (just installed stuff using the package manager), and when I started the server, everything froze.

As mentioned before, the GPD pocket rotates everything because it thinks it is a portrait display. Also, being the high-density display that it is, everything will be very small.

Luckily, the xrandr utitilty will fix both of these problems.

This is what my .xinitrc file looks like

 xrandr -o 3 --size 600x960
 dwm

I currently am using dwm as a window manager.

i3 vs dwm

I usually prefer using the i3 window manager. However, I found that i3 was making emacs glitch out (x11 and GTK versions). dwm did not have these issues, so I went with that instead.

You will need to manually adjust the font size for both. In i3, this can be done in the config file. dwm will have to be recompiled from source. Usually fonts around 24pt look okay.

Touchscreen

The touchscreen was something I assumed wouldn't work, but it does! However, it will not automatically recalibrate when you rotate the screen with xrandr. Luckily enough, the Arch Linux WIKI has a udev script that does the trick nicely.

 ACTION=="add|change", KERNEL=="event[0-9]*", ATTRS{name}=="Goodix Capacitive TouchScreen", ENV{LIBINPUT_CALIBRATION_MATRIX}="0 1 0 -1 0 1"

Put this in a file called 90-goodix-touchscreen.rules and place it in the folder /etc/udev/rules.d. Restart x11 and things should work.

Getting Laptop Lid Fixed

I ran into some initial problems with the laptop lid. Anytime I closed the lid, keyboard/mouse input would freeze when I tried to open it back up again (this could be unfrozen by switching to another tty terminal and back with ctrl-alt-f2 and then ctrl-alt-f1).

It turns out this problem doesn't happen if you explicitely turn the screen off first before closing the lid.

I wrote a little script called "snooze" which turns the screen of and then locks it using the utility slock

 xset dpms force off # turn the screen off
 slock # lock the screen

Later on, I figured out a better solution to the problem using the ACPI daemon running on Alpine. Create a file called /etc/acpi/LID/00000080 and insert the following:

 #!/bin/sh
 echo mem > /sys/power/state

The LID directory did not exist for me, I had to make it myself. It is assumed that the ACPI daemon is already running (by default, I think it should start up on boot).

From there, the lid close worked no problem!

Emacs

Emacs is luckily available through the alpine community repositories. Emacs started up with a tiny unreadable font. This configuration can be saved, but it will write things your .emacs file. This is a problem since I use this config file on many computers.

Running this command will change the font size from the command line:

 emacs --eval "(set-face-attribute 'default nil :height 361)"

Firefox vs Chromium

For web browsing, both Firefox and Chromium are both available as alpine packages through the community packages. For whatever reason, I found chromium to freeze up on Google sites like gmail and search (how ironic), so I installed Firefox. Firefox initially was barking something to me about dbus not being configured correctly. It turns out, you need to explicitely install dbus stuff. I figured this out accidentally while trying to get JACK to run.

Firefox the browswer I am currently using.

Speeding up startup time

To improve start-up time, I removed some services that were acting as bottlenecks.

Networking configuring was the slowest service because of DHCP and the 60 second timeout window, so that was the first to go. My thinking was it was easy enough to explicitely start at login.

Since networking was disabled on boot, I removed some network-dependent services like sshd and chronyd (when you are connected to the internet, be sure to explicitely run chronyd periodically to avoid time skew issues)

Crond was removed as well since I wasn't using it.

On login, x windows can be started automatically with the following:

 if [ $(tty) == "/dev/tty1" ]
 then
     startx
 fi

Monome (via libmonome)

I use the monome grid controller as a tactile music controller for composition and sound design. Communication with the monome is done using the libmonome library. At the time of writing, the liblo library, a dependency used by libmonome, does not seem to be available in the Alpine Linux Repositories. I had to manually compile that from source. Not the end of the world.

JACK audio

JACK is available as a third-party package from the alpine repostitory.

I had some initial trouble getting it to run. For me, the issue was that dbus was not installed. These can be installed with

 apk add dbus-libs dbus-glib dbus dbus-x11

USB-C HDMI output

I managed to get output to an external display as a kind of dock. However, you need to undo any rotation and scaling done by xrandr. I also found that I needed to explicitely turn off the laptop screen in order for the screen to set the proper resolutions.

 xrandr --output DP1 --auto
 xrandr --output eDP1 --off

The font scaling changes I made for emacs and dwm needed to be reduced back to normal.

Console Fonts

The default console fonts are really small! I fixed this by installing the terminus font with

 apk add terminus-font

I then used this command to enlarge the text:

 setfont /usr/share/consolefonts/ter-v28n.psf.gz