I've recently been working on a project requiring encrypted files mounted via a connection to a loop device. While the project will run on an Ubuntu system, I was experimenting with setting it up on my Arch Linux workstation. That's when I noticed that Arch doesn't have any loop devices initialized by default, while all the Ubuntu systems I checked (ranging from 18.04 to 22.10) always have 8 pre-created loop devices. This kind of makes sense, since you need elevated privileges to run
losetup -f
On the other hand, the permissions on /dev/loopN don't allow ordinary users to use them anyway. But in any case I can't figure out who/what is creating these devices. I've looked over the udev rules in /lib/udev/rules.d, and couldn't find anything relevant. I also looked through the systemd service files in /lib/systemd/system and couldn't find anything there, either. This is mostly a curiosity question, as I hate magical events in my operating systems.
Here is the evidence that there are no snaps mounted on this system
root@texas-tea:~# ls /dev/loop*
/dev/loop0 /dev/loop2 /dev/loop4 /dev/loop6 /dev/loop-control
/dev/loop1 /dev/loop3 /dev/loop5 /dev/loop7
root@texas-tea:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238.5G 0 disk
├─sda1 8:1 0 714M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 237.8G 0 part
└─sda5_crypt 253:0 0 237.8G 0 crypt
├─vgtexas--tea-root 253:1 0 47.7G 0 lvm /
├─vgtexas--tea-swap_1 253:2 0 3.7G 0 lvm [SWAP]
├─vgtexas--tea-var 253:3 0 23.9G 0 lvm /var
├─vgtexas--tea-var+condor 253:4 0 952M 0 lvm /var/condor
├─vgtexas--tea-tmp 253:5 0 11.9G 0 lvm /tmp
└─vgtexas--tea-var+local 253:6 0 149.7G 0 lvm /var/local
sr0 11:0 1 1024M 0 rom
root@texas-tea:~# mount | grep loop
root@texas-tea:~#
root@texas-tea:~# losetup -l
root@texas-tea:~#
EDIT: I recently became aware that loop devices can be created as a compile time option or passed as a kernel parameter (see max_loop= here: https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html) Checking /etc/default/[grub|grub.d] I don't see anything related being passed as a kernel parameter on boot, so my current best guess is that the Ubuntu kernel compilers are setting BLK_DEV_LOOP_MIN_COUNT=8 in the build configuration.
losetup -a
doesn't show any of them being in use.% ls /dev/loop*
=>/dev/loop0 /dev/loop1 /dev/loop2 /dev/loop3 /dev/loop4 /dev/loop5 /dev/loop6 /dev/loop7 /dev/loop-control
and without snap installed. I'd guess this is just from theloop
module being loaded at all.