Sunday, January 16

CD packet writing on Linux

The CD packet writing mode on Linux allows you to mount rewritable compact discs as ordinary read/write media. It brought my attention when I was upgrading my Linux kernel to 2.6.10. Apparently, patches to implement packet writing were floating around previously for some time, but now it has made it into the mainline kernel (darn, can't wait until reiser4 is merged).

It is fairly obvious that packet writing support makes using rewritable discs much easier. I have abhorred floppy discs since I got a CD writer. Floppies are so unreliable and their capacity is appalling by modern standards. However, burning CDs involved much overhead - I had to start a burning application, find an unused CD, erase it, create a new compilation, and then finally burn it. That made CDs inconvenient for storing and exchanging small documents of several megabytes.

Probably the biggest disadvantage of packet writing is that you lose about a sixth of the disc capacity - GNOME shows 550MiB free on a fresh 700MB disc. That means that you will have to burn movies the old-fashioned way, otherwise they will not fit.

Packet writing is slower than burning normal images, which is not surprising. I did a small benchmark. Copying a directory of 11 files, about 10 megabytes each, 90MB in total, took about two minutes of real time. My CD burner supports 10x (1500KB/s). I included spin-up time and unmount time. Linux seems to cache writes, so work with the disc is snappy (well, until you fill the buffer), but unmounting takes some time. In theory, the minimum amount of time required would be one minute plus spin-up time. The result is not so bad. If I was burning the data as an image, I would have had to first erase the disc and then wait while lead-in and lead-out were written out in addition to the data itself.

Compatibility with Windows is extremely important. Modern versions support UDF without problems. I just tried to read the CD on Windows XP. It had the title of "LinuxUDF", included the folder "lost+found", and a empty file "Unallocated space", but other files were read properly. Oh, and that darn GNOME created a directory called .Trash-gintas which I had not noticed. Out of curiosity I tried to write to the CD on Windows by drag and drop, and it did not work, therefore Linux CD-RW support is superior.

Here is a guide to get CD packet writing working on Debian GNU/Linux (with udev):

  1. Upgrade the kernel to 2.6.10. If you are compiling it yourself, you will need UDF read/write support and packet writing support (CDROM_PKTCDVD).
  2. modprobe pktcdvd (add pktcdvd to /etc/modules if you want). You obviously do not need it if packet writing support is statically compiled into the kernel.
  3. apt-get install udftools You need not create the device nodes when asked to, they are for the older packet writing interface.
  4. Edit the file /etc/default/udftools. Uncomment the DEVICES declaration, set the value to your CD device, "/dev/cdrom" should work in most cases. You will need to run/etc/init.d/udftools start afterward.
  5. Find an unused rewritable disc, preferably one that supports fast speeds, and insert it.
  6. Run cdrwtool -d /dev/cdrom -q. The CD will be erased and formatted, an UDF file system will be created on the disc.
  7. While the CD is being prepared, which will take a while, mounting can be set up. Create the directory /mnt/cdrw, then edit /etc/fstab, add this line:
    /dev/pktcdvd/0 /mnt/cdrw      udf       rw,user,noauto,noatime 0 0
  8. After the CD has been prepared, mount /mnt/cdrw.
  9. I had some permission problems - /mnt/cdrw was owned by root with no word-write permissions. If you make changes to its permissions, they appear to be saved into the CD. I used chmod 1777 /mnt/cdrw. Maybe there is a better way.
  10. Try copying files to the mounted disc. I especially like the fact that deleting files is trivial. Run umount /mnt/cdrw when you're done playing. If you use GNOME, you should also be able to mount and eject UDF discs by a single click, just like standard CDs. Use the CD-RW icon instead of CD-ROM in the Computer window.

By the way, you can use any file system, not just UDF, but remember to use the noatime option so that the disc is not written to on every read. You do not want to put too much wear on the disc, as they can endure about a thousand rewrites.

No comments: