If you have already created a VM host, you will want to create and delete virtual machines (VMs).
How to add a VM from the MAAS UI
To add a virtual machine from the MAAS UI:
-
Select KVM > .
-
Select the desired VM host by clicking on its name.
-
Select *Add VM".
-
Optionally enter the VM name.
-
Select Use any available core(s) or Pin VM to specific core(s), as desired. Enter specific core identities as appropriate.
-
Enter the RAM desired.
-
Select Show advanced if you want to edit the Domain, Zone, Resource pool, or Architeture. Make those changes as desired.
-
Optionally Define interfaces.
-
Optionally Add disks.
-
Select Compose machine to create the virtual machine.
How to add a VM from the MAAS UI
To add a virtual machine from the MAAS UI:
-
While on VM host’s details view, select ‘Compose’ from the ‘Take action’ drop-down menu to compose a machine.
-
You can choose which storage pool to use from a drop-down list.
Note that when adding more than one disk, the boot disk will be the last disk in the list.
- Click the ‘Compose machine’ button when you’re finished. MAAS will present the VM host detail view.
In a few moments, your new machine will be auto-commissioned. The ‘Machines’ page will reflect this as well. MAAS will deduct the new machine’s resources from the VM host’s resources.
How to delete a VM
To delete a VM, delete it as you would any other MAAS machine:
-
Select the desired machine from the list of machines.
-
Select ‘Delete’ from the ‘Take Action’ menu.
- How to add a VM
- How to set resources while adding a VM
- How to set the architecture while adding a VM
- How to set storage parameters while adding a VM
- How to specify interfaces while adding a VM
- How to find a VM host ID
- How to delete a VM
There is also some background material on VM hosting available, if you need it.
How to add a VM
To compose a basic VM:
maas $PROFILE vm-host compose $VM_HOST_ID
Example output for default composing:
{
"system_id": "73yxmc",
"resource_uri": "/MAAS/api/2.0/machines/73yxmc/"
}
How to set resources while adding a VM
Compose with resources specified:
maas $PROFILE vm-host compose $VM_HOST_ID $RESOURCES
Where $RESOURCES is a space-separated list of six constraints:
- cores= requested cores
- cpu_speed= requested minimum cpu speed in MHz
- memory= requested memory in MB
- architecture= See Architecture below
- storage= See Storage below
- interfaces= See Interfaces below
How to set the architecture while adding a VM
To list available architectures:
maas $PROFILE boot-resources read
Then, for example:
maas $PROFILE vm-host compose $VM_HOST_ID \
cores=40 cpu_speed=2000 memory=7812 architecture="amd64/generic"
How to set storage parameters while adding a VM
Storage parameters look like this:
storage="<label>:<size in GB>(<storage pool name>),<label>:<size in GB>(<storage pool name>)"
For example, let’s examine how to compose a machine with the following two disks:
- 32 GB disk from storage pool
pool1
- 64 GB disk from storage pool
pool2
where we want the first disk to be a bootable root partition /
and the second to be a home directory.
First, create the VM:
maas $PROFILE vm-host compose $VM_HOST_ID "storage=mylabel:32(pool1),mylabel:64(pool2)"
Note that the labels, here mylabel
, are an ephemeral convenience that you might find useful in scripting MAAS actions.
MAAS will create a VM with 2 disks, /dev/vda
(32 GB) and /dev/vdb
(64 GB). After MAAS enlists, commissions and allocates the machine, you can edit the disks before deploying to suit your needs. For example, we’ll set a boot, root, and home partition.
We’ll start by deleting the /
partition MAAS created because we want a separate /boot
partition to demonstrate how yo.
maas admin partition delete $VM_HOST_ID $DISK1_ID $PARTITION_ID
To find $DISK1_ID
and $PARTITION_ID
, use maas admin machine read $VM_HOST_ID
.
Now, create a boot partition (~512MB):
maas admin partitions create $VM_HOST_ID $DISK1_ID size=512000000 bootable=True
We’ll use the remaining space for the root partition, so create another without specifying size:
maas admin partitions create $VM_HOST_ID $DISK1_ID
Finally, create a partition to use as the home directory. Here we’ll use the entire space:
maas admin partitions create $VM_HOST_ID $DISK2_ID
To find $DISK2_ID
, use maas admin machine read $VM_HOST_ID
.
Now, format the partitions. This requires three commands:
maas admin partition format $VM_HOST_ID $DISK1_ID $BOOT_PARTITION_ID fstype=ext2
maas admin partition format $VM_HOST_ID $DISK1_ID $ROOT_PARTITION_ID fstype=ext4
maas admin partition format $VM_HOST_ID $DISK2_ID $HOME_PARTITION_ID fstype=ext4
To find the partition IDs, use maas admin partitions read $VM_HOST_ID $DISK1_ID
and maas admin partitions read $VM_HOST_ID $DISK2_ID
Before you can deploy the machine with our partition layout, you need to mount the new partitions. Here, we’ll do that in three commands:
maas admin partition mount $SYSTEM_ID $DISK1_ID $BOOT_PARTITION_ID "mount_point=/boot"
maas admin partition mount $SYSTEM_ID $DISK1_ID $ROOT_PARTITION_ID "mount_point=/"
maas admin partition mount $SYSTEM_ID $DISK2_ID $HOME_PARTITION_ID "mount_point=/home"
Finally, we deploy the machine. MAAS will use the partitions as we have defined them, similar to a normal Ubuntu desktop install:
maas admin machine deploy $SYSTEM_ID
How to specify interfaces while adding a VM
Using the interfaces
constraint, you can compose virtual machines with interfaces, allowing the selection of VM host NICs.
If you don’t specify an interfaces
constraint, MAAS maintains backward compatibility by checking for a maas
network, then a default
network to which to connect the virtual machine.
If you specify an interfaces
constraint, MAAS creates a bridge
or macvlan
attachment to the networks that match the given constraint. MAAS prefers bridge
interface attachments when possible since this typically results in successful communication.
Consider the following interfaces constraint:
interfaces=eth0:space=maas;eth1:space=storage
Assuming you deploy the VM host on a machine or controller with access to the maas
and storage
spaces, MAAS will create an eth0
interface bound to the maas
space and an eth1
interface bound to the storage
space.
Another example tells MAAS to assign unallocated IP addresses:
interfaces=eth0:ip=172.16.99.42
MAAS automatically converts the ip
constraint to a VLAN constraint (matching the VLAN which corresponds to the subnet can be found – e.g. 172.16.99.0/24
.) and assigns the IP address to the newly-composed machine upon allocation.
See the Machines MAAS API documentation↗
for a list of all constraint keys.
How to find a VM host ID
Here’s a simple way to find a VM host’s ID by name using jq
:
maas $PROFILE vm-hosts read | jq '.[] | select (.name=="MyVMHost") | .name, .id'
Example output:
"MyVMHost"
1
How to delete a VM
maas $PROFILE machine delete $SYSTEM_ID
After you delete a machine, its resources will be available for other VMs.