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

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 Kernel compilation guide.

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

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


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

About author

shibaa987
shibaa987 274 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

Printer Ports

This post was last updated on June 3rd, 2020 at 04:07 pmCommon Printer port settings are as follows: LPT Port I/O Address LPT1 378 LPT2 278 LPT3 3BC Compaq Servers

System Internals 0 Comments

Linux Boot Process

This post was last updated on June 3rd, 2020 at 03:34 pmThe following is from /usr/src/linux-2.4/Documentation/initrd.txt When using initrd, the system typically boots as follows: 1) the boot loader loads

System Internals 0 Comments

What’s an Operating system & why do we need one?

This post was last updated on November 3rd, 2020 at 05:15 pmBasically an operating system (OS) is a software system (collection of interdependent software code) on its own that allows

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply