Installing X.Org and XFCE on a Multi-GPU Gentoo Linux System

Introduction

I installed Gentoo Linux back in April to replace my Windows installation.  Straight after the installation the first thing I wanted was to get X up and running so I had a desktop.  In most distributions this is super easy but there can be a few more steps involved in Gentoo.  I complicated things further by having three different GPUs – an integrated Intel, AMD Radeon and Nvidia GTX.

The combination of these three GPUs and a desire for a multi-monitor configuration means that once X is installed it won’t run with a default configuration and extra work is needed.  Since there may be some other people with similarly non-standard workstation builds I thought this run-through may help.

So today we’re going to be looking at installing X.Org and XFCE4 on Gentoo Linux and then configuring it for basic multi-monitor support with a single GPU that isn’t located at the first location in the PCI bus.

Installing X

For all of this I’m assuming you are logged in as root – if not apply liberal use of the sudo command.

Run emerge to get the basic X11 installation:

emerge x11-base/xorg-server x11-terms/xterm

Either everything will start compiling or, if you have the Radeon driver enabled like me, then there will be a list of configuration changes that are required to packages (in my case different use flags), so we need to run it again granting permission to stage configuration changes if this happens with:

emerge --autounmask-write x11-base/xorg-server x11-terms/xterm

This will run emerge again and stage the configuration changes.  You can write these by running:

dispatch-config

Then press ‘u’ on each config change that is displayed.  Finally you can re-run the original emerge to get it to install.

emerge x11-base/xorg-server x11-terms/xterm

Grab a cup of tea at this point as there are almost 100 packages to install.  Once that’s done we want to update our environmental variables and re-source them.

env-update && source /etc/profile

Configuring X on a Multi-GPU System

If you aren’t doing anything weird with your GPU then you can just start X now:

startx

Unfortunately on my configuration you will see “Fatal server error: no screens found”.  Since I don’t have Nvidia/Intel support built in to anything and only want the Radeon support the error is thrown as there’s no Nvidia driver loaded and the default graphics card on the system is the GTX.  To get around this we need to know where in the system the Radeon is.  The same principle applies in reverse if you have Radeon or Intel at PCI bus ID 1 and want to use Nvidia elsewhere in the system – or if you have drivers for all the cards loaded and want only one specific driver to be used in X.

We need to know which card X should use.  To do this we want to find the PCI address of the card.  The easiest way in my case is to grep for it with:

dmesg | grep -i radeon

Here in my output we see many lines including a few like the below.

[    10.092346] radeon 0000:81:00.0: enabling device (0100 -> 0103)

This indicates an AMD GPU was found at PCI bus location 0000:81:00.0.  We can also do the following to confirm this – replacing V7900 with something else that is an identifier for your card:

lspci | grep -i v7900

Here we see the PCI card confirmed at this bus location:

81:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cayman PRO GL [FirePro V7900]

You can get a list of all GPUs with:

lspci | grep -i “vga compatible controller”

And you’ll see seomthing like this:

01:00.0 VGA compatible controller: NVIDIA Corporation GM206 [GeForce GTX 960] (rev a1)
08:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 30)
81:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cayman PRO GL [FirePro V7900]

The card at 01:00.0 is the one that X will try to use and hence the problem in my case.  For now we just need to remember that 81.

The easiest way, in my opinion, at this point is to hand-craft an X configuration file.  You don’t need to create all of these but as soon as any config is created I’d rather create all of it so that I know exactly what’s going on.  Time to move over to the X configuration folder and start creating config files.  Here I’ll be using nano but use your console editor of choice.

We want to remove the existing empty config that has been placed in the config folder.

cd /etc/X11/xorg.conf.d
rm 20-opengl.conf

Now we want to start creating our configuration files.  First up we define basic keyboard settings.

nano -w 10-Keyboard.conf
Section "InputDevice"
    Identifier "Keyboard1"
    Driver "kbd"
    Option "AutoRepeat" "250 30"
EndSection

Then we want to create our basic mouse configuration.

