Lenovo T400

TuxMobil listed. This is a description of installing Gentoo (amd64) Linux on a Lenovo T400 notebook. The T400 is the 14.1" version of the well known business T-series notebooks. Since introducing the new models in summer 2008 Lenovo offers widescreen displays only. My major demands on a new notebook have been: The first and third demand lead to a 14.1" display diagonal: while 15.4" often result in too big notebooks, the 13" diagonal either leads to a 1280x800 resolution or in very small pixels. However, this is mostly a matter of taste. For example, the Lenovo T500 has a 15.4" diagonal but makes still a compact impress.



The model number of my notebook is 276521G and the order number is NM321GE. The German specification site of this model is available at the IBM website. A summary is given in the following:

Support overview

Generally speaking the Lenovo notebooks, especially the ThinkPads, have excellent Linux support. Actually, there is no device that did not work for me by now. However, I have not yet tested the Bluetooth module, UMTS modem, fingerprint sensor, and the V.90 modem.

Component State
WXGA+, VGA, dual-head Works
WLAN, kismet, Ethernet Works
DVD-writer Works
Card reader Works
Firewire Not yet tested
ACPI, special keys Works
Suspend, hibernate Works
V.90 modem, Bluetooth, UMTS modem Not yet tested
Microphone Works
Fingerprint sensor Not yet tested

Anyhow, other test reports tell us that all the untested components from above should work. In particular, the finger print sensor is supported by the thinkfinger project. The following references provide more in-depth details:

Installing Gentoo Linux

Unfortunately the 2008 Gentoo installer CD lacks of support for the SATA CD-drive. Hence, you have to use another Linux Live-system for booting and installing. In my case I downloaded an Ubuntu 8.10 DVD and followed the Gentoo Wiki instructions. I assume you decided to install the amd64 architecture using stage3 tarballs. You can basically jump directly to the chapter 4 of the Gentoo handbook and we assume that an internet connection is already working. In chapter 6, you have to mount /proc and /dev in a different way than listed in the Gentoo handbook, namely
mount -o bind /proc /mnt/gentoo/proc/
mount -o bind /dev /mnt/gentoo/dev/

If you are using a gcc-4.3 or newer, you can select core2 as march for the CFLAGS. Hence my make.conf results in something like the following listing. Since our processor accommodates two cores we want to set at least -j3 in the MAKEOPTS variable to enable up to three simultaneous compilation jobs.
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /etc/make.conf.example for a more detailed example.
CFLAGS="${CFLAGS} -march=core2"

GENTOO_MIRRORS="http://gentoo.mneisen.org/ http://mirror.bih.net.ba/gentoo/"
USE="acpi alsa bash-completion consolekit dbus exif ffmpeg fuse gtk -hal
-handbook hdaps ipv6 jpeg kde lame laptop latex logrotate mmx mp3 mpeg mplayer
nsplugin ogg opengl policykit png qt3support smp sse sse2 sse3 ssse3 unicode
vim vim-syntax wifi xinerama X"
VIDEO_CARDS="intel fglrx radeon"
#Note, if you use xorg with hal support, you only need evdev and synaptics
INPUT_DEVICES="keyboard mouse synaptics evdev"

Configuration files: Some additional notes:

Graphics, xorg

Many ThinkPads are actually shipped with two graphics adapters built in, known as switchable graphics: The so-called internal adapter (Intel GMA X4500HD (IGP) max.384MB shared memory) and the co-called discrete adapter (ATI Mobility Radeon HD 3470 256MB). Currently only Windows Vista (or later) is able to switch between both adapters on-the-fly. For all other operating systems a reboot and a subsequent change in the BIOS settings is necessary. However, since the release of the Linux kernel 2.6.34, support for switching the graphics adapter at runtime got available, see below.
You should, at least when installing Gentoo, change the BIOS settings to either the discrete or the internal graphics adapter. Otherwise both cards are powered which means (i) higher energy consumption and therefore (ii) more heat production. This can pose an actual problem when doing long-lasting compilations.

Intel chip

I almost constantly use the Intel chip since I rarely need high 3D performance. Regarding the Intel chip the package x11-drivers/xf86-video-intel driver is pulled in when "intel" is added to make.conf's variable VIDEO_CARDS. There is a very informative Gentoo wiki site on the Intel GMA.

