How to de-snap Xubuntu 22.10

Snap uses loopback devices for applications it installs. These can cause a device or resource busy error if loopback device is also used for encrypted container files due to conflict. To cut a long story short, I decided to completely de-snap Xubuntu. This involves complete removal of snap. Below are the steps done in a terminal window.

What occupies the loop0 device can be found out with:
$ sudo fdisk -l | grep "loop" <enter>

It displays:
Disk /dev/loop0: 4 KiB, 4096 bytes, 8 sectors
Disk /dev/loop1: 63.22 MiB, 66293760 bytes, 129480 sectors
Disk /dev/loop2: 63.28 MiB, 66355200 bytes, 129600 sectors
Disk /dev/loop3: 238.49 MiB, 250073088 bytes, 488424 sectors
Disk /dev/loop4: 240.61 MiB, 252301312 bytes, 492776 sectors
Disk /dev/loop5: 91.69 MiB, 96141312 bytes, 187776 sectors
Disk /dev/loop6: 346.33 MiB, 363151360 bytes, 709280 sectors
Disk /dev/loop7: 49.84 MiB, 52260864 bytes, 102072 sectors

Then further, it was found that snaps occupied those loopback devices:
$ losetup -a <enter>

/dev/loop1: []: (/var/lib/snapd/snaps/core20_1623.snap)
/dev/loop6: []: (/var/lib/snapd/snaps/gnome-3-38-2004_119.snap)
/dev/loop4: []: (/var/lib/snapd/snaps/firefox_2356.snap)
/dev/loop2: []: (/var/lib/snapd/snaps/core20_1822.snap)
/dev/loop0: []: (/var/lib/snapd/snaps/bare_5.snap)
/dev/loop7: []: (/var/lib/snapd/snaps/snapd_18357.snap)
/dev/loop5: []: (/var/lib/snapd/snaps/gtk-common-themes_1535.snap)
/dev/loop3: []: (/var/lib/snapd/snaps/firefox_1969.snap)

Disable Snap Services
$ sudo systemctl disable snapd.service <enter>
$ sudo systemctl disable snapd.socket <enter>
$ sudo systemctl disable snapd.seeded.service <enter>

$ sudo snap list --all <enter>
Lists all snap packages which were the list below.

bare 1.0 5
core20 20230126
snapd 2.58.2

To remove snap packages, use:
$ sudo snap remove --purge gnome-3-38-2004 <enter>
$ sudo snap remove --purge gtk-common-themes <enter>
$ sudo snap remove --purge bare <enter>
$ sudo snap remove --purge core20 <enter>
$ sudo snap remove --purge snapd <enter>

Remove snap daemon
$ sudo apt remove –autoremove snapd

To prevent snaps from coming back :-), do:
$ sudo mousepad /etc/apt/preferences.d/nosnap.pref <enter>
Add below lines to the above file
Package: snapd
Pin: release a=*
Pin-Priority: -10

Save the file.

Now run:
$ sudo apt-get update <enter>
$ sudo apt-get dist-upgrade <enter>

Now clear the leftover of snap in /var/cache and in the home directory
sudo rm -rf /var/cache/snapd/ <enter>
rm -rf ~/snap <enter>

This should now have no more snaps. Reboot and see if the loop devices are still there.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s