Ubuntu – Switching to another TTY after running startx and returning breaks Xorg

12.04framebufferttyxorg

I've always been curious about an idiosyncrasy of Xorg that seems to happen on every machine I've tried it on; whenever I start a new X instance on a TTY using startx manually (that is, without the aid of a display manager), switch to another TTY, and then attempt to return to my original TTY, X's framebuffer breaks and I'm dropped to my original shell with X still running. Hitting ^C or ^D will stop X, but I'll have to run startx/xinit again, losing my original session. I.e:

CTRL+ALT+F1
$ startx /usr/bin/xterm -- :1
CTRL+ALT+F7
CTRL+ALT+F1

Will break my X buffer on TTY1. It seems that applications that rely on Wayland/Mir for composition handle TTY switching like I'd expect, but for applications that use X that aren't started with a display manager like LightDM, being unable to return to the X session I manually started is a real pain. Is there any way to correct this problem so that I can switch back to my X session when I switch TTYs?

Best Answer

Ah, the solution was relatively simple, instead of running

$ startx /usr/bin/xterm -- :1

Running

$ startx /usr/bin/xterm -- :1 vt$(tty | sed -e "s:/dev/tty::")

Will prevent X from breaking when I switch TTYs.

Related Question