61

As of Ubuntu 18.04 running lsblk shows 16 snap loops (2-3 times for each snap). The question is, why are they being listed as results for lsblk, fdisf-l, and blkid?

It creates a lot of clutter from the actual disks drive partitions I need to see, namely /dev/ partitions. I know a purported duplicate of this question exists, but it only asks why three loops are being listed per snap. I want to know why these snaps are being listed in the first place, and the purported duplicate does not answer this (perhaps those marking this as duplicate could help me by explaining why it is a duplicate). Technically, they qualify as file systems (which I neither created nor asked for), but they are getting in the way of the information output for the /dev/ partitions I am interested in. This becomes a problem when fdisk -l outputs a three page+ list filled mainly with snaps.

The output of a recent (1 week old) Ubuntu install and I have not installed any snaps:

$ lsblk  
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT  
loop0    7:0    0  14.5M  1 loop /snap/gnome-logs/37  
loop1    7:1    0   2.3M  1 loop /snap/gnome-calculator/170  
loop2    7:2    0  86.6M  1 loop /snap/core/4486  
loop3    7:3    0  86.6M  1 loop /snap/core/4650  
loop4    7:4    0   1.6M  1 loop /snap/gnome-calculator/154  
loop5    7:5    0  14.5M  1 loop /snap/gnome-logs/34  
loop6    7:6    0   3.3M  1 loop /snap/gnome-system-monitor/36  
loop7    7:7    0   2.3M  1 loop /snap/gnome-calculator/178  
loop8    7:8    0    13M  1 loop /snap/gnome-characters/101  
loop9    7:9    0   3.7M  1 loop /snap/gnome-system-monitor/45  
loop10   7:10   0 139.5M  1 loop /snap/gnome-3-26-1604/64  
loop11   7:11   0   140M  1 loop /snap/gnome-3-26-1604/59   
loop12   7:12   0   3.7M  1 loop /snap/gnome-system-monitor/41  
loop13   7:13   0    21M  1 loop /snap/gnome-logs/25  
loop14   7:14   0  12.2M  1 loop /snap/gnome-characters/69  
loop15   7:15   0    13M  1 loop /snap/gnome-characters/96  
sda      8:0    0 298.1G  0 disk  
├─sda1   8:1    0   512M  0 part /boot/efi  
└─sda2   8:2    0 297.6G  0 part /  
sr0     11:0    1  1024M  0 rom  

(supplemental screen capture of above text):
screenshot.jpg

My snap list shows 6 results:

core
gnome-3-26-1604
gnome-calculator
gnome-characters
gnome-logs
gnome-system-monitor

Meanwhile, gnome-disk-utility shows nothing at all for snaps, only showing my HDD and optical drive.

It won't be very efficient if every installed snap gets listed as a block device (2-3 times each to add). Should I expect future updates to deal with this?

Edit:
fdisk-l also dumps out a very long list with 16 instances of these "disk loops" (Disk /dev/loop0, Disk /dev/loop1, etc., each with details which I won't show here because it's too long). This can't be intended behaviour, can it?
blkid also lists 16 loops, as TYPE="squashfs". At least parted -l works as expected, only outing my actual disk partitions.

I just tested this, and installing more snaps does add more to the lsblk output. Therefore, fdisk, lsblk, blkid could have potentially huge output lists, according to the number of snaps available, and installed.

2

6 Answers 6

25

When you type the command

snap list 

you will get the output of actual installed snap packages. The reason is when a snap package is updated, the old version is kept (see snapcraft docu).

Cited from snapcraft document

Garbage collection then removes and purges any snap files, and their writable areas, for snap versions prior to the one that has just been updated — meaning that, at most, two versions of a snap will be present on the system. This saves disk space without compromising the ability to revert the snap to a previous known-good state.

Explicitly removing a snap from your system will also remove the code and purge the data for all prior versions.

For instance you have got installed more than one versions of gnome-calculator.

In case you only need the newest version, you can use

sudo snap remove gnome-calculator --revision <version to be placed>

Using the command

losetup -a 

shows you the mounted snaps (loop devices)

If you want to delete the double ones, type

sudo losetup -d /dev/loop<loopnumber>

It seems to be an error of the snap code, since all older been kept in the /var/lib/snapd/snaps file.

3
  • 3
    sudo: remove: command not found and losetup -d changes nothing.
    – jordy
    Jun 27, 2018 at 12:45
  • 4
    The correct code is sudo snap remove not sudo remove. Please revise your answer.
    – jordy
    Jun 27, 2018 at 13:10
  • this do not remove definetively, next boot they are there Sep 23, 2023 at 0:28
