{ ^_^ } sinustrom Solving life, one problem at a time!

Gentoo on Thinkpad X230

Author: Zoltan Puskas
Categories: linux

Installing Gentoo on a computer with some previous Linux knowledge is pretty straightforward thanks to the well maintained Gentoo Handbook. However since Gentoo is a highly customized distribution there are always some machine specific settings that are not covered by the general guide. In this post I intend to cover these specifics required for Lenovo’s Thinkpad X230 laptop to complement the official handbook.

The installation will be running the 64 bit testing branch (~amd64) as I prefer recent packages and I’m willing to report, or patch a few bugs. If something is not covered here for your specific variation of the X230 setup searching the Gentoo Wiki and the Gentoo forums might be a good start.

Hardware specs

My particular system is labeled with the configuration number 2306-CTO.

Component Type
CPU Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
Graphics Intel HD 4000
RAM 16GB (2x8GB G.Skill DDR3-1600)
Storage Intel 520 Series, 120GB SSD
Display 12.5” IPS (1366x768 resolution)
Wireless 2x2 Centrino Wireless-N 2200
Camera 720p HD camera
Keyboard Backlit, US layout, ThinkLight
Bluetooth Broadcom BCM20702 Bluetooth 4.0
Battery 6 Cell built-in
Ports 1 Mini DisplayPort with audio, 1 VGA, 2 USB 3.0, 1 USB 2.0, 1 Always on USB 2.0, 1 4-in-1 SD Card Reader (SD/SDHC/SDXC/MMC slot), 1 Express Card 54mm, 1 Smart Card Reader, 1 Ethernet RJ45

Hardware related listings from: cpuinfo, lspci, lsusb.

Except for the mic mute button, I have got everything working on this laptop.

Booting up

Since the X230 has no optical drive, the Gentoo installer has to be be booted from an USB stick. To create one follow the LiveUSB/HOWTO on the Gentoo Wiki.

Preparing the disk

As the X230 has UEFI, I decided to go with it instead of the Legacy BIOS + GRUB2 mode. To boot using UEFI it is advised to use GPT partitioning. For this follow the UEFI Gentoo Quick Install Guide on the Gentoo Wiki.

You may also want to create a swap partition. Having 16GB of RAM it is likely to be used very rarely, e.g. I have 2GB of swap space, so there is no need to worry that it will wear the SSD out. It can be useful though when doing some heavy workloads or compiling in the background using tmpfs. Additionally it will leave some additional low usage blocks for more efficient wear leveling.

Configuring the compiler options

In /etc/portage/make.conf set these basic options and use flags before adding your additional own preferences:

# CPU specific optimizations
CFLAGS="-march=native -O2 -pipe"

# Use testing packages

# Tell how many compile threads to use

# Basic use flags to make programs use the CPU features (add more flags based on your own preferences)
USE="avx lm_sensors mmx posix smp sse sse2 sse3 ssse3 sse4_1 threads openmp vaapi wifi xvmc"

# Display and I/O device related driver options
VIDEO_CARDS="intel i965"
INPUT_DEVICES="keyboard mouse evdev synaptics"

# Set low priority so update does not hog the system
# Set compile directory to be in tmpfs (go easy on SSD)

Although the Gentoo Wiki Safe CFLAGS post tells us that the -march should be core-avx-i, I think setting native works better. GCC confirms this:

$ gcc -march=native -E -v - </dev/null 2>&1 | grep cc1
/usr/libexec/gcc/x86_64-pc-linux-gnu/4.8.2/cc1 -E -quiet -v - -march=core-avx-i -mcx16 -msahf -mno-movbe -maes -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mrdrnd -mf16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=3072 -mtune=core-avx-i

Using native will also keep the settings up to date when a newer compiler becomes available in Gentoo. The only exception to this is when you are using distcc compilation. In that case follow the Distcc Wiki to update your CFLAGS.

Kernel configuration

The option list below is not a complete configuration. Only the minimum X230 hardware related parts are described to get your hardware fully functioning. Depending on your computing and peripheral needs you might need to set other options too.

CPU features

Processor type and features  --->
   [*] Machine Check / overheating reporting 
   [*]   Intel MCE Features
   [ ]   AMD MCE Features
  Processor family (Core 2/newer Xeon)  --->
    ( ) Opteron/Athlon64/Hammer/K8
    ( ) Intel P4 / older Netburst based Xeon
    (X) Core 2/newer Xeon
    ( ) Intel Atom
    ( ) Generic-x86-64
  [*] SMT (Hyperthreading) scheduler support
  [*] Multi-core scheduler support
  <*> CPU microcode loading support
  [*]   Intel microcode loading support
  [*] Numa Memory Allocation and Scheduler Support
  [*] ACPI NUMA detection

