Monday, May 04, 2009

Mounting ISO images and creating shell scrips

Problem: Mount an ISO image file
  • Good old terminal
To make a mount point "iso" and mount the CD image "image.iso"
$ sudo mkdir /media/iso && sudo mount -o loop image.iso
To unmount the ISO and clean up the /media directory
$ sudo umount /media/iso && sudo rmdir /media/iso
Always good to know the terminal commands, thanks nixCraft.

  • Add a script to nautilus
$ cd ~/.gnome2/nautilus-scripts && sudo gedit mount
Add this text to make the 'mount' script
#!/bin/bash
#
# nautilus-mount-iso
gksudo -u root -k /bin/echo "got r00t?"
sudo mkdir /media/"$*"
if sudo mount -o loop -t iso9660 "$*" /media/"$*"
then
if zenity --question --title "ISO Mounter" --text "$* Successfully Mounted.
Open Volume?"
then
nautilus /media/"$*" --no-desktop
fi
exit 0
else
sudo rmdir /media/"$*"
zenity --error --title "ISO Mounter" --text "Cannot mount $*!"
exit 1
fi
Now make the umount script
$ sudo gedit umount
and here is the code
#!/bin/bash
#
for I in "$*"
do
foo=`gksudo -u root -k -m "enter your password for root terminal
access" /bin/echo "got r00t?"`
sudo umount "$I" && zenity --info --text "Successfully unmounted /media/$I/" && sudo rmdir "/media/$I/"
done
done
exit0
Set the files as executable
$ chmod 755 mount umount
This should have added the two new scripts to the context menu. Thanks to animacide @ ubuntu forums.

  • Install gMount
$ sudo apt-get install gmountiso
While it's good to know the other methods this one is by far the easiest to use. Thanks gMount

No comments:

Post a Comment