Setting up a minimalistic Ubuntu 16.04 server

Our overall strategy will be the following:

  1. Install a desktop version of Ubuntu 16.04
  2. Convert the desktop installation into a minimalistic server version
  3. Configure the server to play with others (routers and etc)

The reason for installing a desktop version rather than directly installing the server version from the Ubuntu website is because (in my opinion) the server version presents many hardware specific challenges during installation. The process of installing a desktop version and converting it turned out to be much simpler at least in my case — just a few terminal commands had to be executed.

Additionally many more people will be able to follow through with this tutorial due to the fact that installing the the desktop version is rather straightforward.

Note: You will need an Ethernet cable for this tutorial

1) Installation

Download your latest version of Ubuntu 16.04 desktop and burn it on a USB. Proceed to install the OS in your standard manner.

Once the installation is done open a terminal in the newly installed version of Ubuntu and run $ sudo apt update

apt now has the recent package information available

2) Minimalising the Installation

Next, install tasksel: $ sudo apt install tasksel

tasksel is a terminal utility that allows you to install/remove related packages as a coordinated task. For example you can install/remove a server or desktop version of Ubuntu.

The way that tasksel works is that it presents you with variations of the Ubuntu distribution you may install/remove. You can shift between the various different options by pressing the arrow down and up buttons. To select/deselect an option press the space bar when your cursor reaches the intended option.

Proceed to running tasksel: $ sudo tasksel

$ sudo tasksel

You will notice that the Ubuntu desktop option will be selected when the terminal menu opens. Cycle through the options to the very end and select Basic Ubuntu server by pressing the space bar. Press enter to confirm and wait until tasksel completes adding the required packages.

Next, you will have to remove Ubuntu desktop. However when doing so tasksel deletes the Ethernet and WiFi kernel drivers. The work around this problem is to copy the entire kernel module structure in its current state and replace it back later on. We will remove Ubuntu desktop once the module structure is copied. Feel free to save the module structure in any of the user folders. I chose to save it in Documents:

$ sudo cp -r /lib/modules/$(uname -r) ~/Documents

Now remove Ubuntu desktop by deselecting the option in the tasksel menu: $ sudo tasksel

Whilst tasksel executes certain parts of the GUI start to disappear and the interface starts to become unusable. This is perfectly normal — taskel is removing the unnecessary components of your OS which includes the GUI.

To ensure that you are able to use your computer simply open the tty3 interface by pressing: <Ctrl> + <Alt> + 3 . A terminal interface will open up requesting you to enter your username and password.

You will notice that you have access to the internet despite the fact that the network drivers have been uninstalled. You can verify this by running:

$ ping google

The reason why you still have access is because the current kernel modules were loaded at boot time. You will need to restart your PC to see the changes in the loaded kernel modules. Do not restart your computer yet!

Congratulations you now have a minimal version of Ubuntu! Let’s make it usable now!

3) Configuring the Server

First of all let’s start by substituting the current kernel module structure with the kernel module structure we saved before. Copy it from the destination that you originally saved it in. I saved the structure in Documents:

$ rm -r /lib/modules/$(uname -r)
$ sudo cp -r ~/Documents/$(uname -r) /lib/modules

Lets now restart the OS: shutdown -r now

If you find yourself confused on how to access the terminal interface then simply press <Ctrl> + <Alt> + 3 once the computer starts up.

You will now notice a couple of things once your computer has started up again:

  1. All your network kernel module drivers are loaded. To confirm run: $ lspci -v
  2. All your network interfaces apart from localhost are inactive. To confirm run: $ ifconfig
$ ifconfig

To find out the interfaces available (active and inactive) run: $ ifconfig -a

$ ifconfig -a

Next, activate the Ethernet and WiFi interfaces by the running the following commands:

$ sudo ifconfig <your-deactivated-ethernet-interface> up
$ sudo ifconfig <your-deactivated-wifi-interface> up

Run $ ifconfig to verify that all the network interfaces are up now

Finally to initialise the Ethernet network interface you will have to connect your PC to a router via an Ethernet cable and then run the following command:

$ sudo dhclient <your-ethernet-interface>

The dhclient network utility allows you to request an IPv4 address from a DHCP server which usually runs on a router.

Congratulations you have now have a functioning Ethernet interface and you can now access the internet! Run the following to verify:

$ ping google.com

Install and initialise the following package to connect to a WiFi router:

$ sudo apt install network-manager
$ sudo systemctl enable network-manager.service
$ sudo systemctl start network-manager.service

Disconnect your Ethernet cable to test connecting to a WiFi connection. Run the following to connect to a WiFi router: $ nmtui

$ nmtui

You must have access to the internet now. Run the following to verify:

$ ping google.com

Congratulations you now have a functioning and configured version of a Ubuntu server! Happy hacking!

Notes:

  1. If you feel that you need a more minimalistic OS than the one explained above then I would suggest making your own Linux distribution here
  2. The terminal utility lshw can be helpful in diagnosing problems you may face while configuring the network interfaces. Use the following command to view the state of your network hardware (whether it is disabled, enabled and etc): $ lshw -C network