In Fangtooth 25.04 RC.1 you can create Incus VM Instances using external zvol.
This is a good way to migrate an existing VM into the Incus system, but you will be left with a dangling “root” 10GiB volume attached to your VM.
There is no harm in this, and it uses a trivial amount of space, but perhaps it annoys you and your would prefer to replace the root disk with the external zvol, and fully migrate your VM into the Incus ecosystem.
WARNING: Incus 6.0.3 LTS is prone to erasing existing zvols on failure whilst creating a VM, have a backup.
If you do not fully understand these instructions, and their consequences, do not follow these instructions
These instructions are provided for those who want to know how to do this correctly.
NOTE: You need to be su/root or use sudo with these commands.
Firstly, migrate your VM.
Secondly, you need to decide if you are going to “move”, “clone” or “copy” your existing zvol. Use replication if you want to “copy” the zvol, otherwise to clone use a snapshot/clone command, or the GUI.
Then, shutdown your VM.
incus stop <vm-name>
Locate your VM’s root disk,
This command will list all the VM disks on “<pool>”:
zfs list -r -t vol <pool>/.ix-virt/virtual-machines/
Your VM’s root disk will be called <pool>/.ix-virt/virtual-machines/<vm-name>.block
Here is an example:
root@chronus[~]# zfs list -r -t vol tank/.ix-virt/virtual-machines
NAME USED AVAIL REFER MOUNTPOINT
tank/.ix-virt/virtual-machines/dummy-vm.block 112K 48.6T 112K -
If you are cloning, or copying an existing zvol, then do that. Either way we will now “rename” the copy, clone, or the original into place. The zvol that we are renaming must be on the same pool as your incus virtual machine.
Rename the old VM root .block volume with
zfs rename <pool>/.ix-virt/virtual-machines/<vm-name>.block <pool>/.ix-virt/virtual-machines/<vm-name>.old-block
Next, rename your external vol into place
zfs rename <original-zvol-location> <pool>/.ix-virt/virtual-machines/<vm-name>.block
Here is an example:
root@chronus[~]# zfs rename tank/vms/dummy-vm-zvol tank/.ix-virt/virtual-machines/dummy-vm.block
root@chronus[~]# zfs list -r -t vol tank/.ix-virt/virtual-machines
NAME USED AVAIL REFER MOUNTPOINT
tank/.ix-virt/virtual-machines/dummy-vm.old-block 112K 48.6T 112K -
tank/.ix-virt/virtual-machines/dummy-vm.block 14.9M 48.6T 4.16G -
And then remove the old external reference to the zvol from the instance (if any)
incus config device remove <vm name> ix_virt_zvol_root
Then we need to apply Incus’ default volume properties to the new root volume:
zfs set volmode=none primarycache=metadata secondarycache=metadata <pool>/.ix-virt/virtual-machines/<vm-name>.block
Next we need to adjust the size of the root disk device config to match the actual root disk size.
Firstly get the new disks exact size,
zfs get -H -p -o value volsize <pool>/.ix-virt/virtual-machines/<vm-name>.block
Example:
root@chronus[~]# zfs get -H -p -o value volsize tank/.ix-virt/virtual-machines/dummy-vm.block
10737418240
Then to apply the correct size,
incus config device set <vm-name> root size=<size>
Example:
root@chronus[~]# incus config device set dummy-vm root size=10737418240
If you see “Error: Failed to update device “root”: Block volumes cannot be shrunk: Cannot be shrunk”, do not worry, this just means that your existing zvol was smaller than the original root disk, and can safely be ignored.
You should now be able to start your instance.
incus start <vm-name>
And you can destroy the .old-block volume now if you want
zfs destroy <pool>/.ix-virt/virtual-machines/<vm-name>.old-block
And now you should have replaced your VM’s existing root device with the secondary zvol, and that zvol is now located inside your Incus pool, as if it had been created there in the first place, and will correctly follow your VM as you copy/snapshot/migrate it