Ubuntu Linux shutdown the X server

Recently someone asked me a question – “How do I shutdown the X server, so that I have a command line prompt on the console?

Well answer is very simple use script located at /etc/init.d/ directory. If you are using KDE desktop type the command (make sure you save all the work as following command does not ask confirmation):

sudo /etc/init.d/kdm stop

Within few seconds you should be dropped to a command line prompt on the console. To start GUI type command:

sudo /etc/init.d/kdm start

If you are using GNOME:

sudo /etc/init.d/gdm stop

Again to start GNOME desktop:

sudo /etc/init.d/gdm start

Another way – You can change the current runlevel

From a command line, you can use the init command to go immediately into runlevel 1, which is also known as single user text mode. Open terminal and type the following command:

sudo init 1

Again get back to GUI with init 2 command:

sudo init 2

When you type init 1 command your session will then begin to shut down and bring you into single user text mode. When you type init 2 command your session will then begin to shut down and bring you into GUI mode :)

Pretty easy ahh?

So what are GDM and KDM?

  • GDM (the GNOME Display Manager) provides an alternate display manager for the X Window System.
  • KDM (the KDE Display Manger) provides an alternate display manager for the X Window System.
  • In short, both of them are a graphical login interface for computers using Linux or Unix-like operating systems.

Meet the Author

Admin

I like chocolate, gadgets, open source software, photography, traveling and all shades of green colors. I love spending time with fun loving friends and family members. This is my own online journal.

