Working with ISOs and CDR/CDRWs

There are a number of graphical CD-ROM utilities for Linux. Most of these are simply front-ends that call command line tools to do the actual work of building ISOs and burning disks. And graphical tools aren't much help if you're working on servers that don't have a console attached, unless you are running X remotely, perhaps over ssh .With the mkisofs and cdrecord utilities installed, working with ISO images from the command line is very straightforward.

If you've never heard of an ISO, it's slang for an image of an ISO9660 filesystem. The ISO9660 format (along with a couple of common extensions) is the common format of data CD-ROMs.

To make an ISO image to prepare for burning in a CD burner, use mkisofs:

[root@host]# mkisofs -r /home/rob/ > /tmp/rob-home.iso 

The -r tells mkisofs to build Rock Ridge extensions into the resulting image file. This means that long filenames and file permissions will be preserved when the disk is mounted on systems that support Rock Ridge. Linux has great support for RR, and using -r generally makes your life much easier when building disks designed to be used with Linux. Anyone can make an ISO of files that they have read access to; you don't have to be root to run mkisofs. But for the rest of the commands in this hack, you'll likely need root privileges.

Note that mkisofs stores the contents of the directories you specify on the command line, not the directories themselves. In the above example, the ISO will have /home/rob/ mapped to its /, with the contents of /home/rob/ filling the root of the CD.

If you need to make an ISO from an existing data CD, try this:

[root@host]# dd if=/dev/cdrom of=image.iso 

This will create an ISO image of the CD, in all glorious 650+MB, so be sure you have plenty of space before trying this. You may be able to make this go faster by manipulating the bs parameter of dd:

[root@host]# dd if=/dev/cdrom of=image.iso bs=10k 

The optimal setting is usually dependent on your drive and IDE controller, so try a couple of values to see what works best on your system.

To mount an ISO that you've made (either with mkisofs or straight from dd), try this:

[root@host]# mkdir /mnt/iso
[root@host]# mount -o loop,ro -t iso9660 ./image.iso /mnt/iso

If the mount command complains about Could not find any loop device, you might need to load the loopback driver:

[root@host]# modprobe loop 

Once the ISO is mounted, you should be able to cd /mnt/iso and look around at the filesystem contained in the image. If you find problems with it, simply umount /mnt/iso, remove the image file, and try again.

When you're ready to burn an ISO to CDR, try something like this:

[root@host]# cdrecord -v speed=12 dev=0,0,0 -data image.iso

You should specify the writing speed of your burner (or slower) in the speed= option. If you need to erase a CDRW before burning the ISO, try passing the blank= parameter:

[root@host]# cdrecord -v speed=12 dev=0,0,0 blank=fast -data image.iso 

Getting a burner running under Linux isn't as hard as it used to be, thanks to the ide-scsi driver. This is a kernel module that makes IDE (and other) CD burners appear to be SCSI burners, which are much easier to program.

No comments:

Post a Comment