Running Multiple X Sessions on One Machine

On March 26, CTWM released a new version (4.1.0). I wanted to try it out, so I built it. There are a number of ways to test a window manager without making it your daily driver. But Xnest and VirtualBox are poor options, because so many key combinations are trapped by your primary WM and thus never transmitted to the WM inside Xnest or VirtualBox. So I tried to run it the old way: startx /usr/local/bin/ctwm -- vt8, but that didn't go well:

/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server

xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error
Couldn't get a file descriptor referring to the console.

Note

The OS used here is Debian 11. If you're using Fedora (I tested on 38), you'll need to create the /etc/X11/Xwrapper.config file, and X runs by default on vt1. Otherwise very similar. (Keep in mind I had SELinux switched off - it might not like all this, I didn't test that.)

I've been interested in Window Managers for a long time. I used the above (15-20 years ago) to start a second running version of X with a different Window Manager on another virtual terminal. It's possible to switch virtual terminals at any time with Ctrl-Alt-F<N>. On most versions of Linux, there will be six text terminals and one terminal running X (or Wayland?). Usually your X session will be running on virtual terminal 7 (Ctrl-Alt-F7) and the text terminals are on 1 through 6 - but this isn't always true, as I've sometimes seen X use virtual terminal 1 (this is mostly dependent on the distro). If the above had worked, I would have been able to switch between the two X sessions with Ctrl-Alt-F8 and Ctrl-Alt-F7.

It didn't work because I wasn't on a console - I was already in an X session. I could have switched to a text console, but I didn't want to. The fix is to make things less secure, as they were in Linux 15 years ago (I can't claim to understand all the consequences of the changes I'm about to show, so I don't really recommend it ... I'm just saying it worked for me). I edited /etc/X11/Xwrapper.config and added the following two lines (the only non-comment lines in the file):

# comment this line out:
#allowed_users=console
allowed_users=anybody
needs_root_rights=yes

After that, startx /usr/local/bin/ctwm -- vt8 worked. More or less. Unfortunately, I had chosen to do this setup on a machine that's a Barrier client ... and let me tell you, that doesn't play well. Explaining that would take a while: if you're a Barrier user, you'll figure it out, and if you're not don't worry about it.

A better method after initial debugging and testing as above is to run startx -- vt8 - if you do this, startx will read your ~/.xinitrc file which allows more flexibility in launching whatever WM and accompanying programs you want.

All of this will be moot eventually as we'll all be switching to Wayland soon. Or so I've been hearing for several years. And who knows? Maybe Wayland will handle virtual terminals the same way ...