This document provides a step-by-step guide to create a ZFS storage pool for use with LXD. The process involves either using an existing disk/partition or creating a file-based ZFS pool if no dedicated disk is available. In Method 2, we will use the dd
command instead of truncate
or fallocate
to create the sparse file, as these commands may not be fully compatible with ZFS.
ZFS is a highly efficient and feature-rich file system that integrates seamlessly with LXD. It supports advanced features like snapshots, compression, deduplication, and data integrity checks. In this guide, we will create a ZFS storage pool for LXD using two methods:
dd
command (to ensure compatibility with ZFS).Before proceeding, ensure the following:
zfsutils-linux
package is installed.To install ZFS utilities:
sudo apt update
sudo apt install zfsutils-linux
Use the lsblk
or fdisk -l
command to identify the disk or partition you want to use for the ZFS pool. For example:
lsblk
Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 99.5G 0 part /
sdb 8:16 0 500G 0 disk
Here, /dev/sdb
is an unused disk that can be used for the ZFS pool.
Use the zpool
command to create the ZFS pool:
sudo zpool create pssb1avd001 /dev/sdb
Replace:
pssb1avd001
with your desired pool name./dev/sdb
with the actual disk or partition (e.g., /dev/sdb
).For example:
sudo zpool create pssb1avd001 /dev/sdb
Check the status of the ZFS pool:
sudo zpool status
Output:
pool: pssb1avd001
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
pssb1avd001 ONLINE 0 0 0
sdb ONLINE 0 0 0
Once the ZFS pool is created, configure it as an LXD storage pool:
lxc storage create pssb1avd001 zfs source=pssb1avd001
Replace:
pssb1avd001
with your desired LXD storage pool name.pssb1avd001
with the name of the ZFS pool.Verify the LXD storage pool:
lxc storage list
dd
If you don’t have a dedicated disk or partition, you can create a file-based ZFS pool. Instead of using truncate
or fallocate
, we will use the dd
command to create a properly formatted file for ZFS.
Use the dd
command to create a raw disk image file. For example, to create a 10GB file:
sudo dd if=/dev/zero of=/data3/lxc/pssb1avd001.img bs=1G count=10
Replace:
/data3/lxc/pssb1avd001.img
with the desired file path.bs=1G
specifies the block size (1GB).count=10
specifies the number of blocks (10 blocks = 10GB).For example:
sudo dd if=/dev/zero of=/var/lib/lxd/zfs.img bs=1G count=10
Use the zpool
command to create the ZFS pool using the disk image file:
sudo zpool create mc1apool01 /data3/lxc/pssb1avd001.img
Replace:
mc1apool01
with your desired ZFS pool name./data3/lxc/pssb1avd001.img
with the path to the disk image file.For example:
sudo zpool create mc1apool01 /var/lib/lxd/zfs.img
Check the status of the ZFS pool:
sudo zpool status
Output:
pool: mc1apool01
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
mc1apool01 ONLINE 0 0 0
/var/lib/lxd/zfs.img ONLINE 0 0 0
Configure the ZFS pool as an LXD storage pool:
lxc storage create pssb1avd001 zfs source=mc1apool01
Replace:
pssb1avd001
with your desired LXD storage pool name.mc1apool01
with the name of the ZFS pool.For example:
lxc storage create lxd_storage zfs source=mc1apool01
Verify the LXD storage pool:
lxc storage list
To improve performance and reduce disk usage, enable ZFS compression:
sudo zfs set compression=lz4 pssb1avd001
Replace pssb1avd001
with the name of your ZFS pool.
Issue: “Device already in use” error when creating the ZFS pool.
Issue: Insufficient disk space.
dd
or allocate more disk space.Issue: LXD storage pool creation fails.
By following this guide, you can successfully create a ZFS storage pool for LXD using either an existing disk/partition or a file-based approach. Using the dd
command ensures compatibility with ZFS and avoids issues associated with truncate
or fallocate
.