Debian GNU/Linux : Guide to Installation and Usage

Chapter 8

Chapter 84,062 wordsPublic domain

/etc/init.d/boot: Bourne shell script text / / / / meaning that this is a text file containing a Bourne shell script.

7.6 Using a File Manager

Instead of moving files around by hand, you can use a _file manager_. If you move a lot of files around, a file manager can make your work more efficient. There are text-based file managers, such as GNU Midnight Commander (mc), and a number of file managers for the X Window system (for example gmc for the X Window version of GNU Midnight Commander).

Describing each of these is outside the scope of this book, but you may want to try them out if the command line doesn’t meet your needs.

8. Working with Text Files

Text files are prevelant on a GNU/Linux system. They hold everything from documentation to configuration files. Fortunately, it’s easy to work with them.

8.1 Viewing Text Files

A _text file_ is simply a normal file that happens to contain human-readable text. There’s nothing special about it otherwise. The other kind of file, a binary file, is meant to be interpreted by the computer.

You can view either kind of file with the less file pager if you have it installed (install it if you haven’t, it’s quite useful). Type less /etc/profile to view a sample text file. Notice that you can read /the characters even if their meaning is obscure. Type less /bin/ls to view a binary file. As you can see, the ls program is not meant to be read by humans.

Sometimes, you’ll find files that end with .gz. These files may be viewed with zless; you can run it like so:

zless /usr/doc/ae/changelog.Debian.gz

Tip: zless is great for viewing documentation, which is often shipped in .gz form.

The difference between the two kinds of files is purely a matter of what they contain, unlike in some other systems (such as DOS and MacOS), which actually treat the files differently.

Text files can contain shell scripts, documentation, copyright notices, or any other human-readable text.

Incidentally, this illustrates the difference between _source code_ and _binary executables_. /bin/ls is a binary executable you can download from Debian, but you can also download a text file that tells the computer how to create /bin/ls. This text file is the source code. Comparing /bin/ls to /etc/profile illustrates how important source code is if someone wants to understand and modify a piece of software. Free software provides you or your consultants with this all-important source code.

8.2 Text Editors

A _text editor_ is a program used to create and change the contents of text files. Most operating systems have a text editor: DOS has edit, Windows has Notepad, MacOS has SimpleText.

Debian provides a large variety of text editors. vi and Emacs are the classic two, which are probably both the most powerful and the most widely used. Both vi and Emacs are quite complex and require some practice, but they can make editing text extremely efficient. Emacs runs both in a terminal and under the X Window system; vi normally runs in a terminal but the vim variant has a -g option that allows it to work with X. text editors

Simpler editors include nedit, ae, jed, and xcoral. nedit and xcoral provide easy-to-use X Window system graphical interfaces. There are also several vi variants. Additionally, you can find and a GNU Emacs variant called XEmacs.

This book does not cover the use of any particular editor in detail, though we will briefly introduce ae since it is small, fast, and can be found even on the Debian rescue disks, so it pays to know a bit about it for usage in a pinch. When you need to do more serious editing, check out vim or GNU Emacs. Emacs provides an excellent interactive tutorial of its own; to read it, load Emacs with the emacs command and type F1 t. Emacs is an excellent choice for new users interested in a general-purpose or programming editor.

8.3 Using ae

You can start ae by giving it the name of a file to edit, like so:

$ ae filename.txt

This will bring up an editor screen. The top part of this screen provides some quick help; the bottom shows the file you’re editing. Moving around in this editor is simple; just use the arrow keys. You can save the file by pressing C-x C-s and then exit the editor by pressing C-x C-c. Once you feel comfortable with the editor, you can press C-x C-h to turn off the help. That’s it! Knowing this will let you do basic editing. For programming or more detailed editing work, you’ll want to investigate other editors as discussed earlier.

9. The X Window System

This chapter describes the X Window system graphical user interface. It assumes that you have already successfully configured X as described in the Installation Manual (again, the install manual is not yet written; for now you will need to use the XFree86 HOWTO, the contents of /usr/doc/X11, and this chapter). Once you install X, you can enter the X environment by typing startx or via xdm, depending on your choice during configuration.

9.1 Introduction to X

A GUI (Graphical User Interface) is part and parcel of the Windows and Mac operating systems. It’s basically impossible to write an application for those systems that does not use the GUI, and the systems can’t be used effectively from the command line. GNU/Linux is more _modular_, that is, it’s made up of many small, independent components that can be used or not according to one’s needs and preferences. One of these components is the X Window system, or simply X.

This component is also sometimes called X11. Please note that “X Windows” is _not_ correct.

