Simple fix loop device errors with losetup

loop devices are critical for virtualization technologies like xem or Oracle Virtual server. we may face errors like “mount: could not find any free loop device” during building or managing Vms lin dom0.

Step by step guide to build and fix loopdevice errors with losetup

1.Check current available loop devices on Linux ( Oracle Linux related)

losetup -f
it means, next available loop device is loop50.
Else it will give message no loop device available.

2.Create new loop devices

You can create loop devices as per your requirement with losetup command. but you need to create a sequence of loops not random. For example setup -a given all used loop devices. In the last line of output, you will see the last loop user. Now to create mode, you need to use the number next to the above loop device number. For example, if the last loop device listed 60 then you need to create the next loop 61 onwards.

3.Easy way to create Linux loop devices with losetup in a shell script. Following the script, credit goes to the original author ( collect from random site)

for i in {23..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

Above code creates loop devices from 23 to 63. so in short when you out of loop devices, first list them , check the last number and create new loop device from next to the last used number.







Leave a Reply

Your email address will not be published. Required fields are marked *