How to Remove Incomplete or Broken Snap Installation of Nextcloud on Raspberry Pi

16.04raspberrypisnapubuntu-mate

First the caveat: I understand that this question involves Mate and a Raspberry Pi so if you consider it outside the realm of this forum just ignore it. But on the chance that it may be helpful or typical of something involving snaps or that platform, here goes.

I decided to try and install the nextcloud snap. It threw a ton of errors and seemed to freeze in the middle of the process (for over an hour). I killed it and just decided to try and remove it. The install looked like….

$ sudo snap install nextcloud
2016-06-24T08:48:29-04:00 ERROR cannot setup apparmor for snap "nextcloud": cannot load apparmor profile "snap.nextcloud.apache": cannot load apparmor profile: exit status 1
apparmor_parser output:
Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
Warning: unable to find a suitable fs in /proc/mounts, is it mounted?
Use --subdomainfs to override.

2016-06-24T08:53:29-04:00 ERROR cannot setup apparmor for snap "nextcloud": cannot load apparmor profile "snap.nextcloud.apache": cannot load apparmor profile: exit status 1
apparmor_parser output:
Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
Warning: unable to find a suitable fs in /proc/mounts, is it mounted?
Use --subdomainfs to override.

[|] Setup snap "nextcloud" security profiles

When I try snap remove nextcloud I get

error: cannot remove "nextcloud": snap "nextcloud" has changes in progress

What I would primarily like to do is properly remove the snap and recover the space from the partition it created. If partition is the correct term??

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0         7:0    0  46.6M  0 loop /snap/ubuntu-core/120
loop1         7:1    0 113.9M  0 loop /snap/nextcloud/12
mmcblk0     179:0    0  14.9G  0 disk
├─mmcblk0p1 179:1    0    64M  0 part /boot
└─mmcblk0p2 179:2    0  14.8G  0 part /

I tried

snap abort nextcloud

and got

error: cannot find change with id "nextcloud"

I should also note that it doesn't show up as installed as I get only the following

$ snap list
Name Version Rev Developer Notes
ubuntu-core 16.04+20160531.12-01 120 canonical –

Though it does show up in….

$ snap interfaces
:network nextcloud
:network-bind nextcloud

I tried

$ snap changes
ID   Status  Spawn                 Ready  Summary
1    Doing   2016-06-24T12:39:20Z  -      Install "nextcloud" snap

$ sudo snap abort 1

$ snap changes
ID   Status  Spawn                 Ready  Summary
1    Abort   2016-06-24T12:39:20Z  -      Install "nextcloud" snap

But the partition is still there.

** Update, I ran the entire process again for debugging purposes and just let it sit after the "snap abort 1" command. At some point something seems to have completed in the background because lsblk shows nothing and the snap interfaces query shows nothing.

Best Answer

The snap command is actually made up of two components, server and client. You're interacting with the client. When you cancelled the install operation on the client side that's the only place you cancelled it-- the client. So it stopped showing you that it was installing, but it was still installing (this is a bug). (Update: This bug was fixed in snapd v2.20.1.)

On the server side, all of this stuff is happening in "changes." You can read more about them here, but for your purposes, you want to just abort this specific change. To do that, run:

$ snap changes
<snip>
203  Doing   2016-06-24T12:17:45Z  -  Install "nextcloud" snap

Note the ID, 203, and the fact that it's "Doing" it right now. To abort that operation, you use the change ID:

$ sudo snap abort 203

And the change should stop. However, I must say that the fact that the change froze partway through does not bode well for your ability to abort it. If it doesn't work, perhaps try rebooting. If that still doesn't seem to have fixed it and you're okay losing all your snaps and their data, you can completely reset the snapd state with this script.

Related Question