how to extract the contents of a .iso dvd movie disk image file

I decided to back up some of my movie DVD’s to .iso files. This is straightforward under un//x: <code>dd if=/dev/cd0 of=file.iso</code>. However, the files would not mount on my mac’s. A little research revealed the following technique:

  • become root

  • attach a virtual disk device to the .iso file

  • mount the virtual device

  • copy the contents somewhere

  • unmount the virtual device

  • detach the virtual device from the file

  • drop root privileges

this can be accomplished with the folowing commands. for the follwing, the file is named myfile.iso, and the output will be put in a directory named myfile:

bail(){
        echo $1 >&2
        exit 1
}

iso=myfile.iso
dir=`basename $iso .iso`
[ -d $dir ] && bail "output directory $dir already exists. i quit."
mkdir $dir || bail "cannot create output directory: $dir"

# get unused vn device (vn[0-3] possible)
vn=
used_vns=`mount | cut -f1 -d' ' | grep dev/vn`
if [ -z "$used_vns" ] ; then
        vn=/dev/vn0
else
        for f in /dev/vn// ; do
                if ! echo $used_vns | grep $f >/dev/null 2>/dev/null ; then
                        vn=$f
                        break
                fi
        done
fi
[ -n "$vn" ] || bail "no unused vn device available."

su - root

mnt=/tmp/mnt.$dir
mkdir $mnt || bail "unable to create mount point: $mnt"
/usr/libexec/vndevice attach $vn $iso
mount_cd9660 $vn $mnt

cp -R $mnt/// $dir

umount $mnt
/usr/libexec/vndevice detach $vn
rmdir $mnt

exit \# CTL-D - drop root.