Add snapshot function for LXC containers created by Incus

Problem/Justification
I noticed that the LXC system container created by Incus seems to be placed in the .ix-virt/containers directory, which makes it impossible for users to access the container storage path and perform snapshot operations through the Dataset Page. Furthermore, LXC VMs created with Incus completely lose the protection of snapshots.

Impact
Previously, when using the KVM backend, users could only store virtual machine data through zfs zvol. Sincezfs zvol does not allow shrinking, this resulted in a lot of space waste.

Incus provides two mature ways to implement snapshots, one based on zfs dataset and the other based on zfs zvol, but TrueNAS does not currently provide these features. Please refer to:

These are all direct functions provided by Incus, which means they can be implemented at a very low development cost.

In addition, Incus in 25.04 RC.1 provides an instance-based mounting function, which does not seem to be implemented based on Incus Storage Drivers, but is similar to Docker’s path mapping function, and does not allow mounting the root directory.

User Story
There are two ways to achieve this:

  • Use a method similar to ixVolumes to manage snapshots of Incus LXC containers through a separate WebUI, which requires more development and is not flexible. At least I prefer to manage the Dataset after mapping the path through the Host Path, although this may create some security risks.

  • Add an option to the instance creation page to mount the root path of the LXC container to the zfs dataset or zfs zvol function, and then manage it manually through the Dataset Page.

2 Likes

Snapshots are a major functionality of Incus / LXC.
I do hope that TrueNAS will add proper support before the official 25.04 release.

If we’re talking about a thinly allocated ZVOL not being able to be TRIMmed by a VM, it actually has supported that for a long time now. It was TrueNAS that was lagging behind, but even they added that support a while back.

Maybe I am misinterpreting what you’re saying, but if you create a VM in e.g. Truenas Scale Electric Eel with a thinly allocated ZVOL and install Linux in there, enable TRIM (or discard, in Linux parlance) the actual space used by the ZVOL will shrink and grow just fine with the data contained in it.

1 Like

Pretty sure you can actually shrink a zvol. UI protects you from doing it as any data off the end is lost.

If you re-arrange the data, then it works.

1 Like