# [SCRIPT] CD and DVD burning/ripping

## vandien

Here are a few scripts I use regularly. I helped install gentoo on a friends laptop he asked me to send these to him, so I thought some people here might find them useful too. I have them saved in /usr/local/bin so they can be accessed directly by typing their name.

```
#!/bin/bash

# burn-cd-dir <directory>

# makes an iso on the fly and burns it to a CD.

# requires: app-cdr/cdrtools

mkisofs -R -l $* | cdrecord dev=/dev/hdc speed=12 padsize=63s -eject -pad -v driveropts=burnfree -
```

```
#!/bin/bash

# burn-cd-iso <iso image>

# burns a pre-made .iso file to CD.

# requires: app-cdr/cdrtools

cdrecord dev=/dev/hdd speed=12 padsize=63s -dao -eject -pad -v driveropts=burnfree $*
```

```
#!/bin/bash

# burn-dvd-dir <directory>

# burns a directory to a DVD.

# requires: app-cdr/dvd+rw-tools

growisofs -use-the-force-luke=dao -dvd-compat -speed=2 -J -R -Z /dev/hdc $*
```

```
#!/bin/bash

# burn-dvd-iso

# burns a pre-made .iso file to a DVD.

# requires: app-cdr/dvd+rw-tools

growisofs -use-the-force-luke=dao -dvd-compat -speed=2 -Z /dev/hdc=$*
```

```
#!/usr/bin/perl

# calc <expression>

# simple command line calculator

print eval("@ARGV") . "\n";
```

```
#!/bin/bash

# check <word>

# spellcheck a word 

# requires: app-text/aspell app-dicts/aspell-en (or another dictionary)

echo "$@" | aspell -a | grep -v "^@" # | tac | tail -2 | tac
```

```
#!/bin/bash

# rawread /dev/hdc >output.iso

# creates an .iso from a cd/dvd in your cdrom drive.

# borrowed from http://www.troubleshooters.com/linux/coasterless.htm

# requires: app-cdr/cdrtools

device=$1

blocksize=`isoinfo -d -i $device | grep "^Logical block size is:" | cut -d " " -f 5`

if test "$blocksize" = ""; then

        echo catdevice FATAL ERROR: Blank blocksize >&2

        exit

fi

blockcount=`isoinfo -d -i $device | grep "^Volume size is:" | cut -d " " -f 4`

if test "$blockcount" = ""; then

        echo catdevice FATAL ERROR: Blank blockcount >&2

        exit

fi

command="dd if=$device bs=$blocksize count=$blockcount conv=notrunc,noerror"

echo "$command" >&2

$command
```

```
#!/usr/bin/perl

# mkdir <title of movie> and cd into it.

# ripdvd <source>

# quick, low-ish quality dvd-rip. good for animated movies.

# if you don't specify a source, it will default to dvd://1

# the source can be anything you can play with: mplayer <file>

# requires: media-video/mplayer (with proper USE flags set)

if("@ARGV" eq "") {

  $source = "dvd://1";

} else {

  $source = "@ARGV";

}

$title = `pwd`;

chomp($title);

$title =~ s|.+/||;

system("mencoder $source -o $title.avi -alang en -oac copy -ovc xvid -xvidencopts fixed_quant=4 -vobsubout $title -vobsuboutindex 0 -sid 0");
```

```
#!/usr/bin/perl

# mkdir <title of movie> and cd into it.

# ripdvd2 <source>

# long, 2 pass dvd-rip, better quality.

# it will stop after the first step and ask what bitrate you want.

# add "-ss 350 -endpos 20" to each command to test encoding.

# requires: media-video/mplayer (with proper USE flags set)

if("@ARGV" eq "") {

  $source = "dvd://1";

} else {

  $source = "@ARGV";

}

$title = `pwd`;

chomp($title);

$title =~ s|.+/||;

system("mencoder $source -oac copy -ovc frameno -o frameno.avi");

print "\nwhat bitrate do you want to encode at (1200)? ";

$bitrate = <STDIN>;

chomp($bitrate);

if($bitrate eq "") {

  $bitrate = "1200";

}

system("mencoder $source -oac copy -ovc xvid -xvidencopts pass=1:bitrate=$bitrate -o /dev/null");

system("mencoder $source -oac copy -ovc xvid -xvidencopts pass=2:bitrate=$bitrate -o $title.avi");
```

----------

## Aszrael

NICE - thanks for posting

Aszrael

----------

## fangorn

Very nice collection!!

at least there are some command line fans out there   :Cool: 

----------

## dkure

Just a quick comment on all these scripts, first off they seem great, one improvement that could be made with them is if no arguments are given, print how to use the script. This is always useful incase you have forgotten which script to use.

----------

## someguy

{root@oceania:/mnt/sda1/Movies/rips/animatrix}rip

