HOWTO: Nautilus script to mount/unmount .iso files
I recently found a Nautilus shell script on an older post to the forum that could mount .iso files, but it couldn't handle spaces in filenames or mount more than one file at once. After some struggle I've come up with these scripts which handle multiple concurrent mounts and filenames with spaces. You'll want to save these under ~/.gnome2/nautilus-scripts/ and make them executable:
Mount:
File:~/.gnome2/nautilus-scripts/iso-mount.bash |
#!/bin/bash # for I in "$*" do foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"` sudo mkdir /media/"$I" sudo mount -o loop -t iso9660 "$I" /media/"$I" && nautilus /media/"$I" --no-desktop done done exit0 |
Unmount:
File:~/.gnome2/nautilus-scripts/iso-umount.bash |
#!/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 |
To use either one just right-click on the .iso file and use scripts -> mount.
Notes
- NOTE: The ISO file has to be in your home directory for this script to work.
HOWTO: Nautilus script to mount/unmount .iso, .nrg and .bin/.cue files
Below you will find Nautilus scripts that allow you to mount cdrom images in .iso, .nrg or .bin format.
You can mount multiple .iso or .nrg files, and up to 8 .bin files.
A shortcut is placed on your desktop for each mounted image for easy access.
Be sure to complete step 7, otherwise your new Nautilus scripts will not be available for use.
Most of the work was already done by the author of the Mount-ISO service menu for KDE.
1. Add the universe repository: http://easylinux.info/wiki/Ubuntu#How_to_add_extra_repositories
2. In order to mount .bin files, you need to install cdemu.
cdemu requires that you have the correct linux-headers package installed, so open a terminal, and choose the option that corresponds to your system.
Intel Pentium:
Code: |
sudo apt-get install linux-686 linux-image-686 linux-headers-686 linux-restricted-formats-686 |
AMD K Series (Duron, Athlon, Sempron):
Code: |
sudo apt-get install linux-k7 linux-image-k7 linux-headers-k7 linux-restricted-formats-k7 |
Older legacy PC (Intel Pentium Pro or 486):
Code: |
sudo apt-get install linux-386 linux-image-386 linux-headers-386 linux-restricted-formats-386 |
Reboot to take advantage of the linux-headers, you've just installed.
3. Install cdemu.
Paste the following code into a text file and save the file to your desktop:
File:~/Desktop/install-cdemu.sh |
#!/bin/bash # # cdemu installer
apt-get install build-essential checkinstall automake1.6 libtool gcc-3.4
cd ~/Desktop wget http://robert.private.outertech.com/virtualcd/cdemu-0.7.tar.bz2 tar xjf ~/Desktop/cdemu-0.7.tar.bz2 cd ~/Desktop/cdemu-0.7 ls -la /lib/modules/`uname -r`/build make make install
cd ~/Desktop sudo rm -r cdemu-0.7
modprobe cdemu |
Open a terminal:
Code: |
cd ~/Desktop sudo chmod +x install-cdemu.sh sudo sh install-cdemu.sh |
Wait for the installation to finish, then enable the cdemu module:
Code: |
|
Add this line to the end of the /etc/modules file:
Code: |
|
Save the file.
4. Mount-CDImage Nautilus script.
Paste the following code into a text editor and save the file under your nautilus-scripts directory:
File:~/.gnome2/nautilus-scripts/mount-cdimage |
#!/bin/bash # Mount ISO NRG BIN/CUE
# Get filename extension and make it lower-case EXT=`echo $1 | sed -e 's/.*\.//'` EXT_LOW=`echo $EXT | tr 'A-Z' 'a-z'`
# Get the filename without the extension BASE="`echo "$1" | sed 's/\.[^.]*$//'`"
# Mount ISO if [ $EXT_LOW == "iso" ]; then foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"` sudo mkdir /media/"$BASE" && sudo mount -o loop,ro,nodev,noexec,nosuid "$1" /media/"$BASE" && ## Uncomment the next line, if you prefer to have an extra link to the ISO image placed on the desktop. #ln -s "/media/${BASE}" "/home/$USER/Desktop/${BASE}" && gnome-open "/media/${BASE}" fi
# Mount NRG if [ $EXT_LOW == "nrg" ]; then foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"` sudo mkdir /media/"$BASE" && sudo mount -o loop,ro,nodev,noexec,nosuid,307200 "$1" /media/"$BASE" && ## Uncomment the next line, if you prefer to have an extra link to the NRG image placed on the desktop. #ln -s "/media/${BASE}" "/home/$USER/Desktop/${BASE}" && gnome-open "/media/${BASE}" fi
# Mount BIN/CUE if [ $EXT_LOW == "cue" ]; then
# Find a free node to mount NODE=$((`cdemu -s | cut -f 8 -d " " | grep 0 -n -m 1 | cut -c 1`-2))
if [ $NODE -lt "0" ]; then zenity --info --text "You can not mount any more BIN/CUE files." fi
# Node needs to be between 0 and 7 if [ $NODE -ge "0" -a $NODE -le 7 ]; then foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"` sudo mkdir -p "/media/${BASE}" && cdemu $NODE "$1" && sudo mount -t iso9660 /dev/cdemu/${NODE} "/media/${BASE}" && ln -s "/media/${BASE}" "/home/$USER/Desktop/${BASE}" && gnome-open "/media/${BASE}" fi
# If directory is empty, then release cdemu if [ "$(ls -A /media/${BASE})" ]; then echo else cdemu -u $NODE fi
fi
# If directory is empty, then remove empty directory if [ "$(ls -A /media/${BASE})" ]; then echo else sudo rmdir /media/"${BASE}" fi |
5. UnMount-CDImage Nautilus script.
Paste the following code into a text editor and save the file under your nautilus-scripts directory:
File:~/.gnome2/nautilus-scripts/unmount-cdimage |
#!/bin/bash # Unmount ISO NRG BIN/CUE
BASE="$1"
# Get filename extension and make it lower-case # EXT_LOW will be iso, nrg, cue or nonsense EXT=`echo $1 | sed -e 's/.*\.//'` EXT_LOW=`echo $EXT | tr 'A-Z' 'a-z'`
# Isolate the the basename without the extension (in case this is not the case already) if [ $EXT_LOW == "iso" -o $EXT_LOW == "nrg" -o $EXT_LOW == "cue" -o $EXT_LOW == "volume" ]; then BASE="`echo "$1" | sed 's/\.[^.]*$//'`" fi
# Release /dev/cdemu according to whether BIN uses /dev/cdemu0 or /dev/cdemu/0 foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"` DEV="`mount | grep "$BASE" | cut -f1 -d " "`"
if [ ${DEV##/dev/cdemu/} -ge 0 -a ${DEV##/dev/cdemu/} -le 7 ]; then cdemu -u ${DEV##/dev/cdemu/} fi
if [ ${DEV##/dev/cdemu} -ge 0 -a ${DEV##/dev/cdemu} -le 7 ]; then cdemu -u ${DEV##/dev/cdemu} fi
# Unmount foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"` sudo umount /media/"${BASE}" sudo rmdir /media/"${BASE}" sudo rm /home/$USER/Desktop/"${BASE}" |
6. Create-CUESheet Nautilus script.
This Nautilus script creates a .cue file from a .bin file, if the .cue is missing. A .cue file is required to mount a .bin file. This only works for basic .bin files. If your .bin file happens to be a multi-track CD image, you will need specialized software to create a more advanced .cue file.
Paste the following code into a text editor, and save the file under your nautilus-scripts directory:
File:~/.gnome2/nautilus-scripts/create-cuesheet |
#!/bin/bash # Create CUE for BIN
# Isolate the filename without the extension. BASE=`echo "$1" | sed 's/\.[^.]*$//'`
cat <<> "${BASE}.cue" FILE "$1" BINARY TRACK 01 MODE1/2352 INDEX 01 00:00:00 EOF |
7. Open a terminal:
Code: |
sudo chmod 700 ~/.gnome2/nautilus-scripts/* |
taken from http://doc.gwos.org/index.php/Mount_ISO_script