Executable file formats / Emulations  --->
   [*] IA32 Emulation

Power management

Power management and ACPI options  --->
  [*] Suspend to RAM and standby
  [*] Run-time PM core functionality
  [*] ACPI (Advanced Configuration and Power Interface) Support  --->
    [*]   Deprecated /proc/acpi files
    [*]   Deprecated power /proc/acpi directories
    <*>   AC Adapter
    <*>   Battery
    -*-   Button
    -*-   Video
    <*>   Fan
    [*]   Dock
    <*>   Processor
    <*>   Thermal Zone
    <*>   Smart Battery System
      CPU Frequency scaling  --->
        [*] CPU Frequency scaling
        <*>   CPU frequency translation statistics
              Default CPUFreq governor (ondemand)  --->
                ( ) performance
                ( ) userspace
                (X) ondemand
                ( ) conservative
        -*-   'performance' governor
        <*>   'powersave' governor
        <*>   'userspace' governor for userspace frequency scaling
        -*-   'ondemand' cpufreq policy governor
        <*>   'conservative' cpufreq governor
              x86 CPU frequency scaling drivers  --->
                [*] Intel P state control
                <*> ACPI Processor P-States driver
  [*] Cpuidle Driver for Intel Processors

Networking support

[*] Networking support  --->
  <M>   Bluetooth subsystem support  --->
    <M>   RFCOMM protocol support
    <M>   HIDP protocol support
    Bluetooth device drivers  --->
      <M> HCI USB driver
      <M> HCI UART driver
  -*-   Wireless  --->
    <*>   cfg80211 - wireless configuration API
    [*]     enable powersave by default
    [*]     cfg80211 wireless extensions compatibility
    <*>   Generic IEEE 802.11 Networking Stack (mac80211)
  <*>   RF switch subsystem support
Device Drivers  --->
  [*] Network device support  --->
    [*]   Ethernet driver support  --->
      [*]   Intel devices
      <M>     Intel(R) PRO/1000 PCI-Express Gigabit Ethernet support
    [*]   Wireless LAN  --->
      <M>   Intel Wireless WiFi Next Gen AGN - Wireless-N/Advanced-N/Ultimate-N (iwlwifi
      <M>     Intel Wireless WiFi DVM Firmware support

Device drivers

Device Drivers  --->
  <*> Serial ATA and Parallel ATA drivers  --->
    [*]   ATA ACPI Support
    [*]   SATA Port Multiplier support
    <*>   AHCI SATA support
    [*]   ATA SFF support (for legacy IDE and PATA)
    [*]     ATA BMDMA support
    <*>       Intel ESB, ICH, PIIX3, PIIX4 PATA/SATA support
      Input device support  --->
        <*>   Mouse interface
        (1366)  Horizontal screen resolution
        (768)   Vertical screen resolution
        <*>   Event interface
        [*]   Mice  --->
          <M>   PS/2 mouse
      Character devices  --->
        <*> Hardware Random Number Generator Core support
        <*>   Intel HW Random Number Generator support
        <*> TPM HW Random Number Generator support
        [*] HPET - High Precision Event Timer
        <*> TPM Hardware Support  --->
          <M>   TPM Interface Specification 1.2 Interface
  -*- I2C support  --->
    [*]   Enable compatibility bits for old user-space
    <M>   I2C device interface
    [*]   Autoselect pertinent helper modules
          I2C Hardware Bus support  --->
            <M> Intel 82801 (ICH/PCH)
  {*} Hardware Monitoring support  --->
    <M>   Intel Core/Core2/Atom temperature sensor
  -*- Generic Thermal sysfs driver  --->
    <M>   Intel PowerClamp idle injection driver
    <M>   X86 package temperature thermal driver
  [*] IOMMU Hardware Support  --->
    [*]   Support for Intel IOMMU using DMA Remapping Devices
    [*]     Enable Intel DMA Remapping Devices by default

Intel HD4000 graphics

Device Drivers  --->
      Graphics support  --->
        <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)  --->
        <*> Intel 8xx/9xx/G3x/G4x/HD Graphics
          [*]   VESA VGA graphics support
          [*]   EFI-based Framebuffer Support
        -*- Backlight & LCD device support  --->
          <M>   Lowlevel LCD controls
          <M>     Platform LCD controls

Intel HD audio

Device Drivers  --->
  <M> Sound card support  --->
    <M>   Advanced Linux Sound Architecture  --->
      [*]   PCI sound devices  --->
        <M>   Intel HD Audio  --->
          [*]   Build Realtek HD-audio codec support
          [*]   Build HDMI/DisplayPort HD-audio codec support