X itself is a means for programs to talk to your mouse and video card without knowing what kind of mouse and video card you have. That is, it’s an _abstraction_ of the graphics hardware. User applications talk to X in X’s language; X then translates into the language of your particular hardware. This means that programs only have to be written once, and they work on everyone’s computer.

In X jargon, the program that speaks to the hardware is known as an _X server_. User applications that ask the X server to show windows or graphics on the screen are called _X clients_. The X server includes a _video driver_, so you must have an X server that matches your video card.

The X server doesn’t provide any of the features one might expect from a GUI, such as resizing and rearranging windows. A special X client, called a _window manager_, draws borders and title bars for windows, resizes and arranges windows, and provides facilities for starting other X clients from a menu. Specific window managers may have additional features.

Window managers available on a Debian system include fvwm, fvwm2, icewm, afterstep, olvwm, wmaker, twm, and enlightenment. You’ll probably want to try them all and pick your favorite.

Neither the X server nor the window manager provide a _file manager;_ that is, there aren’t any windows containing icons for your files and directories. You can launch a file manager as a separate application, and there are many of them available. The GNOME desktop project is developing an icon-based file manager and other GUI facilities. See the GNOME homepage[1] for the latest news on this.

[1] http://www.gnome.org/

A final feature of X is its _network transparency_, meaning that X clients don’t care if they’re talking to an X server on the same machine or an X server somewhere on the network. In practical terms, this means you can run a program on a more powerful remote machine but display it on your desktop computer.

9.2 Starting the X Environment

There are two ways to start X. The first is to start X manually when you feel like using it. To do so, log in to one of the text consoles and type startx. This will start X and switch you to its virtual console.

The second (and recommended) way to use X is with xdm or X Display Manager. Basically, xdm gives you a nice graphical login prompt on the X virtual console (probably VC 7), and you log in there.

By default, either method will also start an xterm, which is a small window containing a shell prompt. At the shell prompt, you can type any commands just as you would on a text VC. So you can follow all the examples in this book using xterm; the only difference between an xterm and the text console is that you don’t have to log on to the xterm because you already logged on to X.

There are also a lot of things you can do only in X, which are covered in this chapter.

One note: The default xterm window has a smallish font. If you have a small monitor or very high resolution or bad eyesight, you may want to fix this. Follow these steps:

1. Move the mouse pointer into the center of the xterm window. 2. Hold down the Control key and the _right_ mouse button simultaneously. This will give you a font menu. 3. Point to the font you want and release the mouse button.

9.3 Basic X Operations

There are certain commonly used operations in X that you should familiarize yourself with. This section describes some of the basic operations that you may find useful.

9.3.1 The Mouse

The mouse in X works pretty much the same as the mouse on other systems, except that it has three buttons. If your mouse has only two, you can simulate the middle button by clicking both buttons simultaneously. This is kind of tricky and annoying, so investing in a $15 three-button mouse probably isn’t a bad idea. These are available from most computer retailers.

The buttons are numbered from left to right assuming you have a right-handed mouse. So button one is on the left, two is in the middle, and three is on the right. You may see either the numbers or the locations in documentation.

X has a simple built-in copy-and-paste facility. To select text to copy, you click and drag with the left mouse button. This should select the text to copy, assuming the application you’re using has copy-and-paste support. To paste the text, you click the middle mouse button in a different X application. For example, if you receive an e-mail containing an URL, you can select the URL with the left button and then click in your web browser’s “Location” field with the middle button to paste it in.

9.3.2 X Clients

Programs that communicate with the X server are called X clients. Most of these programs will ask the X server to display windows on the screen.

You start an X client the same way you start any other Debian program. Simply type the name of the client on the command line. Try typing xterm into an existing xterm window, and a new xterm client will appear on the screen.

You may notice that the original xterm is now useless, because your shell is waiting for the second xterm to finish. To avoid this problem, you can run the X client in the backgroundby adding a & after the command name like this: xterm &. If you forget, you can place a running process in the background. First suspend the process with CTRL-z, and then place it in the background with the bg command.

If you use a program often, your window manager will generally provide a way to put that program on a convenient graphical menu.

9.3.3 Troubleshooting

Sometimes when you launch an X client from a graphical menu, you won’t be able to see any error messages if it fails. You can find any error messages in the file ~/.xsession-errors.

9.3.4 Leaving the X Environment

