IgnorantGuru's Blog

Linux software, news, and tips

Script: mountiso

«Downloads

Download Links:
Script: downloadbrowseauthenticateinstructions
Debian/Ubuntu: packagesPPA
Arch Linux: AUR
Description: Sets up and performs mounting of ISO files by non-root user
Recommended For: Linux
Requires:
License: GNU GPL v3     * SEE DISCLAIMER *
Related: bic
News: What’s New?
Feedback: commentsissues

 

UPDATE: For a more comprehensive solution to ISO mounting, consider using the newer udevil program. The SpaceFM file manager can also use udevil to mount ISO files automatically when you click them.
 

Overview

Normally on Linux, one must be root to mount and unmount ISO files. mountiso works around this limitation using the method described here. In setup mode it will add two entries to your fstab file (or you can do this manually) to allow it to work. Once this is done you can use mountiso to mount and unmount ISO files as a normal user.

mountiso --help

Sets up and performs mounting of ISO files by non-root user
Usage: mountiso FILE         # mounts FILE to /mnt/iso
       mountiso              # unmounts /mnt/iso
       mountiso [OPTION]     # admin functions   
OPTIONS
--help          displays this usage guide
--setup         sets up system for non-root user mounting of ISO files:
                  a backup of /etc/fstab is made
                  required entries are added to /etc/fstab if needed
                  /dev/loop0 through /dev/loop7 are created if needed
                  (must be run as root)
NOTE
Instead of --setup, you can manually add these lines to /etc/fstab:
 /tmp/mountiso-image.iso /mnt/iso auto ro,loop=/dev/loop7,user,noexec,noauto 0 0
 /dev/loop7 /mnt/iso auto user,noexec,noauto 0 0
and create /dev/loop7, eg:  sudo mknod /dev/loop7 b 7 7
and:  sudo mkdir /mnt/iso


Installation Instructions


Follow the standard Script Installation Instructions. Alternatively, for Debian and Ubuntu a deb package and a PPA repository are available. On Arch Linux, mountiso can be installed automatically using the AUR.

Before using mountiso, you can have it automatically setup your system using:

sudo mountiso --setup

NOTE: On some systems, eg Debian, the loop devices that mountiso adds may be removed when you reboot. To prevent this, edit /etc/modules and add this line:

loop max_loop=8

 
If you don’t want to use ‘mountiso ––setup’ and prefer to configure your system manually, make the following changes:

1) Add these lines to your /etc/fstab file:

/tmp/mountiso-image.iso /mnt/iso auto ro,loop=/dev/loop7,user,noexec,noauto 0 0
/dev/loop7 /mnt/iso auto user,noexec,noauto 0 0

2) Issue these commands to ensure you have seven loop devices and a mount point:

sudo mknod -m660 /dev/loop0 b 7 0
sudo mknod -m660 /dev/loop1 b 7 1
sudo mknod -m660 /dev/loop2 b 7 2
sudo mknod -m660 /dev/loop3 b 7 3
sudo mknod -m660 /dev/loop4 b 7 4
sudo mknod -m660 /dev/loop5 b 7 5
sudo mknod -m660 /dev/loop6 b 7 6
sudo mknod -m660 /dev/loop7 b 7 7
sudo chown root:disk /dev/loop*
sudo mkdir /mnt/iso

If you prefer to use a different loop device than the default (loop7) or a different mount point, edit those settings in the User Defaults section at the top of the script.

Example Usage

# To setup the system:
$ sudo mountiso --setup
fstab backup created: /etc/fstab-mountiso-ac1035da.bak
fstab appended
created directory /mnt/iso
Your system is now setup for non-root mounting of ISO files.

# To mount an ISO file to /mnt/iso:
$ mountiso example.iso

# To unmount:
$ mountiso

6 Comments »

  1. Mounted files shows up in /mnt/iso ok, but down’t show automagically as drives in Thunar or Pcmanfm. How can I fix that?

    Comment by swanson | February 26, 2011 | Reply

    • I don’t know of a way to do that, as strictly speaking it isn’t a drive, just a mounted filesystem. It’s /dev/loop7, but I don’t know how to get them to see that as a drive.

      What I do in pcmanfm-mod is to associate iso files with a script that runs:

      #!/bin/bash
      mountiso "$1"
      pcmanfm-mod -t "/mnt/iso"

      That way when I click on an iso file it is automatically mounted and /mnt/iso opens in a new tab. Then I also have a quick way for running “mountiso” to unmount it (you can either use a keyboard shortcut, or I do it from a chooser script when I right click on the /mnt/iso folder or the iso file).

      Comment by igurublog | February 26, 2011 | Reply

  2. Figured out a way in thunar – you could do this:

    mountiso %f ; thunar /mnt/iso/

    Comment by swanson | February 27, 2011 | Reply

  3. Modifed your mountiso script and fstab to point to a directory in my /home and now mounts show up as disks in the left window of thunar! At least some *.iso’s, some *.img’s did as well but were greyed out and crashed thunar.

    The script is great! I’be tried a lot of mounting scripts nut none have worked – fuseiso segfaulted as well as the gvfs-archive backend. But it doesn’t seem as the loop devices in your script lives between boots? Maybe a short boot script somewhere?

    Comment by swanson | February 28, 2011 | Reply

    • Glad it’s working well for you. You might have a look at this page or similar instructions on increasing the number of loop devices. I don’t know what distro you’re using but with Ubuntu and Arch, the loop devices I add always stay after a reboot, but I’m not sure what else affects that. Thanks for the info.

      Comment by igurublog | February 28, 2011 | Reply

  4. This is what I have in cusotm scripts in Thunar;
    mountisotest && mountisotest %f && thunar /home/mrmedia/ISO

    “mountisotest” is your script only with modified mount point.

    Comment by swanson | February 28, 2011 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 132 other followers