Tag Archives: f16

Thinkpad X220 and Ultrabase 3 Docking Station

As I promised, there will be more posts related to the Fedora 16 configuration on a Thinkpad X220. This one will be about the seamless docking/undocking of the notebook from the dock.

It seems that this is largely still a grey area and is something that rarely seems to work as expected, so I had to hack it away, because this one was one of the biggest problems that I face every day because I take the notebook every day at work and dock it so I’m able to use is as a regular desktop PC and¬† in the afternoon I take it with me at home (one never knows for sure where he’ll end up the next day – at work or at a customer’s site ūüôā

What I was aiming was achieving effortless X setup and display switching under the following conditions:

1. When booting the notebook – should work as expected – show KDM on external display when docked and on local LVDS display when not

2. Proper switching when docking / undocking the notebook and there is active user X session

3. Proper switching when docking / undocking the notebook when KDM is active

4. Proper switching when the notebook is docked / undocked during it was suspended

To achieve this I’ve ended up with a simple bash script that verifies the current configuration (docked / undocked) and switches the display accordingly. What was left was to put it in the all appropriate places, so that it gets executed on all of the above listed conditions. So first about the script – it still a work in progress, but is mostly working properly. I’ll update it here when it becomes more polished. Bare in mind that this was written with KDM in mind, although it shouldn’t be so difficult to be adapted for GDM or other login manager.

The Script (thinkpad-dock.sh)

# wait for the dock state to change
sleep 0.5

export IFS=$"\n"

DOCKED=$(cat /sys/devices/platform/dock.0/docked)

# invoke from XSetup with NO_KDM_REBOOT otherwise you'll end up in a KDM reboot loop
for p in $*; do
case "$p" in

function switch_to_local {
export DISPLAY=$1
export XAUTHORITY=$(find /var/run/kdm -name "A${DISPLAY}-*")

# Turn off all external displays
for output in $(/usr/bin/xrandr --verbose|grep "+"|grep connected| grep -v LVDS|awk '{print $1}'); do
logger -t DOCKING "Switching off $DISPLAY"
/usr/bin/xrandr --output $output --off

# Turn on local display
logger -t DOCKING "Switching on LVDS1"
/usr/bin/xrandr --output LVDS1 --auto

function switch_to_external {
export DISPLAY=$1
export XAUTHORITY=$(find /var/run/kdm -name "A${DISPLAY}-*")

# The Display port on the docking station is on HDMI2 - lets use it and turn of local display
logger -t UNDOCKING "Switching off LVDS1 and turning on HDMI2"
/usr/bin/xrandr --output HDMI2 --primary --left-of LVDS1
/usr/bin/xrandr --output LVDS1 --off
/usr/bin/xrandr --output HDMI2 --primary --auto

case "$DOCKED" in
#undocked event
# Check for logged users with X sessions
for u in $(w | awk '{print $1" "$2}' | grep ' :[0-9]'); do
switch_to_local $(echo $u | awk '{print $2}')
if [ $CONNECTED_USER -eq 0 ] && [ ! $NO_KDM_REBOOT ]; then
# we are at login screen
logger -t KDM_DOCKING "Reloading KDM after X setup"
kill $(cat /var/run/kdm/kdm.pid)
#docked event
for u in $(w | awk '{print $1" "$2}' | grep ' :[0-9]'); do
switch_to_external $(echo $u | awk '{print $2}')
if [ $CONNECTED_USER -eq 0 ] && [ ! $NO_KDM_REBOOT ]; then
logger -t KDM_DOCKING "Reloading KDM after X setup"
kill $(cat /var/run/kdm/kdm.pid)

The Hooks

There are several places where you should put an invoke this script.

1. KDM

Obviously you need it to be run at KDM startup when X is initialized. You need to add this line at the and of /etc/kde/kdm/Xsetup file:

/usr/local/sbin/thinkpad-dock.sh NO_KDM_REBOOT

Where /usr/local/sbin/thinkpad-dock.sh is the location of the above script.

One more thing about the KDM – in order to get proper looking KDM login screen on the external display you’ll need to alter the xorg.conf, otherwise you”ll get a little borked KDM background.

Add this file to /etc/X11/xorg.conf.d/ folder

$ cat /etc/X11/xorg.conf.d/01-external-monitor.conf
Section "Device"
Identifier      "HD3000"
Driver         "intel"
Option          "monitor-LVDS1" "local-display"
Option          "monitor-HDMI2" "external-display"

Section "Monitor"
Identifier      "local-display"
Option "Enable" "false"

Section "Monitor"
Identifier      "external-display"
Option "PreferredMode" "1680x1050"
Option "Position"       "0 0"

Be carefull here as this instructs X to NOT enable by default the local display – it will be “later” activated when KDM is started and thinkpad-dock.sh is invoked.

2. Docking / Undocking events

You’ll need to add this file in /etc/udev/rules.d to catch all dock/undock events through udev:

$ cat 81-thinkpad-dock.rules
KERNEL=="dock.0", ACTION=="change", RUN+="/usr/local/sbin/thinkpad-dock.sh"

3. Suspend / Resume events

Finally you’ll need to ensure and check that the configuration was not changed while the notebook was suspended. To hook the script you’ll need to add this in /etc/pm/sleep.d/

$ cat 00check_dock

case "$1" in
# If sleeping - pretend undocking
/usr/local/sbin/thinkpad-dock.sh SWITCH_TO_LOCAL
# If resuming verify docking station presence

Only one thing to be noted here – the script needs to be executed only during the resume process, but because of some problems that I had during resuming on local display when system was suspended on the dock I had to add the hook also during suspend state and force the X server to be switched over the local display in case the machine is undocked while suspended.


You’ll also need to disable the KDE display management systems, so it does not ask you every time for display reconfiguration because a new display was detected. The only thing that should be done is to stop the service itself like this:

That’s all – there still some quirks that should be polished and may be the script must be made some more general – like defining some variables at the beginning, but I’ll do that later. In general it just works, is quite simple to implement I think and finally the dock is out of my way ūüôā

Tagged , , , ,

Thinkpad x220 – the (almost) perfect setup (Fedora 16)

So here I am – sitting in front of my new laptop – Lenovo Thinkpad X220. The date is November 8, 2011 which happens to be the release date of Fedora 16 codenamed “Jules Verne”. It’s 11:00pm, everybody are already asleep and it’s quite and peaceful in my home (thanks to my son that rarely happens ūüôā – it’s time to start with that perfect setup that I’ve had in my mind for quite some time now. I suppose that this is not going to be a short post – so if you are in same state of mind – thrilled, excited and willing to start that Fedora setup any minute now – this is the time to go grab a cup of coffee, tea or beer maybe ūüôā I’m going to describe all the specific things that I’ve done during the install (leaving the boring stuff behind ūüôā

The Hardware (4291-2WG)

  • Intel i5-2540M
  • 1 x 4GB memory
  • 12.5” HD Premium Display (the one with the IPS panel)
  • 320GB 7200 HDD
  • 80GB Intel mSATA SDD
  • Wireless – Intel 6205
  • Video – Intel HD 3000
  • 720p webcam, fingerprint reader, bluethooth
  • 9 cell battery
  • Thinkpad Ultrabase 3 + DVD Burner

Some thoughts about the hardware – first of all I had some doubts about my choice, but after I’ve received the package – they are *all* gone. What where my main concerns:

  • Display size would be too small – that turned out to be fine by me, but still I had to do some tricks to further “improve” it
  • Lack of USB3 ports – not a dealbreaker in the end as you can always stick an additional ExpressCard that sits flush in the laptop (like this one) whenever you get the need of USB 3.0 speeds
  • The IPS panel would suffer from ghosting – there is a huge thread about that, but the issue was actually addressed by Lenovo in the mid of August and after I’ve received mine I’ve even didn’t bother to check whether it has the new or old panel – the screen is (almost) perfect and is miles away from those TN panels. It has some bleeding from the bottom bezel though noticeable at boot time or at the console (when the screen is almost black), but that is not something that you’ll notice during your day to day work.

One more remark about the hardware that I’ve choose – if you don’t have the option to order a customized device (like me) you can get all available options from the so called “tabook” – Personal Systems Reference Lenovo¬ģ ThinkPad ¬ģ Notebooks. Truly a must read if you are in a position of deciding what Thinkpad to buy.

The Installation

So, enough about the hardware itself – lets get it rolling. You’ll need a boot media first. A couple of options here, but as I wanted to go with the latest and greatest of the available technology I’ve decided to go with UEFI boot on the machine (I really wasn’t able to find any major benefits of using UEFI instead of BIOS BOOT, besides maybe the possibly faster boot times) with got me to the first part of this setup.

1. Preparing bootable media (USB Stick)

I’ve decided to continue using 64bit OS despite the numerous problems that I had with some proprietary¬† software/packages, so I’ve downloaded the Fedora-16-x86_64-netinst.iso. From the Fedora documentation¬† – the are not UEFI bootable media by default – you’ll need the installation ISO file readily downloaded somewhere (on the preinstalled Windows 7 perhaps? or boot the Fedora Live CD image), mount it and extract the UEFI bootable image located under /images/efidisk.img on the iso itself.¬† The Network installation iso contains that file also so you can stick with it. After that you can put it on whatever USB stick you’ve got (the image is around 140MB) using dd:

mount -o loop /<path>/<to>/<file>.iso /mnt/cdrom

dd if=/mnt/cdrom/images/efidisk.img of=/dev/sdc #where /dev/sdc is your USB flash disk (be careful here!)

When this is finished the machine is ready to be rebooted.

REMARK: You’ll need to enter BIOS settings (F1) and select as boot method either only UEFI or at least select UEFI as preferred boot method. After that pressing F12 at boot time will allow you to select the USB stick as temporary boot device.

2. Booting the installation

Nothing special here – I used the Intel SSD of course for the system installation, creating EFI, BOOT and SYSTEM partitions. If everything is correct the Fedora installer will know that it was booted from UEFI and will create GPT table instead of MBR on the SSD, which will automatically be also aligned to the 2048 sector which is exactly at 1MB. To verify that, you can do the following. First select “Review and modify partitioning layout” during the installation setup and then check that the EFI partition is created:

You could also verify the alignment and the partition table format from command line after the disk was formatted:

[root@yggdrasil ~]# parted /dev/sdb
GNU Parted 3.0
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s
(parted) print
Model: ATA INTEL SSDMAEMC08 (scsi)
Disk /dev/sdb: 156301488s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start     End         Size        File system  Name                  Flags
1      2048s     5974015s    5971968s    fat32        EFI System Partition  boot
2      5974016s  6998015s    1024000s    ext4
3      6998016s  156301311s  149303296s                                     lvm

What packages are you going to install is entirely a matter of personal taste, but for me – the most important was to switch the default Desktop Environment that is going to be installed from GNOME to KDE. Also I’ve removed almost all packages in the Base System -> Hardware Support section that were not needed anyway on my system.

Tagged , , , ,