17 comments… add one
  • Alberto Milone Aug 1, 2006, 8:37 am

    You can also type:

    sudo /etc/init.d/gdm restart

    OR

    sudo /etc/init.d/kdm restart

  • vivek Aug 1, 2006, 4:14 pm

    Alberto,

    Well, restart argument will restart the X server. My friends want to shutdown X and go to command line prompt on the console and that is what stop does.

  • T 709 Aug 10, 2006, 8:49 am

    Ubunto ships with a generic video driver for NVIDIA graphic cards (nv). Recent NVIDIA cards should use the newer nvidia kernel module. To achieve this, install nvidia-glx package first. Then change settings in section Device of your recent X11 configuration in /etc/X11/xorg.conf.


    Section "Device"
    Identifier "Graphics Card Identifier String *DO NOT CHANGE*"
    Driver "nvidia"
    EndSection

    Since Graphics Card Identifier String is referenced by onother section, you should not edit this! Only change the module name from nv to nvidia.

    Then restart the X-server. Here we are again.

    P.S. Resolution of the monitor can be added in the section Screen, subsection Display of xorg.conf. See man xorg.conf for details.

  • bill kress May 28, 2007, 5:29 am

    This is driving me nuts. Why did ubuntu mess with runlevels???

    On every other system I’ve ever used, runlevel 1 was single user, 3 was multi-user and 5 was GUI.

    Now it’s like there is only 1 and 5. I’ve never figured out a way to get into multi-user console mode.

    I tried your suggestion:

    bill@bill-laptop-LT:~/scripts$ sudo /etc/init.d/gdm stop
    * Stopping GNOME Display Manager… [ OK ]

    The reason I could paste that is because it’s still there and I’m still running, absolutely nothing happened.

    This is an extremely annoying flaw in an otherwise pretty good system, but whoever decided it would be just so neat to mess with the runlevels should have svn commit rights revoked for life.

  • vivek May 28, 2007, 3:56 pm

    Bill,

    try init 3 command:
    sudo telinit 3

    You can fix this problem by editing /etc/event.d/rc-default file
    Goto /etc/rc3.d and remove gdm entry
    sudo rm *gdm*
    Open vi /etc/event.d/rc-default
    sudo vi /etc/event.d/rc-default

    Find all lines read as – telinit 2 and replace with telinit 3
    telinit 3

    Close and save the file. Reboot system.

  • bill kress Jun 1, 2007, 8:44 am

    Thank you, that feels like a huge weight off my shoulders :)

    It worked and I think I understand that the rcn.d system isn’t as scary as I thought.

    One correction, I think you meant for me to remove the gdm entry from rc2.d?

    What was the telinit change? Does that mean default to runlevel 3 instead of 2? If so, I noticed some differences in other runlevels (4&5), are these levels just unused?

    Thanks again,

    Bill

  • galdir Sep 5, 2007, 4:52 pm

    maybe these dificulties are because ubuntu is using upstart… Im learning somethings about that

  • sdshields Oct 17, 2008, 8:37 pm

    Using Ubuntu 8.04, when I type sudo /etc/init.d/kdm stop, it doesn’t drop to a command prompt. It drops to some text on the screen, but the prompt never shows. cntr-alt-del stops gnome and restarts the PC.

  • manu Nov 6, 2008, 11:02 am

    I might be late in replying but sdshields when you get the text on the screen you need to press alt + f1 or any other function key to go to a console. Then you can login from there.

  • Arun Feb 13, 2009, 11:59 am

    Ubuntu 8.10, when you are Grub loader menu, you can choose to run the Ubuntu in diagnostic Mode.
    So the X server is not started.
    You directly land at the root,
    $ pwd
    $ /root
    $cd /
    $cd —> go the directory where you have stored the NVIDIA*.run file
    $sh NVIDIA*.run

    Now you should be able to see the NVIDIA setup … follow instructions and it is done :)

    I got strange problem after I installed the NVIDIA driver. When I booted into Ubuntu … the NVIDIA logo came … that was fine … I entered my user/pass at gui interface …
    But then my screen suddenly turned BLACK … No Display …
    Ctrl+Alt+F7 bought back the GUI display … I am afraid I have to do it every time … Any isead why it gave me Blank Screen !

    – Arun

  • sunny dhabhai Jul 2, 2009, 1:46 pm

    giving ‘gdm stop’ sometimes dont work since X server still running
    just do like this
    pass ‘gdm stop’ in grapical mode a blue window saying X is running at display :0 whatever; dont press yes or knw let it be press
    alt+f1
    >login root
    now to stop X server delete running process pic localted at :
    rm /tmp/.X0 (xserver is at zero ,you can find it at /tmp/.X then tab to find whrer display running
    after deleting this file you are done !!

    cd /tmp ( contain running pids of all process running )
    then
    rm .X press tab its like .X0 in my box
    delete it

  • Luc Nov 14, 2009, 2:19 am

    thank you very much:
    after:
    sudo /etc/init.d/gdm stop
    I can stop X but can not login to my system any more. (I am certain that uname and passwd is correct but still fail). What might be the cause?

  • Roger Nov 18, 2009, 6:34 pm

    Hi,
    I also can’t stop Gnome typing
    sudo /etc/init.d/gdm stop
    The complete system then hangs for any reason.
    Come on, there are many ways to get it done, e.g.
    sudo gedit /etc/init.d/gdm
    Search for “start)”. Change it to “dostart)”. Save the file.
    shutdown -r now
    Bingo! Do your job and start x with
    sudo /etc/init.d/gdm dostart
    or simply try startx. Should work.
    sudo gedit /etc/init.d/gdm
    Search for “dostart)”. Change it back to “start)”. Save.
    Besides its not a bad idea to copy gdm to your desktop before this operation. Do it as root, so type sudo cp … So you can copy it back if something bad has happened.

  • d9ping Jul 7, 2010, 1:55 pm

    It doesn’t work anymore in ubuntu 10.04.

    $ sudo /etc/init.d/gdm stop
    sudo: /etc/init.d/gdm: command not found

  • Anonymous Aug 6, 2010, 2:37 am

    In ubuntu 10.04 press CTRL+ALT+F1 and type (without the quotes) “sudo service gdm stop”
    to start it type (again without the quotes) “sudo service gdm start” and after srart if youre not automatically kicked back into X, just press CTRL+ALT+F7

  • Bob Feb 11, 2011, 12:48 am

    I just want to shut down x windows???? Why do I have to edit a bunch of files and potentially corrupt my installation????

  • dutchy Mar 17, 2011, 2:17 pm

    With Ubuntu 10.04+ they changed the system to use service menus, so this is the new format to accomplish the same thing:

    $sudo service gdm stop

Leave a Comment