How To Run Multiple X Sessions Without Virtualization

One of the best things about a Linux system is its flexibility. Even though I’ve been a heavy Linux user for years, I still come across features in the OS a related applications that surprise me. A while back I learned to run multiple desktop environments at the same time, using nothing but the features of the software already built in to my distribution, and it’s been very useful for me. It may not sound like much, but it can be VERY useful to be able to run Gnome, KDE, Window Maker, and any other desktops all at the same time. You can flip from Gnome to Window Maker in seconds without having to log out or stop applications or use any kind of virtualization software. X already has everything you need.

To make sure there’s no confusion, I’m NOT talking about multiple monitors. The idea behind this article is that we’ll have multiple desktop environments running on the same computer at the same time, and we’ll be using keyboard shortcuts to switch between them.

For anyone who’s not sure what I mean when I talk about “X”, that’s the shorthand name for the X Window System. Most modern distributions use X.org to handle all their graphical needs. Basically, any time you’re seeing graphics (not just plain text), you’re probably looking at X. It manages the display for Linux and controls what’s on your screen and how it’s handled.

Virtual terminals

X keeps track of things by screens or displays. Right now, if you’re reading this article in Linux, you’re probably on the default screen number 0. You can access the different screens with key combinations. To try it out right now, try hitting Alt + Ctrl + F1. That’ll take you to your first console screen. To get back to the graphical screen, hit Alt + Ctrl + F7. Many people use this as a way to drop to a fullscreen terminal without having to close X.

At this point, you may be thinking “Why F1 and F7?”. Well I’m glad you asked, even though you didn’t really ask. When holding Alt + Ctrl, keys F1 through F6 are your console screens. They’re commonly called “virtual terminals”. Each one has a separate instance of the console running on it, and you can flip back and forth between them using Alt + Ctrl + (F1 through F6).

Once you get past F6, you’re in X’s territory. Much like the virtual terminals, each screen starting with F7 is a separate instance of X, which can have its own programs running, independent of the other screens. So what we’re going to do now is set things up to launch your other desktop environment in the next screen over.

Setting up the second screen

For starters, we’ll want to install whatever window manager or desktop environment you’d like to have running on your second display. In a move that will surprise no one, I’ll recommend Window Maker. For the remainder of this article, I’ll assume that you’re running Ubuntu in the default configuration and that the desktop environment you want to use is Window Maker.

Once you’ve installed Window Maker (or whatever other desktop you’d prefer) the first thing we need to do is open/create the file “.xinitrc” in your home. When X is launched from the command line, it reads this file to decide what needs to be run when X starts. So open or create the file “.xinitrc” in your home directory, and add the line:

and save.

Running the second desktop

Now we’re at the main event. Open your command prompt and enter:

That will tell X to start and to use display number 1 (instead of the default of 0 which you’re probably using as your main desktop). If all went well, you’ll find yourself looking at the default (and kinda ugly) base Window Maker desktop. To switch back to your main desktop, use Alt + Ctrl + F7. Back to Window Maker is Alt + Ctrl + F8. If things didn’t go so well, see the Troubleshooting section below.

Alt + Ctrl + F7 = Gnome desktop

multipleX-gnome

Alt + Ctrl + F8 = Window Maker desktop

multipleX-wmaker

Troubleshooting

X: user not authorized to run the X server, aborting.

This one is a config issue, and one that’s easily remedied. Open the following file as root:

Change

to

I can’t claim to know enough about X’s programming to be able to make any educated statements about potential security problems this may or may not present, but it fixes the problem.

X: client 1 rejected from local host

Another simple fix, just delete any files in your home directory that has a filename starting with “.Xauthority”

You can repeat this process to add any other desktop environments you may happen to want, just change the 1 in

to 2, 3, etc. There are plenty of function keys left!

Joshua Price

Josh Price is a senior MakeTechEasier writer and owner of Rain Dog Software

9 comments

  1. I got this error.

    .xinitrc: line 1: exec: wmaker: not found

    There is no window maker installed in my Fedora. I have KDE installed. What command should I write for KDE?

    And if I want to run all 3 X desktops what should I do?

    1. I personally don’t have KDE installed, but you can find out what the executable would be by opening a terminal and typing “kde” and hitting the tab key twice. That will show all the commands that start with “kde”. You’re probably looking for something like “kde-session”, that’d be my guess.

  2. Its working… Thanx for the help…
    But it is getting weird…
    As you mentioned I am not able to switch between sessions in the way you mentioned…
    My default X is in Cttl + Alt + F1 and if I switch to C+A+F2, to return back i need to press C+A+F1.
    But then if I switch to C+A+F2 and if I press C+A+F7, I dont get anything but a graphical blank screen. Then I need to press C+A+F1 to go to my x screen.

    Same way if I enable “start — :1” and swith to my KDE session. then to come back to my normal gnome session I need to press C+A+F1. and to switch back I need to press C+A+F7 and not C+A+F8. If i press C+A+F8 i get the same screen as I mentioned earlier with C+A+F7 without enabling “startx”

    I think it is bit different in Fedora…

    Anyway thanx for the help and thanx for the post… :)

  3. I never knew this was possible. Very nifty… One problem, though, is that you have to swap your .xinitrc files if you want to launch, say, Fluxbox and GNOME. I don’t use GDM, so my .xinitrc launches my Fluxbox by default, but to start GNOME after Fluxbox is started I can just comment out the “exec startfluxbox” and then uncomment the “exec gnome-session”

    Cool trick, though. :)

    Alan

    1. Alan,
      A better way to do that would be
      “startx /usr/bin/fluxbox — :1” (or whatever window manager you prefer)
      This way you don’t depend on your .xinitrc file to tell X what to start.
      don’t forget to put the full path though.
      mitch

  4. @Joshua
    Probably you should add a warning that trying to run the same application in multiple logins as in the above setup can cause unexpected problems. For instance, firefox will refuse to start the second time while other apps can step on its shoes e.g. preferences, logs etc. can get overwritten by one instance or the other — hardly any app is designed to be able to handle multiple instances running simultaneously by the same user. Btw, the “switch user” functionality present in both GNOME and KDE (actually in gdm and kdm I believe) allows one to do the same thing.

    1. For multiple firefox sessions, use firefox –profilemanager –no-remote

      Create a new firefox profile and there u go.

Comments are closed.