Efficiently recovering data from a bad DVD

Recently I had to get data, mostly tar files, from a backup DVD made 7 years ago. As it turned out, the DVD was mostly unreadable, the filenames appeared but reading the content resulted in I/O errors. So I tried different DVD recovery/ripping tools to get the data

Recently I had to get data, mostly tar files, from a backup DVD made 7 years ago. As it turned out, the DVD was mostly unreadable, the filenames appeared but reading the content resulted in I/O errors. So I tried different DVD recovery/ripping tools to get the data out - and it took forever. The DVD reader was just endlessly scrubbing around while trying to read the data.
I needed to get the corrupted data out once, i.e. copy the content to an iso file, then mount it, and then try my luck with the data recovery. Here's how:

Get the isoinfo tool

First, get the isoinfo tool. On Mac OS X install cdrtools, on Debian the it is in the libcdio-utils package:

brew install cdrtools           # on OSX  
apt-get intall libcdio-utils    # Debian  

Find the device

On Linux it's usually /dev/cdrom, on Mac OS X you have to find the block device. When I can't find a device on any *nix system I often do this:

ls /dev/ > a  
# insert the DVD
ls /dev/ > b  
diff a b  

In my case the device I was looking for was /dev/disk6.

Find block size and volume size

We're looking for the blocksize and the volume size. Use the the isoinfo tool:

> isoinfo -d  -i /dev/disk6
CD-ROM is in ISO 9660 format  
... several lines omitted ...
Logical block size is: 2048  
Volume size is: 4163469  

Copy the DVD to file

With block and volume size at hand perform the copy:

dd if=/dev/disk6 bs=2048 count=4163469 conv=noerror,notrunc of=dvd.iso  

The noerror and notrunc flags tell dd to skip over erros and to preserve any blocks in the output not explicitely written by dd. To monitor the progress insert a pv (see the man page for details):

dd if=/dev/disk6 bs=2048 count=4163469 conv=noerror,notrunc| pv | dd bs=2048 of=dvd.iso  

Mount the iso file and extract the data

Finally mount the iso as readonly. On Mac OS X the incantation is

hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount dvd.iso  

If the image doesn't show up in finder use DiskUtility to mount the filesystem.
Now you can run various data recovery tools in parallel.