Blah, etc. Blah

Sunday Feb 25, 2007

Update: The latest version is here.

I was reading some Sun blogs tonight and found the other Jonathan's blog which reminded me of a script I wrote a long time ago.  This script does basically the same thing, but has a nice mnemonic name and does a little input checking for my own sanity.  Also, I must confess to a little bit of cleanup in the code since I'll be laying it out here on the web.

I hope this is useful to you. 

#!/bin/ksh

########################################################################################
#
# Program : mntiso
#
# Purpose : Mount an ISO image so we don't need to burn a CD or DVD to view the content.
#
# Author : Dale Sears
#
# Version : 0 (Initial Version)
#
# Notes : I think this script could use a few more features. Here are some ideas
# that I didn't bother to implement:
#
# It's rather root-centric in the defaults... There *are* other users, and
# maybe they don't have root access to mkdir /iso
#
# What if I wanted /iso/image1.iso AND /iso/image2.iso mounted at the same time
# for diffs or some other purpose? I could mount things like so:
#
# ~/iso/image1.iso/
# ~/iso/image2.iso/
#
# Check for spaces in filename? It could happen, and it would break
# my lame script.
#
# Use getopts:
#
# -f Force the mount by unmounting what is mounted on MOUNTPOINT.
# -h Usage.
# -? Usage.
# -m Set the mount point different from the default.
#
# I probably could have implemented a few of these instead of writing
# all of this...
#
#######################################################################################


MOUNTPOINT=/iso

usage() {
echo
echo "Usage: "
echo " $0 /the/fully/qualified/path.iso"
echo
}


######################################################################
# How many args?
######################################################################
if [ $# -ne 1 ]
then
usage; exit 1
fi


######################################################################
# Check for leading / on the ISO arg (needed by lofiadm):
######################################################################
case "$1" in

/* ) ISO="$1"
break
;;

* ) usage
exit 1
;;
esac


######################################################################
# Remove possibly existing lofi device for the given ISO:
######################################################################
/usr/sbin/lofiadm -d "$ISO" 2> /dev/null


######################################################################
# Add lofi device for the ISO:
######################################################################
LOFIDEVICE=`/usr/sbin/lofiadm -a "$ISO" 2> /dev/null`

if [ -z "$LOFIDEVICE" ]
then
echo
echo 'Uh, oh... : No lofi Device.'
echo
echo "Perhaps $ISO is already mounted?"
echo
echo "To unmount and try again, use this:"
echo
echo " umount $MOUNTPOINT; $0 $ISO"
echo
exit 2
fi


######################################################################
# Check for $MOUNTPOINT and create as needed:
######################################################################
if [ ! -d "$MOUNTPOINT" ]
then
/bin/mkdir -m 555 "$MOUNTPOINT"
fi


######################################################################
# We've passed enough tests, let's try to mount the ISO and 'mount'
# will complain if $MOUNTPOINT is a file or is busy:
######################################################################
/sbin/mount -F hsfs -o ro $LOFIDEVICE $MOUNTPOINT

Comments:

I wonder, what do you do if the size is not a multiple of 512? Say you have an ISO image from Windows game, then mounting the image doesnt work, because the size is not correct.

Posted by Kebabbert on August 13, 2007 at 06:17 AM PDT #

There is a lot what can be done and just few explanations can make a big difference. I was looking how to overcome the 512 problem while using lofiadm on a .nrg file, and found it. Just dd usage on the original .nrg file.

Thank you and let God bless you.
Zika

Posted by Zivojin on February 24, 2009 at 01:43 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed