SEARCH

How-To Geek

4 Ways to Recover From a Crashed or Frozen X Server on Linux

frozen tux

The X server on Linux provides your graphical desktop. If it crashes, you’ll lose all unsaved work in graphical programs, but you can recover from the crash and restart the X server without restarting your computer.

X server crashes can be caused by bugs with graphics drivers – the proprietary AMD or NVIDIA graphics drivers, for example – hardware problems, or other software bugs.

Image Credit: Francois Schnell on Flickr

Ctrl+Alt+Backspace

The Ctrl+Alt+Backspace keyboard shortcut traditionally restarted the X server on Linux. However, after complaints – particularly from new Linux users that accidentally hit this key combination and lost all their work — this shortcut was disabled by default. To enable it on Ubuntu, Fedora, or any other distribution using a GNOME-based desktop, you can use the Keyboard Layout utility.

image

Click the Options button and enable the Control + Alt + Backspace check box under Key sequence to kill the X server.

image

After it’s enabled, you can press Ctrl+Alt+Backspace to immediately restart your X server. However, this shortcut is implemented by the X server and may not work if X hangs in some ways.

Switch Virtual Consoles

You can use the Ctrl+Alt+F1 keyboard shortcut (and other F-key keyboard shortcuts) to switch to a different virtual console from your X server. (Ctrl+Alt+F7 usually takes you back to X – the exact F key depends on your Linux distribution.)

Once you have, you can log into the virtual console and run the appropriate command to restart your X server. The command you’ll need depends on the display manager you’re using. On Ubuntu, which uses the LightDM display manager, you’d use the following command:

sudo service lightdm restart

image

SSH Into Computer

If you can’t kill the X server locally, you can kill it over the network. Assuming you have an SSH server set up and running on your Linux system, you can log in from another computer and run the appropriate command to restart the X server. Just sign in via SSH to access a remote console and use the appropriate command to restart your display manager – on Ubuntu, it’s the sudo service lightdm restart command above.

image

Use the Magic SysRq Key

We’ve covered using the magic SysRq key in the past – the SysRq is is generally the same as the Print Screen key. Assuming you want to kill the X server locally – not over the network – your system may not be responding to key presses, including the Ctrl+Alt+F1 keyboard shortcut. This can occur because the X server has taken control of the keyboard. To take control away from the X server, use the following key combination:

Alt+SysRq+r

After you have, you can try pressing Ctrl+Alt+F1 to access a virtual console. You can also use the Alt+SysRq+k combination, which kills all programs on your current virtual console, including your X server.

If you want to restart your computer, you can also use the magic SysRq key to cleanly restart your system – see our full post on the magic SysRq key for more information.

Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.

  • Published 07/18/12

Comments (6)

  1. Paul

    Linux crashes? I thought it was meant to be immune to that?

  2. RonV42

    I have lost work many times to flakey x-server/display manager/video driver issues. At least in windows if explorer crashes your app usually still displays and it will allow you to save your work.

  3. TheFu

    @Paul – just the GUI crashes, the OS is still running and so are all the non-GUI apps. You can actually pop in using a different console or from a remote computer and restart it. X Doesn’t crash very often, maybe once every 4+ yrs for me, unless I’ve been dumb and replaced a perfectly working proprietary blob driver with a newer version in the belief that AMD or nVidia made it better. 99% of the time, I was confused and was left with a buggy video driver.

    When the MS-Windows GUI locks up, there is only 1 solution – “Hello, IT. Have you tried turning it off and on again? Uh… okay, well, the button on the side, is it glowing? …yeah, you need to turn it on… uh, the button turns it on… yeah, you do know how a button works don’t you? No, not on clothes.”
    https://en.wikiquote.org/wiki/The_IT_Crowd#Yesterday.27s_Jam_.5B1.1.5D

    Something missing from this discussion is the idea of X/Windows Clients and X/Windows Servers.
    The “server” runs on the PC you are sitting behind.
    The “client” runs on whichever system runs the program. That could be the same system as the server or across the world. I’ve run X-clients located in Russia from my work in Houston before and this was in 1994. Every GUI application is an X-client that talks to an X-Server which handles the mouse, keyboard, display … There is a performance hit for this, which is why DirectX isn’t easy to port to X/Windows platforms. DirectX doesn’t understand remote displays.

    Killing the X/Server sends a ‘kill’ signal to all running X/clients for them to close. You can do this manually with the ‘kill’ command – ‘kill -HUP {pid}’ or use ‘xkill’ to turn your mouse into a poison cross-hairs ready to be clicked on any window to kill it. Try it with a terminal window. That program tells your window manager to send the kill signal to the X-client in the same way.

    Wikipedia has a great article on X/Windows https://en.wikipedia.org/wiki/X_Window_System if you’d like to learn more. The client/server relationship is opposite what we usually think of as the C/S design. You might be able to find an old X/Windows programmer like me to ask more detailed questions. I still have all the books 1-6b from those fairly expensive classes on Xlib, Xt, and Xm toolkits.

    Anyway, X is amazing and has some fantastic built-in features that no other GUI tools support. It is also fun to mess with other people on the same LAN sending raw X-events to their desktop X-server if they don’t have it locked down properly.

  4. Cambo

    @Paul

    No OS is immune to crashes (Mac’s too).

    It’s the frequency of such crashes that make the difference, as well as attack footprints. Most often it’s the GUI that crashes in Linux, not the underlying OS. If the GUI crashes, the OS will usually keep ticking. Usually the reason Linux servers don’t normally install a GUI.

    In Windows, if the GUI crashes, the whole boat sinks. Sometimes restarting explorer.exe will work, sometimes it doesn’t.

  5. Sudo Bash

    @Paul

    If Linux crashed then these solutions will not work. Linux and its GUI are two separate things unlike windows. You can use different desktop environments or window managers with the same old Linux kernel. You can even scrap X11 and run what you need directly on the framebuffer.

    Look at the top of the post:
    “X server crashes can be caused by bugs with graphics drivers – the proprietary AMD or NVIDIA graphics drivers, for example – hardware problems, or other software bugs.”

    No OS is perfect, but my preference is Linux. I rarely have any problems. (When I do it is generally because of my own mistakes. ;)

  6. cam2644

    Never experienced anything like this on Linux but it’s useful info to put away for that rainy day.

Enter Your Email Here to Get Access for Free:

Go check your email!