ATI chip

The ATI chip can be used with at least two different drivers: the xorg open source driver (x11-drivers/xf86-video-ati) and the closed source driver (x11-drivers/ati-drivers). I once had both installed bit for a while I use the closed source drivers only.


For the current stable xorg-server hal support has again been replaced by udev, which is good. The current xorg-server version has the ability to save configurations for devices in /etc/X11/xorg.conf.d, see for example here and here.

Summarizing, I placed the following files in /etc/X11/xorg.conf.d/


Section "InputClass"
        Identifier "ThinkPad HDAPS blacklist"
        MatchProduct "ThinkPad HDAPS accelerometer data"
        Option "AutoServerLayout" "on"

        Option "Ignore" "on"


Section "InputClass"
        Identifier "touchpad-all"
        MatchIsTouchpad "on"
        Option "AutoServerLayout" "on"

        Driver "synaptics"

        Option "SHMConfig" "true"

        Option "TapButton1" "1"
        Option "RTCornerButton" "2"
        Option "RBCornerButton" "3"
        Option "VertEdgeScroll" "true"
        Option "HorizEdgeScroll" "true"

        Option "VertTwoFingerScroll" "true"
        Option "HorizTwoFingerScroll" "true"
        Option "EmulateTwoFingerMinZ" "97"



Section "InputClass"
        Identifier "keyboard-all"
        MatchIsKeyboard "on"
        Option "AutoServerLayout" "on"

        Driver "evdev"

        Option "XkbLayout" "de"

And finally, these are my actual xorg.conf files, which are quite short once one uses xorg.conf.d-files to manage input devices. Note that the actual xorg.conf is generated by my script vga_switch.sh by concatenating, say xorg.conf.intel, with xorg.conf.common, see below.


Section "ServerFlags"
        Option "DefaultServerLayout"  "LayoutIntel"


Section "ServerFlags"
        Option "DefaultServerLayout"  "LayoutRadeon"


Section "ServerLayout"
	Identifier     "LayoutIntel"
	Screen      	0  "ScreenIntel" 0 0

Section "ServerLayout"
	Identifier     "LayoutRadeon"
	Screen      	0  "ScreenRadeon" 0 0

Section "Monitor"
	Identifier   "LVDS"
	VendorName   "Monitor Vendor"
	ModelName    "Monitor Model"

Section "Monitor"
	Identifier   "LVDS2"
	VendorName   "Monitor Vendor"
	ModelName    "Monitor Model"

Section "Monitor"
	Identifier   "VGA2"
	VendorName   "Monitor Vendor"
	ModelName    "Monitor Model"

Section "Device"
	Identifier  "CardIntel"
	Driver      "intel"
	BusID       "PCI:0:2:0"

Section "Device"
	Identifier  "CardRadeon"
	Driver      "radeon"
	BusID       "PCI:1:0:0"

Section "Screen"
	Identifier "ScreenIntel"
	Device     "CardIntel"
	Monitor    "LVDS2"

	DefaultDepth 24

	SubSection "Display"
		Viewport   0 0
		Depth     16
	SubSection "Display"
		Viewport   0 0
		Depth     24

Section "Screen"
	Identifier "ScreenRadeon"
	Device     "CardRadeon"
	Monitor    "LVDS"

	DefaultDepth 24

	SubSection "Display"
		Viewport   0 0
		Depth     16
	SubSection "Display"
		Viewport   0 0
		Depth     24

Section "DRI"
	Mode         0666


As already known for the i810 Intel graphics chip, better performance is gained if color depth is set to 16 Bits in xorg.conf. The difference in glxgears is about 400 fps from 1200 fps to 1600 fps. In contrast using the ATI chip results in about 4200-4400 fps. However, glxgears is not a serious benchmark for graphics chips. But, like everywhere in life, better performance comes with another drawback: the ATI chip consumes about 10W more power than the Intel chip.

KMS (Kernel mode setting)

If you use a xorg-server of at least version 1.6 you can gain from a new feature called KMS. With KMS the kernel is responsible for setting resolutions and the like and not the xorg server any more. Within this change a very fast and potential more stable switch from a virtual terminal to a X session is gained. Beside that there is no need to use a framebuffer for higher resolutions on virtual terminals. See the Gentoo wiki of the Intel GMA for more info. Since recently, I am using KMS for the Radeon card, too. However, I recommend a recent kernel and xorg's graphics driver for that purpose.

