Ever wanted to peek into the contents of an .ISO file, a.k.a. “CD image file” (or many other names), without having to burn it? This post is going to teach you how you can easily access the contents of all the ISO files you want, from now on.
This recipe was prepared and tested on Ubuntu Linux 10.04, but it should pretty much work smoothly in any Linux distribution. Although this has been set up exclusively for ISO images (used in CDs), this can be, in theory, used to almost any filesystem, including DVD’s UDF or any other filesystem you like.
First, make sure you have
autofs, also known as
$ sudo apt-get install autofs
This package will provide a
/etc/init.d/autofs script to control the service and a
/etc/auto.master file to configure the service.
First things first: we need to plan two things: a) where we are going to mount the .iso images, and b) where the .iso files are going to be mounted from. In this example, I have created a structure like:
/local/iso/files will hold the .iso files, while the
/local/iso/images is the place where we are going to access their contents. Thus, if you place a file (or create a symbolic link, for instance) named
/local/iso/files, you are going to be able to access a directory named
/local/iso/images/mydisk.iso/, magically mounted for you.
Let’s get to work
To achieve that we need to edit the
/etc/auto.master file, which is provided by the
autofs package and include a line like:
/local/iso/images /etc/auto.iso --timeout=10
This line tells autofs to manage everything under the
/local/iso/images directory, using the configurations in the
/etc/auto.iso file – that will be created in the next step. Besides that, we’re setting a 10 seconds timeout for the automounted directories – way shorter than the default value of 60 seconds. That is, if no process is using that directory for 10 seconds,
autofs will unmount it.
Next we are going to set up a
/etc/auto.iso file, with the contents:
* -fstype=iso9660,loop :/local/iso/files/&
The star sign “*” on the beginning of the line tells autofs that it should auto-mount anything – as opposed to specifying directories names you wish to be auto-mounted.
The middle piece are the mounting options:
-fstype=iso9660 – the filesystem type for CD images, which is the filesystem that define the internal structure of ISO files (and file CDs, for that matter)
loop – filesystems are mounted from block devices, such as the partitions in your hard-drive, or in your USB pen-drive. Using this option you tell Linux not to complain about mounting a filesystem from a regular file (the ISO file, in this case)
The last piece is a little bit trickier. The colon-sign “:” is necessary because automounting was, historically, designed to automatically mount and unmount remote directories, using NFS. However, today you can not only choose to mount other types of filesystems, as well as mounting local files, like we’re doing now. For remote directories, the syntax would be something like:
When mounting from local devices/files there is no server to specify but you must use the colon sign.
Then you have the ampersand sign “&” at the very end. The ampersand is the counterpart of the wildcard character “*” used for the mounting directories. It means: “replace this ampersand symbol with whatever you actually try to access there under the
Next you must start (or restart) the autofs service so it can pick up these settings. That may vary depending on your distro, but in Ubuntu you simply run:
$ sudo restart autofs
You can now try it by copying an ISO file to the
/local/iso/files – any regular ISO-9660 file should do.
For instance, if you don’t want your mounted directory to have a “.iso” extension, you can edit
/etc/auto.iso to be like:
* -fstype=iso9660,loop :/local/iso/files/&.iso
All set. I have provided a
sample.iso file that you can use to test this. Then you’re going to have something like this:
00:12:28 BRT /local/iso/files $ ls -l
drwxrwxrwt 2 root root 4096 2010-09-25 00:12 ./
drwxr-xr-x 4 root root 4096 2010-09-22 14:53 ../
-rw-r--r-- 1 az az 382976 2010-09-25 00:12 sample.iso
00:12:30 BRT /local/iso/files $ cd ../images/sample
00:14:16 BRT /local/iso/images/sample $ ls -l
drwxr-xr-x 4 az az 2048 2010-09-24 23:58 ./
drwxr-xr-x 3 root root 0 2010-09-25 00:14 ../
drwxr-xr-x 2 az az 2048 2010-09-24 23:58 surprise-surprise/
drwxr-xr-x 2 az az 2048 2010-09-24 23:59 ultrasecret/
There you go, you are viewing the files within the file! 🙂