Aug
20
2008

Easily mount iso files as virtual drives in ubuntu

The biggest flaw in Gmount-iso, AcetoneIso ,Furius ISO Mount and mount.sh scripts is that THEY CANNOT MOUNT ISO IMAGES USING THE UDF FORMAT.
I recently download WAIK from microsoft.com and tried mounting it in ubuntu using the following methods, mount.sh(kernel loop module),GmountIso and AcetoneIso.
None of them could mount it correctly.The mount folder contained a single file called readme.txt
This file contained the following message

This disc contains a “UDF” file system and requires an operating system that supports the ISO-13346 “UDF” file system specification.

So I have modified the mount.sh script available at ubuntugeek.com and ubuntuforums.org to mount both iso9660 and udf formats.The trick here is to replace iso9660 with auto.This modification mounts both standard iso9660 and UDF formats.

The modified code is as follows

#!/bin/bash
#
# nautilus-mount-iso
gksudo -u root -k /bin/echo "got r00t?"
sudo mkdir /media/"$*"
if sudo mount -o loop -t auto "$*" /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

Enter the above code in a text editor and save it as mount.sh in your home folder.

When you replace iso9660 with auto ,then the type of format is automatically detected.
This method does not work with images using the HFS format(used in Macintosh)
To mount HFS image files modify the line like this

if sudo mount -o loop -t hfsplus "$*" /media/"$*"

and save this as mounthfs.sh

So you have 2 scripts to mount iso images.
One to mount udf images and the other to mount the standard iso9660 images.

code for Unmount script

#!/bin/bash
#
gksudo -u root -k /bin/echo "got r00t?"
if sudo umount /media/"$*"
then
zenity --info --text "Successfully unmounted $*"
sudo rmdir /media/"$*"
exit 0
else
exit 1
fi

Enter the above code in a text editor and save it as unmount.sh in your home folder.

Execute the following commands in the Terminal (Application|Accessories|Terminal) to make it executable

sudo chmod +x /home/username/mount.sh

sudo chmod +x /home/username/mounthfs.sh

sudo chmod +x /home/username/unmount.sh

Now copy mount.sh , mounthfs.sh and unmount.sh to the nautilus scripts folder using the following commands.Make sure you replace username with your uername.

sudo mv /home/username/mount.sh ~/.gnome2/nautilus-scripts/

sudo mv /home/username/mounthfs.sh ~/.gnome2/nautilus-scripts/

sudo mv /home/username/unmount.sh ~/.gnome2/nautilus-scripts/

Thats it.Right click on any iso image click on Scripts|Mount.sh or Mounthfs.sh.Your iso image will be mounted as an virtual drive.To unmount it right click on the iso image and click unmount.

«

»

About the Author: Bharat Balegere

Bharat Balegere is a 23 year old blogger from Bengaluru. He is a technology enthusiast and loves tinkering with computers and usb drives.

18 Comments + Add Comment

  • wow. thanks very much. this work 100%.

  • Hi, im new to ubuntu, and where do I replace iso9660 with auto. this will be a great help thanks.

  • I did all the tutorial and it does’nt work to me.
    When I clic mount.sh nothing happens and qhen I clic to unmount.sh ask me for a password

  • I did all the tutorial and it also doesn’t work for me (same than Manu).
    I’m on Ubuntu 11.04

  • Syntax highlighting in GEdit is telling me that the syntax is all messed up on these. Noticed that normal quotes were being replaced with ones that BASH is interpreting incorrectly. Copy/pasting these scripts as they are won’t work; they’ll have to be rewritten. It’s probably just the software that you used to post this modifying things.

  • Excellent; I hadn’t found a better solution than yours yet (assuming it works) and am about to try this. I had just done a search/replace in GEdit to fix the quotes myself before checking back to see if you had checked in. Have you tested this in Ubuntu 11.04 yourself yet?

  • Uh oh. Mount script failed with the “Cannot mount $*!” error. I tried it with gksu instead of gksudo, just on a lark, and this time, at least the Zenity dialog “$* Successfully Mounted. Open Volume?” was displayed (unlike when using gksudo), after which it exited as if nothing were wrong, but the image contents are not showing up in /media/$*, for any image I try, whether ISO or UDF. Going to try in terminal with sudo instead of gksudo or gksu, so I can get some feedback on what’s going on. I’ll post here again if I figure anything out (if I have time to)!

    • I just tried in Ubuntu 11.04 Live Cd and it worked fine.
      To unmount you have to right click on the filename and choose umount.sh.Unmounting from the places bar does not work.

  • Messing with gksu got me nowhere. I returned to gksudo, but not quite with your usage. “gksudo -u root -k /bin/echo “got r00t?”” for some reason messes things up for me. Maybe because Ubuntu has no user named root? I don’t know. When I remove that line, the rest of the script doesn’t work when launched from Gnome, because I get no prompt to authenticate with my superuser password. When I use it with all gksudo instead of sudo, the mount command messes up because gksu/gksudo thinks that the -o option is being passed to it rather than to mount. So, when I make the first line after the removed gksudo -u root line use gksudo instead of sudo, run from the terminal, it all works as if it’s using a superuser session that is already open, and the image mounts fine. Launched from Gnome, though, the script still fails to mount the image. When it works from the command line, though, there is a side-effect in Gnome; in the “Places” sidebar, the name of the image remains even after unmounting, and when you click it, you get an error indicating that the shell can’t mount the image. Just an annoyance, really. I think I’ll just stick to mounting my images from the terminal.

    • Very interesting.Thanks a lot for posting your experiments with this script in Ubuntu 11.04
      I am using Ubuntu 10.04 and it works fine.I will try to fix the script in Ubuntu 11.04.

  • I have probably messed around with something to cause us to have differing results; not sure if the fact that I’m running 64-bit has anything to do with it (I wouldn’t think it would), but maybe it’s worth mentioning. I’m going to keep checking in just out of curiosity here.

  • code will not work under 11.04 64 bit,
    still cannot mount

  • worked like a charm, thanks so much!

  • Thanks, but why do I need root access? Can’t I just mount it somewhere in my home folder or /tmp?

  • excellent work!

    works just fine.. used to mount win 8 iso from hdd..

    thanks!

  • Hey Bharat,

    I tried mounting .iso in UDF format on Ubuntu 12.04 64bit, it keeps giving me Cannot mount dialog with every file I tried. If you are still supporting this good work of yours, please do reply.

    Thank you,

Leave a comment