Cataclysmic Mutation

Machine Learning and Whatever Else

Arch Linux on the Lenovo Thinkpad X220

First thoughts on the hardware

For the past several years, I’ve been using a Mac of one form or another as my everyday machine. For the most part, it’s been a pretty good experience. However, that experience has gotten worse, partly because Lion is just an abysmal OS upgrade, and partly because longstanding minor annoyances with Mac OS X have gradually become more and more grating. At some point, it occurred to me that what I really wanted was Linux again. I briefly considered just installing it on my Macbook Pro, but as I started looking at available PCs, I got really excited about the Lenovo x220. It’s a small, light laptop with high-end performance matched with very good battery life and the option of a second battery that snaps seamlessly onto the laptop. For things like conferences, this seemed like a perfect solution, and I pretty quickly convinced myself to buy one.

Overall, the laptop is really nice. I ordered it with the 6-cell battery and the additional “slice” battery. Together, they promise some 15 hours of battery life under Windows, according to Engadget. My last substantial experience with Linux on my everyday laptop was when power management was a noticeable issue, but I’ve so far been very pleased with how much time I’ve been able to squeeze out of a charge.

I purchased mine with the 2.8GHz Core i7 processor, 4 GB of memory (upgraded myself to 8GB), a 320 GB hard drive (upgraded myself to an Intel x25 160 GB SSD), the “premium” (IPS) display, the 6-cell battery, external “slice” battery, fingerprint reader, 720p webcam, the Intel 6205 wireless adapter, and bluetooth 3.0 adapter.

Without the slice battery, the laptop is very light, although not quite as thin as some other options. Particularly compared to the Macbook Air and competing Ultrabooks, it looks pretty chunky, but even compared to the Macbook Pro, it’s a bit thicker. However, it manages to mostly feel every bit as solid as my Macbook Pro, and with only half the weight. That “mostly” qualifier is necessary because of the rather odd fit of the 6-cell battery. The battery doesn’t fit flush with the laptop, instead extending a bit below the bottom plane of the case. However, it’s not the bulge that draws this complaint. Rather, it’s the fact that the battery feels loose. You can wiggle the battery around in its slot quite easily. It doesn’t seem to be anything that would cause any structural concern, but it definitely detracts a bit from the overall impression of fit and finish.

Update: It turns out that the latch holding the battery into my laptop was actually broken. I’m happy to report that despite my not being able to report the issue for several months (I ordered it over two months before I was back in the US to pick it up), Lenovo agreed to not only repair it for free, but also arrange to do so here in Iceland instead of having to send it away. The process of getting through their support channels to get to that point was frustrating. I’ll perhaps write up a bit more information on that when I have time. But for now, if you have significant looseness in the battery fit, double-check that it’s being locked in place securely and contact Lenovo if you think it’s excessive. Had I done so immediately, I could have saved myself some effort.

One area in which it seems no PC vendor has been able to compete with Apple is in trackpad quality, and while the x220 can’t either, I find the trackpad to be quite good overall. Out of the box, it wasn’t especially good – even in Windows 7 which came preinstalled. However, after installing Arch Linux and configuring the synaptics driver, the trackpad is very good. It doesn’t appear possible to configure the full range of gestures available on the Mac, but the most important ones are there (except for three-finger swipes for forward/backward, which are handled on the Lenovo through dedicated keys next to the arrow keys) and perform well.

The keyboard is, as one would expect from a Thinkpad, excellent. I strongly dislike the chiclet style keyboards Apple puts on all their systems now and which have since become de rigeur for most of the PCs I considered as well. Those forward/backward navigation keys are pretty easy to hit if you’re trying to reach for the arrow keys, and more than once, I’ve been typing something into a form on a browser, reached over to hit the left arrow to go back and edit a word or two previously, and accidentally hit the “back” button leaving the page and destroying my input. This is a problem that should mostly go away over time as I acclimate to the layout, but it’s something to be aware of.

It has a very nice assortment of ports available, although I’d much prefer a DVI port in place of the ancient VGA port. There is additionally an HDMI port, and with an adapter, this can provide a high-quality connection to a modern monitor, but it’s nonetheless silly to default to VGA output.

My other major complaint is with the screen resolution, but PCs in this class almost universally sport the same 1366×768 resolution. Sony’s VAIO Z series is available with a 13” screen and full 1080p resolution, but costs over $1000 more and still requires several compromises compared to the Thinkpad. The resolution of the display is low, but it’s not a dealbreaker. Aside from that, the display is very good. I went with the IPS version of the screen (a $50 upgrade from Lenovo), and the results are as one would expect. The viewing angles are very good, and the display is bright and crisp.

A bit more about the slice battery. It snaps in quite securely; ironically a much more solid fit than the standard 6-cell battery. Obviously, using it makes the laptop much thicker, but it’s still a light and portable machine. I don’t envision using it terribly often, but it’s a wonderful option to have when attending conferences or sequences of meetings that normally end up anchoring everyone it little circles around the nearest power outlet.

Overall, I’m very happy with the machine. If the resolution was a bit higher, even 1440×900, and the VGA port was ditched for DVI, it would be very nearly perfect. As it is, it’s very good, and those flaws are minor enough for me to live with. The battery life is amazingly good for a system this small, and with the optional slice battery, there’s really not another laptop on the market that compares with regard to runtime.

The Buying Experience

A final word about the laptop itself before I jump to getting Arch running on it. Lenovo really needs to do something about the experience of actually buying something from them. Like so many PC vendors, their website is generally a poor experience. It’s not quite a Dell-level train wreck, but it’s closer to it than it is to the experience of buying Apple. There are multiple different ways of finding the system, and the options are presented inconsistently depending on which you choose. In my case, I purchased using the Linux Foundation link, which saved me a fair amount of money. So thanks, Lenovo, for that at least. However, the configuration is divided into three screens. The first is the primarly laptop configuration options (processor, RAM, etc.). The second deals with warranty and add-on software options, and the third with other peripherals. In my case (but not via any of the other paths you can take to configure and buy an x220), the first page included an option to select between the 6-cell and 9-cell battery, and then a separate check-box to select whether to add on an external slice battery. Then the third page presented a list of several additional power options, including batteries. This list included another option to buy some sort of slice battery, but the description was slightly different, and it cost $60 more than the one listed on the first page. The “more information” links on each configuration section were mostly broken, popping up an empty white overlay. A few of the links worked – I could see more information about docking stations for instance, but for the batteries, nothing appeared. At other times, the links would populate, but with the wrong content. In short, the site itself was dreadful. On the plus side, the chat support was very quickly picked up, and the person on the other end was able to tell me that the two batteries were in fact the same, and that the one on page one was there and cheaper because it was part of a pre-packaged x220 configuration on offer. He seemed like he knew what was going on without having to go look up a canned answer in a knowledge base, and that’s very refreshing. But come on Lenovo, get the site in shape. We shouldn’t need to talk to someone to understand what you’re trying to sell us.

Arch Linux on the x220

I spent a few days using the Windows 7 install that came on the laptop just to get a feel for what to expect from the hardware, and then ditched the included mechanical drive in favor of a solid state drive on which I installed 64-bit Arch Linux. The drive bay on the x220 is too short to accept a normal 2.5” laptop hard drive, but the SSD I had, an Intel x25M 160 GB model, is actually a smaller drive with an included spacer. It’s easy to remove the spacer, but doing so leaves you without any screws to put back into the drive, as the included screws are long enough to account for the spacer. I had to visit a computer repair store kind enough to let me scrounge around a bin of screws, but after that, the drive slides in pretty well with the rubber sides from the included drive.

Installation of Arch (I went with the 64-bit version) was fairly uneventful. One thing you should be aware of if you’re buying an x220 is that you need to upgrade to one of the Intel wireless chips, otherwise you’ll end up dealing with a crappy Realtek driver, but the Intel 6205 chip in the one I bought worked without issue.

Disk configuration

I configured a small /boot partition, larger partitions for / and /usr/local, and the remainder devoted to /home, save for an 8 GB swap partition (I have 8 GB of RAM installed, and swap needs to be at least that large to support suspend-to-disk functionality). Because this is all on an SSD, I added the “discard” flag to the mount options in /etc/fstab to enable TRIM support.

Trackpad

The trackpad works OK out of the box, but you’ll want to configure the synaptics driver to get it to work well. In Arch, you need to install the xf86-input-synaptics-clickpad driver from AUR. This will create a file /etc/X11/xorg.conf.d/10-synaptics.conf. Read the synaptics man page for complete details, but I’ve included my configuration below.

Section "InputClass"
    Identifier "touchpad catchall"
    Driver "synaptics"
    MatchIsTouchpad "on"
    MatchDevicePath "/dev/input/event*"
    Option "TapButton1" "1"
    Option "TapButton2" "3"
    Option "TapButton3" "2"
    Option "ClickFinger1" "1"
    Option "ClickFinger2" "3"
    Option "ClickFinger3" "2"
    Option "VertEdgeScroll" "on"
    Option "VertTwoFingerScroll" "on"
    Option "HorizEdgeScroll" "on"
    Option "HorizTwoFingerScroll" "on"
    Option "LockedDrags" "on"
    Option "LockedDragTimeout" "500"
EndSection

This enables two and three finger taps and clicks, assigned to right and middle click respectively, two finger scrolling both horizontally and vertically, edge scrolling in both directions, and “drag locking”, which is the behavior that allows you to lift and replace your finger without interrupting a continuous drag event.

Wifi configuration

If you intend to run Linux, you should definitely upgrade to the Intel wireless chipset. I ordered mine with the 6205 adapter, which works well out of the box. However, getting up to speed on how Arch wants to support the alphabet soup of wireless standards was a bit of a hassle for me. I tried numerous options, all of which worked, but none of which was what I’d call seamless. Part of the problem is that the “friendly” methods tend to assume you’ll be using some Gnome applet to manage the connections, and I’m using Xmonad. I finally hit a sweet spot with Wicd. Configuration for my university’s WPA2-Enterprise network required a bit of trial and error (despite being a CS professor, I have next to no idea what the difference is between TKIP and CCMP is), but once I managed to get it connected, wicd seems to do a good job of connecting to my preferred networks and allowing me to intervene when needed.

Power managment

Power management was always one of the big issues for Linux on laptops. The slice battery on the x220 makes it less of a big deal, but I still want to be as conservative towards my battery as possible. Fortunately, I’ve managed to get the power drain down to very acceptable levels. I haven’t yet managed to get everything working the way I want yet, but it’s quite usable right now.

After installing the necessary packages (pm-utils, cpufrequtils, acpid, etc.), I had a few issues left to resolve. The default acpid handler script wasn’t able to correctly suspend to RAM when I closed the laptop lid. By default, the script tries to catch the actual ACPI events, but a bit of investigation showed that each time I closed and opened the lid, the event number was incremented. Instead, I modified the case in the handler script (at /etc/acpi/handler.sh) dealing with lid events to read as follows:

1
2
3
4
5
6
button/lid)
    if [[ `cat /proc/acpi/button/lid/LID/state | awk '{ print $2 }'` = "closed" ]]; then
        echo "lid closed" >/dev/tty5
        pm-suspend
    fi
    ;;

Now whenever any lid event occurs, it ignores the specific event and just reads the current lid state from the proc filesystem.

Hibernate, or suspend-to-disk, still isn’t reliably working. Currently, the issue seems to involve PulseAudio, but I’ve ran into multiple issues there, so I’m not entirely sure the current breakage isn’t related to something else I’ve done. Regardless, I haven’t had enough time to really dig into the problem just yet, but I’ll update things here when I resolve the problem.

Update: Hibernation is working fine as well, actually without much action at all on my part. I’ve done a couple of system updates since I last fooled with it, so perhaps it was just a matter of getting a new kernel. I’m currently on kernel 3.1.9-2-ARCH, and hibernation works fine out of the box. You will need to add the “resume” hook to your mkinitcpio.conf (as detailed here).

One other annoying issue I haven’t tracked down yet is that sometimes, after resuming from the suspend state, there’s a weird issue with the keyboard in X. If I have a terminal up, it seems to stop responding to keypresses intermittently. For example, I might type “ps -ef”, and nothing will happen after the “ps”. However, the key events are received – if I press enter in that example, ps does receive the “-ef” flags. Exiting and restarting X solves the problem when it occurs, so it’s an annoyance more than anything else, but I definitely want to spend a bit of time tracking down the problem.

CPU frequency scaling works well. I edited the file /etc/conf.d/cpufreq to select the ondemand governor by default, and added lines into the ACPI handler script as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ac_adapter)
    case "$2" in
        AC|ACAD|ADP0)
            case "$4" in
                00000000)
                    echo -n $minspeed >$setspeed
                    for CPUNUM in {0,1,2,3}; do cpufreq-set -c $CPUNUM -g powersave; done
                ;;
                00000001)
                    echo -n $maxspeed >$setspeed
                    for CPUNUM in {0,1,2,3}; do cpufreq-set -c $CPUNUM -g performance; done
                ;;
            esac
            ;;
        *)  logger "ACPI action undefined: $2" ;;
    esac
    ;;

The additions are the two for loops that set the CPU governor for each CPU in the system. I also added the cpufreq daemon to /etc/rc.conf. I’m not sure if both of these steps are required or not.

Also, for reasons I don’t understand (and are almost certainly due to my absence from the Linux world for a while), I’m a little hazy on how certain events are being processed. In particular, some aspects of CPU frequency scaling and PCI power management aren’t happening automatically. For now, I’ve just been running the following script manually when I boot the machine on battery power or unplug the charger, but I need to figure out the appropriate way to get this to happen automatically. If necessary, I can hack a few scripts to force it, but I didn’t want to go that route until I spent a bit more time figuring out if there’s an elegant solution I just don’t know about yet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh

minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"

device_pm() {
        for CONTROL in /sys/bus/{pci,spi,i2c}/devices/*/power/control; do
                [ -w "$CONTROL" ] || continue
                echo $1 > "$CONTROL"
        done
}

case "$1" in
        true)
                echo "Device power management on"
                device_pm auto
                echo "Switching to powersave CPU governor"
                #echo -n $minspeed >$setspeed
                for CPUNUM in {0,1,2,3}; do cpufreq-set -c $CPUNUM -g powersave; done
                ;;
        false)
                echo "Device power management off"
                device_pm on
                echo "Switching to ondemand CPU governor"
                #echo -n $maxspeed >$setspeed
                for CPUNUM in {0,1,2,3}; do cpufreq-set -c $CPUNUM -g ondemand; done
                ;;
esac

exit 0

Edit: turns out the TLP daemon is apparently just misconfigured for my purposes. Changing RUNTIME_PM_ON_BAT=on to RUNTIME_PM_ON_BAT=auto in /etc/default/tlp solves the problem of PCI device power management not working automatically at boot.

Another remaining issue is that the Intel HD audio driver seems to generate a lot of wakeups according to powertop2. Note that you do need to install powertop2 from AUR instead of powertop 1.13 from the core repository, as only the newer version correctly supports reading information from sysfs.

Bluetooth can be stopped and restarted using rfkill (rfkill block bluetooth) and (rfkill unblock bluetooth). As I very rarely use bluetooth, I chose to simply disable it at boot; I’ll unblock it manually if I need to use it. Because it’s sometimes handy to have a convenient place to do this sort of thing, I created a new script in /etc/conf.d named local that I start at boot time. Currently all it does is run the rfkill command to turn bluetooth off, but I can add more things later if needed.

I also modified my xmobarrc to ensure than nothing happened at greater than about five second intervals. On my desktop, for instance, I have an entry showing the time in hh:mm:ss format, updated every second, along with CPU and memory monitors. Dropping the frequency of the system monitors to five seconds and dropping the seconds from the date so it could be updated once per minute saves a noticeable amount of power from the reduced wakeups.

With all this in place, I’m getting very good battery life. With the screen dimmed to maybe 40% brightness, I’m seeing around 7:00 to 7:30 of normal usage on the 6-cell battery. I haven’t done any real testing, but that seems to be a reasonable estimate based on the discharge rate I’m seeing. With the slice battery connect, that number jumps to maybe 15 hours. Powertop doesn’t work completely with sysfs, but Powertop2 is available in prerelease form in AUR, and it shows an average of about 7.5W when the system is idle, although often I see higher use due to my not having managed to get a completely automated solution for setting all the needed options.

Other stuff

The audio and integrated webcam worked fine out of the box. As is typical with Arch, you need to add your user to the appropriate groups for device permissions, but nothing else was needed.

Bluetooth presumably works fine. It detects the controller and turns everything on, but I almost never use bluetooth, and I haven’t tested it to see if it works yet. I actually disable it in /etc/rc.local to save power.

The fingerprint reader doesn’t seem to work, or at least that seems to be what I see online. I haven’t tried to configure it at all. Running fprintd-enroll and swiping across the reader, I do see it detect my finger, so it’s possible that it works just fine if I knew how to configure it, but it’s also possible that there’s no driver for the protocol it speaks, and thus no way to make use of the data. I don’t know.

I think that covers the major points. I’ll update this as I continue to figure things out, particularly the remaining power management issues. For now though, it works plenty well enough for my everyday usage, and if you’re in the market for a small, powerful laptop with absolutely unmatched battery life, I recommend it pretty highly.