The Definitive Guide to Getting Your Linux Desktop Back

Despite every ounce of intuition in your body screaming “No, no, no, no, don’t do it!”, you did it anyway. You just had to click that button. The one that should have been big and red and marked SELF DESTRUCT. And now your computer’s buggered. Isn’t it lovely to have intuition give you it’s best gut wrenching “I told you so!” gloat.

Welcome to the definitive guide to getting your Linux desktop back.

Broken Desktop

What to do when Linux won’t let you log in..?

Whether you have a black screen, a flashing screen, just can’t get past the login screen or you’re stuck in the command-line, you are about to learn a few tricks that will help you get your Linux desktop back to full working order. You will even learn how to open multiple virtual desktops.

Written for Ubuntu, these Linux desktop recovery tricks are laid out in an easy to follow guide that presents recovery solutions in least destructive to this-could-break-everything-or-make-everything-better order.

Whether you’re suffering from an I-know-what-I’ve-done-how-do-I-fix-it problem or a my-Linux-desktop-is-broken-and-I-haven’t-a-clue-what’s-wrong-with-it-but-I-blame-the-kids kinda problem, there is a solution here for you.

A little knowledge goes a long way

Linux is primarily a non graphical operating system.The graphical environment you know and love is an optional component formed by a window system, a window manager and a desktop manager.

When a Linux graphical desktop environment breaks, it is usually caused by a bad setting in any of the following layers of the graphical environment:

  • the window system
  • the window manager
  • the desktop manager
  • the display manager

As well as bad configuration files, I have known for an update or the removal of a software package to also uninstall one or more of those layers or to remove software dependencies required by those layers.

My preferred Linux distro is Kubuntu which is built around Ubuntu. Ubuntu uses the X Window System as the basis of its graphical desktop environment. The X Window System, also called X, makes it possible for graphical programs to communicate with the hardware Linux runs on.

Sitting on top of X is a window manager. There are many different window managers. To name a few of them, we have Kwin, Metacity, Compiz and Emerald. The window manager decorates windows, provides menus and makes interaction with windows possible. Different Window Managers make the various flavors of Ubuntu look and feel different.

The desktop manager usually provides icons, windows, toolbars, folders, wallpapers and desktop widgets.

The login screen that usually greets you when your operating system loads is called the display manager or greeter. The display manager starts the X Server before the login screen shows and initializes the desktop session which loads when you login to your computer. If you were to stop the display manger from the command-line it would also stop your desktop session. Display managers are optional.

A good explanation of the roles played by the window system, window manager and desktop manager is given at tuxfiles.org.

We have Linux display errors Q&A forum here.

Getting the Desktop Back

I have not yet lost documents and files while using any of these methods to restore a Linux desktop from its broken state. However, it is always a good idea to be cautious. You should be able to use a Live Disc to gain access to files stored on the hard drive of a broken operating system. A guide to accessing files with a Live Disc is here.

I recommend you move through these desktop recovery solutions in order from one to eight. If you know what you did to cause your desktop to break then you might be able to guess the solution that will work best for you: what the hell, go with your hunch, I would.

The Preliminaries

First, print this guide or load it in your mobile browser so you have complete access to it.

If you have the command-line browser Lynx installed or if you can install Lynx and you have an Internet connection from your desktopless computer then you can open a second terminal environment with Ctrl+Alt+F2 or F3 (see this guide) and open this desktop recovery guide  in Lynx with the command:

Second, if you need to know the basic steps of how to find your way around the Linux command line then need to look at this navigation guide.

Third, access the Linux shell using Ctrl+Alt+F1. Follow this command line access guide if you cannot access the shell environment.

Fourth, stop the Linux display manager if it is running. Use these instructions to stop and start the Linux display manager. For example, sudo stop lightdm or sudo stop kdm.

Fifth, when the Xorg script begins loading the display it writes a log file to /var/log/Xorg.#.log (where # represents the display number. This is typically 0). Check the log file for error and warning messages with the following command:

Most warnings can be ignored but they do hint at possible solutions. Here’s an example of an ignorable warning (explanation here):

A common and easily fixed error relates to missing font directories. It can usually be ignored but if you wish to fix it you can install additional X Server fonts with

An FAQ of X Server error messages is at the Xorg Wiki.

Sixth, the config files .xinitrc, .xserverrc and .xsession are sometimes placed into a user’s home directory. They can be useful when deliberately placed there by a user to override global settings of the X Window Server but when these files get corrupted they can prevent X from initializing properly. Run the next command to rename these files to prevent them from being used:

Do not recreate these files just yet. Instructions for (re)creating xinitrc, xserverrc and xsession scripts are here for when you need them.

Seventh, these preliminary steps might have fixed your computer so restart your computer with

or

Just a tip: if your computer is being stubborn about being switched off, hold the power button in for 30 seconds.

If your desktop still refuses to load, try the following solutions.

The definitive guide to getting the Linux desktop back

Starting a desktop session as a new user is an excellent way to determine whether a desktop loading error is due to a misconfiguration. If you can log into a desktop environment as a different user then the issue relates to something specific in the desktop configuration of the user whose desktop will not load.

Testing whether you can log in as a different user may help you decide which of the following solutions will work best. If you can successfully log in to a desktop environment as a different user you might find some of these solutions easier to employ.

Solution One: clean var/tmp/

Drop to a shell at the login prompt or use a LiveDisc to get access to the root file system. Browse to /var/tmp/ and check for big files. Delete those big files.

The directory at /var/tmp/ sometimes gets overfilled with huge error logs. I recently found I could not log into Kubuntu because of several huge 16GB dmesg monster zip files. Those zip files would have gotten bigger except they had filled up my OS drive so could grow no more.

Check your OS partition is not full. If it is, remove a few files.

Solution Two: update everything

A botched software update might have caused you to lose your desktop. A bug fix might have been released so update your software package list then upgrade your system. Drop to shell then type:

Next install Aptitude:

Then install missing package dependencies and do a full upgrade with

Restart your computer by typing sudo reboot to check whether the problem has gone away.

Solution Three: reconfigure the window system

A messed up xorg configuration can prevent the X Window System loading properly so reconfigure it with

Restart your computer by typing sudo reboot.

Solution Four: reconfigure the window manager

Different desktop managers tend to use different window managers. Table 1, below, shows commonly used combinations of desktop manager, window manager and display manager software. Refer to table 1 to learn which display manager your system uses then stop it before reconfiguring your window manager with

For example, if you use Kubuntu, your OS will use the KDE desktop environment and the “kde-workspace” window manager (also known as Kwin). You would reconfigure it with

Restart your display manager as shown in Table 1 of Starting (and Stopping) a New Desktop. For example, “sudo start [display manager].

Press Ctrl+Alt+F7 to try to access the graphical environment. If the terminal display at Ctrl+Alt+F7 stays blank, try F8 through F12 instead of F7.

Solution Five: reconfigure the display manager

Reconfigure the display manager or, if you have more than one display manager installed, check which one is set as the default manager then either reconfigure it or set a new default display manager.

First discover the default display manager:

Which will show something like this

The string after the third forward slash is the name of the default display manager. In this case, the display manager is “kdm”.

Stop the display manager with

Next, reconfigure the display manager with

A list of installed display managers is shown during reconfiguration. Make a note of them because you might need to re-install them all.

Choose a display manager to use at login then restart the display manager with

Re-access your GUI with Ctrl+Alt+F7.

Using kdm as an example, I would reconfigure my display manager with

If your desktop still fails to load after a reboot and more than one display manager is installed on your system, try another display manager. Set the OS to use the original display manager if no other display manager option works.

Solution Six: reinstall the window system, window manager and display manager

Where reconfiguration fails, re-installation might succeed.

The Window System is easiest to reinstall:

The Window Manager is easy to reinstall if you know which window manager your system uses. Refer to table 1 to discover which window manager you might be using.

Replace [window manager] with one of the window managers shown in table 1.

Table 1: Common Window & Display Manager Combinations
Example Distro Desktop Environment Window Manager Display Manager
Ubuntu GNOME metacity gdm
Kubuntu KDE kde-workspace kdm
Kubuntu GNOME & KDE compiz kdm or gdm
Ubuntu Unity unity gdm
Lubuntu LXDE lxde ldm
Xubuntu XFCE xfce4 lxdm

For example, to reinstall the GNOME window manager, Metacity, use,

Most display managers can be used in combination with any window manager. For example, you can use GDM with KDE or KDM with GNOME. Refer to table 2 to find out which display manager your computer most likely uses then re-install it with:

For example, if you use KDE then your display manager will likely be KDM so install it with

A more brutal option is to purge the installed window manager and display manager packages from your computer. Purging removes all configuration files so any settings used for the desktop environment would be lost if you purged the system. If the other solutions fail to work then purging might be your only option. Try all other options first and come back to this section if they fail to bring your desktop back to life.

Only purge packages if you have an Internet connection or another means of downloading and re-installing purged packages.

Firstly, make sure any packages to be installed are downloaded afresh by clearing the cache of downloaded packages with

Secondly, purge packages with the command

Thirdly, reinstall the purged package with

Finally, restart your computer.

For example, to purge and reinstall Unity:

Solution Seven: switch to a basic graphics driver

Many graphics problems, blank screens and desktop loading issues are caused by misconfigured, corrupt or buggy graphics drivers. Propriety graphics drivers such as those used by ATI and NVIDIA graphics cards can be especially troublesome.

The easiest way to fix a bad VGA driver is to disable the driver and to use a generic driver such as MESA or VESA. This can be done by recreating the xorg.conf file:

  1. Drop to a shell
  2. Stop your display manager as shown in table 1 of this guide e.g “sudo stop kdm” or “sudo stop gdm”
  3. Delete your xorg.conf file
  4. Paying attention to the capital X, recreate a default xorg.conf file with
  5. The new xorg.conf file will be in your home directory. Move it to /etc/X11/ with
  6. Restart your display manager with “sudo start kdm” or “sudo start gdm” etc…
  7. Access the graphical environment with Ctrl+Alt+F7

xorg.conf stores configuration settings for your display driver. Running the Xorg -configure command causes Xorg to create an xorg.conf file that specifies the use of a generic graphics driver.

Once a generic driver is in use you should be able to load your desktop and install the propriety driver again. Hope that doing so fixes the original issue; if it does not you will need to reset to the generic MESA or VESA driver. If creating a new xorg.conf file does not fix your desktop then you will at least know that your desktop loading error is not necessarily related to your graphics driver.

Solution Eight: reinstall your desktop manager or install a new one

This could take some time because your computer might need to download a lot of software packages.

To reinstall your desktop manager, choose the appropriate installation command for your distro from this list:

Ubuntu

Kubuntu

Lubuntu

Xubuntu

Edubuntu

The good news here is that you can install multiple desktop environments into Linux and Linux will love you for it.

Installing an alternative desktop environment will provide you with a desktop to use until your regular one is fixed. To install a new desktop environment, use the above commands but replace sudo aptitude reinstall with apt-get install.

For example, if you use Ubuntu you can install Kubuntu along side Ubuntu with:

An alternative way to install a new desktop environment is to use Tasksel. Install Tasksel with “sudo apt-get install tasksel” then run it from the command line with “sudo tasksel”. Once Tasksel is loaded, use the up and down arrow keys to scroll through the software packages, use the space bar to select packages and use the enter key to commit changes.

Solution Nine: reconfigure everything

If you are adamant that you want your desktop fixed because you can’t live life without it then a completely nuclear approach is to reconfigure everything. In this case, “everything” does mean every single bit of software installed on your computer via its package manager.

Reconfiguration is achieved with

The option –priority=critical instructs DPKG to show questions that absolutely must be answered by a human to enable a package to be configured. Keep watching the shell because you will need to answer occasional questions that must be answered before DPKG can continue processing software.

A common error chucked out by dpkg while everything is being reconfigured is

The solution is to run the following sed command to comment out any lines beginning “dpkg-maintscript-helper”. These lines are found in all cron files stored in /var/lib/dpkg/info/

After DPKG has reconfigured everything, uncomment those lines with the sed command

If reconfiguring everything does not enable you to gain access to a desktop and none of the other solutions presented in this guide to fixing desktop loading errors revives your desktop then I suggest you use a Live Disc to access your hard drive then backup your home directory and any files you want to keep then reinstall your OS. Alternatively, keep searching for solutions and post them here so we can all benefit from them.

Visit our Linux display errors Q&A forum for more help.

Comments

  1. Brian Davids says

    This is awesome. Thank you. My Linux Mint 14 laptop ran out of battery and after a recharge, I couldn’t get my GUI back after boot. I tried repeated shift on boot, no go. Tried ESC on boot and it brought back the GUI.

  2. John Wayne says

    Wow, excellent article. Helped me fixing my broken Ubuntu and improved my knowledge of Linux desktop environments…

  3. Dirk Ducati says

    I broke a system on purpose just to try this out. I’m not sure exactly which step fixed my system, but after trying everything a couple times. . . it worked! BooYah!!!

  4. says

    very , very , helpfull – I know theres lots of help on the internet – but why o why can it not be included within any of the linux distro’s in a big plain easy to see help file. – once again – thanks alot :D

  5. Robin says

    Hi great help file – i was very hopeful to fix my problem but nothing worked.

    I have a SONY vivobook with an Optimus NVIDIA card. I installed Bumblebee and everything worked fine but for some reason I decided to uninstall it and since then my laptop screen is black. When I connect an external monitor I can use that but the latop screen doesn’t work anymore at all. Funny thing is that when I take a screenshot it shows that the laptop screen is there.

    I don’t see a boot screen or purple border or nothing when it starts up.

    When I try to reconfigure xorg.conf i get the following error: “Number of created screens does not match number of detected devices. Configuration failed”

    I have tried all of your suggestions above.

    I even tried to reinstall but when I start up the screen is always black I can’t get into BIOS or do anything.

    Any suggestions would be appreciated – spent so many hours on this and it just doesn’t work. Really started to like Ubuntu 14.04 until this crippled my machine.

    • says

      Hi Robin.

      The BIOS screen for a VivoBook is normally accessed by holding or continuously tapping the F2 key or the Esc key during boot. When booting the laptop, make sure the laptop is completely switched off before pressing the power button.

      But, I doubt you need to access the BIOS to solve this. Here is what I would do:

      1) I would use the external monitor (because that works) then uninstall the Nvidia card’s device drivers and related software. I would use Synaptic to remove the Nvidia software. Use ‘purge’ to completely remove the software and all configurations. You can install synaptic with sudo apt-get install synaptic or use the Ubuntu software manager.

      2) Next I would go to the home directory and remove the following files (if found): .xinitrc, .xserverrc and .xsession.

      3) Then I would shutdown the computer, disconnect the external monitor then restart the computer. Might need to run sudo dpkg-reconfigure xserver-xorg at this point from a terminal (Ctrl+Alt+F2). Make sure the external monitor is not connected on restart or when running dpkg-reconfigure xserver-xorg.

      4) Lastly, I would restart the laptop and reinstall the Nvidia software.

      Let us know how you get on.

Leave a Reply