MEncoder 1.0pre7try2-3.4.5 (C) 2000-2005 MPlayer Team

CPU: Advanced Micro Devices  (Family: 8, Stepping: 0)

Detected cache-line size is 64 bytes

CPUflags: Type: 8 MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1

Compiled for x86 CPU with extensions: MMX MMX2 3DNow 3DNowEx SSE SSE2

85 audio & 196 video codecs

File not found: 'frameno.avi'

Failed to open frameno.avi

xvidencopts is not an MEncoder option

Exiting... (error parsing cmdline)

i just want to rip and encode  :Sad: 

----------

## vandien

 *someguy wrote:*   

> 85 audio & 196 video codecs
> 
> File not found: 'frameno.avi'
> 
> Failed to open frameno.avi
> ...

 

Make sure you compiled mplayer with the xvid use flag? My flags look like this:

```
[ebuild   R   ] media-video/mplayer-1.0.20060415  USE="X aac alsa cpudetection dts dv dvd dvdread encode gif ipv6 jpeg mad matroska mmx png sdl sse truetype vorbis win32codecs x264 xv xvid -3dfx -3dnow -3dnowext -aalib -arts -bidi -bindist -bl -cdparanoia -custom-cflags -debug -dga -directfb -doc -dvb -edl -esd -fbcon -ggi -gtk -i8x0 -jack -joystick -libcaca -lirc -live -livecd -lzo -matrox -mmxext -musepack -nas -nvidia -openal -opengl -oss -real -rtc -samba -speex -sse2 -svga -tga -theora -unicode -v4l -v4l2 -xanim -xinerama -xmms -xvmc" 0 kB
```

Did you make any changes to the script or is it copied exactly?

----------

## zurd

To rip a DVD, this is what I use, no xvid or xvidencopts option :

1) Make sur the file frameno.avi doesn't exist :

rm frameno.avi

2) Gives us the vbitrate for the quality and an estimate of the filesize, takes only 5-15 minutes to complete :

mencoder -o frameno.avi -ovc frameno -oac mp3lame -lameopts vbr=3 -dvd-device /mnt/dvdrw dvd://1

3) This one takes a few hours though, don't forget to put the vbitrate you choose from number 2 at the 2 places :

mencoder -o movie.avi -ovc lavc -lavcopts vcodec=mpeg4:vpass=1:vbitrate=??? -oac copy -dvd-device /mnt/dvdrw dvd://1 && mencoder -o movie.avi -ovc lavc -lavcopts vcodec=mpeg4:vpass=2:vbitrate=??? -oac copy -dvd-device /mnt/dvdrw dvd://1

Note : Make sure you change /mnt/dvdrw to your location of your DVD

And does anyone have a script to convert mp3 to wav/cdr and burn them on a CD?  :Wink: 

----------

## linuxlife

```

#!/bin/bash

# burn-cd-dir <directory>

# makes an iso on the fly and burns it to a CD.

# requires: app-cdr/cdrtools

mkisofs -R -l $* | cdrecord dev=/dev/hdc speed=12 padsize=63s -eject -pad -v driveropts=burnfree -

```

Is there also a way to just write it down to a .iso file without burning to a CD directly? I dont have a cd-burner in my server (remote)..

----------

## zurd

linuxlife : of course, in fact, mkisofs creates the iso file then cdrecord burn it, so if you just call mkisofs it'll create the iso file for you.

Personally, I use :

mkisofs -JRv -o image.iso /some/directory

J is for using Joliet filename (windows)

R is for using Rockridge filename (linux)

v is for verbose

If it's for a DVD, there's always the -dvd-video for mkisofs.  You could always check the mkisofs --help, tough it is quite big :\

----------

## linuxlife

Thanks for this. I am using now this:

```

mkisofs -J -R -v -o /dev/sdb1/image.iso /

```

but then it tells me that it cant write the iso to disk. If i mount the /dev/sdb1 as /backup im sure it will try to backup the /dev/sdb1 disk too and get in a looping, so i wont try that. But i need to mount it before i can write the backup to it.

```

mount /dev/sdb1 /backup

mkisofs -J -R -v -o /backup/image.iso /dev/sda

```

Does also not work. How do i handle this?

----------

## zurd

But what do you want to accomplish exactly ?

----------

## linuxlife

 *zurd wrote:*   

> But what do you want to accomplish exactly ?

 

my sda disc does have 4 partitions, /boot /var /home /

my sdb disc has 1 partition /

i mount the sdb1 partition normally as /backup

i want to make a full backup of my sda disc and write it down to my sdb disc to the sdb1 partition so i can download it to my workstation and burn it on a cd-rom.

----------

## Arundel

Very nice! Thanks for sharing

----------

## zurd

