Installing Gentoo on a ThinkPad X220

From ThinkWiki
Revision as of 20:29, 6 July 2011 by Flow (Talk | contribs) (Further installation steps)
Jump to: navigation, search
ATTENTION!
Work in progress. If you have feedback, suggestions, anything, contact me

Installing Gentoo on a Lenovo X220 with UEFI and GPT

The goal is a working Gentoo installation utilizing UEFI and GPT on an SSD. I work on improving the page step-by-step, but it's more or less for the advanced gentoo user. But you can always ask me for clarification. :)

Model Specs

General Specs

X220 - 4290-W1B, i5-2520M, 4GB RAM

replaced internal HD with SSD Intel 320 Series 120GB, 2.5", SATA II (SSDSA2CW120G310)

cpuinfo

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      : Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz
stepping        : 7
cpu MHz         : 2501.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 x2apic popcnt aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips        : 4983.17
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

lspci

00:00.0 Host bridge: Intel Corporation 2nd Generation Core Processor Family DRAM Controller (rev 09)
00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09)
00:16.0 Communication controller: Intel Corporation 6 Series/C200 Series Chipset Family HECI Controller #1 (rev 04)
00:16.3 Serial controller: Intel Corporation 6 Series/C200 Series Chipset Family KT Controller (rev 04)
00:19.0 Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (rev 04)
00:1a.0 USB Controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #2 (rev 04)
00:1b.0 Audio device: Intel Corporation 6 Series/C200 Series Chipset Family High Definition Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 1 (rev b4)
00:1c.1 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 2 (rev b4)
00:1c.3 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 4 (rev b4)
00:1c.4 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 5 (rev b4)
00:1d.0 USB Controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation QM67 Express Chipset Family LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation 6 Series/C200 Series Chipset Family 6 port SATA AHCI Controller (rev 04)
00:1f.3 SMBus: Intel Corporation 6 Series/C200 Series Chipset Family SMBus Controller (rev 04)
03:00.0 Network controller: Intel Corporation Centrino Advanced-N 6205 (rev 34)
0d:00.0 System peripheral: Ricoh Co Ltd Device e823 (rev 04)

lsusb


Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 147e:2016 Upek Biometric Touchchip/Touchstrip Fingerprint Sensor
Bus 001 Device 004: ID 04f2:b217 Chicony Electronics Co., Ltd 

Required Kernel modules for the X220 hardware

  • Intel Gigabit Ethernet: (CONFIG_E1000EI)
  • Intel WLAN: (CONFIG_IWLAGNI)
  • Intel HD Grapic: (CONFIG_DRM_I915I)
  • TPM Chip (CONFIG_TCG_TIS)

BIOS Update

Turns out to be very Linux unfriendly. There a ways to boot the .iso image with grub. I tried grub2 with help from syslinux memdisk and reached some kind of bios update menu. But got stuck there. After wasting some time I did it by installing Win7 and running the Windows BIOS update tool. Lenovo has to do better here. For example by providing some sort of Linux BIOS update tool, or at least an UEFI bootable USB stick image.

Boot from USB Stick

Sysresccd (2.2.0), which has a pretty nice script to create a bootable USB-Stick, failed to boot on the X220. Created an bootable usb stick from the gentoo-minimal.iso with unetbootin. Works.

Partition the Drive

# parted

(parted) mklabel gpt

(parted) mkpart primary fat32 1 201

NOTE!
We don't start with sector 0 because of alignment. I am not sure if the result is optimal, but at least parted doesn't complain

(parted) set 1 boot on

(parted) mkpart primary linux-swap 202 4047

(parted) mkpart pimrary ext2 4048 120GB

Format the partitions

# mkfs.vfat /dev/sda1

# mkswap /dev/sda2

# mkfs.btrfs /dev/sda3

NOTE!
The mkfs.btrfs binary is not yet on the gentoo minimal image.

Gentoo Installation

Gentoo stage3

Just like the handbook, boot from gentoo-minimal-image. Unpack stage3 and portage. Edit fstab and set a root password. Everything else can be done later on.

Grub with efi support installation

This was by far the hardest part yet. Because UEFI and GPT a relatively new and I am not so familiar with it and the documentation isn't so good yet. Basically EFI on the X220 looks for a FAT32 formatted GPT partition with the boot flag set. If it finds one it tries to start /EFI/boot/bootx64.efi (Note that this is actually case-insensitive because of FAT32).

