Thursday, November 17, 2011

Backing up your physical media (like CDs / DVDs) including copy protection

When my first floppy discs slowly went unreadable I finally decided to create images of all of my physical media. However this is not as trivial as one would think: A lot of discs (especially games) have copy protections included, so you have to plan what you want to do. My goal is always to create 1:1 copies of the original discs. Please also note that the following information is to the best of my knowledge and / or future hardware may be able to circumvent some of today’s limits (though I doubt that’s too likely).

Without copy protection

ISO / disc dumps

Both terms are equivalent - a file used for optical media (CD, DVD, BlueRay) is usually called an ISO image, while images of other media (floppies, hard discs) often have the ending .img.

These images can be easily created with the UNIX command ‘dd’:

dd if=/dev/<device_you_want_to_make_the_image_from> of=<filename_of_the_image>

Note: While various forum entries praise these commands as the panacea of all copying needs, dd is in fact quite limited or even useless when dealing with copy protections. As dd operates on the UNIX file system, it can only copy the data section of any media - additional information like subchannel data is not visible on this layer and thus cannot be saved. Additionally dd will abort at any read error (or alternatively it will write zeros or skip those sectors completely) - even the most simple protections will check if the error is still there, which wouldn’t be the case any more. And dd will only save the first track of a disc, making it worthless to create copies of Mixed Mode or Audio CDs.

BIN / CUE (/ TOC)

This format has a lot of similarities to the ISO format - in fact, if the media has only a single session the resulting .bin file is exactly the same as the ISO file from above. The difference is that it is possible to store several tracks at once: The .bin file contains the binary data, the .cue file tells where and how to split the file for the individual tracks.

While the format is not an official standard it is easy to understand and has broad support among programs (e.g. almost every burning software and DOSBox, which will also play the audio tracks; notable exceptions are Virtual Machines (VMWare, VirtualBox) which are usually limited to ISO images / disc dumps).

The following commands will create the files:

cdrdao read-cd --datafile <filename>.bin --driver generic-mmc:0x00020000 --device /dev/<CD_DEV> <filename>.toc
toc2cue <filename>.toc <filename>.cue

This first command will create this .bin file and a .toc file (instead of expected .cue file). cdrdao is using the toc files internally, but it offers the converter toc2cue to generate the more common CUE file from that. Another thing to note is the option “–driver generic-mmc:0×00020000”: Most modern CD drives will return audio data in little endian order, however most programs expect the data in big endian order. You can also switch the order later, you can find a handly little program on http://www.ssokolow.com/scripts/index.html#swab.py

Note: I couldn’t get cdrdao to create usable images of copy protected discs, though the options “–read-raw” and “–read-subchan=rw_raw” sounded like they could do so (though the later option will create BIN/CUE files which are not compatible with other programs).

Copy protected discs

Old protection systems (- ~2002)

Old protection systems are based on defect sectors and / or subchannel data. Both of them can be stored with cdrecord:

readcd dev="/dev/<CD_DEV>" -clone -nocorr retries=0 f="<filename>.raw"

New protection systems

… will not work. The reason is simple: The current hardware is not able to create images that are exactly like the original - some programs check for physical properties of the disc, others will create unreachable sectors etc.

While workarounds DO exist it, they require emulation, modified binaries or additional data on the discs. The manufacturers of copy protection mechanisms finally seem to have found a way to really prevent to be able to copy a CD…

Even if the hardware should support all those techniques one day, you still have to invent a new image format to be able to store that information in Linux and extend the burning software to use it.