What is the difference between mount and mount -o loop

I have a iso file named ubuntu.iso.

I can mount it with the command: mount ubuntu.iso /mnt. After mounting it, I can see it from the outout of the command df -h: /dev/loop0 825M 825M 0 100% /mnt.

However, if I execute the command mount -o loop ubuntu.iso /mnt, I’ll get the same result.

As I know, loop device allows us to visit the iso file as a device, I think this is why we add the option -o loop. But I can visit my iso file even if I only execute mount ubuntu.iso /mnt.

So I can’t see the difference between mount and mount -o loop.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Both versions use loop devices, and produce the same result; the short version relies on “cleverness” added to mount in recent years. mount -o loop tells mount explicitly to use a loop device; it leaves the loop device itself up to mount, which will look for an available device, set it up, and use that. (You can specify the device too with e.g. mount -o loop=/dev/loop1.)

The cleverness is that, when given a file to mount, mount will automatically use a loop device to mount it when necessary — i.e., the file system isn’t specified, or libblkid determines that the file system is only supported on block devices (and therefore a loop device is needed to translate the file into a block device).

The loop device section of the mount man page has more details.

Method 2

The loop device is primarily controlled with the losteup command. So losetup -a gives you overview about the used loop devices and attached files. The mount command can mount the block device only. The loop device can create the virtual block device from a file (character device).

In fact there is a great difference between those commands because on older Linux systems the mount could not recognise the file as the correct device to be mounted, but during the time the mount command was completed with lot of feature, hence it can now self decide to try to call the losetup command and mount the result. But if you got a whole disk image not iso format but e.g. with MBR at the beginning, the mount command could not recognise it and you have to find the usable partition (e.g. with the parted disk_image.raw unit B print command) yoursef and than mount it with full option mount comman as :

mount disk_image.raw /mntpoint/ -o loop,offset=${OFFSET_of_PARTITION}

In this syntax the loop device was not specified and it is assumed the system choose the first free (/dev/loop0, /dev/loop1 etc)
Among the other new features of mount command is that you need not specify the filesystem type of the mounted block device (in your case -t iso9660) if the filesystem support was installed.

Method 3

There is no difference between mount ubuntu.iso /mnt and mount -o loop ubuntu.iso /mnt.

The first is transparently handled as if you had used the second.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments