Ubuntu Unattended Installs, Virtualbox, Manipulating initrd.gz, and Makefiles

I have three bare-bones Intel NUCs. I want to install Ubuntu Server 18.04 and then install Kubernetes using kubeadm.

But, installing Ubuntu Server three times is a chore. I've misconfigured the servers multiple times now. I'm honestly tired of it.

So I'll automate it.

Thinking out loud, this is what I'd like to see:

  • Stick a USB into the machine and power on
  • Wait for the install to complete
  • Reboot the machine
  • SSH into the machine from my mac to automate configuration with <insert some tool I've yet to decide on>.

Luckily, I came across the Automatic Installation docs and the lovely InstallCDCustomization wiki.

But, the installation is still physical. I have to create the ISO, load it on a USB stick, walk over to my Intel NUCs and stick in the USB, and boot the instance. Then I have to wait. And if I didn't setup the preseed.cfgcorrectly, I am prompted with a dialog box that stops the installation.

I need a way to simulate the installation on a new system without moving from my chair.

As I edit this post, I realize how lazy I am reading that last sentence.

Luckily, Virtualbox is a handy tool for this.

Virtualbox command line

Here are the commands I found useful simulating the installation.

VBoxManage startvm stormlight
VBoxManage controlvm stormlight poweroff

# Attach stormlight.iso as a DVD
VBoxManage storageattach stormlight --storagectl IDE --port 1 --device 0 --type dvddrive --medium ~/Downloads/stormlight.iso

# Setting medium to "none" removes the drive. 
VBoxManage storageattach stormlight --storagectl IDE --port 1 --device 0 --medium "none"

Working with initrd.gz

Through a lot of trial and error, I realized that the best way to automate the installation process is to modify the initrd.gz archive for the Ubuntu installation process. Sadly, this took a few days of trial an error tinkering with a preseed.cfg file in the root directory of the ISO and with command line flags. Neither solution worked, so modifying the initrd.gz archive it is. Here are a few helpful commands for modifying the archive (which I only just realized now that cpio was a precursor for tar -- cool!).

# Lists files in archive just like ls -l
cpio -ivt < initrd.gz

# Extract a file with isoinfo
isoinfo -i mini.iso -x '/INITRD.GZ;1' > initrd.gz

Makefile on lightweaver

lightweaver is the name of my kubernetes master -- I name my machines after orders of the Knights Radiant. This section probably doesn't matter to you readers as you don't have access to this machine, but hey, these are my development notes ...

On lightweaver (my intel NUC with ubuntu installed by hand), I set up a new working directory to help build and create the ISO with a Makefile. It's at ~/stormlight-iso on lightweaver.

ssh lightweaver
cd stormlight-iso

I also created scripts locally on my Mac to build the stormlight-iso, download to my Mac, run Virtualbox to create the image, and then finally have it shutdown. This is at:


Update (later in the day)

I finally got everything working! Even the SSH and disabled password.

Next: make a private repo and store on GitHub so I don't forget. The repoisotry is designed to run on Ubuntu machines (for now). I will add some form of testing as well.