Linux Loop Devices

Linux Loop Devices


This post was last updated on November 3rd, 2020 at 06:14 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 Kernel compilation guide.


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 (Linux kernel build guide). 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

shibaa987 241 posts

Linux kernel developer and a firmware developer with an experience of 10+ years.

View all posts by this author →

You might also like

System Internals 0 Comments

Linux Recovery

This post was last updated on June 1st, 2020 at 12:11 pmHere’s another version of recovery.html that I put into the Compaq ProLiant Linux Installation HOWTO version 0.7 March 2001.

System Internals 0 Comments

File Permissions in Linux

This post was last updated on May 27th, 2020 at 04:40 pmNote: Any time you change permissions (such as what groups a user belongs to, etc) while that user is

System Internals 0 Comments

Linux /dev Entries

This post was last updated on June 1st, 2020 at 11:57 amLocated here is a listing of the /dev directory. I have posted this information since you may not always


No Comments Yet!

You can be first to comment this post!

Leave a Reply