Debian GNU/Linux : Guide to Installation and Usage

Chapter 9

Chapter 93,949 wordsPublic domain

The file /etc/fstab (it stands for “filesystem table”) contains descriptions of filesystems that you mount often. These filesystems can then be mounted with a shorter command, such as mount /cdrom. You can also configure filesystems to mount automatically when the system boots. You’ll probably want to mount all of your hard disk filesystems when you boot, so Debian automatically adds entries to fstab to do this for you.

Look at this file now by typing more /etc/fstab. It will have two or more entries that were configured automatically when you installed the system. It probably looks something like this:

# /etc/fstab: static file system information. # / # / # # / # # # # /dev/hda1 / ext2 defaults 0 1 / /dev/hda3 none swap sw 0 0 / proc /proc proc defaults 0 0 /dev/hda5 /tmp ext2 defaults 0 2 / /dev/hda6 /home ext2 defaults 0 2 / /dev/hda7 /usr ext2 defaults 0 2 / /dev/hdc /cdrom iso9660 ro,noauto 0 0 / /dev/fd0 /floppy auto noauto,sync 0 0 / / / / / The first column lists the device the filesystem resides on. The second lists the mount point, the third indicates the filesystem type. The line beginning by proc is a special filesystem. Notice that the swap partition (/dev/hda3 in the example) has no mount point, so the mount point column contains none.

The last three columns may require some explanation.

The fifth column is used by the dump utility to decide when to back up the filesystem. In most cases, you can put 0 here.

The sixth column is used by fsck to decide in what order to check filesystems when you boot the system. The root filesystem should have a 1 in this field, filesystems that don’t need to be checked (such as the swap partition) should have a 0, and all other filesystems should have a 2. It’s worth noting that the swap partition isn’t exactly a filesystem in the sense that it does not contain files and directories but is just used by the Linux kernel as secondary memory. However, for historical reasons, the swap partitions are still listed in the same file as the filesystems.

Column four contains one or more options to use when mounting the filesystem. You can check the mount manpage for a summary; see section 5.1 on page [*].

10.2.4 Removable Disks (Floppies, Zip Disks, Etc.)

Add the following lines to your /etc/fstab file:

/dev/sda1 /mnt/zip ext2 noauto,user 0 0 / /dev/sda4 /mnt/dos msdos noauto,user 0 0 / / / / From now on, you’ll be able to mount the DOS-formatted Zip disks with the command mount /mnt/dos, and you be able to mount Linux-formatted Zip disks with the command mount /mnt/zip.

If you have SCSI hard disks in your system, you’ll have to change sda to sdb or sdc in the example above.

10.3 Backup Tools

Backups are important under any operating system. Debian GNU/Linux provides several different utilities that you might want to use. Additionally, while many of these utilities were aimed at tape backups originally, you’ll find that they are now being used for other things. For instance, tar is being used for distributing programs over the Internet. Some of the utilities that you’ll find include the following:

◼ Taper is a menu-driven, easy-to-learn backup program that can back up to a variety of media. Its limitation is that it doesn’t handle large (4GB or larger) backups. ◼ dump is designed specifically for tapes; its main strengths are its interface for file restores, low-level filesystem backups, and incremental backup scheduling. Its limitations include the inability to back up NFS or other non-ext2 filesystems and some rather arcane defaults. ◼ GNU tar (short for Tape ARchiver) is an implementation of what is probably the most widely used backup or archiving utility in Linux today. It makes a good general purpose tool and can deal with the widest variety of target media. Additionally, many different systems can read tar files, making them highly portable. tar’s weaknesses include a weaker incremental backup system than dump and no interactive restore selection screen.

10.3.1 tar

Because tar is used so much, and for quite a bit in addition to backups, it is being described here. For more details, see the tar manual page; instructions for viewing manual pages can be found in section 5.1 on page [*].

tar is an _archiver_. This means that tar can take many files and combine them all into one large file or write them out to a backup device such as a tape drive. Once you have this one large file, you will often want to compress it; the -z option is great for this. Hence, tar offers a great way to distribute programs and data on the Internet, and you’ll find that it is used extensively for this purpose.

Here’s a sample tar command line:

tar -zcvf myfiles.tar.gz /usr/local/bin

Let’s take a look at how this command can be broken down:

tar

Name of the command.—Tells tar that options will follow.

z

Tells tar to use gzip compression automatically; if you use this, it’s good to add a .gz extension as well.

c

Tells tar to create a new archive.

v

This says to be verbose; that is, it tells tar to let you know what it’s doing while it creates the archive.

f

This indicates that the next thing on the command line is the name of the file to be created or the device to be used. If I used /dev/st0 here, for instance, it would write the backup to the tape drive.

myfiles.tar.gz This is the name of the file to be created.

