How to make desktop Ubuntu boot in headless mode?


#1

Hi,

up until now I’ve used my Ubuntu 18.04 desktop as my main machine. But now I’ve bought a macbook and from now on I’d like to use my Ubuntu machine as a server/headless. I have two questions:

  1. what do I need to configure to start Ubuntu without the desktop environment by default? (what I’ve tried so far below)
  2. what is the best way to manage the files of my Ubuntu machine from my mac? On Linux I’ve often used the sshfs integration of nemo. I’d really to use finder/forklift to manage all filesystem related tasks. I’ve found FUSE for mac which can enable sshfs, but haven’t tested it yet. Not sure if sshfs really is the best way to go.

what I’ve tried to deactivate the desktop by default:

  • stop the gdm3 service via sudo systemctl disable gdm3.service
  • change GRUB_CMD_LINUX_DEFAULT="text" in /etc/default/grub (updated grub afterwards)
    but none of that seems to have had any effect.

Thanks for your help.


(Marc Rostock) #2

I am not sure I fully understand your question. :grimacing:

In order to use your machine in “server mode” from your macbook, it is not really important whether a desktop is installed or running on your “server” but rather that the right tools for remote access are installed.

Basically it means you have to install/enable ssh on the server and then use ssh/scp/sft (or GUI-tools based on that) to access the server, like you would an aws instance.

this is for ubuntu 16.04 but it should transfer easily

http://ubuntuhandbook.org/index.php/2016/04/enable-ssh-ubuntu-16-04-lts/

in case you want to then run jupyter notebook and access this from the macbook via the browser, you have to set that up too.

the easiest way to do that is probably by using an ssh tunnel and “portforwarding” on your mac. Jeremy has explained that in one of the early videos (part 1, or workshop for part 1 or lesson one of machine learning for coders.) Something like this:

Without ssh, something like this:
https://jupyter-notebook.readthedocs.io/en/stable/public_server.html

Does this help, don’t know if that is what you meant? Of course you can uninstall the desktop from your server etc. but that doesn’t really make a difference, you might as well leave it in case you want to do something directly on it.


#3

hey marc,

thanks for the reply. I guess I didn’t express myself very well.
What I wanted was basically just that my linux machine booted headless without X server running. SSH is already set up.

So what I did was the following:

I just changed one line in /etc/default/grub to boot without the desktopmanager.

found here

This way I can utilize the gpu completely for deep learning.


(Marc Rostock) #4

yes okay, that is a “different topic” but glad you solved it. And good you post it here, might help other people.

Along those lines, maybe someone finds this useful too (maybe even you):

Maximize GPU Memory availability for Deep Learning but still have GUI (Ubuntu 18.04)
If you want to have a graphical GUI but still use your nvidia gpu only for DL, that is also possible and the way I have set up my machines (Laptop w/ GPU and Desktop w/ GPU). This method works on all machines that have an onboard Intel Graphics chip (which is nearly every computer that uses Intel CPUs), you can use the onboard for the gui and leave 100% of the gpu for calculations which is my intended mode.

This here shows you how to do that:

  • (Install Ubuntu 18.04)

  • Install nvidia driver, reboot.

  • in a terminal use nvidia-smi to check the gpu is recognized correctly, note the memory consumption of up to 400MB just for the xserver GUI.

  • in the xserver desktop go to nvidia-settings-gui and change the PRIME Profile to “Intel (Power Saving Mode)”

  • reboot!

  • in a terminal use nvidia-smi, it should not find a gpu (unless you have multiple…) and give some error message

  • then edit /etc/modprobe.d/blacklist-nvidia.conf and delete or comment the following lines out:

    # blacklist nvidia
    blacklist nvidia-drm
    # blacklist nvidia-modeset
    # alias nvidia off
    alias nvidia-drm off
    # alias nvidia-modeset off
    
  • edit/create/add the following to /etc/modprobe.d/blacklist-nvidia-nouveau.conf:

    blacklist nouveau
    options nouveau modeset=0

  • (this step should have been done when first installing the gpu drivers or the disabling of the nouveau drivers was done in some different way, but add this just to be sure)

  • reboot

  • in a terminal use nvidia-smi, GPU should again be recognized and there should now be NO processes using the GPU and available memory should be the max of the card. At the same time the gui should be running (now powered by the internal Intel Graphics Chip). Yeah! :wink: :+1:

  • Note: On some desktops you might have to use a different monitor output (the one from the main board, not the one from the graphics card). On some it still somehow gets routed through…

