Ubuntu 14.10 and later: It's much, much simpler there. Please see this answer and my comment below.
Note: This only works in Ubuntu 13.04. There are some differences in 13.10.
I have managed to connect two external monitors (in addition to the built-in panel) to my ThinkPad T430 on Ubuntu 13.04, with Optimus ("Switchable graphics") enabled (option 3 in your list). The monitors are connected via the DVI interface, one of them is rotated. In contrast to other solutions, all monitors are attached to the same window manager, so windows can be moved freely between the monitors. This achieves the goal of enhanced battery life if disconnected and using external monitors if connected.
The key idea here is:
- The internal graphics adapter is responsible for managing the image (bitmap) that is actually displayed
- By default, everything is rendered on the internal graphics adapter
- GPU accelerated applications use the discrete graphics adapter, the output is copied to the internal graphics adapter
- For each external monitor, the internal graphics adapter provides a "virtual" display
- Output to the external monitors happens using a second X server, the contents from the "virtual" displays are constantly copied to the second X server
The major benefit over other solutions is that all displays are (seemingly) part of the same X session, so you can freely move windows between the displays.
So far I have noticed no performance penalty.
Instructions
You need to do the following:
- Install Bumblebee from a PPA
- Build and install a custom Intel video driver
- Download, compile and finally install a small program
- Edit two configuration files
- Reboot several times
For most actions you will need a terminal, a text editor, and root access (sudo
). Detailed instructions are given below.
Install Bumblebee
Follow the "basic setup" section of the instructions. Execute as root, the last command actually initiates the reboot:
add-apt-repository ppa:bumblebee/stable
apt-get update
apt-get install bumblebee virtualgl linux-headers-generic
reboot
Don't try to Run bumblebee with nouveau driver only?. From my experience it doesn't work, at least not in this setup.
Validation
You should be able to run optirun glxgears
.
Install a patched version of xserver-xorg-video-intel
Option 1: Install from my PPA (currently only Ubuntu 13.04)
Execute the following as root:
add-apt-repository ppa:krlmlr/ppa
apt-get update
apt-get install xserver-xorg-video-intel
Option 2: Build and install your own package
Choose the most recent patch for xserver-xorg-video-intel
. Click the file, click the "Raw" button, copy the URL in the browser. At the time of writing, this was https://raw.github.com/liskin/patches/master/hacks/xserver-xorg-video-intel-2.20.14_virtual_crtc.patch.
sudo apt-get build-dep xserver-xorg-video-intel
cd ~
apt-get source xserver-xorg-video-intel
cd xserver-xorg-video-intel
# replace the URL below with the one you have noted, if necessary
wget https://raw.github.com/liskin/patches/master/hacks/xserver-xorg-video-intel-2.20.14_virtual_crtc.patch
patch -p1 < *.patch
# The next command will ask for a change log message. Supply something meaningful,
# this will later allow you to distinguish your patched package from the distribution's.
dch -l+virtual
dpkg-buildpackage -b
cd ..
sudo dpkg --install xserver-xorg-video-intel_*.deb
Validation (1), for both options
The command
apt-cache policy xserver-xorg-video-intel
should show the patched version (+virtual
suffix) and the original Ubuntu version.
Necessary for 13.04, for both options
Add the following to your /etc/X11/xorg.conf
, create if necessary:
Section "Device"
Identifier "intel"
Driver "intel"
Option "AccelMethod" "uxa"
Option "Virtuals" "2"
EndSection
Validation (2), for both options
After a reboot, run xrandr
in a terminal. The output should list two additional virtual displays.
Download and build screenclone
Get puetzk's fork of screenclone and its dependencies, and compile it.
sudo apt-get install libxcursor-dev libxdamage-dev libxinerama-dev libxtst-dev git build-essential
cd ~
git clone git://github.com/puetzk/hybrid-screenclone.git
cd hybrid-screenclone
make
Validation
The file screenclone
exists and is executable. (It won't run yet, though.)
Edit xorg.conf.nvidia
- Open the file
/etc/bumblebee/xorg.conf.nvidia
in a text editor, as root
- Comment out or remove the lines that read
UseEDID
or UseDisplayDevice
- In the
Section "ServerLayout"
, add an entry Screen "Screen0"
At the bottom of the file, add the following:
Section "Screen"
Identifier "Screen0"
Device "Device0"
DefaultDepth 24
SubSection "Display"
Depth 24
EndSubSection
EndSection
Reboot
Testing
My setup assumes a landscape monitor connected to the first DVI port of the docking station, and a portrait one connected to the second DVI port. Run the following commands in a terminal from the directory where screenclone is located, adapt as necessary.
xrandr --output LVDS1 --output VIRTUAL1 --mode 1920x1200 --right-of LVDS1 --output VIRTUAL2 --mode 1920x1200 --right-of VIRTUAL1 --rotate left
./screenclone -b -x 1:0 -x 2:1 &
sleep 1
xrandr -d :8 --output DP-2 --right-of DP-1 --rotate left
fg
Note how the display rotation has to be defined twice. You can omit the second invocation of xrandr
if no rotation is desired (and, of course, the --rotate left
in the first invocation).
By terminating screenclone
with Ctrl+C (which has been put into the foreground again using fg
), the discrete graphics adapter is shut off. You can verify this with cat /proc/acpi/bbswitch
. Still, screen space is reserved for the two now disconnected monitors. To switch back to laptop display only, use
xrandr --output LVDS1 --output VIRTUAL1 --off --output VIRTUAL2 --off
Cleanup
Copy screenclone
to a directory that is in the PATH
(e.g., /usr/local/bin
)
Create a bash
script to automate startup and shutdown of the external displays. This script will setup external displays on start and switch to laptop display only on exit (e.g., by hitting Ctrl+C).
#!/bin/bash
set -m
xrandr --output LVDS1 --output VIRTUAL1 --mode 1920x1200 --right-of LVDS1 --output VIRTUAL2 --mode 1920x1200 --right-of VIRTUAL1 --rotate left
trap "xrandr --output LVDS1 --output VIRTUAL1 --off --output VIRTUAL2 --off" EXIT
screenclone -b -x 1:0 -x 2:1 &
sleep 1
xrandr -d :8 --output DP-2 --right-of DP-1 --rotate left
fg
Alternative option: My collection of scriptlets contains two scripts, extmon-start
and extmon-stop
, that enable and disable the second and third monitor. Edit the extmon-start
script to suit your configuration.
References
My answer largely draws from the following resources:
xorg-xserver-video-intel
driver, no need to use my PPA or the patch. Also no need to editxorg.conf
, "virtual" CRTCs are created on demand. The rest should be similar. There is now even a tool that replacesscreenclone
, it's calledintel-virtual-output
and will integrate more smoothly with the display configuration of your desktop. I'll do a writeup once I get my tri-head setup with rotation to work properly. – krlmlr Nov 25 '13 at 13:06intel-virtual-output
myself and set thexorg.conf
to have aVIRTUAL1
display. Butxrandr
keeps telling me, that it's disconnected. Any ideas on that? – flx Nov 26 '13 at 04:03xrandr --newmode
; thecvt
tool helps computing the modeline), and assign this to the virtual display (xrandr --addmode
). The mode should match that of your real display. See if a second virtual display is created automagically. This is what theintel-virtual-output
tool does by itself, and it looks like the last issues there have been fixed or are about to be. – krlmlr Nov 26 '13 at 08:05intel-virtual-output
spawns a second X server on vt :8. But I don't know how to bring that X server to the display. It just stays dark/in standby. Any ideas? – flx Dec 02 '13 at 05:54xrandr
call using-d :8
? Why don't you giveintel-virtual-output
a try instead? It's working for me now. – krlmlr Dec 02 '13 at 08:45intel-virtual-output
. however I try it, in whichever combination. Nothing happens. :( – flx Dec 03 '13 at 05:10intel-virtual-output
. Why don't you file an issue in Bugzilla under "xorg" and then "Driver/intel"? – krlmlr Dec 03 '13 at 06:37intel-virtual-output -b
? – krlmlr Dec 03 '13 at 08:09xrandr
does not show anyDP
for the monitor attached to the docking station via DVI. It shows aVGA
as connected, even though there is non attached. Thanks a lot for your time anyway! – flx Dec 03 '13 at 08:23