Grub-1.99 from scarabeus overlay is needed. Fix the STRIP_MASK error, remove last "a". Enable GRUB_PLATFORMS=efi-64 in make.conf. TODO add tar.gz with fixed ebuild for adding to overlay


Help needed
I don't think that this is needed, it's from the Arch Wiki on UEFI boot. Maybe outdated, please report if it works without for you or simply delete this part.

# cp /usr/share/grub/{unicode.pf2,ascii.pf2} /boot/efi/efi/grub/

Important part:

NOTE!
The efi_gop grub module is very important. If it's not loaded, you won't see anything on boot after grub

# grub-mkimage -d /lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/boot/bootx64.efi part_gpt btrfs fat ext2 normal chain boot configfile linux multiboot efi_gop

Optional but useful:

# cp /lib/grub/x86_64-efi/*.mod /boot/efi/efi/boot/

# cp /lib/grub/x86_64-efi/*.lst /boot/efi/efi/boot/

Minimal grub.cfg

set prefix(hd0,gpt1)/efi/boot
pager=1
timeout=20

menuentry "Gentoo Linux" {
        set root=(hd0,gpt3)
        linux /boot/bzImage root=/dev/sda3 ro raid=noautodetect
}

Put grub.cf in same directory as bootx64.efi: /boot/efi/efi/boot/


Thanks to Finnbarr P. Murphy for his blog posts about Grub and UEFI

Kernel

For UEFI on the X220 you have to use a kernel > 3.0-rc1. Suspend-to-RAM and brightness control of the display work with kernel >= 3.0-rc6.

My current Kernel .config (3.0-rc6). Please feel free to comment if you have spotted an unnecessary enabled hardware option or something that should be enabled on the X220. The config is hosted as github gist, so you can easily ask for merges with your version. This is work in progress :)

make.conf

/etc/make.conf

CFLAGS="-march=core2 -O3 -pipe"
CXXFLAGS="${CFLAGS}"
CHOST="x86_64-pc-linux-gnu"
MAKEOPTS="-j 4"
GRUP_PLATFORMS="grub_platforms_efi-64"
INPUT_DEVICES="evdev synaptics"
VIDEO_CARDS="intel vesa fbdev"

Finishing touches

Set timezone

Set locale.gen

Hardware setup

WLAN Intel Advanced 6205

# emerge wpa_supplicant linux-firmware

NOTE!
You will see a lot of "DMAR:[DMA Write] Request device [03:00.0] fault addr XXXXXXXX" errors in syslog. But the device seems to work just fine

Further installation steps

Emerging the system

xorg

# emerge xorg-x11 The touchpad can be accessed by the evdev and the synaptics driver, which can lead to x11 not starting. To fix this add the following lines to /usr/share/X11/xorg.conf.d/50-synaptics.conf.

     MatchDevicePath "/dev/input/event*"
            Option "TapButton1" "1"
            Option "TapButton2" "2"
            Option "TapButton3" "3"

gnome and gdm

# emerge gnome

ATTENTION!
nss failes to emerge on systems with a 3.0 kernel. See Gentoo Bug 372001

Bug 372001 workaround from here allows you to emerge nss.

# emerge gdm

Network Manager

Emerge a newer version of NetworkManager which comes with a built-in gentoo module. You can read more about the module on Mu Qioa's Blog

# emerge =net-misc/networkmanager-0.8.2-r10 --autounmask-write

# rc-update add NetworkManager default

Make sure that the ifnet module (gentoo interface handling) is enabled: /etc/NetworkManager/nm-system-settings.conf

[main]
plugins=ifnet,keyfile
[ifnet]
managed=true
auto_refresh=false

Ecryptfs home

I have setup an ecryptfs home for my user account and written an how-to about it in the gentoo-wiki. Read it here

Fingerprint reader

While I don't use the fingerprint reader for auth purposes (It's just insecure). It would be nice to scan some fingers for fun :-). Unfortunately there is a bug in libfprint that fails every enroll with "Enroll failed with error -22". Hopefully it will be fixed soon.

# emerge fprint_demo

Extra Keys

working

Most keys work out of the box. Tested so far are:

  • FnF2 lock screen
  • FnF3 display battery status
  • FnF4 suspend to RAM
  • FnF5 enable/disable WLAN (Note that there is also a hardware switch on the left side of the X220 which disabled WLAN and bluetooth
  • FnEnd and Fn}Pos 1 brightness controll
  • Volume up/down/mute
  • TinkVintage Button, emits XF86Launch1

TODO

  • FnF8 - disable/enable touchpad
  • Fn{{key|F