Sudo snap remove lxd - removes LXD but does not remove the the group "lxd" in /etc/group/ - shouldn't it?

Using Ubuntu 18.04
LXD v 3.6

Using SNAP LXD if I install LXD then create a container cn1 …

sudo snap install lxd
sudo lxd init

then

lxc launch ubuntu cn1
lxc exec cn1 bash
adduser someID

Sometime later if I use SNAP to remove LXD

sudo snap remove lxd

it does remove LXD but … but in /etc/group in the HOST it doesn’t remove the LXD “group” also.

Shouldn’t it ?

1 Like

In my trying to achieve exactly what you are asking about a method was given. It is NOT ‘simple’.
See: How to remove LXD from my system

Hi Brian!

It’s a common practice in the packaging of applications in Linux to keep any groups that were created.
Let’s check mysql-server.

$ lxc launch ubuntu:18.04 mycontainer
$ lxc ubuntu mycontainer
ubuntu@mycontainer:~$ sudo apt update
ubuntu@mycontainer:~$ grep mysql /etc/group
ubuntu@mycontainer:~$ sudo apt install mysql-server -y
ubuntu@mycontainer:~$ grep mysql /etc/group
mysql:x:115:
ubuntu@mycontainer:~$ sudo apt remove --purge mysql-server -y
ubuntu@mycontainer:~$ sudo apt remove autoremove -y
ubuntu@mycontainer:~$ grep mysql /etc/group
mysql:x:115:
ubuntu@mycontainer:~$

Oh, oh. The mysql group is still there.

So, why does that happen? Because when a group is created, it might be used by users.
It is not in the purview of the package to deal with group membership and removing users from groups.
When a group gets created, stays created.

@simos & @dabeegmon

thanks …

I guess I was puzzled why the lxd “group” would be left to exist when lxd itself no longer exists on the system that group would have no more purpose? oh, well :slight_smile:

@simos and @dabeegmon

To help with accomplishing what Stephane recommended for completely removing SNAP LXD from a system I found this:

It would seem to accomplish at least the 1st Four steps Stephane recommended?

Right, you’ll effectively want:

  1. lxc list
  2. lxc delete <whatever came from list>
  3. lxc image list
  4. lxc image delete <whatever came from list>
  5. lxc network list
  6. lxc network delete <whatever came from list>
  7. echo ‘{“config”: {}}’ | lxc profile edit default
  8. lxc storage volume list default
  9. lxc storage volume delete default <whatever came from list>
  10. lxc storage delete default

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

I’ve not tried this python3 script yet but am setting up a VM that I can install SNAP LXD in, create a bunch of containers with some in the RUN state and others in the STOPPED state and will try it out.

If it works it could be a real time saver if you have dozens or hundreds of containers leaving just steps 5-10 to do?

That’s normal, most packages that create groups also don’t remove them.

That’s because you may have filesystem paths or other resources that belong to this group and removing the group from the list would then just cause them to be owned by a numeric gid instead. It would then become a problem when installing another package as that package would get the gid which was used by the previous group, effectively granting access to that piece of software to anything which was leftover from the previous one.

I created an Ubuntu 18.04 KVM VM and in that created 40 Ubuntu 18.04 LXD containers using SNAP LXD.

I left 1/2 running and 1/2 stopped.

Then I ran iihaan’s lxd-delete-containers python script using the 2 command options:

To Delete all containers: ./delete_all_lxd_containers.py -c
To Delete all images: ./delete_all_lxd_containers.py -i

And in just a minute or two all was deleted.

The only thing I had left to do was steps 7-10.

Which wasn’t as bad as I was thinking it might be.

So it looks like this works okay for a big part of the job of deleting/removing SNAP LXD cleanly.