Get Virtualizor

Expanding the Limit of Loop Devices in Linux

While newer Linux kernels (2.4 and above) provide a simple method to increase loop device support by modifying the /etc/modules.conf file or using a boot parameter, older kernels (such as 2.2) had a limited default support for only 8 loop devices compiled into the kernel. Consequently, this default limit restricted the sharing of more than 8 CDs on a network. To surpass this limitation, it was necessary to make modifications to the kernel source code and perform a recompilation of the kernel.

Please use the following methods to determine the version of the kernel you are currently running.

bash# uname -a

or

bash# cat /proc/version

Customizing Loop Device Configuration in Linux

Modern kernels provide the flexibility to adjust the number of supported loop devices without requiring a kernel recompilation. One such method involves adding an options line to the /etc/modules.conf file. This approach is applicable if loop support is configured as a loadable kernel module, which is the default configuration in most major Linux distributions today. By modifying the /etc/modules.conf file, you can conveniently customize the loop device support without the need for kernel source code modifications or recompilation.

Open the /etc/modules.conf file and append the following line to make the necessary configuration changes.

options loop max_loop=64

Once you have made the aforementioned modification, you can either reboot your system to apply the changes or attempt to use the rmmod and insmod commands to dynamically apply the configuration without requiring a reboot. However, please note that if you currently have any loop devices mounted, you may encounter an error stating "loop: Device or resource busy," preventing the module from being unloaded. In such cases, it is recommended to unmount any active loop devices before attempting to use rmmod and insmod for seamless configuration update.

Note
In case you do not have an /etc/modules.conf file, it is possible that your module configuration file is named /etc/conf.modules (although this naming convention is now deprecated). 
Proceed to Creating Additional Loop Devices In /Dev Directory to continue with the instructions.

Modifying Boot Parameters for Loop Device Support

If loop support is compiled directly into the kernel rather than being loaded as a module, you can specify the desired number of loop devices to support by appending it to the Linux boot prompt.

boot:  linux max_loop=64

Alternatively, if you are using LILO as your bootloader, you can edit the Linux boot stanza in the /etc/lilo.conf file and add or modify the append= line accordingly. Here is an example stanza demonstrating the usage of append= (please remember to only add or modify the append line and not alter the entire stanza, as it may result in booting issues). For detailed information about LILO configuration, refer to the LILO mini-HOWTO available at http://www.linuxdoc.org/HOWTO/mini/LILO.html.

image=image=/boot/vmlinuz

label=linux
root=/dev/hdb5
initrd=/boot/initrd.img

append=" max_loop=64"

vga=788
read-only

Once you have made the necessary modifications to the /etc/lilo.conf file, it is essential to execute the lilo command in order for the changes to be applied and take effect.

bash# lilo

Added linux *
Added linux-nonfb
Added failsafe
Added windows
Added floppy

After restarting your system, you can verify your boot command line by entering the following command:

bash# cat /proc/cmdline
Note
We cannot confirm whether the loop module (compiled as a module), reads the /proc/cmdline file upon module loading, which implies that an options line in /etc/modules.conf may not be necessary. However, it is conceivable that the module can handle this behavior (and if it doesn't, it is recommended to do so). To sum up: I have not conducted any tests to verify this. 
Proceed to Creating Additional Loop Devices In /Dev Directory to continue with the instructions.

Adjusting Kernel Settings for Enhanced Loop Device Support

In case you are utilizing an older kernel version (such as 2.2) or if you possess a high level of proficiency in recompiling the kernel, it is possible to augment the number of supported loop devices by making modifications to the /usr/src/linux/drivers/block/loop.c file.

Note
If you discover that the kernel sources are not installed on your machine, it is advisable to refer to the documentation provided by your Linux Distribution for instructions on installing them. The Kernel Sources are typically included with all distributions as part of the GNU GPL licensing.

Modify the numerical value in the following line according to the desired number of loop devices you require.

#define MAX_LOOP 16

If you need assistance in getting started with compiling the new kernel or module, I recommend referring to the README file located at /usr/src/linux/README or consulting The Linux Kernel HOWTO for guidance.

Creating Additional Loop Devices in /dev Directory

It is recommended to verify the number of /dev entries available for loop devices

bash# ls -l /dev/loop*

You can utilize the mknod command to generate the necessary devices in the /dev directory for loop devices. The loop devices typically have a major number of "7", and the minor numbers begin at "0". For instance, if your MAX_LOOP value was defined as "8" in /usr/src/linux/drivers/block/loop.c, you should have devices named /dev/loop0 through /dev/loop7 already created. To create an additional device such as /dev/loop8, you can execute the following command, replacing both instances of "8" with the appropriate number for your specific requirement.

bash# mknod -m660 /dev/loop8 b 7 8

Verify the owner, group, and permissions of the newly created file by using the ls -l command. If needed, you can modify the owner and group using the following command:

bash# chown root.disk /dev/loop8

To modify the permissions of the file, you can utilize the following command:

bash# chmod 666 /dev/loop8
    Was this page helpful?
    Newsletter Subscription
    Subscribing you to the mailing list