Linux: Mount an ISO File
Why Would I Want to Mount an ISO File?
There are two common uses for mounting an ISO file under Linux. These two uses are; to retrieve a file from within the ISO without having to burn it to disk and to use the mount point as a “virtual cdrom drive”. Often times I find myself only wanting a file or a few files from within an ISO file I have downloaded or made myself. To retrieve this file I could burn the ISO file to disk and then access the files on the disk (CD or DVD) but why bother wasting a CD or DVD when I can simply mount the ISO to a directory and access the files from there? Other times I am on a computer with no optical drive and need to access a file, a few files or all files within an ISO file. Without the ability to mount the ISO file in the file system I would be out of luck. This way I can mount the ISO file to a directory and access it as if it were a cdrom drive. This can save you time and a lot of CD or DVD disks assuming you work with a lot of ISO files.
The Commands Used to Mount an ISO File
To mount an ISO file on a Linux machine you will need to use the mount and loop commands like so:
mount -o loop testISO.iso /mnt/iso
This will mount an ISO file, named testISO.iso, in your current directory to the directory /mnt/iso, but before you can do this you will need to create the /mnt/iso directory so that the mount command has somewhere to mount the ISO. To do this simply execute the following command:
sudo mkdir /mnt/iso
How to Access the ISO once Mounted
In the above example we mounted an ISO file named testISO.iso to the directory /mnt/iso so in order to access the files contained within the ISO file we have to first switch to the mount directory:
Once we are in the mount directory we can get a list of files in the directory (the files that were on the original ISO file) with the following command:
From there we can execute, read and write to the files assuming we have the proper permissions on the Linux machine. The proper permissions will mean you need sudo (root) access or for an administrator to add you to the cdrom and mount groups.
When You are Finished with the ISO File
Once you have accessed the files you needed on the ISO you will want to unmount the ISO file with the following command:
sudo umount /mnt/iso
That’s all there is to it. A very useful tool when working on a computer with no optical drive or mounting an ISO file quickly to grab a few files from it.
All photos courtesy of stock.xchng.