Mount ISO images with a right click in the Ubuntu file manager (Nautilus)

I recently discovered a handy script for Nautilus to mount an ISO image using the right click context menu. It’s a handy feature that lets you quickly peek inside an iso CD/DVD image (in read-only mode), without messing around typing the typical command line (sudo mount -o loop -t iso9660 myimage.iso /media/iso).

Rather than the original script in the post linked above, I actually like the all-in-one version posted by Derek Frye in the comments … but it seemed a little RedHat-centric, and messed up some characters when I cut-n-pasted it from the comments. Here is my tweaked version here, suitable for Ubuntu:

  1. #!/bin/bash
  2. # adapted from:
  3. if (/usr/bin/gksudo -u root -k -m "enter your password to gain root privleges" /bin/echo "getting root"); then
  4. for i in `/bin/echo $*`; do
  5.     if (/bin/mount | /bin/grep "$i"); then
  6.     # disk is mounted, umount
  7.         if ! (/usr/bin/sudo /bin/umount /media/"$i" && /usr/bin/sudo /bin/rmdir /media/"$i"); then
  8.             /usr/bin/zenity -error –text="cant umount /media/$i and/or rmdir /media/$i"
  9.             exit 1
  10.         fi
  11.     else
  12.     # disk isn‘t currently mounted
  13.    if ! (/usr/bin/sudo mkdir /media/"$i" && /usr/bin/sudo /bin/mount -o ro,loop -t iso9660 "$i" /media/"$i"); then
  14.        /usr/bin/zenity -error -text="can’t mkdir /media/$i and/or mount $i"
  15.        exit 1
  16.    fi
  17.    fi
  18. done
  19. exit 0
  20. else
  21. exit 1
  22. fi

To install this you need to:

  • Copy and paste the script above into a file ~/.gnome2/nautilus-scripts/iso-mounter (ie using the gedit Text Editor)
  • Set the permissions of iso-mounter to executable (chmod +x iso-mounter using the commandline, or right-click Properties using the Nautilus file manager).

To test it out, find an ISO image file using the file manager (or if you don’t have one, download one, like the latest Ubuntu alpha testing image, intrepid-desktop-i386.iso). Right click on the file icon … you should see Scripts in the popup context menu. Roll over Scripts and you will see iso-mounter .. click on it, enter your password when prompted (mounting requires root privilages), and then look in /media … there will now be a directory (like /media/intrepid-desktop-i386.iso) which is a read-only view of your iso file. You can click on the iso-mounter context menu a second time to unmount the iso.

Enjoy !

2 thoughts on “Mount ISO images with a right click in the Ubuntu file manager (Nautilus)

  1. Thanks for the script.
    I’ve also added in the beginning


    so that it will be able to mount ISO images that have names with spaces.

Leave a Reply

Your email address will not be published. Required fields are marked *