apt purge snapd fails in LXD (on amd64)

Bug #1878674 reported by Balint Reczey
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
snapd (Debian)
New
Unknown
snapd (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I have started an LXD container and tried removing snapd:
$ lxc launch ubuntu-daily:groovy snapd-postrm
Creating snapd-postrm
Starting snapd-postrm
$ lxc shell snapd-postrm
root@snapd-postrm:~# apt purge snapd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfreetype6 squashfs-tools
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  snapd*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 105 MB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 31149 files and directories currently installed.)
Removing snapd (2.44.3+20.04) ...
Stopping snap.lxd.activate.service
Stopping unit snap.lxd.activate.service
Waiting until unit snap.lxd.activate.service is stopped [attempt 1]
snap.lxd.activate.service is stopped.
Stopping snap.lxd.daemon.service
Stopping unit snap.lxd.daemon.service
Waiting until unit snap.lxd.daemon.service is stopped [attempt 1]
snap.lxd.daemon.service is stopped.
Stopping snap.lxd.daemon.unix.socket
Stopping unit snap.lxd.daemon.unix.socket
Waiting until unit snap.lxd.daemon.unix.socket is stopped [attempt 1]
snap.lxd.daemon.unix.socket is stopped.
dpkg: warning: while removing snapd, unable to remove directory '/snap': Device or resource busy - directory may be a mount point?
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
(Reading database ... 31079 files and directories currently installed.)
Purging configuration files for snapd (2.44.3+20.04) ...
Stopping snap.lxd.activate.service
Stopping unit snap.lxd.activate.service
Waiting until unit snap.lxd.activate.service is stopped [attempt 1]
snap.lxd.activate.service is stopped.
Removing snap.lxd.activate.service
Stopping snap.lxd.daemon.service
Stopping unit snap.lxd.daemon.service
Waiting until unit snap.lxd.daemon.service is stopped [attempt 1]
snap.lxd.daemon.service is stopped.
Removing snap.lxd.daemon.service
Stopping snap-core18-1754.mount
Stopping unit snap-core18-1754.mount
Waiting until unit snap-core18-1754.mount is stopped [attempt 1]
snap-core18-1754.mount is stopped.
Removing snap core18 and revision 1754
Removing snap-core18-1754.mount
Stopping snap-lxd-14954.mount
Stopping unit snap-lxd-14954.mount
Waiting until unit snap-lxd-14954.mount is stopped [attempt 1]
snap-lxd-14954.mount is stopped.
Removing snap lxd and revision 14954
Stopping unit snap.lxd.daemon.unix.socket
Waiting until unit snap.lxd.daemon.unix.socket is stopped [attempt 1]
snap.lxd.daemon.unix.socket is stopped.
Stopping unit snap.lxd.daemon.unix.socket
Waiting until unit snap.lxd.daemon.unix.socket is stopped [attempt 1]
snap.lxd.daemon.unix.socket is stopped.
Removing snap-lxd-14954.mount
Stopping snap-snapd-7264.mount
Stopping unit snap-snapd-7264.mount
Waiting until unit snap-snapd-7264.mount is stopped [attempt 1]
snap-snapd-7264.mount is stopped.
Removing snap snapd and revision 7264
Removing snap-snapd-7264.mount
Final directory cleanup
rm: cannot remove '/snap': Device or resource busy
dpkg: error processing package snapd (--purge):
 installed snapd package post-removal script subprocess returned error exit status 1
Errors were encountered while processing:
 snapd
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@snapd-postrm:~# echo $?
100

I noticed the failure first when building LXD autopkgtest backend images:

autopkgtest-build-lxd ubuntu-daily:groovy
...
Removing snap snapd and revision 7264
Removing snap-snapd-7264.mount
Final directory cleanup
rm: cannot remove '/snap': Device or resource busy
dpkg: error processing package snapd (--purge):
 installed snapd package post-removal script subprocess returned error exit status 1
...

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in snapd (Ubuntu):
status: New → Confirmed
Revision history for this message
Johan Ehnberg (johan-ehnberg) wrote :

I am seeing this as well. A workaround is to remove all snaps but core, then unmount the snap core before purging with apt.

Revision history for this message
Thiago Martins (martinx) wrote :

I can also confirm this too! Here is a list of problems that I'm seeing with snap inside LXD containers:

https://askubuntu.com/questions/1288779/the-snapd-package-fails-to-upgrade-inside-of-ubuntu-20-04-lxd-container

At first, "apt update ; apt full-upgrade" fails... Then, I thought, let's remove this `snapd` thing. Nop, doesn't work either!

Here is the error when I try `apt remove --purge snapd` inside of an LXD Container:

https://pastebin.com/TTj4Z4Jp

Johan, do you mind sharing how are you removing snapd out from your containers?

Thanks!

Revision history for this message
Johan Ehnberg (johan-ehnberg) wrote :

In our case we decided to spend the same effort on orchestrating for images:ubuntu/focal/cloud (which comes without snapd) rather than working around issues with snap on the thicker default image.

But the workaround above can be used, and I remember it was documented elsewhere on launchpad or maybe askubuntu. Going back on our git I can see the following (YMMV):

# Remove snapd
snap remove lxd
snap remove core18
snap remove snapd
umount /snap/
rm -rf ~/snap /snap /var/snap /var/lib/snapd
apt-get purge snapd

Revision history for this message
Thiago Martins (martinx) wrote :

Thanks Johan! But this procedure failed too.

I'll try the images without snapd!

But, currently, I'm using an image called just "focal", which comes with this creepy snapd. I can't find an image called "ubuntu/focal/cloud"...

Which source are you using for your images? I'm using "https://cloud-images.ubuntu.com/releases" simplestreams.

Thanks again!

Revision history for this message
Thiago Martins (martinx) wrote :

Never mind! Found it at https://images.linuxcontainers.org! No more snapd!! Wheee!!

Changed in snapd (Debian):
status: Unknown → New
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.