1.1 Hacks #1-22
A running Linux system is a complex interaction
of hardware and software where invisible daemons do the
user's bidding, carrying out arcane tasks to the
beat of the drum of the uncompromising task master called the Linux
kernel.
A Linux system can be configured to perform many different kinds of
tasks. When running as a desktop machine, the visible portion of
Linux spends much of its time controlling a graphical display,
painting windows on the screen, and responding to the
user's every gesture and command. It must generally
be a very flexible (and entertaining) system, where good
responsiveness and interactivity are the critical goals.
On the other hand, a Linux server generally is designed to
perform a couple of tasks, nearly always involving the squeezing of
information down a network connection as quickly as
possible. While pretty screen savers and GUI features may be critical
to a successful desktop system, the successful Linux server is a high
performance appliance that provides access to information as quickly
and efficiently as possible. It pulls that information from some sort
of storage (like the filesystem, a database, or somewhere else on the
network) and delivers that information over the network to whomever
requested it, be it a human being connected to a web server, a user
sitting in a shell, or over a port to another server entirely.
It is under these circumstances that a system administrator finds their
responsibilities lying somewhere between deity and janitor.
Ultimately, the sysadmin's job is to provide access
to system resources as quickly (and equitably) as possible. This job
involves both the ability to design new systems (that may or may not
be rooted in solutions that already exist) and the talent (and the
stomach) for cleaning up after people who use that system without any
concept of what "resource
management" really means.
The most successful sysadmins remove themselves from the path of
access to system resources and let the machines do all of the work.
As a user, you know that your sysadmin is effective when you have the
tools that you need to get the job done and you never need to ask
your sysadmin for anything. To pull off (that is, to hack) this
impossible sounding task requires that the sysadmin anticipate what
the users' needs will be and make efficient use of
the resources that are available.
To begin with, I'll present ways to optimize
Linux
to perform only the work that is required to get the job done and not
waste cycles doing work that you're not interested
in doing. You'll see some examples of how to get the
system to do more of the work of maintaining itself and how to make
use of some of the more obscure features of the system to make your
job easier. Parts of this section (particularly Command Line and
Resource Management) include techniques that you may find yourself
using every day to help build a picture of how people are using your
system and ways that you might improve it.
These hacks assume that you are already familiar with Linux. In
particular, you should already have root on a running Linux system
available with which to experiment and should be comfortable with
working on the system from the command line. You should also have a
good working knowledge of networks and standard network services.
While I hope that you will find these hacks informative, they are
certainly not a good introduction to Linux system administration. For
in-depth discussion on good administrative techniques, I highly
recommend the Linux Network
Administrator's Guide and
Essential System Administration, both by
O'Reilly and Associates.
The hacks in this chapter are grouped together into the following
five categories: Boot Time, Command Line, Automation, Resource
Management, and Kernel Tuning.
- Boot Time
-
Removing Unnecessary Services
Forgoing the Console Login
Common Boot Parameters
Creating a Persistent Daemon with init
- Command Line
-
n>&m:
Swap Standard Output and Standard Error
Building Complex Command Lines
Working with Tricky Files in xargs
Immutable Files in ext2/ext3
Speeding Up Compiles
- Automation
-
At home in your shell environments
Finding and eliminating setuid/setgid binaries
Make sudo work harder for you
Using a Makefile to automate admin tasks
Brute forcing your new domain name
- Resource Management
-
Playing Hunt the Disk Hog
Fun with /proc
Manipulating processes symbolically with procps
Managing system resources per process
Cleaning up after ex-users
- Kernel Tuning
-
Eliminating unnecessary drivers from the kernel
Using large amounts of RAM
hdparm: fine tune IDE drive parameters
|