Monthly Archives: October 2018

Notes from the VirtualBox – Part 4

Configuring Ubuntu 18 Server

The single most critical bit of advice about configuring VBox and Ubuntu 18 server is to create the second network adapter in VBox BEFORE you install Ubuntu. If you install Ubuntu server and then create the second VBox network adapter, it takes a lot of screwing around to be able to communicate with it. And overall it doesn’t work as well as when it is configured from the beginning to use a second network adapter. It’s easier to just delete that VBox instance and reinstall than it is to make all the required changes.

That said, let’s get started.

Configuring VBox and Installing Ubuntu 18 Server 

Follow the instructions given in Part 1 and Part 2 of this series to set up a new VM for Ubuntu 18 server and installing it. The biggest difference in installing Ubuntu 18 server and Ubuntu 18 desktop is that you need to select the server .iso image at installation time. The server install process is not as pretty because it is text based but it’s still pretty much the same stuff. If you have installed Ubuntu desktop you should be able to install Ubuntu server.

TIP: One thing I found is that if you start the install process and then cancel it, the next time you try to start that VM it will NOT restart the install process. Instead, it will try to boot off the VM virtual disk and then will halt and ask for a bootable disk. Instead of trying to fix that VM, it’s easier to just right-click on the VM’s name (in the left-hand panel of VBox Manager) and remove it. You can then create a new VM configured as required, click the Start button, and then start the installation process again.

When it has finished the server installation, it requires a reboot. It will ask you to remove the install medium – you can just hit enter since there is no medium to install.

The first time it boots up it will probably stop for 2 minutes or so with a message that includes “Wait for Network to be Configured”. This message is caused by Ubuntu expecting an actual physical device to respond at the dhcp-assigned address of the second (virtual) network adapter. Fortunately, you can specify that the second network adapter is optional and the delay will be eliminated (described below). Less usefully, you can also just remove the VBox-defined second network adapter (Host-Only) to make the wait and the message go away.

Connecting to Ubuntu 18 Server

Starting with Ubuntu 17, the network setup has been handled with NetPlan which uses a “renderer” to configure the network. In Ubuntu 18 desktop the renderer is NetworkManager, a slick tool that automatically manages the network configuration. In Ubuntu 18 server, the renderer is networkd which configures the network using the settings specified in a configuration file in /etc/netplan (50-cloud-init.yaml for servers and 01-network-manager-all.yaml for desktops).

First, let’s see how the network adapters are setup by default. Display info about your network adapters using the ip command as shown below:

sudo ip address show
Default settings for two network adapters

All three devices are named automatically. Device 1 is named “lo” for loopback and this one is always provided. Device 2 is named enp0s3 and this is the NAT network adapter – this is the device that talks to the internet. Device 3 is named enp0s8 and this is the Host-Only network adapter – this is the device that can communicate with other systems in your computer, either the host machine or one or some of the other guest machines.

The configuration file that produced this setup can be viewed as follows:

sudo nano /etc/netplan/50-cloud-init.yaml
Default server netplan file

Note that both addresses are automatically assigned using dhcp. The NAT device always gets 10.0.2.15/24 but the Host-Only devices receives 192.168.56.101/24, except that the 101 gets incrementally higher with each restart (so .101, .102, .103, etc.). Which means that if you want to set up Filezilla or putty or your browser to communicate with your VBox server, you will always have to check what your server’s address is before you try to connect to the server.

Fortunately, it’s easy to set up your server so the Host-only network adapter is assigned a static address. The following screenshot shows the changes that need to be made.

Modified Network Adapter Configuration File

A new second line has been added that specifies that the renderer is networkd. This ensures that the configuration file is used to setup the network adapters.

