This is a small workaround I came up with to mount/unmount iso image files in #!. Iso files are great to work with be it the os installer or back up of your dvd/cd data. By default you would read them with the archive manager, but that makes it cumbersome since you have to extract each file before you can work with it.
A better approach is to mount the iso file to some location and work with its content there. A simple cli command will help you do it. And to make things more convenient, i created basic shell scripts which help me manage the iso files that i have to work with.
The idea is to mount the iso at a known location after doing some basic checks like whether the file argument provided is an iso, is the mount point location available for use etc.
Here’s the script for mounting an iso file.
#! /bin/sh
clear
if [ $# -eq 0 ]
then
echo "No iso file provided"
echo "Usage ::"
echo "isomount <file-name.iso>"
exit 0
fi
if [ $1 = '--help' ]
then
echo "Usage ::"
echo "isomount <file-name.iso>"
exit 0
fi
if [ ! -f $1 ]
then
echo "File $1 does not exist"
exit 0
fi
fileNameLength=`expr length $1`
start=`expr $fileNameLength - 2`
fileExt=`expr substr $1 $start $fileNameLength`
if [ $fileExt != "iso" -a $fileExt != "ISO" ]
then
echo "File not a valid iso"
exit 0
fi
if [ ! -d ~/iso-mount ]
then
echo "Mount directory is missing. Creating one..."
mkdir ~/iso-mount
fi
echo "Mounting file "$1"..."
sudo mount -o loop $1 ~/iso-mount/
thunar ~/iso-mount/ &
If the checks are valid then the iso file gets mounted at /home/<user>/iso-mount/. And the file manager opens the mount location for immediate use.
To unmount the iso, the script simply issues a umount command like so –
#! /bin/sh
echo "Attempting unmounting ~/iso-mount"
fileCount=`ls ~/iso-mount/ | wc -l`
if [ $fileCount -eq 0 ]
then
echo "Mount point seems already unmounted"
echo "Nothing needs to be done"
exit 0
fi
sudo umount ~/iso-mount/
echo Done
I have saved these scripts at location /usr/bin with executable rights and root previledge.
koolksp@crunchbang:~$ ls -l /usr/bin/iso*
-rwxr-xr-x 1 root root 606 Apr 30 08:44 /usr/bin/isomount
-rwxr-xr-x 1 root root 241 Dec 24 22:52 /usr/bin/isounmount
See them in action –
koolksp@crunchbang:~$ isomount openSUSE-13.1-GNOME-Live-i686.iso
Mounting file openSUSE-13.1-GNOME-Live-i686.iso...
And the files open up in Thunar the file manager for #!
For unmounting simply execute the isounmount script.
koolksp@crunchbang:~$ isounmount
Attempting unmounting iso-mount
Done