Simple CD-ROM & ISO image cookbook.

Posted by Steve on Sun 16 Oct 2005 at 15:46

There are many times when you need to work with CD-ROM images (or ISO files) under Linux. This simple cookbook shows you how to accomplish the most common tasks.

Ripping a CD-ROM to an ISO image

Creating backups of CD-ROM images for storage, or to use as installation media for Qemu is a reasonably common task.

If your CD-ROM device is /dev/cdrom you can use the following command to create an ISO image from it:

dd if=/dev/cdrom of=myimage.iso
Mounting an existing ISO image

If you've made a previous backup of a CD-ROM, or downloaded the ISO image of a new Linux distribution you can mount it to see what is inside the image - before you burn it.

First make sure you have an existing, and empty, directory to mount the image upon:

mkdir -p /mnt/iso

Now mount the image with the loopback module:

modprobe loop
mount -t iso9660 -o loop myimage.iso /mnt/iso
Modifying an ISO Image

Whilst ISO images are readonly when mounted you can "fake" their writability using the unionfs filesystem driver. This cool module allows you to combine two, or more, directories and present their union in a new location.

Under Debian you can build and use this kernel module by running:

apt-get install module-assistant unionfs-source
module-assistant prepare
module-assistant build unionfs
module-assistant install unionfs
insmod unionfs

Once built and installed you can "merge" the mounted ISO image and another directory by running:

mkdir /mnt/tmp
mkdir /mnt/combined
mount -t unionfs -o dirs=/mnt/tmp:/mnt/iso none /mnt/combined

This will give you a directory /mnt/combined containing both the contents of the ISO image you previously mounted in /mnt/iso and the directory /mnt/tmp (which will be empty initially).

Now you can modify the read-only ISO image! Make any additions to the image by modifying the /mnt/combined directory. Instead of modifying the files upon the ISO image though the changes will be saved to the directory /mnt/tmp.

Neat.

Creating an ISO image of a directory

If you have a directory containing files which you'd like to burn to CD-ROM you should first create an ISO image.

Install the appropriate software with:

apt-get install mkisofs

Then create the actual image with :

mkisofs -o /tmp/output.iso  -J -R /path/to/files
Burning an ISO image to CD-ROM

If you've created an ISO image you can burn it to your CD-writer using the cdrecord program. Install it with:

apt-get install cdrecord

Usage is really beyond the scope of this introduction, but in brief you'd first proceed by finding the CD-Writer device upon your system:

root@itchy:~# cdrecord -scanbus
... snip ...
        1,0,0   100) 'HDT72251' '6DLAT80         ' 'V43O' Disk
        1,1,0   101) *
        1,2,0   102) *
... snip ...

Here we have a device labelled "1,0,0". To write an image to that writer we run:

cdrecord -dev 1,0,0 /tmp/output.iso
Creating Checksums of Images

When transferring large files such as ISO images you will almost certainly wish to make sure you've not downloaded/uploaded a corrupt file.

In this case you can list the MD5/SHA1 hashes alongside the file. This allows users to verify that their downloads were correct.

To create a checksum of a file run one of:

md5sum filename
sha1sum fileName

Ideally you should post both sums:

skx@itchy:/mnt$ sha1sum /tmp/iso.iso 
b9f4f11960b90959e8c1ac736bd89dfa986bfa04  /tmp/iso.iso

skx@itchy:/mnt$ md5sum  /tmp/iso.iso
d9866bfa8a52b65c612c74c17710819a  /tmp/iso.iso

(These two commands are contained within the coreutils package - which should be installed upon all Debian GNU/Linux systems)

 

 


Posted by Anonymous (24.58.xx.xx) on Sun 16 Oct 2005 at 22:32
You may also want to consider using readcd (also in the cdrecord package) to create the CD image. It has several error-detection/correction features that may be useful for CDs that are not in perfect shape.

[ Parent | Reply to this comment ]

Posted by Anonymous (194.237.xx.xx) on Mon 17 Oct 2005 at 11:59
And also, you should consider NOT using ide-scsi because it's deprecated, buggy, not supported - and not working. dev=ATAPI:/dev/hd[abcd] is the better way.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Mon 17 Oct 2005 at 12:06
[ Send Message | View Steve's Scratchpad | View Weblogs ]

That's a whole subject I'm just going to avoid .. !

Steve
--

[ Parent | Reply to this comment ]

Posted by ybiC (68.99.xx.xx) on Mon 17 Oct 2005 at 14:07
[ Send Message ]
Am I correct in understanding that your "ide-scsi... dev=ATAPI..." statement applies to Linux kernel 2.6 and not 2.4?

[ Parent | Reply to this comment ]

Posted by Anonymous (67.163.xx.xx) on Mon 17 Oct 2005 at 22:07
yes, you are.

[ Parent | Reply to this comment ]

Posted by Anonymous (212.199.xx.xx) on Tue 25 Oct 2005 at 19:46
I puzzled that no one has yet suggested cdrdao instead of the problematic cdrecord...
IMHO, cdrdao is the perfect selection for burning whole ISO files, without social issue's involved ;)

[ Parent | Reply to this comment ]

Posted by Anonymous (80.58.xx.xx) on Wed 2 Nov 2005 at 15:43
Sorry, you're wrong. ATAPI is deprecated too, ATA should be used instead. That is: dev=ATA:/dev/hd[abcd]

[ Parent | Reply to this comment ]

Posted by Anonymous (195.142.xx.xx) on Tue 18 Oct 2005 at 13:49
Why use dd while we have the glorious cat? While dd is also ok, it is not really necessary if you don't plan to crop the image or perform strange EBCDIC transformations... I think it's simpler to write just:
tonguc@terra:~$ cat /dev/cdrom > cdrom.iso

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Tue 18 Oct 2005 at 13:57
[ Send Message | View Steve's Scratchpad | View Weblogs ]

Personal preference really.

Although with dd you can also do things like set the block size, or be explicit about the size if you wish..

Steve
--

[ Parent | Reply to this comment ]

Posted by Anonymous (216.160.xx.xx) on Mon 14 Nov 2005 at 02:51
I did some research on the subject of reading iso images from CDs and found that cat can be very unreliable. I found a very useful page by Steve Litt on how to get a good image using isoinfo and dd. It teaches you how to make a decent script, or enter a few easy commands to get a pretty good image with none of the caveats of using cat or blindly using dd. Last I checked, the page was at http://www.troubleshooters.com/linux/coasterless.htm

[ Parent | Reply to this comment ]

Posted by rmcgowan (143.127.xx.xx) on Tue 18 Oct 2005 at 17:21
[ Send Message ]
This is the first I've heard about 'unionfs'. I presume, based on your description, that to preserve the 'changes', I'd have to build a new ISO image based on the union mount point?

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Tue 18 Oct 2005 at 17:24
[ Send Message | View Steve's Scratchpad | View Weblogs ]

Yes that is correct.

(Although if you remount the original ISO / CD-ROM with the same temporary directory then things will be persisted).

If I get the time I'll write something focussed completely upon unionfs - it is a very useful filesystem driver, with a lot of interesting uses.

Steve
--

[ Parent | Reply to this comment ]

Posted by Anonymous (200.123.xx.xx) on Wed 19 Oct 2005 at 14:17
UnionFS is the magic part in the last Knoppix releases where you can 'write' on the root filesystem (add new programs, etc)

[ Parent | Reply to this comment ]

Posted by Anonymous (68.239.xx.xx) on Sat 22 Oct 2005 at 23:22
According to the mkisofs man page -hide-joilet should take a glob argument. Is that missing from the example, or is -J the glob pattern to match?

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Sun 23 Oct 2005 at 13:23
[ Send Message | View Steve's Scratchpad | View Weblogs ]

There was a missing argument, I've just removed that flag for the moment as it doesn't make sense in a simple example.

Good catch!

Steve
--

[ Parent | Reply to this comment ]

Posted by chaw (72.224.xx.xx) on Sat 23 Feb 2008 at 16:49
[ Send Message ]
Instead of the module-assistant command sequence, we may use the shorter, if more cryptic, 'm-a a-i unionfs' (or 'module-assistant auto-install unionfs').

[ Parent | Reply to this comment ]

Posted by Anonymous (190.139.xx.xx) on Fri 18 Jul 2008 at 04:33
i can't believe creating a iso image from a cd was so terribly simple. (i googled a lot for this)
thanks a lot, is a very very useful note.

[ Parent | Reply to this comment ]

Posted by Anonymous (2001:0xx:0xx:0xxx:0xxx:0xxx:xx) on Tue 27 Sep 2011 at 05:32
readom is the modern Debian replacement for readcd, from the wodim package.

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

Which init system are you using in Debian?






( 1066 votes ~ 7 comments )