This of course was not “invented” by me but is a summary of numerous SO articles I had to go through to get this working.
Currently works with the supported nvidia-390 (via apt install) driver, have not tested with 396 or higher yet.


#5

cool, that’s also a good idea (at least in theory). given the constant hassle I had with my nvidia card / drivers / cuda etc on linux, I’d rather not change anything while it is still working :slight_smile:

I find it very interesting that you mentioned that the video output sometimes still works from the same output port. I wonder on what that depends on.

Which distro are you running, normal Ubuntu?


(Marc Rostock) #6

I am running plain Ubuntu 18.04.1 on both machines now. Previously had 16 running but with lots of hassle.
Yes, I also always had lots of issues. But currently stable (which is why I dont even want to try upgrading to the 396 driver or later, as long as I don’t have an urgent need for it. :wink:

BTW: I just thought this would make a good topic on its own, just to realize it existed already, so I reposted my reply there to. Folks there have also managed to set up the same split between internal and gpu in different ways:


(Marc Rostock) #7

Re: the monitor output - My dell notebook only has one hdmi output which must be shared somehow between the cards. On my desktop tower I had to plug the cable in the onboard-output to get it to work. But I found many people in forums claiming that was not necessary, so I cannot really confirm that, although the way the laptop does it shows that it must be technically feasible…


(Bill Ross) #8

Have you found a way to make it sleep from cmd line? That’s the main thing I use the monitor for. :slight_smile:


#9

I can’t think of a reason why I would ever put my computer to sleep via ssh, but maybe this helps:


Why do want to put it to sleep instead of shutting it down when you are working headless?

I start my computer via WOL, work on it via ssh and then shut it down. I also integrated it in Homekit, this way I can start my desktop via siri.


(Bill Ross) #10

Thanks! ‘systemctl suspend’ works perfectly.

Why do want to put it to sleep instead of shutting it down when you are working headless?

Startup time from suspend is faster than boot for me, ~ 3 sec to be on the lan. Plus I have my web server running on it (that uses weights from my nets via dbase for weighted random choices), and startup time was > 15 sec, tho now that I’ve trimmed it to 6 sec, I could fire it up on boot. Ssh suspend means not having to reach around to the desktop mouse/screen to drop down the ‘Suspend’ option. If I can come out of suspend with WOL on ssh, that’ll be perfect… project for a rainy day. In actuality, a tap on the desktop keyboard works fine to wake it. Another reason for slow boot is that grub waits to see if I want to boot Windows, which I use sometimes.

Speaking of the web server, I just added a feature where you can easily compare the nets’ predicted worst to predicted best X’s, and it feels big, so the approach might be an interesting internal sales tool for ML tech for some.


#11

BTW I just switched back to Linux Mint. I’ve been using different kinds of Ubuntu distros continuously for the past several years and I found that Linux Mint is by far the most stable when you are using a nvidia card.
I personally find Cinnamon ugly as it can be, but since I now use it mainly via ssh that isn’t an issue anymore.

So when you want to turn of the desktop environment you’d use

sudo service gdm3 stop

on Linux Mint you’d use

sudo service lightdm stop


#12

Just a note for other users: marcmuc’s instructions worked for my ThinkPad T460p / Ubuntu 18.04 with Intel HD Graphics 530 and GeForce 940MX – no edits needed. The Nvidia driver version was 390. Much appreciated!


(Ernest Mugo) #13

In my experience, the most straightforward way is to just run Ubuntu server which you can download from https://www.ubuntu.com/download/server