Debian GNU/Linux : Guide to Installation and Usage
Chapter 10
There are a number of important differences between symlinks and hard links.
Symlinks can cross filesystems. This is because they contain complete filenames, starting with the root directory, and all complete filenames are unique. Because hard links point to inode numbers, and inode numbers are unique only within a single filesystem, they would be ambiguous if the filesystem wasn’t known.
You can make symlinks to directories, but you can’t make hard links to them. Each directory has hard links—its listing in its parent directory, its . entry, and the .. entry in each of its subdirectories—but to impose order on the filesystem, no other hard links to directories are allowed. Consequently, the number of files in a directory is equal to the number of hard links to that directory minus two (you subtract the directory’s name and the . link). comparing!hard links and symlinks You can only make a hard link to a file that exists, because there must be an inode number to refer to. However, you can make a symlink to any filename, whether or not there actually is such a filename.
Removing a symlink removes only the link. It has no effect on the linked-to file. Removing the only hard link to a file removes the file.
Try this:
cd; ln -s /tmp/me MyTmp
cd to your home directory. ln with the -s option makes a symbolic link - in this case, one called MyTmp that points to the filename /tmp/me.
ls -l MyTmp
Output should look like this:
lrwxrwxrwx 1 havoc havoc 7 Dec 6 12:50 MyTmp -> /tmp/me
The date and user/group names will be different for you, of course. Notice that the file type is l, indicating that this is a symbolic link. Also notice the permissions: Symbolic links always have these permissions. If you attempt to chmod a symlink, you’ll actually change the permissions on the file being pointed to.
chmod 700 MyTmp
You will get a No such file or directory error, because the file /tmp/me doesn’t exist. Notice that you could create a symlink to it anyway.
mkdir /tmp/me
Creates the directory /tmp/me.
chmod 700 MyTmp
Should work now.
touch MyTmp/myfile
Creates a file in MyTmp.
ls /tmp/me
The file is actually created in /tmp/me.
rm MyTmp
Removes the symbolic link. Notice that this removes the link, not what it points to. Thus you use rm not rmdir.
rm /tmp/me/myfile; rmdir /tmp/me
Lets you clean up after yourself. symlinks!removing
Device Files
Device files refer to physical or virtual devices on your system, such as your hard disk, video card, screen, and keyboard. An example of a virtual device is the console, represented by /dev/console.
There are two kinds of devices:character and block. _Character devices_ can be accessed one character at a time. Remember the smallest unit of data that can be written to or read from the device is a character (byte).
_Block devices_ must be accessed in larger units called blocks, which contain a number of characters. Your hard disk is a block device.
You can read and write device files just as you can from other kinds of files, though the file may well contain some strange incomprehensible-to-humans gibberish. Writing random data to these files is probably a bad idea. Sometimes it’s useful, though. For example, you can dump a postscript file into the printer device /dev/lp0 or send modem commands to the device file for the appropriate serial port.
/dev/null / / / /dev/null is a special device file that discards anything you write /to it. If you don’t want something, throw it in /dev/null. It’s essentially a bottomless pit. If you read /dev/null, you’ll get an end-of-file (EOF) character immediately. /dev/zero is similar, except that you read from it you get the \0 character (not the same as the number zero).
Named Pipes (FIFOs)
A named pipe is a file that acts like a pipe. You put something into the file, and it comes out the other end. Thus it’s called a FIFO, or First-In-First-Out, because the first thing you put in the pipe is the first thing to come out the other end.
If you write to a named pipe, the process that is writing to the pipe doesn’t terminate until the information being written is read from the pipe. If you read from a named pipe, the reading process waits until there’s something to read before terminating. The size of the pipe is always zero: It doesn’t store data, it just links two processes like the shell |. However, because this pipe has a name, the two processes don’t have to be on the same command line or even be run by the same user.
You can try it by doing the following:
cd; mkfifo mypipe
Makes the pipe.
echo "hello" > mypipe &
Puts a process in the background that tries to write “hello” to the pipe. Notice that the process doesn’t return from the background; it is waiting for someone to read from the pipe.
cat mypipe
At this point, the echo process should return, because cat read from the pipe, and the cat process will print hello.
rm mypipe
You can delete pipes just like any other file.
Sockets
Sockets are similar to pipes, only they work over the network. This is how your computer does networking. You may have heard of “WinSock,” which is sockets for Windows.
We won’t go into these further because you probably won’t have occasion to use them unless you’re programming. However, if you see a file marked with type son your computer, you know what it is.
13.2.3 The proc Filesystem
The Linux kernel makes a special filesystem available, which is mounted under /proc on Debian systems. This is a “pseudo-filesystem” because it doesn’t really exist on any of your physical devices.
The proc filesystem contains information about the system and running processes. Some of the “files” in /proc are reasonably understandable to humans (try typing cat /proc/meminfo or cat /proc/cpuinfo); others are arcane collections of numbers. Often, system utilities use these to gather information and present it to you in a more understandable way.
People frequently panic when they notice one file in particular— /proc/kcore —which is generally huge. This is (more or less) a copy /of the contents of your computer’s memory. It’s used to debug the kernel. It doesn’t actually exist anywhere, so don’t worry about its size.
If you want to know about all the things in /proc, type man 5 proc.
13.2.4 Large-Scale Copying
Sometimes you may want to copy one directory to another location. Maybe you’re adding a new hard disk and you want to copy /usr/local to it. There are several ways you can do this.
The first is to use cp. The command cp -a will tell cp to do a copy preserving all the information it can. So, you might use
cp -a /usr/local /destination
However, there are some things that cp -a won’t catch[1]. So, the best way to do a large copy job is to chain two tar commands together, like so:
[1] Sparse files and hard links are two examples.
tar -cSpf - /usr/local | tar -xvSpf - -C /destination
The first tar command will archive the existing directory and pipe it to the second. The second command will unpack the archive into the location you specify with -C.
13.3 Security
Back in section 7.1 on page [*], we discussed file permissions in Linux. This is a fundamental way to keep your system secure. If you are running a multi-user system or a server, it is important to make sure that permissions are correct. A good rule of thumb is to set files to have the minimum permissions necessary for use.
If you are running a network server, there are some other things to be aware of as well. First, you ought to uninstall or turn off any network services you’re not using. A good place to start is the file /etc/inetd.conf; you can probably disable some of these. For most /network services, it’s also possible to control who has access to them; the /etc/hosts.allow and /etc/hosts.deny files (documented in man 5 hosts_access) can control who has access to which services. You also ought to keep up-to-date with patches or updates to Debian; these can be found on your nearest Debian FTP mirror.
Some other commonsense rules apply:
◼ Never tell anyone your password. ◼ Never send your password in cleartext across the Internet by using something like telnet or FTP. Instead, use encrypted protocols or avoid logging in remotely. ◼ Avoid using root as much as possible. ◼ Don’t install untrusted software, and don’t install it as root. ◼ Avoid making things world-writable whenever possible. /tmp is one exception to this rule.
While this is probably not of as much use to somebody not running a server, it is still pays to know a bit about security. Debian’s security mechanism is what protects your system from many viruses.
13.4 Software Development with Debian
Debian makes a great platform for software development and programming. Among the languages and near-languages it supports are: C, C++, Objective-C, Perl, Python, m4, Ada, Pascal, Java, awk, Tcl/Tk, SQL, assembler, Bourne shell, csh, and more. Writing programs is beyond the scope of this book, but here are some of the more popular development programs in Debian:
gcc The GNU C Compiler, a modern optimizing C compiler.
g++ The C++ compiler from the gcc line.
cpp The C preprocessor from gcc.
perl The Perl interpreter. Perl is a great “glue” language.
gdb GNU Debugger, used to debug programs in many different languages.
gprof Used for profiling, this program helps you to find ways to improve the performance of your programs.
emacs GNU Emacs is a programmers’ editor and IDE.
as The GNU Assembler.
II. Reference
A. Reading Documentation and Getting Help
A.1 Kinds of Documentation
On Debian systems, you can find documentation in at least the following places:
◼ man pages, read with the man command. ◼ info pages, read with the info command. ◼ The /usr/doc/_package_ directories, where package is the name of the Debian package.
Tip: zless is useful for reading the files in /usr/doc; see section 8.1 on page [*] for details.
◼ /usr/doc/HOWTO/contains the Linux Documentation Project’s HOWTO documents, if you’ve installed the Debian packages containing them. ◼ Many commands have an -h or -help option. Type the command name followed by one of these options to try it. ◼ The Debian Documentation Project[1] has written some manuals. ◼ The Debian support page[2] has a FAQ and other resources. You can also try the Linux web site[3].
[1] http://www.debian.org/~elphick/ddp/
[2] http://www.debian.org/support/
[3] http://www.linux.org
The confusing variety of documentation sources exists for many reasons. For example, info is supposed to replace man, but man hasn’t disappeared yet. However, it’s nice to know that so much documentation exists!
So where to look for help? Here are some suggestions:
◼ Use the man pages and the -help or -h option to get a quick summary of a command’s syntax and options. Also use man if a program doesn’t yet have an info page. ◼ Use info if a program has info documentation. ◼ If neither of those works, look in /usr/doc/_packagename_. ◼ /usr/doc/_packagename_ often has Debian-specific information, even if there’s a man page or info page. ◼ Use the HOWTOs for instructions on how to set up a particular thing or for information on your particular hardware. For example, the Ethernet HOWTO has a wealth of information on Ethernet cards, and the PPP HOWTO explains in detail how to set up PPP. ◼ Use the Debian Documentation Project manuals for conceptual explanations and Debian-specific information. ◼ If all else fails, ask someone. See section A.1.3 on page [*]. Using man pages is discussed above in section 5.1 on page [*]. It’s very simple: press the space bar to go to the next page, and press q to quit reading. Using info, viewing files in /usr/doc, and asking for help from a person are all discussed in the remainder of this chapter.
A.1.1 Using info
info is the GNU documentation viewer. Some programs provide documentationin info format, and you can use info to view that documentation. You can start up the viewer by simply typing info, or by supplying a topic as well:
info emacs
You can also bring up the information on info itself, which includes a tutorial, like so:
info info
Now, you may navigate with these keys:
arrows
Move the cursor around the document
m RET
Select the menu item that’s at the cursor
u
Move “up” in the document
n
Move to the next page
p
Move to the previous page
s
Search for something
g
Go to a specific page
q
Quit info
You might notice that the top line of the screen indicates the next, previous, and “up” pages, corresponding nicely to the actions for the n, p, and u keys.
A.1.2 HOWTOs
In addition to their books, the Linux Documentation Project has made a series of short documents describing how to set up particular aspects of GNU/Linux. For instance, the SCSI-HOWTO describes some of the complications of using SCSI—a standard way of talking to devices—with GNU/Linux. In general, the HOWTOs have more specific information about particular hardware configurations and will be more up to date than this manual.
There are Debian packages for the HOWTOs. doc-linux-text contains the various HOWTOs in text form; the doc-linux-html package contains the HOWTOs in (surprise!) browsable HTML format. Note also that Debian has packaged translations of the HOWTOs in various languages that you may prefer if English is not your native language. Debian has packages for the German, French, Spanish, Italian, Japanese, Korean, Polish, Swedish and Chinese versions of the HOWTOs. These are usually available in the package doc-linux-_languagecode_, where _languagecode_ is fr for French, es for Spanish, etc. If you’ve installed one of these, you should have them in /usr/doc/HOWTO. However, you may be able to find more recent /versions on the Net at the LDP homepage[4].
[4] http://www.metalab.unc.edu/LDP/
A.1.3 Personal Help
The correct place to ask for help with Debian is the debian-user mailing list at [email protected]. If you know how to use IRC (Internet Relay Chat), you can use the #debian channel on irc.debian.org. You can find general GNU/Linux help on the comp.os.linux.* USENET hierarchy. It is also possible to hire paid consultants to provide guaranteed support services. The Debian website[5] has more information on many of these resources.
[5] http://www.debian.org/
Again, please _do not_ ask the authors of this book for help. We probably don’t know the answer to your specific problem anyway; if you mail debian-user, you will get higher-quality responses, and more quickly.
Always be polite and make an effort to help yourself by reading the documentation. Remember, Debian is a volunteer effort and people are doing you a favor by giving their time to help you. Many of them charge hundreds of dollars for the same services during the day.
Tips for asking questions
◼ Read the obvious documentation first. Things like command options and what a command does will be covered there. This includes manpages and info documentation. ◼ Check the HOWTO documents if your question is about setting up something such as PPP or Ethernet. ◼ Try to be sure the answer isn’t in this book. ◼ Don’t be afraid to ask, after you’ve made a basic effort to look it up. ◼ Don’t be afraid to ask for conceptual explanations, advice, and other things not often found in the documentation. ◼ Include any information that seems relevant. You’ll almost always want to mention the version of Debian you’re using. You may also want to mention the version of any pertinent packages: The command dpkg -l _packagename_ will tell you this. It’s also useful to say what you’ve tried so far and what happened. Please include the exact error messages, if any. ◼ Don’t apologize for being new to Linux. There’s no reason everyone should be a GNU/Linux expert to use it, any more than everyone should be a mechanic to use a car. ◼ Don’t post or mail in HTML. Some versions of Netscape and Internet Explorer will post in HTML rather than plain text. Most people will not even read these posts because the posts are difficult to read in most mail programs. There should be a setting somewhere in the preferences to disable HTML. ◼ Be polite. Remember that Debian is an all-volunteer effort, and anyone who helps you is doing so on his or her time out of kindness. ◼ Re-mail your question to the list if you’ve gotten no responses after several days. Perhaps there were lots of messages and it was overlooked. Or perhaps no one knows the answer—if no one answers the second time, this is a good bet. You might want to try including more information the second time. ◼ Answer questions yourself when you know the answer. Debian depends on everyone doing his or her part. If you ask a question, and later on someone else asks the same question, you’ll know how to answer it. Do so!
A.1.4 Getting Information from the System
When diagnosing problems or asking for help, you’ll need to get information about your system. Here are some ways to do so:
◼ Examine the files in /var/log/. ◼ Examine the output of the dmesg command. ◼ Run uname -a.
B. Troubleshooting
In Debian, as in life, things don’t always work as you might expect or want them to. While Debian has a well-deserved reputation for being rock-solid and stable, sometimes its reaction to your commands may be unexpected. Here, we try to shed some light on the most common problems that people encounter.
B.1 Common Difficulties
This section provides some tips for handling some of the most frequently experienced difficulties users have encountered.
B.1.1 Working with Strangely-Named Files
Occasionally, you may find that you have accidentally created a file that contains a character not normally found in a filename. Examples of this could include a space, a leading hyphen, or maybe a quotation mark. You may find that accessing, removing, or renaming these files can be difficult.
Here are some tips to help you:
◼ Try enclosing the filename in single quotation marks, like this: less ’File With Spaces.txt’ ◼ Insert a ./ before the filename: less ’./-a strange file.txt’ ◼ Use wildcards: less File?With?Spaces.txt ◼ Use a backslash before each unusual character: less File\ With\ Spaces.txt
B.1.2 Printing
One common source of trouble is the printing system in Debian. Traditionally, printing has been a powerful but complex aspect of Unix. However, Debian makes it easier. An easy way to print is with the package called magicfilter. magicfilter will ask you a few questions about your printer and then configure it for you. If you are having troubles printing, give magicfilter a try.
B.1.3 X Problems
Many questions revolve around X. Here are some general tips for things to try if you are having difficulties setting up the X Window system:
◼ For mouse problems, run XF86Setup and try the PS/2, Microsoft, MouseSystems, and Logitech options. Most mice will fit under one of these. Also, the device for your mouse is /dev/psaux for PS/2 mice and a serial port such as /dev/ttyS0 for serial mice. ◼ If you don’t know what video chipset you have, try running SuperProbe; it can often figure this out for you. ◼ If your screen doesn’t have a lot of color, try selecting a different video card or tell X how much video RAM you have. ◼ If your screen goes blank or has unreadable text when you start X, you probably selected an incorrect refresh rate. Go back to XF86Setup or xf86config and double-check those settings. ◼ xvidtune can help if the image on the screen is shifted too far to the left or right, is too high or low, or is too narrow or wide. ◼ xdpyinfo can give information about a running X session. ◼ XF86Setup can set your default color depth. ◼ You can select your default window manager by editing /etc/X11/window-managers. / ◼ /var/log/xdm-errors can contain useful information if you are having trouble getting xdm to start properly.
As a final reminder, try the XF86Setup or xf86config tools for configuring or reconfiguring X for your hardware.
B.2 Troubleshooting the Boot Process
If you have problems during the boot process, such as the kernel hangs during the boot process, the kernel doesn’t recognize peripherals you actually have, or drives are not recognized properly, the first things to check are the boot parameters. They can be found by pressing F1 when booting from the rescue disk.
Often, problems can be solved by removing add-ons and peripherals and then booting again. Internal modems, sound cards, and Plug-n-Play devices are especially problematic.
Tecras and other notebooks, and some non-portables fail to flush the cache when switching on the A20 gate, which is provoked by bzImage kernels but not by zImage kernels. If your computer suffers from this problem, you’ll see a message during boot saying A20 gating failed. In this case, you’ll have to use the ‘tecra’ boot images.
If you still have problems, please submit a bug report. Send an email to [email protected]. You _must_ include the following as the first lines of the email:
Package: boot-floppies Version: _version_
Make sure you fill in version with the version of the boot-floppies set that you used. If you don’t know the version, use the date you downloaded the floppies, and include the distribution you got them from (e.g., “stable” or “frozen”).
You should also include the following information in your bug report:
architecture i386
model your general hardware vendor and model
memory amount of RAM
scsi SCSI host adapter, if any
cd-rom CD-ROM model and interface type, i.e., ATAPI
network card network interface card, if any
pcmcia details of any PCMCIA devices
Depending on the nature of the bug, it also might be useful to report the disk model, the disk capacity, and the model of video card.
In the bug report, describe what the problem is, including the last visible kernel messages in the event of a kernel hang. Describe the steps you performed that put the system into the problem state.
C. Booting the System
This appendix describes what happens during the GNU/Linux boot process.
How you boot your system depends on how you set things up when you installed Debian. Most likely, you just turn the computer on. But you may have to insert a floppy disk first.
Linux is loaded by a program called LILO, or LInux LOader. LILO can also load other operating systems and ask you which system you’d like to load.