[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Using loop devices in Debian

On 1/26/14, Richard Owlett <rowlett@cloud85.net> wrote:
> Zenaan Harkness wrote:
>> On 1/24/14, Richard Owlett <rowlett@cloud85.net> wrote:
>>> Having read http://en.wikipedia.org/wiki/Loop_device, I suspect
>>> using a loop device will alleviate some of my problems.
>> Let's make sure we're not in XY problem territory.
> <snickers> *GRIN* !
> IOW Not sure if *IN*, but definitely at least near.
> Which is why my post ended with:
>       "Could some one point to good reference so that I might ask
> good questions."

Well, let's say that learning to use loopback devices will definitely
solve the problem of wanting to learn loopback devices :)

> As you noticed, my posts have a recurring theme.
> None of the explicit responses have explicitly loop
> devices/mounting/???.
> However. loop mounting has repeatedly come up when following
> chains of links.
> I need a loop education.

I'll have a crack, see below.

> Would have gone directly to Wheezy except that Gnome3 is a
> terminally ugly user experience.

Here's where I remind you there are multiple install CDs - for various
desktops, and also for no desktop (a great option!, and the one I use
myself - it's about a 250MiB image, there is the even smaller
netinstall, but I suggest that's a bit too little for your needs right

Then, just install and learn one thing at a time. It's an option.

Also, you should _definitely_ spend a few hours getting familiar with
the Advanced Install mode (text only), of _any_ Debian install disk.
Lots of options, lots of stuff some of which is _really_ useful to
know, if ever you need to rescue one of your boxes.

The advanced install is essentially the same for every Debian disc
(except netinstall, and the available packages) - it's possible to do
a minimal install with the advanced install option, and this is what I
always do - I _never_ use the "non-advanced" installs - personally
don't trust them to not install stuff I don't want :) :)

>> https://lists.debian.org/debian-user/2013/11/msg00374.html
>> As you can see from that link, your follow up message showed that this
>> procedure worked for you.

OK, loopback mounting:

lsmod|grep lo
and this should give at least one line beginning with "loop" - this is
the required kernel module. If you don't have such a line then:
insmod loop
and check again with your lsmod command.

ls -l /dev/lo*
and have a look-see. You should have /dev/loop-control , as well as
/dev/loop0 , /dev/loop1 etc up to whatever limit is set.

These are the (special device-) files in the filesystem which allow
you to do loopback mounting. They are created by the loop module and
the appropriate commands.

If you want or need to increase the maximum number of loopback devices
available _by_default_ when you next boot, edit
and make sure there is a line like the following (I have 11 by default):
loop max_loop=11

If you don't want to reboot, and need to create some (extra) loop
devices, and I'll assume you already have loop0 to loop7, try:
cd /dev
mknod -m 660 loop8 b 7 8
mknod -m 660 loop9 b 7 9

You should also set the ownership of these files as follows:
chown root.disk loop8 loop9 ...

The parameter -m specifies the file access permissions (here: -rw-rw----)
and you can also use chmod command to change those file access permissions,
/dev/loop8 is the name of the device to create
and b stands for Block Device.
The numbers at the end are the 'major' and 'minor' numbers (linux
kernel/ driver terminology, somewhat arbitrary but nevertheless very
specific - love those oxy-oxy-morons).
The first one (the major number) sets the device type and therefore
which driver to use.
Loop devices have the major number 7.
The second digit (the minor number), is a number used internally by
the driver. This can be any cipher, in this case it's the number of
the loop device counted from 0.

Now you can mount an ISO image, using an available (currently unused)
loop device, as follows:
LO_DEV=`losetup -f --show my-iso-file.iso`; echo $LO_DEV
This command will give you output of the loop device filename chosen
and used (if successful) by losetup command, and store that in $LO_DEV
environment variable.

Now you can mount (assuming the above step was successful) your
loopback device file somewhere in the filesystem (the mount command
often can figure out the filesystem type, but I've included that just
in case) eg:
mount $LO_DEV /mnt -t iso9660
cd /mnt
ls -l

Note that the mount command can do the loopback device file setup
(linking your ISO image to a particular device file), automatically,
mount my-iso-file.iso /mnt -t iso9660 -o loop

once you are finished with your loopback activities, undo the steps above, eg:
# make sure we're not below the dir to be unmounted:
cd /
# unmount loop device
umount /mnt
# detach iso file from loop device:
losetup -d $LO_DEV

(I think, at least in the past, mounting with the -o loop option,
would not automatically undo this last step, but it's been a while -
anyway, by doing it manually, you make sure you've cleaned up after
yourself, so that the loop device is available again without having to

Remember to read the man pages, eg
man losetup

man mount has a section "THE LOOP DEVICE" which tells us amongst other stuff:
Since Linux 2.6.25 is supported auto-destruction of loop devices and
then any loop device allocated by mount will be freed by umount
independently on /etc/mtab.

eg there are useful info output to generate, eg losetup $LO_DEV will
show the status of that loop device.

If you are unsure what is mounted:

If you are unsure what loop devices have not been freed up:
for i in /dev/loop*; do echo "status of device ${i} is:"; losetup $i; done

Have fun,

Reply to: