Build a MAAS and LXD environment in 30 minutes with Multipass on Ubuntu

Key Value
Summary Build a MAAS and LXD environment in 30 minutes with Multipass
Categories server
Difficulty 3
Author Anton Smith

Overview

Duration: 2:00

Time to try MAAS! We wanted to make it easier to go hands on with MAAS, so we created this tutorial to enable people to do that, right on their own PC or laptop. Below, we’ll explain a bit about how MAAS works and then dive straight into it.

Hang in there, because you’ll be up and running in no time, installing operating systems with ease and without breaking a sweat!

Installing MAAS itself is easy, but building an environment to play with it is more involved. MAAS works by detecting servers that attempt to boot via a network (called PXE booting). This means that MAAS needs to be on the same network as the servers.

Having MAAS on the same network as the servers can be problematic at home or the office, because MAAS also provides a DHCP server and it can (will) create issues if target servers and MAAS try to interact on your usual network.

A potential MAAS test setup

One way to try MAAS is to have a separate network, such as a simple switch+router, with several servers attached. One of these servers runs MAAS, and the others are target servers that MAAS can provision. Such a setup might look like this:

image

In this tutorial, we’re going to build all of this automatically for you inside a virtual machine, using multipass. No need to build all of this infrastructure just to try MAAS, we’ll take care of it for you.

Multipass

Multipass is a tool from Canonical that can help you easily create VMs (Virtual Machines). This tutorial uses Multipass to create a self-contained Virtual Machine that includes MAAS and an LXD host right on your desktop or laptop.

LXD

Inside the VM, Multipass will use LXD and Linux configuration to build a virtual private switch and router, and provide a way to create what are called “nested VMs”, or virtual machines inside the virtual machine made by Multipass. These nested VMs will represent servers that MAAS can provision.

When we’re finished, you’ll be able to log in to the MAAS server running inside the VM on your computer, compose nested VMs using LXD, and then commission and deploy them. It will then be simple to spin up a quick MAAS environment without needing to build a complete real environment.

image

Requirements

Duration: 1:00

You will need:

  • Ubuntu 18.04 LTS or higher OR Windows with Hyper-V
    (Note: this tutorial has been tested with Ubuntu, but there are reports it works with Hyper V on Windows. Read more about enabling Hyper-V here.)
  • 16 GB of RAM
  • A quad core CPU with virtualisation support (Intel VT or AMD-V)
  • Virtualisation support enabled in the BIOS
  • 30 GB of free disk space

The memory and disk space is required because we will later be launching nested VMs inside our new environment using MAAS and LXD.

Don’t have the right machine?

If you don’t have the right machine or OS to try the tutorial, don’t worry - we have created a quick video of ourselves running through the tutorial which you can watch here.

Install multipass

Duration: 2:00

During this tutorial, we’re going to be entering quite a few commands in a terminal. Open a terminal of your choice, and let’s get started.

First up, let’s install multipass:

sudo snap install multipass

Check whether multipass installed correctly and is functioning by launching an Ubuntu guest and running the following commands:

multipass launch --name foo
multipass exec foo -- lsb_release -a

You should see the following output:

Delete the test VM, and purge it:

multipass delete --purge foo

Congratulations, you’ve just run a test VM with Multipass! Now it’s time to create your MAAS and LXD environment.

Check whether virtualisation is working

Duration: 2:00

We now need to check whether virtualisation is working correctly. This is a relatively simple process. In your terminal, run:

sudo apt install cpu-checker
kvm-ok

You should see the following output:

Assuming your machine supports hardware virtualisation, we are ready to move on and launch MAAS.

:warning: Note
The tutorial will not work unless you have ensured virtualisation support is enabled.
The first place to check if you don’t see the expected output is your BIOS - consult your motherboard or laptop manufacturer documentation if you are uncertain.

Launch the MAAS and LXD multipass environment

Duration: 4:00

Launching the MAAS and LXD VM is as simple as the test VM was to launch, except that this time you will pass a cloud-init config file, and a few other parameters for CPU cores, memory, and disk space.

The below command looks a bit long, so let’s break it down:

  • wget will pull down the config file from a Canonical github repository and pipe it to multipass
  • multipass accepts the output from wget as input for the cloud-init parameter

Feel free to check the contents of the cloud-init config file before running this. Copy the entire command below (both lines) and run it:

wget -qO- https://raw.githubusercontent.com/canonical/maas-multipass/main/maas.yml \
 | multipass launch --name maas -c4 -m8GB -d32GB --cloud-init -

Wait for multipass to finish launching the MAAS and LXD VM. When the command completes, verify that it is running:

multipass list

You should see the following:

Here you can see two IP addresses. One belongs to the internal network (10.10.10.1) for MAAS and LXD guest VMs to communicate. You can use the other to connect to MAAS from your computer.

The internal network is 10.10.10.0/24. Take note of the other IP address; you will need it in the following steps. In the above output, that IP address is 10.97.28.47. Later on, we will refer to this IP as <MAAS IP>, but you will need to replace it with yours.

Great work! Now you’re ready to try out MAAS.

Log into MAAS

Duration: 1:30

Now that MAAS is running, you need to login and finalise the setup for MAAS by configuring DNS and verifying the installation.

From a browser on your computer, go to:

http://<MAAS_IP>:5240/MAAS

Don’t worry that it’s not HTTPS - you’re accessing this on your own PC (nobody can eavesdrop).

You should see the MAAS log in page:

Log in with the username admin and password admin, and you should be greeted with the welcome screen. DNS in the DNS forwarder field should be prepopulated with 8.8.8.8, but you can change it if you like to another DNS provider:

:warning: Note
During setup, you might notice the following text displayed as a banner: “Boot image import process not started … Visit the boot images page to start the import.” Don’t worry, this will go away once MAAS has downloaded what it needs. Don’t click on the link in the banner.

Scroll down and click the green Continue button. You should then see the Images screen. This is where you can tell MAAS which images to automatically download and keep synchronised. For now, just leave the selections as they are and click the green Update selection button:

You should now be at the ssh key setup screen. This is a very important part of using MAAS, because MAAS automatically puts SSH public keys on machines when deploying them, enabling you to gain access to them. Normally you’d have to generate a key-pair or specify your Github or Launchpad keys. But this time around, we’ve taken care of this for you already - there is a key-pair ready and installed inside the VM.

This means you can skip adding a ssh key-pair - just click Skip user setup, and then when it asks if you are sure, click the green Skip user setup button:

Verify and explore your MAAS and LXD installation

Duration: 4:00

Let’s take a look around our new setup. MAAS might still be downloading some Ubuntu images, getting itself ready to use them to deploy. By default, this is around 1 GB, so depending on your network speed it might take a little while.

First, click the KVM tab up top. You should see a LXD server already set up for you, similar to the following:

Second, click the Controllers tab up top. You should see that you have a controller of type rack and region controller, and the status should show a green tick:

Now, click the Images tab. If MAAS has finished syncing the Ubuntu images mentioned above, then you should see that the status says “Synced”:

If it’s not synced yet, wait for a few minutes and refresh the page.

Once the images are synced, it’s time for some fun – using MAAS to create our first VM guest with LXD!

Create a VM guest

Duration: 2:00

Click the KVM tab up top again, and click the MAAS link for the KVM host in the “NAME” column, which should bring you here:

Click Add virtual machine, and you should see:

Now fill in the details. For an Ubuntu guest, we need to set RAM, CPU and disk to their recommended values:

  • Set the Hostname field to AwesomeVM1
  • Set the RAM to 6 GB
  • Set the storage to 8 GB
  • Set the CPU cores to 2

When you’re done, scroll down and click the green Compose machine button. Scroll back up and you should see:

Notice how the CPU cores, memory, and disk space consumption by your first VM is being tracked by LXD. Note that, if you have space, you can compose more than one VM by repeating this step and providing CPU, memory, and disk space.

Congrats! You’ve now created your first VM guest. We’re almost done!

Commissioning and deploying Ubuntu to the VM guest

Duration: 4:00

MAAS should have already started commissioning the machine. When commissioning, MAAS does some testing to make sure everything is fine with the machine. It will run CPU, memory and storage tests, and when it’s done (assuming everything is good), it will show that the machine is in a READY state.

Click the Machines tab up top and you should see your new VM host in the list with a status of Commissioning. It should look like this:

Click the machine and you should see more details:

Click the Commissioning tab to watch the commissioning progress live.

When it’s done, the machine will move into a ready state, and can be viewed from the Machines tab or from within the machine view itself:

It’s now time to deploy Ubuntu to the machine! From the Machines tab, tick the AwesomeVM1 tickbox. Then simply click the green Take action button in the top right and click deploy:

After clicking deploy, you will see the following screen, click the green Start deployment for machine button:

You should see that MAAS starts deploying Ubuntu to the machine. It will take a while to deploy Ubuntu depending on the speed of your computer.

When it’s done, assuming everything went well, you should now see the machine status changes to reflect the Ubuntu version installed:

