If you want to run a machine container, you would use LXD. But if you want to run a virtual machine, you would use multipass. multipass is so new, that is still in beta. The name is not known yet to Google, and you get many weird results when you search for it.

Both containers and virtual machines, you can set them up manually without much additional tools. However, if you want to perform real work, it helps if you have a system that supports you. Let’s see what multipass can do for us.

Installing the multipass snap

multipass is available as a snap package. You need a Linux distribution, and the Linux distribution has to have snap support.

Check the availability of multipass as a snap,

$ snap info multipass name: multipass summary: Ubuntu at your fingertips publisher: saviq description: | Multipass gives you Ubuntu VMs in seconds. Just run `multipass.ubuntu create` and it'll do all the setup for you. snap-id: mA11087v6dR3IEcQLgICQVjuvhUUBUKM channels: stable: – candidate: – beta: 2017.2.2 (37) 44MB classic edge: 2017.2.2-4-g691449f (38) 44MB classic

There is a snap available, and is currently in the beta channel. It is a classic snap which means that it has less restrictions that your typical snap.

Therefore, install it as follows,

$ sudo snap install multipass

Trying out multipass

Now what? Let’s run it.

$ multipass Usage: /snap/multipass/37/bin/multipass [options] <command> Create, control and connect to Ubuntu instances. This is a command line utility for multipass, a service that manages Ubuntu instances. Options: -h, --help Display this help -v, --verbose Increase logging verbosity, repeat up to three times for more detail Available commands: connect Connect to a running instance delete Delete instances exec Run a command on an instance find Display available images to create instances from help Display help about a command info Display information about instances launch Create and start an Ubuntu instance list List all available instances mount Mount a local directory in the instance purge Purge all deleted instances permanently recover Recover deleted instances start Start instances stop Stop running instances umount Unmount a directory from an instance version Show version details Exit 1

Just like with LXD, launch should do something. Let’s try it and see what parameters it takes.

$ multipass launch Launched: talented-pointer

Oh, no. Just like with LXD, if you do not supply a name of the container/virtual machine, they pick one for you AND proceed in creating the container/virtual machine. So, here we are with the virtual machine creatively named talented-pointer.

How do we get some more info about this virtual machine? What defaults were selected?

$ multipass info talented-pointer Name: talented-pointer State: RUNNING IPv4: 10.122.122.2 Release: Ubuntu 16.04.3 LTS Image hash: a381cee0aae4 (Ubuntu 16.04 LTS) Load: 0.08 0.12 0.07 Disk usage: 1014M out of 2.1G Memory usage: 37M out of 992M

The default image is Ubuntu 16.04.3, on a 2GB disk and with 1GB RAM.

How should we have created the virtual machine instead?

$ multipass launch --help Usage: /snap/multipass/37/bin/multipass launch [options] [<remote:>]<image> Create and start a new instance. Options: -h, --help Display this help -v, --verbose Increase logging verbosity, repeat up to three times for more detail -c, --cpus <cpus> Number of CPUs to allocate -d, --disk <disk> Disk space to allocate in bytes, or with K, M, G suffix -m, --mem <mem> Amount of memory to allocate in bytes, or with K, M, G suffix -n, --name <name> Name for the instance --cloud-init <file> Path to a user-data cloud-init configuration Arguments: image Ubuntu image to start

Therefore, the default command to launch a new instance would have looked like

$ multipass launch --disk 2G --mem 1G -n talented-pointer

We still do not know how to specify the image name, whether it will be Ubuntu 16.04 or something else. saviq replied, and now we know how to get the list of available images for multipass.

$ multipass find multipass launch … Starts an instance of Image version ---------------------------------------------------------- 14.04 Ubuntu 14.04 LTS 20171208 (or: t, trusty) 16.04 Ubuntu 16.04 LTS 20171208 (or: default, lts, x, xenial) 17.04 Ubuntu 17.04 20171208 (or: z, zesty) 17.10 Ubuntu 17.10 20171213 (or: a, artful) daily:18.04 Ubuntu 18.04 LTS 20171213 (or: b, bionic, devel)

multipass merges the CLI semantics of both the lxc and the snap clients :-).

That is, there are five images currently available and each has several handy aliases. And currently, the default and the lts point to Ubuntu 16.04. In spring 2018, they will point to Ubuntu 18.04 when it gets released.

Here is the list of aliases in an inverted table.

Ubuntu 14.04: 14.04, t, trusty

Ubuntu 16.04: 16.04, default, lts, x, xenial (at the end of April 2018, it will lose the default and lts aliases)

Ubuntu 17.04: 17.04, z, zesty

Ubuntu 17.10: 17.10, a, artful

Ubuntu 18.04: daily:18.04, daily:b, daily:bionic, daily:devel (at the end of April 2018, it will gain the default and lts aliases)

Therefore, if we want to launch a 8G disk/2GB RAM virtual machine myserver with, let’s say, the current LTS Ubuntu, we would explicitly run

$ multipass launch --disk 8G --mem 2G -n myserver lts

Looking into the lifecycle of a virtual machine

When you first launch a virtual machine for a specific version of Ubuntu, it will download from the Internet the image of the virtual machine, and then cache it locally for any future virtual machines. This happened earlier when we launched talented-pointer. Let’s view it.

$ multipass list Name State IPv4 Release talented-pointer RUNNING 10.122.122.2 Ubuntu 16.04 LTS

Now delete it, then purge it.

$ multipass delete talented-pointer $ multipass list Name State IPv4 Release talented-pointer DELETED -- $ multipass purge $ multipass list No instances found.

That is, we have a second chance when we delete a virtual machine. A deleted virtual machine can be recovered with multipass recover.

