Mount disk images using losetup

I regularily mount disk images on some machine, but I always forget the sequence of commands. In Debian based distros, the losetup utility is part of the mount package which should be installed by default. Some GUI tools seem to have been developed, but they all seem badly maintained and/or packaged, so this is my preferred method.

To check what is the first usable loop device, run

losetup -f

After that, use the output of that command to link the disk image to the loop device file (using root privileges):

losetup -P /dev/loopX example.img

The -P flag searches through the image for partitions, which you need to mount.

After that, create the folder named example and run the command:

mount /dev/loopXpY example

The disk image should now be mounted in that directory. Depending on the Y variable, the right partition was mounted.