Linux notes

Writing CDs & DVDs

I've found many of the CD-burning GUIs included in various Linux distributions are more trouble than they're worth. Here's how to bypass them and burn CDs and DVDs directly from the command line.

Burning a CD

You need to know the name of your CD and/or DVD burner(s). On my system I have two:

You'll use the program cdrecord to burn the disc. This is a very versatile program; use man cdrecord to read the manual page on it. There are many options, most of which you can ignore for plain-and-simple burning.

Burning a CD from an .iso image file

Use this method when you have an .iso image file of the data you want. Things like Linux distributions are often distributed as a single .iso file, which you download and then burn to a CD. To burn the CD from the .iso file is straightforward - here is an example.

cdrecord dev=/dev/hdd /home/chris/Desktop/ubuntu6.10desktopi386.iso

This tells cdrecord to use the .iso image file ubuntu6.10desktopi386.iso, which is in the directory /home/chris/Desktop/, and create a disc from it using the CD writer device specified by dev=/dev/hdd (this is the Sony CDRW CRX216E on my system).

cdrecord will respond with a load of output to the terminal window, which you can happily ignore - it will write the disc correctly.

Burning the contents of a directory to a CD

In order to burn the contents of one or more directories to a CD, you use a program called mkisofs to gather together everything you want to put on the CD into a single file. This file is then used to create the disc using cdrecord, as in the example above. In the following example, I want to burn everything in the directory /home/chris/mydata to CD.

mkisofs -R -o temp_file.raw /home/chris/mydata cdrecord dev=/dev/hdd temp_file.raw

The first line invokes mkisofs to create a filesystem that can be written to the CD. The program takes all the files and directories you want on the disc and packages them into another file, the name of which you specify using the -o switch (here it is 'temp_file.raw'). The -R switch generates additional file information using the Rock Ridge protocol - you don't need to worry about this - take a look at man mkisofs if you are curious.

Burning files to a DVD

DVD writing has historically been a hassle in Linux; fortunately it is easy from the command line. We use the rather oddly named program growisofs to handle the job. Here we want to burn a couple of large files to a DVD.

growisofs -dvd-compat -speed=2 -Z /dev/hdc -R -J -pad "The Root of All Evil - The God Delusion (1 of 2).avi" "The Root of All Evil - The Virus of Faith (2 of 2).avi"

The various options are described in the manual entry for growisofs, but essentially -dvd-compat ensures maximum DVD compatibility, the -speed option sets the speed of the writing process, -Z, -R and -J options set ISO9660, Rock Ridge and Joliet options. The DVD burner to use is specified by /dev/dvd. Notice that the files to be written have awkward spaces in them, and so they are surrounded by double quotes. The two filenames are simply separated by spaces. This will generate a DVD containing the two files specified.

Burning a DVD from an .iso image file

Here we are burning a DVD from a single .iso image file:

growisofs -dvd-compat -Z /dev/hdc=/home/chris/Desktop/evilroot.iso

Whatever file layout we had created in the .iso image file will be reproduced on the DVD.

Setting xterm colours

I use Cygwin, and one thing that is annoying is the default colours used in xterm, the X terminal window that is invoked when you issue the command startx. I prefer a black background and white text, rather than the other way around. Setting this the way I like led me a merry chase through a number of dead ends... here is the method I found to work

In your Cygwin root directory (get there with cd ~), create an .Xdefaults file. Initially this will be empty. You will fill this file with commands that set various X resources to values that make xterm look like you want it to.

The xterm man page describes, under 'Resources', those that you can change and affect xterm. The most useful ones for setting colours are:

There are many colours that you can specify by name. The colours and their names are listed in a file, rgb.txt, that lives in the directory /usr/lib/X11. For simplicity, you can see the file from my Cygwin setup here.

Your .Xdefaults file will be very simple if you are just setting colours - here is the file from my Cygwin setup.

Setting the PATH variable

In Cygwin