Great work - the machine is now ready for us to log in and verify that it is up and running.

Important: take note of the IP address displayed for your AwesomeVM1 machine in the screenshot above. We will refer to this as <AwesomeVM1 IP> in the next step. In our screenshot above, the IP address is 10.10.10.2, which belongs to the private network created for MAAS and LXD by multipass.

Verify the VM guest is up and running

Duration: 1:30

Go back to the terminal you started earlier, which should still be logged in to the multipass shell on your MAAS VM:

Ping your AwesomeVM1 guest:

ping <AwesomeVM1 IP>

You should see ping responses:

SSH into the VM guest by running the following command. Accept the authenticity notice:

ssh ubuntu@<AwesomeVM1 IP>

You should see that you are now in a shell on the AwesomeVM1 machine:

Great work!

Try pinging something on the internet from the machine:

ping ubuntu.com

Again, you should see ping responses:

That’s it! We’ve successfully created and deployed a VM inside our multipass VM using MAAS and LXD.

That's all folks!

Duration: 0:00

Fantastic work! We now have our own MAAS and LXD environment!

You’ve learned:

  • How to install a MAAS and LXD playground environment using Multipass
  • How to create a VM guest
  • How to setup MAAS with an SSH key
  • How to quickly verify whether MAAS and LXD are operating correctly
  • How to create a VM guest
  • How to deploy Ubuntu using MAAS to a machine
  • How to log in to the VM guest and verify it is functioning

Play around creating some more VMs, but be aware of your CPU, memory, and storage limitations. If you like, you can experiment with deleting machines from the Machines tab and recreating VMs in the KVM tab.

Next steps

If you want to get a bit more advanced, you can try editing the maas.yml file and altering how much storage LXD assigns. You can also change the multipass command to start your MAAS VM, adding more CPU cores, memory and disk. Note that you need to ensure that the disk space you assign using multipass is large enough to accommodate both MAAS and the LXD storage.

To learn more about bare metal provisioning and MAAS, try our ebook.

Learn more about MAAS at https://maas.io. Perhaps you would like to build a real physical environment for MAAS and LXD?

1 Like
  1. AwesomeVM1’ does not conform to the hostname naming convention, and an error will be thrown:‘cannot set hostname “AwesomeVM1”: name not valid ’。Please modify the ‘AwesomeVM1’ in the document to a usable value, for example: awesomevm1。
  2. Maas3.1 cannot use the LXD mode normally, because after the deployment is completed, when creating a VM on the KVM page, there is no ‘Architecture’ to choose from. Modify ‘snap install maas’ in maas.yml to ‘snap install --channel=3.0/stable maas’ and there is no such issue.
1 Like

Thanks for bringing this to my attention.

#2 looks like a bug and I’ve filed it here: https://bugs.launchpad.net/maas/+bug/1955912
I’ve also changed the tutorial repo so that it sets the MAAS version to 3.0 for now as per your suggestion.

#1 may also be a bug but I will come back.

Again, thank you for highlighting this!

Nice Tutorial. However, with the latest versions of MAAS 3.1 and LXD 4.22. It is not able to commission any KVM composed machines.

Following the tutorial step-by-step everything seems to be fine up until the step “Create VM Guest”. The screen shot you have differs from what is seen in the current version, clicking on “Add Virtual Machine” gets me to composing the machine. Composing Machine also works as per your description.

The machine composition happens but commissioning fails with a lot of errors (Most of the commissioning scripts fail). There is also a power error. Commissioning scripts also are trying to run BMC scripts. I do not understand why maas does not recognize that the composed machine is virtual.

If you have seen this behavior or if you have suggestions on what to look for it would be greatly appreciated.

Thank You

Hi - sorry yes there are some issues with maas 3.1 and lxd. For now I’ve reverted the tutorial to use maas 3.0 (again), so you can take the latest cloud init file and make a new multipass VM and things should be fine.

@xsyourpal could you attach a screenshot of the commissioning tab for the machine as well as the output/error for failing scripts?

The failure happens even when following the Tutorial exactly as shown. This is using the configuration provided in the tutorial, so maas version is 3.0

Thank You for your help.

I am only allowed to upload one screenshot at a time. Therefore 2 reply’s to your request

I did revert to following your tutorial exactly. The commissioning errors happen even then, so it is not related to maas version per se. The screenshots I have provided are with using multipass with its standard local.driver qemu

I also tried following the tutorial by changing the multipass local.driver to lxd on my bare metal host. That approach also did not work, however the error in that case was:
“Error:Pod unable to compose machine: Unable to compose machine because: Failed talking to pod: Failed creating instance record: Instance type “virtual-machine” is not supported on this server”

Thank you for your help.

could you paste the output of lxc info <machine-name> --show-log for that VM?

Sorry, I meant lxc info --show-log vm01 from the MAAS machine, to get the info about the VM that’s failing commissioning

The command lxc info vm01 --show-log returns Error: Not Found. So does not seem vm01 instance was even created.
I have tried this tutorial on two different systems (both ubuntu 20.04) and both of them give the same error.

The Logs from the Commissioning action after composing shows the following:

what host are you using? are you running this on an ubuntu machine?

I just re-tested it on a fresh ubuntu 21.04 host and it worked ok.

Note, the tutorial relies on nested VMs, so if you are running your ubuntu host itself in a VM, that might cause issues.

I.e. Multipass creates a new VM, and inside that the tutorial uses LXD to create more VMs. If you are already inside a VM for your host, then that is 3 layers, and we have not verified the tutorial in that scenario.

I ran the tutorial using the yaml that you have provided so that the setup matches yours. I ran on two bare metal machines, one is a server class and one workstation both running Ubuntu 20.04.

I just tried to run the tutorial again on another machine and I see the same error. Details of that system are as follows:

Hardware: Intel NUC Intel® Core™ i5-4250U CPU @ 1.30GHz
OS: Linux nuc 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

This command:
wget -qO- https://raw.githubusercontent.com/canonical/maas-multipass/main/maas.yml
| multipass launch --name maas -c4 -m8GB -d32GB --cloud-init -

sets everything up nicely and I see nothing that would indicate a departure from what you have shown in your tutorial. Composing the virtual machine seems to kick off fine, with resource allocation properly accounted for, the deviation is in the failed commissioning where it seems to try to use the power scripts like it was real hardware. I am following tutorial steps closely. As I mentioned above, my systems have Ubuntu 20.04 fully updated.

I believe, the nesting is baremetal-Multipass-VM (maas)–Composed VM (so two levels)

Having tried it a few times, I believe this tutorial does not seem work on Ubuntu 20.04.1 systems unless some other user has had a different experience. I do not have a system to do a fresh 21.04 install and try run the tutorial at the moment

Thank You for helping on this.

Hi, I went back and tested again and made sure my host was 20.04 and it worked for me, including deploying a VM. I did edit my yaml file to change to maas 3.1 and to use a new LXD version.

It looked like this. Note the LXD snap refresh, which will make sure it’s using a new LXD. However, this should not make any difference really, as I also tested without these changes and it worked fine. I’m a bit stuck understanding what’s going wrong for you.

    snap:
      commands:
        - snap install maas
    #    - snap install --channel=3.0/stable maas
        - snap install --channel=latest/stable lxd
        - snap refresh --channel=latest/stable lxd
        - snap install maas-test-db

Thank You for taking the time to investigate this issue.
Unfortunately all my efforts result in the same error on commissioning.

In the Multipass VM, I have:

core18 20211215 2284 latest/stable canonical✓ base
core20 20220114 1328 latest/stable canonical✓ base
lxd 4.22 22340 latest/stable canonical✓ -
maas 3.0.0-10029-g.986ea3e45 18309 3.0/stable canonical✓ -
maas-cli 0.6.5 13 latest/stable canonical✓ -
maas-test-db 12.4-17-g.9e70484 54 3.0/stable canonical✓ -
snapd 2.54.2 14549 latest/stable canonical✓ snapd

In the maas.yaml, the following lines…trying to install maas both ways, one of them matches what you have (both methods of installing maas result in the same error)

commands:
# - snap install maas
- snap install --channel=3.0/stable maas
- snap install --channel=latest/stable lxd
- snap refresh --channel=latest/stable lxd
- snap install maas-test-db

Switching the lines:
snap install maas
# snap install --channel=3.0/stable maas
does not help since it then install maas 3.1 and that also results in commissioning error.

It is a very nice tutorial. Just seems very sensitive to having precise environment for it to work.

Thank You

Hi,
I got the same error message than you on another tutorial, I realised it was because I forgot to activate the virtualisation on the BIOS…

Did you do this test:

After enabling CPU virtualisation it works fine for me.

3 Likes

Hello

What does this mean:

" If you want to get a bit more advanced, you can try editing the maas.yml file and altering how much storage LXD assigns."

I understand maas.yml is used when creating maas VM via multiboot, aren’t lxd specifics done from inside maas WebUI? Is there a separate yml file for lxd?