# How to Use LXD Storage Pools & Volumes

**URL:** <https://discussion.scottibyte.com/t/how-to-use-lxd-storage-pools-volumes/317>\
**Category:** Uncategorized\
**Created:** [December 12, 2023, 11:43pm UTC](https://discussion.scottibyte.com/t/how-to-use-lxd-storage-pools-volumes/317 "2023-12-12T23:43:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://discussion.scottibyte.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://discussion.scottibyte.com/u/scott)\
**Post date:** [December 12, 2023, 11:43pm UTC](https://discussion.scottibyte.com/t/how-to-use-lxd-storage-pools-volumes/317/1 "2023-12-12T23:43:58Z")

</div>

When you create containers, you are using the “default” profile which uses storage in the default storage pool and also assigns device eth0. In this video, we learn how to create other storage pools and custom volumes.

The “default” profile for LXD can be viewed or edited with the following command from your LXD host:

```auto
lxc profile edit default

```

The default profile will appear as follows:

![image](https://discussion.scottibyte.com/uploads/default/original/1X/8a496b694805992e9e2b4760d887bbf78ed7dad8.png)

We can list our storage pools:

```auto
lxc storage list

```

By default, you will have only the “default” storage pool.

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/c37fc4ef2bc727d83856a4040125e9a1a3fa44f6.jpeg)

The default profile and the default storage pool are a part of the configuration that you get with the “lxd init” command that I covered in the “LXD Step by Step” tutorial.

The default storage pool contains images downloaded from [linuxcontainers.org](http://linuxcontainers.org), block storage devices for each container, snapshot storage, and also custom volumes. You can see the content of your default storage pool with the following command:

```auto
lxc storage volume list default

```

My output from this command looks like this:

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/4dd6110105df2a34a67f763e9abc2b0fbdcc7e0b.jpeg)

When you initially configured your LXD server with the “lxd init” command as shown in the “LXD Step by Step” tutorial, we created the default storage pool as a virtual zfs file system inside of a file.

This time, I created another virtual file for another LXD Storage Pool which I arbitrarily configured at 50GB just for the demo.

```auto
truncate -s 50G /home/scott/pool2.img

```

Create a zfs pool from this raw file space:

```auto
sudo zpool create pool2 /home/scott/pool2.img -m none

```

Make this zfs pool a new storage pool on the LXD server and call it pool2.

```auto
lxc storage create pool2 zfs source=pool2

```

Show the list of zfs pools:

```auto
sudo zpool list

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/c907ceb6f467440a70a5a91906ab9887786e35b2.jpeg)

Before we can create containers in the new pool, we need to create a profile to use the pool:

```auto
lxc profile create pool2

```

Edit the new profile.

```auto
lxc profile edit pool2

```

Clear out all the lines in the file using the CTRL K command in the nano editor and then paste in the following lines:

```auto
config: {}
description: Pool2 LXD profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: pool2
    type: disk
name: pool2

```

Do a CTRL O and enter to save the file and a CTRL X to exit the nano editor.

Create a couple containers in pool2 using the following commands:

```auto
lxc launch ubuntu:22.04 container1 --profile pool2
lxc launch ubuntu:22.04 container2 --profile pool2

```

The command:

```auto
lxc list

```

will list all of your containers with no indication which pools they are in.

To get an idea of what is stored in pool2:

```auto
lxc storage volume list pool2

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/3657d2331722ce2fe705fc91972e9f6f2574a131.jpeg)

The “image” with the long name above is the Ubuntu 22.04 image downloaded from [linuxcontainers.org](http://linuxcontainers.org) used to create container1 and container2.

Volumes can be used just like an additional disk drive or storage space for LXD. We can create a custom volume in pool2 named volume1 with the following command:

```auto
lxc storage volume create pool2 volume1

```

You can list the contents of pool2 and you will now see volume1 has been added:

```auto
lxc storage volume list pool2

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/5387d01e4eb2e6e9ebb8b4a2c02028ad79091c11.jpeg)

We can attach this new volume to to container1 as a mount point named /volume1:

```auto
lxc storage volume attach pool2 volume1 container1 /volume1

```

We can move inside of the container:

```auto
lxc shell container1

```

We can list the storage in the container:

```auto
df

```

Below you will see that /volume1 is present.

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/a04ee610af7ef63d0269c1d621d0855b80d8028c.jpeg)

Notice in the following screen shot that you can move over to /volume1 and create a file inside it with the touch command:

![image](https://discussion.scottibyte.com/uploads/default/original/1X/7927cb8205ef218372b645160d86ec3a6cc0525e.png)

Exit the container1 shell to logout and return to your LXD server:

```auto
exit

```

Let’s attach container2 to volume1 as well:

```auto
lxc storage volume attach pool2 volume1 container2 /volume1

```

When you log into container2 as follows, you will see that the data in /volume1 is also accessible in container2 as shown below:

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/bac56c8d5166e0ea73d04e9ccf94d50503d45086.jpeg)

This is great for sharing data between multiple containers easily. Just note that no file locking is done. This means that your application will need to keep this in mind.

To detach volume2 from both containers:

```auto
lxc storage volume detach pool2 volume1 container1
lxc storage volume detach pool2 volume1 container2

```

To stop both containers:

```auto
lxc stop container1
lxc stop container2

```

We can delete both containers:

```auto
lxc delete container1
lxc delete container2

```

To delete volume1:

```auto
lxc storage volume delete pool2 volume1

```

Before you can delete a storage pool, you must delete everything using the storage pool. List the pool2 contents:

```auto
lxc storage volume list pool2

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/0fff2e820c4e36bc17c3f9fa07633686a0db4f01.jpeg)

Notice above that the Ubuntu image used to create the two containers is still in pool2.

Delete this image:

```auto
lxc image delete 9caf306128b249bc3e6fabf8f59925149dad56c13ebd06bff7bb06215c451c5b

```

If you list your pools:

```auto
lxc storage list

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/31839919529b5d2120502975068269ba6c0d5ee2.jpeg)

Notice that pool2 is still in use by one object in the screen shot above.

We have to delete the pool2 profile which is stored in pool2.

```auto
lxc profile delete pool2

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/bf4a6beaf14f3214a40a0866824e2983f28d882f.jpeg)

We can now delete pool2:

```auto
lxc storage delete pool2

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/66f830a613ff173056a8e499b61af79a0f175666.jpeg)

At this point, you can delete the virtual file since it has been removed as a zfs file system.

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/82a6ea73e22ce4b98b20e93602b77adfb6580ebf.png)  
 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/8bd25f8f09909947405b26c683575485f8ea1ea8.png)
