Quick-add KVMs for MAAS

When designing or testing with MAAS, it’s often handy to start with virtual machines. If you’re just on your laptop, and you want to check out a new MAAS version, or mock up some datacentre idea you’ve been considering, KVMs are often very useful. You could create pods, of course, but it’s also very simple just to create a few individual KVM machines and enlist them in MAAS. This article will show you how.

You’ll need to first install libvirt (aka, Virtual Machine Manager) — on the machine where you plan to install and test MAAS — since libvirt is the tool that provides KVMs. Once you’ve done this, you can open the Virtual Machine Manager application. You’ll see a screen that looks something like the one below, though it may not be populated with any KVMs yet:

The Virtual Machine Manager’s KVM list, which is the default landing page

To begin creating a new KVM, choose File –> New Virtual Machine from the menubar at the top, which brings you to a corresponding dialog:

Select the “Network Boot (PXE)” option and click the “Forward” button:

Choose the “Generic…” operating system by typing a few letters of “Generic” in the text box and selecting the relevant choice when it becomes available, then go Forward:

For CPU and memory, you can usually accept the defaults:

On the other hand, the storage values have a noticeable effect on local disk usage, so note that, generally, only about 5.0 GiB are needed for a simple, test KVM:

In the next screen, you’ll have the chance to set a name; here, we’ve used a pseudo-MAC address, although you can name the machine whatever you want (and then return later to set the name to match the MAC address assigned by libvirt, if desired):

Selecting “Finish” will create the virtual machine and attempt to boot it – which will fail, since no device currently knows about this KVM (and hence can’t boot it). Not to worry; you’re not done yet:

Select the “information” button (blue circle, white lowercase “i”) to switch to the KVM configuration screens, then select the “Boot Options” choice from the left-hand menu:

Turn off the “IDE” item under “Boot device order:”

When you select “Apply,” a dialog will pop up to remind you that you need to restart this KVM for changes to take effect (don’t worry about restarting yet):

Switch to the “NIC…” option and set the “Network source” and “Device model” as shown, then select “Apply” and respond to the dialog:

You’ll next select the dropdown arrow next to the “on/off” menu bar option and select “Force reset,” then answer the prompt in the affirmative:

You now have a KVM that can be added to MAAS.

If you want more than one, you can simply right-click on the one you’ve just created and select “Clone.” Cloned KVMs tend to use considerably less host disk space than newly-created ones, and the cloning process saves you considerable time. Here’s what cloning looks like:

Another KVM will instantiate, using the name of the cloned KVM with an added “-clone” suffix:

Note that the “-clone” suffix will automatically increment as you keep cloning the same machine (e.g., “-clone1,” “-clone2”, ….).

Disabling DHCP for Virtual Machine Manager

Before attempting to enlist your new KVMs into MAAS, you must modify the KVM networking arrangements so that MAAS can manage DHCP requests. The command-line utility “virsh” is the easiest way to do this:

Presumably, you’ll be using the “default” network, but if you’ve created a different network connection, substitute its name in the following instructions.

Before modifying the default network, you need to disable it. This is accomplished via the “net-destroy” command:

Once you’ve disabled the network, you can edit it with “net-edit:”

In the editor window, you’ll want to select the <dhcp>…</dhcp> section and delete it, then save and quit the file:

Finally, you want to restart the default network with the “net-start” command:

This sequence of steps prevents the Virtual Machine Manager from attempting to provide DHCP, which would prevent MAAS from properly accessing and enlisting the machines.

Adding KVMs to MAAS manually

Manually creating a machine from a KVM requires just a few pieces of information, most of which you can gather from the KVM itself:

In the left column, you’re only required to enter a machine name and the machine’s MAC address:

Here, we’ve assigned a variant of the MAC address as the machine name. Note that the machine name cannot include colons (“:”), so dashes are substituted. In the right column, it’s necessary to choose the power type. When enlisting KVMs, the correct power type is “Virsh,” as shown below:

For default configurations, the Virsh Address is “qemu+ssh://[your-login-id]@192.168.122.1/system,” where “[your-login-id]” is replaced by your username or login ID on the machine where you’re hosting MAAS and the Virtual Machine Manager. Likewise, the password is your normal login password for the same host. Finally, the Virsh VM ID is retrieved from the “Overview” screen of the KVM itself:

As you add machines, they automatically commission:

When you’ve finished, all commissioned machines will be at the “Ready” state.

A couple of tips

Here are a couple of tips for adding individual KVMs as MAAS machines:

  1. Cloned machines tend to take up less disk space on your host laptop. It’s not a perfect rule, but it does tend to hold most of the time.
  2. Watch your laptop processor limit when creating machines; specifically, don’t commission too many at once — you may cause your laptop to run out of resources and freeze up or reboot. The same goes for deploying machines, and for accidentally leaving too many on when you’re playing around.

That’s it! That’s all there is to adding a few KVMs to check out MAAS or play around with ideas.

About the author

Posted in: