Willkommen auf BeltOfOrion.de
 Impressum |  Datenschutzerklärung |  CSS |  XHTML

Linux howtos

A collection of howtos for linux

This section covers some useful scripts that i have accumulated over time. In the future i will add more but at the moment i start with the mount dvd images on the fly script. All script and instructions here are provided with no warranty of any kind. Only use them if you know what you are doing!

Mount and launch dvd iso images with a double click

The Problem:

Who needs physical dvd's today anyway? The only problem with iso images is that mounting and dismounting them manually via the loopback device is kind of cumbersome. So if you have a variety of movies as dvd images on your hard disc and would like to be able to start them in a movie player with a double click read on...

The Solution:

I provide you with a shell script and instructions to mount dvd images on the fly. When sucessfully done iso images can be mounted and started automatically using the totem player. In order to set everything up correctly you need root privileges on your local machine. For using it later user rights will suffice. For the script to work you need totem-xine and the apropriate codecs to play dvd's but you can easily adopt it to your player of choice.

Let's start bash script for mounting dvd images on the fly:

#!/bin/bash -

MOUNT_DIR=~/tmp_iso
ISO_FILE=$1

clear

echo "Mounting iso image"
echo "------------------"

if [ ! -e $ISO_FILE ]
then
  echo "File not found...exiting" 
  exit 1
fi

echo -n "Creating symbolic link at /tmp/image...";
ln -sf $ISO_FILE /tmp/image
echo "done"

echo -n  "Mounting iso image..."
mount /tmp/image
echo "done"

echo -n "Launching totem player on iso image..."
totem /media/iso_image &> /dev/null
echo "done"

echo -n "Unmounting iso image..."
umount $ISO_FILE
echo "done"
download icon  Download movie_mount.sh

You can use the following command to automatically download and install the script to a newly created ~/script directory in your home directory.

mkdir ~/scripts; wget http://beltoforion.de/howto/movie_mount.sh -O ~/scripts/movie_mount.sh
chmod u+rwx ~/scripts/movie_mount.sh 

When executed the script takes the name of the iso image as its only parameter. It then creates a symbolic link to the iso image at /tmp/image. The iso image is them mounted using this link and the loopback device. Afterwards the totem player is started. When the totem player is closed the iso image is dismounted automatically. In order for all this to work add the following line to the file /etc/fstab:

/tmp/image /media/iso_image iso9660 defaults,user,noauto,loop 0 0
The following command will do just that:
echo -e "#mount generic iso image via loopback device\n/tmp/image /media/iso_image iso9660 defaults,user,noauto,loop 0 0" | sudo tee -a /etc/fstab

The new line will instruct the mount command what to do when beeing applied to the location /media/iso_image It will use the loopback device and mount the dvd image provided in /tmp/image as ISO 9660 type of device (which is a CD/DVD) acessible with normal user rights. But all this will not work unless we actually create the mount point used by the script/fstab entries. By default this is /media/iso_image. You can create it by typing:

sudo mkdir /media/iso_image

After creating the mount point the script is ready to work. You can now mount dvd images on the fly using the movie_mount.sh script with any DVD image file as its parameter. Finally you may want to setup your gnome/KDE or whatever your graphical environment is to launch files of type *.iso with the movie_mount.sh when beeing double clicked. How this is done depends on your window manager and is not scope of this howto. But ususally you have to right click on an ISO image and select "Open with other application", and that select movie_mount.sh as this application.