The enp0s8 device (the Host-Only network adapter) has two lines modified and four lines added. The first modification changes the first addresses entry to specify the desired static ip address; I chose 222 because it was unlikely to get mixed in with any dynamically assigned ip addresses that started with 101. The second modification changes the dhcp4 line to no (it used to say true.

The gateway4, nameservers, and second addresses lines were just copied from other examples on the internet. The most important line is the optional: true line. This is what will prevent your boot process from waiting for two minutes for the static ip address to respond.

When the changes have all been made, save the file and exit. Then execute the following command:

sudo netplan apply
The Host-Only Network Adapter is Now Assigned to 192.168.56.222

The default configuration of the Ubuntu 18 servers should have openssh installed automatically. Let’s check:

sudo ufw enable
sudo ufw status
sudo ufw app list

If the Uncomplicated FireWall (ufw) has already been enabled, it will ask if you want to duplicate it; if so, cancel the enable command. The ufw status command will probably respond that it is active. The command ufw app list will show all of the applications installed that could be process thru the firewall; mine only shows OpenSSH. If your server does not list OpenSSH, refer to Part 3 for instructions on installing OpenSSH. Once OpenSSH is available on your server:

sudo ufw allow openssh
sudo ufw status
Allowing OpenSSH thru ufw and Its New Status

It also would have been possible to allow port 22 instead of allowing OpenSSH but I believe the advantage of specifying the software instead of the port number is that if I wanted to SSH into my machine on a non-standard port (such as 5336), I could configure OpenSSH accordingly and the firewall would automatically adjust (although a reboot might be required). If I specified the exact port number, I would have to specify the exact port number in ufw; no problem there but then I’d have to decide if other applications might use port 22 and if I wasn’t certain, I’d probably leave port 22 open, which is less than ideal because it would leave an extra surface available to be attacked.

To complete the communications setup, the Ubuntu server needs to have Apache (or the web server of your choice) installed. Refer to the instructions in Part 3 of this series or other instructions available on the internet for help installing a web server.

Once you have your web server installed, be sure to issue the following command:

sudo ufw allow apache2
sudo ufw status

Your web server should now be available inside the VBox.

Notes from the VirtualBox – Part 3

Connecting to the New VBox Ubuntu 18 Desktop

Now that we have a shiny new installation of Ubuntu 18 desktop running inside a VBox, it’s time to open up some connections to it. For example, I want to be able to access my VBox Ubuntu from Windows using SSH. I also want to be able to view web pages that are being served by Apache running on my VBox Ubuntu. These are typical of the activities that you would need to be able to perform if you were responsible for maintaining a web site that was hosted by a commercial provider, such as GoDaddy or A2Hosting.

Starting with Ubuntu 17, netplan or NetworkManager became the default method for managing all network adapters. NetworkManager is the default tool (renderer) used with Ubuntu desktop, while networkd became the default renderer for Ubuntu server. This is important because a significant amount of obsolete instructions is still posted on the internet. This blog will only discuss NetworkManager; networkd will be discussed in the upcoming blog about Ubuntu 18 server running in VBox.

Fortunately, NetworkManager is very friendly and just handles it all for you. If you configured your VBox VM to have two network adapters (NAT and Host-only) before installing Ubuntu, those adapters will have addresses assigned to them automatically by NetworkManager.

The easiest way to verify that your network adapters have been assigned addresses is to open a terminal window and then type this command

sudo ip address show

A screen similar to the following will be displayed:

Results of running the ip command

Note that device 2 is named enp0s3. This name is generated by the system based on some special magic formula that superseded the old-style names such as eth0, eth1, etc. enp0s3 is the default connection for the NAT adapter that provides connectivity to the outside world.

Device 3 is named enp0s8 and is also automatically generated for us. It is automatically assigned an IP4 address, typically 192.168.56.xxx for Host-Only network adapters. If your system doesn’t have a third device or if the device doesn’t have an ip address, exit your Ubuntu instance and inside VBox manager add a network adapter (typically Host-Only). When you get back into your Ubuntu instance and repeat the ip command it should show device 3 with an ip address.

NetworkManager in the latest versions of Ubuntu desktop is a slick piece of code but I’m not sure how it’s configured. The configuration file in /etc/netplan only specifies the renderer (NetworkManager); apparently all other details are left to NetworkManager unlike Ubuntu 18 server that requires all network adapter details be specified completely. More in the next blog.

Now that we have two adapters, if we try to access either a web page or an SSH connection from Window we will get failures because the default Ubuntu 18 desktop install doesn’t include the tools to respond to http requests or ssh requests.

So back to our terminal window. Type the following command:

sudo ufw status

If the Uncomplicated Firewall (ufw) is not installed, install it as follows:

sudo apt install ufw

If ufw responds that it is inactive, enable it as follows:

sudo ufw enable

You can repeat the ufw status command at this point and it should tell you that it is active and which ports are available (which should be none).  Now find out which applications have been configure to communicate with the outside world as follows:

sudo ufw app list

Typically, there will be no apps listed or just CUPS (Common Unix Printing System).

Install and Activate OpenSSH

Let’s setup OpenSSH to be allowed thru the firewall first.

sudo ufw allow OpenSSH

If it doesn’t know anything about OpenSSH, it hasn’t been installed. Install the OpenSSH server as follows:

sudo apt install openssh-server
sudo systemctl status ssh

The OpenSSH application should now be listed as enabled and active, similar to the following:

We installed OpenSSH but the service is referred to as ssh

Update the firewall as follows:

sudo ufw allow ssh      or/both
sudo ufw allow OpenSSH

If you do both commands there will be two rules for SSH, as shown when the    sudo ufw status  command is executed.

Both ssh and OpenSSH are available on port 22

Now on Windows, open putty and point it at your VBox Ubuntu:

Note the IP address is the same as the enp0s8 IP address

Click the Open button to start connecting to your VBox Ubuntu. It may complain about not recognizing your VBox Ubuntu but since we are forced to be on (inside) this computer, it is safe to continue. Log in with your user name and password and you’ll be able access your VBox Ubuntu from Windows and perform any terminal operations that you could inside VBox Ubuntu terminal window.

Install and Activate Apache Web Server

Apache web server is the most popular web server in the world and has proven to be robust and stable for many years. It is not automatically installed when you installed Ubuntu 18 desktop into VBox. It can be installed as follows:

sudo apt install apache2
sudo service apache2 start

Now, if we run the command   “sudo systemctl” we will find it running:

Apache is running (3rd line from bottom)

Now we need to make sure Apache can get thru the firewall, so:

sudo ufw allow http       OR/BOTH
sudo ufw allow Apache

Check the firewall status as follows:

sudo ufw status

And the displayed info should be similar to the following:

Now if we go to our Windows browser of choice and put in the IP address given for enp0s8 then we should get a screen similar to the following:

Notes from the VirtualBox – Part 2

Setting up Ubuntu 18 in VBox

Now that we have created a “placeholder” for Ubuntu in the VBox Manager, we can get started installing Ubuntu 18 Desktop. We won’t go step by step thru the installation process because there are many guides available that will walk users thru a new Ubuntu installation.

Instead, we’ll focus on a couple of sticking points that I ran into (and lost many hours trying to resolve them).

BEFORE starting your new VBox Ubuntu instance, set it up as follows:

  • Configure the amount of RAM this instance will use
  • Configure the number of CPU’s it will use
  • Configure the number of network adapters it will use

Display Details in VBox Manager

Show the details about the currently selected VM in the main panel by:

  • Clicking on the Details box in the center of the Welcome screen 
  • Clicking on the Machine Tools dropdown arrow and then selecting Details

The VBox Manager will change to info about each of its major subsystems (shown below):

Configure the Amount of RAM

The System info box shows that this instance of Ubuntu has been configured with 2 GB of Base Memory. Since I have 12 GB installed on my system, I can afford to allocate 4 GB total to this instance. And experience has shown that it will perform a little better and will be less likely to use the swap disk.

To change memory, click on the word “System” in the System info box to display the System tab of the Settings dialog box (shown below).

Drag the control to the right to increase Base Memory to the desired size or left to decrease Base Memory. Click OK button when the desired size has been selected.

Configure the Number of CPU’s (Processors)

The Create New Virtual Machine scripts defaults to one CPU, no exceptions. If your computer has more than one CPU or CPU Core, it will benefit from increasing the number of CPU’s allocated to your VM. My computer runs an Intel i7 processor with 4 cores (or 8 hyperthreads); experience has shown that allocating up to half of these hyperthreads to the VM works fine.

To change the number of CPU’s,  click on the word “System” in the System info box to display the System tab of the Settings dialog box (shown below).

Drag the control to the right to increase the number of CPU’s allocated to this VM. Click the OK button when the desired number has been selected. NOTE that this step could also been performed when changing Base Memory setting previously.

Configure Number of Network Ports

The default setup has one virtual network adapter configured that will reach the internet using NAT (Network Address Translation). If you just want to run a browser then you can skip the rest of this step. However, if you think you might want to run a web server inside your VBox, you will need to set up a second virtual network adapter.

Many VBox instructions available on the internet apply to earlier configurations. In VBox 5.2.19 and later, do the following:

  • Click on the File Menu and then select Preferences. In the dialog box, click on the Network option. If a NatNetwork option is NOT active, click the green plus-sign icon to add and activate it and then click the OK button.
  • Click on the word Network in the Network info box to display the Network tab in the Settings dialog box.
  • Click on the Adapter 2 tab and tick the Enable Network Adapter checkbox.
  • Click on the Attached to: dropdown selector and chose the Host-only Adapter option.  This allows any OS on your computer to “see” this adapter. 
  • When the Network settings look like the following image, click the OK button.

Making these changes before installing Ubuntu improves the quality of the installation, especially when installing the Ubuntu 18 server. The desktop version is friendlier and does a few more things for you but the server version puts all options under your control and won’t do anything unless you specifically instruct it to do something (with great power goes great responsibility). 

Installing Ubuntu

After all of the above, we are ready to install Ubuntu.

  • Click the Start icon (green arrow pointing right). The first time you start your VM, it will detect that it doesn’t have a bootable OS installed on its virtual hard disk so it begins the installation process.
  • In the “Select start-up disk” dialog box, change the Host Drive (virtual hard disk defined earlier, on left) by clicking on the folder icon and then navigating to your Ubuntu download and selecting it, as shown on the right.

Click the Start button and the standard Ubuntu installation process will begin. And like any standard Ubuntu installation, there will be a test of your faith, when it asks if you want to erase the hard drive and lose all your data. It is referring to the virtual hard disk and not your real physical hard disk. 

When done, it will display “Installation is complete. You need to restart the computer in order to use the new installation.” Click the Restart Now button. 

A message will display, “Please remove the installation medium, and then press ENTER”. Since there is no medium to remove, just press ENTER.

Your vbox will grind away for a while and then the familiar user log in screen will display. 

Part 3 of this series will discuss installing the Linux server and some of the problems that may be encountered installing and configuring the server.

Notes from the VirtualBox – Part 1

Setting Up VBox

VirtualBox (VBox) is Oracle Corporation’s entry into the Virtual Machine market. And since it is a free software product, I decided to download it and install it. And I am pleased to announce that it is simple to download and install on Windows 10 (Linux & Mac versions are also available). But without easy access to a VBox guru, getting it configured was a little trickier.

I had tried numerous times to set up my desktop and laptops to dual-boot into either Windows or Linux but without success. Between overly-zealous boot sector protection,  UEFI vs BIOS, and disappearing grub, the best I’d been able to accomplish was selecting either UEFI or BIOS to enable the desired operating system. To change from the currently selected OS to the other OS required a hard reboot, pressing F2 key repeatedly to activate the BIOS setup screens, selecting either the UEFI or BIOS method, and then rebooting again. Needless to say, a slow and clumsy process.

Fortunately, VBox has fixed this problem for me. Now, after booting Win10, I can launch one or more guest machines inside my VBox and have access to any one of them. They are all live and running simultaneously; I can click on the desired OS (window) and use the resources available in that OS as easily as using multiple apps side by side in Windows. This is a big improvement over my attempts to dual boot.

Important Concepts

VBox is based on the concept of host machine and guest machine(s). The host machine is the base computer’s operating system, or Windows 10 in my case. The guest machine is the operating system that runs inside of VBox, or Ubuntu gnu/linux for me.

Installation of VirtualBox

Once the VituralBox installer has been downloaded, just execute it and then follow the prompts. The Win10 installer is smooth and fast and simple. I haven’t tried the other installers, so I can’t guarantee that they will work as easily. The installation routine also doesn’t require any hard decisions, such as disk partitions or CPU cores because those decisions are all associated with the guest machines that you install.

Installation of Guest Machines

Start the VBox Manager and a screen similar to the following should appear. The empty white panel on the left of the screen is where the guest machines will be listed after you have created them. Click the blue New button to create a new virtual machine.

The Create Virtual Machine dialog box appears (on left). As you start to name your new VM, it will try to guess what type of OS you are installing (on right). 

Default New VM with Blank Name
Guesses Your New VM Based on Name

I have already downloaded the .iso image for Ubuntu 18.04 desktop so I will name the new VM “ubuntu 18” – it is just a name so VBox doesn’t care if I name it “third door on the left” or “Bert”. Since I will also be installing Ubuntu 18 server later, I probably don’t want to get too “creative”.

Next it will ask how much memory you want to allocate to this new VM. I have 12 GB of RAM available but its default setting is 1 GB (on left). Even though it is easy to change this setting at any time, I will change it to 2 GB for initial set up (on right).

Next it will ask about the virtual hard disk to add. The first option doesn’t add a virtual hard drive which may be useful for some special situations but none come to mind. The second option is probably the most used option as it provides a place where you can install a new OS. The third option allows you to re-use or share an existing virtual hard drive between various VMs, which seems like it would be useful if you wanted to performance test different configurations using a common software base or if you wanted to reuse the installed software and data but wanted to reinstall the OS. 

I usually create a new virtual hard disk (2nd option). The default size is 10 GB but you don’t actually set the size on this dialog – that will happen in a few steps. And I usually select the first option for the Hard disk file type.

For Storage on physical hard disk (left), I normally select the Dynamically allocated hard disk file; so far the performance has been more than adequate. And finally we can set the size of the virtual hard disk (right). I normally set it to 20 GB.

And in a flash, you are returned to the VBox Manager with the new VM shown on the left. It happens so quickly because the allocated virtual hard disk was not formatted and Ubuntu was not actually installed. Instead, space has been reserved for Ubuntu, nothing more.

New Ubuntu Desktop VM added to Panel on Left

The next part in this series will discuss the installing and configuring Ubuntu 18 desktop and Ubuntu 18 server.