If you create a subdirectory to hold scripts that you write - let's say you are unimaginative enough to call this directory 'scripts' - then you'll need to modify the $PATH environment variable in order to be able to run those scripts from anywhere, rather than having to be in the scripts directory. A good way to do this automatically, every time you start Cygwin, is to add a command to do so to the .bashrc file. This command will append any additions to the path to the existing $PATH variable. In the bash shell, variables are modified with the export keyword, and it is used to modify the $PATH variable like this:

export PATH=$PATH:"/cygdrive/c/Documents and Settings/ccarter.GEMINI-HILO/scripts"

Note the use of the double quotes around the addition. This is necessary because of the spaces in the path that I wanted to add. If you leave the quotes out, bash will complain and refuse to change the $PATH. If your changes to $PATH are rational, i.e. if you're not doing this on a Windows box under Cygwin, you probably won't have to bother as your extensions to $PATH won't include any spaces.

For completeness, here is my .bashrc file.

In Debian or Ubuntu

On recent Debian or Ubuntu systems I have found the above method not to work. What did work was to modify the /etc/environment file, then log out and log back in again. You should then find any PATH statement you put in the environment file has been read and the path updated accordingly.

Below is what the /etc/environment could look like on a typical machine. Note that it just consists of a single PATH statement, and the user ('joeuser') has added the path to a 'scripts' directory at the end.


Using SSH with X11 forwarding

This feature of SSH is a great timesaver in that it eliminates the need to manually set the $DISPLAY environment variable every time you connect to a remote machine and want to run an X application.

When you connect to your remote machine, you should use the following sequence.

xhost + ssh -X -l user

The first line allows anyone to make connections to the X server running on your machine, which is necessary to make the connection you need. The second line establishes the SSH connection to the remote host ('') as the user 'user'. The -X switch does the magic, by enabling X11 forwarding. To see if it is working, try invoking a small X11 program on the remote machine; say xclock or xcalc.

xclock &
xcalc &

If you try this and get '~$ Error: Can't open display:', check that the SSH configuration on the remote machine is actually allowing X11 forwarding. To disallow it is the default.

Modifying your SSH server (daemon) configuration

The SSH daemon (sshd) is configured by a file called sshd_config, which lives at /etc/ssh/sshd_config on my machine. To allow X11 forwarding, simply change the line 'X11Forwarding no' to 'X11Forwarding yes' and then restart SSH (see below).

Checking the amount of available disk space

Linux has a comprehensive tool to report on the usage of disk ('filesystem') space on your machine - the program is called df (man page). However its default output is somewhat awkward to decipher, as it doesn't break the often rather large numbers representing free and used space down with appropriate units. So, the command:


will result in something like this:

Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda1 76185728 35752372 36563300 50% / tmpfs 128212 0 128212 0% /dev/shm tmpfs 10240 808 9432 8% /dev user@machine:~$

which, while correct, is less comprehensible than the result you get when you add the switch -h, or --human-readable.

df -h

Filesystem Size Used Avail Use% Mounted on /dev/hda1 73G 35G 35G 50% / tmpfs 126M 0 126M 0% /dev/shm tmpfs 10M 808K 9.3M 8% /dev user@machine:~$

Using man (manual) pages effectively

Linux encapsulates a lot of its documentation in the so-called 'man' pages ('man' meaning 'manual'). Man pages are accessed from the command line like this:
man ssh
which displays the first page of the manual entry for the 'ssh' command. You can scroll up or down a line at a time using the arrow keys; or down a page at a time by pressing the space bar. The 'u' and 'd' keys also scroll up and down by less than a full page.

Man sections

What is not often realised is that the manual pages are divided into sections, of which there are ten. You'll see the section that a command comes from in brackets after its name, on the first page of its manual entry. For example:
SSH(1) BSD General Commands Manual SSH(1) NAME ssh - OpenSSH SSH client (remote login program)
The '(1)' means that this command is contained in Section 1 of the manual documentation (Section 1 is 'user commands', by the way). If there is another command with the same name in another section - as sometimes happens - you can direct man to a particular section placing the section number between the command and its argument, like this:
man 6 banner
which directs man to display the manual page on the banner command from section 6 ('games'). Note that this is not required if there is only one entry for banner across the all the sections. In this case,
man banner
is just as effective.


Some tips that are just too concise for their own section.

Still to come...