Building a new VM

Introduction

Before you can use minimega, you must build disk images or RAM disks for your VMs. The minimega distribution includes vmbetter, which can build several minimal RAM disks (see the vmbetter tutorial for more information). These work well for generic experiments but sometimes, you need more than a minimal install. This article describes the process to build a VM disk from an install CD.

Install CD

First, you must obtain an install CD as an ISO image. This can be downloaded from the web or provided by a vendor.

Starting a VM

In order to perform the install, we create a new qcow and launch a VM with it and the cdrom:

disk create qcow2 ubuntu.qcow2 20G
vm config disk ubuntu.qcow2
vm config cdrom ubuntu.iso
vm config snapshot false
vm launch kvm ubuntu
vm start all

Importantly, we set snapshot=false so that any changes we make to the disk persist. Without this flag, all the changes would disappear when we killed the VM.

Network-based install

Some installers make use the Internet to pull more recent packages or software. See this article for more information.

Perform the install

The VM should now be running and the installer will be waiting for user input. Start miniweb and click through the installer using the web interface.

Post-install configuration

Once the VM is installed, you may make additional changes to the filesystem in order to make persistent changes. This could mean installing additional software or configurations.

Adding miniccc to VMs

Typically, we add miniccc to our VM images to facilitate experiment control. First, we must load the binary onto the VM. This can be done in a number of different ways including over the network (if the VM is launched with an interface) or via the hotplug API.

Once miniccc is on the VM, we must configure it to start automatically.

init Scripts (Linux)

There are several examples of integrating miniccc into vmbetter-built VMs in the repo (see misc/vmbetter_configs/).

systemd Integration (Linux)

To start miniccc automatically with systemd, add the following to /etc/systemd/system/miniccc.service:

[Unit]
Description=miniccc

[Service]
ExecStart=/miniccc -v=false -serial /dev/virtio-ports/cc -logfile /var/log/miniccc.log

[Install]
WantedBy=multi-user.target

You may need to adjust the ExecStart command if you copied miniccc elsewhere. And then enable the service:

systemctl enable miniccc.service

This will start miniccc whenever the VM starts. If you are adding to a VM with snapshot=false, you should now shutdown the VM and save the disk image.

Task Scheduler (Windows)

The built-in Task Scheduler on Windows can be configured to run miniccc.exe on startup.

Final steps

Clean up

To make the image smaller, you may wish to remove any cached files (e.g. run apt clean).

Sysprep (Windows)

Before finalizing a Windows VM, it is a good idea to use Sysprep to generalize the VM. This removes computer-specific information so that when you launch multiple VMs from the same image, they each have a different identifier.

Shutdown

Finally, shutdown the VM from within the VM using the standard shutdown mechanism. Wait for the VM to fully shutdown to ensure that the filesystem is in a consistent state. minimega will update the VM state to quit when the VM has fully powered off. You may now call vm flush to remove the VM.

The image should now be ready to use:

vm config disk ubuntu.qcow2
vm launch kvm ubuntu[0-3]
vm start all

Note that further changes can be made by launching the VM with snapshot=false.

Authors

The minimega authors

3 July 2018