Linux Loop Devices

Linux Loop Devices


This post was last updated on June 1st, 2020 at 07:00 pm

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).


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


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 ( 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.

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:

Previous Setting the Date and Time in Linux
Next SAMBA in Linux - Administration Checklist

About author

Sibananda Sahu
Sibananda Sahu 186 posts

A Linux Kernel Developer and a Firmware Developer by profession. Have worked with few big companies: BROADCOM Corporation, Cypress Semiconductor, LSI Corporation, TOSHIBA Corporation, Western Digital; on various cutting edge technologies and product lines, such as: RAID storage Driver, SSD Firmware, WLAN Firmware etc. Having more than 9 years of experience in Software Engineering domain. Now, took a pledge to educate all aspirant students to teach about Linux Kernel Development.

View all posts by this author →

You might also like

System Understanding 0 Comments

Understanding and Working with the MBR

This post was last updated on May 26th, 2020 at 09:50 pmStandard MBR functionality can be restored by adding proper boot code back into the MBR. This document will mostly

System Understanding 0 Comments

Drivers in Linux

This post was last updated on May 26th, 2020 at 10:43 pm Contents0.1 What to do with static drivers, module drivers, append=, and insmod.0.2 Drivers in Linux can take on

System Understanding 0 Comments

Digging into an initrd File

This post was last updated on May 27th, 2020 at 05:23 pm Please refer to rhdiskmod.html for complete information. That page will eventually replace this page. Contents1 Unpacking an initrd2


No Comments Yet!

You can be first to comment this post!

Leave a Reply