Error: Failed to remove symlink

I tried stopping an archlinux vm and it took forever to stop. So i lxc delete --force vm and it deleted alright. But trying to create the archlinux vm gives me the ‘rror: Failed instance creation: Failed creating instance record: Add instance info to the database: This “instances” entry already exists’ ERROR.

As I tried deleting the folders I also get 'Error: Failed to remove symlink “/var/snap/lxd/common/lxd/virtual-machines/archlinux”: remove /var/snap/lxd/common/lxd/virtual-machines/archlinux: directory not empty

Going into the subroot rot rm -rf the folder doesn’t work either. Any assistance would be much appreciated

Regards,
Jesse

What storage pool does this use?

dir

Does it show in lxc list?

Yes

And you’ve tried deleting it using lxc delete <instance> -f?

And get this error ‘Error: Failed to remove symlink “/var/snap/lxd/common/lxd/virtual-machines/archlinux”: remove /var/snap/lxd/common/lxd/virtual-machines/archlinux: directory not empty’

What does ls -la /var/snap/lxd/common/lxd/virtual-machines/archlinux show?

ls: cannot open directory ‘/var/snap/lxd/common/lxd/virtual-machines/archlinux’: Permission denied

Sorry sudo ls -la /var/snap/lxd/common/lxd/virtual-machines/archlinux

total 156
dr-x------ 3 root root 4096 Aug 15 16:55 .
drwx–x–x 3 root root 4096 Aug 15 20:02 …
-rw-r–r-- 1 root root 737 Aug 15 16:55 agent-client.crt
-rw------- 1 root root 288 Aug 15 16:55 agent-client.key
-rw-r–r-- 1 root root 769 Aug 15 16:55 agent.crt
-rw------- 1 root root 288 Aug 15 16:55 agent.key
dr-x------ 5 lxd root 4096 Aug 16 08:50 config
-rw-r–r-- 1 root root 131072 Aug 15 16:55 qemu.nvram

Any luck on a fix?

Have you rebooted to ensure that any mounts inside the snap namespace are cleared?

Yes I have, a couple of times

It’s still in my list in a ‘stopped’ state

Can you show sudo ls -la /var/snap/lxd/common/lxd/virtual-machines

total 16
drwx–x–x 3 root root 4096 Aug 15 20:02 .
drwx–x–x 17 root root 4096 Aug 18 08:09 …
dr-x------ 3 root root 4096 Aug 15 16:55 archlinux
lrwxrwxrwx 1 root root 70 Aug 15 10:43 ubuntu → /var/snap/lxd/common/lxd/storage-pools/default/virtual-machines/ubuntu

Yes so looks like the archlinux file isn’t a symlink but a directory?

Have you been doing anything “custom” with regards to mounting directories?

No

Hrm, well something very unusual has been going on outside of LXD as LXD never unpacks the image into /var/snap/lxd/common/lxd/virtual-machines and instead unpacks into /var/snap/lxd/common/lxd/storage-pools/<pool_name>/virtual-machines/<instance_name> and then creates a symlink to it
in /var/snap/lxd/common/lxd/virtual-machines/<instance_name>.

Normally the image unpack occurs before creating the symlink.

As we can see has happened for the ubuntu instance.

I can’t say what has been happening on your system, but I guess the only solution is to manually remove that directory now using: sudo rm -rvf /var/snap/lxd/common/lxd/virtual-machines/archlinux

You should then be able to do lxc delete <instance> to clear the database too.