/usr/local/bi / / / / This is the name of the file or directory to store in the archive. It’s also possible to specify several items here.

You may often find tar.gz files (or simply tgz files) on the Internet. You can unpack these with a command like:

tar -zxvf filename.tar.gz

11. Networking

One of the key benefits of GNU/Linux over other systems lies in its networking support. Few systems can rival the networking features present in GNU/Linux. In this chapter, we tell you how to configure your network devices.

11.1 PPP

This section is a quick-start guide to setting up PPP on Debian. If it turns out that you need more details, see the excellent |PPP HOWTO| from the Linux Documentation Project. The HOWTO goes into much more detail if you’re interested or have unique needs.

11.1.1 Introduction

If you connect to the Internet over a phone line, you’ll want to use PPP (Point-to-Point Protocol). This is the standard connection method offered by ISPs (Internet service providers). In addition to using PPP to dial your ISP, you can have your computer listen for incoming connections - this lets you dial your computer from a remote location.

11.1.2 Preparation

Configuring PPP on Debian GNU/Linux is straightforward once you have all the information you’ll need. Debian makes things even easier with its simple configuration tools.

Before you start, be sure you have all the information provided by your ISP. This might include:

◼ Username or login ◼ Password ◼ Your static IP (Internet Protocol) address, if any (these look like 209.81.8.242). This information isn’t needed for most ISPs. ◼ Bitmask (this will look something like 255.255.255.248). This information isn’t needed for most ISPs. ◼ The IP addresses of your ISP’s name servers (or DNS). ◼ Any special login procedure required by the ISP.

Next, you’ll want to investigate your hardware setup: whether your modem works with GNU/Linux and which serial port it’s connected to.

A simple rule determines whether your modem will work. If it’s a “winmodem” or “host-based modem,” it won’t work. These modems are cheap because they have very little functionality, and they require the computer to make up for their shortcomings. Unfortunately, this means they are complex to program, and manufacturers generally do not make the specifications available for developers.

If you have a modem with its own on-board circuitry or an external modem, you should have no trouble at all.

On GNU/Linux systems, the serial ports are referred to as /dev/ttyS0, /dev/ttyS1, and so on. Your modem is almost certainly connected to /either port 0 or port 1, equivalent to COM1: and COM2: under Windows. If you don’t know which your modem is connected to, run the program wvdialconf to try to detect it (see below); otherwise, just try both and see which works.

If you want to talk to your modem or dial your ISP without using PPP, you can use the minicom program. You may need to install the minicom package to make the program available.

11.1.3 The Easy Way: wvdial

The simplest way to get PPP running is with the wvdial program. It makes some reasonable guesses and tries to set things up for you. If it works, you’re in luck. If it guesses wrong, you’ll have to do things manually.

Be sure you have the following packages installed:

◼ ppp ◼ ppp-pam ◼ wvdial

When you install the wvdial package, you may be given the opportunity to configure it. Otherwise, to set up wvdial, follow these simple steps:

Log in as root, using su (as described in an earlier chapter).

touch /etc/wvdial.conf

touch will create the following file if the file doesn’t exist; the configuration program requires an existing file.

wvdialconf /etc/wvdial.conf

This means you’re creating a configuration file, /etc/wvdial.conf.

Answer any questions that appear on the screen. wvdialconf will also scan for your modem and tell you which serial port it’s on; you may want to make a note of this for future reference.

11.2 Ethernet

Another popular way to connect to the Internet is via a LAN that uses Ethernet. This gives you a high-speed local network in addition to Internet access. Fortunately, though, you should have already configured Ethernet networking during installation so there isn’t much you need to do now. If you ever need to modify your configuration, here are the files that you will be interested in:

◼ /etc/init.d/network has things such as your IP address, netmask, and default route. ◼ /etc/hostname records your hostname. ◼ /etc/hosts also records your hostname and IP address.

12. Removing and Installing Software

This chapter describes ways of installing and removing software packages. There are several ways of doing both. Here we discuss installation and removal of pre-built software, such as Debian packages, and installation of source that must be built by you.

12.1 What a Package Maintenance Utility Does

An application or utility program usually involves quite a few files. It might include libraries, data files like game scenarios or icons, configuration files, manual pages, and documentation. When you install the program, you want to make sure you have all the files you need in the right places.

You’d also like to be able to uninstall the program. When you uninstall, you want to be sure all the associated files are deleted. However, if a program you still have on the system needs those files, you want to be sure you keep them.

Finally, you’d like to be able to upgrade a program. When you upgrade, you want to delete obsolete files and add new ones, without breaking any part of the system.

The Debian package system solves these problems. It allows you to install, remove, and upgrade software _packages_, which are neat little bundles containing the program files and information that helps the computer manage them properly. Debian packages have filenames ending in the extension .deb, and they’re available on the FTP site or on your official Debian CD-ROM.

