Attempt to cp an existing VM results in error

I have an existing LXD VM called “win11”.
Recently I had NO problem making a copy named “win11-demo”

I’d deleted the VM “win11-demo” a few days ago but now if I try to re-create it
using "$ lxc cp win11 win11-demo it now fails?

See below…

$ lxc ls
±-----------------±--------------±--------±-------±-----------------------------±-------------------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±-----------------±--------------±--------±-------±-----------------------------±------------------+
| ubuntu-vm | STOPPED | | | VIRTUAL-MACHINE | 0 |
±-----------------±--------------±--------±-------±-----------------------------±------------------+
| win11 | STOPPED | | | VIRTUAL-MACHINE | 0 |
±-----------------±--------------±--------±-------±-----------------------------±------------------+

$ lxc cp win11 win11-demo
Error: Create instance from copy: Cannot create volume, already exists on target storage

Any suggestion on how to fix this?

The $ lxc ls no longer lists “win11-demo” (see above) so why this error above?

thanks for any hints on how to resolve

The error suggests that the storage volume on the disk itself is still present.

What storage driver are you using?

All the drives on this machine are BTRFS

What does this show:

ls /var/snap/lxd/common/lxd/storage-pools/<pool>/virtual-machines -la

That directory is “empty”

$ lxc storage list
±-----------------±-------±-------------------------------------±------------±--------±--------+
| NAME | DRIVER | SOURCE | DESCRIPTION | USED BY | STATE |
±-----------------±-------±-------------------------------------±------------±--------±--------+
| lxd-storage-pool | btrfs | dc4358a7-6db1-4ab7-85c8-4e9e85d15ee4 | | 6 | CREATED |
±-----------------±-------±-------------------------------------±------------±--------±--------+

$ sudo su
ls -la /var/snap/lxd/common/lxd/storage-pools/lxd-storage-pool
drwx–x–x 1 root root 0 Mar 25 09:25 .
drwx–x–x 1 root root 32 Mar 25 09:25 …

And I do have 2 VMs currently stopped that are on that pool…

# lxc ls
±----------±--------±-----±-----±----------------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±----------±--------±-----±-----±----------------±----------+
| ubuntu-vm | STOPPED | | | VIRTUAL-MACHINE | 0 |
±----------±--------±-----±-----±----------------±----------+
| win11 | STOPPED | | | VIRTUAL-MACHINE | 0 |
±----------±--------±-----±-----±----------------±----------+

Try this:

sudo nsenter --mount=/run/snapd/ns/lxd.mnt -- ls -la /var/snap/lxd/common/lxd/storage-pools/lxd-storage-pool

# sudo nsenter --mount=/run/snapd/ns/lxd.mnt – ls -la /var/snap/lxd/common/lxd/storage-pools/lxd-storage-pool

total 16
drwxr-xr-x 1 root root 214 Mar 25 09:25 .
drwx–x–x 1 root root 32 Mar 25 09:25 …
drwx–x–x 1 root root 0 Mar 25 09:25 buckets
drwx–x–x 1 root root 36 Apr 30 19:41 containers
drwx–x–x 1 root root 0 Mar 25 09:25 containers-snapshots
drwx–x–x 1 root root 0 Mar 25 09:25 custom
drwx–x–x 1 root root 0 Mar 25 09:25 custom-snapshots
drwx–x–x 1 root root 512 Apr 30 19:37 images
drwx–x–x 1 root root 60 Apr 30 20:28 virtual-machines
drwx–x–x 1 root root 0 Mar 26 10:58 virtual-machines-snapshots

We need to see inside the virtual-machines directory.

sudo nsenter --mount=/run/snapd/ns/lxd.mnt – ls -la /var/snap/lxd/common/lxd/storage-pools/lxd-storage-pool/virtual-machines

Sorry Tom, (its pretty early here)
I was entering your previous commands verbatum but on this machine lxd snap is installed on Ubuntu 22.04 on - /dev/nvme0n1p4

but using…

$ lxd init

the “lxd-storage-pool” was configured on /dev/sda1 mounted on /mnt/lxd-storage-pool


So rerunning:

# ls /mnt/lxd-storage-pool/virtual-machines -la
total 16
drwx–x–x 1 root root 60 Apr 30 20:28 .
drwxr-xr-x 1 root root 214 Mar 25 09:25 …
d–x------ 1 root root 252 Apr 4 10:10 ubuntu
d–x------ 1 root root 252 Mar 25 09:40 ubuntu-vm
d–x------ 1 root root 234 Mar 25 09:30 win11
d–x------ 1 root root 234 Mar 25 09:30 win11-demo

The above does still show a win11-demo directory

/mnt/lxd-storage-pool/virtual-machines/win11-demo# ls -la
total 20326064
d–x------ 1 root root 234 Mar 25 09:30 .
drwx–x–x 1 root root 60 Apr 30 20:28 …
-rw-r–r-- 1 root root 656 Mar 25 09:30 agent-client.crt
-rw------- 1 root root 288 Mar 25 09:30 agent-client.key
-rw-r–r-- 1 root root 688 Mar 25 09:30 agent.crt
-rw------- 1 root root 288 Mar 25 09:30 agent.key
-r-------- 1 root root 2219 Apr 17 16:34 backup.yaml
dr-x------ 1 lxd root 188 Apr 17 16:34 config
-rw-r–r-- 1 root root 91 Mar 23 22:02 metadata.yaml
-rw------- 1 lxd root 540672 Apr 17 16:34 OVMF_VARS.4MB.ms.fd
lrwxrwxrwx 1 root root 19 Mar 25 09:30 qemu.nvram → OVMF_VARS.4MB.ms.fd
-rw-r–r-- 1 root root 59055800320 Apr 17 16:34 root.img

OK so its still there indeed. We needed to switch into the LXD snap’s mount namespace to see it because its mounted there from /mnt/lxd-storage-pool/.

Suggest trying to removing it and then copying again.

Thanks…
Yes, that fixed it.

But makes me wonder why that directory wasn’t deleted when I originally deleted the win11-demo vm?

I’m not sure what happened. If you can get a reproducer and log a bug we can hopefully prevent it happening in the future.