Please note that I have activated KMS for the Intel card per default in my 2.6.30 kernel config. So if you use my kernel config you either disable this option, our you use at least xorg-server-1.6.

Automatically switching xorg.conf

Once someone wants to use both chips we have the problem that the xorg.conf has to be exchanged according to the currently enabled graphics chip. I solved the problem by writing a little init.d script and a shell script /usr/local/bin/vga_switch.sh which is doing that for me. Note that 'vga_switch.sh' has now support for vga_switcheroo, see below.


# Stefan Huber <shuber2@gmail.com>

description="Sets xorg.conf according to the used graphics adapter"

	before xdm
	need localmount

	if [ "`lspci | grep VGA | wc -l`" -ge "2" ]
		einfo "Both graphic adapters activated."
	/usr/local/bin/vga_switch.sh --off
	/usr/local/bin/vga_switch.sh --autoset-xorg

	return 0
This script also generates a xorg.conf by xorg.conf.common and xorg.conf.{intel,radeon}. Note that you will need the file 'getXenv.inc', which is provided at this site. To call this script at boot time execute the following command:
rc-update add xorg-conf boot


Switching graphics at runtime

With Linux kernel 2.6.34 support for switching graphics adapters at runtime became available. The corresponding code is called 'vga_switcheroo' and has been developed by David Airlie. The kernel config for 2.6.34 listed on this site activates the support for vga_switcheroo. In order to make vga_switcheroo working it is necessary that (i) the Intel and Radeon drivers support KMS and have been integrated directly into the kernel, (ii) support for debugfs is activated. Further, I had to activate detection of primary console (CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY); otherwise I got a blank screen some time. The scripts 'vga_switch.sh' already brings the support for changing the graphics adapter, see above.

I configured acpid to execute 'vga_switch.sh --gui' when pressing Fn+F3. A gui using kdialog pops up and asks to which adapter one wants to switch to. You can select one adapter and then the kernel waits until you logout and X is restarted. After that kdm reappears and X is up with the selected graphics adapter. Calling 'vga_switch.sh' without an argument tells you the current powering state.

It seems that vga_switcheroo has some problems with suspend/resume. Power off the second graphics adapter and then suspend and resume the notebook. After resuming both cards consume power but vga_switcheroo tells us that only one card is turned on. Powering off the second card does not help but sending the command for turning on both cards hangs the kernel. However, if both cards are powered before suspending, you can power off the second card after resuming. See the corresponding '/etc/pm/sleep.d/90vga_switch' file below. See also this bug report.

Dual head, mirroring

With current xrandr packages (or grandr, or krandrtray) setting up dual head or mirroring with an VGA-connected monitor can be done on-the-fly. However, note that (at least for Intel chip) the Virtual screen size is per default limited to 2048x2048. Hence adding a 1024x768 display to the 1440x900 LVDS panel does not fit. You can override this settings in the xorg.conf. There is a good description of xrandr-1.2 at thinkwiki.org. Interestingly, for some time I am using version 2.8 of the intel drivers and the virtual size is now 8192x8192 for some reason.

If you want to set up the Fn-key combinations appropriately, you may want to setup ACPI properly. (See later section for that.) I use the following configuration:


event=ibm/hotkey HKEY 00000080 00001007


event=ibm/hotkey HKEY 00000080 00001009


. /usr/local/bin/getXenv.inc


function vgaoff()
    logger "No VGA1 connected: putting LVDS1 to standard setup"
    xrandr --output VGA1 --off \
        --output LVDS1 --mode 1440x900 --scale 1x1
    echo "off" > $STATEFILE

function vgamirror()
    logger "Mirror LVDS1 to VGA1"
    xrandr --output VGA1 --mode 1024x768 \
        --output LVDS1 --same-as VGA1 --mode 1024x768
    echo "mirror" > $STATEFILE

function vgarightof()
    logger "Putting VGA1 right of of LVDS1"
    xrandr --output LVDS1 --auto --mode 1440x900 \
        --output VGA1 --auto --right-of LVDS1
    echo "right-of" > $STATEFILE