To leave X, you need to use a menu. Unfortunately for beginners, this is different for every window manager, and for most window managers, it can be configured in many ways. If there’s an obvious menu, look for an entry like “Exit” or “Close Window Manager.” If you don’t see a menu, try clicking each of the mouse buttons on the background of the screen. If all else fails, you can forcibly kill the X server by pressing CTRL-ALT-Backspace. Forcibly killing the server destroys any unsaved data in open applications.

9.4 Customizing Your X Startup

When you start X, Debian runs some shell scripts that start your window manager and other X clients. By default, a window manager, an xconsole, and an xterm are started for you.

To customize your X startup, the file /etc/X11/config must contain the line allow-user-xsession. If it does not, log in as root and add the line now. Then log back in as yourself and continue the tutorial.

You can see how Debian’s X startup works in the file /etc/X11/ Xsession. Note that you can change the behavior of /etc/X11/Xsession by modifying the file /etc/X11/config, which specifies a few system-wide preferences.

To run the clients of your choice when X starts, you create an executable shell script called .xsession in your home directory.

$ touch ~/.xsession

This creates the file.

$ chmod u+x ~/.xsession

This makes the file executable.

Once .xsession is created, you need to edit it to do something useful with your favorite text editor. You can do anything you want to in this script. However, when the script’s process terminates, X also terminates.

In practical terms, this means that you often end the script with a call to exec. Whatever program you exec will replace the script process with itself, so commands found after the exec line will be ignored. The program you exec will become the new owner of the script process, which means that X will terminate when this new program’s process terminates.

Say you end your .xsession with the line exec fvwm. This means that the fvwm window manager will be run when X starts. When you quit the fvwm window manager, your X session will end, and all other clients will be shut down. You do not have to use a window manager here; you could exec xterm, in which case typing exit in that particular xterm would cause the entire X session to end.

If you want to run other clients before you use exec, you will need to run them in the background. Otherwise .xsession will pause until each client exits and then continue to the next line. See the previous section on running jobs in the background (basically you want to put an ampersand at the end, as in xterm &).

You can take advantage of this behavior, though. If you want to run commands at the end of your X session, you can have your .xsession run a window manager or the like and wait for it to finish. That is, leave off the exec and the &; just enter fvwm by itself. Then put the commands of your choice after fvwm.

It would probably help to look at a few sample .xsession files. In all the examples, replace fvwm with the window manager of your choice.

The simplest .xsession just runs a window manager:

exec fvwm

This will run fvwm, and the X session will end when fvwm exits. If you do it without the exec, everything will appear to behave the same way, but behind the scenes .xsession will hang around waiting for fvwm, and .xsession will exit after fvwm does. Using exec is slightly better because fvwm replaces .xsession instead of leaving it waiting. You can use the ps or top command to verify this.

A more useful .xsession runs a few clients before starting the window manager. For example, you might want some xterms and an xclock whenever you start X. No problem; just enter xterm & xterm & xclock & exec fvwm. Two xterms and an xclock start up in the background, and then the window manager is launched. When you quit the window manager, you’ll also quit X.

You might try it without the backgrounding just to see what happens. Enter this command: xterm xclock exec fvwm. xterm will start, and wait for you to exit it. Then xclock will start; you’ll have to exit xclock before fvwm will start. The commands are run in sequence, since the script waits for each one to exit.

You can use sequential execution to your advantage. Perhaps you want to keep track of when you stop working every day:

xterm & xclock & fvwm date >> ~/logout-time

This will fork off an xterm and an xclock and then run fvwm and wait for it to finish. When you exit fvwm, it will move on to the last line, which appends the current date and time to the file ~/logout-time.

Finally, you can have a program other than the window manager determine when X exits:

xclock & fvwm & exec xterm

This script will run xclock and fvwm in the background and then replace itself with xterm. When you exit the xterm, your X session will end.

The best way to learn how to use .xsession is to try some of these things out. Again, be sure you use chmod to make it executable; failure to do so is a common error.

10. Filesystems

A Debian system uses a filesystem to store and manage your data. This chapter introduces you to the filesystem, describes how to add and remove filesystems, and shows you how to back up your system.

10.1 Concepts

It’s probably a good idea to explain a little theory before discussing the mechanics of using disks. In particular, you must understand the concept of a _filesystem_. This can be a bit confusing because it has several meanings.

_The_ filesystem refers to the whole directory tree, starting with the root directory /, as described in earlier chapters.

A filesystem in general means any organization of files and directories on a particular physical device. “Organization” means the hierarchical directory structure and any other information about files one might want to keep track of: their size, who has permission to change them, etc. So you might have one filesystem on your hard disk, and another one on each floppy disk.

