Home

CD/DVD packet writing on Debian GNU/Linux Sarge (3.1)

CONTENTS

1. Introduction
2. Kernel settings
3. Installing udftools
4. Configuring the packet writing device
5. Preparing the media
6. Updating /etc/fstab
7. Problems

1. Introduction

The Linux kernel has for quite a while supported packet writing on writable (and rewritable) CD's and DVD's. Packet writing means that you can write to a CD/DVD in the same way you would write to a usb key, for example. So you no more need to create ISO-images and burn them onto discs, which is very clumsy and slow. The downside is that the discs you write will not probably work on CD/DVD drives which do not support packet writing or do not have packet writing software installed.

This howto is meant especially for Debian Sarge (3.1), but you might find it useful even if you have some other Linux distribution.

UPDATE (18.7.2007): Having tested packet writing extensively, I've noted that various drives have variable support for packet writing. Although in theory almost all current DVD writers should support packet writing, some work quite well, while others work, but not well enough to be useful. Many drives burn ordinary DVD's just fine, but choke into I/O errors when using the Linux packet writing device. I guess this all comes down to buggy DVD-drive firmware. The bottom line is that If packet writing does not work on your drive, first try to upgrade the drive firmware. If that does not help, probably nothing will. Be prepared to connect the drive to a Windows box, as the firmware updater is most likely a Windows-only proprietary program.

2. Kernel settings

Packet writing requires support from the Linux kernel. You should first verify your kernel version:

localhost:/# uname -r
2.6.17-ipsec
localhost:/#

If you are using the Debian standard kernels then this howto may not be useful to you, as the older 2.6.x kernels (such as Debian 2.6.8) handle packet writing a bit differently. In fact, on stock Debian kernels packet writing might work out of the box, but it did not work with my 2.6.17 kernel.

Next you should check if you have packet writing and udf modules loaded:

localhost:/# lsmod|grep udf
udf                    72516  0
localhost:/# lsmod|grep pktcdvd
pktcdvd                22972  2
cdrom                  33760  2 pktcdvd,ide_cd
localhost:/#

If the modules were not loaded, try loading them with "modprobe udf pktcdvd". If you get error messages, such as FATAL: Module pktcdvd not found. then there you might have a problem. It is, however, possible that the driver is not compiled into a module, but straight into the kernel. Nowadays most drivers are compiled as modules, so it is quite likely that you'll have to build your own kernel or get a kernel that has packet writing support. In case you decide to build your own kernel, try googling with words "linux kernel compile" to find some thorough documentation. I can only give a quickstart...

First grab the most recent kernel sources you can find from http://www.kernel.org. Copy the kernel source package to /usr/src and issue the following commands:

localhost:/# apt-get install kernel-package
localhost:/# cd /usr/src
localhost:/usr/src# tar -jxf your_new_kernel_package.tar.bz2
localhost:/usr/src# rm /usr/src/linux
localhost:/usr/src# ln -s your_new_kernel_tree linux
localhost:/usr/src# cd linux
localhost:/usr/src/linux# make menuconfig

While in kernel configuration menu make sure that you select at least the following:

Consult Kernel compilation HOWTO's and guides for all the other choices you have to make. The amount of choices and terms may seem daunting at first, but once you do it a couple of times it gets much much easier. When you've done with the kernel configuration, save the config and exit.

Now we'll compile and install the kernel "the Debian way" with following commands:

localhost:/usr/src/linux# make-kpkg --append-to-version "custom" kernel_image
localhost:/usr/src/linux# cd ..
localhost:/usr/src# dpkg -i your_kernel_package.deb

If you use grub, you should be ready to go. If you don't trust the dpkg's grub update you probably want to check that /boot/grub/menu.lst is setup correctly.

That's it, now do a reboot. If you get weird behaviour and/or kernel panic, read through the Kernel compilation guides once more and reconfigure the kernel again and again until you get a functional system :).

3. Installing udftools

In addition to kernel modules we need a software package called udftools. It is in fact the only piece of software we need in addition to basic Linux tools. If you are using the 2.6.8 kernel that comes with Debian Sarge then you should first try installing udftools with apt-get. I did not have any luck with the Debian version so I had to compile my own udftools.

If Debian udftools doesn't work for you, get the latest version from http://sourceforge.net/projects/linux-udf. To get my udftools to work I had to download a patch from http://web.telia.com/~u89404340/packet.html. You should first compile the udftools without the patch and try if it works. If it doesn't, then apply the patch.

UDFtools is quite simple to install. Just unpack the udftools-1.0.0b3.tar.gz (or whatever version is current) and do a

localhost:/home/samuli/Downloads/udftools-1.0.0b3# ./configure;make;make install

If you find out that you need the patch, do as follows:

localhost:/home/samuli/Downloads/udftools-1.0.0b3# patch < udftools-1.0.0b3.patch

