Wednesday, March 07, 2007

Cloning a CD/DVD Disc on MacOS Using a Console

MacOS has a handful of good command line tools for working with discs, images and burning devices. Unfortunately direct support for disc cloning is missing.

I wrote a little shell script that makes it very easy to create a 1:1 copy of CD/DVD discs.
#!/bin/sh

DEVICE_NAME=`drutil status | grep dev | cut -d / -f 3`

diskutil unmountDisk $DEVICE_NAME
watch ls -lh /tmp/disk2burn.iso&
WATCH_PID=$!
dd if=/dev/$DEVICE_NAME of=/tmp/disk2burn.iso
kill $WATCH_PID
hdiutil burn /tmp/disk2burn.iso
if test $? -eq 0; then
 rm -r /tmp/disk2burn.iso
 echo 'DONE!!!'
fi
This script uses watch command to display the progress of the dd command that creates an iso dump of the original media. You can get the watch from darwinports/macports. If you don't care about the progress of creating the iso dump, you can just use:
#!/bin/sh

DEVICE_NAME=`drutil status | grep dev | cut -d / -f 3`

diskutil unmountDisk $DEVICE_NAME
dd if=/dev/$DEVICE_NAME of=/tmp/disk2burn.iso
hdiutil burn /tmp/disk2burn.iso
if test $? -eq 0; then
 rm -r /tmp/disk2burn.iso
 echo 'DONE!!!'
fi

The script discoveres the name your DVD drive $DEVICE_NAME at runtime, e.g. disk1 for (/dev/disk1). This requires that the disc is present in the drive before you start the script.

Note: This script won't copy DRM protected discs (DVD movies, protected Audio CDs) :-(

Btw I didn't know what was the correct usage of the words "disk" and "disc", this article from apple makes it clear.

Update(07-03-24): I found a bug in my scripts that I fixed and I changed the scripts so that the DEVICE_NAME is discovered at run time.

No comments: