Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
I still do. I never noticed mount can do that implicitly. –  Bananguin Feb 25 '13 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 '13 at 23:09

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 harddisk the same way. That's why we create abstraction layers.

Block device are such an abstraction. Block device 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 withit. 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 file(system)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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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