joemcmanus
on 29 August 2019


This article is more than 5 year s old.


I needed to install a clean instance of Bionic to test some code, but I did not want to use a full virtual machine as I was in a hurry.  To do this, I used LXD to quickly deploy new Bionic and Xenial instances in minutes. 

If you are not familiar with LXD, it is a next generation container management system that is more like a VM than a traditional container. If you find yourself in a similar spot, here are the 3 commands to get an instance of Linux running and fourth to get you logged in. 

TL;DR 

snap install lxd

lxd init

(accept the default/yes to everything)

lxc launch ubuntu:18.04 bionic

lxc exec bionic -- /bin/bash

For the more inquisitive reader, first you install LXD as a snap.

snap install lxd

Then you set up LXD using lxd init and select ‘yes’ to the defaults. 

lxd init

Next, install your system using lxc launch <the image> <nickname> . Below we install Ubuntu 18.04 and give it the nickname ‘bionic’. 

lxc launch ubuntu:18.04 bionic

To connect to the system, use lxc exec. 

lxc exec bionic -- /bin/bash

Now verify your guest OS. 

I specifically wanted to compare something on Xenial and Bionic, so I ran the same commands except I substituted 16.04 for 18.04. 

Create another LXD image of Xenial and execute bash to connect. 

That is your first step in to a larger world. 

What’s Next ? 

One task I do fairly often as a security engineer is set up a web service and attac^H^H to test it for vulnerabilities. With the LXD instances you have created so far they are only available on the host they are running on.  I usually test from a remote host – to do that with LXD you configure a LXD proxy. In the following example, we’ll set up a proxy to allow web traffic into our LXD container. 

lxc exec bionic bash

apt install lighttpd

You are going to want to make sure you are connecting to the right VM, create a page unique to your instance by editing /var/www/html/index.html 

On the host, not the container, you will run lxc config to add a proxy. 


lxc config device add bionic web proxy listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80

Now in your container, start your lighttpd service. 

lxc exec bionic bash`

service lighttpd start

Browse from your workstation to the IP of your lxd host. 

With that you know have a very lightweight virtual container environment capable of performing any number of tasks. 

Note For Ubuntu Server Users

These examples were all performed on an Ubuntu 19.04 Desktop, on Ubuntu Server LXD setup is even simpler. For those on Ubuntu 16.04 and 18.04 LXD is often pre-installed as a deb, if you want to switch to the snap run “snap install lxd” followed by “lxd.migrate”. On Ubuntu Server 18.10 and newer LXD is installed as a snap, simply run “lxd init” to begin using LXD.


Newsletter
signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts


Canonical
25 June 2025

Native integration now available for Pure Storage and Canonical LXD

Article Canonical announcements

Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer delivering enterprise-grade all-flash storage, have partnered to introduce a native integration between LXD and Pure Storage FlashArray. This collaboration allows organizations to combine open source virtualization with industry-leading block storage...

Canonical
25 June 2025


Miona Aleksic
21 May 2025

Simplify security maintenance and compliance with Ubuntu Pro auto-attach for LXD guests

Article Cloud and server

With the latest LXD release, Ubuntu Pro now supports auto-attachment for LXD guest instances, offering organizations a seamless way to extend Ubuntu Pro benefits across their infrastructure.

Miona Aleksic
21 May 2025


Isobel Kate Maxwell
24 April 2025

The hitchhiker’s guide to infrastructure modernization

Article Cloud and server

One of my favourite authors, Douglas Adams, once said that “we are stuck with technology when what we really want is just stuff that works.” Whilst Adams is right about a lot of things, he got this one wrong – at least when it comes to infrastructure. As our Infra Masters 2025 event demonstrated, infrastructure

Isobel Kate Maxwell
24 April 2025