Let’s create a new virtual machine and time it.

$ time multipass launch -n myVM default Launched: myVM Elapsed time : 0m16.942s User mode : 0m0.008s System mode : 0m0.016s CPU percentage : 0.14

It took about 17 seconds for a virtual machine. In contrast, a LXD container takes significantly less,

$ time lxc launch ubuntu:x mycontainer Creating mycontainer Starting mycontainer Elapsed time : 0m1.943s User mode : 0m0.008s System mode : 0m0.024s CPU percentage : 1.64

We can stop and start a virtual machine with multipass.

$ multipass list Name State IPv4 Release myVM RUNNING 10.122.122.2 Ubuntu 16.04 LTS $ multipass stop myVM $ multipass list Name State IPv4 Release myVM STOPPED -- Ubuntu 16.04 LTS $ multipass start Name argument or --all is required Exit 1 $ time multipass start --all Elapsed time : 0m11.109s User mode : 0m0.008s System mode : 0m0.012s CPU percentage : 0.18

We can start and stop virtual machines, and if we do not want to specify a name, we can use –all (to perform a task to all). Here it took 11 seconds to restart the virtual machine. The time it takes to start a virtual machine is somewhat variable and on my system it is in the tens of seconds. For LXD containers, it is about two seconds or less.

Running commands in a VM with Multipass

From what we saw earlier from multipass –help, there are two actions, connect and exec.

Here is connect to a VM.

$ multipass connect myVM Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-103-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Get cloud support with Ubuntu Advantage Cloud Guest: http://www.ubuntu.com/business/services/cloud 5 packages can be updated. 3 updates are security updates. Last login: Thu Dec 14 20:19:45 2017 from 10.122.122.1 To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. ubuntu@myVM:~$

Therefore, with connect, we get a shell directly to the virtual machine! Because this is a virtual machine, it booted a new Linux kernel, Linux 4.4.0 in parallel with the one I use on my Ubuntu system. There are 5 packages that can be updated, and 3 of them are security updates. Nowadays in Ubuntu, any pending security updates are autoinstalled by default thanks to the unattended-upgrades package and its default configuration. They will get autoupdated sometime within the day and the default configuration will automatically do the security updates only.

We view the available updates, five in total, three are security updates.

ubuntu@myVM:~$ sudo apt update Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB] Get:4 http://security.ubuntu.com/ubuntu xenial-security/main Sources [104 kB] Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB] Get:6 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [48.9 kB] Get:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [408 kB] Get:8 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [179 kB] Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [98.9 kB] Fetched 1,145 kB in 0s (1,181 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 5 packages can be upgraded. Run 'apt list --upgradable' to see them. ubuntu@myVM:~$ apt list --upgradeable Listing... Done cloud-init/xenial-updates 17.1-46-g7acc9e68-0ubuntu1~16.04.1 all [upgradable from: 17.1-27-geb292c18-0ubuntu1~16.04.1] grub-legacy-ec2/xenial-updates 17.1-46-g7acc9e68-0ubuntu1~16.04.1 all [upgradable from: 17.1-27-geb292c18-0ubuntu1~16.04.1] libssl1.0.0/xenial-updates,xenial-security 1.0.2g-1ubuntu4.10 amd64 [upgradable from: 1.0.2g-1ubuntu4.9] libxml2/xenial-updates,xenial-security 2.9.3+dfsg1-1ubuntu0.5 amd64 [upgradable from: 2.9.3+dfsg1-1ubuntu0.4] openssl/xenial-updates,xenial-security 1.0.2g-1ubuntu4.10 amd64 [upgradable from: 1.0.2g-1ubuntu4.9] ubuntu@myVM:~$

Let’s update them all and get done with it.

ubuntu@myVM:~$ sudo apt upgrade Reading package lists... Done ...ubuntu@myVM:~$

Can we reboot the virtual machine with the shutdown command?

ubuntu@myVM:~$ sudo shutdown -r now $ multipass connect myVM terminate called after throwing an instance of 'std::runtime_error' what(): ssh: Connection refused Aborted (core dumped) Exit 134 $ multipass connect myVM Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-104-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Get cloud support with Ubuntu Advantage Cloud Guest: http://www.ubuntu.com/business/services/cloud 0 packages can be updated. 0 updates are security updates. Last login: Thu Dec 14 20:40:10 2017 from 10.122.122.1 ubuntu@myVM:~$ exit

Yes, we can. It takes a few seconds for the virtual machine to boot again. When we try to connect too early, we get an error. We try again and get connect.

There is the exec action as well. Let’s see how it works.

$ multipass exec myVM pwd /home/ubuntu $ multipass exec myVM id uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),109(netdev),110(lxd)

We specify the VM name, then the command to run. The default user is the ubuntu user (non-root, can sudo without passwords). In contrast, with LXD the default user is root.

Let’s try something else, uname -a.

$ multipass exec myVM uname -a Unknown option 'a'. Exit 1

It is a common Unix shell issue, the shell passes the -a parameter to multipass instead of leaving it unprocessed so that it runs in the virtual machine. The solution is to add — at the point we want the shell to stop processing parameters, like in

$ multipass exec myVM -- uname -a Linux myVM 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

If you try to exec commands a few times, you should encounter a case where the command hangs. It does not return, and you cannot Ctrl-C it either. It’s a bug, and the workaround is to open another shell in order to multipass stop myVM and then multipass start myVM.

Conclusion

It is cool to have multipass that complements LXD. Both tools make it easy to create virtual machines and machine containers. There are some bugs and usability issues than can be reported at the Issues page. Overall, it makes running virtual machines and machine containers so usable and easy.

Share this: Twitter

Facebook

Reddit

Email

Print



Like this: Like Loading...