Home / How to mount an ISO image on Linux

How to mount an ISO image on Linux

An ISO image or .iso file contains the disk image of an ISO 9660 file system, which is used for storing data on CD-ROMs and DVD-ROMs. It is possible to take an ISO image and record it onto a CD or DVD using various applications for doing so, and it is also possible to mount the ISO image using Linux, so that you can access the files without having to actually burn it to disk first.

ISO images downloaded from the Internet typically contain operating system installation software, such as installing Linux (eg Fedora, Ubuntu, openSUSE, Mandriva, CentOS etc) or BSD (eg FreeBSD, OpenBSD and NetBSD). Sometimes you might need to access files on these ISO images but don’t want to actually waste a disk just to access them.

Mounting an ISO image on Linux is as simple as this, running the command from a terminal either as root or using sudo:

mount -t iso9660 -o loop /path/to/filename /mnt/loop0

The /path/to/filename in the above example would be the path to and filename of the ISO image, eg /home/chris/temp/CentOS-5.1-i386-bin-1of6.iso, and /mnt/loop0 at the end of the command is a place to mount the file to and must be a directory that actually exists. If it does not exist, then you’ll get an error message like this:

mount: mount point /mnt/loop0 does not exist

I’m just using /mnt/loop0 as an example, but you could make it any directory that you would like to mount it to, as long as it exists.

After the ISO image has been successfully mounted, it’s just like accessing any directory on your regular filesystem, only it is read only and none of the files can be modified. For example, doing this:

ls -l /mnt/loop0

will display the directory listing of the ISO image mounted at /mnt/loop0 that we have mounted in the earlier example above. In the example of the CentOS 5.1 CD, the listing would look like this:

drwxr-xr-x 2 root root 86016 2007-11-25 08:36 CentOS
-rw-r--r-- 7 root root   212 2007-03-30 13:50 EULA
-rw-r--r-- 7 root root 18009 2007-03-10 18:01 GPL
drwxr-xr-x 4 root root  2048 2007-11-25 08:31 images
drwxr-xr-x 2 root root  2048 2007-11-25 08:31 isolinux
drwxr-xr-x 2 root root  8192 2007-11-25 08:31 NOTES
-rw-r--r-- 2 root root   655 2007-11-24 12:46 RELEASE-NOTES-cs
-rw-r--r-- 2 root root  1401 2007-11-24 12:46 RELEASE-NOTES-cs.html
-rw-r--r-- 2 root root   839 2007-11-24 12:46 RELEASE-NOTES-de
-rw-r--r-- 2 root root  1571 2007-11-24 12:46 RELEASE-NOTES-de.html
-rw-r--r-- 2 root root   694 2007-11-24 12:46 RELEASE-NOTES-en
-rw-r--r-- 2 root root  1367 2007-11-24 12:46 RELEASE-NOTES-en.html
-rw-r--r-- 2 root root   788 2007-11-24 12:46 RELEASE-NOTES-es
-rw-r--r-- 2 root root  1619 2007-11-24 12:46 RELEASE-NOTES-es.html
-rw-r--r-- 2 root root   852 2007-11-24 12:46 RELEASE-NOTES-fr
-rw-r--r-- 2 root root  1641 2007-11-24 12:46 RELEASE-NOTES-fr.html
-rw-r--r-- 2 root root   766 2007-11-24 12:46 RELEASE-NOTES-ja
-rw-r--r-- 2 root root  1565 2007-11-24 12:46 RELEASE-NOTES-ja.html
-rw-r--r-- 2 root root   706 2007-11-24 12:46 RELEASE-NOTES-nl
-rw-r--r-- 2 root root  1433 2007-11-24 12:46 RELEASE-NOTES-nl.html
-rw-r--r-- 2 root root   752 2007-11-24 12:46 RELEASE-NOTES-pt_BR
-rw-r--r-- 2 root root  1480 2007-11-24 12:46 RELEASE-NOTES-pt_BR.html
-rw-r--r-- 2 root root   801 2007-11-24 12:46 RELEASE-NOTES-ro
-rw-r--r-- 2 root root  1473 2007-11-24 12:46 RELEASE-NOTES-ro.html
drwxr-xr-x 2 root root  2048 2007-11-25 09:07 repodata
-rw-r--r-- 7 root root  1512 2007-03-10 18:01 RPM-GPG-KEY-beta
-rw-r--r-- 2 root root  1504 2007-02-20 06:57 RPM-GPG-KEY-CentOS-5
-r--r--r-- 1 root root  6360 2007-11-25 09:07 TRANS.TBL

To unmount the ISO image when you are done, simply do this, running the command from a terminal either as root or using sudo:

umount /mnt/loop0

If you didn’t run it as root or using sudo, then you’ll see an error similar to this:

umount: /mnt/loop0 is not in the fstab (and you are not root)

Just run it again using sudo or as the root user and it should work fine.

Mounting more than one ISO image at the same time

If you need to have more than one ISO image mounted at the same time so you can reference files on several ISO images at once, then just mount each one using a different /dev/loopX and different mount location. For example, to mount all 6 of the CentOS CD images used in the above example, you would do the following.

First of all make sure the directories we are going to mount them to have been created (we’ll mount CD 1 at /mnt/loop1, CD 2 at /mnt/loop2 and so on, so as not to cause confusion):

mkdir /mnt/loop1
mkdir /mnt/loop2
mkdir /mnt/loop3
mkdir /mnt/loop4
mkdir /mnt/loop5
mkdir /mnt/loop6

Using a little bit of BASH magic we can simplify the above to this:

for i in 1 2 3 4 5 6; do mkdir /mnt/loop$i; done

And then mount each one. The following assumes we are in the same directory location as the ISO image files.

mount -t iso9660 -o loop CentOS-5.1-i386-bin-1of6.iso /mnt/loop1
mount -t iso9660 -o loop CentOS-5.1-i386-bin-2of6.iso /mnt/loop2
mount -t iso9660 -o loop CentOS-5.1-i386-bin-3of6.iso /mnt/loop3
mount -t iso9660 -o loop CentOS-5.1-i386-bin-4of6.iso /mnt/loop4
mount -t iso9660 -o loop CentOS-5.1-i386-bin-5of6.iso /mnt/loop5
mount -t iso9660 -o loop CentOS-5.1-i386-bin-6of6.iso /mnt/loop6

And using a little BASH magic again, we can simplify this as follows:

for i in 1 2 3 4 5 6;
  do mount -t iso9660 -o loop CentOS-5.1-i386-bin-$iof6.iso /mnt/loop$i;
done

That will mount all 6 CD images to /mnt/loop0 through /mnt/loop6 . Note that the after $i is required, otherwise the for loop will think the variable name is $iof6. Escaping the o like $io fixes this.

Updated February 19th 2008

Thanks to Isaac Emesowum for letting me know that you don’t need to specify the "ro" option or the actual loop device because the system will assign it automatically, and will notify you if it runs out of loop devices. I have updated the above mount command examples accordingly.

Another update on February 19th…

I was just mounting an ISO image to checksum the contents just now, and decided to try not specifying the "-t iso9660" and that worked, so it looks like the mount command is smart enough to work out that it’s a CD image. This simplifies the mount command to this:

mount -o loop filename.iso /mnt/location