Device Drivers  --->
  <M> Multimedia support  --->
    [*]   Cameras/video grabbers support
    [*]   Media USB Adapters  --->
      <M>   USB Video Class (UVC)
      [*]     UVC input events device support

USB support

Device Drivers  --->
      HID support  --->
        {*} HID bus support
        [*]   /dev/hidraw raw HID device support
        <*>   Generic HID driver
            USB HID support  --->
              <M> USB HID transport layer
              [*] PID device support
              [*] /dev/hiddev raw HID device support
  [*] USB support  --->
    {M}   Support for Host-side USB
    [*]     USB announce new devices
    [*]     Enable USB persist by default
    <M>     xHCI HCD (USB 3.0) support
    <M>     EHCI HCD (USB 2.0) support
    [*]       Root Hub Transaction Translators
    [*]       Improved Transaction Translator scheduling
    <M>     OHCI HCD (USB 1.1) support
    <M>       OHCI support for PCI-bus USB controllers
    <M>     UHCI HCD (most Intel and VIA) support
    <M>     USB Mass Storage support

SD card reader

Device Drivers  --->
  <M> MMC/SD/SDIO card support  --->
    <M>   MMC block device driver
    <M>   Secure Digital Host Controller Interface support
    <M>   SDHCI support on PCI bus
    [*]     Ricoh MMC Controller Disabler

Thinkpad specific drivers

Device Drivers  --->
  [*] X86 Platform Specific Device Drivers  --->
    <M>   ThinkPad ACPI Laptop Extras
    [*]     Console audio control ALSA interface
    [*]     Video output control support
    [*]     Support NVRAM polling for hot keys
    <M>   Thinkpad Hard Drive Active Protection System (hdaps)

Setting up X

If not installed already get the Intel graphics driver for X:

# emerge xf86-video-intel

Don’t forget to set the use flags: +dri, +sna,+udev, +xvmc for the video driver.

Also emerge the input drivers (if they are not already):

# emerge xf86-input-synaptics xf86-input-evdev xf86-input-mouse xf86-input-keyboard

In order to make the touchpad fully functional create the following configuration files:


Section "InputClass"
        Identifier      "Trackpoint Wheel Emulation"
        MatchProduct    "TPPS/2 IBM Trackpoint|DualPoint Stick|Synaptics Inc. Composite Touchpad / TrackPoint|Thinkpad USB Keyboard with Trackpoint|USB Trackpoint pointing device"
        MatchDevicePath "/dev/input/event*"
        Option          "EmulateWheel"          "true"
        Option          "EmulateWheelButton"    "2"
        Option          "Emulate3Buttons"       "false"
        Option          "XAxisMapping"          "6 7"
        Option          "YAxisMapping"          "4 5"


Section "InputClass"
        Identifier      "touchpad"
        MatchProduct    "SynPS/2 Synaptics Touchpad"
        Driver          "synaptics"
        Option          "VertResolution"        "100"
        Option          "HorizResolution"       "65"
        Option          "MinSpeed"              "1"
        Option          "MaxSpeed"              "1"
        Option          "AccelerationProfile"   "2"
        Option          "AdaptiveDeceleration"  "16"
        Option          "ConstantDeceleration"  "16"
        Option          "VelocityScale"         "32"

Also enable XVMC acceleration.

# eselect xvmc list
  [1]   xorg-x11
  [2]   intel-i810
  [3]   intel-i915/i965
# eselect xvmc set 3


SSDs make life much faster, unfortunately they can be worn out more easily. In order to extend the life of the SSD we can do two things to avoid necessary writes and also keep the performance:

Mount /tmp to RAM

Add the following line to /etc/fstab

tmpfs           /tmp            tmpfs           size=8G         0 0

Used in combination with the PORTAGE_TMPDIR set previously all the portage compiling will take place in the memory instead of the disk. 8GB is enough to compile anything at this time.

Use periodic TRIM

Mount the ext4 partition without the trim option. /etc/fstab shall have a line similar to this.

/dev/sda2       /               ext4            noatime         0 1

Then set up a monthly cron job to do the trimming. For that you will need will need fstrim and anacron.

# emerge fstrim anacron

And create /etc/cron.monthly/fstrim

fstrim -v /

Wireless networking

Ethernet works out of the box with the kernel drivers enabled, however for WiFi you will need to install the relevant iwlwifi firmware, in this case:

# emerge iwl2000-ucode

NetworkManager will handle everything else afterwards.

Docking station

The docking station will work out of the box, it requires no additional drivers or packages. I have tested it with my Mini Dock Plus Series 3 (Type 4338).