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
Related articles
Q.Why are some of the keys on my keyboard doing strange...
Q.Is my phone’s Bluetooth any use?
Q.Can I switch boot drives so that I can work on older...
St Helena, a 'small British village' in the mid-Atlantic, is seeking support and funding for a broadband connection
|
|
|
|
|
Computeractive Excel (2010) Online tutorialPrice: £19.99 |
Computeractive Word (2010) Online TutorialPrice: £19.99 |
Computeractive Powerpoint (2010) Online TutorialPrice: £19.99 |
Angry BirdsPrice: £9.99 |
Back Issue CD-Rom 14 (2011)Price: £15.99 |