What is a “loop device” when mounting?

I am mounting an ISO file, and looking at this tutorial. They use the command:

$ mount -o loop disk1.iso /mnt/disk

I’m trying to understand the use of -o loop. I have two questions:

  1. When I look at the long man page for mount, it takes time to find that -o option. If I do man mount | grep "-o" I get an error, and when I look in the file I do not find any info that “loop” is a command text for option -o. Where is that documented?
  2. Also, what is the “loop device” concept for mounting?

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

A loop device is a pseudo (“fake”) device (actually just a file) that acts as a block-based device. You want to mount a file disk1.iso that will act as an entire filesystem, so you use loop.

The -o is short for --options.

And the last thing, if you want to search for “-o” you need to escape the ‘-‘.

Try:

man mount | grep "-o"

Method 2

Traditionally, UNIX systems have had various types of nodes in their filesystems:

  • directory
  • file
  • symlink
  • block device
  • character device
  • FIFO
  • UNIX domain socket

While there are now exceptions, generally block devices containing filesystems are mounted on directories.

Since you want to mount a file, you must first create a loop block device that is backed by the file. This can be done using losetup, but mount -o loop is a shortcut that handles that behind the scenes.

Method 3

Loop device is a device driver that allows you to mount a file that acts as a block device (a loop device is not actually a device type, it’s an ordinary file).

For example:

mount -o loop demo.img /mnt/DEMO/
ls -l /mnt/DEMO/

You can now look at the /mnt/DEMO subdirectory for the contents of the demo.

Method 4

I have a related question about using the loop device.

File systm zfs is designed to use full hardware disks.

I want to use a zfs file system. My needs are about 40 gigs. I have a 256gig ssd. What I would like to know, is how to setup the fstab entry so that a boot of that linux distro, recognizes the loop device and allows me to use the remaining roughly 212gigs for other purposes.

To be specific, What does the installer for Ubuntu 22.04 gnome version need to know/do if I want to use zfs pointing to that loop device?


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
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x