安装linux(11)

--- (文/曾瑞源)

Question 4.5. My swap area isn't working.

When you boot (or enable swapping manually) you should see
Adding Swap: NNNNk swap-space

If you don't see any messages at all you are probably missing swapon -av
(the command to enable swapping) in your /etc/rc or /etc/rc.local (the
system startup scripts), or have forgotten to make the right entry in
/etc/fstab:
/dev/hda2 none swap sw
for example.

If you see
Unable to find swap-space signature
you have forgotten to run mkswap. See the manpage for details; it works
much like mkfs.

Check the Installation HOWTO for detailed instructions of how to set up a
swap area.

- -----------------------------------------------------------------------------

Question 4.6. How do I remove LILO so my system boots DOS again ?

Using DOS (MS-DOS 5.0 or later, or OS/2), type FDISK /MBR. This will
restore a standard MS-DOS Master Boot Record. If you have DR-DOS 6.0, go
into FDISK in the normal way and then select the `Re-write Master Boot
Record' option.

If you don't have DOS 5 or DR-DOS you need to have the boot sector that
LILO saved when you first installed it. You did keep that file, didn't
you ? It's probably called boot.0301 or some such. Type
dd if=boot.0301 of=/dev/hda bs=445 count=1
(or sda if you're using a SCSI disk). This may also wipe out your
partition table, so beware ! If you're desperate, you could use
dd if=/dev/zero of=/dev/hda bs=512 count=1
which will erase your partition table and boot sector completely: you can
then reformat the disk using your favourite software; however this will
render the contents of your disk inaccessible --- you'll lose it all
unless you're an expert.

Note that the DOS MBR boots whichever (single!) partition is flagged as
`active'; you may need to use fdisk to set and clear the active flags on
partitions appropriately.

- -----------------------------------------------------------------------------

Question 4.7. Why can't I use fdformat except as root ?

The system call to format a floppy may only be done as root, regardless of
the permissions of /dev/fd0*. If you want any user to be able to format a
floppy try getting the fdformat2 program; this works around the problems
by being setuid to root.

- -----------------------------------------------------------------------------

Question 4.8. Is there something like Stacker or Doublespace for Linux ?

Currently none of the Linux filesystems can do compression in the
filesystem.

There is a transparently uncompressing C library, which is a drop-in
replacement for the standard C library. It allows programs to read
compressed (ie, GNU zipped) files as if they were not compressed. You
install it, and then you can compress files using gzip and have programs
still find them. Look on sunsite.unc.edu in /pub/Linux/libs. The author
is Alain Knaff .

There is a compressing block device driver that can provide
filesystem-independant on the fly disk compression in the kernel. It is
called `DouBle'. There is a source only distribution on sunsite.unc.edu
in /pub/Linux/utils/compress; the auther is Jean-Marc Verbavatz
. Note that since this compresses inodes
(administrative information) and directories as well as file contents any
corruption is quite likely to be serious.

There is also a package available called tcx (Transparently Compressed
Executables) which allows you to keep infrequently used executables
compressed and only uncompress them temporarily while you use them.
You'll find it on the Linux FTP sites [Q2.5 `Where can I get Linux
material by FTP ?']; it was also announced in comp.os.linux.announce.
Note - this is not the same as gzexe, which is an inferior implementation
of the same concept.

- -----------------------------------------------------------------------------

Question 4.9. My ext2fs partitions are checked each time I reboot.

See Q9.11 `EXT2-fs: warning: mounting unchecked filesystem'.

- -----------------------------------------------------------------------------

Question 4.10. I have a huge /proc/kcore ! Can I delete it ?

None of the files in /proc are really there - they're all "pretend" files
made up by the kernel, to give you information about the system, and don't
take up any hard disk space.

/proc/kcore is like an "alias" for the memory in your computer; its size
is the same as the amount of RAM you have, and if you ask to read it as a
file the kernel does memory reads.

- -----------------------------------------------------------------------------

Question 4.11. My AHA1542C doesn't work with Linux.

The option to allow disks with more than 1024 cylinders is only required
as a workaround for a DOS misfeature and should be turned *off* under
Linux. For older Linux kernels you need to turn off most of the "advanced
BIOS" options - all but the one about scanning the bus for bootable
devices.

===============================================================================

Section 5. Porting, compiling and obtaining programs

Q5.1 What is ld.so and where do I get it ?
Q5.2 Has anyone ported / compiled / written XXX for Linux ?
Q5.3 How do I port XXX to Linux ?
Q5.4 Can I use code or a compiler compiled for a 486 on my 386 ?
Q5.5 What does gcc -O6 do ?
Q5.6 Where are and ?
Q5.7 I get errors when I try to compile the kernel.
Q5.8 How do I make a shared library ?
Q5.9 How do I make my executables smaller ?
Q5.10 Does Linux support threads or lightweight processes ?

- -----------------------------------------------------------------------------

Question 5.1. What is ld.so and where do I get it ?

ld.so is the new dynamic library loader. Each binary using shared
libraries used to have about 3K of start-up code to find and load the
shared libraries. Now that code has been put in a special shared library,
/lib/ld.so, where all binaries can look for it, so that it wastes less
disk space, and can be upgraded more easily.

It can be obtained from tsx-11.mit.edu in /pub/linux/packages/GCC and
mirror sites thereof. The latest version at the time of writing is
ld.so.1.4.4.tar.gz.

- -----------------------------------------------------------------------------

Question 5.2. Has anyone ported / compiled / written XXX for Linux ?

First, look in the Linux Software Map (LSM) --- it's in the docs directory
on sunsite.unc.edu, and on the other FTP sties.

Check the FTP sites (see Q2.5 `Where can I get Linux material by FTP ?')
first --- search the find-ls or INDEX files for appropriate strings.
Check the Linux Projects Map (LPM), on ftp.ix.de in
/pub/Linux/docs/Projects-Map.gz.

If you don't find anything, you could either download the sources to the
program yourself and compile them -- see Q5.3 `How do I port XXX to Linux
?' -- or, if it's a large package which may require some porting, post a
message to the newsgroup.

If you compile a largeish program please upload it to one or more of the
FTP sites and post a message to comp.os.linux.announce (submit your
posting to ).

If you're looking for an application-type program the chances are someone
has already written a free verson. Try reading the FAQ in
comp.sources.wanted for instructions on how to find sources.

You should also check the Projects-FAQ, available in
/pub/Linux/docs/faqs/Projects-FAQ on sunsite.unc.edu.

- -----------------------------------------------------------------------------

Question 5.3. How do I port XXX to Linux ?

In general Unix programs need very little porting. Simply follow the
installation instructions. If you don't know and don't know how to find
out the answers to some of the questions asked during or by the
installation procedure you can guess, but this tends to produce buggy
programs. In this case you're probably better off asking someone else to
do the port.

If you have a BSD-ish program you should try using -I/usr/include/bsd and
- -lbsd on the appropriate parts of the compilation lines.

- -----------------------------------------------------------------------------

Question 5.4. Can I use code or a compiler compiled for a 486 on my 386 ?

Yes.

The -m486 option to GCC, which is used to compile binaries for 486
machines, merely changes certain optimisations. This makes for slightly
larger binaries which run somewhat faster on a 486. They still work fine
on a 386, though, with little performance hit.

GCC can be configured for a 386 or 486; the only difference is that
configuring it for a 386 makes -m386 the default and configuring for a 486
makes -m486 the default; in either case these can be overriden on a
per-compilation basis or by editing /usr/lib/gcc-lib/i*-linux/n.n.n/specs.

GCC does not currently know how to do optimisation well for the 586,
because Intel won't release the necessary information except under
nondisclosure. Don't buy a Pentium or wait for people to reverse-engineer
the required optimisations.

- -----------------------------------------------------------------------------

Question 5.5. What does gcc -O6 do ?

Currently the same as -O2; any number greater than 2 currently works just
like 2. The Makefiles of newer kernels use -O2, and so should you.

GCC 2.6 adds optimisation level -O3. However, GCC 2.6.0 and several of
the following versions are known to have some problems with Linux, though
these will hopefully be solved soon. In any case you should not use -O3
on a program until you're sure it doesn't create any problems.

- -----------------------------------------------------------------------------

Question 5.6. Where are and ?

These are in the directories /usr/include/linux and /usr/include/asm.

However they should be symbolic links to your kernel sources in
/usr/src/linux and not real directories.

If you don't have the kernel sources download them --- see Q7.6 `How do I
upgrade/recompile my kernel ?'.

Then use rm to remove any garbage, and ln to create the links:
rm -rf /usr/include/linux /usr/include/asm
ln -sf /usr/src/linux/include/linux /usr/include/linux
ln -sf /usr/src/linux/include/asm /usr/include/asm

- -----------------------------------------------------------------------------

Question 5.7. I get errors when I try to compile the kernel.

Make sure that /usr/include/linux and /usr/include/asm aren't actual
directories but instead symbolic links to /usr/src/linux/include/linux and
/usr/src/linux/include/asm respectively.

If necessary, delete them using rm and then use ln -s to make the links as
in Q5.6 `Where are and ?'.

Remember that when you apply a patch to the kernel you must use the -p0 or
- -p1 option: otherwise the patch may be misapplied. See the manpage for
patch for details.

If you're using a kernel more recent than 1.1.44 you should find that
there are new directories /usr/src/linux/include/asm-i386. The directory
asm there should be removed, as should the directory asm. The symlinks
Makefile target will make these be symbolic links to asm-i36 and
arch/i386/boot respectively. The easiest way to make sure all this gets
done is not to try to patch 1.1.44 to make 1.1.45, but to download
linux-1.1.45.tar.gz instead.

ld: unrecognised option `-qmagic' means you should get a newer linker,
from tsx-11.mit.edu in /pub/linux/packages/GCC.

- -----------------------------------------------------------------------------

Question 5.8. How do I make a shared library ?

Get tools-n.nn.tar.gz from tsx-11.mit.edu, in /pub/linux/packages/GCC/src.
It comes with documentation that will tell you what to do.

- -----------------------------------------------------------------------------

Question 5.9. How do I make my executables smaller ?

The most common cause of large executables is the -g compiler flag. This
produces (as well as debugging information in the output file) a program
which is statically linked, i.e. one which includes a copy of the C
library instead of using a dynamically linked copy.

Other things that are worth investigating are -O and -O2 which enable
optimisation (check the GCC documentation) and -s which strips the symbol
information from the resulting binary (making debugging totally
impossible).

You may wish to use -N on very small executables (less than 8K with the
- -N), but you shouldn't do this unless you understand its performance
implications, and definitely never with daemons.

Using QMAGIC binaries also can reduce the size of binaries, especially
small ones. Don't worry about this unless you know what QMAGIC is; Linux
is moving to QMAGIC as a default.

- -----------------------------------------------------------------------------

Question 5.10. Does Linux support threads or lightweight processes ?

As well as the Unix multiprocessing model involving heavyweight processes,
which is of course part of the standard Linux kernel, there are several
implementations of lightweight processes or threads, most of which are
generic packages for any Unix:

* In sipb.mit.edu:/pub/pthread or ftp.ibp.fr:/pub/unix/threads/pthreads.
Documentation isn't in the package, but is available on the World Wide
Web at http://www.mit.edu:8001/people/proven/home_page.html.
* In ftp.cs.washington.edu:/pub/qt-001.tar.Z is QuickThreads. More
information can be found in the technical report, available on the same
site as /tr/1993/05/UW-CSE-93-05-06.PS.Z.
* In gummo.doc.ic.ac.uk:/rex is lwp, a very minimal implementation.
* In ftp.cs.fsu.edu:/pub/PART, an Ada implementation. This is useful
mainly because it has a lot of PostScript papers that you'll find useful
in learning more about threads. This is not directly useable under
Linux.

Please contact the authors of the packages in question for details.

===============================================================================

The remainder of the FAQ is in the next part ...


Section 6. Solutions to common miscellaneous problems

Q6.1 Setuid scripts don't seem to work.
Q6.2 Free memory as reported by free keeps shrinking.
Q6.3 When I add more memory it slows to a crawl.
Q6.4 Some programs (e.g. xdm) won't let me log in.
Q6.5 Some programs let me log in with no password.
Q6.6 My machine runs very slowly when I run GCC / X / ...
Q6.7 I can only log in as root.
Q6.8 My screen is all full of weird characters instead of letters.
Q6.9 I have screwed up my system and can't log in to fix it.
Q6.10 Emacs just dumps core.
Q6.11 I've discovered a huge security hole in rm !
Q6.12 lpr and/or lpd aren't working.

- -----------------------------------------------------------------------------

