Jul 102011
 

gcdemu-logoI was in need to mount some image from Nero, and so i discovered an useful small program: CDEmu.

CDEmu is a CD/DVD-ROM device emulator for linux, licensed under GPL v2 or later. It is a from-scratch rewrite of the legacy CDEmu project, which was started by Robert Penz.

And while i was searching for some documentation i found this useful from Gentoo Forum, a bit old, but still good:

Now that CDemu 1.0.0 is in Portage i decided to update my Nautilus mount script. What does it do? You Just right-click on an image, choose Scripts, disk-mount. It will load your image into an available device, your desktop’s automounter does the rest. Easy. CDemu supports all kinds of images, as opposed to mount -o loop, which can only handle iso. Also, you don’t need root rights to mount.




The script can also be adapted to run from the command line. Just replace occurences of zenity --error --text with echo and use the script like this: disk-mount /path/to/image

Requirements: CDemu 1.0.0 running in daemon mode, Zenity

First, emerge cdemu (unmask it first) and zenity. I recommend setting the devices to a higher value in /etc/conf.d/cdemud, else you can only mount one image at a time.
Start the daemon ( /etc/init.d/cdemud start ) and set it to start automatically at bootup ( rc-update add cdemud default )
Make a script in /home/*user*/.gnome2/nautilus-scripts and call it disk-mount or something. Paste this into the file and make it executable:

#!/bin/bash
 
# CD image mounter for CDemu 1.0.0
# v0.2 by haarp
# Todo: Make it possible to parse more than one file at once ($2, $3, etc.)
 
# Make sure the daemon is running
if pgrep cdemud >/dev/null; then
:
else zenity --error --text "CDemu daemon is not running, aborting."; exit 1
fi
 
# Make sure we have a free device and save lowest free dev in $DEV
DEV=$(cdemu -b system status | grep "N/A" | head -n1 | awk '{print $1}')
if [ ! "$DEV" ]; then
zenity --error --text "You can not load any more images."; exit 1
fi
 
# Get filename extension and make it lower-case
EXT_LOW=$(tr '[:upper:]' '[:lower:]' <<< "${1##*.}")
 
SUPPORT="0"
 
# Automatically parse supported extensions and put them in $supported
supported=(); while read line; do supported+=(${line##*:}); done < <(cdemu -b system supported-parsers)
 
for ELEMENT in "${supported[@]#.}"; do      # If extension is part of supported extensions...
if [ "$ELEMENT" = "$EXT_LOW" ]; then
SUPPORT="1"
fi
done
 
if [ "$SUPPORT" = "1" ]; then
 
# Execute CDemu, load image into $DEV and save output in $CDEMU
CDEMU=$(cdemu -b system load $DEV "$1")
 
# Test whether it really got loaded. If not, pop message box containing $CDEMU
CDEMULINE=$(cdemu -b system status | grep "$1")
if [ ! "$CDEMULINE" ]; then
zenity --error --text "$CDEMU"
fi
 
# Note: CDemu doesn't return a proper exit value on failure, else below code would work
#if CDEMU=$(cdemu -b system load $DEV "$1"); then
#   :
#else zenity --error --text "$CDEMU"
#fi
 
else zenity --error --text "Selected file is not a supported image."; exit 1
fi

Now right-click on an image, select “Scripts” and “disk-mount”. It will mount the disk if possible. In case of an error, it will give you the error message issued by cdemu. To unload the image, just “eject” the disk.

For .bin images you will need a cue-sheet. Got a script for that too. It assumes that the bin image does only contain one data track;

#!/bin/bash
# Create Cuesheet for BIN images
 
# Isolate the filename without the extension.
BASE=`echo "$1" | sed 's/\.[^.]*$//'`
 
cat << EOF > "${BASE}.cue"
FILE "$1" BINARY
  TRACK 01 MODE1/2352
    INDEX 01 00:00:00
EOF

Limitations:
– Don’t select more than one file, it will only mount the first
– Currently, this script is set to work with daemon-mode cdemud.

I haven’t tested the user-mode cdemud, but the script needs to be modified to work with it

Popular Posts:

Flattr this!

  3 Responses to “Easy image mounting with CDemu and Nautilus”

  1. You can also try my indicator applet Mounty. It uses fuse-utils to mount iso, img, bin, mdf, nrg
    https://launchpad.net/mounty

  2. awk ‘ /N\/A/ { print $1; exit }

    Otherwise very cool! 😉

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*