HOW-TO: Mount ISO Images

There are a million reasons (perhaps exaggerated, but you get the point) why you should mount an ISO file. To name one, access to the harddrive is way faster than access to the optical drive. Another would be, not all hosts have optical drives or access to the physical host is restricted. Or perhaps, the device can read optical media but could not "burn" or write to it. And the list goes on but the fact of the matter is: the optical drive is rarely used, if at all.

Windows has virtual CD/DVD drives and most of these add-on software(s) are free. How about in the _nix platforms? Do the machines need virtual devices? Are the software(s) free as well? How are they installed? These questions are only a few that need answers. Perhaps discussing the process will, in turn, directly address the questions.

Linux. In Linux, ISO images are mounted via the loop device. It makes possible to specify transfer functions like encryption or decryption, compression or other purposes using loop device driver.

As super-user or root, create the directory to be used as mount point.

root@host # mkdir /SOME/PATH

Mount the ISO image like below.
root@host # mount -o loop /PATH/TO/IMAGE.iso /SOME/PATH

The ISO image (IMAGE.iso) can now be accessed under /SOME/PATH.

To unmount the image, the usual unmount command can be run.
root@host # umount /SOME/PATH

Solaris. Solaris, just like linux has a loopback device "lofi" - the loopback file driver. The lofi file driver exports a file as a block device, making it possible for the system to read and write to the device (or to the underlying file related to the device).

With the ISO image exported as a block device, the lofi file driver allows normal system utilities like mount to operate on the image. The exported block device of the ISO image can now be mounted, accessing the ISO image.

From Sun online documentation:
  The tool lofiadm administers lofi(7D), the loopback file driver. lofi(7D) allows a file to be associated with a block device. That file can then be accessed through the block device. This is useful when the file contains an image of some filesystem (such as a floppy or CD-ROM image), because the block device can then be used with the normal system utilities for mounting, checking or repairing filesystems. See fsck(1M) and mount(1M).

Use lofiadm to add a file as a loopback device, remove such an association, or print information about the current associations.

The lofi(7D) driver is not available and will not work inside a zone.

First, create the block device using lofiadm.
root@host # lofiadm -a /PATH/TO/IMAGE.iso

In running the above command, lofiadm picks the device and prints the device name to the standard output. The absolute path to IMAGE.iso must be given -- /PATH/TO/IMAGE.iso. Otherwise, lofiadm will return an error.

You can run lofiadm alone to list the devices.
root@host # lofiadm
Block Device File Options
/dev/lofi/1 /PATH/TO/IMAGE.iso -

With the block device (/dev/lofi/1) created, it could now be mounted.
root@host # mount -F hsfs -o ro /dev/lofi/1 /mnt

The above creation and mouting can be executed in a single command.
root@host # mount -F hsfs -o ro `lofiadm -a /PATH/TO/IMAGE.iso` /SOME/PATH

Unmounting the device is similar to unmounting in Linux. Very straightforward. After unmount has executed, the lofi block device still exists and, if desired, can be deleted. Execution of standalone lofiadm on the command line will show which block device to delete. In this example, there is only one block device /dev/lofi/1.
root@host # lofiadm -d /dev/lofi/1

There are a lot of advantages in mounting an ISO image in both Solaris and Linux. And best of all, there is no need to install additional software as the system itself has the necessary tools to make it possible. There goes the answer.

You might also be interested in:


We at pimp-my-rig strive to keep on improving, help us reach that goal by leaving comments or constructive criticisms. Don't miss out on our next feature -- subscribe via RSS (What is RSS?).

Share This