Question 6.1. Setuid scripts don't seem to work.

That's right. This feature has been deliberately disabled in the Linux
kernel because setuid scripts are almost always a security hole. If you
want to know why read the FAQ for comp.unix.questions.

- -----------------------------------------------------------------------------

Question 6.2. Free memory as reported by free keeps shrinking.

The `free' figure printed by free doesn't include memory used as a disk
buffer cache - shown in the `buffers' column. If you want to know how
much memory is really free add the `buffers' amount to `free'.

The disk buffer cache tends to grow soon after starting Linux up, as you
load more programs and use more files and the contents get cached. It
will stabilise after a while.

- -----------------------------------------------------------------------------

Question 6.3. When I add more memory it slows to a crawl.

This is quite a common symptom of a failure to cache the additional
memory. The exact problem depends on your motherboard.

Sometimes you have to enable caching of certain regions in your BIOS
setup. Look in the CMOS setup and see if there is an option to cache the
new memory area which is currently switched off. This is apparently most
common on a 486.

Sometimes the RAMs have to be in certain sockets to be cached.

Sometimes you have to set jumpers to enable the caching.

Some motherboards don't cache all the RAM if you have more RAM per amount
of cache than they expect. Usually a full 256K cache will solve this
problem.

If in doubt, check your motherboard manual. If you still can't fix it
because the documentation is inadequate you might like to post a message
giving *all* the details - make, model number, date code, etc. so that
other Linux users can avoid it.

- -----------------------------------------------------------------------------

Question 6.4. Some programs (e.g. xdm) won't let me log in.

You are probably using non-shadow-password programs but are using shadow
passwords.

If so, you have to get or compile a shadow password version of the
program(s) in question. The shadow password suite can be found in
(amongst other places):
tsx-11.mit.edu:/pub/linux/sources/usr.bin/shadow-*
This is the source code; you will probably find the binaries in
.../linux/binaries/usr.bin.

- -----------------------------------------------------------------------------

Question 6.5. Some programs let me log in with no password.

You probably have the same problem as in Q6.4 `Some programs (e.g. xdm)
won't let me log in.', with an added wrinkle:

If you are using shadow passords you should put an asterisk in the
password field of /etc/passwd for each account, so that if a program
doesn't know about the shadow passwords it won't think it's a passwordless
account and let anyone in.

- -----------------------------------------------------------------------------

Question 6.6. My machine runs very slowly when I run GCC / X / ...

You may not have any swap enabled. You need to enable swapping to allow
Linux to page out bits of data programs aren't using at the moment to disk
to make more room for other programs and data. If you don't Linux has to
keep data in memory and throw away in-memory copies of programs (which are
paged straight from the filesystem) and so less and less program is in
memory and everything runs very slowly.

See the Installation HOWTO and the Installation and Getting Started Guide
[Q2.1 `Where can I get the HOWTOs and other documentation ?'] for details
of how to set up a swap partition or swapfile; see also Q4.5 `My swap area
isn't working.'.

Alternatively you may have too little real memory. If you have less RAM
than all the programs you're running at once use Linux will use your hard
disk instead and thrash horribly. The solution in this case is to not run
so many things at once or to buy more memory. You can also reclaim some
memory by compiling and using a kernel with less options configured. See
Q7.6 `How do I upgrade/recompile my kernel ?'.

You can tell how much memory and/or swap you're using by using the free
command, or by typing
cat /proc/meminfo

If your kernel is configured with a ramdisk this is probably wasted space
and will cause things to go slowly. Use LILO or rdev to tell the kernel
not to allocate a ramdisk (see the LILO documentation or type man rdev).

- -----------------------------------------------------------------------------

Question 6.7. I can only log in as root.

You probably have some permission problems, or you have a file
/etc/nologin.

If the latter put rm -f /etc/nologin in your /etc/rc or /etc/rc.local.

Otherwise check the permissions on your shell, and any filenames which
appear in error messages, and also the directories containing these files
all the way back up the tree to the root directory.

- -----------------------------------------------------------------------------

Question 6.8. My screen is all full of weird characters instead of letters.

