HOWTO Packet Writing on CD-RW

Packet Writing on CDRW and DVDRW media REF: http://www.g-loaded.eu/2005/11/10/packet-writing-on-cdrw-and-dvdrw-media/

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&#8217;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&#8217;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&#8217;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 &quot; 60-udev.rules &quot; in the /etc/udev/rules.d/ directory. It is not recommended to edit the default &quot;50-udev.rules&quot; as this can be updated by Red Hat. We put the number &quot;60&quot; 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==&quot;pktcdvd&quot;, NAME=&quot;pktcdvd/control&quot;, GROUP=&quot; disk &quot;, MODE=&quot;0660&quot; KERNEL==&quot;pktcdvd[0-9]*&quot;, NAME=&quot;pktcdvd/pktcdvd%n&quot;, GROUP=&quot; disk &quot;, MODE=&quot;0660&quot;

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 &quot;disk&quot; 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:

b rw &#45;&#45;&#45;&#45;&#45;&#45;&#45; 1 raoul disk 22, 0 Sep 03 18:16 /dev/hdc The above shows that user &quot;raoul&quot; 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&#8217;s &quot;Removable Drives and Media&quot; preferences. We&#8217;ll get back to this later on.
 * 1) ls -l /dev/hdc

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 &#8216;s quick setup ( -q ) option. As root type: The -t option sets the writer&#8217;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&#8217;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&#8217;s currently the only way I know to format a CDRW disc under linux.
 * 1) cdrwtool -d /dev/hdc -q -t 10

Before mounting a CDRW medium for packet writing you need to create a device association with pktsetup (part of udftools). As root type: 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&#8217;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&#8217;t this a convenience! I use both DVD-RW and DVD+RW discs and have not encountered problems so far. Before you can &quot;packet write&quot; on a rewritable DVD you need to format it. We&#8217;ll need dvd+rw-format (part of dvd+rw-tools) for this.
 * 1) pktsetup pktcdvd0 /dev/hdc

To format a DVD-RW medium: 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 &quot;Restricted Overwrite&quot; mode, so it can be used for packet writing. To format a DVD+RW medium:
 * 1) dvd+rw-format -force=full /dev/hdc

In this case the -force option can be omitted when the medium is new. It&#8217;s necessary though when reformatting a disc. Create the device mapping as described in the CDRW section. As root: Then we need to create the UDF structure on the formatted disc. As root: The options are self-explanatory, but in short:
 * 1) dvd+rw-format -force /dev/hdc
 * 1) pktsetup pktcdvd0 /dev/hdc
 * 1) mkudffs --media-type=dvd --udfrev=0x0150 /dev/pktcdvd/pktcdvd0

  &#8211;media-type : The type of medium we use.  &#8211;udfrev : the revision of the UDF filesystem that we want to create. 0&#215;0201 (rev 2.01) is the default for mkudffs. Revision 0&#215;0150 (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: Mounting a rewritable medium for packet writing is the same for both CDs and DVDs. As root:
 * 1) mkdir /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:
 * 1) mount -t udf -o rw,noatime /dev/pktcdvd/pktcdvd0 /media/cdvdrw/
 * 1) umount /media/cdvdrw/

To show the active device mappings type as root: To delete the device association type as root: Now, you may finally eject the media&#8230; 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:
 * 1) pktsetup -s
 * 1) pktsetup -d pktcdvd0
 * 1) 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&#8217;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:  As root, insert the disc in the drive Create the device association with pktsetup Mount it for packet writing Change the permissions on the mount point. For our example:

</li> </ol> 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&#8217;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: You will be asked for the root password. An alternative is to use &quot;sudo&quot; without asking for a password, but this will not be covered here.
 * 1) chmod 777 /media/cdvdrw
 * 1) su -l root -c &quot;pktsetup pktcdvd0 /dev/hdc&quot;

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: To unmount just type: To delete the mapping:
 * 1) mount /media/cdvdrw/
 * 1) umount /media/cdvdrw/
 * 1) su -l root -c &quot;pktsetup -d pktcdvd0&quot;

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: 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
 * 1) umount /dev/hdc
 * 1) ! /bin/bash

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 &quot;pktsetup -d pktcdvd0&quot;
 * 1) check if /dev/pktcdvd/pktcdvd0 exists

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 &quot;pktsetup pktcdvd0 /dev/hdc&quot; 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&#8217;s filename in a terminal: Common Errors
 * 1) myscript

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  device is created instead of a   directory. You can easily overcome this issue by deleting the wrong device and by adding a UDEV ruleset in a  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==&quot;pktcdvd&quot;, NAME=&quot;pktcdvd/control&quot;, GROUP=&quot; disk &quot;, MODE=&quot;0660&quot; KERNEL==&quot;pktcdvd[0-9]*&quot;, NAME=&quot;pktcdvd/pktcdvd%n&quot;, GROUP=&quot; disk &quot;, MODE=&quot;0660&quot;

Now you should substitute  with your username, or a group that your user belongs to. Alternatively, you could simply add your user to the group  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  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:
 * 1) eject /dev/hdc

cdrwtool does not work Well, I&#8217;m not surprised! It does not work with my DVD writer either. Some tweaking with  could solve this problem though. Further Reading Although the documentation on packet writing is very limited, more info can be found at: <ol> the <a href="http://lists.suse.com/archives/packet-writing/">SUSE packet writing mailing list</a></li> the packet-writing.txt file included in the fedora kernel docs. (contains only basic information)</li>

</ol>

The <a href="http://www.g-loaded.eu/2005/11/10/packet-writing-on-cdrw-and-dvdrw-media/">Packet Writing on CDRW and DVDRW media</a> by <a href="http://www.g-loaded.eu">George Notaras</a>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.