“Filesystem” is also used to mean a _type_ of filesystem. For example, MS-DOS and Windows 3.1 organize files in a particular way, with particular rules: Filenames can have only eight characters, for example, and no permission information is stored. Linux calls this the msdos filesystem. Linux also has its own filesystem, called the ext2 filesystem (version two of the ext filesystem). You’ll use the ext2 filesystem most of the time unless you’re accessing files from another operating system or have other special needs.

Any physical device you wish to use for storing files must have at least one filesystem on it. This means a filesystem in the second sense—a hierarchy of files and directories, along with information about them. Of course, any filesystem has a type, so the third sense will come into play as well. If you have more than one filesystem on a single device, each filesystem can have a different type—for example, you might have both a DOS partition and a Linux partition on your hard disk.

10.2 mount and /etc/fstab

This section describes how to mount a floppy or Zip disk, discusses the /dev directory, and addresses distributing the directory tree over multiple physical devices or partitions.

10.2.1 Mounting a Filesystem

On a GNU/Linux system there’s no necessary correspondence between directories and physical devices as there is in Windows, in which each drive has its own directory tree beginning with a letter (such as C:\).

Instead, each physical device such as a hard disk or floppy disk has one or more filesystems on it. In order to make a filesystem accessible, it’s assigned to a particular directory in another filesystem. To avoid circularity, the root filesystem (which contains the root directory /) is not stored within any other filesystem. You have access to it automatically when you boot Debian.

A directory in one filesystem that contains another filesystem is known as a _mount point_. A mount point is a directory in a first filesystem on one device (such as your hard disk) that “contains” a second filesystem, perhaps on another device (such as a floppy disk). To access a filesystem, you must mount it at some mount point.

So, for example, you might mount a CD at the mount point /cdrom. This means that if you look in the directory /cdrom, you’ll see the contents of the CD. The /cdrom directory itself is actually on your hard disk. For all practical purposes, the contents of the CD become a part of the root filesystem, and when you type commands and use programs, it doesn’t make any difference what the actual physical location of the files is. You could have created a directory on your hard disk called /cdrom and put some files in it, and everything would behave in exactly the same way. Once you mount a filesystem, there’s no need to pay any attention to physical devices.

However, before you can mount a filesystem or actually create a filesystem on a disk that doesn’t have one yet, it’s necessary to refer to the devices themselves. All devices have names, which are located in the /dev directory. If you type ls /dev now, you’ll see a pretty lengthy list of every possible device you could have on your Debian system. For a summary of some devices, see Table 2.1 on page [*]. A more thorough list can be found on your system in the file /usr/src/linux/Documentation/devices.txt.

To mount a filesystem, we want to tell Linux to associate whatever filesystem it finds on a particular device with a particular mount point. In the process, we might have to tell Linux what kind of filesystem to look for.

10.2.2 Example: Mounting a CD-ROM

As a simple demonstration, we’ll go through mounting a CD-ROM, such as the one you may have used to install Debian. You’ll need to be root to do this, so be careful; whenever you’re root, you have the power to manipulate the whole system, not just your own files. Also, these commands assume there’s a CD in your drive; you should put one in the drive now. Then start with the following command:

su

If you haven’t already, you need to either log in as root or gain root privileges with the su (super user) command. If you use su, enter the root password when prompted.

ls /cdrom

Use this command to see what’s in the /cdrom directory before you start. If you don’t have a /cdrom directory, you may have to make one using mkdir /cdrom.

mount

Simply typing mount with no arguments lists the currently mounted filesystems.

mount -t iso9660 _CD-device_ /cdrom

For this command, you should substitute the name of your CD-ROM device for _CD-device_ in the above command line. If you aren’t sure, /dev/cdrom is a good guess because the install process should have created this symbolic link on the system. If that fails, try the different IDE devices: /dev/hdc, etc. You should see a message like this: mount: block /device dev/hdc is write-protected, mounting read-only. / / / The -t option specifies the type of the filesystem, in this case iso9660. Most CDs are iso9660. The next argument is the name of the device to mount, and the final argument is the mount point. There are many other arguments for mount; see the manual page for details.

Once a CD is mounted, you may find that your drive tray will not open. You must unmount the CD before removing it.

ls /cdrom

Confirms that /cdrom now contains whatever is on the CD in your drive.

mount

Displays the list of filesystems again; notice that your CD drive is now mounted.

umount /cdrom

This unmounts the CD. It’s now safe to remove the CD from the drive. Notice that the command is umount with no “n,” even though it’s used to unmount the filesystem.

exit

Don’t leave yourself logged on as root. Log out immediately, just to be safe.

10.2.3 /etc/fstab: Automating the Mount Process