How to Stop and Start GUI on Debian

debiangnomegui

I would like to start Debian without the GUI and then just type commands in to launch the desired programs (which are located on my local machine), eg

$ chromium-browser &

I already do a similar thing when sshing in to other machines on the LAN – it is handy if I need to visualise csv data for example in soffice. i currently have gnome desktop and Debian 7 installed.

I have found some instructions for disabling the GUI on startup with Debian, however I am reluctant to try them out for fear of being locked out of using the web browser once I do this (I will need it to seek help using the browser if I get stuck).

I was wondering if I could temporarily test out the method of starting the GUI on one of the other terminals (eg ctrl+alt+f1) to see if there are any problems? Will this work? Will it be equivalent to starting the GUI when booting without a GUI?

If this is feasible, please could someone provide full instructions for:

  • enabling the GUI on terminal f1 so that i can run gui programs (without showing the full desktop interface)
  • turning off the desktop interface GUI on bootup

obviously I will need to run X11 to load GUI programs – that's fine, but I'm looking to boot up into text mode and then just execute GUI programs as needed.

doing some tests on an ubuntu 12.04 virtualbox vm (hopefully not too different to debian 7?)…

$ ps aux | grep gdm
# *blank*
$ ps aux | grep kdm
# *blank*
$ ps aux | grep lightdm
root      1225  0.0  0.0 270664  3500 ?        Ssl  12:43   0:00 lightdm
root      1234  1.9  2.2 236564 112276 tty7    Ss+  12:43   0:01 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch -background none
root      1382  0.0  0.0 156772  3572 ?        Sl   12:43   0:00 lightdm --session-child 12 19
$ sudo update-rc.d lightdm disable
update-rc.d: warning: /etc/init.d/lightdm missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Disabling system startup links for /etc/init.d/lightdm ...
 Removing any system startup links for /etc/init.d/lightdm ...
   /etc/rc0.d/K20lightdm
   /etc/rc1.d/K20lightdm
   /etc/rc2.d/K80lightdm
   /etc/rc3.d/K80lightdm
   /etc/rc4.d/K80lightdm
   /etc/rc5.d/K80lightdm
   /etc/rc6.d/K20lightdm
 Adding system startup for /etc/init.d/lightdm ...
   /etc/rc0.d/K20lightdm -> ../init.d/lightdm
   /etc/rc1.d/K20lightdm -> ../init.d/lightdm
   /etc/rc6.d/K20lightdm -> ../init.d/lightdm
   /etc/rc2.d/K80lightdm -> ../init.d/lightdm
   /etc/rc3.d/K80lightdm -> ../init.d/lightdm
   /etc/rc4.d/K80lightdm -> ../init.d/lightdm
   /etc/rc5.d/K80lightdm -> ../init.d/lightdm
$ sudo shutdown -r 0

and the gui is back up and running again after the reboot! so this clearly did not have the desird effect. however:

$ sudo /etc/init.d/lightdm stop

kills the gui. moving to tty2 (by pressing ctrl+alt+f2) and attempting to open firefox:

$ firefox &
Error: no display specified

so attempting to specify a display:

$ export DISPLAY='0.0'
$ firefox &
Error: cannot open display: 0.0

and now i'm stuck. i can still get the gui back on ctrl+alt+f7 by entering the following into tty2:

$ sudo /etc/init.d/lightdm start

but this is not what i want. i just want to be able to run firefox without showing all the other desktop things such as the clock and the menu bars, etc.

trying out some of the things in goldilocks' answer

$ sudo /etc/init.d/lightdm stop
$ echo "#!/bin/bash" > ~/.xinitrc
$ echo "exec firefox" >> ~/.xinitrc
$ xinit

this does exactly what i want :)

Best Answer

The instructions to disable xdm/kdm/gdm/whichever-dm-you-have is correct. If you don't do this, you boot to a graphical login (that's the dm = display manager), and then whenever you quit X (which should be as easy as ctrl-alt-backspace -- try it, but close your apps first), the DM will respawn another graphical login, making it impossible to escape the GUI.

Another possibility with debian is to check in /etc/rc[N].d for a runlevel which does not start the dm, and make that the initdefault in /etc/inittab. I don't have an unmodified debian system at hand, so I can't say which if any that will be -- possibly 2. Do not choose 0, 1, or 6.

Once the dm is disabled, you boot to a login console. From there you can start X with the command startx. This includes a default DE and if you've been using gnome that will probably be it. You can also create an ~/.xinitrc, which is a shell script which will be run in place of the default. Generally they can be pretty minimal, eg:

#!/bin/sh

exec gnome-session

Should start gnome (I believe -- I don't have a gnome system at hand either).

Note that you can't run a GUI application without X; it's not clear from your post you understand that. GUI programs are actually clients that need the Xorg server to work. You can start a bare X with no DE or WM and a specific application by replacing the exec gnome-session line with the name of the application, but beware you'll then have no way to start anything else and when you close that application, you'll be looking at a blank screen with a cursor floating in it.

There's nothing dangerous in all this and it is easy to re-enable the DM if you want.

Related Question