Installing Ubuntu 20.04 Server
Part of the Kubernetes the hard way on bare metal/VM. This is a detailed step by step guide for beginners.
Introduction
This guide is part of the Kubernetes the hard way on bare metal/VMs series. On its own this may be useful to you however since it’s tailored for the series, it may not be completely suited to your needs.
This guide is to help people set up and configure a basic Ubuntu server from start to finish. It will go into quite a bit of detail including software RAID and LVM and as such if you don’t have at least 2 disks available then you may not be able to follow along exactly; that doesn’t mean you can’t follow along though!
I’m going to presume you have a physical PC/server or virtual machine on which you wish to install Ubuntu.
If you’re using a physical machine then you’ll need to download the ISO and put it onto a USB stick or CD so that you can install Ubuntu. There are plenty of guides online on how you can achieve this; however two quick examples for USB sticks are:
- Linux: Run in a terminal
sudo dd if=/path/to/ubuntu.iso of=/dev/USB_Device
- Windows: You can use PenDrive Linux
If you’re using Virtualbox or libvirt/KVM/QEMU then you can just attach the ISO directly to the VM. If you’re not sure about how this is done then take a look at my tutorials on how to use them.
libvirt/QEMU/KVM
Virtualbox
Resources
See the main series under Setting up the resources for the VM specs
Steps
Boot the ISO/USB/CD and select your preferred language for the installer and then select Install Ubuntu Server
Location and Keyboard
Select your language and the location of the system then configure the keyboard layout.
Networking
If you’re doing this from home then it’s likely you will have DHCP enabled on your network which, in short, allows your machines to automatically get IP addresses from the router. In this case you should find you don’t have to configure the network; other networks can have DHCP enabled too. You can skip over this section to configuring the hostname if this is the case, as this is where you will land instead of the screen shown below.
If you don’t have DHCP and/or are using a static IP then continue with the steps below.
My network details are as follows (yours will possibly differ):
IP address: 192.168.0.110
Subnet: 255.255.255.0
Gateway: 192.168.0.1
Name servers: 8.8.4.4 and 8.8.8.8 <- These are Google’s name servers. You may have different ones.
Choose the option to configure manually and enter your IP address.
Then enter your subnet, gateway and name server addresses. See the example below for how to do this.
If you require a proxy address, you will know this, else leave the proxy address and mirror as they are. They should be sufficient.
Disks — RAID — Preparation
This whole section on disks may seem daunting at first, but run through it a few times and it’ll become second nature.
You could use guided storage layout, but you came here to learn!
So select Custom Storage Layout.
You should do the following steps on both disks until the Disks — Create /boot & LVM Device section as we’ll be configuring them for RAID 1. RAID 1 (in particular) requires the disks be exactly the same size so that it can work. If you’re not using RAID you can skip over this to the Disks — Create /boot section, though a small amount of work on your part will be required to do this RAID-less as the guide will only hint at how you can do it rather than show you as you go on.
First you’ll need to configure both of the disks as a boot device. Select each disk and select “Use As A Boot Device” on the first disk and “Add As Another Boot Device” on the second disk.
Now we’ll create some unformatted partitions that will be used for RAID.
First we’ll configure the one that will be used for /boot.
On both disks select “Add a GPT Partition” and then enter a size of “1G”.
Set the format to “Leave Unformatted” and select “Create”.
Next we’ll create the unformatted partitions that will be used for the LVM and in turn the root filesystem.
On both disks select “Add a GPT Partition” and then leave the size blank.
Set the format to “Leave Unformatted” and select “Create”.
Now we’ll configure RAID 1 on the system to create mirroring. Now, in a VM this isn’t really necessary but in the real world, you want this as a minimum to ensure redundancy.
You should have something that looks like the first image below.
To configure RAID, Select “Create Software RAID (md)”
Leave RAID Level as 1.
Then select the two partitions that are 1G in size. Then select create.
Now you should have something that looks like the first image below, with “md0 (new)”.
Now we’ll do the same for the larger partition. So again, “Create Software RAID (md)”
Leave RAID Level as 1.
Then select the two partitions that are left. Then select create.
Now we’ll prepare those newly create RAID.
First let’s start with the boot partition, as we won’t want this as part of the LVM system we’ll set up afterwards.
So, with the 1GB RAID device we can click on that and select “Add GPT Partition”.
Then leave the size empty as we want to use the full space available.
Set the format to “EXT4”.
Set the mount point to “/boot” and select “Create”
Next, we’ll setup the device for LVM.
Then leave the size empty as we want to use the full space available.
Set the format to “Leave Unformatted”.
Disks — Create LVM
You’re ready to start creating the LVM. The reason I’ve opted for this is because I prefer it when it comes to extending disks. It makes it much easier to add disks to systems and extend file systems without, generally, any migration.
You don’t have to use RAID or LVM however this is a setup that more closely resembles a real world scenario (although hardware RAID is preferable). If you opt not to use LVM, just set the large partition to EXT4 and the Mount point of it to / in the previous step.
Anyway, let’s configure the Volume Group for LVM.
Select “Create Volume Group (LVM)”.
Leave the name as it is and select the partition (RAID Device) that is shown.
If you want to encrypt the partition, you can do so here. This will require you to enter a password on boot.
Once done, select “Create”.
Select the Volume Group you just created (VG0) and select “Create Logical Volume”.
You can set the name to whatever you like but as this will be for the root filesystem, I have set it to “lv-root”.
Leave the size empty to use all of the space available.
Set the format to “EXT4” and the Mount to “/”.
Once done, select “Create”.
Now we’re done, the disk should look something like this.
Once you’re happy, simply select Done and then Continue to proceed with wiping the disk (if any data existed) and creating your new partition layout.
You made it!
Now I know the disk configuration may seem complex but once you’ve done it a few times, it becomes pretty easy. Most guides will take you through only using a single disk and either creating everything in one partition or, if you’re lucky, breaking it down to /boot, / and swap* (boot, root and swap). Whilst that’s fine, it’s unlikely you’ll see this in a real world scenario.
*Important note: You haven’t set any swap space up here. This is because this guide is part of my Kubernetes tutorial series which requires swap to be disabled. If you’re NOT following the Kubernetes guide then it is recommended you configure swap space. You should delete the partitions you’ve created so far and create the swap in the same way you did the /boot sector (you’ll see it as an option in “Use as” when configuring the partition) and it should generally be 2 x your RAM amount — unless using more than 64GB. Create it after /boot and before the large space (this doesn’t matter but makes life easier later when resizing).
Hostname & User account
The hostname (server name) is the name that the machine will be identified as. You may want to use something like web, mail, database, hosting, controller; anything you want really can go here. If you’ve been given a hostname, use that.
So here, enter your Name, Server name, Username and password; you’ll need to do this twice to confirm the password.
Install OpenSSH
Next we’ll install OpenSSH. This is required to connect to the machine remotely and to copy TLS keys across to the nodes (in the Kubernetes tutorial).
Configuring packages
I will not recommend selecting any packages here if following along with the Kubernetes tutorial, any packages that we need will be installed later.
Final stages
Once the OS has been installed, it will update the system with any that are required and then you’ll be prompted to reboot.
Log in
You’re officially done however for the sake of completion, lets log in. Once it has rebooted you should see the screen below, enter your username and press enter. You’ll then be prompted for the password you set during install.
When you type the password, it will not show on screen but don’t worry, it is being entered.
Press enter when done and you’ll see a load of text outputted, this is the message of the day, and a flashing cursor next to ~$
Welcome to the shell (bash).
Once logged in you can start running commands. Here are the commands to update Ubuntu.
sudo apt update
— This will refresh the package list allowing the system to see if any updates or new packages are available.
sudo apt upgrade -y
— This will upgrade all of the packages that can be upgraded. Remove -y if you want to see the packages will be upgraded and be prompted for Y or N to continue or cancel.
Sudo is used to run commands with escalated privileges. If you run the commands above without sudo, they will fail.
SSH access
You can already connect to the server via SSH as we installed the package during install. If you’re on a VM with NAT you may need to create some forwarding rules to make the below work.
All you need is the IP address of the VM, your username and your password. If you’re on Linux or Mac, you can ssh straight from the terminal: ssh username@ipaddress
. If on Windows, there are many options but Windows Subsystem For Linux or Powershell would be the easiest to get started.
There are a million and one tutorials online that will show you how to achieve this so I won’t be getting into it any more than that today.
Conclusion
You’re done!
What you’ve learned:
- How to install Ubuntu Server
- How to configure a static IP during installation
- How to configure RAID
- How to configure LVM
- How to log in and update the system
- Basic SSH access
Go make yourself a cup of tea and relax.
Next: Back to Tutorial