How to remove LXD from my system

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!!!)

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…).

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.

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.

2 Likes

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.

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:

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.

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.

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

@stgaber
Hi, I cannot do the last step.
My pool is called “zfspool1” but I cannot remove it because it is referenced in the default profile and I cannot remove the default profile

mirto@mirto-P65:~$ sudo lxc profile show default
config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: zfspool1
    type: disk
name: default
used_by: []
mirto@mirto-P65:~$
mirto@mirto-P65:~$ sudo lxc storage delete zfspool1
Error: Storage pool "zfspool1" has profiles using it:
default
mirto@mirto-P65:~$ sudo lxc profile delete default
Error: The 'default' profile cannot be deleted
mirto@mirto-P65:~$ 

Also I cannot change the pool: value using a non existent pool

What can I do?

delete the pool: value ?

I mean: change the default profile from line

pool: zfspool1

to line

pool: xxx

xxx is a non existent pool so when I try to save the default profile
I receive the error

mirto@mirto-P65:/etc/init.d$ sudo lxc profile edit default
[sudo] password di mirto: 
Config parsing error: The "xxx" storage pool doesn't exist
Press enter to open the editor again

and you can exit only issuing a ^C so the profile is not changed.

I mean: delete the pool value. lxc profile edit default, delete root, save.

Thanks it worked: pool accept an empty value

mirto@mirto-P65:/etc/init.d$ sudo lxc profile edit default
[sudo] password di mirto: 
mirto@mirto-P65:/etc/init.d$ sudo lxc profile show default
config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: ""
    type: disk
name: default
used_by: []
mirto@mirto-P65:/etc/init.d$ sudo lxc storage volume list zfspool1
+------+------+-------------+---------+
| TYPE | NAME | DESCRIZIONE | USED BY |
+------+------+-------------+---------+
mirto@mirto-P65:/etc/init.d$ sudo lxc storage delete zfspool1
Storage pool zfspool1 deleted
mirto@mirto-P65:/etc/init.d$

I completed the last steps.
So I suppose that now I can remove lxd.

Also to note for those using the BTFRS file system. You will want to delete the sub volumes nested under the created storage volume. You most likely won’t be able to delete the storage volume prior to doing this.

To view volumes you can use:

btfrs subvolume list /var/lib/storage-pools/[STORAGE NAME]

To simply delete everything, I’d recommend

btfrs subvolume delete /var/lib/storage-pools/[STORAGE NAME]/*
btfrs subvolume delete /var/lib/storage-pools/[STORAGE NAME]