Notes about Linux packet writing

Updated: 2005-09-02
Created: 2002

Linux, the kernel, supports (mostly) either packet writing or something similar. Packet writing is a mode of writing to writable or rewritable CDs and DVDs that is incremental, that is block by block, instead of track by track, and with a lot less space overhead than .

Packet writing therefore allows one to handle CDs and DVDs that support it in part like a regular random access disc drive.

Types of CD and DVD media

CD and DVD media fall into thre categories depending on their rewritability:

Or put another way:

Block IO and CD and DVD media

The block IO subsystem of recent kernels can use rewritable media as if they were big floppies, writing to them directly, but this is somewhat slow; it cannot write at all to writable or erasable media, which traditionally have been written using bulk image writers like cdrecord (or Burgner) for CD-R and CD-RW or dvd+rw-tools for DVD+R, DVD+RW, DVD-R and DVD-RW.

The packet writing driver pktcdvd is a wrapper around a block device, and grabs the IO requests that would have gone to the IO device and assembles them in packets that are then sent to the CD or DVD drive in packet mode.

This has two important advantages:

However, because of various mishaps, not all drives are supported by the packet writing driver. Here are lists of drives known to work with it:

Software needed for packet writing

For packet writing these different types of software are needed:

The pktcdvd driver in the kernel
This driver comes in many different versions for different kernel versions (here is the ancient original version), and some versions have to be patched to add useful functionality or correct mistakes.
Kernel versions 2.16.12 and later have a driver that does not need to be patched; for other kernel versions follow the instructions here and here. But upgrading to the latest kernel is a lot better. The pktcdvd driver can support an old or a new API, and the new API was introduced in version 0.20 and it is important to make sure that it is available. You can check the version of the driver looking at the kernel logs for the version information it prints when the driver is initialized.
The utilities to control the driver
These utilities allow wrapping the packet driver around a block device, they are the udftools package. The name comes from UDF, the filesystem used most often for packet writing, but the package includes packet writing utilities that are not UDF specific.
If your pktcdvd driver is version 0.20 or later offering the new API, the package, if version 1.0.0b3 or earlier, must be patched as described here. Recent binary packages for udftools from most distributions already have the patch.

Preparing CDs or DVDs for packet writing

Because CD and DVD media can be used in several different modes, they often need to be physically formatted for the specific use they are put to.

CD-R, DVD+R, and DVD-R media cannot be formatted, because they are write-once; the writing mode is instructed to the drive writing to them, and the packet writing driver chooses the right mode.

MO and DVD-RAM media are as a rule ready to use, having been hard-formatted during manufacturing.

CD-RW, DVD+RW, DVD-RW can be formatted in several different modes, and it is critical that they be formatted in the right mode for use in packet writing:

Wrapping the packet writing driver

In order to use the packet writing driver it must be wrapper around the ordinary CD or DVD block driver, so reads or writes to the packet driver device are reflected onto the actual CD or DVD device.

This is done using the pktsetup utility from the udftools package, in one of two ways:

Old API
Using the old API, for pktcdvd versions before 0.20, one must create (or have created by automagic systems like devfs or udev) enough devices like /dev/pktcdvd0. This can be done for example with:
for I in 0 1 2 3; do mknod /dev/pktcdvd"$I" c 97 "$I"
Once these devices are created, the wrapping can be done with
pktsetup /dev/pktcdvd0 /dev/dvdwriter
New API
This requires the most recent udftools (version 1.0.0b3 as of 050902) with the new API patch. With the new API the packet writing device gets created with whatever name one chooses as the first argument of pktsetup, under the /dev/pktcdvd/ directory, for example with:
pktsetup 0 /dev/dvdwriter
which creates /dev/pktcddvd/0 (note the slash). The /dev/pktcdvd/ directory will also contain a control special file for the use of pktsetup, which should not be used directly.
Either way the wrapping packet writing device, for example /dev/pktcdvd0 or /dev/pktcdvd/0, will then be available for reading and writing to.

Creating and using a filesystem

Once the disc has been prepared and the packet writing deviced wrapped, it is possible to start writing to and using the disc in read or write mode.

For fully rewritable devices like MO, DVD-RAM and DVD+RW (and DVD-RW once in packet writing mode) one can in theory format the disc with and use any filesystem, including the classic ext2 and ext3.

However because even fully rewritable discs of that type tend to have limited write cycles, or very slow rewrite, it is usually best to use a filesystem designed keeping this is mind, like UDF.

Packet writing hints

Error messages in the log saying the medium is read-only
For some drives and/or media, many Linux kernel releases up to and including 2.6.16 could not do writes. This seems to have been fixed in 2.6.17.7 at least. This problem is accompanied by error messages like end_request: I/O error referring to the CD/DVD writer being used. These errors have nothing to do with packet writing, but rather with the CD/DVD writing layer.
Use of idescsi
In recent releases of the Linux 2.6 kernel there is no need of using the ATAPI/SCSI wrapper, idescsi for packet writing. You can use the IDE/ATA device name directly.

Packet writing resources