nano -w 15-Mouse.conf
Section "InputDevice"
    Identifier "Mouse1"
    Driver "mouse"
EndSection

We’re going to setup multi-monitor support later so let’s just create a stub monitor configuration for now.

nano -w 20-Monitor.conf
Section"Monitor"
    Identifier "Monitor1"
EndSection

Now time for the one we’ve all been waiting for – the GPU configuration.  Here we must specify the PCI bus ID.  Rather unhelpfully X’s configuration takes an integer address value whereas the number we got from lspci (81) is hexadecimal.  You want to convert the hexadecimal to integer – just search for “hex to int online tool” in your favourite search engine.  In my case 81 turns in to 129.  With that in mind the configuration file should look like below.

nano -w 30-Radeon.conf
Section "Device"
    Identifier "AMD FirePro V7900"
    Driver "radeon"
    Option "AccelMethod" "glamor"
    Option "TearFree" "on"
    BusID "PCI:129:00"
    Screen 0
EndSection

Now we need to tie the monitor and GPU together.  This is the concept of a “screen”.

nano -w 80-Screen.conf
Section "Screen"
    Identifier "Screen1"
    Device "AMD FirePro V7900"
    Monitor "Monitor1"
    DefaultDepth 24
    Subsection "Display"
        Modes "2560x1440"
    EndSubsection
EndSection

The final config file we want to create is the overall server layout tying together the GPU/monitor combinations (screns) and keyboards and mice.

nano -w 99-Layout.conf
Section "SeverLayout"
    Identifier "Layout"
    Screen "Screen1"
    InputDevice "Mouse1" "CorePointer"
    InputDevice "Keyboard1" "CoreKeyboard"
EndSection

With that X should now be able to run on the correct GPU – let’s test it.

startx

You should now see X running with some X terms.  It will look ugly as we have no window manager installed so that’s our next task.

Press CTRL+ALT+F1 to return to the console then CTRL+C to kill X.

Installing XFCE4

Since we’ll be using a desktop from now on let’s tell Gentoo that.  First let’s see what number Gentoo assigns to desktop configuration

eselect profile list

You’ll see a whole bunch come back.  If you are using gnome or KDE Plasma then there will be specific versions listed, if you’re using systemd instead of OpenRC then likewise you’ll see a corresponding value for you.  For those of us using OpenRC and neither Gnome or Plasma we just want the desktop configuration “default/linux/amd64/13.0/desktop”.  On my machine this was the third profile indicated with a [3] at the start so we want to use that.

eselect profile set 3

With that done it’s time to merge in XFCE.  You can do this package by package or go for the meta-package which brings in the majority of XFCE.  That’s the route I’m going for.

emerge xfce-base/xfce4-meta

Time for some more tea – there was a two hour wait here on my system and then another few applications to get a base system up and running.  I want the XFCE terminal, the audio mixer, task manager, file browser and a basic web browser.  So let’s pull those in.

emerge x11-terms/xfce4-terminal xfce-extra/xfce4-mixer xfce-extra/xfce4-taskmanager x11-themes/xfwm4-themes xfce-base/thunar www-client/midori

Some of these packages in my case were listed as unstable so we need to confirm the changes.

emerge --autounmask-write x11-terms/xfce4-terminal xfce-extra/xfce4-mixer xfce-extra/xfce4-taskmanager x11-themes/xfwm4-themes xfce-base/thunar www-client/midori

Save those config changes.

dispatch-config

Confirm each change with a ‘u’ and then do the merge again.

emerge x11-terms/xfce4-terminal xfce-extra/xfce4-mixer xfce-extra/xfce4-taskmanager x11-themes/xfwm4-themes xfce-base/thunar www-client/midori

Another half an hour done and a quick profile update once more:

env-update && source /etc/profile

Switch to the user you want to use X with – press ALT + F2 to get to another terminal and login with a standard user.

We need to configure that user to use XFCE4 – this is just done by updating their X configuration to call XFCE whenever it runs.

echo “exec startxfce4“ > ~/.xinitrc

Now we can run X as this user:

startx