You probably sent some binary data to your screen by mistake. Type echo
^V^[c (that's e c h o space control-V escape c return) to fix it. Many
Linux distributions have a command reset that does this.

- -----------------------------------------------------------------------------

Question 6.9. I have screwed up my system and can't log in to fix it.

Reboot from an emergency floppy or floppy pair, for example the Slackware
boot- and root-disk pair (in the install subdirectory of the Slackware
mirrors) or the MCC installation boot floppy. There are also two diy
rescue disk creation packages on sunsite.unc.edu in
/pub/Linux/system/Recovery. These are better as they'll have your own
kernel on them, so that you don't run the risk of missing devices,
filesystems, etc.

Get to a shell prompt and mount your hard disk with something like
mount -t ext2 /dev/hda1 /mnt

Then your filesystem is available under the directory /mnt and you can fix
the problem. Remember to unmount your hard disk before rebooting (cd back
down to / first or it will say it's busy).

- -----------------------------------------------------------------------------

Question 6.10. Emacs just dumps core.

You probably have the X version of Emacs that comes with SLS. It doesn't
work without the X libraries. The solution is to install X Windows or get
a newer Emacs binary without any X Windows support.

- -----------------------------------------------------------------------------

Question 6.11. I've discovered a huge security hole in rm !

No you haven't. You are obviously new to Unix and need to read a good
book on it to find out how things work. Clue: ability to delete files
under Unix depends on permission to write the directory they are in.

- -----------------------------------------------------------------------------

Question 6.12. lpr and/or lpd aren't working.

Check the Printing HOWTO [Q2.1 `Where can I get the HOWTOs and other
documentation ?'].

===============================================================================

Section 7. How do I do this or find out that ... ?

Q7.1 How can I get scrollback in text mode ?
Q7.2 How do I switch virtual consoles ? How do I enable them ?
Q7.3 How do I set the timezone ?
Q7.4 What version of Linux and what machine name am I using ?
Q7.5 How can I enable or disable core dumps ?
Q7.6 How do I upgrade/recompile my kernel ?
Q7.7 Can I have more than 3 serial ports by sharing interrupts ?
Q7.8 How do I make a bootable floppy ?
Q7.9 How do I remap my keyboard to UK, French, etc. ?
Q7.10 How do I get NUM LOCK to default to on ?

- -----------------------------------------------------------------------------

Question 7.1. How can I get scrollback in text mode ?

With the default US keymap you can use Shift with the PageUp and PageDown
keys (NB these must be the grey ones, not the ones on the numeric keypad
!). With other keymaps check the maps in /usr/lib/keytables; you can
remap the scroll up and down keys to be whatever you like --- for example,
in order to remap them to keys that exist on an 84-key AT keyboard.

You can't increase the amount of scrollback, because of the way it is
implemented using the video memory to store the scrollback text, though
you may be able to get more scrollback in each virtual console by reducing
the total number of VC's --- see .

- -----------------------------------------------------------------------------

Question 7.2. How do I switch virtual consoles ? How do I enable them ?

In text mode, press (Left) Alt-F1 to Alt-F12 to select the consoles tty1
to tty12. To switch out of X windows you must press Ctrl-Alt-F1 etc;
Alt-F5 or whatever will switch back.

Your kernel probably doesn't have all 12 compiled in; the default is 8.
This is controlled by NR_CONSOLES in linux/include/linux/tty.h.

If you want to use a VC for ordinary login you need to list it in
/etc/inittab, which controls which terminals and virtual consoles have
login prompts. NB: X needs at least one free VC in order to start.

- -----------------------------------------------------------------------------

Question 7.3. How do I set the timezone ?

Change directory to /usr/lib/zoneinfo; get the timezone package if you
don't have this directory. The source can be found on sunsite.unc.edu in
/pub/Linux/system/Admin/timesrc-1.2.tar.gz.

Then make a symbolic link named localtime pointing to one of the files in
this directory (or a subdirectory), and one called posixrules pointing to
localtime. For example:
ln -sf US/Mountain localtime
ln -sf localtime posixrules
This change will take effect immediately - try date.

Don't try to use the TZ variable - leave it unset.

- -----------------------------------------------------------------------------

Question 7.4. What version of Linux and what machine name am I using ?

Type:
uname -a

- -----------------------------------------------------------------------------

Question 7.5. How can I enable or disable core dumps ?

Since 0.99pl14 Linux has had corefiles turned off by default for all
processes.

You can turn them on or off by using the ulimit command in bash, or the
limit command in tcsh. See the manpage for the shell for more details.

That command affects all programs run from that shell (directly or
indirectly), not the whole system.

If you wish to enable or disable coredumping for all processes by default
you can change the default setting in - see the definition
of INIT_TASK.

- -----------------------------------------------------------------------------

Question 7.6. How do I upgrade/recompile my kernel ?

See the README which comes with the kernel release on ftp.funet.fi, in
/pub/OS/Linux/PEOPLE/Linus and mirrors thereof. Try to get it from a
closer site if possible; ftp.funet.fi is a very busy site and therefore
slow -- see Q2.5 `Where can I get Linux material by FTP ?'. You may
already have a version of the kernel source code installed on your system,
but if you got it as part of a standard distribution it is likely to be
somewhat out of date (this is not a problem if you only want a
custom-configured kernel, but it probably is if you need to upgrade.)

Remember that to make the new kernel boot you must run LILO after copying
the kernel into your root partition -- the Makefile in recent kernels has
a special zlilo target for this; try make zlilo.

Russel Nelson posts summaries of what changes in recent kernel patches to
comp.os.linux.development, and these are archived on ftp.emlist.com in
/pub/kchanges.

- -----------------------------------------------------------------------------

Question 7.7. Can I have more than 3 serial ports by sharing interrupts ?

Not without some trickery. This is a limitation of the ISA bus
architecture.

See the Serial HOWTO for information about how to work around this
problem.

- -----------------------------------------------------------------------------

Question 7.8. How do I make a bootable floppy ?

Make a filesystem on it with bin, etc and lib directories -- everything
you need. Install a kernel on it and arrange to have LILO boot it from
the floppy (see the LILO documentation, in lilo.u.*.ps).

If you build the kernel (or tell LILO to tell the kernel) to have a
ramdisk the same size as the floppy the ramdisk will be loaded at
boot-time and mounted as root in place of the floppy.

- -----------------------------------------------------------------------------

Question 7.9. How do I remap my keyboard to UK, French, etc. ?

For recent kernels, get kbd*.tar.gz from the same place as you got the
kernel source. Make sure you get the appropriate version; you have to use
the right keyboard-mapping package to go with your kernel version. The
latest at the time of writing is kbd-0.85.tar.gz, which works with kernel
versions from 1.0.

For older kernels you have to edit the top-level kernel Makefile, in
/usr/src/linux.

You may find more helpful information in the Keystroke FAQ, on
ftp.funet.fi in /pub/OS/Linux/doc/kbd.FAQ.

- -----------------------------------------------------------------------------

Question 7.10. How do I get NUM LOCK to default to on ?

Use the setleds program, for example (in /etc/rc.local):
for t in 1 2 3 4 5 6 7 8
do
setleds +num < /dev/tty$t > /dev/null
done

setleds is part of the kbd-0.8x package (see Q7.9 `How do I remap my
keyboard to UK, French, etc. ?').

Alternatively, patch your kernel. You need to arrange for KBD_DEFLEDS to
be defined to (1 << VC_NUMLOCK) when compiling drivers/char/keyboard.c.

===============================================================================

Section 8. Miscellaneous information and questions answered

Q8.1 What is a .gz file ? And a .tgz ? And ... ?
Q8.2 What does VFS stand for ?
Q8.3 What is a BogoMip ?
Q8.4 What is the Linux Journal and where can I get it ?
Q8.5 How many people use Linux ?
Q8.6 How should I pronounce Linux ?

- -----------------------------------------------------------------------------

Question 8.1. What is a .gz file ? And a .tgz ? And ... ?

.gz (and .z) files have been compressed using GNU gzip. You need to use
gunzip (which is as a symlink to the gzip command which comes with most
Linux installations) to unpack the file.

.taz and .tz are tarfiles (made with Unix tar) compressed using standard
Unix compress.

.tgz (or .tpz) is a tarfile compressed with gzip.

.lsm is a Linux Software Map entry, in the form of a short text file.
Details about the LSM and the LSM itself are available in the docs
subdirectory on sunsite.unc.edu.

The file command can often tell you what a file is.

If you find that gzip complains when you try to uncompress a gzipped file
you probably downloaded it in ASCII mode by mistake. You must download
most things in binary mode - remember to type binary as a command in FTP
before using get to get the file.