<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>
<channel>
	<title>G-Loaded Journal &#187; Packet-Writing</title>
	<atom:link href="http://www.g-loaded.eu/tag/packet-writing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Mon, 05 Dec 2011 19:55:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Packet Writing on CDRW and DVDRW media</title>
		<link>http://www.g-loaded.eu/2005/11/10/packet-writing-on-cdrw-and-dvdrw-media/</link>
		<comments>http://www.g-loaded.eu/2005/11/10/packet-writing-on-cdrw-and-dvdrw-media/#comments</comments>
		<pubDate>Thu, 10 Nov 2005 14:22:53 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Packet-Writing]]></category>
		<category><![CDATA[UDF]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/2005/11/10/packet-writing-on-cdrw-and-dvdrw-media/</guid>
		<description><![CDATA[How to prepare CD-RW and DVD&#177;RW media (formatting, creation of UDF structure) and mount them for use as large floppy diskettes.]]></description>
			<content:encoded><![CDATA[<p><strong>Packet writing</strong> 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. <strong>Rewritable media</strong> 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.</p>
<p>Anyway, using rewritable media for <em>critical backups</em> is not really recommended, but they can be perfectly used as temporary storage.<br />
<span id="more-95"></span></p>
<h4>Prerequisites</h4>
<p>Fedora Core&#8217;s official kernel already has packet-writing and <strong>UDF</strong> 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 <strong>pktcdvd</strong> and <strong>udf</strong>, when they are needed.</p>
<p>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;<strong>60-udev.rules</strong>&quot; in the <strong>/etc/udev/rules.d/</strong> 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:</p>
<pre class="codesnp">KERNEL==&quot;pktcdvd&quot;, NAME=&quot;pktcdvd/control&quot;, GROUP=&quot;<strong><span style="text-decoration:underline;">disk</span></strong>&quot;, MODE=&quot;0660&quot;
KERNEL==&quot;pktcdvd[0-9]*&quot;, NAME=&quot;pktcdvd/pktcdvd%n&quot;, GROUP=&quot;<strong><span style="text-decoration:underline;">disk</span></strong>&quot;, MODE=&quot;0660&quot;</pre>
<p>Now you should substitute <strong>disk</strong> 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.</p>
<p>You will also need to install the <strong>udftools</strong> and <strong>dvd+rw-tools</strong> packages. The first is absolutely necessary. The second is only needed if you intend to format rewritable DVD media.</p>
<p>Furthermore, you have to be sure that you have write access to your CD/DVD writer device. Assuming that this is <strong>/dev/hdc</strong>, from a terminal type:</p>
<pre class="console"># ls -l /dev/hdc
b<strong><span style="text-decoration:underline;">rw</span></strong>&#45;&#45;&#45;&#45;&#45;&#45;&#45;  1 <strong><span style="text-decoration:underline;">raoul</span></strong> disk 22, 0 Sep 03 18:16 <strong><span style="text-decoration:underline;">/dev/hdc</span></strong></pre>
<p>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.</p>
<p>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.</p>
<h4>Preparing CDRW media for packet writing</h4>
<p>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 <strong>cdrwtool</strong>&#8216;s quick setup (<strong>-q</strong>) option. As root type:</p>
<pre class="console"># cdrwtool -d /dev/hdc -q -t 10</pre>
<p>The <strong>-t</strong> 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.</p>
<p>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 <a href="http://www.g-loaded.eu/2005/09/16/the-worst-thing/">blog entry</a>. 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.</p>
<p>Before mounting a CDRW medium for packet writing you need to create a device association with pktsetup (part of udftools). As root type:</p>
<pre class="console"># pktsetup pktcdvd0 /dev/hdc</pre>
<p>This associates the packet module (pktcdvd) with your recorder and the packet device is placed in the directory /dev/pktcdvd/.</p>
<h4>Preparing DVDRW media for packet writing</h4>
<p>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 <strong>dvd+rw-format</strong> (part of dvd+rw-tools) for this.</p>
<p>To format a <strong>DVD-RW</strong> medium:</p>
<pre class="console"># dvd+rw-format -force=full /dev/hdc</pre>
<p>The <strong>-force=full</strong> 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.</p>
<p>To format a <strong>DVD+RW</strong> medium:</p>
<pre class="console"># dvd+rw-format -force /dev/hdc</pre>
<p>In this case the <strong>-force</strong> option can be omitted when the medium is new. It&#8217;s necessary though when reformatting a disc.</p>
<p>Create the device mapping as described in the CDRW section. As root:</p>
<pre class="console"># pktsetup pktcdvd0 /dev/hdc</pre>
<p>Then we need to create the UDF structure on the formatted disc. As root:</p>
<pre class="console"># mkudffs --media-type=dvd --udfrev=0x0150 /dev/pktcdvd/pktcdvd0</pre>
<p>The options are self-explanatory, but in short:</p>
<ul>
<li><strong>&#8211;media-type</strong>: The type of medium we use.</li>
<li><strong>&#8211;udfrev</strong>: 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.</li>
</ul>
<h4>Mounting rewritable media for packet writing</h4>
<p>At first we need to create a new mount point for our rewritable discs. This has to be done once. As root:</p>
<pre class="console"># mkdir /media/cdvdrw</pre>
<p>Mounting a rewritable medium for packet writing is the same for both CDs and DVDs. As root:</p>
<pre class="console"># mount -t udf -o rw,noatime /dev/pktcdvd/pktcdvd0 /media/cdvdrw/</pre>
<p>The mount option <strong>noatime</strong> is of major importance as it prevents unnecessary writes on the media. Make sure you always include it to avoid unnecessary wear. The option <strong>rw</strong> stands for read/write. Read the mount man page for more info.</p>
<p>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.</p>
<h5>Unmounting the disc</h5>
<p>To unmount the medium just type:</p>
<pre class="console"># umount /media/cdvdrw/</pre>
<p>To show the active device mappings type as root:</p>
<pre class="console"># pktsetup -s</pre>
<p>To delete the device association type as root:</p>
<pre class="console"># pktsetup -d pktcdvd0</pre>
<p>Now, you may finally eject the media&#8230;</p>
<p><em><span style="text-decoration:underline;">Special Note</span></em>: Deleting the device association should not be necessary, but there seems to be a <strong>bug</strong> 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:</p>
<pre class="console"># eject /dev/hdc</pre>
<p>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.</p>
<h4>Who has write access on a rewritable medium?</h4>
<p>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 <strong>has to be done once for every disc</strong>. 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:</p>
<ol>
<li>As root, insert the disc in the drive</li>
<li>Create the device association with pktsetup</li>
<li>Mount it for packet writing</li>
<li>Change the permissions on the mount point. For our example:
<pre class="console"># chmod 777 /media/cdvdrw</pre>
</li>
</ol>
<p>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.</p>
<h4>Mounting as a user</h4>
<p>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:</p>
<pre class="console"># su -l root -c &quot;pktsetup pktcdvd0 /dev/hdc&quot;</pre>
<p>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.</p>
<p>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:</p>
<pre class="codesnp">/dev/pktcdvd/pktcdvd0 /media/cdvdrw udf noauto,noatime,rw,users 0 0</pre>
<p>From now on, to mount the rewritable medium as a user just type:</p>
<pre class="console"># mount /media/cdvdrw/</pre>
<p>To unmount just type:</p>
<pre class="console"># umount /media/cdvdrw/</pre>
<p>To delete the mapping:</p>
<pre class="console"># su -l root -c &quot;pktsetup -d pktcdvd0&quot;</pre>
<p>Again you will be asked for the root password.</p>
<h5>Having the automounter enabled</h5>
<p>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:</p>
<pre class="console"># umount /dev/hdc</pre>
<p>And then proceed with creating the mapping and then mount as described in the previous paragraph.</p>
<h5>A little automation</h5>
<p>A little bash script is always a great convenience</p>
<pre class="codesnp">
#! /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 &quot;pktsetup -d pktcdvd0&quot;
	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</pre>
<p>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 <strong>bin</strong> 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:</p>
<pre class="console"># myscript</pre>
<h4>Common Errors</h4>
<p>Here are some :</p>
<h5>ctl open: Not a directory</h5>
<p>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 <code>/dev/pktcdvd</code> device is created instead of a <code>/dev/pktcdvd/</code> directory. You can easily overcome this issue by deleting the wrong device and by adding a UDEV ruleset in a <code>/etc/udev/rules.d/60-udev.rules</code> file to get rid of the problem once and for all. As root, delete the device:</p>
<pre class="console">rm -f /dev/pktcdvd</pre>
<p>The UDEV rules to add:</p>
<pre class="codesnp">KERNEL==&quot;pktcdvd&quot;, NAME=&quot;pktcdvd/control&quot;, GROUP=&quot;<strong><span style="text-decoration:underline;">disk</span></strong>&quot;, MODE=&quot;0660&quot;
KERNEL==&quot;pktcdvd[0-9]*&quot;, NAME=&quot;pktcdvd/pktcdvd%n&quot;, GROUP=&quot;<strong><span style="text-decoration:underline;">disk</span></strong>&quot;, MODE=&quot;0660&quot;</pre>
<p>Now you should substitute <code>disk</code> with your username, or a group that your user belongs to. Alternatively, you could simply add your user to the group <code>disk</code> 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.</p>
<h5>Cannot eject medium as a user</h5>
<p>The <code>pktcdvd</code> 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:</p>
<pre class="console"># eject /dev/hdc</pre>
<h5>cdrwtool does not work</h5>
<p>Well, I&#8217;m not surprised! It does not work with my DVD writer either. Some tweaking with <code>hdparm</code> could solve this problem though.</p>
<h4>Further Reading</h4>
<p>Although the documentation on packet writing is very limited, more info can be found at:</p>
<ol>
<li>the <a href="http://lists.suse.com/archives/packet-writing/">SUSE packet writing mailing list</a></li>
<li>the <strong>packet-writing.txt</strong> file included in the fedora kernel docs. (contains only basic information)</li>
</ol>
<div class="cc-block"><em><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></em>, 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>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2005/09/16/the-worst-thing/" rel="bookmark">The worst thing&#8230;</a></li>
<li><a href="http://www.g-loaded.eu/2007/05/15/blanking-a-rewritable-cddvd-in-gnome/" rel="bookmark">Blanking a rewritable CD/DVD in GNOME</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/encrypt-devices-using-dm-crypt-and-luks/" rel="bookmark">Encrypt devices using dm-crypt and LUKS</a></li>
<li><a href="http://www.g-loaded.eu/2005/09/19/a-different-approach-hal/" rel="bookmark">A different approach&#8230;HAL</a></li>
<li><a href="http://www.g-loaded.eu/2005/09/18/udev/" rel="bookmark">UDEV</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2005/11/10/packet-writing-on-cdrw-and-dvdrw-media/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

