# Simple howto burn and rip cd's



## graudeejs (Dec 29, 2008)

To create iso

```
$ mkisofs -o /path/to/output.iso -R -J /path/to/files/you/want/on/cd
```

to burn cd-r/cd-rw

```
$ burncd data /path/to/output.iso fixate
```

To burn files/directory, to cd without making iso file (thanks to Vermaden  @ daemonforums.org)

```
$ mkisofs -J -R /path/to/some/file/or/dir | burncd data - fixate
```

to burn compressed cd:

```
$ gunzip -c file.iso.gz | burncd data - fixate
```

to blank cd-rw

```
$ burncd blank
```

to get cd/dvd image (to get iso from disk)

```
$ dd if=/dev/acd0 of=/path/to/disk.iso bs=2048
```

to burn dvd iso to disk with burncd

```
$ burncd dvdrw /paht/to/image.iso
```

to burn dvd iso to disk with growisofs

```
$ growisofs -dvd-compat -Z /dev/cd0=/path/to/image.iso
```

to burn files to dvd without creating iso

```
$ growisofs -Z /dev/cd0 -R -J /some/files
```

above 2 commands will overwrite content on dvd+-rw disk
no need to blank (so it seams. i tested on my pc)


to append to dvd (must use same options as when creating this dvd)

```
$ growisofs -M /dev/cd0 -R -J /some/more/files
```

to finalize dvd (slow) (you need this after appending to dvd, to maintain maximal compatibility, it's not 100% necessary)

```
$ growisofs -M /dev/cd0=/dev/zero
```

to format dvd-rw with burncd (slow!)

```
$ burncd format dvd-rw
```

to format dvd+rw with burncd (slow!)

```
$ burncd format dvd+rw
```

To blank dvd-rw (very slow!) (thanks to Vermaden  @ daemonforums.org)

```
$ growisofs -Z "/dev/cd0=/dev/zero"
```

to blank dvd+rw (slow)

```
dvd+rw-format /dev/cd0
```

to burn audio cd from wav files

```
$ burncd audio file1.wav file2.wav file3.wav fixate
```

here's simple script that uses mplayer and burncd to burn audio cd's from directory with music files (basically any file that mplayer can play)

```
#!/bin/sh
for i in `ls`; do
  rm -f /tmp/cd_track.wav
  mplayer -vo null -vc dummy -af resample=44100 -ao pcm:file=/tmp/cd_track.wav $i
  burncd audio /tmp/cd_track.wav
done
rm -f /tmp/cd_track.wav
burncd audio fixate
exit 0
```

and here's another simple script to rip audio cd's to mp3

```
#!/bin/sh
mkdir /tmp/cd
cd /tmp/cd
cdparanoia -B -d /dev/acd0
for i in `ls *.wav`; do
  lame -m s "$i" -o "$(echo $i | awk '{print substr($0,6,2)}' -).mp3"
  rm -f "$i"
done
echo 'files are in /tmp/cd'
exit 0
```

you can rip 1 audio track to wav with

```
$ cdparanoia -B -d /dev/acd0 1
```
in this example it'll rip track 1 only
and convert it to mp3 with

```
lame -m s audio.wav -o audio.mp3
```


to attach and mount iso image

```
$ mdconfig -a -t vnode -u 0 -f /path/to/image.iso
$ mount -t cd9600 /dev/md0 /mnt
```


to umount and detach iso image

```
$ umount /mnt
$ mdconfig -du 0
```


To make it all happen you need:

in kernel

```
options 	CD9660			# ISO 9660 Filesystem, because you want to read them ;)
device		atapicd		# ATAPI CDROM drives
device		atapicam
device		cd				# nessacery for dvd's
device 		pass
device 		scbus
options		MD_ROOT
device		md
options         UDF
```

and permission to write to /dev/acd0 /dev/cd0 /dev/pass1

note: The pass device number will also depend on the order that SCSI devices are enumerated by the kernel. To determine exactly which one it is, one can use *camcontrol devlist* as root [thanks to phoenix @ daemonforums.org]

note, you can't run growisofs using su, you need to do that as user....

here's some part of my /etc/devfs.conf

```
own     acd0    root:users
perm    acd0    0660

own     cd0     root:users
perm    cd0     0660

own     pass1   root:users
perm    pass1   0660

own     pass0   root:users
perm    pass0   0660
```

Here's list of utils you can install to convert from different formats to iso files:
sysutils/iat - converts BIN, MDF, PDI, CDI, NRG, and B5I to ISO
sysutils/nrg2iso - Convert Nero .nrg CD-Image format to ISO
sysutils/ccd2iso - A CloneCD to ISO converter
sysutils/daa2iso - Convert PowerISO DAA files to ISO9660
sysutils/mdf2iso - A Alcohol 120% to ISO converter
sysutils/nrg2iso - Convert Nero .nrg CD-Image format to ISO
sysutils/uif2iso - Convert MagicISO UIF files to ISO9660
sysutils/bchunk - Converts .bin/.cue files to .iso/audio

note: if you have more than one drive, you need to specify which one to use with burncd as well
use -f flag for this

```
burncd -f /dev/acd1 data /path/to/image.iso fixate
```

to use mkisofs you need to install sysutils/cdrtools
to use growisofs you need to install sysutils/dvd+rw-tools

to use cdparanoia you need to install audio/cdparanoia
to use lame you need to install audio/lame
to use mplayer you need to install multimedia/mplayer



resources:
burncd(8)
mkisofs(8)
growisofs(1)

mplayer(1)
cdparanoia(1)

mdconfig(8)

lame(1) , hmm why this is not available in freebsd online manual pages?


*UPDATE*
To avoid allowing rw access to all pass* devices (thanks to mart), you can do fallowing:

```
$ dmesg | grep -i cd0.*target
cd0 at [color="Red"]ata1[/color] bus 0 target 0 lun 0
$ echo 'hint.scbus.0.at="[color="Red"]ata1[/color]"' >> /boot/device.hint
```
This will make sure that your burner on ata1 (in this case) will be assigned to pass0 always, as long as it's on ata1
now all you have to do is allow only

```
own     pass0   root:users
perm    pass0   0660
```
in /etc/devfs.conf


----------



## SirDice (Dec 29, 2008)

Errmm.. burncd uses the ATAPI (IDE) interface.. 
So stricly speaking you don't need atapicam and all for that.

atapicam is needed for cdrecord (SCSI) and similar burn programs (nautilus i.e.).


----------



## Pushrod (Dec 29, 2008)

You can also do:

mkisofs -o /dev/stdout -R -J /path/to/files/you/want/on/cd | burncd data /dev/stdin fixate


----------



## graudeejs (Dec 31, 2008)

SirDice said:
			
		

> Errmm.. burncd uses the ATAPI (IDE) interface..
> So stricly speaking you don't need atapicam and all for that.
> 
> atapicam is needed for cdrecord (SCSI) and similar burn programs (nautilus i.e.).



you need atapicam to use growisofs


----------



## mart (Dec 31, 2008)

killasmurf86 said:
			
		

> To make it all happen you need:
> 
> in kernel
> 
> ...



Some additions from my own experiences trying to figure this out a few days ago...

1. Recompiling kernels is not required.  atapicam can be started via /boot/loader.conf as described in the handbook.  It's a personal choice, but avoiding custom kernels makes security updates easier.

2. If you're using a burner connected by USB, then refer to handbook as the setup is much different to the one described here.

3. Device numbers changing.  This is a PITA.  The enumeration on my machine means that my DVD burner (on IDE via atapicam) is enumerated _after_ my usb drives.  This means my DVDs passthrough device (passN) will change, frequently, depending on if I have a USB key inserted or not.  I can pass 'pass*' to devfs.conf (or devfs.rules), but that opens up _all_ passthrough devices, hardly ideal.  *Anyone know of a consistent, secure, way to handle this (fixed to something like a UID, perhaps)?*

4.  DMA Errors.  I can get DVD-R, DVD+RW and DVD+DL disc to burn beautifully with growisofs, but dmesg shows a ton of ata and dma related errors.  The errors occur on initializing the device, and when discs are inserted.  I'm not at my FreeBSD machine right now, but they appeared related to enabling ata/atapi dma as described in the handbook.  I haven't found a solution to these errors yet, but I see similar reports on freebsd mailing lists going back to ~2004.  It's possible the errors are unimportant, but I'm wondering if they're also interfering with automounting via hal/thunar-vol-man (which seems broken for me) and/or xfburn (which seems to have issues recognizing and registering DVD media).


----------



## graudeejs (Dec 31, 2008)

I use custom kernel and no problems updating to latest security fix...
Well i prefer recompiling everything from sources... haven't tried binary update


----------



## mart (Dec 31, 2008)

killasmurf86 said:
			
		

> I use custom kernel and no problems updating to latest security fix...



I didn't say there would be problems, just that it's easier and probably something best avoided unless you really _need_ to.  I'm a firefighter, and have never had a problem with burning buildings, but it doesn't mean I recommend running into them unless it's really necessary )).

BTW: Some more useful information, in addition to what's already included in the handbook, can be found here: /usr/ports/sysutils/k3b/pkg-message

Now, if someone could post additional info on how to do all this securely, in a consistent manner that survives device reordering, and without all the ata/dma issues, and throw in how to do automounting *correctly* in xfce I'd be *very* thankful (hint, hint)...


----------



## mart (Jan 2, 2009)

mart said:
			
		

> Device numbers changing. This is a PITA. The enumeration on my machine means that my DVD burner (on IDE via atapicam) is enumerated after my usb drives. This means my DVDs passthrough device (passN) will change, frequently, depending on if I have a USB key inserted or not. I can pass 'pass*' to devfs.conf (or devfs.rules), but that opens up all passthrough devices, hardly ideal. Anyone know of a consistent, secure, way to handle this (fixed to something like a UID, perhaps)?



*Partly solved:  *I've figured out how to avoid device reordering, which means I can impose more restrictive devfs.conf rules (i.e. permit access to only this _specific_ device, rather than all passthrough devices).  It also means I can separate usb thumb drive and dvd burner permissions easily, and it makes scripts a whole lot simpler to write... 

NOTE:  I couldn't find much documentation, so there may be more to this than I've done so far, but the following works great for me...


```
1. Discover where your drive is located (in my case cd0)

   [mart@bsddesktop /usr/home/mart]$ dmesg | grep -i cd0.*target
   cd0 at ata3 bus 0 target 0 lun 0

2. Add a device hint to /boot/device.hints (here's mine for reference)

   [mart@bsddesktop /usr/home/mart]$ tail -4 /boot/device.hints 
   # mart:  lock dvdburner (on ata3) to scsi 0
   hint.scbus.0.at="ata3"

3. Tighten up your devfs rules i.e. ensure they're locked to the
   [I]specific[/I] passthrough device [I]only[/I], and to the [I]specific[/I] group [I]only[/I].

4. Reboot

5. Verify its now fixed to scbusN / passN (in my case N=0)

   [mart@bsddesktop /usr/home/mart]$ camcontrol devlist
   <BENQ DVD DD DW1620 B7W9>          at scbus0 target 0 lun 0 (cd0,pass0)
   <USB2.0 CardReader CF RW 0.0>>     at scbus1 target 0 lun 0 (pass1,da0)
   <USB2.0 CardReader Combo 0.0>>     at scbus1 target 0 lun 1 (pass2,da1)
```
Obviously, use your own info, not mine.  Repeat for other devices if necessary.

I still get the 


```
acd0: FAILURE - INQUIRY ILLEGAL REQUEST asc=0x24 ascq=0x00
```
and

```
acd0: FAILURE - READ_BIG timed out
```
errors.  And I *still* can't get !@$%^$#&* automount functioning properly with xfce...  *can anyone*?


----------



## pablo (Jan 3, 2009)

Sorry if it's  not appropriate topic for mu question, but
is there a way to burn/mount under FreeBSD CD-images produced by ALCOHOL120% (some *.mds & *.mdf files)?


----------



## graudeejs (Jan 3, 2009)

install sysutils/mdf2iso from ports
convert cd/dvd image to iso and burn/mount as described in this howto.

but i don't know if there will be any header data lost [you know stuff that is necessary to run legal games], however data on disk will be accessible

you could try and report


Here's list of utils to convert different formats to iso:
sysutils/nrg2iso
sysutils/ccd2iso
sysutils/daa2iso
sysutils/mdf2iso
sysutils/nrg2iso
sysutils/uif2iso


----------



## graudeejs (Jan 6, 2009)

Pushrod said:
			
		

> You can also do:
> 
> mkisofs -o /dev/stdout -R -J /path/to/files/you/want/on/cd | burncd data /dev/stdin fixate



it doesn't work on my PC ;(

I removed this from howto for time being


----------



## trybeingarun (Dec 27, 2009)

Thanks killasmurf86!
I dint know this many options existed for one task. 

I was struggling with k3b for a while before posting my question. Unfortunately I still don't know why k3b dint work(it failed even to start). One of the blogs suggested to create a link /dev/cd0 for /dev/acd0 even after which k3b failed to load. Anybody has any idea how to get it to work?


----------



## graudeejs (Dec 27, 2009)

you probably need to

```
# kldload atapicam
# kldload cd
# kldload pass
```

and set permissions so you, as user, have rw access to /dev/cd*X* and /dev/pass*Y*

replace X and Y with correct device number
after this you should be able to burn cd/dvd with k3b untill you restart...

to make this permanent read my 1st post at end.... at end there are some tips. I don't say anything about k3b, but if you apply everything mentioned to your system, k3b will work {should}


also you should read comments


----------



## cpcnw (Feb 27, 2010)

If you just want a 'backup copy' of your valuable dvd originals there is a port in multimedia called lxdvdrip which is quite useful.

My own attempts at writing dvd's from CLI resulted in a few coasters so I checked out the above. Following the ripping process I noticed that the cli used for growisofs was as follows ;


```
growisofs -speed=10 -dvd-compat -use-the-force-luke=dao -Z /dev/cd1 -V DVD_TITLE -dvd-video /tmp/DVD_TITLE
```


----------



## cpcnw (Mar 4, 2010)

Here's a hands free [almost] script for copying audio CD's ~ resulting CD's are correctly identified by CDDB


```
#!/bin/sh
echo "Insert audio CD in acd0 and press enter..."
read p
for i in /dev/acd0t* 
do
trackno=`echo $i | cut -d"t" -f2`
dd if=$i of=track${trackno}.cdr bs=2352
done
cdcontrol -f acd0 eject
echo "Insert blank CDR and press enter ..."
read p
burncd -f /dev/acd0 audio *cdr fixate 
cdcontrol -f acd0 eject 
echo "Hit enter to remove temps or Ctrl-C to keep!"
read p
rm track*.cdr
echo "All Done!"
```

Special thanks to Steve Parker for giving me a hand with this!


----------



## phoenix (Mar 4, 2010)

"bs=2352"  Audio CDs use a different sector size than data CDs?  Data CDs use 2048 B.


----------



## cpcnw (Mar 5, 2010)

http://www.freebsd.org/doc/handbook/creating-cds.html

Just taking advice of handbook? Maybe I should cross reference ...


----------



## ckester (Jan 7, 2011)

Most of the examples I've seen for how to use mkisofs assume that what you want to burn to the CD/DVD is everything in and under one or more directories.

But what if I only want to burn *some* of the files in those directories?  For example, if I'm doing an incremental backup and only want the files that have recently changed.  What techniques do people use in cases like that?

I've considered recreating the directory tree(s) under a backuproot directory, hardlinking the changed files into there, and then giving the backuproot directory as the /path/to/files argument to mkisofs.  But I'm wondering if there's a simpler way? 

(I tried giving mkisofs the names of the specific files to use, but this flattens the entire hierarchy and leads to naming conflicts.)

Second question: how do you deal with the case where the size of the resulting ISO is bigger than will fit on a DVD?


----------



## bes (Jan 8, 2011)

For backup purposes you can also choose to burn a file directly to CD, without creating an ISO 9660 file system(see Handbook 18.6.8 Burning Raw Data CDs),and it is  possible to split the big archive into pieces.
For exmaple file archive.tar.gz with size 2G:

```
split -b 680m archive.tar.gz [PREFIX]
ls 
archive.tar.gz [PREFIX]aa [PREFIX]ab [PREFIX]ac
```
then burn all pieces [PREFIX]*,respectively one for disk:

```
burncd -f /dev/acd0 -s max data [PREFIX]?? fixate
```
Now we have backups on 3 CD's.

Recovery:
Copy all CD's from the raw device node to files on hard and concatenate them:

```
cp /dev/acd0 path2/file
cat file1 ... file > archive.tar.gz
```


----------

