Guide to Unix/Explanations/Compact Discs
Ripping CD audio
[edit | edit source]This copies the audio from a CD track to a file. With some drives (one without analog connections to the sound card) this is the only way to correctly play a file.
Granting permission to the user
[edit | edit source]First you should have read-and-write permission to the CD device. (You could become root to rip the CD, but then you would have to "chown" the file back to you.)
First look at your CD devices nodes. On *BSD, they are at /dev/cd* and /dev/rcd*. If they look like this:
$ ls -l /dev/cd* brw-r--'--- 1 root operator 3, 0 Nov 1 16:26 /dev/cd0a brw-r--'--- 1 root operator 3, 2 Nov 1 16:26 /dev/cd0c brw-r--'--- 1 root operator 3, 16 Nov 1 16:26 /dev/cd1a brw-r--'--- 1 root operator 3, 18 Nov 1 16:26 /dev/cd1c
Here, root needs to grant read and write permission to the user. We decide to add the users to group "wheel". Once they are in, we change the group of the devices and grant read and write permission to the group:
$ sudo chgrp wheel /dev/cd* /dev/rcd* $ sudo chmod g+gw /dev/cd* /dev/rcd* $ ls -l /dev/cd* brw-rw--'-- 1 root wheel 3, 0 Nov 1 16:26 /dev/cd0a brw-rw--'-- 1 root wheel 3, 2 Nov 1 16:26 /dev/cd0c brw-rw--'-- 1 root wheel 3, 16 Nov 1 16:26 /dev/cd1a brw-rw--'-- 1 root wheel 3, 18 Nov 1 16:26 /dev/cd1c
Ripping tracks
[edit | edit source]We must insert a CD before ripping the track.
Here, for example, we rip track 2 and store it in song.wav. Our ".wav" suffix is because that is the default format of cdparanoia. With a CD in:
$ cdparanoia 2 song37.wav
Eject a disc
[edit | edit source]Many systems provide an eject command.
$ eject cd0
Burn a disk
[edit | edit source]Scenario: put the contents of a directory called backup to CD.
Here we do the actual burn (and eject) as root. The user needs to have "sudo" access, but not any special access to the CD device node.
Create a disk image of the CD. We will call it burn.iso.
- -R is ISO6990 Rock Ridge support
- -r is Rock Ridge but with all files to root (usable on computers with different users)
- -hfs indicates a hybrid ISO9660/HFS disk
$ mkisofs -o burn.iso -r -hfs backup $ chmod a-w burn.iso
Mount it to check for validity. (NetBSD/OpenBSD)
$ sudo vnconfig /dev/svnd0c burn.iso $ sudo mount -r -t cd9660 /dev/svnd0a /mnt $ diff /mnt backup $ echo $? 0 $ sudo umount /mnt $ sudo vnconfig -u /dev/svnd0c
The filesystem is good though file is misleading:
$ file burn.iso burn.iso: x86 boot sector, extended partition table
Insert a blank disk.
This is a test burn to demonstrate cdrecord -v.
$ sudo cdrecord -v -dummy dev=/dev/cd0c burn.iso cdrecord: No write mode specified. cdrecord: Assuming -tao mode. cdrecord: Future versions of cdrecord may have different drive dependent defaults. cdrecord: Continuing in 5 seconds... Cdrecord-Clone 2.01 (--) Copyright (C) 1995-2004 Jörg Schilling TOC Type: 1 = CD-ROM scsidev: '/dev/cd0c' devname: '/dev/cd0c' scsibus: -2 target: -2 lun: -2 Using libscg version 'schily-0.8'. SCSI buffer size: 61440 atapi: 0 Device type : Removable CD-ROM Version : 0 Response Format: 2 Capabilities : Vendor_info : 'MATSHITA' Identifikation : 'CD-RW CW-8123 ' Revision : 'CA0T' Device seems to be: Generic mmc2 DVD-ROM. Current: 0x0009 Profile: 0x0010 Profile: 0x0008 Profile: 0x0009 (current) Profile: 0x000A Using generic SCSI-3/mmc CD-R/CD-RW driver (mmc_cdr). Driver flags : MMC-2 SWABAUDIO BURNFREE Supported modes: TAO PACKET SAO SAO/R96P SAO/R96R RAW/R16 RAW/R96P RAW/R96R Drive buf size : 1731072 = 1690 KB FIFO size : 4194304 = 4096 KB Track 01: data 114 MB Total size: 130 MB (12:58.58) = 58394 sectors Lout start: 131 MB (13:00/44) = 58394 sectors Current Secsize: 2048 ATIP info from disk: Indicated writing power: 5 Is not unrestricted Is not erasable Disk sub type: Medium Type B, low Beta category (B-) (4) ATIP start of lead in: -11834 (97:24/16) ATIP start of lead out: 359849 (79:59/74) Disk type: Short strategy type (Phthalocyanine or similar) Manuf. index: 24 Manufacturer: Sony Corporation Blocks total: 359849 Blocks current: 359849 Blocks remaining: 301455 Starting to write CD/DVD at speed 24 in dummy TAO mode for single session. Last chance to quit, starting dummy write 0 seconds. Operation starts. Waiting for reader process to fill input buffer ... input buffer ready. BURN-Free is ON. Turning BURN-Free off Starting new track at sector: 0 Track 01: 114 of 114 MB written (fifo 100%) [buf 98%] 8.2x. Track 01: Total bytes read/written: 119586816/119586816 (58392 sectors). Writing time: 102.275s Average write speed 7.6x. Min drive buffer fill was 98% Fixating... WARNING: Some drives don't like fixation in dummy mode. Fixating time: 34.457s cdrecord: fifo had 1947 puts and 1947 gets. cdrecord: fifo was 0 times empty and 1860 times full, min fill was 80%. $ echo $? 0
An actual burn:
$ sudo cdrecord dev=/dev/cd0c burn.iso Password: cdrecord: No write mode specified. cdrecord: Assuming -tao mode. cdrecord: Future versions of cdrecord may have different drive dependent defaults. cdrecord: Continuing in 5 seconds... Cdrecord-Clone 2.01 (--) Copyright (C) 1995-2004 Jörg Schilling scsidev: '/dev/cd0c' devname: '/dev/cd0c' scsibus: -2 target: -2 lun: -2 Using libscg version 'schily-0.8'. Device type : Removable CD-ROM Version : 0 Response Format: 2 Capabilities : Vendor_info : 'MATSHITA' Identifikation : 'CD-RW CW-8123 ' Revision : 'CA0T' Device seems to be: Generic mmc2 DVD-ROM. Using generic SCSI-3/mmc CD-R/CD-RW driver (mmc_cdr). Driver flags : MMC-2 SWABAUDIO BURNFREE Supported modes: TAO PACKET SAO SAO/R96P SAO/R96R RAW/R16 RAW/R96P RAW/R96R Starting to write CD/DVD at speed 24 in real TAO mode for single session. Last chance to quit, starting real write 0 seconds. Operation starts. Track 01: Total bytes read/written: 119586816/119586816 (58392 sectors). $ echo $? 0
We should eject the finished disk now. The OS or drive might not know that the disk now has a filesystem on it.
$ sudo eject cd0
If we reinsert the disk then we can mount/unmount it:
$ sudo mount /dev/cd0a /mnt $ sudo umount /mnt