Simple clear advice in plain English

Hands on: Brush up your image

Linux can treat an image file – an exact copy of your disk data – as a device itself

Linux handles this using the ‘loop’ driver. This tells the kernel that the device you wish to mount is not a standard block device but a regular file on a filesystem. It couldn’t be much simpler to use. As an example, we can create an image file from a partition:

# dd if=/dev/hda1 of=image.ext3

Next, if we try to mount this file directly, the mount command gives an error, but guesses what we are trying to do.

The suggestion is to use ‘-o loop’, which tells mount to use the loop driver to mount the file. Running the command again with this option works (see attached picture):

# mount -o loop image.ext3/files

Finally, the mount command is run to display the currently mounted filesystems, and the results are grepped to show lines containing ‘image.ext3’. As you can see, the filesystem is recognised as ext3, and the mount options show that ‘/dev/loop0’ is in use.

If you now access the files and directories in /files, you are writing to and reading from the image file instead.

In every other way, the behaviour is identical to mounting a normal block device; the filesystem looks and behaves the same way, and applications and utilities neither know nor care about the underlying structure when they use it. Unmount the loop filesystem in the same way as normal:

# umount /files

When you mount a filesystem with ‘-o loop’, everything is automatically set up for you to access the filesystem immediately. An alternative method is to set up a loop device yourself and then mount that in the regular direct way.

This involves associating a loop device (such as /dev/loop0) with a file. Use the ‘losetup’ command to manipulate loop devices. First of all, associate the device:

# losetup /dev/loop0 image.ext3

You can check the status of a loop device by running losetup with the device’s name alone. Once done, /dev/loop0 behaves exactly like a regular block device, and so can be mounted normally:

# mount /dev/loop0 /files

As you can see from the screen, the filesystem is mounted just like any other. Unmount it in the usual way, but also remove the association between /dev/loop0 and the image file with losetup:

# umount /files

# losetup -d /dev/loop0

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

memonic-notetaking-software

Record and organise notes with Memonic Desktop

A handy program for keeping notes

Worry-free Wifi illustration

How to make the most of your Wifi

Get rid of all your Wifi problems with our guide to wireless networking

Edit Windows' right-click menus

How to add to and customise the right-click menus in Windows

If you right-click your mouse, a menu of extra options pops up. If you want to add extra choices to this, then Filerfrog makes it easy to customise your Windows list

Question & Answer

Q.Why are some of the keys on my keyboard doing strange...

> Read the answer

Q.Is my phone’s Bluetooth any use?

> Read the answer

Q.Can I switch boot drives so that I can work on older...

> Read the answer

Best deals on the web

img

Samsung RV520-A07

£359.98- Buy it now

img

Acer Aspire 5750G (LX.RXP02.019)

£399.99- Buy it now

img

Apple MacBook Pro (MD313B/A)

£904.37- Buy it now

Latest issue & subscription deals

Poll

Are you concerned about viruses that target mobile phones?

Jargon Buster

Computing terms explained in plain English

Virtual drive

A set of files seen by Windows as a separate hard disk.

Great shopping deals from Computeractive