Packet Writing Without Tears: How to use Rewritable Optical Media in Ubuntu
Pedro A. López-Valencia
python -c 'print "cGFsb3BlenZAZ21haWwuY29t".decode("base64")'
The Linux kernel supports packet writing on read-only and rewritable media since kernel 2.6.8, as was the case in Hoary. Yet I only managed to have it work consistently in Breezy. It took some head scratching, but then it hit like a truck: You don't need to be a rocket scientist to do it!!!. But trying to understand how to do it can make a grown man cry.
What the heck is Packet Writing?
Good question! One of the design goals of the UDF filesystem was to allow incremental data addition to optical media. That is, to be able to write packets of data. In essence it allows one to use a CD or a DVD as an oversized floppy disk. In fact, many of you may have used EasyCD, Roxio's Write-On-CD, Nero InCD, or some other commercial product in MS Windows to read and write CDs, particularly CDRWs, this way.
As it is the case with floppy disks, reliability is poor; any glitch and your data is done for. Furthermore many software vendors in the MS Windows world have managed to make their implementations incompatible to each other, to the point that you may not be able to open for writing a disk created with a different utility, and even fail to read it. And they may claim to use the same UDF format version!
In other words, if you think you will be doing your critical data backups with packet writing instead of old-fashioned CD mastering and burning or tape backups or whatnot, you are playing with fire. Now that I've given you dire warnings, let me tell you that packet writing has its uses. It is up to you to take the risk or not.
The ingredients
Although the kernel has support for packet writing, you need to install the user space tools to be able to access the kernel services. Enable the universe repositories and:
Code:
sudo apt-get install udftools
Now add the cd writer to the init files:
Code:
sudo <your_editor> /etc/default/udftools
In my particular case I'm using a CD writer in /dev/hdd, thus I edited the file to contain this line:
Do read the comments in that file but don't bother trying to be creative with the device filenames defined in NEWINTNAMES, else you'll have access permissions trouble later on.
Now, set up your drive:
Code:
sudo /etc/init.d/udftools start
This init script loads the kernel module and sets up the link between the block device (/dev/hdd in this case) and the virtual packet drive device /dev/pktcdvd/0 (there is only one device defined and it gets the first alllocated name). If you want to know more, I strongly recommend you read the manual pages for mkudffs, cdrwtool and pktsetup.
Formatting your CD-RW
Take a CD-RW or DVD-/+RW and format it:
Code:
sudo cdrwtool -t 4 -d /dev/hdd -q
Go brew a carafe of cofee and grab some muffins. Drink slowly... There are several options you can set up including the UDF version, you'll find that information in the manual pages.
cdrwtool burns at a speed of 12x by default, yet most CDRWs and DVD-/+RWs, particularly the cheap ones, support slower burning speeds. 4x seems to be a very common maximum speed for rewritable media, so I've put it in the example above. It is always a good idea to define explicitly the max writing speed of your media, or formatting will fail.
Before you start formatting your CD, make sure that you have DMA active in your burner; else you'll get funny formatting errors and failures. By default, Ubuntu's kernels do not activate DMA busmastering on anything different to PATA disks, because older CD readers and burners tend to belly up when you activate DMA in the IDE bus and lock up the system.
In order to activate permanently DMA, you must edit your /etc/hdparm.conf. Suppose you have a CD or DVD burner in /dev/hdc then you would add the following lines:
Code:
/dev/hdc {
dma = on
io32_support = 1
}
/etc/hdparm.conf is read every time your box boots up. If you can't wait, you can activate the settings from the command line too. Open a terminal window and type:
Code:
sudo hdparm -c1 -d1 /dev/hdc
Mounting your cd
There is only one thing to consider. You need to use the special packet writing device, not the normal disk device!!! Like this:
Code:
sudo mount -t udf -o utf8,noatime /dev/pktcdvd/0 /your/mount/point
I've added the utf8 option because that's the default filesystem encoding in Ubuntu, and noatime because that reduces drastically the number of access writes to the disc. This is particularly important if using a DVD-/+RW, because writable DVDs are programmed to allow 1000 writes, not one more!!!
Making the CD/DVD-RW writable by you
Before you start using your CD-RW, you need to make it writable by other users different to root:
Code:
sudo chown 777 /your/mount/point/.
Note the dot at the end.
Making a permanent addition to your system
Now you are ready to set up your system to mount and unmount your CDs without effort. Create an entry in /media:
Code:
sudo mkdir -p /media/cdwriter
and add the following to /etc/fstab:
Code:
/dev/pktcdvd/0 /media/cdwriter udf user,noauto,noatime,utf8 0 0
You will be able to mount the CD/DVD-RW by double-clicking on an icon in the computer browser, if using Ubuntu. If using KDE, you are on your own.
Bookmarks