LKM - loop: loop device driver
Welcome to the tutorial guide. The guide will provide a user with advise and guidance on loop device driver. This information will let a user mount a filesystem that is stored in a regular file. That other file is called the backing file.
One use of this is to test an ISO 9660 filesystem before irreversibly burning it onto a CD. A user can build the filesystem in a 650 MB regular file. That file will be the input to the CD burning program, but a user should define a loopback device based on that file as backing file and then mount the filesystem right from the backing file.
It can also give a user a handy way to transmit collections of files over a network. It’s like a tar file, only a user don’t have to pack and unpack it – a user just mount the original file.
Some people use loop devices on a machine that sometimes runs Windows and sometimes runs Linux to allow them to maintain the Linux system via the Windows system: put a Linux root filesystem in a file in a FAT filesystem that Windows can access, then mount the Linux root filesystem via a loop device when Linux is running.
A user can keep the filesystem encrypted or compressed, or encoded in any arbitrary way, in the backing file. The loop device encodes (e.g. encrypts) as he/she write to it, and decodes (e.g. decrypts) as a user reads.
An encoding system is based on a “transfer function”. There are two transfer functions built into the loop module: the identify transfer function and a simple XOR encryption function. A separate kernel module can add any transfer function by calling the loop module’s exported loop_register_transfer() function.
There appear to be various modules floating around that provide transfer functions to do compression and encryption (DES, IDEA, Fish, etc.). Some of them appear to be part of current Linux kernel distributions. In addition, there appear to be various alternative loop device drivers, many of them also called loop, that have such transfer functions built in.
Please note that you do not confuse these loop devices with the “loopback device” used for network connections from the machine to itself. That isn’t actually a device at all - it’s a network interface.
A user can set up a loop device by issuing an ioctl to it to bind a file to it. The typical program to issue this ioctl is losetup. There are also options on the normal ‘mount’ command to do loop device setup under the covers, but because that confuses the logically separate operations of setting up a loop device and mounting a filesystem, for the sake of clarity you’re probably better off using losetup.
Please view this example:
modprobe loop
Module Parameters:
max_loop
Number of loop devices that will exist. Contrary to what its name suggests, the number that a user can specify is the number of loop devices that always exist. An existing device is not necessarily configured (bound to a backing file), though, so this number can be thought of as the maximum number of loop devices that you can configure.
The minor numbers for these loop devices are consecutive starting at 0.
If you followed advise and guidance as provided in this tutorial guide then you would have successfully learnt about the loop driver.













