How to keep a Linux GUI from starting up by default on boot

Facebooktwittergoogle_plusredditpinterestlinkedinmail

disable gui on linux desktopFor quite a while now I’ve been stuck trying to create a Laptop/Server on Linux. I’m talking about a laptop/server (it does both things), not a “server built on a laptop”. Why? Well, I have an old laptop (it’s so damn old it’s a Centrino) that I repurposed as a home server. That’s what it does 90% of the time. And for the rest of my day to day work, I use a desktop.

But, if I ever need to go on the road, I’m stuck with no PC. I either have to get a laptop on loan from someone, or work on my cell phone or tablet. And I’m really not a big fan of working on a cell phone or tablet: it’s pretty uncomfortable after a while. Now, on the road I don’t do any serious computing: just your regular old word processing, spreadsheets, checking email, surfing the web… see where I’m going here? If I have a dual-purpose laptop, and need to go on the road, I just grab it and go. And it doesn’t matter if my laptop is a Centrino from the stone age: if it can run Google Docs or Libreoffice fine, that’s what I need.

So, what problem did I have?

Where I was stuck was with the GUI. If you want to run Linux there’s no real “dual purpose” distributions. Most distributions give you either a “desktop” or “server” configuration from the factory, and you go from there. Server configurations usually don’t have a GUI (or have a limited one) and desktop configurations have a wonderful GUI, but it consumes system resources like crazy. And remember I’m running a dinosaur of a laptop here: you should hear the exhaust fan go crazy when the display manager starts on this thing.

disable gui on linux desktopIf I was running a more decent CPU, with more resources, I’d probably slap a desktop distribution on there, run a couple of apt sessions to install the missing server modules, and be done with it. But with this thing, I have to be a little bit more careful. Seeing how the graphical user interface makes the system load go crazy and the temperature shoot up, and considering that 90% of the time this particular laptop is going to be working as a headless server, it’s really not worth it to have a GUI running all the time. And before anyone starts talking about server maintenance,  I do all that stuff from the command line just fine, don’t need a GUI for that.

How I solved this one

To cut a long story short, initially I tried installing a barebones server distribution (I used Ubuntu server for that one) and putting a GUI on top of it. Turned out awful: the linux server GUI was missing a lot of those little tools that make desktop distributions very usable, and there were a ton of small configuration options you had to tweak to get everything to play together nicely.

So I went the other way: install a linux desktop distribution, and kill the GUI by default. Computer starts in text mode, and when I want a GUI, I load a GUI.

I found a wonderful Linux distribution for that idea, which is Linux Lite. It’s based on Ubuntu so I’m totally familiar with it, it has a lot of the server programs I need built in, and it’s designed to run on minimum system resources. Linux Lite was my candidate. I installed it, it worked, and a couple hours later the only thing I had left to do was deactivate the GUI by default.

disable gui on linux desktopAnd that’s where it started to get complicated, because Linux Lite is a desktop distribution. It assumes that everyone wants to run to GUI by default and that no one in their right mind would want to look at a command line. So Linux Lite protects the GUI so you can’t deactivate it by accident. On top of that since Linux Lite is based on Ubuntu, and Ubuntu isn’t exactly 100% compliant with linux policies, there’s minute differences that make it misbehave if you start editing your /etc configuration files.

In short, I spent several hours trying out all sorts of solutions that didn’t work. Everything from the unorthodox “chmod -x” on the /etc/init.d scripts, to playing around with runlevels and grub. And no matter what I did, the GUI always popped up and my system load and temperature went crazy.

Fortunately just as I was ready to give up I found a solution that actually worked. And it was way easier than I thought.

What I did was change the default systemd target. Sounds complicated, but it’s not. Linux Lite starts with a target called “graphical.target” by default… a “target” is sort of a profile that tells systemd what stuff to start on boot.

There’s another target built into Linux Lite called “multi-user.target”. That one simply boots into command line mode, with no GUI. What you do to switch is this:

  1. Sudo into root, or sudo each command. You’re going to be working with system settings here, and as a regular user, you’re probably not authorized to do this.
  2. Start by looking at your default, on the command line run systemctl get-default . Write down what you get, in my case, I got “graphical.target” as a reply from systemctl. If something messes up, you’ll need to revert to that setting, so remember it.
  3. Now, change your systemd target: systemctl set-default multi-user.target That sets your startup profile to regular old multi user command prompt.
  4. Run systemctl get-default again, to make sure your target was changed. You should now get “multi-user.target” as a reply.

Done. Next time you reboot, you’ll see the graphical Linux Lite logo pop up during the boot process, but then the entire system will drop to command line. Wonderful!

Now I just boot into text mode for server mode. And when I want to do some work on my laptop, I simply “startx” and up comes the lightdm GUI. And when I log out from the GUI, I’m right back at the command prompt. Exactly what I wanted.

I still have a bit of configuration left to do, to allow inbound ssh, file sharing and whatnot, but that’s easy compared to this GUI thing.

Facebooktwittergoogle_plusredditpinterestlinkedinmail