When it asks which file to patch, enter pktsetup/pktsetup.c. It should then apply the patch. Next do the following to reconfigure and recompile udftools:

localhost:/home/samuli/Downloads/udftools-1.0.0b3# make uninstall
localhost:/home/samuli/Downloads/udftools-1.0.0b3# make clean
localhost:/home/samuli/Downloads/udftools-1.0.0b3# ./configure;make;make install

Now that udftools is installed, we'll have to configure the packet writing device.

4. Configuring the packet writing device

UPDATE (18.7.2007): On Debian Etch (4.0) and Ubuntu (at least 6.10+) you only need to edit /etc/default/udftools to enable packet writing. After modifying this file just restart the udftools service and everything should be taken care of for you.

Recent 2.6.x kernels add packet writing devices to /dev/pktcdvd. For example, the first packet writing device is called /dev/pktcdvd/0, the second one /dev/pktcdvd/1 etc. In older 2.6.x kernels the devices were called with names such as /dev/pktcdvd0. Before you proceed, check that you don't already have the required devices:

localhost:/# ls -l /dev/pktcdvd/
totale 0
brw-rw----  1 root cdrom 254,  0 2006-08-06 09:46 0
brw-rw----  1 root cdrom 254,  1 2006-08-06 09:46 1
crw-r--r--  1 root root   10, 63 2006-08-06 09:45 control
localhost:/#

In this case the devices are already present, so the rest of the chapter can be skipped.

Each packet writing device has to be bound to a physical device, such as /dev/hdd (slave device on second IDE channel). This is done with the program pktsetup, which comes with the udftools package. It is quite simple to use:

localhost:/# pktsetup 0 /dev/hdd
localhost:/#

You can replace the "0" with another number if necessary (see below). I had problems with this exact step, but after patching udftools they disappeared. If you try to bind a physical device to a packet writing device that is already in use, you'll see the following error:

localhost:/# pktsetup 0 /dev/hdd
Device node '0' already in use
localhost:/#

For some reason my udev does not create the necessary entries in /dev/pktcdvd. I did not want to mess with udev entries so I added two commands in /etc/init.d/rc.local, which I use as a custom startup file:

#!/bin/sh
# /etc/init.d/rc.local

case "$1" in
start)
  pktsetup 0 /dev/hdc
  pktsetup 1 /dev/hdd
  ;;
stop)
  echo "Removing custom settings"
  ;;
esac
exit 0

If you don't already have a similar startup file, do as follows after you've created the file:

localhost:/# chmod 755 /etc/init.d/rc.local
localhost:/# update-rc.d rc.local defaults

See "man update-rc.d" if you run into trouble.

5. Preparing the media

When the packet writing device is ready, it's time to grab an empty DVD. I have mostly DVD+RW's so I can't comment on how other media works with packet writing. First you'll need to format the media and then create an udf filesystem on it:

localhost:/# dvd+rw-format /dev/hdd
* DVD+RW/-RAM format utility by , version 4.10.
* 4.7GB DVD+RW media detected.
* formatting 9.5\
localhost:/# mkudffs /dev/hdd
start=0, blocks=16, type=RESERVED
start=16, blocks=3, type=VRS
start=19, blocks=237, type=USPACE
start=256, blocks=1, type=ANCHOR
start=257, blocks=16, type=PVDS
start=273, blocks=1, type=LVID
start=274, blocks=2294573, type=PSPACE
start=2294847, blocks=1, type=ANCHOR
start=2294848, blocks=239, type=USPACE
start=2295087, blocks=16, type=RVDS
start=2295103, blocks=1, type=ANCHOR
localhost:/#

In above case k3b had already created an udf filesystem on this disc, so your output may be different. If you want to use CD-RW discs, prepare them with cdrwtool, which is also a part of udftools package:

localhost:/# cdrwtool -d /dev/hdd -q

I have not (yet) tried how reliably these CD's with udf filesystem work, so I can't give any comments on that.

NOTE: in addition to this you will need to modify each CD's or DVD's permissions if you want to write to them as non-root user. See next chapter for more info on this.

6. Updating /etc/fstab

The only thing that is yet to be done is adding entries to fstab. I have two DVD-drives, one at /dev/hdc and one at /dev/hdd. Only the second one is actually a DVD-burner, but to keep things as simple as possible, I created a packet writing device for both. Here are the relevant entries in /etc/fstab:

# /etc/fstab: static file system information.
# "file system" "mount point"   "type"  "options"	"dump"  "pass"

/dev/hdc        /media/cdrom0   iso9660 ro,users,noauto	0 0
/dev/hdd        /media/cdrom1   auto    rw,users,noauto,noatime,async	0 0
/dev/pktcdvd/0  /media/packetcd0 udf    noauto,noatime,rw,users	0 0
/dev/pktcdvd/1  /media/packetcd1 udf    noauto,noatime,rw,users	0 0

Whenever I want to use a device without packet writing I mount it to /media/cdrom0 or /media/cdrom1. When I need packet writing, I mount my CD/DVD to /media/packetcd1. I have /media/packetcd0 bound to /dev/hdc because it would be confusing if /media/cdrom1 and /media/packetcd0 would refer to the same device.

When you have mounted your new CD/DVD, you will encounter a new problem:

localhost:/# mount /media/packetcd1
localhost:/# cd /media
localhost:/media# ls -la packetcd1
totale 1
drwxr-xr-x   3 root root    92 2006-08-06 11:59 .
drwxr-x---  10 root users 1024 2006-08-05 15:07 ..
drwxr-xr-x   2 root root    40 2006-08-06 11:59 lost+found
localhost:/media/packetcd1#

As you can see, /media/packetcd1 is owned by root and nobody else can write to it. You can fix this with following commands:

localhost:/media# chmod -R 775 packetcd1
localhost:/media# chown -R root:users packetcd1
localhost:/media# ls -la packetcd1
totale 1
drwxrwxr-x   3 root users   92 2006-08-06 11:59 .
drwxr-x---  10 root users 1024 2006-08-05 15:07 ..
drwxrwxr-x   2 root users   40 2006-08-06 11:59 lost+found
localhost:/media#

Now root AND the users that belong to the group "users" can write to the media. This modification will be saved to the disk, so there's no need to do it on every mount. To ease preparation of new DVD+RW discs I've created a script that formats and modifies permissions automatically:

#!/bin/sh
# dvd+rw-prepare
#
# Verify that the user has enough privileges to run the script
# This _DOES NOT_ work if you just "sudo". In that case you
# can either modify the script OR remove this check altogether

if [ $(whoami) != "root" ]; then
        echo "This script can be run only by the root user..."
        exit
fi

# Format the disc and create a filesystem onto it

dvd+rw-format /dev/hdc
mkudffs /dev/hdc

# Wait a while to make sure that the drive is finished
sleep 60

# Mount the DVD+RW, modify the permissions and eject it
mount /media/packetcd0
chown -vR root:users /media/packetcd0
chmod -vR 775 /media/packetcd0
umount /media/packetcd0
eject /dev/hdc

Now there's nothing left to be done. Happy copying and enjoy!

7. Problems

I've had only a few problems with packet writing. The worst one, which has (hopefully) gone for good caused the DVD to get stuck into the DVD-drive for good. Then, when I tried to do a shutdown, the computer just got stuck in the last few phases of powering down. Luckily most of the system services had already been stopped, so nothing important broke when I finally decided to pull the plug. This happened 2 or 3 times, which was enough for me.

I believe that the problem was caused at least parly by buggy firmware. Unfortunately my DVD-writer only supports updating firmware on Windows with a special proprietary program. I almost started installing the VMWare Server and Windows 98 to get my firmware updated. Luckily I first tried removing my DVD-ROM drive, which was originally the master drive of the second IDE port. Now my DVD-Writer was alone - as master - in the second IDE port. This seemed to put an end to the misbehavior. I'll let you know if I run into more troubles.

Here's some info on my DVD-Writer (a LG) in case you want to avoid buying it :) :

samuli@localhost:~$ /sbin/hdparm -i /dev/hdc 

/dev/hdc:

 Model=HL-DT-ST DVDRAM GSA-4167B, FwRev=DL11, SerialNo=77D3A7DE5484
 Config={ Fixed Removeable DTR<=5Mbs DTR>10Mbs nonMagnetic }
 RawCHS=0/0/0, TrkSize=0, SectSize=0, ECCbytes=0
 BuffType=unknown, BuffSize=0kB, MaxMultSect=0
 (maybe): CurCHS=0/0/0, CurSects=0, LBA=yes, LBAsects=0
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio3 pio4  
 DMA modes:  mdma0 mdma1 mdma2 
 UDMA modes: udma0 udma1 *udma2 
 AdvancedPM=no
 Drive conforms to: device does not report version: 

 * signifies the current active mode

samuli@localhost:~$

There is another rather annoying problem for which I have not yet found a solution... I can't use DVD-RAM's if I use the packet writing device. The DVD-RAM discs just refuse to mount, even manually with mount -t ext2 /dev/hdc /media/cdrom0. I have also tried applying my DVD+RW-prepare recipe to them, but that does not work, even though it does not give any errors.

Another minor quirk I've found is that if you mount a normal CD-ROM with mount /media/cdrom0 or similar, you can't eject it with command eject /media/cdrom0 or eject /dev/hdc. You'll have to use the command eject /media/packetcd0 or eject /dev/pktcdvd/0. I don't really know WHY it has to be like this, but it just is :).


Samuli Seppänen, University of Turku

Registered Linux user #392780