Samstag, 28. Januar 2012

Display Port on Thinkpad T420 with Nvidia Optimus

I unpacked my new business notebook (Thinkpad T420) yesterday.
Naturally, the first thing I did was installing Linux on it. I chose Linux Mint 12 Lisa.
Soon after this was finished I tried to attach a second display via the provided Display Port. That didn't work. The display wasn't detected at all. I attached the display via the VGA-port and it worked fine. However the picture on the secondary display looks pretty blurry as VGA is not well suited for high resolutoins (1920x1200 in this case). So I dug a little deeper.

The system contains two display adapters. An Intel IGP for low power consumption, and an nvidia quadro for performance. Soon I found out the possible issue with the non-working Display Port. It is connected to the nvidia-card which is not enabled by default.

So I tried to find a way to switch to the nvidia-card. Kernel support for that runs under the name "vgaswitcheroo". However, every guide to vgaswitcheroo left me at a dead end indicating, that my system does not support it. After further digging I found out that this is actually true.

The system uses the new nVidia Optimus, which aims to do the switching on demand and completely transparent to the user. What sounds like an awesome idea, turned out to work only on Windows 7 (at least according to the tooltip in BIOS/UEFI-setup). In fact the Linux-support for Optimus is not that good.

The initial setup kept the nvidia-card always active, but was not able to use it at all. After looking for ways to get it work using ironhide. While this thing seems to be able to benefit from the additional performance of the nvidia card and also has the ability to actually turn it off, I still could not find a way to get the display port working.

The only way I could get it working was by modifying the configuration in BIOS/UEFI-setup.
I set the display device to "discrete graphics" and the Optimus detection to "Disabled". This results in the Intel card completely disabled.
The system booted fine, but the xserver looked pretty bad using nouveau. So I installed the binary driver.
# apt-get install nvidia-current
# nvidia-xconfig
Gnome 3 is usable again and the display port is working perfectly.
But I wanted to be able to use the Intel card as well.
So I went back to BIOS-setup and enabled nVidia Optimus again.

The system booted using the intel card with KMS enabled. However the x-server wouldn't start because the xorg.conf references the nvidia-driver that cannot be loaded properly now.
I used a console to delete the xorg.conf, and xserver came back to life.
# mv /etc/X11/xorg.conf /etc/X11/xorg.conf.nvidia-glx
# start lightdm 
However Gnome 3 went into fallback-mode. I soon discovered that some leftover of the nvidia-binary-driver was the cause. So I disabled that one as well:
# update-alternatives --config x86_64-linux-gnu_gl_conf
# restart lightdm
And Gnome 3 was working perfectly again.

As this is pretty tedious to do manually every time when switching graphicscards in the BIOS, I decided to automate this. I created an upstart-job to detect the current graphics card configuration and adjust the config accordingly. I created a file named "graphic-select.conf" with the following content:

# changes some settings according to the graphics-card found
description "Display driver selector"
start on (startup
 and filesystem
 and started udev)
exec /usr/local/bin/select-card.sh
And the handler-script "select-card.sh":

#!/bin/sh
if lspci | grep "VGA compatible controller: Intel Corporation" > /dev/null; then
 echo "selecting intel"
 test -e /etc/X11/xorg.conf && mv /etc/X11/xorg.conf /etc/X11/xorg.conf.ibkp  update-alternatives --set x86_64-linux-gnu_gl_conf /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf
 LDCONFIG_NOTRIGGER=y ldconfig
else
 echo "selecting nvidia"
 ln -s /etc/X11/xorg.conf.nvidia-glx /etc/X11/xorg.conf
 update-alternatives --auto x86_64-linux-gnu_gl_conf
 LDCONFIG_NOTRIGGER=y ldconfig
fi
I put the upstartjob in "/etc/init" and the handler-script in "/usr/local/bin/".
And that's it. Now on every boot the script checks which VGA adapter is active and adjusts the configs for running Xorg/Gnome3 accordingly.

The solution is not perfect, but I will accept switching graphics card BIOS as a workaround (for now).

Samstag, 7. Januar 2012

Reading RSS on Kindle

So I got an Amazon Kindle for Christmas. I like it for its display because epaper is much nicer to read than LCD screens. So I start my quest searching for a way to read my daily news update on my kindle.

For ordinary tables there are many offers out there (free and commercial) each using its own app to provide the content. Well this doesn't work on my Kindle as it's just a stupid e-reader.

So as a first step I want to read my favorite RSS-feeds on my Kindle every morning.
There are some commercial platforms that offer to send your favorite RSS-feeds as ebooks to your kindle.
Since I have my own little server at home, I thought, that can't be that hard to do myself.

So I created some python-scripts that would do the same without providing data to a third party service, since the server is up anyways.

I put the scripts on github to make them accessible to everybody.
There are two important scripts in this project: collect.py and main.py

The collect script is responsible for regularly polling the desired RSS-feeds and storing the article data locally. It does so by storing the data in a sqlite database. The main script takes the locally stored data, creates mobi-files from it and sends it to the configured email-address.
It converts the local data to a html-page which is then converted to an ebook.

To run the scripts in ubuntu 10.04, I installed the following packages:

  • python-feedparser (Library to parse the feed obviously)
  • python-lxml (Library to manipulate HTML)
  • calibre (ebook-software containing command-line tools to convert ebook-formats)
  • xvfb (Fake X-Server because calibre-scripts won't work without X)
So to set it all up:
# apt-get install python-feedparser python-lxml calibre xvfb
# git clone git://github.com/ChristophGr/rss4kindle.git
Then a config-files has to be created from the provided sample.
Then you may want to setup the scripts in your crontab like this:
# crontab -e 

0 * * * * /home/me/rss4kindle/collect.py
30 5 * * */home/me/rss4kindle/main.py

This way the desired feeds are polled every hour, and the result is sent to the kindle every day at 5:30 AM.
Coming closer to replace my daily newspaper ;)