How to remove LXD from my system


#1

I have tried LXD both installed from source and installed using snapd.

Snapd is ‘normally’ set up so that when one uses snap remove xxxxx that software is removed.
LXD is a ‘special’ snap as advised in these pages where LXD is given greater access to the underlying system for its particular needs. This also means that it is not possible to remove LXD using snap remove lxd. In trying this one is left with a number of directories what can’t even be removed by using rm -r (there is a system refusal resultant).
So how do I remove LXD (installed using snapd) from my system?
(Hopefully without having to do a M$ fix!!!)


Sudo snap remove lxd - removes LXD but does not remove the the group "lxd" in /etc/group/ - shouldn't it?
(Stéphane Graber) #2

The main issue with removing LXD is related to storage pools as those can cause a number of mounts that then misbehave when the snap is removed.

You should make sure to delete all containers, images, custom storage volumes and storage pools prior to removing the snap. I’d also recommend removing all networks for good measure.

With that done, the snap should remove cleanly.

We do have on our todo to add logic to the snap that will have it do that for you on package removal (not sure if snapd has implemented hooks for that yet though…).


#3

Thank you.

To make sure I have this correct - - - what I need to do is whilst still in lxd is to first kill lxdbr0 (and and other networking), then I would delete all the containers (this presently needs to done one at a time) and images. Then any storage volumes need to be removed and lastly all storage pools need to be removed. Then, and only then, can lxd be removed.

How does one remove the storage pools?
The storage pools are setup using lxd init but that ‘tool’ really doesn’t give any indication on how to remove any storage pool.


(Stéphane Graber) #4

Right, you’ll effectively want:

  • lxc list
  • lxc delete <whatever came from list>
  • lxc image list
  • lxc image delete <whatever came from list>
  • lxc network list
  • lxc network delete <whatever came from list>
  • echo ‘{“config”: {}}’ | lxc profile edit default
  • lxc storage volume list default
  • lxc storage volume delete default <whatever came from list>
  • lxc storage delete default

Effectively listing and the deleting all the objects until everything’s clean.


#5

Thank you for the complete list.

I’m assuming that after all the listed tasks are completed then it is safe to go apt remove snapd and apt purge snapd to complete the process.

Thanking you for your assistance.


(Stéphane Graber) #6

Yeah, once the LXD snap is properly removed, removing snapd should be fine.
I suspect snapd is supposed to cleanup all snaps on removal but I’m not sure I’d necessarily trust that to happen :slight_smile:


(Sachin) #7

Should we add the lxc profile list also to the list of things to be cleaned ?

The lxc list --format yaml is useful to do selective cleanup. Can we have the yaml format supported for all commands so that automated scripts can do the cleanup. Some of the commands don’t support the yaml output.


#8

erm, I just installed lxd on a Lubuntu 16.04 LTS VM with snap and it was only for a quick test, created a container, tested it, deleted it and the associated image, did a sudo snap remove lxd and no error, everything seems to have worked without a glitch. Under /var/snap there is only core, so it seems that no storage is left behind, lxdbr0 is gone too. Seems progress to me.


(Sachin) #9

Used the output from lxd init --dump. This file is in the YAML format and gives most of the information I wanted for cleanup.