12.2 dpkg

The simplest way to install a single package you’ve downloaded is with the command dpkg -i (short for dpkg -install). Say you’ve downloaded the package icewm_0.8.12-1.deb and you’d like to install it. First log on as root, and then type dpkg -i icewm_0.8.12-1.deb, and icewm version 0.8.12 will be installed. If you already had an older version, dpkg will upgrade it rather than installing both versions at once.

If you want to remove a package, you have two options. The first is most intuitive: dpkg -r icewm. This will remove the icewm package (-r is short for -remove). Note that you give only the icewm for -remove, whereas -install requires the entire .deb filename.

-remove will leave configuration files for the package on your system. A configuration file is defined as any file you might have edited in order to customize the program for your system or your preferences. This way, if you later reinstall the package, you won’t have to set everything up a second time.

However, you might want to erase the configuration files too, so dpkg also provides a -purge option. dpkg -purge icewm will permanently delete every last file associated with the icewm package.

12.3 dselect

dselect is a great front-end for dpkg. dselect provides a menu interface for dpkg, and can automatically fetch the appropriate files from a CD-ROM or Internet FTP site. For details on using dselect, see section 3.20 on page [*].

12.4 Compiling Software

Many programs come in source format, often in tar.gz form. First, you must unpack the tar.gz file; for details on doing this, see section 10.3.1 on page [*]. Before you can compile the package, you’ll need to have gcc, libc6-dev, and other relevant “-dev” packages installed; most of these are listed in the devel area in dselect.

With the appropriate packages installed, cd into the directory that tar created for you. At this point, you’ll need to read the installation instructions. Most programs provide an INSTALL or README file that will tell you how to proceed.

13. Advanced Topics

By now, you should have a strong base for which to build your GNU/Linux skills on. In this chapter we cover some very useful information regarding some advanced GNU/Linux features.

13.1 Regular Expressions

A regular expression is a description of a set of characters. This description can be used to search through a file by looking for text that matches the regular expression. Regular expressions are analogous to shell wildcards (see section 6.6 on page [*]), but they are both more complicated and more powerful.

A regular expression is made up of text and _metacharacters_. A metacharacter is just a character with a special meaning. Metacharacters include the following: . * [] - \^ $.

If a regular expression contains only text (no metacharacters), it matches that text. For example, the regular expression “my regular expression” matches the text “my regular expression,” and nothing else. Regular expressions are usually case sensitive.

You can use the egrep command to display all lines in a file that contain a regular expression. Its syntax is as follows:

egrep ’regexp’ filename1 ...

The single quotation marks are not always needed, but they never hurt.

For example, to find all lines in the GPL that contain the word GNU, you type

egrep ’GNU’ /usr/doc/copyright/GPL

egrep will print the lines to standard output. If you want all lines that contain freedom followed by some indeterminate text, followed by GNU, you can do this:

egrep ’freedom.*GNU’ /usr/doc/copyright/GPL

The . means “any character,” and the * means “zero or more of the preceding thing,” in this case “zero or more of any character.” So .* matches pretty much any text at all. egrep only matches on a line-by-line basis, so freedom and GNU have to be on the same line.

Here’s a summary of regular expression metacharacters:

. Matches any single character except newline.

* Matches zero or more occurrences of the preceding thing. So the expression a* matches zero or more lowercase a, and .* matches zero or more characters.

[_characters_] The brackets must contain one or more characters; the whole bracketed expression matches exactly one character out of the set. So [abc]matches one a, one b, or one c; it does not match zero characters, and it does not match a character other than these three.

^ Anchors your search at the beginning of the line. The expression ^The matches The when it appears at the beginning of a line; there can’t be spaces or other text before The. If you want to allow spaces, you can permit 0 or more space characters like this: ^ *The.

$ Anchors at the end of the line. end$ requires the text end to be at the end of the line, with no intervening spaces or text.

[^_characters_] This reverses the sense of a bracketed character list. So [^abc] matches any single character, _except_ a, b, or c.

[_character-character_] You can include ranges in a bracketed character list. To match any lowercase letter, use [a-z]. You can have more than one range; so to match the first three or last three letters of the alphabet, try [a-cx-z]. To get any letter, any case, try [a-zA-Z]. You can mix ranges with single characters and with the ^metacharacter; for example, [^a-zBZ]means “anything except a lowercase letter, capital B, or capital Z.”

() You can use parentheses to group parts of the regular expression, just as you do in a mathematical expression.

|| means “or.” You can use it to provide a series of alternative expressions. Usually you want to put the alternatives in parentheses, like this: c(ad|ab|at)matches cad or cab or cat. Without the parentheses, it would match cad or ab or at instead

\ Escapes any special characters; if you want to find a literal *, you type \*. The slash means to ignore *’s usual special meaning.

