Boot Ubuntu 16.04 into command line / do not start GUI

31

20

I want my Ubuntu 16.04 to not start GUI on boot and show command line console only. I have tried the following recipies but none of them are for version 16.04 and so they do not seem to work — GUI starts anyway:

  1. GRUB_CMDLINE_LINUX=”text”

  2. Changing the default runlevel

Ideally I also want to be able to start GUI by typig a command.

Greendrake

Posted 2016-07-28T17:26:25.383

Reputation: 647

Answers

27

You could disable the display manager service with systemctl. For example if your display manager is lightdm then run:

sudo systemctl disable lightdm.service

This will prevent the service from starting at boot.

Edit:

I forgot to mention how to start the GUI. It is as simple as starting the systemd service:

sudo systemctl start lightdm.service

Tristan Vigil

Posted 2016-07-28T17:26:25.383

Reputation: 548

1This worked for me on 16.04 on a arm board. Thanks. :) – wojci – 2016-11-09T18:51:26.840

This did not work on my system. (16.04 LTS on a PC) It shows the initial screen with all the [ OK ] messages as the services start, and then freezes. – Paul Williams – 2018-03-30T03:24:43.690

BTW to re-enable the service the command is actually sudo systemctl enable lightdm.service – Paul Williams – 2018-03-30T04:25:07.730

17

Instead of text use runlevel 3:

GRUB_CMDLINE_LINUX="3"

# To remove all the fancy graphics you need to get rid of `splash`.
GRUB_CMDLINE_LINUX_DEFAULT=”quiet”

# Uncomment to disable graphical terminal (grub-pc only) 
GRUB_TERMINAL=console

Then update-grub and reboot.


But you really only need GRUB_CMDLINE_LINUX="3". For quick test hit ESC during booting to get into the grub boot menu. Then press e and find the line which specifies kernel and add 3 at the end:

 linux /vmlinuz root=/dev/mapper/ubuntu ro 3

Boot it with CTRL+x


Ideally I also want to be able to start GUI by typig a command.

One of these:

$ sudo telinit 5
$ sudo service lightdm restart
$ sudo systemctl start lightdm

Tested on Ubuntu 16.04.1 LTS.

A.D.

Posted 2016-07-28T17:26:25.383

Reputation: 416

2Replacing "text" by "3", worked for me ! Very efficient ! Thanks – ThomasGuenet – 2017-01-26T17:02:30.727

hi. the answer looks nice but its hard to understand. I just Ideally need one command to boot into text mode, do what I need, and go back into normal desktop mode. – nyxee – 2017-08-19T02:29:49.157

1@nyxee My answer has 3 sections. Follow the second: "For quick test hit..." – A.D. – 2017-08-19T06:29:27.003

I appreciate the information in your post. by the time people look for this information, they are normally exhausted with other options. I gave an example of a simple answer below. – nyxee – 2017-08-19T23:32:14.770

1Nice answer. I'm just used to post longer answers with a lot of information so we all can learn more. And also I'm familiar with grub cmd line options so it's faster for me to add 3 and I'm good to go + it's multi-distro solution :) – A.D. – 2017-08-20T16:40:55.433

I'm still looking at it to understand whats going on. When i'm done with the unity issues i'll be back . just had to uninstall ubuntu-desktop and unity (the original cause of my problems) – nyxee – 2017-08-22T10:31:06.203

great answer, which file contain the "linux /vmlinuz root=/dev/mapper/ubuntu ro 3" command ? – Max L. – 2017-09-30T16:01:59.990

/boot/grub/grub.cfg but this file is generated so you should be doing changes in /etc/default/grub instead. – A.D. – 2017-09-30T16:37:18.270

11

  • When in GUI-mode, this will take you to text-mode (runlevel 2,3,4) on reboot. You may get a blank screen (no-gui) which is a reminder that there's no GUI :-), enter ctrlalt(F1,F2,...) to use the runlevels.

systemctl set-default multi-user.target

  • This will take you back to GUI boot when you are in text-mode.

systemctl set-default graphical.target

nyxee

Posted 2016-07-28T17:26:25.383

Reputation: 241

9

One of the following, as part of the kernel command line (editable via GRUB), should work:

  • systemd.unit=multi-user.target will override the default of "graphical.target" – this, along with systemctl set-default, is the equivalent of "default runlevel";
  • systemd.mask=lightdm.service will forbid a specific service from starting, until manually systemctl unmask'd later;
  • systemd.mask=display-manager.service – same;
  • rescue aka systemd.unit=rescue.target is the equivalent of "single-user runlevel"; not for daily use, but useful when fixing broken GUI.

user1686

Posted 2016-07-28T17:26:25.383

Reputation: 283 655

it would be useful to mention how you return to normality from that "emergency setting" . – nyxee – 2017-08-19T02:27:36.353

1For the benefit of others, the actual CLI command you want is systemctl set-default multi-user.target (and I believe systemctl set-default graphical.target would reset it) – Andrea – 2017-09-17T20:19:27.363

That's only if you want it semi-permanent, and can reach a shell in the first place. The main post has nothing to do with CLI commands. – user1686 – 2017-09-17T22:08:31.197

3

for ubuntu 18.04 enable root user

 sudo passwd

and then

systemctl set-default multi-user.target

Mohannd

Posted 2016-07-28T17:26:25.383

Reputation: 187