SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2010-03-05 05:50:35

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,462
Website

Script to quickly mount/unmount an iso file

I got tired of typing the same stuff in a terminal over and over, so put this script together to add to Thunar's custom actions.
If you are looking at .iso files a lot it might be handy. It will make a folder in the current directory, mount the iso file to it (with gksu) and open thunar in that folder. If the iso is mounted already it will unmount it. The folder is deleted once you've unmounted it. You won't be able to edit the iso file, just view it, or copy stuff out of it.
edit 130321: Now modified to use fuseiso - no password needed. Also,the folder is no longer opened in Thunar - that seemed more annoyance than help. (Also works with .bin, .mdf, .img and .nrg files.) You'll need to install fuseiso:

sudo apt-get install fuseiso
#!/bin/bash
# open-iso.sh
# mount .iso file in new folder, unmount if mounted already
# requires fuseiso and libnotify-bin (for notify-send messages)

shopt -s nocasematch
[[ -f $1 ]] && [[ $1 =~ \.(iso|bin|mdf|img|nrg)$ ]] ||  { notify-send "open-iso.sh" "$1 is not a supported file type"; exit 1 ;}
shopt -u nocasematch
foldername=${1}.mount
if grep "^fuseiso[[:space:]]$(readlink -f $foldername)" /etc/mtab >/dev/null
then
	fusermount -u "$foldername" || { notify-send "open-iso.sh" "failed to unmount $1"; exit 1;}
	notify-send "open-iso.sh" "$1 has been unmounted"
else
	[[ -d $foldername ]] && [[ $( ls -A $foldername ) ]] && { notify-send "open-iso.sh" "$foldername is not empty" ; exit 1 ;}
    fuseiso -p "$1" "$foldername" || { notify-send "open-iso.sh" "failed to mount $1"; exit 1;}
    notify-send "open-iso.sh" "$1 has been mounted on $foldername"
fi

exit

As usual, put it in ~/scripts or somewhere handy and add a custom action like '~/scripts/open-iso.sh %f'. Make the appearance conditions "Other Files" and File pattern '*.iso;*.ISO;*.bin;*.BIN;*.img;*.IMG;*.nrg;*.NRG;*.mdf;*.MDF'.

Last edited by johnraff (2013-03-20 16:51:34)


John
--------------------
( a boring Japan blog , and idle twitterings )

Offline

Help fund CrunchBang, donate to the project!

#2 2010-03-05 10:00:55

jotapesse
#! Junkie
From: Algarve, Portugal
Registered: 2009-02-07
Posts: 312

Re: Script to quickly mount/unmount an iso file

Nice!

I just have an ISO shortcut (to a previously created dir) on the side with a custom action (same appearance conditions) to mount the iso file:

sudo mount -o loop -t iso9660 %f /mnt/ISO

and another one to umount it. Not as fancy. wink


On an ASRock VisionX 321B, Asus EeeBoxPC 1501P and EeePC 1000H with Debian Sid/Experimental Xfce 4.10 Linux
How to: Install Xfce 4.10 with upgraded Apps and Plugins

Offline

#3 2010-03-05 18:04:32

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,462
Website

Re: Script to quickly mount/unmount an iso file

Edited it a bit: decided to delete the folder once the iso is unmounted, and added a few checks and error messages to 'notify-send' (it's installed by default in #!).

This kind of stuff is fun - once you've got it set up, the computer does the work! smile

Last edited by johnraff (2010-03-05 18:06:19)


John
--------------------
( a boring Japan blog , and idle twitterings )

Offline

#4 2010-10-20 12:32:41

rabidjoe
#! Member
From: Under My Hat
Registered: 2010-09-24
Posts: 78

Re: Script to quickly mount/unmount an iso file

Excuse the necro-bump but thanks for the tip, using it now myself smile

Offline

#5 2010-10-20 17:22:34

nogg321
Member
From: Birmingham UK
Registered: 2009-09-06
Posts: 35

Re: Script to quickly mount/unmount an iso file

are we talking about statler/debian?
I am and if I insert a cd etc. or a usb stick, the system mounts it and opens thunar for me already!
am I doing something wrong ?!

p.s. I always close thunar and start mc, but it's usefule to see the contents straight away.

regards


Linux - It's not rocket surgery, after all!
web - nigelhoward.site90.com
skype - nogg321

Offline

#6 2010-10-20 20:40:51

luc
#! Die Hard
From: Munich, Germany
Registered: 2010-03-21
Posts: 561

Re: Script to quickly mount/unmount an iso file

nogg321 wrote:

am I doing something wrong ?!

you think/talk about CDs (actual physical discs made of plastic) they are talking about .iso image files (just some file format like any other)

Last edited by luc (2010-10-20 20:41:16)

Offline

#7 2011-10-17 15:56:06

mips
Member
Registered: 2011-07-19
Posts: 41

Re: Script to quickly mount/unmount an iso file

When I run this script on ubuntu 11.10 it works great but it opens another instance of thunar?

Offline

#8 2011-10-18 17:19:28

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,462
Website

Re: Script to quickly mount/unmount an iso file

Yes, it opens a new thunar window with the mounted iso file system. Unfortunately, you need to close that window manually after the iso is unmounted.

To be honest, I think that script has been outdated by the fuseiso package, which lets you mount iso files without having to use root privileges. I might write a new version, which would be much simpler. Meanwhile, check the Arch Wiki.


John
--------------------
( a boring Japan blog , and idle twitterings )

Offline

#9 2012-06-16 16:08:36

jotapesse
#! Junkie
From: Algarve, Portugal
Registered: 2009-02-07
Posts: 312

Re: Script to quickly mount/unmount an iso file

Just an update to this post, using thunar, the following is very simple:

http://forums.debian.net/viewtopic.php?p=285354#p285114


On an ASRock VisionX 321B, Asus EeeBoxPC 1501P and EeePC 1000H with Debian Sid/Experimental Xfce 4.10 Linux
How to: Install Xfce 4.10 with upgraded Apps and Plugins

Offline

#10 2012-06-16 16:27:08

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,462
Website

Re: Script to quickly mount/unmount an iso file

Thank you jotapesse. Fuseiso really makes it simple! smile


John
--------------------
( a boring Japan blog , and idle twitterings )

Offline

#11 2013-03-20 16:56:43

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,462
Website

Re: Script to quickly mount/unmount an iso file

I had to open an iso file multiple times last week, finally got tired of typing my password and rewrote the script to use fuseiso, which makes things much simpler. In fact, although a script gives you more flexibility, if you don't want the error checking and popup notifications you can just put a fuseiso command straight into Thunar's custom actions, as jotapesse pointed out:

jotapesse wrote:

Just an update to this post, using thunar, the following is very simple:

http://forums.debian.net/viewtopic.php?p=285354#p285114


John
--------------------
( a boring Japan blog , and idle twitterings )

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo