3

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?

  • You'll probably need to say what OS you're using. – Michael Homer Apr 20 '17 at 6:37
  • 2
    Possible duplicate of How to burn iso image to DVD using dd command – Stefan Apr 20 '17 at 8:25
  • Thanks @Stefan, but it is not a duplicate precisely because I do not want to write an ISO image. I want to write arbitrary data. – Toni Homedes i Saun Apr 20 '17 at 9:08
  • 2
    Keep in mind that for both CDs and DVDs you can only burn complete tracks, and you'll have to update "adminstrative" information ("fixup") on the medium as you do that. The kernel /dev/cdrom might have had some defaults to to this (never tried it), but it really doesn't work in the general case, so I'm not surprised if support was dropped, and just piping data to it risks buffer underruns. Have you tried dvdrecord or cdrecord (yes, also burns dvd's) on the tar file? It will be an interesting exercise to read it again, though. – dirkt Apr 20 '17 at 10:47
  • Use a decent blocksize and you'll succeed. – roaima Apr 20 '17 at 13:42
3

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.

  • Thanks @dirkt good explanation. I wanted to experiment with writing to DVD+RW before buying a BLU-RAY writer for making backups on the fly, without creating disc images beforehand, tape backup style. I'm seeing it's too complex. I will finally take the safe approach of creating the images first and then burning them. – Toni Homedes i Saun Apr 21 '17 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.