Home > Computer, Shell Scripts > Mounting an .iso file

Mounting an .iso file

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:

#!/bin/sh

# 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
fi

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

# 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).

Advertisements
Categories: Computer, Shell Scripts Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: