21

According to the following question:
What is a "loop device" when mounting?
A loop device is a file that acts as a block-based device. While I can understand that conceptually, how is this different from mounting any other file? For example, if I take a dd image of an ext2 filesystem and then mount it, I don't have to use the loop option- mount -t ext2 file.dd /mnt/mount-point succeeds.

When should I use the loop option and what difference is there between mounting using the loop option and mounting without it?

2 Answers 2

27

Technically a loop device is a block device that writes to a file, rather than a piece of hardware. So you always use/need to use the loop back device when mounting a file.

So much for a direct answer. Maybe this serves as an explanation:

The kernel implements several layers of abstraction so that it can treat different hardware the same way. Imagine if you had to rebuild the ext2 driver for every brand of controller there is. Nobody wants that, but we want to treat every hard disk the same way. That's why we create abstraction layers.

Block devices are such an abstraction. Block devices have certain attributes and expose certain functions that can be used by other software. It doesn't matter whether you have an ATA HDD or SCSI HDD or tape drive, you always use the exact same structs and function to interact with it. It is then the task of the kernel and more explicit of that abstraction layer, to do the right thing when the block device is accessed. The right thing in the case of the block device interface is passing on the calls and data to and from the right device driver. That device driver can be, for instance, the SCSI subsystem or the driver for the loop device.

The loop device driver transforms operations on the associated block device into filesystem operations, that's how the data/partitions end up in a file.

I am probably terribly wrong in the terminology used and the name and number of abstraction layers involved. I just wanted to sketch the basic concept so it becomes clear that the loop device is not a file doing something, but it's a something that uses files. The file doesn't do anything different than it is used to do.

8

If you don't have to use the loop option to mount a regular file, it is because mount is detecting this and activating it for you automatically. You used to have to specify it manually.

2
  • I still do. I never noticed mount can do that implicitly.
    – Bananguin
    Feb 25, 2013 at 18:49
  • @user1129682 I wonder if different versions of the kernel or different distros have or don't have this feature?
    – Suchipi
    Feb 25, 2013 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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