Here are some more examples to help you get a feel for things:

c.pe matches cope, cape, caper.

c\ .pe matches c.pe, c.per.

sto*p matches stp, stop, stoop.

car.*n matches carton, cartoon, carmen.

xyz.* matches xyz and anything after it; some tools, like egrep, only match until the end of the line.

^The matches The at the beginning of a line.

atime$ matches atime at the end of a line.

^Only$ matches a line that consists solely of the word Only—no spaces, no other characters, nothing. Only Only is allowed.

b[aou]rn matches barn, born, burn.

Ver[D-F] matches VerD, VerE, VerF.

Ver[^0-9] matches Ver followed by any non-digit.

the[ir][re] matches their, therr, there, theie.

[A-Za-z][A-Za-z]* matches any word which consists of only letters, and at least one letter. It will not match numbers or spaces.

13.2 Advanced Files

Now that you have a basic understanding of files, it is time to learn more advanced things about them.

13.2.1 The Real Nature of Files: Hard Links and Inodes

Each file on your system is represented by an _inode_ (for Information Node; pronounced “eye-node”). An inode contains all the information about the file. However, the inode is not directly visible. Instead, each inode is linked into the filesystem by one or more _hard links_. Hard links contain the name of the file and the inode number. The inode contains the file itself, i.e., the location of the information being stored on disk, its access permissions, the file type, and so on. The system can find any inode if it has the inode number.

A single file can have more than one hard link. What this means is that multiple filenames refer to the same file (that is, they are associated with the same inode number). However, you can’t make hard links across filesystems: All hard references to a particular file (inode) must be on the same filesystem. This is because each filesystem has its own set of inodes, and there can be duplicate inode numbers on different filesystems.

Because all hard links to a given inode refer to _the same file_, you can make changes to the file, referring to it by one name, and then see those changes when referring to it by a different name. Try this:

cd; echo "hello" > firstlink

cd to your home directory and create a file called firstlink containing the word “hello.” What you’ve actually done is redirect the output of echo (echo just echoes back what you give to it), placing the output in firstlink. See the chapter on shells for a full explanation.

cat firstlink

Confirms the contents of firstlink.

ln firstlink secondlink

Creates a hard link: secondlink now points to the same inode as firstlink.

cat secondlink

Confirms that secondlink is the same as firstlink.

ls -l

Notice that the number of hard links listed for firstlink and secondlinkfiles!inodes is 2.

echo "change" >> secondlink

This is another shell redirection trick (don’t worry about the details). You’ve appended the word “change” to secondlink. Confirm this with cat secondlink.

cat firstlink

firstlink also has the word “change” appended! That’s because firstlink and secondlink refer to _the same file_. It doesn’t matter what you call it when you change it.

chmod a+rwx firstlink

Changes permissions on firstlink. Enter the command ls -l to confirm that permissions on secondlink were also changed. This means that permissions information is stored in the inode, not in links.

rm firstlink

Deletes this link. This is a subtlety of rm. It really removes links, not files. Now type ls -l and notice that secondlink is still there. Also notice that the number of hard links for secondlink has been reduced to one.

rm secondlink

Deletes the other link. When there are no more links to a file, Linux deletes the file itself, that is, its inode.

All files work like this—even special types of files such as devices (e.g. /dev/hda).

A directory is simply a list of filenames and inode numbers, that is, a list of hard links. When you create a hard link, you’re just adding a name-number pair to a directory. When you delete a file, you’re just removing a hard link from a directory.

13.2.2 Types of Files

One detail we’ve been concealing up to now is that the Linux kernel considers nearly everything to be a file. That includes directories and devices: They’re just special kinds of files.

As you may remember, the first character of an ls -l display represents the type of the file. For an ordinary file, this will be simply -. Other possibilities include the following:

ddirectory lsymbolic link bblock device ccharacter device pnamed pipe ssocket

Symbolic Links

Symbolic links (also called “symlinks” or “soft links”) are the other kind of link besides hard links. A symlink is a special file that “points to” a hard link on any mounted filesystem. When you try to read the contents of a symlink, it gives the contents of the file it’s pointing to rather than the contents of the symlink itself. Because directories, devices, and other symlinks are types of files, you can point a symlink at any of those things.

So a hard link is a filename and an inode number. A file is really an inode: a location on disk, file type, permissions mode, etc. A symlink is an inode that contains the name of a hard link. A symlink pairs one filename with a second filename, whereas a hard link pairs a filename with an inode number.

All hard links to the same file have equal status. That is, one is as good as another; if you perform any operation on one, it’s just the same as performing that operation on any of the others. This is because the hard links all refer to the same inode. Operations on symlinks, on the other hand, sometimes affect the symlink’s own inode (the one containing the name of a hard link) and sometimes affect the hard link being pointed to.