16

You can use the -e7 flag to lsblk to exclude loopback devices which is short and easy to type (if maybe not easy to remember)

lsblk -e7
2
  • And for the very lazy ones: add this to your ~/.bash_aliases (or whatever your default shell is): alias lsblk=lsblk -e 7.
    – Jens
    Dec 18, 2020 at 14:51
  • the problem I believe is mounting duplicated software, this masks the real problem. Sep 23, 2023 at 0:31
15

From the content in your question, your problem is about searching for a way to have control over what you're seeing when you try to view your block devices than how snap uses block devices for its operation.

I agree with your referenced distinction between fdisk -l and parted -l. While fdisk shows a very good detailed output of block devices, it shows too many other things that distract from what you're trying to see.

Resolution

You can use filter the lsblk formatted output. This works well to give a clean output like what you get with gnome-disk-utility.

$ lsblk -o name,mountpoint,label,size,fstype,uuid | egrep -v "^loop"

Or as you indicated in your question:

$ sudo parted -l

For the df command in your question, use:

$ df | egrep -v /dev/loop
4
  • 6
    I was waiting a long time for someone to suggest exactly this, a filtered output for lsblk (rather than all those comments defending the excessive output as normal and good). I would like to avoid having to do this, however, just because plain and straight lsblk was quick, easy to remember, and it worked beautifully, before snap interfered with it. I want it back as it was. Hopefully, the excessive output is just a bug that will get fixed.
    – jordy
    Jun 22, 2018 at 9:36
  • 4
    @danthonyd Thanks for the acknowledgment. I was sure I understood the question and felt certain it deserved a spot in the AU database of information for consideration and answering. This is something I've been concerned about for a long time. However, the problem isn't Snap. The problem is with the fdisk developers. They should add a method to filter out real devices over the pseudo devices to remove the excessive output and make their application more manageable, like the Gnome-disk-utility. No one would be using fdisk to manage their loop devices. (continued)... Jun 22, 2018 at 10:31
  • 4
    ... (continued) They don't even need to see it in the the fdisk output. That is what losetup and other pseudo application commands are for. So why bother showing it, if you can't manage it with the tool. This flaw in the fdisk design is making apps like parted and lsblk more popular and user friendly. Jun 22, 2018 at 10:34
  • 1
    Thank you. I'm adding | egrep -v "^loop" to all my 16.04 lsblk scripts today to reduce maintenance on the day I convert to 18.04. (FYI I had already up-voted your answer before today) Oct 21, 2018 at 15:32
3

If you use the snap version of the system monitor, then you will see all file systems used by snap as well as the ones you use.

An easy "fix" is to uninstall Gnome System Monitor from the app store. It is the snap-version.

Then install Gnome System Monitor from the normal repositories using Synaptic package manager. It is the normal version that installs a bunch of files all over you root partition. Nice!

And you will see just what you expect to see when you launch Gnome System Monitor...

1
  • 1
    Great! This is what I was looking for. The commands are snap remove gnome-system-monitor (no sudo required), followed by sudo apt install gnome-system-monitor (this time with sudo).
    – PerlDuck
    Nov 17, 2018 at 19:06
2

I realize this is an older question but since it was near the top of the search results when googling for why blkid / fdisk -l generate lots of "loop" entries, I figured I'd share for the next guy/gal.

One option that might work (depending on your requirements) is simply removing snapd. On Linux Mint 19.3 (Ubuntu 18.04 base), snapd is not installed by default and is thus not required. To my understanding, Ubuntu 18.04 is different in that snapd is included out-of-the-box. Under Mint 19.3, installing snapd generates the same "loop" entries in fdisk -l and blkid and running sudo apt purge snapd gets rid of them.

I have NOT tested this under Ubuntu 18.04 specifically, but assuming that nothing critical would be impacted by removing snapd, then this may be a viable option if you don't actually use snap as a user.

I don't think removing snapd will break anything critical in Ubuntu based on 1, 2 but I did see a note here that you might need to reinstall some default Ubuntu packages that were installed as snaps (sudo apt install gnome-software gnome-calculator gnome-logs gnome-characters gnome-system-monitor). I am not sure if this is a complete list / what default packages would be needed under MATE/KDE/xfce/etc. To verify this, I would highly recommend testing in a virtual machine unless you don't care about reinstalling in the event something goes wrong.

For Mint 19, I can confirm uninstalling snapd gets rid of the "loop" entries in fdisk -l , blkid , mount , and probably other commands.

1

To only show mounts excluding loopback you could also simply:

lsblk -af |grep -sv loop

;)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .