Packet Writing on CDRW and DVDRW media

19 Comments

How to prepare CD-RW and DVD±RW media (formatting, creation of UDF structure) and mount them for use as large floppy diskettes.

Packet writing is a method of writing data on a CD or DVD in small increments. You can even delete or overwrite data like on a floppy diskette. Although packet writing could be a great solution for backups, especially when using the large DVD media, actually it’s not. Rewritable media wear out as you write, move, delete data and there is no way to predict when your files will get corrupted. Many CD/DVD media brands guarantee error-free usage for up to 1000 overwrites.

Anyway, using rewritable media for critical backups is not really recommended, but they can be perfectly used as temporary storage.

Prerequisites

Fedora Core’s official kernel already has packet-writing and UDF filesystem support enabled as modules, so you do not need to make any changes to your kernel’s configuration. The system will load the appropriate modules, in this case pktcdvd and udf, when they are needed.

All you have to do is to add a UDEV ruleset for module pktcdvd, so that the devices are created correctly. This can easily be done by adding rules to a file named "60-udev.rules" in the /etc/udev/rules.d/ directory. It is not recommended to edit the default "50-udev.rules" as this can be updated by Red Hat. We put the number "60" in the filename, so that it is read after the 50-udev.rules file. As root, add the following lines to 60-udev.rules:

KERNEL=="pktcdvd", NAME="pktcdvd/control", GROUP="disk", MODE="0660"
KERNEL=="pktcdvd[0-9]*", NAME="pktcdvd/pktcdvd%n", GROUP="disk", MODE="0660"

Now you should substitute disk with your username, or a group that your user belongs to. Alternatively, you could simply add your user to the group "disk" and leave the above as is. If you have previously loaded the pktcdvd module, you have to unload/reload it for these rules to take effect or simply reboot the machine.

You will also need to install the udftools and dvd+rw-tools packages. The first is absolutely necessary. The second is only needed if you intend to format rewritable DVD media.

Furthermore, you have to be sure that you have write access to your CD/DVD writer device. Assuming that this is /dev/hdc, from a terminal type:

# ls -l /dev/hdc
brw-------  1 jsmith disk 22, 0 Sep 03 18:16 /dev/hdc

The above shows that user "jsmith" has read/write access (rw) to the /dev/hdc device. In fedora, when you login, your user becomes the owner of the CD/DVD writer device, so that he can burn CDs. I strongly advise new linux users to check this out, just to be sure that this detail is not going to cause any trouble.

Finally, you should temporarily deactivate automounting of removable media. We do not want this feature to interfere with the whole process. This can easily be done through your GNOME’s "Removable Drives and Media" preferences. We’ll get back to this later on.

Preparing CDRW media for packet writing

Before you can mount your CDRW disc and use it like a diskette, you have to prepare it for packet writing. This includes blanking, formatting and creating the UDF structure on it. The recommended way of doing this is to use cdrwtool‘s quick setup (-q) option. As root type:

# cdrwtool -d /dev/hdc -q -t 10

The -t option sets the writer’s speed. It defaults to 12x if omitted. Anyway, whatever speed your writer or media may support, this process is going to take very long (over 30 minutes). So, be patient and do not try to eject the media or reboot the machine while cdrwtool is running.

I have to admit that no matter what I have tried so far, cdrwtool, even the CVS version, has never worked for my DVD writer. It worked though on another machine with an old CD writer, so I tend to believe that cdrwtool’s code is pretty much incomplete. More info on this can be found in this blog entry. The point is that you have to try it since it’s currently the only way I know to format a CDRW disc under linux.

Before mounting a CDRW medium for packet writing you need to create a device association with pktsetup (part of udftools). As root type:

# pktsetup pktcdvd0 /dev/hdc

This associates the packet module (pktcdvd) with your recorder and the packet device is placed in the directory /dev/pktcdvd/.

Preparing DVDRW media for packet writing

Now, let’s get serious! Rewritable DVD media offer a great amount of storage space, and with packet writing we can use all these GBs like a normal diskette. Ain’t this a convenience! I use both DVD-RW and DVD+RW discs and have not encountered problems so far. Before you can "packet write" on a rewritable DVD you need to format it. We’ll need dvd+rw-format (part of dvd+rw-tools) for this.

To format a DVD-RW medium:

# dvd+rw-format -force=full /dev/hdc

The -force=full option insures that the whole length of the medium gets formatted. This option is a necessity when formatting an already used disc. Formating a DVD-RW disc puts it in "Restricted Overwrite" mode, so it can be used for packet writing.

To format a DVD+RW medium:

# dvd+rw-format -force /dev/hdc

In this case the -force option can be omitted when the medium is new. It’s necessary though when reformatting a disc.

Create the device mapping as described in the CDRW section. As root:

# pktsetup pktcdvd0 /dev/hdc

Then we need to create the UDF structure on the formatted disc. As root:

# mkudffs --media-type=dvd --udfrev=0x0150 /dev/pktcdvd/pktcdvd0

The options are self-explanatory, but in short:

  • –media-type: The type of medium we use.
  • –udfrev: the revision of the UDF filesystem that we want to create. 0x0201 (rev 2.01) is the default for mkudffs. Revision 0x0150 (rev 1.50) is recommended though in order to avoid compatibility issues between different operating systems.

Mounting rewritable media for packet writing

At first we need to create a new mount point for our rewritable discs. This has to be done once. As root:

# mkdir /media/cdvdrw

Mounting a rewritable medium for packet writing is the same for both CDs and DVDs. As root:

# mount -t udf -o rw,noatime /dev/pktcdvd/pktcdvd0 /media/cdvdrw/

The mount option noatime is of major importance as it prevents unnecessary writes on the media. Make sure you always include it to avoid unnecessary wear. The option rw stands for read/write. Read the mount man page for more info.

Now, as root, you can copy, move, delete, overwrite files like on a normal floppy diskette. Keep in mind that these operations may take some seconds to complete depending on the amount of data being written on the disc, so let the drive finish writing before unmounting.

Unmounting the disc

To unmount the medium just type:

# umount /media/cdvdrw/

To show the active device mappings type as root:

# pktsetup -s

To delete the device association type as root:

# pktsetup -d pktcdvd0

Now, you may finally eject the media…

Special Note: Deleting the device association should not be necessary, but there seems to be a bug in pktcdvd, that will give you trouble if you do so. If, without deleting the device mapping, you mount a normal iso9660 CD or DVD disc in the recorder and then unmount it, you will not be able to eject it. You will have to do it with root:

# eject /dev/hdc

So, keep this in mind. Before you mount a rewritable medium for packet writing you have to set up the device association with pktsetup and after unmounting it, you have to tear down this association.

Who has write access on a rewritable medium?

Right after the disc has been prepared for packet writing, only root is able to actually write data on it. You need to modify the permissions for the disc so that a user can write on it. This only has to be done once for every disc. Having mounted the rewritable medium for packet writing, modify the mount point’s permissions and ownership according to your needs. This has to be done by root. So, if for example you want all the users to be able to modify data on a disc:

  1. As root, insert the disc in the drive
  2. Create the device association with pktsetup
  3. Mount it for packet writing
  4. Change the permissions on the mount point. For our example:
    # chmod 777 /media/cdvdrw

This has to be done once for every disc. Setting the permissions on the mount point without having a rewritable disc mounted has no effect on the disc’s access rights. Keep this in mind.

Mounting as a user

In a normal linux system, a user cannot set up device mappings with pktsetup. Due to the pktcdvd bug I mentioned earlier you have to create and delete the device mapping before and after mounting a disc for packet writing respectively. As a user, you can create an association from a terminal like this:

# su -l root -c "pktsetup pktcdvd0 /dev/hdc"

You will be asked for the root password. An alternative is to use "sudo" without asking for a password, but this will not be covered here.

A normal user is not able to issue a mount command either. This can be done only by root. So, to make things easy for users we need to add a new fstab entry. This has to be done once and will further simplify things as you will not have to type the whole mount command every time. Before making any changes to system files, a good tactic is to keep backups of them. Having backed it up, as root, edit the /etc/fstab file and append this line:

/dev/pktcdvd/pktcdvd0 /media/cdvdrw udf noauto,noatime,rw,users 0 0

From now on, to mount the rewritable medium as a user just type:

# mount /media/cdvdrw/

To unmount just type:

# umount /media/cdvdrw/

To delete the mapping:

# su -l root -c "pktsetup -d pktcdvd0"

Again you will be asked for the root password.

Having the automounter enabled

At this point you may enable automounting of removable media from the GNOME preferences. The automounter by default mounts all CD or DVD media, even UDF formatted, as iso9660. So, prior to mounting the medium as UDF for packet writing, you have to:

# umount /dev/hdc

And then proceed with creating the mapping and then mount as described in the previous paragraph.

A little automation

A little bash script is always a great convenience

#! /bin/bash

# check if /dev/pktcdvd/pktcdvd0 exists
if [ -e /dev/pktcdvd/pktcdvd0 ]; then
	# The following unmount a UDF disc, delete the device mapping
	# and eject the media
	umount /media/cdvdrw/
	su -l root -c "pktsetup -d pktcdvd0"
	eject /dev/hdc
else
	# The following line unmounts a disc that has been mounted by the automounter.
	# Comment it out if you do not use the automounter
	umount /dev/hdc
	# The following creates the device mapping and
	# mounts the disc for packet writing
	su -l root -c "pktsetup pktcdvd0 /dev/hdc"
	mount /media/cdvdrw/
fi
exit 0

This script mounts or unmounts a disc for packet writing. Save it in a file, set the executable attribute for your user, and place it in your ~/bin/ directory. If the bin directory does not exist in your home, create it and do a logout/login. From now on you can execute it by simply typing the script’s filename in a terminal:

# myscript

Common Errors

Here are some :

ctl open: Not a directory

This usually appears when you set up the device association with pktsetup. A proper UDEV rule is missing in fedora, so, when the pktcdvd module is loaded, a /dev/pktcdvd device is created instead of a /dev/pktcdvd/ directory. You can easily overcome this issue by deleting the wrong device and by adding a UDEV ruleset in a /etc/udev/rules.d/60-udev.rules file to get rid of the problem once and for all. As root, delete the device:

rm -f /dev/pktcdvd

The UDEV rules to add:

KERNEL=="pktcdvd", NAME="pktcdvd/control", GROUP="disk", MODE="0660"
KERNEL=="pktcdvd[0-9]*", NAME="pktcdvd/pktcdvd%n", GROUP="disk", MODE="0660"

Now you should substitute disk with your username, or a group that your user belongs to. Alternatively, you could simply add your user to the group disk and leave the above as is. For these rules to take effect you can either unload/reload the pktcdvd module or reboot the machine. Then proceed with the device mapping normally.

Cannot eject medium as a user

The pktcdvd module seems to have a bug. If you do not delete the device mapping and mount a normal CD or DVD disc, unmount it and then try to eject it, it cannot be done. Root can eject it though. From a terminal as root:

# eject /dev/hdc

cdrwtool does not work

Well, I’m not surprised! It does not work with my DVD writer either. Some tweaking with hdparm could solve this problem though.

Further Reading

Although the documentation on packet writing is very limited, more info can be found at:

  1. the packet-writing.txt file included in the fedora kernel docs. (contains only basic information)

Packet Writing on CDRW and DVDRW media by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2005 - Some Rights Reserved

19 responses on “Packet Writing on CDRW and DVDRW media

  1. Gorilla Permalink →

    This is very good how-to, thanks for it!

  2. Someone Permalink →

    Is it possible to read such cds on windows??

  3. George Notaras Post authorPermalink →

    Thanks for your feedback.

    Both CDs and DVDs written with the pktcdvd driver should be readable in Windows. When preparing a CDRW disc for packet writing with cdrwtool without defining a UDF revision, then it defaults to rev 1.50, which is compatible with many operating systems. When creating the UDF structure with mkudffs without specifying a UDF revision, then it defaults to rev 2.01. Anyway, I think there would be no problem reading these CDs and DVDs under Windows. At least I didn’t have any.

    On the other hand, it was not possible to use InCD under Windows to write on a DVD+RW disc, which was previously prepared for packet writing with the pktcdvd driver. This probably happens with both CDRW and DVDRW media. I don’t really know what the problem is in this case or if I miss anything. The disc gets mounted as a simple DVDR, so no writing is allowed.

    I have recently found a UDF verification utility made by Phillips Research, but didn’t have the time to try it.

    I don’t know if this would help in resolving the above issue, but I post this link here if anyone is interested.

  4. Chris Permalink →

    This is one of the most helpful web pages I’ve ever seen (at least, this week). I was ridiculously happy when my simple cp command made the red light on my burner start blinking. Thanks.

  5. George Notaras Post authorPermalink →

    Thanks Chris. I was in the same state of happiness when I finally got it to work. Rewritable optical media prove to be extremely convenient sometimes for temporary storage. I mainly use DVDs because of the large capacity.

  6. Olivier Permalink →

    There’s one additional problem when a user mounts a cd (or dvd) directly from the device (/dev/hdc, for instance) which is still bound to /dev/pktcdvd0. It seems the kernel (2.6.14.3 in my case) is only able to read to the size of the /dev/pktcdvd0 device, which leads to the end of your cd being temporarily unreadble.
    After “pktsetup -d pktcdvd0” and perhaps a remount of /dev/hdc, everything returns to normal. I will post a bugreport when I get the time.

  7. George Notaras Post authorPermalink →

    It seems that leaving the mapping on gives nothing else, but trouble… Thanks for posting this info, Olivier. I hadn’t noticed it before.

  8. Francesco Permalink →

    Hi, I’m a linux user for 1 year and I’m surprised for the number of trouble that I have now faced for the packet writing since altough I use Slackware I have never had any kind of problem.
    I have installed the udftools and I have patched them but when I gave the input: “pktsetup pktcdvd0 /dev/hdc” I had this output : “ctl open: Not a directory”. I added the rules you have said in 60-udev.rules but when I rebooted nothing changed. I have added in /etc/rc.d/rc.local the following lines:
    rm /dev/pktcdvd
    mkdir /dev/pktcdvd

    Now there aren’t problem when I give the command “pktsetup pktcdvd0 /dev/hdc” but when i try to mount a cd formatted with cdrwtool the output tells me it’s impossible to determine the file system and perhaps there are bad options on the block device. Instead if I mount a cd formatted with Incd it mounts it but if i try to copy a file on it the led of the dvd-writer doesn’t stop to be on and the device results to be busy altough the file, by Konqueror, seems to be already copied.
    Thank you to everyone can give me an help

  9. George Notaras Post authorPermalink →

    Hi, Francesco. I am not surprised that the kernel pktcdvd module has got you into trouble. I had many issues, until it worked properly.

    The first thing that needs to be settled is the proper creation of the device nodes in /dev/. If there are no UDEV rules, then it’s most probable that the necessary device nodes will be created in the wrong place. The creation of the /dev/pktcdvd/ directory is handled by UDEV, so creating this directory in rc.local is not needed.
    You should also check if there are any default UDEV rules for pktcdvd. Maybe you will need to rename the file with the rules I have suggested to 40-udev.rules or anything that will be read before the default 50-udev.rules file.

    You have written that you have resolved your issues with the device node creation, but I just added this info.

    Now, for the other problems you have encountered:
    Make sure, through a Slackware mailing list or by any other means, that the version of the pktcdvd module that is included in your running kernel version is functioning properly and that no issues have been reported about it. This is critical. I had encountered the same problem (the drive led wouldn’t stop blinking), probably to malfunctioning pktcdvd module. This had happened only once, but I cannot remember the version of the kernel…
    Second, make sure that your kernel has support for the UDF filesystem. If the udf module does not get loaded together with the pktcdvd module when you setup the device mapping, then try to load it in rc.local.
    About cdrwtool, as I have written in this article, I could not make it prepare my CDRW media for packet writing. I do not know which exactly is the problem, but I guess that it does not work well with my DVD writer. I can tell you, that I had almost quit due to these damn cdrwtool malfuctions and its non-informative error messages. I would suggest that you try some DVD rewritable media instead. dvd+rw-tools seem to be much more stable, but you can use them only with DVDRWs. I currently do not use any CDRWs because of the little storage space they provide.
    A last thing I would suggest is to try to copy some files to the rewritable medium using cp, instead of konqueror or any other graphical file manager, just to make sure that it works.

    I hope these will help. It is very difficult to tell what exactly is wrong. It may need some time until you investigate your issue.

  10. Francesco Permalink →

    Slackware 10.1 uses by default the kernel 2.4.29 and in testing the 2.6.10 (even if a lot of person find this more stable than the 2.4). The two kernels are vanilla ones. For this reason it seems there is a mix between udev and devfs. In /etc/udev/rules.d the file for the rules isn’t 50-udev.rules but conf-udev.rules or something similar that I had already renamed in 50-udev.rules and I had already tried to put your rules in 10-udev.rules but unfortunately nothing changes. I have said that probably there is a mix between devfs and udev since there are some files in /etc/udev/rules.d called “devfs.rules.unsupported” and “/etc/udev/rules.d/compat.rules.unsupported”. Anyway these files don’t deal with pktcdvd and when I give the command “pktsetup pktcdvd0 /dev/hdc” are correctly created the two file /dev/pktcdvd/pktcdvd0 and /dev/pktcdvd/control.
    The version of pktcdvd is “0.2 a” and the kernel I’m using is the 2.6.13.2 compiled by myself with abilitated the udf fs and the pktcdvd (not as modules. They are in the kernel). I’ve tried to use the dvd but there is the same problem: altough the cp command has finished the led of the dvd-writer is always on since I’have copied the files. I’ll try to post to the packetwriting mailing list. Thank you anyway…

  11. George Notaras Post authorPermalink →

    Unfortunately I cannot provide any more help. I am out of ideas… Perhaps you should also try adding one of the following lines to /etc/modprobe.conf or /etc/modules.conf:

    alias block-major-97 pktcdvd
    or
    alias block-major-252 pktcdvd

    I believe that you need a newer kernel version.

  12. walwat Permalink →

    Thank You Raul for very helpful page!!! It works.
    Maybe I have solution of Francesco’s problem.
    Tray as root: pktsetup -d pktcdvd0 && rm -f /dev/pktcdvd && pktsetup pktcdvd0 /dev/hdd
    (of course replace hdd with your writing device).
    This first create wrong pktcdvd, than remove it and again create but the proper one.
    It has to be done after every reboot, so proposed by Raul script in the line creating device mapping can be:
    su -l root -c “pktsetup -d pktcdvd0 && rm -f /dev/pktcdvd && pktsetup pktcdvd0 /dev/hdd”
    insted of: su -l root -c “pktsetup pktcdvd0 /dev/hdd”.
    You can also do: pktsetup pktcdvd0 /dev/hdd && rm -f /dev/pktcdvd && pktsetup pktcdvd0 /dev/hdd.
    Obviously there is a bug in pktsetup.
    I hope it will help and thanks again Raul.

  13. George Notaras Post authorPermalink →

    It’s always good to hear that things work! Thanks for the comment, walwat. :-)

  14. Claudio Permalink →

    Thank’s for this great tutorial. I am new in Linux and it helped a lot! I am using this to make Autobackups for important files with rsync and cron in Fedora 4. Fedora has released the new Kernel 2.6.17 and the module pktcdvd is gone. I am getting this message: “FATAL: Module pktcdvd not found.
    Can’t find pktcdvd character device.” I have tried to load the module with modprobe (is it right?) and got the same message. What now? I went back to the 2.6.16 kernel but the update is labeled as “security”.
    Thank’s for any help.

  15. jimmy martin Permalink →

    Thanks for the great article. I followed all the steps but when it came to mounting the RW media for packet writing using this command: mount -t udf -o rw,noatime /dev/pktcdvd/pktcdvd0 /media/cdvdrw/

    My computer would always freeze up needing a reboot. But I now have a desktop icon that says DVD-RW LinuxUDF. In Nautilus when I click on the RW icon there is a folder there called lost+found.

    When I try to drag and drop a file to the disc in Nautius file manager I get an error message:
    “Error while copying to “/media/LinuxUDF” You do not have permissions to write to this folder.

    Even when I log in as root I get the same message.
    Is there a workaround way to remove any root permissions while using a GUI file manager.

    I tried this comand: “chmod 777 /media/cdvdrw” but it didn’t work.

    Jimmy

  16. George Notaras Post authorPermalink →

    I would recommend testing it from a console, for example by using the cp command to transfer files to the rewritable medium.
    Was the medium mounted when you run the chmod command? Maybe you should include the -R (recursive) chmod option.
    If you have used the UDEV rule as is, does the user who tries to write to the medium belong to the group disk?

  17. Laszlo Permalink →

    When trying to mount, I have the same computer lock-up problems jimmy martin mentioned. What’s the fix?

  18. George Notaras Post authorPermalink →

    I haven’t used any rewriteable media for a while. I guess it’s time for a test (soon). There might be bugs that need to be reported.
    Thanks for your feedback.