Write arbitrary data to DVD in Linux

dddvd

I need to write arbitrary data, not an ISO image to a DVD, without a filesystem.

Years ago it was possible to do something like:

tar vcf - whatever/ | dd of=/dev/cdrom

And have a CDROM with no filesystem and a plain tar file.

Doing it now with a DVD-RW dd fails with:

dd: writing to '/dev/sr0': No space left on device
1+0 records in
0+0 records out
0 bytes copied, 7.9702e-05 s, 0.0 kB/s

How can you nowadays write arbitrary data to a DVD with Linux?

Best Answer

Quick introduction into CD formats:

A CD-R can record multiple sessions. Each session must be complete and "closed" before it can be read. Each session contains a lead-in, a lead-out and a number of tracks. You can write all the tracks in one session (disk at once, option -dao) or each track in turn from different files (conceptually) with pauses in between (track at once, option -tao), but you must write all tracks and close the session.

The data format for CDs (CD-ROM, "yellow book") was designed on top of the audio format (CD-DA, "red book"), and properly separates the continous digital audio stream into sectors. For this, it needs some header information, and that's why you have 2352 bytes in an audio "sector", but only 2336 bytes for data. On top of that, the error correction on audio CDs is good enough for audio, where you can tolerate a few wrong bits, but not good enough for data. Therefore each sector gets additional error correction bits, leaving 2048 bytes of user data. This is also called "Mode 1". This is the default in cdrecord, and I don't recommend using any other mode to write data. The available "raw" modes allow writing subchannel data, but you have no need for that.

You will need to pad your tracks to proper blocksize before writing, however. And no, 4512 bytes is not a multiple of 2048 bytes. So for backup, something like

tar -c --record-size=2048 -f track.tar

and then something like

cdrecord -multi dev=0,0,0 -data track.tar

to make a multi-session CD with a single track. If the CD is not full, you can append another session.

DVDs have a different format, different blocksizes and different restrictions, and I haven't personally tried this on a DVD yet, so I'd rather not try to give details, but in principle it works similarly.

Edit:

If the goal is to make frequent backups on DVD+RW or DVD-RW (the + or - is important, these are different formats), you can tolerate failures, so you might actually try streaming from tar. You also probably don't need multiple sessions.

You can also stream from mkisofs, which is even better because there won't be trouble mounting it, and man cdrecord has an example:

mkisofs -R /master/tree | cdrecord -v -dao fs=6m speed=2 dev=2,0 -

The last - is for "read data from stdin". You may want to fiddle with the speed, FIFO size, I/O priorities (that's another can of worms), driveropts=burnfree if supported, etc.

For permanent backups on write-once media, I'd always recommend doing it the safe way, without streaming.

Related Question