Custom Storage Volumes with LXD

Image Source

Canonical Ltd. provides a container system similar to the popular Docker, but it can do so much more. For instance, it can run multiple processes inside the same container simultaneously, whereas Docker can only run one at a time. LXD (pronounced Lex-Dee) is an image-based system that enables the user to create a container from a pre-existing Linux image from one of its remote image servers, which reduces your workload considerably. The user feels as if they’re running an OS inside the container, rather than a single application. In other words, you get the benefit of a VM coupled with the simplicity of a container.

Storage Pools and Storage Volumes

LXD has the ability to create multiple storage pools on which you can generate storage volumes. Think of a storage pool as a hard drive (or an array of hard drives) and storage volumes as partitions on those hard drives—only they’re not on your own computer, they’re stored on the container’s host computer. The literal difference between a storage volume and a partition is that volumes are established on a dynamic disk (a structure across the aforementioned array of disks) while a partition is on a basic disk, like the ones used for your computer’s hard drive.

It’s really useful to generate multiple storage volumes for organization and project management—all while keeping your OS and local file directories safe from the content inside these containers and vice versa. LXD takes this functionality a step further by supporting custom storage volumes to make additional storage that fits your specific needs. These customized volumes may be part of the same storage pool as its own instance or part of a different storage pool, which could even be an entirely different class of storage. Plus, these custom volumes can be attached to multiple containers in a variety of locations. 

You actually made your first storage pool when you set up your first container, but it might not have been obvious during the initiation process. Create new storage volumes with this simple command:

lxc storage volume create pool-name volume-name

It’s that easy!

Remember, you can create multiple storage volumes with LXD, so make as many as you need to keep your project organized. Run the above command each time you want to create a new volume. 

Move your custom volumes between pools with these commands:

lxc copy volume-name

lxc move volume-name

At any time, you’re able see a list of your storage volumes, along with their status, type, and more, with this simple command:

lxc list 

Multiple Instances

One of the coolest things you can do with your new storage volumes is to attach them to multiple instances. This can be beneficial if you want to use them to balance the load across several web servers or even to share large assets with different containers, like for Big Data analysis. This saves you having to copy the stored information several times. 

Use these commands to attach your volumes to different containers:

lxc storage volume attach pool-name volume-name container-name1 /volume-name

lxc storage volume attach pool-name volume-name container-name2 /volume-name

Both of these instances will see the exact same information in your storage volume.

As always when working with data, it’s wise to backup or take snapshots of your progress regularly. It’s important to know the difference between snapshots and backups, as well as when it’s advisable to use each. Snapshots are similar to Apple’s Time Machine in the sense that you can go back to a specific point—basically an undo button in the container. 

Snapshots and Backups

Snapshots are both easy and inexpensive—a perfect way to save the state of your work at a particular location. Unlike backups, snapshots are not a full copy of the VM hard disk, but they are very useful in development and testing. For example, if something goes wrong during development, you can undo and return to the point it was working correctly. At each point in your development when things are working, just take a snapshot to easily return to that spot before the break.

Keep in mind that snapshots are not backups. Backups are self-contained. They save everything both running in and out of the container, but they’re not useful to go back to a specific point in your work; however, they are quite useful in case of a complete system failure or irreversible data loss. It’s also possible to backup a LXD server, capturing instances, images, networks, profiles, and storage volumes.

There are a few choices when deciding where to store your LXD data, depending on your needs. For example, you can share your data with the host computer or create a loop disk, which are both quite simple to set up, or even have a dedicated disk/partition, which is a little more difficult—but has a higher performance. The details of each are outside the scope of this article, but you can read about them and more through our LXD online knowledge base.

Between the ability to generate multiple, custom storage volumes and the experience of  OS-level virtualization, LXD is the perfect solution to fill your business needs when the complexity of a VM is too much and the limitations of Docker slow down your progress. Canonical Ltd. offers a versatile, powerful alternative to the containerization landscape. 

Leave a Reply