Creating The Perfect Software Development Environment: Day 02

Introduction

When building an Ubuntu VM, I like to install Ubuntu Server using the virtualized kernel. This gives us a little better performance and the freedom to install whatever desktop environment we want. The trade-off is that there is a manual step to the process that has to be revisted anytime we want to refresh the box.

Creating The VirtualBox Machine

Assuming that you already have a working VirtualBox environment, the first thing we need to do is grab the Ubuntu Server ISO. Make sure to download the 64-bit version, otherwise you will run into some odd issues down the road. Besides, RAM is cheap and you'll want more than 4GB of memory to do your work.

Once the ISO is downloaded, we need to create a new virtual machine in VirtualBox.

The first half of this step is to configure a new machine in VirtualBox. The most important element to this configuration is to use the paravirtualized network driver. Doing this improves network efficiency because much of the network stack can be bypassed, sending packets directly to the host's NIC

Name the virtual machine
Select Linux as the operating system.
Select RAM
2GB of RAM should be plenty.
Create virtual hard drive
Make a new virtual hard disk.
Select VirtualBox Disk Image
Select the VirtualBox specific format.
Select dynamic allocation
Don't allocate the entire drive right away.
Select 100GB drive size
100GB drive should be plenty.
Leave notes for yourself
Leave notes for your future self. You will be glad you did.
Disable floppy disk support
Disable floppy disk support. Why leave an attack vector open?
Give the VM 2 cores
How many cores you allocate will be determined by your host hardware.
Insert the ISO into the virtual cd-rom drive
The ISO file should be "loaded" into the cd-rom drive.
Specify the paravirtualized network driver
The paravirtualized network driver speeds things up a bit.
Move the VirtualBox menu to the top of the screen
I like to move the VirtualBox menu away from the Ubuntu menu.
Summary of the VirtualBox configuration
Final pre-flight check.

Running The Ubuntu Installer

Now that we have the VM configured, the time has come to run the installer. The key concept to remember in this step is to let the installer know that we are installing into a virual environment. That will give us access to the virtualization aware kernel, providing a bit of a performance boost. I do a lot of work with Docker, which has a tendency to use up inodes, so I like to use XFS formatted drives. If you aren't a Docker developer, then the default ext4 should work just fine for you. I also like to create a boot partition separate from the OS partition.

The following steps also appear as screen captures below.

  1. Install the virtualization aware kernel
  2. Name the machine bionic
  3. Use Vagrant for the full name
  4. Use vagrant for the user name and vagrant for the password
  5. Use manual partitioning to create 2 partitions
  6. Create a 1GB XFS boot partition
  7. Use the remaining space to create an XFS slash partition
  8. Do not enable automatic updates
  9. Select OpenSSH Server and Basic Ubuntu Server for sofware packages
  10. Log in for the first time
  11. Run sudo apt-get update and sudo apt-get dist-upgrade to update the box
  12. Run sudo shutdown -r now to reboot the machine
  13. Log back in and verify that no new package updates are available
  14. Shutdown the machine

F4 to select 'Install a minimal virtual machine'
Use F4 to select 'Install a minimal virtual machine'
Manually partition the drive
We'll use manual partitioning
Select the virtual disk
Select the only disk.
Create a new partition
Let's make a new partition.
Setting for the boot partition
This is what the boot partition looks like.
Setting for the 'slash' partition
This is what the "slash" partition looks like.
Select 'Basic Ubuntu Server' and 'OpenSSH Server'
We'll need SSH support and basic tooling.
Initial log in
This is what the initial login looks like.
After package and kernel update
This is what things look like after we update packages and the kernel.
Disk partitions
This is what the final disk mounts look like.

Administrative Rights

In order to install software, modify configuration files and shutdown the machine, our user will need to temporarily elevate its privileges via the sudo command. Typically, the user has to enter in their password before sudo can be used. In an automated environment, like we are using here, this is a major inconvenience. There are several ways to elevate the user but I prefer to set up passwordless sudo. This is a security risk but since we're creating a disposable virtual machine for development, I'm okay making the trade off.

We need to add a file to the system, /etc/sudoers.d/passwordless, which gives users in the sudo or wheel groups the ability to elevate their privileges without entering a password. After adding the file, set its permissions to be read-only via chmod 0400 /etc/sudoers.d/passwordless


%sudo    ALL=(ALL)  NOPASSWD:ALL
%wheel   ALL=(ALL)  NOPASSWD:ALL
Defaults !requiretty
            

Conclusion

Now that we have a clean Ubuntu installation, we'll use it next time as a base for our Vagrant box.