Sometimes it's useful to be able to do the opposite of burning an ISO image to a CD or DVD, i.e. take a data CD/DVD and extract the ISO filesystem image from it. In principle, this should just be as simple as using dd to copy the data from the drive:
$ dd if=/dev/cdrom of=file.iso bs=2048
However, there is a bug in the ide-cd code in the 2.6 kernel (affecting Fedora Core 3 and later) whereby the kernel's readahead mechanism reads past the end of the data on the CD and hence appends garbage to the end of the ISO file. It is this problem that causes spurious mediacheck failures when installing the OS.
Fortunately there is workaround for this problem: the filesystem data at the start of the extracted file can be read using the isosize command to find out exactly how big the ISO filesystem is. The extracted file can then be truncated to the correct size, For people getting mediacheck errors, this provides a sane way of checking that the media has been burned correctly, as the ISO file can be extracted from the media and either compared with the original downloaded ISO image file (e.g. using cmp) or by checking the sha1sum.
The attached isograb script can be used to do this.
For example, with a burned copy of the FC-5 i386 ISO:
$ isograb extracted.iso This is isograb version 0.1 isograb: extracting data from /dev/cdrom to extracted.iso 1588706+0 records in 1588706+0 records out 3253669888 bytes (3.3 GB) copied, 468.063 seconds, 7.0 MB/s isograb: size of extracted.iso is 3253669888 isograb: size of ISO image is 3253669888 bytes
If your CD/DVD is not in the /dev/cdrom device, use the -d devicename option to isograb to specify where the media is, e.g.:
$ isograb -d /dev/cdwriter extracted.iso
The cmp utility can then be used to compare an extracted ISO file with the original, if you still have the original:
$ cmp FC-5-i386-DVD.iso extracted.iso && echo Identical Identical
If there was a difference, the output would be different:
$ cmp FC-5-i386-DVD.iso extracted.iso && echo Identical FC-5-i386-DVD.iso extracted.iso differ: byte 1294869, line 5014
If you don't have the original ISO image, you can use the sha1sum utility to compare the checksum with the distributor's checksum value (e.g. in the SHA1SUM file):
$ sha1sum extracted.iso ed9a852cf77250c3ae111c621d350af5c0b0a29b extracted.iso $ grep FC-5-i386-DVD.iso SHA1SUM ed9a852cf77250c3ae111c621d350af5c0b0a29b FC-5-i386-DVD.iso
Since the two values are the same, the burned DVD is OK.
References
Alan Cox (kernel hacker) on not using the mediacheck facility:
http://www.redhat.com/archives/rhl-devel-list/2006-March/msg01191.html
- Bugzilla entries:
- Reading and Writing CDs Reliably in Linux
http://www.troubleshooters.com/linux/coasterless.htm (wish I'd seen this before I before I wrote the isograb script - rawread from this site does much the same thing, but in what's probably a cleaner way
)