package snapd (not installed) failed to install/upgrade: installed snapd package post-removal script subprocess returned error exit status 1

Bug #1950634 reported by David Jericho
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
snapd (Ubuntu)
Fix Committed
Low
Alberto Mardegan

Bug Description

I had purged snapd, replaced firefox with the deb version, but had not yet replaced gnome-software with the deb version. Upon reboot, snapd tried to auto install again (bad Ubuntu, bad), and failed.

Please ensure the OS honours my request that it stays uninstalled, and if my I need to install gnome-software via the deb version, please inform me as such when I purge snapd.

ProblemType: Package
DistroRelease: Ubuntu 21.10
Package: snapd (not installed)
ProcVersionSignature: Ubuntu 5.13.0-21.21-generic 5.13.18
Uname: Linux 5.13.0-21-generic x86_64
NonfreeKernelModules: zfs zunicode zavl icp zcommon znvpair nvidia_modeset nvidia
ApportVersion: 2.20.11-0ubuntu71
AptOrdering:
 snapd:amd64: Purge
 NULL: ConfigurePending
 NULL: PurgePending
 NULL: ConfigurePending
Architecture: amd64
CasperMD5CheckResult: pass
Date: Thu Nov 11 20:42:27 2021
ErrorMessage: installed snapd package post-removal script subprocess returned error exit status 1
InstallationDate: Installed on 2021-11-10 (0 days ago)
InstallationMedia: Ubuntu 21.10 "Impish Indri" - Release amd64 (20211012)
Python3Details: /usr/bin/python3.9, Python 3.9.7, python3-minimal, 3.9.4-1build1
PythonDetails: N/A
RelatedPackageVersions:
 dpkg 1.20.9ubuntu2
 apt 2.3.9
SourcePackage: snapd
Title: package snapd (not installed) failed to install/upgrade: installed snapd package post-removal script subprocess returned error exit status 1
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
David Jericho (davidjericho) wrote :
Revision history for this message
Alberto Mardegan (mardy) wrote :

Hi David! I'm sorry to read that you had this bad experience. What is the current situation?

I see from the logs that the error occurred because the snapd post-removal script found that the /var/snap directory was in use. Can you please check what are its contents now (you could run `tree /var/snap` to find out, or just `find /var/snap`, if "tree" is not installed)?

Also please run these commands for me, and paste the results:
- ls /snap/
- ls /etc/systemd/system/snap*

Changed in snapd (Ubuntu):
status: New → Incomplete
Revision history for this message
David Jericho (davidjericho) wrote :

Hello,

/var/snap is entirely empty, although the directory is present.

With no snap now installed, /snap of course doesn't exist, however there are systemd units foe snap, linked to /dev/null

host:~/$ ls -al /etc/systemd/system/snapd*
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.apparmor.service -> /dev/null
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.autoimport.service -> /dev/null
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.core-fixup.service -> /dev/null
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.recovery-chooser-trigger.service -> /dev/null
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.seeded.service -> /dev/null
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.service -> /dev/null
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.snap-repair.timer -> /dev/null
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.socket -> /dev/null
lrwxrwxrwx 1 root root 9 Nov 11 20:42 /etc/systemd/system/snapd.system-shutdown.service -> /dev/null

I believe /var/snap may have been in use as I was logged into the graphical desktop environment at the time, and I was unaware that part of the desktop was a snap until I did some Googling.

Revision history for this message
Alberto Mardegan (mardy) wrote :

Thanks for the information, David. But is apt happy now, or is it still complaining about the snapd package state? What happens if you run "apt -f install"?

Revision history for this message
David Jericho (davidjericho) wrote :

Hi Alberto,

Apt is happy now, no warnings about packages or anything at this point. As noted, I did have to manually clean it up, and apt install gnome-software to repair the behaviour of the desktop trying to reinstall snapd.

Alberto Mardegan (mardy)
Changed in snapd (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Alberto Mardegan (mardy) wrote :

Thanks David!

(feel free to ignore the following: I'm just writing some notes here for my colleagues, as a starting point to fix the issue)

Indeed, out post-remove script (located in debian/snapd.postrm in the source tree) does

    echo "Final directory cleanup"
    for d in "/snap/bin" "/snap" "/var/snap"; do
        # Force remove due to directories for old revisions could still exist
        rm -rf "$d"
        if [ -d "$d" ]; then
            echo "Cannot remove directory $d"
        fi
    done

which leaves open the possibility of a failed "rm" causing the whole script to fail. The dpkg terminal log provided by David clearly show that this was the case:

```
Final directory cleanup
rm: cannot remove '/var/snap': Device or resource busy
dpkg: error processing package snapd (--purge):
 installed snapd package post-removal script subprocess returned error exit status 1
```

Since the error is logged anyway, I think we should not fail here and instead proceed no matter what.

Changed in snapd (Ubuntu):
importance: Undecided → Low
assignee: nobody → Alberto Mardegan (mardy)
Revision history for this message
Alberto Mardegan (mardy) wrote :
Changed in snapd (Ubuntu):
status: Confirmed → Fix Committed
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.