if /-z%20%60xrandr%20%7C%20grep%20%22VGA1%20connected%22%60
    case `cat $STATEFILE 2> /dev/null` in




. /usr/local/bin/getXenv.inc

logger "Disabeling VGA"
xrandr --output VGA1 --off
echo "off" > /tmp/vgastate


getXuser() {
        user=`who| grep -m1 " :$displaynum " | awk '{print $1}'`
        if [ x"$user" != x"" ]; then
                userhome=`getent passwd $user | cut -d: -f6`
                export XAUTHORITY=$userhome/.Xauthority
                export XAUTHORITY=""

#Find the right XServer to be configured.
for x in /tmp/.X11-unix/*; do
   displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
   if [ x"$XAUTHORITY" != x"" ]; then
       export DISPLAY=":$displaynum"        

Multimedia keys

There are several explanations for setting up the multimedia keys for the T400 notebook, like here, here, or here. The latter also links to a more detailed tutorial.

As a shortcut you may want to add the following file:


keycode 144 = XF86AudioPrev
keycode 153 = XF86AudioNext
keycode 160 = XF86AudioMute
keycode 162 = XF86AudioPlay
keycode 164 = XF86AudioStop
keycode 174 = XF86AudioLowerVolume
keycode 176 = XF86AudioRaiseVolume
keycode 233 = XF86Forward
keycode 234 = XF86Back
Update: It seems that the buton now work without setting the keymaps obove. So I recommend to test them before applying the recommended settings from above.

By the way, the ThinkLight which illuminates the keyboard with a led on the top of your display works via BIOS mechanisms and has not be setup. Also the kmilo plugin for KDE works for me. It display via an OSD changes in brightness of the display or volume settings. Also the power button works out of the box. However, it took me a week to find out that I have to press the button about a second for a shutdown. My old notebook reacted instantly. But be aware that if you press the button several seconds then the notebook will simply be powered off, without shutting down cleanly.

Font sizes

In my case KDE, gvim, thunderbird and virtually all applications show unusable font sizes. To fix this, you can add the following line to the given file. See this information from Mozilla for further infos.


Xft.dpi: 96

As an alternative one could also set this value via the "Fonts" properties in 'kcontrol'. Anyhow, the solution above is much cleaner, since it applies also to non-KDE environments.


I formerly used vesafb as framebuffer to increase the screen resolution at the virtual terminals. However, when activating the ATI chip my kernel was not able to boot: display got black and then the notebook rebooted. Removing the vga kernel parameter "fixes" the problem. But since I use KMS now for the Intel graphics there is no need for a vga kernel parameter to gain higher resolution.

Transflective Display

There have been some speculations of Lenovo having built in transflective displays in the T-series of the Thinkpads. Interestingly, I have never found some official information from Lenovo on that stuff. Even though one could expect heavy marketing for such a feature. However, there is definitely something going on with the panel on my notebook. Reports stating that one could use the T400 outdoor without backlight in the same way as with backlight are clearly wrong (at least for my model). However, if I turn off the backlight, one can percept the content on the display. (Ok, that was possible, to some extent, for my old notebook too. But this panel has a much better contrast for that test case.) However, I do not expect someone to use that constantly for his work. On the bottom line, I would call that possibly a semi-transflective display...

Energy consumption, suspend/hibernate

My 6 cell battery has a capacity of 56Wh powering the notebook for about 4-5 hours when doing non energy consuming tasks. If I turn off WiFi, bring the TFT brightness to 30% and use the ondemand frequency governor the energy consumption comes down to about 12-13W. Installing laptop-mode-tools can bring down power consumption to approximately 10-11W. By the way, I recommend using more recent versions of laptop-mode-tools since they have better support for recent hardware, like the wireless card of the T400. Using the ATI graphics adapter instead of the Intel internal graphics adapter adds about 10W to the total power consumption. See some German notes on the ATI card for details.

On the T400 both, suspend and hibernate, works without the tuxonice patchset. While KDE's klaptop applet was already able to trigger suspend and hibernate, I installed sys-power/pm-utils for making that available from command line. The most important commands are pm-hibernate and pm-suspend and they worked out of the box. A short 45' experiment reveals about 390mW power consumption in suspend mode. If you use pm-utils, you can place scripts in /etc/pm/sleep.d/ which are called after resume, suspend, hibernate, et cetera. In particular, I use the following scripts:


case "$1" in
                /usr/local/bin/vga_switch.sh --on
                /usr/local/bin/vga_switch.sh --off
        *) exit $NA                                                                     


case "$1" in


# See above for file listing
. /usr/local/bin/getXenv.inc

if [ -n "$user" ]; then
	su $user -c "dbus-send --session \
	    --dest=org.freedesktop.ScreenSaver \
	    --type=method_call --print-reply \
	    /ScreenSaver org.freedesktop.ScreenSaver.Lock"
The kernel versions 2.6.35 have a suspend bug related with the i915 graphics chipset. The bug has been fixed for 2.6.36 kernel versions, see also the corresponding bug report.
Since kernel version 2.6.36 one has to load the tpm_tis module with the parameter itpm=1 in order to make suspend work properly. See also the corresponding bug report. Alternatively, one can also unload the module before going into suspend ore hibernate.

Load_Cycle_Count problem

Too aggressive power management properties of the hard disk can lead to a frequent number of so-called "load cycles". However, hard disks are only built for a specific number of such load cycles. This problems, in some variants, have been frequently described on various places. See for example here, here and here.

The problem can sometimes be recognized by click-sounds from the hard disk. You can simply check if your system is affected by calling

$ smartctl --all /dev/sda | grep -E "^(193|  9) "
  9 Power_On_Hours          0x0032   098   098   000    Old_age   Always       -       1516
193 Load_Cycle_Count        0x0032   136   136   000    Old_age   Always       -       193014
This shows us, that in the mean my hard disk performed 127 load cycles per hour! This is far too much! The hard disk used in this notebook is specified at the website of Western Digital. Summarizing, my hard disk is specified for 600.000 cycles and in the last half year it performed 200.000 of them. However, my old notebook even performed 1.2 Million cycles up to now.

To temporarily this problem you can call

$ hdparm -I /dev/sda | grep -m 1 Advanced
	Advanced power management level: 128

$ hdparm -B 254 /dev/sda
The output tells us first that the APM parameter is at 128 and then we set it to 254. This parameter controls the power management behaviour of the hard disk. Unfortunately, after a power state change of the notebook (for example suspend to ram) this parameter is reset to 128, and the hard disk shows the old behaviour. (I guess this is done by the BIOS.) My solution is the following: Install laptop-mode-tools and check that the file '/etc/pm/sleep.d/99laptop-mode' has been created. (Do not use too old versions of laptop-mode-tools.) This file re-applies laptop-mode-tools settings after resuming. Further, configure in '/etc/laptop-mode/laptop-mode.conf' the parameters LM_AC_HD_IDLE_TIMEOUT_SECONDS and LM_BATT_HD_IDLE_TIMEOUT_SECONDS to a higher value. With recent versions of laptop-mode-tools this has been changed from 5 to 20 as default. However, I use 60 on my notebook. Do not forget to enable CONTROL_HD_IDLE_TIMEOUT!

You want to check if the settings work by monitoring the idle notebook (no IO performing tasks running) with the following command:

$ while true; do smartctl --all /dev/sda | grep 193; sleep 10; done
193 Load_Cycle_Count        0x0032   136   136   000    Old_age   Always       -       193014
193 Load_Cycle_Count        0x0032   136   136   000    Old_age   Always       -       193014
193 Load_Cycle_Count        0x0032   136   136   000    Old_age   Always       -       193014
193 Load_Cycle_Count        0x0032   136   136   000    Old_age   Always       -       193014
The tools lm-profiler (included in the laptop-mode-tools package) and iotop show you IO performing tasks.


It is recommended to activate the IBM resp. Thinkpad related ACPI capabilities in the kernel. In my '/etc/conf.d/modules' I set the line 'modules_2_6="acpi-cpufreq thinkpad_acpi"' for enabeling ACPI and additional IBM features. For example you may want to inspect '/proc/acpi/ibm' where you can (de)activate bluetooth, WiFi, ThinkLight, et cetera. To use the Fn-keys for suspending and hibernating my notebook I added the following files. Do not forget to make the action scripts executeable.


event=ibm/hotkey HKEY 00000080 00001002


event=ibm/hotkey HKEY 00000080 00001003


event=ibm/hotkey HKEY 00000080 00001004


event=ibm/hotkey HKEY 00000080 00001004


# See above for file listing






/usr/local/bin/vga_switch.sh --gui

Temperature sensors

Using the thinkpad_acpi kernel module, a file '/proc/acpi/ibm/thermal' is offered which looks for example like this:
temperatures: 33 37 29 -1 50 -128 29 -128 32 40 32 -128 -128 -128 -128 -128
Every value stands for the temperature measured by a sensor somewhere in the notebook. At thinkwiki.org for several Thinkpad models a list is given telling one the position of the particular sensors. For the T400 I think I found out the following mapping:
  1. CPU neighbourhood: This value is identical to the one reported by '/proc/acpi/thermal_zone/THM0/temperature'. However, ACPI reports that THM1 is the CPUs temperature. Both strongly respond on launching CPU consuming tasks, where THM1 does this even faster. However, this value also responds on hot air at the cooling gill.
  2. Ultrabay: Blowing hot air at the dvd drives location leads to a response on this sensor.
  3. Express card: Blowing hot air at the express card location leads to a response on this sensor.
  4. ATI graphics: Choosing discrete graphics in BIOS changes this value from -1 to a reasonable value which responds on launching fgl_glxgears. If you have no ATI card installed, you get -128.
  5. Main battery: Value changes to -128 if battery is removed. However, this value is almost always at about 50 and only sometimes changing. On the other hand I heard of T400 with a 9 cell battery having values around 34.
  6. Ultrabay battery? At thinkwiki.org there is a conjecture for the T500 that this could be the corresponding value to sensor no. 5 for the ultrabay battery. I have no such battery, so I could not test this.
  7. Main battery: Value changes to -128 if battery is removed. This value correlates much better with '/sys/devices/platform/smapi/BAT0/temperature'.
  8. Ultrabay battery? See the note above.
  9. Hard disk: Blowing hot air at the hard disks location leads to a response on this sensor. However, the value is a few degrees below the one reported by 'smartctl --all /dev/sda'. The reason might be that SMART reads the hard disks sensor which is inside the hard disk. This corresponds to the observation that the SMART value is responding much slower.
  10. Intel graphics: This value strongly responds on calling 'gtkperf' if integrated graphics is selected in BIOS. Even if ATI graphics card is selected in BIOS, this value is provided.
  11. Heatsink? This conjecture is due to the entry for the T500 at thinkwiki.org. Nevertheless, this value responds on CPU load and hot air at the cooling gill, but much slower than value no. 1.
I wrote a little shell script tempinfo.sh which plots the temperatures more nicely. In fact, I call this script from conky in order to print the temperatures.

Modules tp_smapi and hdaps

As an owner of a Lenovo T400 you may probably be interested into the modules tp_smapi and hdaps. The former one controls the so-called SMAPI-BIOS build in, which itself controls for example in-depth battery settings and the latter one is used for accessing the built-in acceleration sensor. There is a detailed website at thinkwiki.org.

I recommend to set the hdaps use-flag such that the hdaps module is installed too. Further, the module thinkpad_ec needs the parameter "force_io=1". Therefore, my /etc/conf.d/modules file contains the lines

modules_2_6="$modules_2_6 thinkpad_ec tp_smapi hdaps"

Battery profiles

Once you have installed the package app-laptop/tp_smapi, you can access several battery settings at '/sys/devices/platform/smapi/'. Such settings include the maximum capacity to which a battery is charged or the threshold which must be reached to charge the battery. I strongly recommend to read the battery treatment notes at thinkwiki.org. Especially if you use your thinkpad often as office computer, you might be interested in not charging the battery always to 100% capacity. I wrote a little init script that supports three profiles 'desktop', 'mobile', 'default'. Depending on the profile set, the single parameters of the battery are set accordingly. You download install it as follows:
$ whoami
$ cd /tmp
$ wget www.sthu.org/files/batprofile.tar.bz2
$ tar -xvf batprofile.tar.bz2 -C /
$ rc-update add batprofile default
$ vi /etc/conf.d/batprofile
The init script further provides the two parameters 'reload' and 'info'. Just call '/etc/init.d/batprofile describe' to get a description.