linuxlife : Sorry for the delay, it's weird I didn't receive an e-mail from forums.gentoo.org that someone replied :\

Anyway, I see what you're trying to accomplish now, I think you should give this a try :

```
mkisofs -J -R -v -o /mnt/sdb1/image.iso -x /mnt -x /tmp -x /dev -x /proc /
```

so -x is to exclude some path, like here I excluded /mnt, /tmp, /dev and /proc, feel free to modify them as you wish.  The last / is to tell mkisofs to make an image of your root filesystem.  And be sure to not use -o /dev/something, that won't work, mount your backup hard disk to /mnt and use the -x /mnt to not include it.  That should do the trick!

----------

## linuxlife

Thanks zurd! I solved directly the other problem. Do nog include the /sys/ folder (/sys/ error):

"You really don't want to include /sys, or /proc, in an iso image (or in a tarball, for that matter)"

Finally a complete working set of commands to make a complete disk copy in .iso format:

```

mkdir /mnt/backup

mount /dev/sdb1 /mnt/backup

mkisofs -J -R -v -o /mnt/backup/image.iso -x /mnt -x /tmp -x /dev -x /sys -x /proc -x /usr/portage -x /var/tmp/portage /

mkisofs -J -R -v -o /mnt/backup/portage_files.iso /usr/portage /var/tmp/portage

```

```
Output:

-rw-r--r--  1 root root 861M Jun  6 06:42 image.iso

-rw-r--r--  1 root root 542M Jun  6 06:47 portage_files.iso

```

My only question left is: why do not include the /dev/ folder to the iso? When i do not add them i can put back the image on all sort of computers/servers, or is this list created every time on boot?

----------

## zurd

I'm not sure about the /dev folder, I think, tough, that with either devfs or udev, it is creating the list when you boot.

Anyway, why should we re-invent the wheel?  Check out this page on how to make a backup of your system, they created a nice working script for that :

http://blinkeye.ch/mediawiki/index.php/GNU/Linux_System_Backup_Script_%28stage4%29

It came from that thread :

https://forums.gentoo.org/viewtopic-p-2223380.html#2223380

----------

## linuxlife

Ah fine. Will fully read and try that tomorrow!

----------

## synss

 *dkure wrote:*   

> Just a quick comment on all these scripts, first off they seem great, one improvement that could be made with them is if no arguments are given, print how to use the script. This is always useful incase you have forgotten which script to use.

 

He is right on both points, for those who do not know how to do the usage trick, follow this example:

```
#!/bin/bash

if [ -z ${1} ]; then cat << EOF

burn-cd-iso <iso image>

burns a pre-made .iso file to CD.

requires: app-cdr/cdrtools

EOF

exit

fi

/usr/bin/cdrecord dev=/dev/hdd speed=12 padsize=63s -dao -eject -pad -v driveropts=burnfree $*

```

Simple.

 *zurd wrote:*   

> I'm not sure about the /dev folder, I think, tough, that with either devfs or udev, it is creating the list when you boot. 

 

If you use udev, /dev is mounted in RAM anyway (in tmpfs, I believe) so not saved after shutdown and is "dynamically" created when you boot and updated when you plug/unplug hardware. Do not make back ups of that guy.

----------

## linuxlife

Hey,

is it possible that after i did a format of both harddisks and i raw copy back the whole .iso burned cd to the harddisks that it wont run?

----------

## zurd

linuxlife : if you use dd if=/dev/hda of=/dev/hdb1/hda-backup.iso

and trying to use that iso to recreate hda it won't work out of the box.

You'll need to do a few other things like calling LILO or Grub and other things that I'm not all fully aware of.

To make a backup of your HD, you should use that link :

http://blinkeye.ch/mediawiki/index.php/GNU/Linux_System_Backup_Script_%28stage4%29

----------

## linuxlife

hehe ok, i should have done that some earlier  :Wink: 

----------

## synss

[EDIT: and I just found vlorb, emerge vlorb]

on the fly ripping at the console, for cd audio (can be improved but it does the job)

```
#!/bin/bash

#rip-cd-audio DIR

#

#rip-cd-audio on the fly

#

#requires ogg-vorbis, cdparanoia, cdplay

NBTRACK="$(cdplay -i | tail -1 | cut -d" " -f1)"

NLOOP=0

DIR="${1}"

[[ -z "${DIR}" ]] && DIR='ripped-audio-cd'

[[ -e "${DIR}" ]] && echo "${DIR} exists... exiting" && exit

mkdir "${DIR}"

cd "${DIR}"

while [[ $NLOOP -ne $NBTRACK ]]

do

   NLOOP=`expr $NLOOP + 1`

   cdparanoia -r $NLOOP - | oggenc -r -q6 -o track${NLOOP}.ogg -

done

```

----------

## mudrii

nice scripts

Thx for post

----------