Within a few seconds you’ll have your first desktop.  A thing of beauty.  You can click the top right corner and select “Log Out…” then select log out to drop back to the terminal.

Configuring Multi-Monitor Support

The easiest way to do multi-monitor support is with xrandr.  First off we want to install it into our Gentoo system – you’ll need to switch back to your root terminal (ALT+F1) for this.

emerge x11-apps/xrandr

Switch back to your user terminal (ALT+F2) and run X again.

startx

A terminal should alreayd be there, if it’s not then launch a terminal from the bar at the bottom and in that terminal run xrandr:

xrandr

We can now see the connected monitors – in my case for this example we see DisplayPort-0 and DisplayPort-1.  The names of the ports will vary depending on your graphics card.  Write down which port is connected and what resolution is supported as we’ll need those later.

You can now log back out of XFCE and switch back to you rroot terminal with ALT+F1 and edit your monitor configuration.

cd /etc/X11/xorg.conf.d
nano -w 20-Monitor.conf

Your config should now read as below but where Dell2515Left and Dell24Top are arbitrary names you give your monitors for your own reference and the PreferredMode matching the supported modes we got from xrandr.  The primary option should be set on a single monitor and the Above option helps to locate the top Dell monitor.  There is also “Below”, “RightOf” and “LeftOf” as well as the option fo setting specific locations.

Section "Monitor"
    Identifier "Dell2515Left"
    Option "PreferredMode" "2560x1440_60.00"
    Option "Primary" "true"
EndSection

Section "Monitor"
    Identifier "Dell24Top"
    Option "PreferredMode" "1920x1200_60.00"
    Option "Above" "Dell2515Left"
EndSection

We need to then update the screen to tie monitors to the GPU again.

nano -w 80-Screen.conf

This time set the values as below – but again using your identifiers as above.

Section "Screen"
    Identifier "Screen1"
    Device "AMD FirePro V7900"
    Monitor "Dell2515Left"
    DefaultDepth 24
    Subsection "Display"
        Depth 24
    EndSubsection
EndSection

Finally a change to the AMD Radeon configuration to tie each port to the device itself.

nano -w 30-Radeon.conf
Section "Device"
    Identifier "AMD FirePro V7900"
    Driver "radeon"
    Option "AccelMethod" "glamor"
    Option "TearFree" "on"
    Option "DisplayPort-1" "Dell2515Left"
    Option "DisplayPort-0" "Dell24Top"
    BusID "PCI:129:00"
    Screen 0
EndSection

Switch back to your user with ALT+F2 and re-run X.

startx

At this point you should have dual monitors configured correctly.  You can log back out and then go to your root user.  For AMD GPUs we now want to enable compositing – so create a new X configuration.

nano -w 05-Extensions.conf
Section "Extensions"
    Option "Composite" "Enable"
EndSection

This probably gives you a good start but you may want to now do a more precise multi-monitor configuration.  To do this I use arandr.

emerge arandr

If you get a requirement for use flags repeat the process we’ve already done a few times (–autounmask-write, dispatch-config, ‘u’ then re-run emerge).  If you go back into X in your user session:

startx

Then in a terminal on XFCE run arandr:

arandr

You’ll be greeted with a more user-friendly way to set your screen locations relative to each other.  If you need further tweaking or want to change specifics then you can do it here and hit the green tick apply button.  Once you’re happy with it do Layout -> Save As and save it to ~/SetupMonitors.sh then in a terminal do:

chmod +x ~/SetupMonitors.sh
nano -w ~/.xinitrc

And add a new first line (before startxfce4):

~/SetupMonitors.sh

Now whenever you restart X your exact monitor config will be used here (alternatively you can take these settings and put them back in your X config – just another way to do it).

Phew!

Well that took longer than planned but works pretty nicely.  Since doing this initially I’ve actually swapped over to my Nvidia GPU as my main one (the AMD one was noisy and my intended use-case for the GTX 960 hasn’t come about yet so I may as well use it as my primary GPU again) but a useful lesson regardless in configuring X.

I hope you find this useful and I’ll provide some more updates on how I’m using X on a daily basis shortly.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s