Posts Tagged ‘mount’

Mounting an .iso file

October 30, 2011 Leave a comment

In Linux it is easy to access the content of some .iso-file directly without having to burn it to a CD/DVD. Just mount the .iso-file to some directory of your choice and you can browse it like any directory:

sudo mount <iso-file> <existing directory> -t iso9660 -o loop

The following script also prints some help if called with the wrong number of parameters and creates the directory if not yet existing:


# print help if called with wrong parameter count
if [ $# -ne 2 ]; then
        echo "USAGE:   isomount <isofile> <location>"
        echo "INFO:    Mounts the specified .iso-file to the given"
        echo "         directory location (if it is not existing then"
        echo "         it is created with user-rights)"
        echo "EXAMPLE: isomount MyFile.iso /tmp/fooooo"
        exit 1

# create directory if not existing and exit on error
if [ ! -d "$2" ]; then
        mkdir $2
        if [ $? -ne 0 ]; then
                exit 1

# mount the iso-file
sudo mount $1 $2 -t iso9660 -o loop

Just save these lines in some file (e.g., isomount) and make it executable (e.g., with chmod 755 isomount).

Categories: Computer, Shell Scripts Tags: ,