Remove or restore LXD

I’ve been screwed up trying to remove LXD. It’v been installed through snap, then I tried to delete it through ubuntu software store (it gave no issue or messages) and then, when i’v spot that there is still /snap/lxd folder i’v tried to delete it. And only after could’t be able to delete some number-named folder i thought.
So now i deleted “current” folder from /snap/lxd and when try to launch lxc have the following:

~$ lxd.lxc
internal error, please report: running “lxd.lxc” failed: cannot find current revision for snap lxd: readlink /snap/lxd/current: no such file or directory

when try to delete lxd get next:

$ sudo snap remove lxd
error: cannot perform the following tasks: Save data of snap “lxd” in automatic snapshot set #9 (cannot create archive: tar: common/lxd/disks/default.img: file changed as we read it (and 2 more))

and trying to install it:

$ sudo snap install lxd
snap “lxd” is already installed, see ‘snap help refresh’

Is anyone can help me with my problem either delete lxd completely and then reinstall it from zero or somehow repair it. My experience with it only one day so i’m bit afraid of crush something irreversibly while trying it by myself farther (since i haven’t any valuable data/containers with this lxd the main aim to get lxd to “just installed” state rather then repair something existing)

I have become an expert at uninstalling and reinstalling. I have two scripts.
ls /var/snap/lxd/common/lxd/logs
snap remove lxd
snap remove lxc
apt remove -y lxd
apt autoremovesnap remove lxd
remove lxc
apt remove -y lxd
apt autoremove
zpool list
apt purge lxd
ls /var/snap/lxd/common/lxd/logs
dpkg --purge --force-all lxd
dpkg --reconfigure -a
zpool destroy local
apt-get remove --purge snapd
sudo rm -rf /snap
sudo rm -rf /var/snap
rm -vf /etc/systemd/snap-.mount
rm -vf /etc/systemd/snap-.service
rm -vf /etc/systemd/snap-*.service
ls /var/snap/lxd/common/lxd/logs

Run this one or two times, till you get nothing. Reboot.
ls /var/snap/lxd/common/lxd/logs
apt install snap
apt install snapd
snap install lxd
ls /var/snap/lxd/common/lxd/logs
lxd init
lxc version
lxc info
ls /var/snap/lxd/common/lxd/logs
lxc list

Run these on each machine… Do step one first. and then you can do step 2 on each machine at a time.
It is a little overkill but you want to get ride of all LXD completely.
Of course you lose all your data in containers.

Hope it works for you.

Thanks a lot for such a guide! I definitely don’t care about lxd while i can reinstall it from somewhere, but really it can’t be purge for sure without removing snap itself? If so - thank you once more and i’ll go get rid of everything that lay on the way to clear lxd


I wrote a post some time ago on this, However, the post is dated, I wrote it for LXD 2.0.

For your specific case, snap remove lxd should suffice. However, you get a weird error indicating that the LXD service is still running and probably misbehaving because some components have been removed.

Removing manually files from /snap/lxd is a big no-no. That is supposed to be a mounted read-only file system. I would try to shutdown lxd (systemctl stop lxd.service, etc) and then snap remove.

If you can give me some ideas on how to mess up LXD, I might write an updated article on cleaning up.

My experience says otherwise, and before this script, I was even told that the only way to get LXD going was to reinstall the Ubuntu. Did that several times. Running snap remove lxd alone wont clear everything… Of course anyone can try less first. But many time after you try it ends up telling you machine is still part of cluster. So to me it is safer to blow it all away and start over. On my servers I do not use Snap for anything other than LXD so it is easy for me to take it out and put back without affecting the rest of the Server.

thank for you advice but I wasn’t be able to shutdown the lxd if it was running. The systemctl stop says there is no such serveice, snap stops it successfully but it has no effect to the uninstallation attempt. So I do like Tony_ suggest and reinstall the snap. I’m not yet installed lxd (maybe in couple of days) and I will let you know how it’s doing if you have some interest.