17

How to add more /dev/loop* devices on Fedora 19? I do:

# uname -r
3.11.2-201.fc19.x86_64
# lsmod |grep loop

# ls /dev/loop*
/dev/loop0  /dev/loop1  /dev/loop2  /dev/loop3  /dev/loop4  /dev/loop5  /dev/loop6  /dev/loop7  /dev/loop-control
# modprobe loop max_loop=128
# ls /dev/loop*
/dev/loop0  /dev/loop1  /dev/loop2  /dev/loop3  /dev/loop4  /dev/loop5  /dev/loop6  /dev/loop7  /dev/loop-control

So nothing changes.

2
  • loop isn't a module in fedora 19, its compiled in.
    – Sirex
    Nov 3, 2013 at 22:57
  • 1
    you'd probably use mknod. but why would you want to create more loop files without connecting them to anything?
    – strugee
    Nov 4, 2013 at 0:51

3 Answers 3

21

When you run it as root, losetup -f will automatically create loop devices as needed if there aren't any free ones available.

So rather than doing it yourself with mknod, the easiest way to create a new loop device is with sudo losetup -f. That approach will give you a free existing loop device if one exists, or automatically create a new one if needed.

2
  • The error message you get when running losetup -f as a non-root user currently isn't very helpful though, so I filed bugzilla.redhat.com/show_bug.cgi?id=1215370 to suggest improving that.
    – ncoghlan
    Apr 25, 2015 at 22:04
  • Based on that report, the losetup error changed to be Permission denied rather than No such file or directory, giving a better nudge to trying again with more privileges.
    – ncoghlan
    Oct 25, 2022 at 8:37
13

You have to create device nodes into /dev with mknod. The device nodes in dev have a type (block, character and so on), a major number and a minor number. You can find out the type and the major number by doing ls -l /dev/loop0:

user@foo:/sys# ls -l /dev/loop0
brw-rw---- 1 root disk 7, 0 Oct  8 08:12 /dev/loop0

This means loop device nodes should have the block type and major number of 7. The minor numbers increment by one for each device node, starting from 0, so loop0 is simply 0 and loop7 is 7.

To create loop8 you run, as root, command mknod -m 0660 /dev/loop8 b 7 8. This will create the device node /dev/loop8 with permissions specified along the -m switch (that's not necessary as you're probably running a desktop system, but it's a good idea not to let everyone read and write your device nodes).

1
  • 2
    You forgot the node type after the name, so the command should be mknod -m 0660 /dev/loop8 b 7 8. Dec 7, 2015 at 20:51
7

Heh, incomplete :) Simply use this script for adding new /dev/loops. Remember for changing numbers, script makes to 63'th loop, starts from 8'th because 0-7 is made by default. Notice, rights are copied from /dev/loop0 :)

for i in {8..63}; do if [ -e /dev/loop$i ]; then continue; fi; \
mknod /dev/loop$i b 7 $i; chown --reference=/dev/loop0 /dev/loop$i; \
chmod --reference=/dev/loop0 /dev/loop$i; done

Notice, recipe above are from 2014 year. At now is 2023 year :) Currently developed kernel creates all /dev/ device by devfs virtual filesystem. For backward compatibility it displays 0 to 7 loop device automatically, but it creates additional loop devices when it is needed. At now there is no limit 256 loop devices encoded by 1 byte minor number. Modern kernels supports 2 byte minor number, then limit is 65535 devices.

This is currently used in union like filesystems, for Docker or K8S containers.

Finally, recipe for modern systems is useless

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.