Linux Loop Devices
Updated December 13, 2000
Created Dec 13, 2000

By default you have 8 loop devices (loop0 - loop7). You can extend this number up to 255 (maybe even 256, I haven't tested it that high).

Preparation:

Have the kernel source tree installed along with all the other development packages needed in order to build a kernel. This may be done by just redoing the loop.o module; however, I don't have instructions on doing that so I will show you the method I know. If you need to know what packages you need to have installed, then check http://www.cpqlinux.com/kernel.html.

Steps:

Edit /usr/src/linux/drivers/block/loop.c
Find the line that says:
#define MAX_LOOP 8

Leave the line exactly as is (with the # sign in front) and only change the 8 to a 255. The new line would look like:
#define MAX_LOOP 255

Save the file and exit from the editor.

Now when you build this as a module you will now have the ability to use more loop devices.

Build the module. The only way I know to get everything to build right is to go through the whole kernel build routine (http://www.cpqlinux.com/kernel.html). Once you build the module and kernel and put them into place and run /sbin/lilo, then you are ready to add device nodes.

Device nodes are required to access the loop devices. You already have loop0 - loop7. You can run the following loop to create the rest of the nodes (loop8 - loop255). You can type all of the following lines of code on one single line if you leave off the trailing "\" characters.
   C=8; echo; echo "Creating loop device nodes."; \
   while [ $C -lt 256 ]; do mknod /dev/loop$C b 7 $C; \
   echo -n .; C=`expr $C + 1`; done; echo;
Note: the quoting around the expr section are called backtick's and they are located with the tilde character ("~") in the upper left hand corner of the keyboard. The character is not a single quote.

Now once you have rebooted and loaded the new kernel and loop.o module, and created your device nodes, you are ready to use more than 8 loop devices.

Example:
mount -t iso9660 /tmp/rh61.iso /mnt/rh61 -o loop
mount -t vfat /tmp/boot.img /mnt/boot -o loop
mount -t iso9660 /home/ftp/pub/RedHat70/disk1.iso
/home/ftp/pub/RedHat70/disk1 -o loop
...
Now you don't have to stop when you get to your old limit of 8.

More info:
There is a soft limit that will get in the way. The following script will show this to you:

Script for testing maximum number of loop devices you can get on a Linux server:
scripts/maxloop_sh.txt



Homepage: http://www.cpqlinux.com












1