index

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]


index_A

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

accounts, disabling
addgroup command 2nd
adduser command 2nd
performance in scripts
system users, creating with
AGP (accelerated graphics port)
video cards
agpgart module
Alt-Fn keyboard commands
amavisd-new
setting up SpamAssasin on Postfix
with Clam Anti-Virus on Postfix
amavisd.conf file 2nd
AMD processor performance ratings
anycast
Apache web servers
access logs, viewing with Webalizer
ApacheToolbox
Basic and Digest user authentication
blocking obnoxious visitors
directory indexes, preventing truncation
documentation
for packages
DSO (Dynamic Shared Objects)
server configuration for
error pages
file permissions and ownership, setting
httpd binaries
hosting multiple domains
domains and VirtualHost directives
hosting options
individual user web directories
init script for
installing 2.0 from source
configuration
default installation directories
installing, source versus packages
LAN web sites, isolating from the Internet
deny/allow access rules
logfiles for virtual hosts
MPMs, Linux
MPMs, non-Linux
multi-language page delivery via content negotiation
Content-language directives
type map files
new modules, adding
password-protecting individual directories
redirecting URLs to new directories
simple public web servers, setting up
starting at boot
supported operating systems
user's manual, local access of
using favicons
versions
1.3 and 2.0 compared
VirtualHost directives
web crawler control with robots.txt
apachectl 2nd
apropos
apt-cdrom command
apt-get command 2nd 3rd
-u flag
apt-get install command
for package upgrades
apt-get remove command
apt-get source command
apt-get update
apt-proxy command
apt-proxy.conf
adding your package cache to
asynchronous filesystems
atomic commits
authentication
authentication backends
ntpkeys scheme for timeservers
public-key authentication
Samba servers, adding to
smtp-auth on Postfix
authenticating the Postfix server to other servers
AuthName directive
authoritative servers
authorized_keys file
Automachron sntp client
automatic shutdown
autotext, creating with Vim abbreviations
awk, sorting capabilities


index_B

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

b+trees
backports
backup and recovery
hard disks compared to tapes
Mondo Rescue [See Mondo Rescue]
rsync [See rsync]
tape backups
backup servers,building with rsync
bandwidth billing
Bash prompt, customization for ssh
binary-only drivers
BIND (Berkeley Internet Name Domain) 2nd
BIND entries
building a secondary server
checking syntax
configuring a public DNS server
load balancing
local caching servers
running a private server
BitKeeper version control system
boot partition and journaling filesystems
boot process 2nd 3rd [See also bootloaders]
Apache web server startup
Debian boot disks, creating
default runlevel, changing
Red Hat boot disks, creating
bootloaders
boot partition, configuring
chain loading
dual-booting
Linux/Windows 95/98/ME
Linux/Windows NT/2000/XP
GRUB [See GRUB]
LILO [See LILO]
MBR (Master Boot Record)
backing up
multiboot systems
Linux OSs, adding to
preparation
build commands, kernels
2.6 version
bunzip2
bunzip2 archives, unpacking


index_C

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

caching servers 2nd
BIND and
DNS servers, Linux and Window client configuration
separation from DNS servers
cat command for reassembly of large files
CD drive information, displaying
CD-DA (Compact Disk Digital Audio) format
CD-R, CD-RW, and CD-ROM hardware standards
CD/DVD recording
audio CDs for CD players, recording
bootable CDs, creating
CD Recordable FAQ and DVD FAQ
CD standards books
CD-RW disks, lifespan of
CD-RWs, erasing
CDs/DVDs, copying
data CDS, building file trees on
data CDs, making
data DVDs, recording
filesystem standards
hardware standards and formats
large files, spanning over several CDs
multisession data CDs, recording
SCSI addresses, finding for CD/DVD writers
SCSI emulation, enabling for IDE/ATAPI CD/DVD writers
write options
.cdr format, conversion to CD audio
cdrecord command
blank option
CD/DVD copying
multisession options
-scanbus option
chain loading
CheckInstall utility 2nd
checkout command
chfn command
chgrp command
chkconfig utility
chmod command 2nd
numeric notation
chown command 2nd
batch operations using
chroot jail
ci -u command
CIFS/SMB file sharing protocols
Clam Anti-Virus scanner
classes utility (CUPS)
co -l command
col command
command syntax
commit -m command
Common Unix Printing System [See CUPS]
compiling programs, system preparation
config utility
configuration files
/courier/pop3d.cnf
amavisd.conf 2nd
bashrc, prompt customization for ssh
.config file and kernels
.cvsrc
/etc/modules.conf
/etc/fstab
httpd.conf [See httpd.conf]
.joerc
.joercprefs
named root
named.conf 2nd
ntp.conf
adding access controls
/postfix/main.cf
Cyrus-SASL, enabling in
mail checks
managing unsolicited bulk email
on Debian
setting up virtual mailbox domains
rsyncd.conf
sshd_config, for X tunneling
.vimrc
XF86Config
editing
XV86Config
consoles, using with X Windows
Content Negotiation
content servers
Content-language directives
Core Development Tools
Courier, maildirmake command
Courier-IMAP
configuration file
cp command
CPanel
CPU information, displaying
cron and crontab files
CrossOver Office
Ctrl-Alt-Delete command
disabling or controlling access to
Ctrl-Alt-Fn keyboard command
CUPS (Common Unix Printing System) 2nd
dedicated printer servers, building
distributed printing with classes
filters
networking printers
printer drivers
printer shares over mixed LANs with Samba
printers, installing on a Linux PC
serving Linux clients
troubleshooting
users, restricting from printers and classes
CVS 2nd
add subcommand with -kb flags
with -kkv flags
binary files, storage
checkout command
command syntax
commit subcommand
-m option
compared to RCS
configuring the working environment
customizing
cvs init command
CVS Pservers
mirroring
security concerns
cvsd utility
installing from source
diff subcommand
environment variables
log subcommand
marking specific files as a set
owner and group creation
remove command
repositories
accessing remotely
adding new files to
administration files for, creating
anonymous read-only repositories
deleting files from
local single-user, creating
mirroring
shared, creating
sharing between groups
storage size, calculating
retrieving old files from
rtag subcommand
sandbox
stable and development project branches, creating
status command 2nd
tags
update command
updating working files in a shared project
file state codes
working directory
Cygwin
Cyrus-SASL installation
on Debian


index_D

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

DAC (digital-to-analog converter)
daemontools
DAO (disc-at-once) write option
Debian
apt-proxy.conf
boot disks, creating
building a local repository
cvsd utility
Cyrus-SASL, installing
debianutils package
mkboot utility
dependency conflicts, resolving
download sites and vendors
finding out what's installed
getting software for
initialization
installing programs from non-Debian repositories
loadable kernel modules, adding
managing runlevels
mirror sites
mirrors
packages
installing
installing from CD-ROMs
maintaining package caches
package names compared to RPM package names
package search page
removing
resolving dependencies
updating
upgrading
POP3 mail servers, building
Courier, installing
Postfix configuration
postfix reload command
testing
releases
codenames
running a mixed system
upgrading
runlevels
security updates
source, installing from
sources.list, editing
text and graphical login runlevels
timeservers, using with an intermittent connection
user and group numbering
users, sorting human from system
dedicated servers
delayed allocation
deny/allow access rules
dependencies
failed dependencies, fixing
resolving in Debian packages
device names for storage disks, finding
DHCP (Dynamic Host Configuration Protocol)
dhcp clients
adding static hosts to
DHCP servers
dig command 2nd
DNS servers, testing and querying
Direct Rendering Infrastructure [See DRI]
directories
copying, moving, and renaming
share setup with setgid, sticky bit
disk geometry, displaying
disk partitions, creating with fdisk
disk quotas
display managers
djbdns
djbdns entries
dnsip queries
guilding a public DNS server
installing
local caching nameservers, running
dmesg
DNS (Domain Name System)
accredited domain name registrars
anycast
authoritative servers or content servers
BIND (Berkeley Internet Name Domain)
blackhole lists
caching DNS resolvers
caching servers
djbdns [See djbdns]
DNS servers
testing and querying with dig and dnstrace
glossary
implementation
private DNS servers
root servers
separation, DNS servers from caching servers
dnscache-conf logfiles
DNSRBLs (DNS blackhole lists)
dnstrace
documentation
distributions, included in
graphical viewers
info command [See info command and pages]
keyword searches
man command [See man command and pages]
online resources
programs, finding all documentation for
Domain Name System [See DNS]
domain names, fully qualified, configuring
domain wildcards
dpkg command 2nd
querying features
DRI (Direct Rendering Infrastructure)
3D hardware acceleration, enabling
presence in kernel, verifying
drive partition information, displaying
drives, identifying
DSO (Dynamic Shared Objects)
dual booting with Windows
DVD FAQ
DVD recording [See CD/DVD recording]
DVD video, recording, and writing hardware standards
dvd+rw-tools homepage
Dynamic Host Configuration Protocol [See DHCP]
Dynamic Shared Objects (DSO)


index_E

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

e2fsprogs package
edquota command
egrep command
El Torito filesystem standard
email [See mail]
errors and failed dependencies
/etc/fstab configuration files
automating mounting of filesystems on hard drives
/etc/passwd files, vulnerability
Evolution Connector
Ext2 filesystem
creating on new partitions
Ext3 filesystem
creating on new partitions
extents
external fragmentation


index_F

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

failed dependencies error
famd
favicons
fdisk 2nd
finding partitions using
Fedora graphical login manager
FHS (Filesystem Hierarchy Standard)
file attributes
file permissions
defaults, setting with umask
setting
file sharing
enabling on Windows PCs
protocols, history of
Samba [See Samba servers]
file types
directory locations
files
copying, moving and renaming
creating
large files, copying to multiple CDs
permissions and ownership
Apache web servers, setting for
changing
CVS owner and group, creating
SSH files, setting on
filesystems
asynchronous filesystems
b+trees
chown
/etc/fstab, configuring with
Ext3 filesystem
extents
external fragmentation
FHS
inodes
internal fragmentation
internals
JFS filesystem
journaling filesystems
Linux file types
logical blocks
logical volumes
metadata
mount command
mounting and unmounting on hard drives
new partitions, creating on
partitioning criteria and
ReiserFS filesystem
required elements, Linux filesystem
umount command
XFS filesystem
find command
and batch file ownership changes
for verifying ownership changes
finddoc script
Foomatic
FreshRPMs
fsck command
fstab command


index_G

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

gcc program
gdm
GECOS data
modifying
getty
Gimp-Print
GNU
Arch version control system
binutils
coreutils
tar
Google
GPU (graphics processing unit)
Grand Unified Bootloader [See GRUB]
graphical user interfaces [See GUIs]
graphical viewers
grep command
groff command
groupadd command
groupdel command
groups
adding and deleting members
batch addition of users to
groupware
growisofs utility
grpck command
grpquota partition
GRUB (Grand Unified Bootloader)
boot menu, creating
boot parameters, discovering from the command shell
installing
grub-install script
without a floppy
LILO, migration from
locking individual GRUB menu entries
menu.lst, customizing
new kernels adding
password protecting system files
restoring to the MBR with Knoppix
splash images, creating
Gtypist
GUIs (graphical user interfaces)
version identification
X Window System [See X Window System]
X.org [See X.org windowing system]
Xnets
gunzip


index_H

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

halt command
hard drive capacity, calculating
hard links
hardware
binary-only drivers
CD/DVD standards and formats
dmesg, hardware detection using
finding device names for mount and fstab
HCLs (hardware compatibility lists)
lspci, detecting with
PCI devices, detecting
/proc, hardware snapshots using
Haugh, Julianne Frances
\:help command (Vim)
host-keys
authentication
generating
storage
hosts files 2nd
httpd binary (Apache web servers)
httpd.conf
LogFormat directives
Rewrite directives
VirtualHost directives
VirtualHosts logfiles


index_I

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

IANA (Internet Assigned Numbers Authority)
ICANN (Internet Corporation for Assigned Names and Numbers)
accredited domain name registrars
id command
IDE devices
driver versions, displaying
hard drive data, displaying
listing
ide-scsi pseudo-device driver
IMAP (Interactive Message Access Protocol)
IMAP folders, sharing
IMAP mail servers, building and testing
info command and pages 2nd
printing info pages
selective printing
init
runlevels, changing with
initialization scripts
initrd image, creating
inittab file, default runlevels
inodes
int 0 command
internal fragmentation
Internet Explorer, security issues 2nd
Internet mail [See mail]
ipconfig
ISA devices, listing
ISO-9660 filesystem standard
ISPs (Internet Service Providers) Terms of Service


index_J

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

JFS filesystem
creating on new partitions
jfsutils package
JOE (Joe's Own Editor)
commands
copying between two files
customizing
emulation modes
example, source code install
opening two windows in
searching and replacing
.joerc file
.joercprefs file
Joliet filesystem standard
journaling filesystems


index_K

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

K3b
kdm
kerneld
kernels
2.4 version
adding features to
finding SCSI address CD and DVD writers
IDE/ATAPI CD and DVD writers
latest stable version, upgrading to
removing unnecessary files
2.6 version
building
CD/DVD drives
new features, adding
xconfig and
build commands
.config file
config utility
configuring
initrd image, creating
kernel build tree
kernel maintainers
kernel sources
kernel sources and /usr/src/linux
menuconfig utility
modification
multiple versions on one system
new loadable kernel modules, adding
patches, removing
patching
patch options
typical size
upgrading
2.4 to 2.6 and boot errors
xconfig
keychain
keyword searches, command documentation
kmod utility
Knoppix
boot loader restoration using
booting
creating a boot diskette
editing configuration files
installing software
installing to hard disk
virus-scanning Windows PCs
Konqueror


index_L

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

language specific pages, serving through content negotiation
LILO (Linux Loader)
boot diskette, creating
booting with
GRUB, migration to
journaling filesystems and
multiboot systems using for
multibooting Windows and Linux
new kernels adding
password-protection
links
Linux
available mail clients
books and magazines
boot process
clients and caching DNS servers
Core Development Tools
default runlevel, changing
file types
HCLs (hardware compatibility lists)
manual configuration of startup services
online resources
hardware
rebooting
runlevels 2nd
changing
security vulnerabilities
shutdown
automating
starting and stopping
init
Usenet groups
video adapters, compatibility of
video, configuring [See video configuration]
X Windows
Linux Disk Quota package
Linux Loader [See LILO]
ln command
local caching name servers, running with BIND
locate command
logfiles for VirtualHosts on Apache
logging out, ssh-agent shutdown
logical blocks
logical volumes
logins
display manager, changing
passwordless for cron jobs
using keychain
using ssh-agent
lpr command
lsmod command
lspci command 2nd


index_M

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

MAC (Media Access Control) addresses
mail
clients, required connection information
protocols
ports for
receiving
sending
servers
configuring fully qualified domain names
enabling user connections
groupware/email servers
IMAP folders, sharing
IMAP mail servers, building and testing
Postfix mail servers [See Postfix mail servers]
security [See security]
SMTP response codes and commands
webmail
whitelists
mail transfer agents (MTAs)
maildirmake command
make
2.6 version kernel builds
kernel builds
make uninstall command
malware
man command and pages
-Hmozilla option
command syntax
-f switch
finding
lost man pages, finding
man -k
manpath, configuring
organization
printing man pages
selective printing
reading without a viewer
rebuilding the man database
-t option
Mandrake graphical login manager
manpath command
map command (Vim)
marks command (Vim)
mass_passwd script 2nd 3rd
mass_useradd script 2nd
MBR (Master Boot Record) 2nd
backing up
GRUB boot loader, restoring with Knoppix
MDA (mail delivery agent)
meminfo
memory and swap information, displaying
menuconfig utility
metadata
mime_header_checks
mkboot utility
mkdir command
mkinitrd command
mkisofs utility
bootable CDs, making with
-graft-points option
growisofs frontend
multisession options
modeless editors
Mondo Rescue 2nd
backups, verifying
bootable system restore CDs, creating
bootable system restore DVDs, creating
cloning Linux systems
mindi-kernel, using for ÒsaneÓ backups
Mondo disks
selected file restores
system restores from
monitoring a system in real time
Monotone version control system
Moolenaar, Bram
mount command
CD/DVD writers mounting
filesystems on hard drives
finding device names for storage disks
Mount Rainier ReWrite hardware standard
Mozilla
mp3 format
conversion to CD audio
mpg123 utility
MPMs (multiprocessing modules)
PerChild MPM (Apache 2.0)
MTAs (mail transfer agents)
MUA (mail user agent)
multi-monitor displays, configuring
multiboot systems with GRUB
Linux OSs, adding to
Windows 95/98/ME, adding to
Windows NT/2000/XP, adding to
multiboot systems with LILO
Windows and Linux
multiprocessing modules (MPMs)
multisession write option
mv command


index_N

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

name resolution
DNS [See DNS]
hosts files
enabling local resolution with
named
named.conf file 2nd
named.root file
NetBEUI (NetBIOS Enhanced User Interface)
NetBIOS (Network Basic Input Output System)
netGo
netsync protocol
network printers, sharing 2nd
over mixed LANS with Samba
troubleshooting
users, restricting
Windows clients without Samba
without name resolution
nobody user
Novell Evolution
nroff command
NTFS filesystem, write access
ntp (Network Time Protocol) 2nd [See also timeservers]
ntp pools
classes
dig command
pinging timeservers
traceroute
ntp.conf configuration file
ntp.conf file, controlling timeserver access with
configuration options
ntpd (Network Time Protocol daemon)
restart command and
ntpkeys authentication scheme
ntp-keygen flags
null-passphrase keys
numeric notation for file permissions


index_O

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

ogg-vorbis format
conversion to CD audio
oldconfig command
online resources
hardware
Open Relay Database
OpenSSH 2nd [See also SSH]
CVS repositories, remote access
encryption and authentication
first-time setup
host-keys
authentication
generating
storage
keys, copying to authorized_keys file
logins
in to remote machines
passwordless for cron jobs
using keychain
private keys
public keys
public-key authentication 2nd
ssh-agent
shutdown at logout
sshd
starting and stopping
using multiple key pairs
using on Windows PCs
X, tunneling over SSH
openssl s_client
Orange Book
$origin directive
Oualline, Steve
Outlook and Outlook Express, security concerns
ownership of files, changing


index_P

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

packages [See also RPM]
Apache web servers, documentation for
creating from source code
Debian [See Debian, packages]
upgrades using apt-get install command
partitions
boot partition configuration
fdisk, creating with
filesystems, creating on
information, displaying
passwd command
-e option
passwd file, vulnerability
passwords
managing
mass changing of
password file integrity, checking
patches for kernels, installing
PCI bus, displaying connected devices
PerChild MPM (Apache 2.0)
Pinfo
ping
measuring timeserver distance with
PLD (Polished Linux Distribution)
Polished Linux Distribution (PLD)
pool.ntp.org
POP (Post Office Protocol)
POP3 mail servers
building
Courier-Imap, installing
on Debian
Postfix, installing
smtp daemon, verifying operation
common commands
testing
smtp with telnet and openssl s_client
TLS/SSL support
unencrypted POP3 with telnet
Postfix mail servers 2nd 3rd [See also mail, servers] [See also security]
authentication to other servers with smtp-auth
Clam Anti-Virus scanner
configuration file
enabling SASL
couriermlm mailing lists
administration
creating
Cyrus-SASL installation
verifying support
database file formats
DNS blackhole lists
installing
Internet mail
sending
Internet mail, recieving
log files
messages with attachments, rejecting
mime_header_checks
POP3 mail servers [See POP3 mail servers]
root and postmaster alias files and database
SASL libraries
smtp daemon verification
smtpd_sender_restriction directive
SpamAssasin, setup
using amavisd-new
starting
UBE (unsolicited bulk email) controls
basic configurations
user authentication with smtp-auth
virtual mailbox domains
/postfix/main.cf
mail checks
managing unsolicited bulk email
poweroff command
ppid
pre (pre-release candidate) patches
Prefork MPM (Apache 1.3)
printers [See also CUPS]
finding drivers for
installing
sharing over networks 2nd
mixed LANS with Samba
serving Windows clients without Samba
troubleshooting
users, restricting
without name resolution
private keys
changing
/proc
cat utilities and
program installation 2nd
ps command, finding a user's processes
Pservers
mirroring
using to build read-only CVS repositories
pts
public DNS servers
building with tinydns
public keys
public web servers
public-key authentication 2nd
PuTTY
pwck command
Python finddoc script


index_Q

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

quota command
quotacheck command


index_R

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

RAMDAC (Random Access Memory digital-to-analog converter)
rc (release candidate) patches
RCS (Revision Control System) 2nd
, v (comma v) suffix
building simple local repositories
checking out and checking in files
comments
displaying files without checking out
file versions, comparing
file comparison symbols
managing system configuration files
preserving working copies
retrieving older file revisions
rlog command
working and RCS directories
rcsdiff command
Red Book
Red Hat [See also RPM]
boot disks, creating
graphical login manager
groupadd command
initialization
loadable kernel modules, adding
runlevels
managing
user and group numbering
users, sorting human from system
redhat-config-xfree utility
Regional Internet registries
ReiserFS filesystem
creating on new partitions
reiserfsprogs package
remote access
OpenSSH [See OpenSSH]
scp
sftp
ssh
SSH (Secure Shell) protocol
SSH-2
remote X sessions, security of
removable media, mounting and unmounting
remove command
repetitious typing, reduction with Vim autotext
repquota command
restart command used with ntpd
Rewrite directives
RJOE
rjpm command
rlog command
rm command
rmdir command
robots.txt file
Rock Ridge filesystem standard
root privileges
su command
sudo command
RPM (Red Hat Package Manager) 2nd [See also rpm command]
CheckInstall utility
dependencies, breaking
dependencies, verifying
dependency resolvers
information, collecting from uninstalled packages
information, collecting on installed packages
installation problems, fixing
installing packages
public RPM archives
rebuilding the RPM database
recently installed packages, finding
removing packages
ÒRPM hellÓ
rpm queries that follow symlinks
rpm-orphan-find script
rpmbuild package
source packages, installing
customizing build options
source-built libraries, tracking
upgrading packages
rpm command 2nd [See also RPM (Red Hat Package Manager)]
-e option
-h option
-i option
--initdb option
--last option
-p switch
-q options
--rebuilddb option
--replacepkgs option
--test option
-U flag
RSA key pair generation
rsync
anonymous public rsync servers, building
automating over ssh backups
-av flag
backup servers, building
command options
configuration files
creating a message of the day
customizing filepaths
--cvs-exclude option
daemon, launching at startup
--delete flag
fine-tuning file selection
limiting bandwidth requirements
local file transfers and synchronization
Pservers, mirroriing over SSH
rsync modules, securing
secure transfers with ssh
synchronizing tinydns servers
Windows clients, installing on
runlevels
changing after boot
changing default runlevel
Debian, managing in 2nd
Red Hat, managing in


index_S

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

Samba servers
adding authentication to
anonymous file servers, building for Windows
batch conversion of system users ot Samba users
controlling share access with access control lists
CrossOver Office, running Windows applications with
enabling users' home directory access
Linux clients, connecting
to file servers or peer networks
to Samba domains via command-line tools
to Samba domains via GUI LAN browsers
to Samba workgroups via command-line tools
Linux clients, sharing Windows printers with
logins from Windows 95/98/ME
passwords, Samba and Linux, syncing
passwords, Windows, handling encrypted and non-encrypted
primary domain controllers, building
public shares for users, creating
roaming profiles, enabling
Samba versions 2.x and 3.x, compared
Windows clients, connecting to Samba domains
95/98/ME
NT/2000
XP
Windows clients, sharing Linux printers with
Windows/Linux peer networks, building
SAO (session-at-once) write option
Sarge
sources.list
SASL (Simple Authentication and Security Layer)
scp
SCSI addresses, finding for CD/DVD writers
SCSI device information, displaying
SCSI devices, listing
SCSI emulation, enabling for IDE/ATAPI CD/DVD writers
search engines, controlling server access by
security 2nd
amavisd-new
Clam Anti-Virus scanner
Debian, updates for
defense checklist
DNS blackhole lists
fundamental precautions
GRUB password protection
GRUB, locking users from menu entries
incoming mail, applying restrictions
LILO, password-protection of
messages with attachments, rejecting
nobody user, risk mitigation
ntp exploits, preventing
SpamAssasin, installing on Postfix
SSL
UBE (unsolicited bulk email) controls
basic configurations
whitelists, creating
Windows hosts, modification
ServerLayouts
choosing among at startup
setting a default
services
manual start and stop
prioritization
startup services, manually configuring
sessions
session write option
switching between console and X Windows sessions
VIM
setgid
setuid, security problems with
sftp
Shadow Suite
shared servers
shutdown
automating
Sid
sources.list
Slackware
graphical login manager
initialization
runlevels
users, sorting human from system
slay program
SMTP (Simple Mail Transfer Protocol)
response codes and commands
smtp-auth
authenticating Postfix servers to other servers
user authentication on Postfix
smtpd_recipient_restrictions directive
SOA (Start of Authority)
soft links
software installation
RPM-based systems [See RPM]
source-built systems
source code
creating packages from
CheckInstall, using
generating file lists for easy uninstalls
installing from on Debian
installing programs from
programs, installing from
system preparation
sox command
-h option
spam prevention with DNS blackhole lists
SpamAssasin, setting up on Postfix
amavisd-new, using
Spamhaus and Spamcop
SPEWS (Spam Prevention Early Warning System)
split utility
Squirrelmail
SRAM (Static Random Access Memory)
SRPM (source RPM)
ssh 2nd
Bash prompt, customizing for
secure file transfers over rsync
SSH (Secure Shell) protocol 2nd [See also OpenSSH]
file permissions, setting
X, tunneling over SSH
ssh-agent
shutdown at logout
ssh-keygen command
sshd
starting and stopping
startup services, manually configuring
startx command
configuring
opening additional X sessions
status command
su command
Subversion version control system
sudo command
supermount command
SuSE
graphical login manager
loadable kernel modules, adding
SuSE OpenExchange
users, sorting human from system
symlinks
system-config-network graphical configuration tool
system-config-xfree utility


index_SYMBOL

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

^ (caret)
,v (comma v) suffix
$origin directive
3D acceleration hardware
enabling with XFree87/DRI
troubleshooting


index_T

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

TAO (track-at-once) write option
tape backups
tdfx module
telinit
Terms of Servic (TOS)
text editors
default editor, setting
Emacs
Joe [See Joe]
vi and clones
Vim [See Vim]
third-party modules, installation
time-to-live values
timeservers
access controls adding
iptables,using
ntp.conf, using
clients, connecting to a local timeserver
Windows clients
connecting over an intermittent connection
Debian, utilities required for
etiquette
identifying connected time servers
local time servers, building
multiple local timeservers, setting up
ntp.conf files for local servers
ntp (Network Time Protocol)
ntp pools, choosing
classes
dig command
pinging timeservers
traceroute
ntp rpm versus xntp
ntp.conf configuration file
ntpd (Network Time Protocol daemon) 2nd
ntpdate
compared to ntpd 2nd
ntpkeys authentication scheme
ntpq command
pool.ntp.org
public time servers
tinydns
building a private server
building a public DNS server
load balancing, enabling
synchronizing with a second tinydns server
testing a tinydns server
tinydns-conf logfiles
TLS (Transport Layer Security)
TOS (Terms of Service)
touch command
traceroute
measuring timeserver distance with
track write option
tty (virtual consoles)
tty command
type map files
typing tutor utility (Gtypist)


index_U

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

UBE (unsolicited bulk email) controls for Postfix
basic configurations
UDF (Universal Disk Format) filesystem standard
UID (user identification)
batch change of file ownership using
changing without affecting login name
umask
umount command
Òdevice is busyÓ error
uname command 2nd
uninstalling source built programs
update command
working files in a shared project
update-rc.d command
URLs (Uniform Resource Locators)
this book
USB devices, listing
uscpi-tcp
Usenet groups
hardware
useradd command 2nd
performance in scripts
system users, creating with
userdel command
UserDir-type web sites 2nd
password-protecting
usermod command
users, managing
adding users
batch addition of new users
batch addition of users to groups
deleting users
disabling accounts
re-enabling
disk quotas
granting of root permissions
group members, adding and deleting
groups, adding
groups, deleting
killing user processes
password management
passwords, changing en masse
sorting human from system users
system groups, creating
system users, creating
user accounts, modifying
owned files outside the home directory
potential impacts
user's UID and GID, finding
/usr/source/linux and kernel sources
usrquota partition


index_V

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

\:version command (Vim)
version control systems
atomic commits
commercial systems
CVS system [See CVS]
free open source systems
RCS system [See RCS]
uses
vi text editor and clones 2nd [See also Vim]
video configuration
login display manager, changing
multi-monitor displays
running multiple window managers with Xnest
startx
video acceleration hardware 2nd
enabling
troubleshooting
video adapters
installing
Linux compatiblility
video cards
drivers
X Window System version, determining
XF86Config file
locating
XF86Config fle
editing
Vim 2nd 3rd
autotext, creating with abbreviations
commands, mapping to keystrokes
compile-time options
customizing
editing modes
:help command
learning
navigation using marks
stored sessions, using
\:version command
.vimrc file
vimtutor command
virtual consoles (tty)
virtual hosting
logfiles for
virtual mailbox domains
creating user logins in Courier
VirtualHost directives (Apache)
virus prevention using Clam Anti-Virus scanner
visudo utility
vmlinuz


index_W

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

.wav format
conversion to CD audio
web browsers
with Digest authentication support
web crawlers, controlling server access by
web hosting
dead links, preventing
user directories, setting up
Web Hosting Talk forums
web servers [See Apache web servers]
Webalizer
webmail
whereis -m command
whitelists
Windows
anonymous Samba file servers and
clients and caching DNS servers
dhcp client configuration
file sharing, enabling
OpenSSH, running on
peer networks with Linux, building
printer networking without Samba
Samba domains, connecting to
95/98/ME
NT/2000
XP
security, improving 2nd
sharing Windows printers with Linux clients
spam proliferation and
static hosts, adding to dhcp
timeserver clients for
using Linux printers over Samba
Windows applications, running on Linux
winipcfg
Woody
sources.list
Worker MPM (Apache 2.0)


index_X

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

X utilities
X Window System
consoles, using with
SSH, tunneling over
starting and stopping sessions
terminology
version, determining
X.org windowing system
xconfig utility
xdm
XF86Config file
editing
for multihead display
hardware video acceleration
locating
multiple ServerLayouts
ServerFlags
xf86config utility
XFdrake utility
XFree86 utility
3D hardware acceleration, enabling with DRI
XFS filesystem
XFS filesystems
creating on new partitions
xfsprogs package
Xinerama
xinetd services
Xnest


index_Y

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

Yellow Book
Yelp
Yum (Yellow Dog Updater, Modified)
changing download sources
clean options
configuring
GPG keys
installed packages, retrieving information about
installing
maintaining
mirrors
packages, installing and upgrading
packages, removing
querying commands


index_Z

[SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

zcat command
zless command


Appendix A. Finding Linux Documentation

    Recipe A.1. Linux Documentation on the Web

    Recipe A.2. Books and Magazines


Recipe A.1. Linux Documentation on the Web

Linux is truly a child of the Internet. Keeping up with advances and finding documentation means becoming acquainted with search engines and relevant Web sites. The first stop is the Web site of your Linux distribution. Look for online manuals, howtos, FAQs, knowledge bases, mail lists, and list archives. Most Linux distributions are customized to some degree, so you'll need to know your distro-specific quirks.

Next, visit the Web sites of the individual programs you are using, and look for their mail lists, online documentation, and user communities.

Then there are a large number of general-interest Linux web sites, and online Linux publications. In this chapter are a number of resources I've found to be useful. Note that many of these welcome contributions from readers and ordinary Linux users. Don't be shy- share what you know.

As always, pay heed to proper netiquette. Search list archives before posting a question. If it's been answered recently, or often, you'll get yelled at. Mind your manners, and ignore trolls and rude people. Life is too short to waste in silly flame wars.

A.1.1 Linux Web Sites

The Linux Documentation Project

http://www.tldp.org/

IBM developerWorks

http://www-106.ibm.com/developerworks/linux/

Librenix

http://librenix.com/

O'Reilly Network

http://oreillynet.com/

TuxMobile

http://www.tuxmobil.org/howtos.html

Wireless LAN resources for Linux

http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/

The Linux Kernel Archives

http://www.kernel.org/

Linux Gazette

http://linuxgazette.net/

This is, as far as I know, the only group devoted to supporting women Linux users, and an excellent group it is. There are several great mailing lists, including Newchix for newbies; courses on various subjects, such as programming, filesystems, and networking; and there are even Linuxchix chapters all over the world, where people can meet in the flesh. Yes, face-to-face, in person.

LinuxChix

http://linuxchix.org/

O'Reilly's Safari Bookshelf deserves a special mention. It's an online, searchable library of over 1,300 computer books. It includes books from many good publishers. Subscriptions are quite affordable. Take it for a test-drive with their two-week free trial.

Safari Bookshelf

http://safari.oreilly.com/

A.1.2 Usenet

There are dozens of Linux groups on Usenet. Try these for starters:

comp.os.linux.announce
comp.os.linux.hardware
comp.os.linux.networking
comp.os.linux.security

A.1.3 Google

How did we ever live without Google?

Google home page

http://google.com

Google Groups, a great searchable front-end to Usenet

http://groups.google.com/


Recipe A.2. Books and Magazines

First, check out any printed manuals for your Linux distribution. Red Hat and SuSE's manuals, for example, are very good.

These are my choices for an essential Linux library:

  • Linux in a Nutshell, by Ellen Siever

  • Running Linux, by Matt Welsh, Matthias Kalle Dalheimer, Terry Dawson, Lar Kaufman

  • Mastering Regular Expressions, by By Jeffrey E. F. Friedl

  • Building Secure Servers with Linux, by Mick Bauer

  • Linux Server Hacks, by Rob Flickenger

  • Essential System Administration, by Æleen Frisch

  • Linux Security Cookbook, by Daniel J. Barrett, Richard Silverman,

  • Learning the bash Shell, Second Edition, by Cameron Newham, Bill Rosenblatt

  • Linux Network Administrator's Guide, by Olaf Kirch, Terry Dawson

  • TCP/IP Network Administration, by Craig Hunt

  • PC Hardware in a Nutshell, by Robert Bruce Thompson, Barbara Fritchman Thompson

A.2.1 Magazines:

  • Linux Journal

  • Linux Magazine

  • SysAdmin Magazine

  • Unix Review

You'll notice there are no distribution-specific publications, and nothing for dummies or idiots. Just good, well-written, thorough Linux materials.


Appendix B. Online References

    Recipe B.1. Hardware Web Sites

    Recipe B.2. Usenet


Recipe B.1. Hardware Web Sites

Linux FAQ

http://en.tldp.org/FAQ/Linux-FAQ/index.html

Linux Network Drivers at Scyld Computing Corporation

http://www.scyld.com/network

Wireless LAN resources for Linux

http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux

Linux On Mobile Computers

http://tuxmobile.org/

Linux Devices

http://www.linuxdevices.com/

Linux USB Project

http://www.linux-usb.org/

Linux Firewire

http://www.linux1394.org/

LinuxPrinting.org

http://www.linuxprinting.org/

SANE - Scanner Access Now Easy

http://www.sane-project.org/

Advanced Linux Sound Architecture

http://www.alsa-project.org/

Open Sound System for Linux

http://www.4front-tech.com/linux.htmlOSS/

XFree86

http://www.xfree86.org/

Xouvert, a fork of XFree86, that aims for faster development, and better support of modern video cards

http://www.xouvert.org/

KernelTrap

http://kerneltrap.org/

Linux-Dell-laptops

http://www.whacked.net/ldl/faq/

Debian-laptop mailing list

http://lists.debian.org/debian-laptop/

Linmodems

http://www.linmodems.org/

Hardware Guys

http://www.hardwareguys.com

This is the companion site to the book PC Hardware in a Nutshell. It's not Linux-oriented, but it's a great resource all the same.


Recipe B.2. Usenet

comp.os.linux.hardware
comp.os.linux.portable
comp.os.linux.powerpc
comp.os.linux.x
comp.os.linux.alpha


Appendix C. Microsoft File Types

MS Access Database Wiz. Template MDZ

MS Access Database/Template/Add. MDB, MDT, MDA, MDW

MS Access Description File       DES

MS Access Menu File              MNU

MS Access Modem File             MDM

MS Archive                       MAR

MS Assembler Cross Reference     CRF, REF

MS Audio/Visual Interleave       AVI

MS Briefcase Database            BFC

MS Chat Animated Character       AVB

MS Clean Boot File               CB

MS ClipArt Gallery               CAG

MS Compatibility Database        CAT

MS Compiler Compiled Source Code COD

MS Debug Information File        DBG

MS Developer Studio Project File DSP

MS Developer Studio Workspace    DSW

MS DOS Code Page Information     CPI

MS DOS Help                      HLP

MS Draw Palette                  PAL

MS Excel Add-in File             XLL

MS Excel Backup                  XLK

MS Excel Chart                   XLC

MS Excel Dialogue                XLD

MS Excel Macro                   XLM

MS Excel VBA Module              XLV

MS Excel Worksheet/Add-In/Templ. XLS, XLA, XLT, XLB

MS Excel Workspace/Workbook      XLW

MS Find Saved Search             FND

MS HyperTerminal Shortcut        HT

MS IE Cascading Style Sheet      CSS

MS IExplorer Connection Wizard   ICW

MS Image Color Matching Profile  ICM

MS Internet Explorer Cache       DAT

MS Language Character Set        NLS

MS Linker Database               ILK

MS Midi Music                    RMI

MS Money Data                    MNY

MS Multi-Media Movie             MMM

MS Multiplan Spreadsheet         COL

MS Network Shortcut              MCC

MS Office Assistant Actor        ACT

MS Office Assistant Preview      ACP

MS Office Binder Doc/Temp        OBD

MS Office Binder Template        OBT

MS Office Binder Wizard          OBZ

MS Outlook Message Store         PST

MS Outlook Express Email Folder  MBX

MS Outlook Express Email Index   IDX

MS Outlook Express Email Tree    NCH

MS Outlook Express News Message  NWS

MS Paint Bitmap                  MSP

MS Personal Address Book         PAB

MS Pictures                      PCS

MS PowerPoint Slides             PPT

MS PowerPoint Template           POT

MS Powerpoint Slideshow          PPS

MS Program Information           PNF

MS Project File                  MPP

MS Query Database                DBF

MS Query Database Index          MDX

MS Rich Text Format Document     RTF

MS ScanDisk/CHKDSK Fragment File CHK

MS Schedule+ Print File          FMT

MS Setup Wizard Dependency File  DEP

MS Spell Checker Dictionary      DIC

MS Spelling Auto Correct List    ACL

MS Tip of the Day File           TIP

MS Visual BASIC Include File     BI

MS Visual C++ Compiled Resources RES, APS, RCT

MS Visual C++ Debug File         SBR

MS Visual C++ Definition File    DEF

MS Visual C++ DLL Exports File   EXP

MS Visual C++ Interface Des Lang IDL

MS Visual C++ Object Desc. Lang. ODL

MS Visual C++ Precompiled Header PCH

MS Visual C++ Program Database   PDB, BSC, NCB, IDB

MS Visual C++ Registry Source    RGS

MS Visual C++ Resource File      RC

MS Windows 3.1 True Type Font    TTF

MS Windows 3.x Logo              LGO

MS Windows 3.x Screen Grabber    2GR, 3GR

MS Windows 3.x Screen Saver      SCR

MS Windows 3.x System Font       FON, FOT

MS Windows 95 Password List File PWL

MS Windows 95 Plus! Palette      PAL

MS Windows Address Book          WAB

MS Windows Animated Cursor       ANI

MS Windows Audio Converter       ACM

MS Windows Bitmap                BMP

MS Windows Briefcase Document    BFC

MS Windows Cabinet Archive       CAB

MS Windows Calendar              CAL

MS Windows Card File             CRD

MS Windows Clipboard File        CLP

MS Windows Control Panel Applet  CPL

MS Windows Cue Cards             CUE

MS Windows Cursor                CUR

MS Windows Desktop Theme         THEME

MS Windows Disk Map File         DMF

MS Windows Driver (16 bit)       DRV, DLL

MS Windows Driver (16 bit)       EXE, VXD, SYS, DRV

MS Windows Fax Cover             CPE, CPD

MS Windows Help Answer Wizard    AW

MS Windows Help Contents Table   CNT

MS Windows Help File             HLP

MS Windows Help Full Text Search FTS

MS Windows Help Global Index     GID

MS Windows Help Module           CHM, CHI, CHQ

MS Windows Help Text Search      TSC

MS Windows Icon                  ICO

MS Windows Install Script        INS

MS Windows Library (16 bit)      DLL, DRV, VBX, EXE

MS Windows Library (32 bit)      DLL, TLS, OCX, CPL

MS Windows MetaFile (placeable)  WMF

MS Windows Office Toolbar Button TBB

MS Windows Password List         PWL

MS Windows Printer Driver        WPD

MS Windows Program (16 bit)      EXE, MOD, BIN

MS Windows Program (32 bit)      EXE, SCR, MOD, SYS

MS Windows Program (WIN386)      EXE

MS Windows Program Group         GRP, GRB

MS Windows Program Information   PIF

MS Windows Registry              DAT, DAO

MS Windows Registry Import File  REG, DAT

MS Windows Resource              RES

MS Windows Shortcut/Link         LNK

MS Windows Sound Mix             MIX

MS Windows SQL Application       APP

MS Windows Swap File             SWP

MS Windows True Type Font        TTF

MS Windows Type Library          TLB, TWD

MS Windows Uninstall Script      ISU

MS Windows Wave Sound            WAV

MS Windows Welcome Bitmap        WBM

MS Word for DOS Document         DOC

MS Word for DOS Font             DAT

MS Word for DOS Printer Def.     PRD

MS Word for DOS Style Sheet      STY

MS Word for Macintosh Document   MCW

MS Word for Windows Document     DOC, DOT, WIZ, WZS, WRI

MS Word for Windows Template     DOT

MS Works Database                WDB

MS Works Document                WPS

MS Write Document                WRI


Appendix D. Init Script for CVSD

#! /bin/sh

# /etc/init.d/cvsd script for starting cvsd

# copied from the Debian installation of CVSD

# Copyright (C) 2002, 2003, 2004 Arthur de Jong

#

# This program is free software; you can redistribute it and/or modify

# it under the terms of the GNU General Public License as published by

# the Free Software Foundation; either version 2 of the License, or

# (at your option) any later version.

#

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

# GNU General Public License for more details.

#

# You should have received a copy of the GNU General Public License

# along with this program; if not, write to the Free Software

# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

CVSD_BIN=/usr/sbin/cvsd

DESC="cvs pserver chroot wrapper"

CVSD_CFG=/etc/cvsd/cvsd.conf

[ -x "$CVSD_BIN" ] || exit 0

[ -f "$CVSD_CFG" ] || exit 0

PIDFILE=`sed -n 's/^ *PidFile *\([^ ]*\) *$/\1/p' < $CVSD_CFG`

[ -n "$PIDFILE" ] && PFO="--pidfile $PIDFILE"

case "$1" in

start)

  echo -n "Starting $DESC: cvsd"

  start-stop-daemon --start --quiet \

                    $PFO \

                    --exec $CVSD_BIN \

                    -- -f $CVSD_CFG \

    || echo -n " already running"

  echo "."

  ;;

stop)

  echo -n "Stopping $DESC: cvsd"

  start-stop-daemon --stop --quiet  \

                    $PFO \

                    --exec $CVSD_BIN \

    || echo -n " not running"

  echo "."

  [ -n "$PIDFILE" ] && rm -f $PIDFILE

  ;;

restart|force-reload)

  echo -n "Restarting $DESC: cvsd"

  start-stop-daemon --stop --quiet --retry 10 \

                    $PFO \

                    --exec $CVSD_BIN

  [ -n "$PIDFILE" ] && rm -f $PIDFILE

  start-stop-daemon --start --quiet \

                    $PFO \

                    --exec $CVSD_BIN \

                    -- -f $CVSD_CFG \

    || echo -n " not restarted"

  echo "."

  ;;

status)

  echo -n "Status of $DESC: "

  if [ -n "$PIDFILE" ]

  then

    if [ -f "$PIDFILE" ]

    then

      if kill -0 `cat $PIDFILE` > /dev/null 2>&1

      then

        echo "running."

        exit 0

      else

        echo "stopped."

        exit 1

      fi

    else

      echo "stopped."

      exit 3

    fi

  else

    if ps -ef | grep cvsd | grep -v grep > /dev/null 2>&1

    then

      echo "probably running. (no PidFile in cvsd.conf)"

    else

      echo "probably not running. (no PidFile in cvsd.conf)"

      exit 3

    fi

  fi

  ;;

*)

  echo "Usage: $0 {start|stop|restart|force-reload}" >&2

  exit 1

  ;;

esac

exit 0


Chapter 1. Finding Documentation

    Section 1.1. Introduction

    Recipe 1.2. Understanding man Pages

    Recipe 1.3. Finding Appropriate man Pages

    Recipe 1.4. Finding Lost man Pages

    Recipe 1.5. Reading man Pages Without a man Viewer

    Recipe 1.6. Configuring Your manpath

    Recipe 1.7. Using info Pages

    Recipe 1.8. Printing man Pages

    Recipe 1.9. Printing info Pages

    Recipe 1.10. Printing Selected man or info Pages

    Recipe 1.11. Finding All of the Documentation for a Program


1.1. Introduction

Documentation for Linux programs is abundant. Finding it can be a bit challenging, though. You're not going to find lots of sleek, glossy printed manuals, because most Linux software is distributed online, rather than in shiny boxed sets.

There's another difficulty, too: Linux follows the grand Unix tradition of small, specialized programs working cooperatively, so any Linux distribution contains a large number of individual programs. For example, Tom's Root Boot, "The most GNU/Linux on one floppy disk," contains over 230 separate, individual programs on a single 3.5" diskette. A general-purpose distribution such as Mandrake or SuSE contains several thousand programs and there are over 12,000 packages in the Debian repositories. While organizing and maintaining a printed library presents some difficulties, the good news is that all of these things are documented. Whatever you want to know, there is a way to find it.

1.1.1 man and info: The Universal Linux Manuals

Almost every program written for Linux has a man page. They're usually not the best teaching tool for newbies. Their purpose is to document the command syntax and every command option, and to be universally available. No matter what kind of strange desert-island scenario you may find yourself in, there will always be man pages. And because man pages are incorporated into the programs to which they belong, you'll find that only installed programs have man pages and that the versions of those pages are pertinent to your system.

info pages tend to be more verbose than man pages and are hyperlinked. The hyperlinks navigate to the various nodes, or chapters, inside the document and to cross-references in other info pages. Many info pages are simply reformatted man pages. But in some instances—primarily the GNU project programs—the info pages are more detailed, containing tutorials and extensive examples.

1.1.2 Other Documentation

A large number of README, CHANGELOGS, RELEASE NOTES, COPYRIGHT, INSTALL, integrated Help systems, and HTML docs are going to be squirreled away in various locations on your system. Yes, it's a jumble. Don't worry, you'll learn easy ways to find all these things in this chapter, including a nice Python script to do the finding for you.

There are many web sites that host complete archives of man and info pages, which comes in handy if your system is missing the ones you want, or you want to read them without having to download and install new programs. A Google search will find them quickly.

The commercial Linux distributions—for example, Red Hat, SuSE, Mandrake, Xandros, and Linspire—supply excellent user manuals. Every major Linux distribution provides a feast of online resources. Search engines, user mailing lists, Usenet, and all sorts of Linux web sites also supply a wealth of help and information.

1.1.3 Graphical Viewers

There are several good graphical man and info page viewers:

Konqueror

The web and file browser in KDE also contains an excellent man and info page viewer. Simply type man:foo or info:/foo in the address bar. It is easy to print from Konqueror, and easy to select individual man or info pages for printing.

Yelp

The Gnome viewer. Displays man and info pages, and Gnome's help documents. It is indexed and searchable.

Pinfo

A nice ncurses-based info and man viewer for the console. Users can add new documents to it, and it supports regexp searches.


Recipe 1.2. Understanding man Pages

1.2.1 Problem

You're trying to use some programs (for example, everyone's favorite, grep; the name tells you so much) and you can't make them them do what you want. So, heeding the standard "RTFM" (read the fine man page) advice, you dig up the relevant man pages. But they don't make a lot of sense—now what?

1.2.2 Solution

Learn how man pages are organized, and familiarize yourself with their conventions for teaching command syntax and options, and you'll find that man pages really are helpful.

1.2.3 Discussion

Linux sees all the man pages on a system as part of a single manual. This manual is divided into sections:

1 Executable programs or shell commands
2 System calls
3 Library calls
4 Special files (usually found in /dev)
5 File formats and conventions
6 Games
7 Miscellaneous
8 System administration commands
9 Nonstandard kernel routines
n New documentation, which may be moved later
l Local documentation, specific to your system

Each individual program, utility, or function has its own page in this manual, like a page in a book. Finding the man page for a program or command is usually as easy as typing man foo, where foo is the name of the program.

You've probably seen references to numbered man pages, like grep(1). This is referring to man grep in section 1. Call it up this way:

$ man 1 grep

Some man pages are in more than one section. man foo will only display the first one. You can list all of them with the -f switch:

$ man -f man

man (1)   an interface to the online reference manuals

man (7)   macros to format man pages

Each man page is divided into sections. The section names vary, but you'll usually see these: NAME, SYNOPSIS, DESCRIPTION, OPTIONS, FILES, EXAMPLES, SEE ALSO, BUGS, and AUTHOR.

Here's the notation used to show command syntax, found in the Synopsis of the man pages:

command-name [optional flags] any-other-required-elements

Command flags are shown this way:

bold text

Type this exactly as it is shown.

italic text

Italic text indicates an argument, which means you replace it with your desired value. Depending on the viewer you are using, you may not see italics, but rather underlines or bold text.

[-abc]

Everything inside square brackets is optional and can be combined.

[-a|-b|-c]

Options separated by the pipe | (Shift-backslash) cannot be combined.

argument...

The ellipsis indicates that several arguments can be listed. Watch out for delimiters—usually they are spaces, but sometimes commas are used.

[expression] ...

The ellipsis indicates that several expressions can be listed.

Short options can be typed two ways:

-abc

or:

-a -b -c

Long options must be individually hyphenated, and they use double hyphens:

--option1 --option2 --option3

Long options are especially useful in scripts, so you can remember what the script does.

The bulk of most man pages is a list of the options available.

1.2.4 See Also

  • man(1)


Recipe 1.3. Finding Appropriate man Pages

1.3.1 Problem

You need a program or utility to perform a specific function—for example, counting the words in a file—but you don't know what to look for. If you knew what you were looking for, you wouldn't need to look for it, right? How do you get out of this dilemma?

1.3.2 Solution

Do keyword searches with apropos or man -k. For example, if you want a command to count the words in a file, use:

$ apropos count words

or:

$ man -k count words

american-english (5) - a list of english words

grpconv (8)          - convert to and from shadow passwords and groups.

grpunconv (8)        - convert to and from shadow passwords and groups.

kmessedwords (1)     - a letter order game for KDE

lppasswd (1)         - add, change, or delete digest passwords.

pwconv (8)           - convert to and from shadow passwords and groups.

pwunconv (8)         - convert to and from shadow passwords and groups.

shadowconfig (8)     - toggle shadow passwords on and off

wc (1)               - print the number of newlines, words, and bytes in files

It doesn't matter which you use; apropos and man -k are the same. There are a lot of options, but wc looks like the program you want.

Remember the -f switch, to find all versions of a man page:

$ man -f manpath

manpath (1)      - determine search path for manual pages

manpath (5)      - format of the /etc/manpath.config file

1.3.3 Discussion

These commands perform keyword searches in the Description sections of the man pages. You can use any number of search terms, but the more you use, the more results you'll get, because they search each keyword in sequence.

Because these are literal keyword searches, broad concepts like "bandwidth shaping" or "user management" do not carry the same meaning for apropos and man -k; they see "bandwidth shaping" as two unrelated search terms, so single-word searches usually work best.

1.3.4 See Also

  • apropos(1), man(1)


Recipe 1.4. Finding Lost man Pages

1.4.1 Problem

You can't find a man page for an installed program, and you're certain it should be on the system.

1.4.2 Solution

Sometimes the man database gets corrupted, users make strange modifications, or programs install man pages incorrectly. First try searching with whereis -m:

$ whereis -m cat

cat:/usr/man/man1/cat.1.gz /usr/share/man/man1/cat.1.gz

Now you've found the page. Read it with man:

$ man /usr/man/man1/cat.1.gz

If that doesn't work, try rebuilding the man database with mandb:

# mandb

If that doesn't work, try a system-wide search with locate and egrep:

$ locate / cat. | egrep -w 'cat\.[1-9][a-zA-Z]*[.gz]?'

This works for any man page—simply replace cat with whatever you're looking for.

If none of these approaches turn up the man page you are looking for, try the finddoc script in Recipe 1.11. If this doesn't find it, it's not on your system.

1.4.3 Discussion

There are all kinds of man page repositories on the Web, so you can always try a Google search. However, some programs simply don't have man pages, so don't ruin your health searching for one that may not exist.

1.4.4 See Also

  • whereis(1), mandb(8)

  • grep comes in several flavors; see grep(1) for details


Recipe 1.5. Reading man Pages Without a man Viewer

1.5.1 Problem

You're working on a system that is seriously messed up, and you can't read man pages because the man viewer doesn't work.

1.5.2 Solution

Try reading the raw man page with zcat and nroff:

$ zcat /usr/man/man1/cat.1.gz | nroff -man | less

As a last resort, read the raw page code with zless:

$ zless /usr/man/man1/cat.1.gz

.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.32.

.TH CAT "1" "July 2003" "cat (coreutils) 5.0" "User Commands"

.SH NAME

cat \- concatenate files and print on the standard output

.SH SYNOPSIS

.B cat

[\fIOPTION\fR] [\fIFILE\fR]...

It's not pretty, but it works.

1.5.3 Discussion

nroff is a wrapper for groff, for formatting man pages. groff is a document-formatting, or typesetting, program. It enables you to create many differently formatted documents from a single source file: HTML, .pdf, printed hard copies, info pages, and many more. See Chapter 9 of Running Linux for a good introduction.

1.5.4 See Also

  • mandb(8), locate(1),

grep(1), nroff(1),

groff(1), zless(1),

zcat(1)

  • Recipe 1.6

  • Chapter 9 of Running Linux, by Matt Walsh, Matthias Dalheimer, Terry Dawson, and Lar Kaufman (O'Reilly)


Recipe 1.6. Configuring Your manpath

1.6.1 Problem

You're repeatedly having trouble finding man pages; using tools from Recipe 1.4, you find that most of the missing pages are in a directory that man doesn't seem to know about. Perhaps a newly-installed program put its man pages in a strange place, like /opt/man. Or perhaps you want to put some man pages in a nonstandard location. How do you configure man to find them?

1.6.2 Solution

Edit /etc/manpath.config.

Suppose the directory you want to add is /opt/man. Add /opt/man to /etc/manpath.config:

# every automatically generated MANPATH includes

# these fields

MANDATORY_MANPATH                   /usr/man

MANDATORY_MANPATH                   /usr/share/man

MANDATORY_MANPATH                   /usr/X11R6/man

MANDATORY_MANPATH                   /usr/local/man

MANDATORY_MANPATH                   /opt/man

And you're done. Now man will find the man pages in the new directory.

When you create a custom man page directory, be sure to include the section directories:

$ ls /opt/man/local

man1  man2  man3  man4  man5  man6  man7  man8  man9

It's not necessary to include all the numbered sections, just the ones pertinent to the man pages you'll be storing there.

If you're going to have subdirectories—for example, /opt/man and /opt/man/local—be sure to list them in this order:

MANDATORY_MANPATH                   /opt/man/local

MANDATORY_MANPATH                   /opt/man

Subdirectories must be listed before parent directories, or they will be overlooked by the man viewer.

1.6.3 Discussion

You can run manpath with no options to see your current manpaths:

$ manpath

/usr/local/man:/usr/share/man:/usr/X11R6/man:/usr/man

1.6.4 See Also

  • manpath(1), manpath(5)


Recipe 1.7. Using info Pages

1.7.1 Problem

You decide to give info pages a try, so you call up info tar (or any other info page of your choice). But you find that navigating info tar is confusing and difficult. What is the best way to learn your way around?

1.7.2 Solution

Use info's built-in tutorial. Type info at any command line, hit the letter h, then do what it says. It should take 15-30 minutes, and it is time well-spent.

1.7.3 Discussion

Even though some folks think that info pages are unnecessarily complicated to navigate, it is worth getting acquainted with them. Even though they are more difficult to navigate than man pages, they are (usually) easier to understand. Once you get the hang of moving around in them, you can go very fast and find information quickly. Info pages often contain more information than man pages, and they sometimes include tutorials and extensive examples.

There are also a number of nice info viewers, such as pinfo, Konqueror, and Yelp. Pinfo runs in the console, and Konqueror and Yelp need X. Konqueror is especially easy to navigate and to use for printing selected pages.

1.7.4 See Also

  • info info


Recipe 1.8. Printing man Pages

1.8.1 Problem

You want to print a man page, nicely formatted and readable. You have tried man foo | lpr, but it doesn't look very good. The margins are too small, and all the formatting is lost.

1.8.2 Solution

One way to print a nicely formatted man page is to use the -t flag, which formats it especially for printing. man finger is good for practice, because it's only two pages long:

$ man -t finger | lpr

To use a networked printer:

$ man -t finger | lpr -P printername

To see your available printers:

$ lpstat -p -d

Another option is to use the following command, which formats the page in HTML and sends it to the web browser of your choice:

$ man -Hmozilla finger

Then use the browser's print command. Be sure there is no space between -H and the browser name.

1.8.3 Discussion

All of the major Linux distributions ship with CUPS, the Common Unix Printing System. CUPS supports both the System V (lp) and Berkeley (lpr) commands. This recipe uses the Berkeley commands. Here is the System V equivalent.

$ man -t finger | lp

To use a networked printer:

$ man -t finger | lp -d printername

1.8.4 See Also

  • man(1), lpr(1), lp(1)

  • Chapter 14

  • CUPS Software Users Manual (http://localhost:631/documentation.html)


Recipe 1.9. Printing info Pages

1.9.1 Problem

You want to print some info pages, but there doesn't seem to be a built-in print command for info.

1.9.2 Solution

You can use lpr:

$ info finger | lpr

However, this may result in too-small margins and odd line breaks, depending on your printer defaults. Use lpr options to format it:

$ info finger | lpr -o cpi=12 -o page-left=54 -o page-right=54 -o page-top=54 \

 -o page-bottom=54

The numbered values are points, or 1/72". This example creates 3/4" margins all the way around. cpi=12 sets the number of characters to 12 per inch. All of these options are documented in the CUPS Software Users Manual, at http://localhost:631/documentation.html.

1.9.3 Discussion

All of the major Linux distributions ship with CUPS, the Common Unix Printing System. CUPS supports both the System V (lp) and Berkeley (lpr) commands. This recipe uses the Berkeley commands. Here are the System V equivalents.

To print an info page use:

$ info finger | lp

To print the info page using lp's formatting options use:

$ info finger | lp -o cpi=12 -o page-left=54 -o page-right=54 -o page-top=54 \

-o page-bottom=54

1.9.4 See Also

  • info info, lpr(1), lp(1)

  • Chapter 14

  • CUPS Software Users Manual (http://localhost:631/documentation.html)


Recipe 1.10. Printing Selected man or info Pages

1.10.1 Problem

You would like to print selected man and info pages, because most man and info documents are quite long. For example, man bash consumes 33 printed pages. How can you print pages selectively?

1.10.2 Solution

Export the man or info page to a plain text file, using the col command. Then you can easily select the pages to print. To do this with man bash or info bash use:

$ man bash | col -b > bash.txt

$ info bash | col -b > bash.txt

1.10.3 Discussion

If you just type man bash > bash.txt, the results will be unpleasant. col -b cleans things up considerably by removing reverse line feeds, or backspaces. This is especially suited for converting man pages to plain text, because man pages are full of reverse line feeds, which then appear in text files as either empty boxes or repeated characters.

1.10.4 See Also

  • col(1)


Recipe 1.11. Finding All of the Documentation for a Program

1.11.1 Problem

You want to find all the relevant readmes, changelogs, howtos, guides, examples, samples, and other documentation that accompanies your installed programs.

1.11.2 Solution

Use finddoc, that wonderful Python script that comes to you courtesy of the excellent Akkana Peck.

You can call it anything you like. Remember to make it executable:

$ chmod +x finddoc

Using it requires only the script name and the name of the program for which you need the documentation. For example:

$ ./finddoc grep

/usr/share/doc/grep

/usr/share/doc/grep-dctrl

/usr/share/doc/grep-dctrl/changelog.gz

...

The output can be filtered through other commands, or redirected to a file:

$ ./finddoc | grep -i examples | lpr

$ ./finddoc | grep -i faq

$ ./finddoc | grep -i examples > python-examples.txt

1.11.3 Program: finddoc

#!/usr/bin/env python

# Finddoc: A Script For Finding Linux Program Documentation

# When making your own copy of this script, be sure to

# preserve the leading spaces exactly as they are written

# here, because Python needs them.

# Search for documentation related to the given strings;

# case-insensitive, and whole-word only.

# Relies on "locate" and assumes that the locate

# database is current.

#

# Copyright 2003 by Akkana Peck.

# You may use, distribute or modify this program

# under the terms of the GPL.

import sys, os, string, re

# This is the list of document-related filenames

# to search for. You may edit this list as needed.

# Be sure to add only lowercase names.

docfilenames = [

 "changelog",

 "readme",

 "install",

 "howto",

 "authors",

 "news",

 "todo",

 "config",

 "sample",

 "samples",

 "example",

 "examples",

 "ref",

 "guide",

 "manual",

 "quickstart",

 "thanks",

 "notes",

 "features",

 "faq",

 "acknowledgement",

 "bugs",

 "problems"

]

def system_out (cmdstr) :

 retlist = [  ]

 fp = os.popen(cmdstr)

 while 1:

  s = fp.readline( )

  if not s : break

  retlist.append(s)

 fp.close( )

 return retlist

# main( )

for arg in sys.argv :

 #print string.split(arg, " \t./")

 files = system_out("locate " + arg + " | grep -w " + arg);

 for path in files :

  #print path

  # Special case for anything with "man", "doc", or "info" in the path:

  if (string.find(path, "/man") >= 0) \

   or (string.find(path, "/doc") >= 0) \

   or (string.find(path, "/info") >= 0) :

   print path,

)

   continue

  # Now see if it matches any of the docfilenames:

  base = os.path.basename(path)

  for nam in docfilenames :

   if base =  = "" : continue

   # Non full word search would use this:

:

   # Full-word-search:

   # Make a regexp to search for nam as full-word only

   pat = "^" + nam + "$"

   if (re.compile(nam).search(base, 1)) :

    print path,

    base = ""

    continue

1.11.4 See Also

  • locate(1), grep(1)

  • Chapter 9 of Python in a Nutshell


Chapter 10. Patching, Customizing, and Upgrading Kernels

    Section 10.1. Introduction

    Recipe 10.2. Adding New Features to the 2.4 Kernel

    Recipe 10.3. Slimming a Stock 2.4 Kernel

    Recipe 10.4. Upgrading to the Latest Stable Version of the 2.4 Kernel

    Recipe 10.5. Building the 2.6 Kernel

    Recipe 10.6. Adding New Features to the 2.6 Kernel

    Recipe 10.7. Adding a New Loadable Kernel Module

    Recipe 10.8. Patching a Kernel

    Recipe 10.9. Removing a Kernel Patch

    Recipe 10.10. Creating an initrd Image

    Recipe 10.11. Creating a Boot Disk on Debian

    Recipe 10.12. Creating a Boot Disk on Red Hat


10.1. Introduction

Patching, customizing, and upgrading the Linux kernel are useful tasks to master, and they're really not all that scary. These are among the few system maintenence chores that require a reboot, which can be dismaying for those who glory in sustaining long uptimes. Other than that, it's no worse than patching or upgrading any other software.

You'll need kernel sources, and gcc, the GNU C compiler. There are two places to get kernel sources: from your own distribution, or from http://kernel.org. The different Linux distributions modify kernels to varying degrees. Red Hat, SuSE, and Mandrake ship heavily modified kernels. Debian and Slackware mess with them only a little bit. It's possible that installing a vanilla kernel from http://kernel.org will cause things to break on distributions that use modified kernels, so it's better to use kernel sources for your distribution. (See Chapter 2 and Chapter 3 for more information on obtaining and installing Linux software, and Recipe Recipe 4.2 to learn about build tools.)

As with most Linux software, when you patch a kernel, you're not patching your existing kernel; rather, you're patching the sources and building a new binary, so you'll end up with two kernels. This is a good thing, because then you'll have your original kernel to use in the event the new one doesn't boot. You can install as many different kernels as you like, and test the latest releases and different configurations.

When should you modify a kernel?

  • To optimize it for your hardware

  • To get new functionality

  • To remove unneeded functions

  • To test new features

  • To upgrade

10.1.1 Configuring the New Kernel

Configuration is the most time-consuming part of building a new kernel. It's also the most important. This step is where you decide what hardware, filesystems, power-management features, and other features are going to be supported. There are over a hundred different items to choose from, and there are potentially three decisions to make for each feature: should it be enabled, and if so, as a loadable module or statically compiled into the kernel? As a general rule, if it can be made into a module, do it. This conserves memory, as memory is not allocated for modules until they are actually in use. Also, it's easier to update or add modules than it is to rebuild the whole kernel.

The kernel configurator contains help entries for almost every item. It tells you if a feature can be built as a module, or if it must be built into the base kernel. The help entries describe what each feature is for and advise you what to do with it if you're not sure it should be enabled. If there is no help entry and you don't know what to do, it's safe to enable it. At worst, you'll have a fatter kernel with features you don't use.

The kernel configuration program won't let you make something into a module if it needs to be part of the base kernel, with one important exception: the driver for the disk drive that contains the root filesystem. This must be built into the base kernel, so that the system can boot. Otherwise, you're in a chicken-and-egg situation: drivers are needed to load the root filesystem, but the filesystem cannot be loaded because the drivers are on the filesystem. If you don't build the drivers into the kernel, you'll need to create an initrd image. initrd creates an initial ramdisk that loads the disk drivers, so that the system can boot.

A common misconception is that using loadable modules is slower than building everything into a monolithic kernel. Either way, it simply involves calls to memory locations, so there is no speed difference at all.

Use menuconfig for configuring 2.4 kernels, and use either menuconfig or xconfig for 2.6 kernels. menuconfig is ncurses-based, so you don't need X. If you don't have ncurses, your options are to install it or to use config, which is a seriously dreadful choice. config is the original kernel configurator. It takes forever, and if you make a single mistake you have to start over.

xconfig was completely redesigned for the 2.6 kernel. It's efficient and extremely helpful, containing good help files for every option. You'll need Qt, qt-devel, gtt, and X to run it. Figure 10-1 shows you the xconfig user interface in all its glory. As you can tell, there are lots of optional features you can configure.

Figure 10-1. xconfig user interface

The kernel build tree contains reams of documentation. Look in linux-$VERSION/Documentation/. Also, see linux-$VERSION/README for important installation tips, and read linux-$VERSION/Documentation/Changes for important information on what versions of gcc and other utilities.


Recipe 10.2. Adding New Features to the 2.4 Kernel

10.2.1 Problem

You want to add some new feature to your existing 2.4 kernel, such as support for new hardware, new filesystems, or additional networking capabilities. For example, you've just finally gotten around to buying a USB drive for backup, and you've never used USB before. How do you find out whether your system supports USB now? And how do you add it if it doesn't?

10.2.2 Solution

Download fresh kernel sources and compile a new kernel using your existing .config file, adding the new features you want.

The prerequisites are:

  • First, make sure you have at least 500 MB of free disk space for the build process.

  • Next, make hard copies of the outputs of dmesg, lscpi, cat /proc/cpuinfo, and lsusb. (See Chapter 5 for more information on these.)

  • Back up all of your data, and have a bootable rescue disk at hand.

  • You'll also need a kernel .config file.

To add a new feature to your existing kernel, download new sources of the same kernel version. To find your kernel version, use uname:

$ uname -r

2.4.22

Unpack the new kernel sources into a folder in your home directory, such as ~/src:

$ tar xvjf linux-2.4.22.tar.bz2

Edit the new kernel makefile (~/src/linux-2.4.22/Makefile), giving a custom value to EXTRAVERSION, such as EXTRAVERSION = -new-kernel.

Run the following commands from ~/src/linux-2.4.22:

$ make mrproper

Copy your .config file to ~/src/linux-2.4.22 now.

Next, configure the new kernel. The configurator will ask many questions. This is where you select the new features you want:

$ make oldconfig

Then run these commands:

$ make dep

$ make bzImage

$ make modules

$ su

# make modules_install

# cp ~/src/linux-2.4.22/arch/i386/boot/bzImage  /boot/vmlinuz-2.4.22-new-kernel

# cp ~/src/linux-2.4.22/System.map /boot/System.map-2.4.22-new-kernel

Finally, to use your new kernel, add it to your bootloader and reboot. A GRUB entry looks like this:

title     Kernel  2.4.22, new kernel

root      (hd0,0)

kernel    /boot/vmlinuz-2.4.22-new-kernel root=/dev/hda1 ro

LILO users do this:

image=boot/vmlinuz-2.4.22-new-kernel

    label=Kernel 2.4.22, new kernel

    root=/dev/hda1

    read-only

And remember to re-run LILO, to write the new configuration to the boot record:

# /sbin/lilo

Save a copy of your new .config file in a directory outside of the build tree, so that it does not get deleted or overwritten. Give it a unique, helpful name:

$ cp ~/src/linux-2.4.22/.config  ~/kernel-configs/.config-2.4.22-jan-04

You can also add coments to the .config file itself, to help you keep track:

# Automatically generated by make menuconfig: don't edit

#

# jan 2004 added udf r/w support, jfs, and xfs

When you're satisfied that the new kernel works correctly, you can delete the old kernel, its /lib/modules/$VERSION directory, the build tree, and its bootloader entries (or you can hang on to them, if you prefer).

10.2.3 Discussion

A lot of documentation tells you to put your kernel sources and build tree in /usr/src/linux. This is a bad idea. As the kernel Readme states: "Do NOT use the /usr/src/linux area! This area has a (usually incomplete) set of kernel headers that are used by the library header files. They should match the library, and not get messed up by whatever the kernel-du-jour happens to be." And you don't want to abuse rootly powers by using a directory that requires root access. A kernel can be built anywhere, even on a completely separate PC.

10.2.3.1 Finding .config

If you've previously built a kernel on your system, you'll find the .config file in the top-level directory of the old build tree. If you have not built a kernel on the system, look in /boot for .config, as most distributions put it there. If you find one in /usr/src/linux, it's most likely a generic .config, and not useful to you.

If there is not a .config file for your system, skip ahead to Recipe Recipe 10.3, because you'll have to configure your new kernel from scratch. make oldconfig will still work, but it will use the defaults in the build tree, which will not suit your system at all. make oldconfig tells you which file it is using:

$ make oldconfig

...

# Using defaults found in arch/i386/defconfig

You don't want to use that one! It should say this:

# Using defaults found in .config

Hit Ctrl-C to interrupt and start over, if necessary.

10.2.3.2 Explanations of the build commands

You can have several kernels on your system, as long as you remember to give each one a unique EXTRAVERSION value and to use a unique name when copying the new kernel image to /boot.

Documentation/Changes recommends using gcc 2.95.3. Most newer distributions ship with 3.x, which ought to work, but if you have problems you can install more than one version of gcc on your system, and select the one you want to use at compile-time:

$ make bzImage CC=gcc-2.95.3

make mrproper cleans the build tree to a pristine state, removing configuration files, dependency information, and object files. Do this even with freshly downloaded sources. (mrproper, according to Linux lore, is named for Mr. Proper. Mr. Proper is the European version of Mr. Clean, for those occasions when you need to make something cleaner than clean.) mrproper cleans the build tree more thoroughly than make clean, which removes object files but does not touch configuration or dependency files. Read the Makefile to see exactly what files are removed.

make oldconfig reuses your existing kernel configuration. When you're making a minor addition to your kernel, make oldconfig lets you whiz right through and only asks about new things. It will not let you change any existing settings. "y/n/m/?" means "yes, build this into the kernel / no, do not add this feature / yes, add this as a module / help, please."

If you don't know what to choose, hit ? for help.

make dep builds all the necessary dependencies.

make bzImage compiles the new kernel. This can take up to an hour, depending on the speed of your PC and how complex your new kernel is.

make modules compiles all of the necessary modules.

make modules_install is the first operation that requires superuser privileges. For this example, your new modules are installed into /lib/modules/2.4.22.

cp ~/src/arch/i386/boot/bzImage /boot/vmlinuz-2.4.22-new-kernel copies your nice new kernel image to the /boot directory, and renames it. It is important, when installing multiple kernels, to make sure each one has a unique name and to use the same kernel name in your bootloader.

cp ~/src/System.map /boot/System.map-2.4.22-new-kernel copies the new System.map to /boot. Be sure that the System.map has the same version number as the kernel to which it belongs. The System.map is a symbol table that maps kernel addresses to human-readable names. For example:

c01001f8 t int_msg

c0100210 t ignore_int

c0100232 t idt_descr

The kernel is happier with numbers, while human coders do better with names. This map keeps everyone happy. If you are running multiple kernels on a system, each kernel needs its own System.map. If you have the wrong System.map, the consequences are not dire. You'll occasionally see the "System.map does not match actual kernel" error message, and you won't get accurate kernel debugging if you need to troubleshoot.

10.2.4 See Also

  • This chapter's "Introduction," for where to get kernel sources and where to look for documentation

  • The online help in the kernel configurator—almost every configuration item has an entry


Recipe 10.3. Slimming a Stock 2.4 Kernel

10.3.1 Problem

You would like to overhaul the kernel that came with your distribution and weed out all the unnecessary drivers, getting rid of support for hardware and functions you don't need.

10.3.2 Solution

Download new sources of the same kernel version and compile the new kernel, configuring it from scratch. To find your kernel version, use uname:

$ uname -r

2.4.22

The prequisites are:

  • First, make sure you have at least 500 MB of free disk space for the build process.

  • Next, make hard copies of the outputs of dmesg, lscpi, cat /proc/cpuinfo, and lsusb. (See Chapter 5 for more information on these.)

  • Back up all of your data, and have a bootable rescue disk at hand.

Unpack the new kernel sources into a folder in your home directory, such as ~/src:

$ tar xvjf linux-2.4.22.tar.bz2

Edit the new kernel makefile (~/src/ linux-2.4.22/ Makefile), giving a custom value to EXTRAVERSION, such as EXTRAVERSION = -slim-kernel

All of the following commands are run from ~/src/linux-2.4.22:

$ make mrproper

$ make menuconfig

$ make dep

$ make bzImage

$ make modules

$ su

# make modules_install

# cp ~/src/linux-2.4.22/arch/i386/boot/bzImage  /boot/vmlinuz-2.4.22-new-kernel

# cp ~/src/linux-2.4.22/System.map /boot/System.map-2.4.22-new-kernel

When you configure the kernel, keep in mind that you are starting from scratch, so you must explicitly enable every feature that you want. And you must make sure that features you do not want are not enabled. These are some core features that you definitely want:

  • Loadable module support, built into the kernel.

  • Under the "General Setup" menu, be sure that support is built in for a.out binaries, ELF binaries, and MISC binaries.

  • Be sure to build support for all of your boot devices—IDE drives, CD-ROM, floppy disk, SCSI disk, or USB—into the kernel. If you leave them out, or build them as modules, your system will require a ramdisk (initrd image) to boot.

When you're finished, add the new kernel to the bootoader, reboot, and enjoy. Remember to copy your new .config file to a directory outside of the build tree to preserve it.

10.3.3 Discussion

This procedure configures the new kernel from scratch. make oldconfig doesn't work, because it does not let you change the old configuration; it only lets you add new things.

A typical base kernel runs around 1-3 MB (compressed), and the corresponding /lib/modules/$version runs around 10-30 MB. Some folks like to strip their kernels to the absolute bare essentials. On a server, especially one that is exposed to the Internet, it's a good security practice to keep it as lean as possible. But having a bit of fat on a desktop system or workstation isn't all that significant, and it may be convenient for future changes.

The name vmlinuz, according to lore, came about because the kernel on old Unix systems was vmunix. The vm stands for "virtual memory," to distinguish it from older kernels that did not have this feature. In your build tree, you'll see a vmlinux file. vmlinuz is the compressed version of this file. There's no need to be dull and stick with naming your kernels vmlinuz-$version. You can name them anything you like—kernel-mustard, kernel-panic, kernel-of-truth, fred-and-ginger . . . anything at all.

10.3.4 See Also

  • This chapter's "Introduction," for where to get kernel sources and where to look for documentation

  • The online help in the kernel configurator—almost every configuration item has an entry

  • Recipe Recipe 10.2, for explanations of build commands, managing .config files, and installing the new kernel


Recipe 10.4. Upgrading to the Latest Stable Version of the 2.4 Kernel

10.4.1 Problem

You've heard there have been many updates and patches to the kernel. You would like to update your old kernel to the latest stable version (e.g., from 2.4.22 to 2.4.25), because this is the easiest way to get all the updates and patches.

10.4.2 Solution

Back up of all of your data, and have a bootable rescue disk at hand.

Make hard copies of the outputs of dmesg, lscpi, cat /proc/cpuinfo, and lsusb.

Unpack the new kernel sources into a folder in your home directory, such as ~/src:

$ tar xvjf linux-2.4.25.tar.bz2

Edit the new kernel makefile (~/src/linux-2.4.25/Makefile), giving a custom value to EXTRAVERSION, such as EXTRAVERSION = -new-kernel.

All of the following commands are run from ~/src/linux-2.4.25:

$ make mrproper

If want to use your existing .config file, copy it to ~/src/linux-2.4.25 now and continue with this recipe. If not, go back to Recipe Recipe 10.3.

Run the following commands:.

$ make oldconfig

$ make dep

$ make bzImage

$ make modules

$ su

# make modules_install

# cp ~/src/linux-2.4.25/arch/i386/boot/bzImage  /boot/vmlinuz-2.4.25-new-kernel

# cp ~/src/linux-2.4.25/System.map /boot/System.map-2.4.25-new-kernel

Add the new kernel to your bootloader, reboot, and enjoy.

10.4.3 Discussion

http://lwn.net and http://kerneltrap.org are good sites for keeping on top of kernel news, changes, improvements, and problems.

10.4.4 See Also

  • This chapter's "Introduction," for where to get kernel sources and where to look for documentation

  • Recipe 10.2, for complete details on building and installing a kernel

  • The online help in the kernel configurator—almost every configuration item has an entry


Recipe 10.5. Building the 2.6 Kernel

10.5.1 Problem

You would like to try the 2.6 kernel, and you need to know the new build commands, which are different from those for the 2.4 kernel.

10.5.2 Solution

In this example, our new kernel is version 2.6.3. Back up of all of your data, and have a rescue disk at hand.

Make hard copies of the outputs of dmesg, lscpi, cat /proc/cpuinfo, and lsusb.

Download and unpack new kernel sources into a folder in your home directory, such as ~/src. Change to the top-level directory of your new source tree (~/src/linux-2.6.3).

Edit the new kernel makefile (~/src/linux-2.6.3/Makefile), giving a custom value to EXTRAVERSION, such as EXTRAVERSION =-test. Then run the following commands:

$ make mrproper

$ make xconfig

$ make

$ su

# make modules_install

# cp ~/src/linux-2.6.3/arch/i386/boot/bzImage  /boot/vmlinuz-2.6.3-test

# cp ~/src/linux-2.6.3/System.map  /boot/System.map-2.6.3-test

Save a copy of your new .config file in a directory outside of the build tree. Add the new kernel to your bootloader, reboot, and have fun.

10.5.3 Discussion

You need Qt, qt-devel, and X to run xconfig. menuconfig also works nicely.

The make command, all by itself, replaces make dep, make bzImage, and make modules.

10.5.4 See Also

  • This chapter's "Introduction," for where to get kernel sources

  • Recipe 10.2, for explanations of the build commands and how to configure the bootloader

  • The online help in the kernel configurator—almost every configuration item has an entry


Recipe 10.6. Adding New Features to the 2.6 Kernel

10.6.1 Problem

You need to add features to your 2.6 kernel.

10.6.2 Solution

Follow Recipe 10.5, except you'll use oldconfig instead of xconfig:

$ make mrproper

Copy your existing .config file to ~/src/linux-2.6.3 now. Then run the following commands:

$ make oldconfig

$ make

$ su

# make modules_install

# cp ~/src/linux-2.6.3/arch/i386/boot/bzImage /boot/vmlinuz-2.6.3-test

# cp ~/src/linux-2.6.3/System.map  /boot/System.map-2.6.3-test

Add your new kernel to your bootloader, and you're ready to go.

10.6.3 Discussion

Do not try to use a 2.4 .config file—the two kernels are quite different, and it will cause many troubles.

The make command, all by itself, replaces make dep, make bzImage, and make modules.

10.6.4 See Also

  • The documentation in the kernel build tree, starting with the Readme, which covers building, configuring, and compiling the kernel

  • This chapter's "Introduction," for where to get kernel sources and where to look for documentation

  • Recipe 10.2, for explanations of the build commands and how to configure your bootloader


Recipe 10.7. Adding a New Loadable Kernel Module

10.7.1 Problem

You have changed or added some hardware, such as a NIC card, sound card, or USB device, and you need to install a new kernel module (driver) for the device.

10.7.2 Solution

The steps are the same for 2.4 and 2.6 kernels. Change to the directory that contains the build tree (e.g., ~/src/linux-2.4.25). You'll need a good, up-to-date .config file. Copy it to the top level of your build tree, then run:

$ make oldconfig

As you go through the configuration, find the driver you need and select it as a module (for example, the tulip module, which is a common driver for many Ethernet cards). Then:

$ make dep

$ make modules

# make modules_install

# depmod -av

Load the module with modprobe:

# modprobe tulip

This whole process doesn't need a reboot.

10.7.3 Discussion

make menuconfig also works, if you can't use oldconfig. It just takes longer, and you have to be careful to not leave out anything important.

If you're installing a third-party module that is not in the kernel tree, you must rely on the vendor's installation instructions. The usual method is to download sources, build the module, then load it with modprobe. Some vendors, like nVidia, provide a script that does everything for you.

Most distributions probe hardware at bootup, and automatically load the correct modules. If this does not happen, you'll need to configure some startup files. On Red Hat and SuSE, add the module to /etc/modules.conf. On Debian, add it to /etc/modules. Slackware uses rc.modules.

Even easier is to enable kmod, the automatic module loader, in your kernel. Most distributions enable it by default. In the kernel configurator, look for "Automatic kernel module loading" (2.6 kernel) or "Kernel module loader" (2.4) under "Loadable module support."

Don't use kerneld; kmod replaced it starting from the 2.2 kernel.

10.7.4 See Also

  • This chapter's Introduction, for where to get kernel sources and where to look for documentation

  • Recipe 10.2, for explanations of the build commands, where to find a .config file, and how to preserve it for reuse


Recipe 10.8. Patching a Kernel

10.8.1 Problem

You want to add a new feature or correct a problem by patching your kernel, test some new features, or update to the next point release.

10.8.2 Solution

Download and apply the patch to the kernel sources, then compile and build the new kernel. In this example, we are upgrading the 2.6.3 kernel to 2.6.4.

The patch must be in the next-highest directory upstream from your build tree, like this:

$ ls ~/src

linux-2.6.3  patch-2.6.4.bz2

Now change to the top level of your build tree, then unpack and apply the patch:

$ cd linux-2.6.3

$ bzip2 -dc ../patch-2.6.4.bz2 | patch -s -p1

Or, you can do a test drive with the —dry-run option:

$ bzip2 -dc ../patch-2.6.4.bz2 | patch -s -p1 —dry-run

Now configure and build your kernel, and away you go.

Your build tree thoughtfully includes a script to handle applying patches for you, in /scripts/patch-kernel. This is a great little script, especially when you have several patches to apply, because it automatically applies them in the correct order. Usage is simple. From your top-level source directory, run:

$ scripts/patch-kernel

Patches must be applied in order, and you must have all of them. For example, to use patch-2.6.5-rc6, you also need the first five patches in the series (rc1 through rc5). When you're upgrading to a newer point release, you can't skip any of them; all of them have to be applied in sequence.

10.8.3 Discussion

This is what the different patch options mean:

-d

Decompress.

-c

Send output to stdout.

../ patch-2.6.4.bz2

Specifies that the patch file is one directory level up.

-s

Silent output, except for errors.

-p

Strips directory prefixes from the filenames in the patch, also called the "patch level." p1 strips the first prefix from the filepaths in the patch, because it's highly unlikely that you have the same directory structure as the author of the patch. p0 would do a literal copy, and the operation would probably fail.

-s

Successful operation returns no output

Kernel patches come in several flavors. Release candidate (rc) patches are one step removed from being accepted into the stable kernel trees; pre-release (pre) candidates are two steps away. If you're dying to have a new feature and you don't want to wait for the final stable release, rc and pre patches are the way to go. Numbering is seemingly backward: patch-2.6.5-rc3 will wind up in the 2.6.4 kernel.

The official kernel releases on Kernel.org are the "Linus" kernel trees. These are well tested and considered production-ready. Even-numbered kernels are stable releases; odd-numbered kernels are under development. The Linux kernel is actively maintained back to 2.0, and all kernels back to the beginning of Linux are available in the archives.

Each stable kernel has its own maintainer. Linus Torvalds, of course, is the Big Boss of everything. The maintainers of the individual kernels are.

  • David Weinehall (2.0)

  • Marc-Christian Petersen (2.2)

  • Marcelo Tosatti (2.4)

  • Andrew Morton (2.6)

Then there are the various kernel trees, run by different maintainers. These are where new designs and features are tested. If they survive, they will eventually be merged into the stable kernel tree. Patches from these have the maintainer's initials appended, as in patch-2.6.5-rc3-mm4. The abbreviations you'll see are:

-ac

Maintainer: Alan Cox. Pending patches for sending to Marcelo (for 2.4 series), and extra add-ons, fixes, etc.

-ck

Maintainer: Con Kolivas. 2.4-based patchset for performance tweaks to the scheduler and vm, and faster desktop performace.

-mm

Maintainer: Andrew Morton. Primarily virtual memory improvements.

-rmap

Maintainer: Rik van Riel. rmap relates to performance and design of virtual memory management.

-aa

Maintainer: Andrea Arcangeli. Virtual memory updates, fixes, and improvements.

-dj

Maintainer: Dave Jones. Forward ports of 2.4 bugfixes to 2.5 series.

-osdl

For the enterprise; large, heavy-use machines and high-performance databases.

10.8.4 See Also

  • patch(1)

  • Kernel Newbies (http://kernelnewbies.org)

  • Kernel.org (http://kernel.org)


Recipe 10.9. Removing a Kernel Patch

10.9.1 Problem

You applied a patch, and now you want to get rid of it. It may be unstable or buggy, or maybe you simply made a mistake and want to start over.

10.9.2 Solution

Use the same command you used to unpack and apply it, adding the -R option:

$ bzip2 -dc ../patch-2.6.4.bz2 | patch -s -p1 -R

10.9.3 See Also

  • patch(1)

  • Kernel Newbies (http://kernelnewbies.org)

  • Kernel.org (http://kernel.org)


Recipe 10.10. Creating an initrd Image

10.10.1 Problem

You are using SCSI drives, and you like to load the drivers as modules, because there are so many different SCSI drivers. You want the flexibility to change drives or controllers without rebuilding the kernel every time, and you don't want to fatten your kernel by compiling in every possible driver. But how will the system boot without the SCSI driver built into the base kernel?

10.10.2 Solution

Build an initrd (initialize RAM disk) image with mkinitrd (make initial RAM disk) after you build the kernel. Then add an entry to your bootloader that loads the image.

On both 2.4 and 2.6 kernels, after running make modules_install, run mkinitrd:

# mkinitrd -o /boot/initrd-2.4.25-new-kernel.img

This builds the image and installs it into the /boot directory. Then create your bootloader entries. In GRUB:

title     Kernel  2.4.25, new kernel

root      (hd0,0)

kernel    /boot/bzImage-2.4.25-new-kernel root=/dev/hda1 ro

initrd    /boot/initrd-2.4.25-new-kernel.img

LILO users do this:

image=/boot/bzImage-2.4.22-new-kernel

    initrd=/boot/initrd-2.4.25-new-kernel.img

    label=Kernel 2.4.22, new kernel

    root=/dev/hda1

    read-only

Remember to run /sbin/lilo to activate the changes.

10.10.3 Discussion

Be sure to read the mkinitrd man page for your system, as the options differ slightly between the different distributions.

It's perfectly okay to build your SCSI driver into the base kernel; using initrd isn't required.

Most of the major Linux distributions use initrd, so that their stock kernels will boot on most systems without needing every driver in the world to be built in.

10.10.4 See Also

  • mkinitrd(8)


Recipe 10.11. Creating a Boot Disk on Debian

10.11.1 Problem

You forgot to create a boot diskette when you installed your Linux system, and now you want to make one. You know how to create a GRUB or LILO boot diskette, and you know that you can download and burn a nice Knoppix disk for free. But all you really want is a nice little generic boot diskette for your Debian system.

10.11.2 Solution

Use the mkboot utility and a new, blank diskette. The default is to create a bootdisk using vmlinuz and the current root partition:

$ mkboot

You may specify a kernel:

$ mkboot vmlinuz-2.4.21

Or a different root partition and kernel:

$ mkboot /dev/hda2 vmlinuz-2.4.21

If your floppy drive has a non-standard location, use the -d flag to tell mkboot where it is:

$ mkboot -d /dev/fd1

10.11.3 Discussion

mkboot is part of the debianutils package.

Remember to write-protect your diskette by moving the little slide up, so that the slide is open. Always test boot disks before putting them away, and be sure to keep it with the system it was created on.

10.11.4 See Also

  • mkboot(8)


Recipe 10.12. Creating a Boot Disk on Red Hat

10.12.1 Problem

You forgot to create a boot diskette when you installed your Linux system, and now you want to make one. You know how to create a GRUB or LILO boot diskette, and you know that you can download and burn a nice Knoppix disk for free. But all you really want is a nice little generic boot diskette for your Red Hat/Fedora system.

10.12.2 Solution

Use the mkbootdisk utility and a new, blank diskette. You must specify the kernel name:

$ mkbootdisk vmlinuz-2.6.5-1.358

mkbootdisk, by default, does not generate any output. You can turn on verbosity:

$ mkbootdisk --verbose vmlinuz-2.6.5-1.358

If your floppy drive is not /dev/fd0, you must specify the device name:

$ mkbootdisk --device /dev/fd1 vmlinuz-2.6.5-1.358

10.12.3 Discussion

Remember to write-protect your diskette by moving the little slide up, so that the slide is open. Always test boot disks before putting them away, and be sure to keep it with the system it was created on.

10.12.4 See Also

  • mkbootdisk(8)


Chapter 11. CD and DVD Recording

    Section 11.1. Introduction

    Recipe 11.2. Finding the SCSI Address for CD and DVD Writers

    Recipe 11.3. Enabling SCSI Emulation for IDE/Atapi CD and DVD Writers

    Recipe 11.4. Making a Data CD for General Distribution

    Recipe 11.5. Building File Trees on a Data CD

    Recipe 11.6. Copying a CD or DVD

    Recipe 11.7. Erasing a CD-RW

    Recipe 11.8. Recording a Multisession Data CD

    Recipe 11.9. Creating a Bootable CD

    Recipe 11.10. Spanning a Large File over Several CDs

    Recipe 11.11. Recording Data DVDs

    Recipe 11.12. Recording an Audio CD for Standard CD Players


11.1. Introduction

Linux offers a host of CD/DVD writing and authoring utilities. The entire field is evolving rapidly, and CD/DVD standards are in a chaotic state. There are several competing, incompatible standards, and more are looming on the horizon as commercial distributors toil to develop a magical disc that will permit playback but not copying. This chapter sidesteps all of this drama and introduces some basic techniques for writing data CDs and DVDs. You'll need the cdrtools and dvd+rw-tools packages.

To create discs the easy way, use K3b. It is a graphical frontend to cdrtools, cdrdao, mkisofs, growisofs, and other command-line editing tools. K3b makes it easy to set up your drives and to give users any necessary root privileges, such as those required by cdrecord and cdrdao. The layout is logical and simple to use; it gets my vote as the best CD/DVD writer on any platform. Of course, the Linux world offers many more choices, such as GCombust, X-CD-Roast, and Gnome Toaster. These are all simple to use, so this chapter will cover the command-line tools. Understanding these will also make the graphical tools more useful, as you'll understand the commands and weird terminology.

A major change in the 2.6 kernel is that you no longer need to use SCSI emulation for CD/DVD drives. Instead of running cdrecord scanbus to find the SCSI bus addresses, simply use the /dev names of the devices:

# cdrecord dev=/dev/hdc <commands>

If you have upgraded from a 2.4 to a 2.6 kernel and you used IDE-SCSI for your CD/DVD drives, be sure that the IDE-SCSI entries are removed from your bootloader, or you'll get strange boot errors.

11.1.1 Glossary of Formats and Standards

Here are the hardware standards:

CD-R

CD-Recordable, or WORM (Write Once, Read Many). CD-Rs are universal and should be readable in any CD-ROM drive.

CD-RW

CD-Rewritable, or WMRM (Write Many, Read Many). A drive must be "multiread" to be able to read CD-R and CD-RW discs. CD-RWs should be readable in all contemporary drives.

CD-ROM

Compact Disc-Read-Only Memory. Commercially produced discs are pressed, not burned with a laser, and cannot be written to.

Mount Rainier ReWrite

The circuitry needed by a drive to support UDF.

DVD-Video

The standard used on commercially produced movie discs, playable on all DVD machines.

DVD-R and DVD+R

WORM format. Playable on all DVD players. DVD-R has two different, incompatible disc types: DVD-R(A) and DVD-R(G). You can't use A discs in G writers, and vice versa.

DVD-RAM

Rewritable, designed for data storage. Theoretically, it can take up to 100,000 rewrites per disc. You can also record and play movies on a PC, but a standalone DVD player probably won't be able to read DVD-RAMs.

DVD-R/RW

Designed for recording movies. This DVD standard is supported by the DVD Forum (http://www.dvdforum.com).

DVD+R/RW

A competing, incompatible standard to DVD-R/RW, supported by the DVD+RW Alliance (http://www.dvdrw.com). Only DVD+R/RW supports UDF.

The newest generation of DVD drives for computers support all formats. Standalone DVD recorders are still fighting standards wars between the DVD+ and DVD- formats.

Here are the CD and DVD filesystem standards:

El Torito

Bootable format specification.

UDF

Universal Disk Format, the industry-standard incremental packet-writing filesystem. This allows dropping files directly on to a disc, just like on a 3.5" diskette. It was expected that Linux would fully support this in the 2.6 kernel, but it's not there yet.

ISO-9660

The old file layout standard, allowing only 8.3 filenames (from the ancient MS-DOS days, where filenames could have only up to 8 letters and had to have 3-letter file extensions).

Rock Ridge

Extensions to ISO-9660, allowing long filenames and Unix-style symlinks. It preserves all file attributes, such as ownership and permissions. Unix file attributes are not displayed when the disc is read on a Windows system.

Joliet

Microsoft extension to the ISO-9660 filesystem that allows Unicode characters to be used in filenames, as well as long filenames. It also creates truncated filenames for MS-DOS compatibility (these weird-looking things: FILENA~1.TXT). It allows filenames of up to 64 characters, including spaces, and is readable by Windows 95 or later and by Macintosh computers running the Joliet Volume Access extension. Macs will not read Joliet filenames that are longer than 31 characters.

Here are the CD standards books:

Yellow Book

Physical format for data CDs

Orange Book

Physical format for recordable CDs, with multisession capability:

Part I: CD-MO (Magneto-Optical)
Part II: CD-R (Write-once; includes "hybrid" spec for PhotoCD)
Part III: CD-RW (Re-writable)

Red Book

CD Audio standard that describes the physical properties of the disc and the digital audio encoding

These books can be purchased from http://www.licensing.philips.com, if you really want to get into the gory details.

These are the write options:

Session

Any single recorded segment on a disc, which can contain data files or a number of music tracks. A disc can contain several sessions.

Track

The program area of a CD is divided into tracks; each track can contain data of only one type. A disc (even a DVD) holds a maximim of 99 tracks—the number is hardcoded.

Multisession

Allows adding files to a single disc over time, rather than having to record all of your files in a single session. For a disc to be readable, the session must be "closed," or fixated. However, this prevents adding more files to the disc. Multisession links the individual sessions and updates the disc's table of contents so that it appears as a single directory.

SAO (session-at-once)

A single, complete session (lead-in, program, and lead-out areas) of a CD-R or CD-RW disc, written in one uninterrupted sequence.

DAO (disc-at-once)

Writes the entire CD in one pass, or session. The entire burn must complete without interruption, and no more sessions may be added. This is the most reliable way to record audio tracks.

TAO (track-at-once)

Allows the writes to be done in multiple passes. There is a maximum of 99 tracks per disc. Sometimes this causes audio CDs to not play correctly on audio disc players, though I've found it to be reliable.

For more information on DVDs, see the DVD FAQ at http://www.dvddemystified.com/dvdfaq.html.

For more information on CDs, see the CD Recordable FAQ at http://www.cdrfaq.org.


Recipe 11.2. Finding the SCSI Address for CD and DVD Writers

11.2.1 Problem

You're using a 2.4 kernel and want to write a CD or DVD. You need to know the SCSI bus address, or dev= number, for your CD/DVD writer.

11.2.2 Solution

cdrecord -scanbus will find it for you. This is what a CD/DVD-ROM and a CD writer on a single system look like:

$ cdrecord -scanbus

Cdrecord 1.10 (i686-pc-linux-gnu) Copyright (C) 1995-2001 Jrg Schilling

Linux sg driver version: 3.1.24

Using libscg version 'schily-0.5'

scsibus0:

0,0,0 0) 'TOSHIBA ' 'DVD-ROM SD-M1202' '1020' Removable CD-ROM

0,1,0 1) 'LITE-ON ' 'LTR-24102B ' '5S54' Removable CD-ROM

0,2,0 2) *

0,3,0 3) *

0,4,0 4) *

0,5,0 5) *

0,6,0 6) *

0,7,0 7) *

DVD writers look like this:

1,2,0 2) 'PIONEER ' 'DVD-ROM DVD-303 ' '1.09' Removable CD-ROM

The first three numbers for each item refer to the SCSI bus, device ID, and LUN (Logical Unit Number), respectively. The fourth number is the device ID again. cdrecord wants the first three numbers, like this:

dev=0,1,0

11.2.3 Discussion

cdrecord requires root privileges. The most common convention for giving users permissions to use cdrecord is to create a cdrecord group.

Sometimes you'll see documentation where it looks like this:

dev=1,0

It's a common convention to leave off the leading 0 for devices on SCSI bus 0. However, it's not much trouble to type an extra digit and leave no room for doubt.

The 2.6 kernel needs no special steps to determine the device ID. Simply use the /dev name:

$ cdrecord dev=/dev/hdc <commands>

11.2.4 See Also

  • cdrecord(1)


Recipe 11.3. Enabling SCSI Emulation for IDE/Atapi CD and DVD Writers

11.3.1 Problem

Your CD-writing program (whether it's cdrecord or one of the good graphical programs such as X-CD-Roast or K3b) reports that it cannot find any drives on your system, or it sees your CD-R/RW drive just fine but does not see your CD-ROM drive, so you can't copy discs.

11.3.2 Solution

Make sure the IDE-SCSI emulation system is enabled and your drives are configured to use it. This applies only to the 2.4 Linux kernel, because the 2.6 kernel supports IDE/ATAPI drives directly, using the standard /dev/hd* designations.

First, verify that the ide-scsi pseudo-device driver is available:

$ locate ide-scsi.o

/lib/modules/2.4.21/kernel/drivers/scsi/ide-scsi.o

Next, there are two text files to edit: /etc/modules.conf, and the configuration file for your bootloader. (Debian users, please refer to the "Discussion" section of this recipe, as file locations are different.) First, find the device names for your drives:

$ dmesg | grep '^hd.:'

hda: IBM-DTLA-305020, ATA DISK drive

hdb: TOSHIBA DVD-ROM SD-M1202, ATAPI CD/DVD-ROM drive

hdc: LITE-ON LTR-24102B, ATAPI CD/DVD-ROM drive

The CD drives are hdb and hdc. Add the following to /etc/modules.conf:

alias scsi_hostadapter ide-scsi

options ide-cd ignore="hdb hdc"

alias scd0 sr_mod

pre-install sg     modprobe ide-scsi

pre-install sr_mod modprobe ide-scsi

pre-install ide-scsi modprobe ide-cd

Next, LILO users, add the following to the end of lilo.conf, using the hd* designations for your devices:

append="hdb=ide-scsi"

append="hdc=ide-scsi"

GRUB users, add the following to /etc/grub.conf at the end of the kernel line, using the hd* designations for your devices:

hdb=scsi hdc=scsi

It should look like this, all on one line:

kernel   /boot/vmlinuz-2.4.21 root=/dev/hda1 ro hdb=scsi hdc=scsi

Reboot, then verify that the ide-scsi module loaded:

$ lsmod | grep ide-scsi

ide-scsi           9456   1

scsi_mod          55124   2 [ide-scsi sr_mod]

Now when you run cdrecord -scanbus it should show SCSI device names for all the drives you configured to use IDE-SCSI, and you should be ready to start CD writing.

Note that the device names are changed now, so when you mount the discs the device names won't be /dev/hd* any more, but rather /dev/scd*. You'll probably want to update /etc/fstab with the new /dev names.

11.3.3 Discussion

Debian's module configuration files are in different locations. First, Debian uses /etc/modules and /etc/modutils/idecd_opts. Add:

ide-scsi

to /etc/modules. Then add:

options ide-cd ignore="hdb hdc

to /etc/modutils/idecd_opts.

There is no downside to running all of your CD/DVD drives under the IDE-SCSI subsystem, except for having different device names.

The 2.6 kernel needs no special steps. Simply use the /dev name:

$ cdrecord dev=/dev/hdc <commands>

Remember, you can use a cdrecord group to grant permissions to users for cdrecord.

11.3.4 See Also

  • grub(8), lilo(8)


Recipe 11.4. Making a Data CD for General Distribution

11.4.1 Problem

You want to create a data CD that will be readable on Linux and Windows, with non-restrictive file permissions. The disk may contain text files, documents, programs, or graphical images.

11.4.2 Solution

Use mkisofs, mount, and cdrecord. First use mkisofs to package all of the files into a single .iso file, then mount the .iso to verify the filesystem is good. Then write to disk with cdrecord.

In this example, the .iso is called data.iso, the CD is named data_disk, and all the files will be copied from the /disk-data directory. The mountpoint for the .iso is /test-iso.

Here are the commands:

# mkisofs -J -r -v -V data_disk -o data.iso  /disk-data

# mkdir /test-iso

# mount -t iso9660 -o ro,loop  data.iso /test-iso

# ls /test-iso

# umount /test-iso

# cdrecord -v -eject dev=0,1,0 data.iso

11.4.3 Discussion

This recipe shows the root user running all commands, for simplicity, because mount, mkisofs, and cdrecord require root privileges. To allow users to run the mount command, use sudo. To allow users to run mkisofs and cdrecord, create a cdrecord group. Make it own mkisofs and cdrecord, and put users in the cdrecord group.

Remember that the 2.6 kernel doesn't need IDE-SCSI, so you can just use the /dev name:

# cdrecord dev=/dev/hdc <commands>

There's a whole lot of doings packed into these few lines. Let's break them down one at a time. mkisofs takes all of your files and rolls them into one big .iso file. If you've ever downloaded a Linux distribution to burn to CD, it was packaged as an .iso file. This is a common source of confusion for Linux newbies, who don't understand why they have this giant single file, instead of a nice directory tree full of Linux files.

Let's look at the mkisofs line in more detail:

# mkisofs -J -r -v -V data_disk -o data.iso  /disk-data

Here are the options:

-J

Use Joliet naming conventions, for Windows compatibility.

-r

Use Rock Ridge naming conventions for Unix/Linux compatibility, and make all files publicly readable.

-v

Use verbose mode.

-V data_disk

Create a volume ID (data_disk); this is the disc name that shows up in Windows Explorer and with the file - < /dev/scd* command (see Recipe Recipe 9.12 for how to find the /dev names).

-o data.iso /disk-data

The name of the new .iso image, and the files selected for packaging into the .iso, which in this case is everything in /disk-data. Note that the root directory /disk-data is not copied, only the contents.

Mounting the .iso before burning the disc is cheap insurance to make sure you're not creating a coaster. If you see all of your files, it's good to go. If not, the .iso is no good, and it needs to be rebuilt. Here's how to test your .iso:

# mkdir /test-iso

# mount -t iso9660 -o ro,loop data.iso  /test-iso

Then look in the /test-iso directory to verify your files.

Here are the parts of the mount command:

-t iso9660

The filesystem type. Data CDs are always iso9660 (except when they are udf, but you would not need to create an .iso image for these).

-o ro,loop data.iso

Mount options for the file data.iso: in this case read-only, using the loop device. The loop device lets you mount filesystems that are embedded in files, the classic use being .iso images.

/test-iso

The directory created to be the mountpoint.

Now that the .iso is all ship-shape, we can burn it to disc.

# cdrecord -v -eject dev=0,1,0 data.iso

The options are:

-v

Be verbose.

-eject

Eject the disc when finished. This is optional.

dev=0,1,0

The SCSI address of the CD writer.

data.iso

The name of the .iso file that contains the files you want burned to disc.

cdrecord automatically writes at the highest speed the drive and disc support. If there are errrors, try specifiying a lower write speed:

# cdrecord -v -eject speed=4 dev=0,1,0 data.iso

Modern writers have fast write speeds (20X and higher). However, many CD-R/RW discs are limited to much slower speeds. Usually, cdrecord will auto-detect the appropriate write speed.

11.4.4 See Also

  • cdrecord(1), mount(8), mkisofs(8)

  • Recipe 9.12


Recipe 11.5. Building File Trees on a Data CD

11.5.1 Problem

When you select directories for writing to CD, mkisofs discards the root directories and keeps only the files and subdirectories. But you'd like to preserve the file trees, or create new ones.

11.5.2 Solution

Use the -graft-points option in mkisofs. This example preserves the existing directory structure for the directories scripts and finances:

$ ls

finances  scripts

$ mkisofs -r -J -v  -o cdimg1.iso -graft-points scripts/=scripts  finance/=finances

...

Which is easily verified by mounting the image and viewing the file tree with the tree -d command:

$ sudo mount -t iso9660 -o ro,loop cdimg1.iso  /mnt/iso

$ tree -d /mnt/iso

mnt

|-- finances

`-- scripts

Suppose you want to move these two directories into /files/archive/june on the CD. First, the directory /files/archive/june must be present on the hard drive. Then run:

$ mkisofs -r -J -v  -o cdimg1.iso -graft-points  \

files/archive/june/finances/=finances   files/archive/june/scripts/=scripts

Again, we can mount it and check:

$ tree -dL 4 /mnt/iso

mnt

`-- files

    `-- archive

        `-- june

            |-- finances

            `-- scripts

This works for both files and directories.

11.5.3 See Also

  • tree(1), mkisofs(8)


Recipe 11.6. Copying a CD or DVD

11.6.1 Problem

You need to make copies of CDs or DVDs—data, audio, video, or any format.

11.6.2 Solution

To directly copy from the source disc to the recordable disc, use this command:

$ cdrecord -v dev=0,1,0 -isosize /dev/scd0

This is fast, but risky, because any interruption to the data stream will spoil the entire copy. It's better to cache it to a hard drive first. This example makes a dummy run first:

$ dd if=/dev/scd0 of=/tmp/diskfile.iso

$ cdrecord dev=0,1,0 fs=8m -v -eject -dummy /tmp/diskfile.iso

Simply delete the -dummy flag to write to disc.

11.6.3 Discussion

Remember that the 2.6 kernel doesn't need IDE-SCSI—just use the /dev name:

# cdrecord dev=/dev/hdc <commands>

Don't forget that you'll need a tmp file as large as the disc you're copying.

The dd command does a literal, byte-by byte copy. Its components are:

if

Input, or source, file.

/dev/scd0

/dev name for the drive. Be sure to use the correct /dev name for your drive (see Recipe Recipe 11.3). The disc does not need to be mounted.

of

Output, or destination, file.

/tmp/diskfile.iso

Temporary copy of the source disc on the hard drive. Call it anything you want, as long as it has an .iso extension.

The cdrecord options are the same as in Recipe Recipe 11.4, with two new ones:

fs=8m

This defines the size of the ring buffer: the bigger the better, up to a point. Remember, interruptions are fatal; fs=8m creates a large enough buffer to keep the recorder working if something slows down the data transfer. If 8 MB isn't enough, you might need a better PC. On the other hand, more than 8 MB is not necessarily better, as the operating system can waste time reloading the Memory Management Unit (MMU) tables. The default is 4 MB.

-dummy

A marvelous option for doing a dry run before risking an actual disc. The recorder does everything with the laser turned off, giving the user a chance to catch errors before committing them to disc.

11.6.4 See Also

  • cdrecord(1), dd(1)

  • Recipe 11.4


Recipe 11.7. Erasing a CD-RW

11.7.1 Problem

You want to erase a rewritable disk, to prepare it for recording new material, or you might want to erase single tracks.

11.7.2 Solution

Use the blank option for cdrecord. blank=fast erases only the table of contents (TOC), the program memory area (PMA), and the pregap:

$ cdrecord -v blank=fast dev=0,1,0

A more complete erasure is done with the all option:

$ cdrecord -v blank=all dev=0,1,0

Don't count on this for a secure erasure; data can still be recovered. blank=fast is perfectly fine for routine use, and it's a lot faster—plus, your CD-RW will last longer.

You can erase the last session on a multisession disc:

$ cdrecord blank=session

And on the off chance that your drive supports blanking at the track level, you can erase tracks just like sessions, starting with the last one:

$ cdrecord blank=track

11.7.3 Discussion

Blanking at track level is not supported by most drives. Erasing tracks or sessions in random order is not possible, either—you have to start at the end and work your way back. If you get error messages when using any of the blank options, try adding -force:

$ cdrecord blank=track -force

However, the disc is probably damaged or defective, so the wiser course is to discard it.

To see all the blanking options, use:

$ cdrecord blank=help

Keep in mind that CD-RWs have a limited lifespan and can take only so many erasures. The number varies, but you should get at least 100 rewrites before it becomes unreliable.

11.7.4 See Also

  • cdrecord(1)


Recipe 11.8. Recording a Multisession Data CD

11.8.1 Problem

You want to add data files to a disc over time, rather than all at once. cdrecord closes and fixates discs, so that no additional files can be added. How do you get around this?

11.8.2 Solution

This is a two-step process. Both cdrecord and mkisofs have special options for creating multisession discs. The first time you write files to a CD, create an .iso in the usual manner, then use the -multi switch in cdrecord:

$ cdrecord -v -eject dev=0,1,0 -multi first-image.iso

Then create additional .iso images using the -C and -M options:

$ mkisofs -o second-image.iso -J -r -V Session2 -C `cdrecord dev=0,1,0 -msinfo` \

-M 0,1,0 /path-to-new-files

Then write the new .iso to disc, using the -multi option again:

$ cdrecord -v -eject dev=0,1,0 -multi  second-image.iso

Do this as many times as you like. When you get to the last session, omit the -multi option. It's important to close and fixate the disc, or it won't be readable in most drives. Another way to close and fixate the disc, without recording an additional session, is with the fix option:

$ cdrecord -v -fix  -eject dev=0,1,0

11.8.3 Discussion

CDs are written in sessions. Each session covers a number of disc sectors. On a single-session disc, there is a lead-in, a single TOC, the data, and a lead-out, which finalizes the disc and prevents further recording on the disc. mkisofs links multiple sessions together on a multisession disc. To do this, it needs to know the starting and ending sector numbers of each session. Let's take it a piece at a time:

$ mkisofs -o second-image.iso -J -r  -C `cdrecord dev=0,1,0 -msinfo` \

-M 0,1,0 /path-to-new-files

-o second-image.iso

Give the new .iso you are building a name; call it anything you want.

-J

Use Joliet naming conventions, for Windows compatibility. This is optional.

-r

Use Rock Ridge naming conventions for Unix/Linux compatibility, and make all files publicly readable. This is required for creating multisession discs.

-C `cdrecord dev=0,1,0 -msinfo`

The -C flag goes by several names: CD+, CDExtra, last_sess_start, next_sess_start. It tells mkisofs the ending point of the last session and the starting point of the next session. The backticks tell the shell to find and use the values automatically. You can generate these values manually, and see for yourself:

$ cdrecord dev=0,1,0 -msinfo

12968,20172

-M 0,1,0

The -M flag must be used when you use the -C flag. This is the SCSI bus address of the CD writer.

/path-to-new-files

List here the files, or directory, that are going into the new .iso.

11.8.4 See Also

  • cdrecord(1), mkisofs(8)


Recipe 11.9. Creating a Bootable CD

11.9.1 Problem

You need to burn a bootable CD. You already have the boot image and data files.

11.9.2 Solution

The boot image needs to be rolled into the .iso with mkisofs.

If the bootable image is on a floppy disk, first make a boot/ directory in the file tree that is going on the CD, and copy it there:

$ dd if=/dev/fd0 of=~/cd-files/boot/boot.img bs=10k count=144

Or copy it from another location on the hard drive:

$ cp boot.img  ~/cd-files/boot/boot.img

Then package the .iso:

$ mkisofs -r -b boot/boot.img -c boot/boot.catalog -o bootable-cd.iso ~/cd-files

Now burn it to disc with cdrecord, in the usual fashion, and you have a bootable CD.

11.9.3 Discussion

mkisofs uses the El Torito specification to create a boot image that fools a PC into thinking it's seeing a boot floppy. All you need is the boot image, and mkisofs creates the boot catalog.

The options are:

-r

Set the file ownership and modes so that anyone can read the files.

-b boot/boot.img

Specify the path and filename of the boot image. The boot/ directory is relative to the root filesystem of the CD.

-c boot/boot.catalog

Create and name the boot catalog file.

-o bootable-cd.iso ~/cd-files

Name the new .iso, and give the path to the files that go into it.

11.9.4 See Also

  • mkisofs(8)


Recipe 11.10. Spanning a Large File over Several CDs

11.10.1 Problem

You have a very large file, such as a tar archive or a large graphical image, that you wish to store on CD. However, it is larger than a single disc.

11.10.2 Solution

Use the split utility to divide the file, then convert the new files to .iso images and burn them to discs. Use cat to reassemble the original file.

For example, here is a 2-GB tar archive named big-backup. This example splits it into 650-MB chunks. The CD capacity is 700 MB, but there must be room for file overhead:

$ split -b 650m big-backup.tar.gz

creating file `xaa'

creating file `xab'

creating file `xac'

Each file is now about 682 MB. Now convert each one to an .iso image:

$ for i in xa*; do echo -e "$i"; mkisofs -o $i.iso $i; done

This generates a lot of output. When it's finished, the ls command will show this:

$ ls

xaa  xaa.iso  xab  xab.iso  xac  xac.iso

Now you can transfer each one of the .iso files to its own CD:

$ cdrecord -v -eject dev=0,1,0 xaa.iso

$ cdrecord -v -eject dev=0,1,0 xab.iso

$ cdrecord -v -eject dev=0,1,0 xac.iso

To reassemble the tarball, copy the .iso files from the CD to your hard drive, and use the cat command:

$ cat xaa xab xac > big-backup.tar.gz

Or, append the contents of each CD to the archive on your hard drive one at a time, without having to copy them over first:

$ cat /cdrom/xaa > big-backup.tar.gz

$ cat /cdrom/xab >> big-backup.tar.gz

$ cat /cdrom/xac >> big-backup.tar.gz

You can name the reassembled file anything you like—just be sure to preserve the tar.gz extension. And you can now extract the archive:

$ tar xvzf big-backup.tar.gz

11.10.3 Discussion

This is a good way to make a quick and dirty backup, or to move a large number of files, but don't count on it for regular backups. If any of the split files become corrupted, it is difficult to recover the data, especially from compressed files.

See Chapter 16 to learn how to do large backups.

11.10.4 See Also

  • split(1), tar(1), cat(1)

  • Chapter 16


Recipe 11.11. Recording Data DVDs

11.11.1 Problem

You want to record data files on DVD, such as backups, image galleries, or Linux installation discs from .iso images.

11.11.2 Solution

Use growisofs, from dvd+rw-tools. Before you touch anything, make sure you do not have automount or supermount enabled for your DVD writer. Supermount/automount will guarantee a coaster.

Copying files from a hard drive to DVD is done in one step:

# growisofs -Z <device name> <mkisofs commands> <files>

For example:

# growisofs -Z dev=1,2,0 -dvd-compat -udf -R -J -v /home/carla

It is easy to add more files to the DVD. Always use the -Z option for the first batch of files written to the DVD, then use the -M flag for all additional files:

# growisofs -Z dev=1,2,0 -dvd-compat -udf -R -J -v /etc

# growisofs -M dev=1,2,0 -dvd-compat -udf -R -J -v /shared/projectfiles

# growisofs -M dev=1,2,0 -dvd-compat -udf -R -J -v /var/www/public_site

There's no need to explicitly close and fixate the disc.

You may also write .iso images; for example, when you want to create a Linux installation disc on DVD:

# growisofs -Z dev=1,2,0=KNOPPIX_V3.4-2004-05-17-EN.iso

11.11.3 Discussion

An increasing number of Linux distributions are becoming available on DVD-sized .isos, and none too soon, as some take up eight or more CDs.

growisofs replaces cdrecord, and is a frontend to mkisofs, so you get to use the same, familiar mkisofs options, with these two exceptions:

  • Don't use -o to specify an output file, because growisofs writes directly to the DVD.

  • Don't use -C, because growisofs figures out the starting and ending points of tracks all by itself.

-dvd-compat helps to ensure compatibility with the majority of DVD drives.

-udf adds limited udf support. As this was written, packet writing was still not reliably implemented in the Linux kernel. This can be left out, though the price of including it "just-in-case" is just a few bits of extra metadata.

There are RPMs, Debian packages, and tarballs for dvd+rw-tools. The tarball also includes a spec file, if you want to roll your own RPM.

It's not necessary to format new DVD-RW discs, because from version 5.10 growisofs does it automatically as you add files to the DVD. To get your version number, run:

$ growisofs —version

supermount is supposed to enable inserting and removing disks, like floppies, without having to enter mount and unmount commands. It is starting to appear on Red Hat, SuSE, and other distributions, and is usually enabled by default.

To disable supermount temporarily:

# /usr/sbin/supermount -i disable

Use -i enable to reenable it. Unfortunately, supermount doesn't work very reliably yet, so you might be better off disabling it permanently. Remove supermount entries from /etc/fstab to do so. To get rid of it with extreme prejudice, remove the magicdev package:

# rpm -q magicdev

or in Debian:

# apt-get remove magic-dev

11.11.4 See Also

  • The dvd+rw-tools home page (http://fy.chalmers.se/~appro/linux/DVD+RW)


Recipe 11.12. Recording an Audio CD for Standard CD Players

11.12.1 Problem

You want to know how to record audio CDs for playback on a standard audio disk player, like in your car. You need to know how to convert different audio file formats, such as ogg-vorbis, mp3, .wav, and .cdr, because these do not play on standard audio CD players, only on computers.

11.12.2 Solution

Use sox, normalize, and cdrecord. And use CD blanks that are made for audio recording.

The first step is to use sox to convert your sound files to .cdr format, to convert them to the correct file structure; then convert the .cdr to .wav format.

Then, the -audio option for cdrecord converts .wav files to CD-DA (Compact Disk Digital Audio) format, which is what standard audio CD players need.

$ sox soundfile filename.cdr

$ sox filename.cdr filename.wav

$ cdrecord -v -nofix -eject dev=0,1,0 -audio -pad filename.wav

The -pad options ensures that disk sectors will be filled correctly, and -nofix leaves the disk open for adding additional music tracks. To fix and close the disk:

$ cdrecord -v -fix  -eject dev=0,1,0

Converting files one at a time is tedious. This Bash command converts a batch of .ogg files to .cdr format:

$ for i in *.ogg ; do echo $i ; sox $i ${i%%.ogg}.cdr ; echo ${i%%.ogg}.cdr;done

Simply substitute whatever file extensions you need to convert.

If you're compiling a collection of tracks from diverse sources, use the normalize utility to equalize sound volumes,with the -m (mixed-mode) option:

$ normalize -m /soundfiles/*.wav

There are many ways to select tracks to record. This command records all the *.wav-formatted songs in the /home/songs directory, in sorted order: numbers first, then alphabetic capitals, then alphabetic lowercase.

$ cdrecord -v -nofix -eject dev=0,1,0 -audio -pad /home/songs/*.wav

Or, you can change to the /songs directory, then list individual songs:

$ cdrecord -v -nofix -eject dev=0,1,0 -audio -pad song1.wav song3.wav song7.wav

Be sure to use an audio CD-R made for playback in standard audio players.

11.12.3 Discussion

Newer versions of sox are supposed to support .mp3, but this isn't always the case. Run sox -h to see what formats it supports. If your particular version of sox will not convert .mp3s, use mpg123 and sox:

$ mpg123 -b 10000 -s  filename.mp3  | sox -t raw -r 44100 -s -w -c 2 -filename.wav

-b 10000

This sets the buffer size, in bytes.

-s

The -s flag redirects to stdout, instead of trying to play the file.

sox -t raw -r 44100 -s -w -c 2

This is the same as .cdr format, only all the specs are spelled out.

There is a limit of 99 songs per disk. They would have to be very short songs to actually stuff that many on to a CD. You could record about 30 Ramones songs, or a single Beethoven symphony, so it just depends.

If your music files are already in the .wav format, like the files you get from online music services, you probably don't need to convert them. However, not all .wav files have the correct structure for making CDRs; cdrecord will halt and give an error message if this is the case. Use sox to convert the errant .wav to .cdr, then .cdr to .wav.

.wav and .flac formats are the highest-quality digital audio formats. Always start with these, if you can. Then convert them to other formats as needed. The primary reason to convert is to save disk space, as .wav and .flac files are very large. An .ogg file is typically one-tenth the size of a .wav file.

Ogg Vorbis is an open, patent-free, audio encoding and streaming technology. It has no licensing fees or other restrictions that accompany patented, proprietary formats like MP3. It delivers decent sound quality in a compressed, lossy format. "Lossy" means bits are stripped away to reduce file sizes.

MP3 is also a compressed, lossy format of good quality. It's a patented, proprietary format, so there are restrictions on its use, the code is closed, and there are licensing fees for artists and distributors. Thomson and Fraunhofer, who control the MP3 format, are adding DRM (Digital Rights Management, or copy restriction) technology to the MP3 format.

11.12.4 See Also

  • cdrecord(1), sox(1), normalize(1)


Chapter 12. Managing the Bootloader and Multi-Booting

    Section 12.1. Introduction

    Recipe 12.2. Migrating from LILO to GRUB

    Recipe 12.3. Installing GRUB Without a Floppy Disk

    Recipe 12.4. Installing GRUB with grub-install

    Recipe 12.5. Preparing a System for Multibooting Linux

    Recipe 12.6. Adding More Linuxes to a Multiboot System

    Recipe 12.7. Discovering Boot Parameters from the GRUB Command Shell

    Recipe 12.8. Configuring the Boot Partition

    Recipe 12.9. Creating the GRUB Boot Menu

    Recipe 12.10. Customizing menu.lst

    Recipe 12.11. Adding Windows 95/98/ME to a Linux System

    Recipe 12.12. Adding Windows NT/2000/XP to a Multiboot System

    Recipe 12.13. Restoring GRUB to the MBR with a Knoppix CD

    Recipe 12.14. Protecting System Files with a GRUB Password

    Recipe 12.15. Locking Out Users from Individual GRUB Menu Entries

    Recipe 12.16. Creating a GRUB Splash Image

    Recipe 12.17. Booting Linux with LILO

    Recipe 12.18. Multibooting Linuxes with LILO

    Recipe 12.19. Multibooting Windows and Linux with LILO

    Recipe 12.20. Creating a LILO Boot Diskette

    Recipe 12.21. Password-Protecting LILO

    Recipe 12.22. Backing Up the MBR


12.1. Introduction

Linux has two excellent bootloaders: GRUB (the Grand Unified Bootloader) and LILO (Linux Loader). GRUB is newer and more capable than the elder LILO. Both are flexible, configurable, and capable of managing complex boot scenarios, such as multibooting several different operating systems or different Linux kernels, and passing in boot-time kernel options.

If you're still running LILO, it might be worth considering migrating to GRUB. While they work similarly, there are four major differences that set GRUB apart:

  • You can discover boot images, kernels, and root filesystems from the GRUB command shell.

  • GRUB stores boot information in a filesystem, rather than in the master boot record (MBR).

  • GRUB reads filesystems and kernel executables, rather than inflexibly restricting the user to disk geometry.

  • And best of all, GRUB is completely operating system-independent. If you install GRUB into a separate boot partition, you can remove and reinstall operating systems to your heart's content, without having to reinstall the bootloader every time.

Both GRUB and LILO can boot non-Linux operating systems, such as Windows, OS/2, the BSD Unixes, and so forth. For operating systems that they cannot boot directly, such as Windows, GRUB and LILO employ chain loading. That is, they point the way to Windows's own bootloader.

The MBR is the first 512 bytes of the first sector of the first partition on the drive. It contains the partition table and the first-stage bootloader. The first-stage loader is a wee bit of code stored in the first 446 bytes of the MBR, which points the way to the second-stage loader, which is stored in the /boot directory. The remaining 66 bytes are for the partition table.

Linux partitioning is limited to 63 total partitions per IDE drive: 3 primary partitions, with the 4th containing up to 60 logical partitions in a single extended partition.

SCSI drives are limited to 15 partitions per drive: 3 usable primary partitions, and 12 logical partitions in a single extended partition.


Recipe 12.2. Migrating from LILO to GRUB

12.2.1 Problem

You've read the advantages of GRUB in the previous section. You are using LILO and would like to replace it with GRUB, preferably without needing to overhaul your entire system.

12.2.2 Solution

GRUB can be installed without disrupting anything.

First, install GRUB, or upgrade to the latest version. To get the version number, use:

$ grub —version

grub (GNU GRUB 0.94)

Then, take a few preparatory steps:

  1. Make a hard copy of your partition table (fdisk -l | lpr).

  2. Make a hard copy of lilo.conf.

  3. Back up your data and have a rescue disk, like a LILO boot diskette or Knoppix, at hand.

  4. Leave your LILO installation intact, in case you want it back.

Next, follow these steps, in order:

  1. Create a GRUB boot diskette.

  2. Install GRUB to the MBR.

  3. Boot the system.

  4. Edit GRUB's configuration file, menu.lst.

To create a boot floppy, find the /grub/i386 directory. The official location is /usr/lib/grub/i386-pc. Red Hat uses /usr/share/grub/i386-pc, and other distributions may vary as well. Copy the stage1 and stage2 files to the diskette with dd:

$ dd if=stage1 of=/dev/fd0 bs=512 count=1

1+0 records in

1+0 records out

512 bytes transferred in 0.550740 seconds (930 bytes/sec)

$ dd if=stage2 of=/dev/fd0 bs=512 seek=1

209+1 records in

209+1 records out

107250 bytes transferred in 6.889581 seconds (15567 bytes/sec)

$

Now reboot to the diskette. You will be greeted by the nice blue GRUB screen:

GRUB version 0.93 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB lists possible

command completions. Anywhere else TAB lists the possible completions of a

device/filename. ]

grub>

Next, you need to find the root device, which is the partition that contains GRUB's first- and second-stage boot files:

grub> find /boot/grub/stage1

 (hd0,0)

This value is our root device. Set the root device:

grub> root (hd0,0)

Note that GRUB has its own partition numbering scheme. hd0,0 is the same as /dev/hda1. (See the "Discussion" section of this recipe for details.)

Now install GRUB to the MBR, which is the first sector of the first drive:

grub> setup (hd0)

Now it is time to finish booting. Again, set the root device:

grub> root (hd0,0)

Next, enter the path to the kernel and the path to the root filesystem. These are in lilo.conf. Be sure to append ro, to mount the kernel and root filesystem read-only:

grub> kernel /boot/vmlinuz-2.4.21 root=/dev/hda1 ro

Don't confuse "root" on the kernel line with the root device. "Root" on the kernel line identifies the root filesystem. The root device is the partition containing the /boot directory.

This step applies only to systems that require a ramdisk to boot. Enter the path to the initrd image, which should also be in lilo.conf:

grub> initrd /boot/initrd-2.4.21.img

Finally, enter the boot command, and the system should start normally:

grub> boot

If your root and kernel parameters do not work, see Recipe Recipe 12.7 for how to find them from the GRUB command shell.

Now you'll probably want to create the GRUB boot menu. See Recipe 12.9 for details.

12.2.3 Discussion

Always test your rescue disks before you need them.

GRUB uses its own partition numbering scheme; it starts from 0, instead of 1. Both SCSI and IDE drives are represented by hd. Floppy drives are fd.

This is the Linux partition table:

1-4
Primary partitions
5 and up
Extended partitions

In GRUB, it's like this:

0-3
Primary partitions
4 and up
Extended partitions

Additional drives are hd1, hd2, and so on. So hd0,3 is the same as /dev/hda4; hd1,5 is /dev/hdb6.

Note that the root device uses GRUB's numbering system:

grub> root (hd0,0)

and the root filesystem, which is specified on the kernel line, does not:

grub> kernel /boot/vmlinuz-2.4.21 ro root=/dev/hda1

12.2.4 See Also

  • This chapter's "Introduction" for a comparison of GRUB and LILO

  • Recipe 12.7

  • Recipe 12.9

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.3. Installing GRUB Without a Floppy Disk

12.3.1 Problem

You would like to install GRUB, but your system does not have a floppy drive. Or you have a floppy drive but can't find a usable floppy disk.

12.3.2 Solution

Use GRUB's own command shell to set it up.

First, install GRUB, or upgrade to the latest version. To get the version number, use:

$ grub —version

grub (GNU GRUB 0.94)

Next, take a few preparatory steps:

  1. Make a hard copy of your partition table (fdisk -l | lpr).

  2. Make a hard copy of lilo.conf.

  3. Back up your data and have a rescue disk, like Knoppix, at hand.

  4. Leave your LILO installation intact, in case you want it back.

Then open a root shell on your Linux system, and start up a GRUB shell:

# grub

Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB  version 0.94  (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB lists possible

command completions. Anywhere else TAB lists the possible completions of a

device/filename. ]

grub>

Find the stage1 loader:

grub> find /boot/grub/stage1

 (hd0,0)

Now run these three commands:

grub> root (hd0,0)

grub> setup (hd0)

grub> quit

Reboot, and you will be greeted by the GRUB command shell.

You'll probably want to boot into Linux and create a GRUB boot menu. See Recipe 12.7 and Section 12.9 to learn how to do this.

12.3.3 Discussion

This is what happened with those three little commands:

grub> root (hd0,0)
Set the root device.
grub> setup (hd0)
Install GRUB to the MBR.
grub> quit
Exit GRUB.

You will see output similar to this:

grub> root (hd0,0)

 Filesystem type is reiserfs, partition type 0x83

grub> setup (hd0)

 checking if "/boot/grub/stage1" exists...yes

 checking if "/boot/grub/stage2" exists...yes

 checking if "/boot/grub/e2fs_stage1_5" exists...yes

 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 15

 sectors are embedded.

 Succeeded.

 Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p

 (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"...Succeeded

grub> quit

12.3.4 See Also

  • Recipe 12.7

  • Recipe 12.9

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.4. Installing GRUB with grub-install

12.4.1 Problem

Recipe Recipe 12.3 does not work on your Debian, Gentoo, or other Linux system, because the GRUB files are installed into /usr/lib/grub. Or maybe you just want a simpler method for installing GRUB without a floppy disk.

12.4.2 Solution

Use GRUB's built-in installation script, grub-install.

First, install GRUB, or upgrade to the latest version. To get the version number, use:

$ grub —version

grub (GNU GRUB 0.94)

Then run grub-install. When you have a separate /boot partition, you must specify it:

# grub-install —root-directory=/boot  /dev/hda

Otherwise, all you need is the device name for the drive:

# grub-install  /dev/hda

Then run:

# update-grub

This creates a new menu.lst. When you reboot, the GRUB menu will appear and your system will boot normally.

12.4.3 Discussion

update-grub probably won't create a complete menu.lst on a multiboot system, but it will enable you to boot into Linux. Then you can add your other operating systems to menu.lst.

12.4.4 See Also

  • grub-install(8)

  • info grub

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)


Recipe 12.5. Preparing a System for Multibooting Linux

12.5.1 Problem

You plan to multiboot several different Linux distributions, and you want to prepare your system. You want a standalone /boot partition and shared /home and /swap partitions.

12.5.2 Solution

Most Linux distributions let you customize the partitioning during installation. Create new partitions only as you need them during each installation, and leave free space for additional installations.

Let's walk through a clean Fedora installation on a 20-GB IDE drive, using this partitioning scheme:

/dev/hda1
Primary
100 MB
/boot
/dev/hda2
Primary
2,500 MB
/
/dev/hda3
Primary
3,000 MB
/home
/dev/hda4
Extended
/dev/hda5
256 MB
/swap
Free space
14,144 MB

Here are the steps:

  1. Boot up the first installation CD. Select your keyboard, mouse, and display. When you get to the Disk Partitioning Setup window, select "Manually partition with Disk Druid." A nice graphical display shows your hard drive.

  2. Delete any existing partitions. Highlight them one at a time, then click the "delete" button.

  3. Next, highlight "Free Space," and click "New." The mountpoint is /boot. Select Ext2 for the filesystem, and enter the partition size. One hundred megabytes is the minimum Fedora will accept for /boot. Click OK. That is now /dev/hda1.

  4. Highlight "Free Space" again and click "New." The mountpoint is /. Select Ext3, 2500 MB. Click OK. That's /dev/hda2.

  5. Highlight "Free Space" again and click "New." The mountpoint is /home. Select Ext3, 3000 MB. Click OK. That's /dev/hda3.

  6. Highlight "Free Space" again and click "New." Scroll down "filesystem options" until you find "swap." There is no mountpoint; make it 256 MB. Click OK. This is /dev/hda5.

  7. At this point you may go back and make changes, because the new partition table has not yet been written to disk. When you're finished, write the changes to disk by clicking OK in the main Disk Druid menu.

Now you can continue with the installation. Make sure that you install GRUB, not LILO. When you install additional Linuxes, they will share /home and /swap. You can install any number of Linuxes, until your disk is full or you have used all available partitions.

12.5.3 Discussion

Most modern Linux distributions install GRUB by default. Make sure you don't install LILO.

QTParted is an excellent graphical utility for creating, deleting, moving, and resizing disk partitions. QTParted is included on Knoppix, so you can set up your partitioning before installing a new Linux, if you prefer. You can also make changes after installation, even to partitions with data on them. Of course, you must have good backups first. QTParted does a good job, but messing with partitions can backfire.

Putting /swap on its own partition improves performance, and it can be shared on a multiboot system. Giving /home its own partition lets you share it between the different Linux systems you're running, and it allows you to do all sorts of system installations and removals without forcing you to restore your data from backup every time.

Linux partitioning is limited to 63 partitions per IDE drive: 3 usable primary partitions, with the 4th containing up to 60 logical partitions in a single extended partition.

SCSI drives are limited to 15 partitions per drive: 3 usable primary partitions, and 12 logical partitions in a single extended partition.

12.5.4 See Also

  • fdisk(8)

  • Chapter 13

  • QTParted home page (http://qtparted.sourceforge.net)


Recipe 12.6. Adding More Linuxes to a Multiboot System

12.6.1 Problem

You have your nice new boot partition all set up, and your first Linux installed. Now you're ready to add more Linuxes.

12.6.2 Solution

Install additional Linuxes into logical partitions. Then you'll need to create GRUB boot menu entries for each one.

First, prepare the system according to Recipe Recipe 12.5.

Next, boot the installation CD of the second Linux. This example uses Libranet Debian for the second Linux. When you get to the disk partitioning menu, select "Partition & layout drives." You will then see a menu showing the existing disk partitions. Highlight "Free" and select "New." Enter 2500 MB for the partition size. The mountpoint is /. Choose your filesystem type, and make sure "Initialize?" is checked. This is now /dev/hda6.

Select /dev/hda3 to "Modify." Select /home and Ext3, and do not check "Initialize?"

You may now go back and make changes to the partitioning, or select "Write" to write your new partition table to disk. After you select "Write," a warning will appear: "ALL EXISTING DATA ON THESE PARTITIONS WILL BE DESTROYED," with a list of partitions that are going to be formatted, or "initialized." Only / should be listed here.

Continue with the installation. When you get to the bootloader installation menu, do not overwrite the MBR. The installer will ask, "Do you want Linux to handle booting your system?" Say no. You want the boot files installed to the first sector of the root partition, which is /dev/hda6.

When Libranet requires a reboot, bring up the GRUB command shell at boot, and boot Libranet manually:

grub> root (hd0,0)

grub> kernel /boot/vmlinuz-2.4.21 root=/dev/hda6 ro

grub> boot

(See Recipe 12.7 to learn how to discover the boot parameters from GRUB.)

When everything is working satisfactorily, edit menu.lst to add the new system to the GRUB boot menu. (See Recipe 12.9.)

Write down the partitions you create during installation; it will help when you edit menu.lst.

12.6.3 Discussion

The Libranet installer will automatically find any existing swap partitions; you don't need to select them during installation.

You can edit menu.lst from any of your new Linuxes. Simply mount the boot partition, and there it is:

# mkdir /bootpartition

# mount /dev/hda1  /bootpartition

# vim /bootpartition/boot/grub/menu.lst

This highlights some of the benefits of using a boot partition—you always know where it is, and it is safely isolated from your root filesystems.

Partitioning is probably the most complicated part of building a multiboot system. Use logical partitions as much as possible. With only four primary partitions available per physical hard disk, you'll run out pretty quickly if you don't.

12.6.4 See Also

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.7. Discovering Boot Parameters from the GRUB Command Shell

12.7.1 Problem

You don't know the locations of Linux kernels and root devices on your system, and you need to find them so you can boot the system.

12.7.2 Solution

Use GRUB's tab completion to find root devices and kernel images.

First, boot to the GRUB command shell by hitting c when GRUB starts up.

To find the root device (partition containing /boot), type root (hd0 and hit the Tab key until you see some partitions displayed:

grub> root (hd0,<tab>

 Possible partitions are:

    Partition num: 0, Filesystem type is ext2fs, partition type 0x83

    Partition num: 1, Filesystem type is ext2fs, partition type 0x83

When there are several partitions displayed, and you are not sure which one you want, it does not hurt to try them all. First, try (hd0,0):

grub> root (hd0,0)

 Filesystem type is ext2fs, partition type 0x83

Then search for the kernel image. Type kernel /boot/vmlinuz, and hit Tab. If there is no /boot/vmlinuz, GRUB will tell you:

grub> kernel /boot/vmlinuz<tab>

Error 15: File not found

If this happens, reset the root device to the other partition, and look for a kernel image there:

grub> root (hd0,1)

 Filesystem type is ext2fs, partition type 0x83

grub> kernel /boot/vmlinuz<tab>

possible files are: vmlinuz vmlinuz-2.4.21

Okay, you've found a kernel. Type the path to the kernel and the root filesystem:

grub> kernel /boot/vmlinuz-2.4.21 ro root=/dev/hda2

Remember, GRUB's partition numbering starts from zero, so hd0,1 = /dev/hda2.

These next two steps apply only to systems that require a ramdisk to boot. Find initrd:

grub> find /boot/init<tab>

grub> find /boot/initrd-2.4.22-1.img

Load the initrd image:

grub> initrd /boot/initrd-2.4.22-1.img

Now you can boot up:

grub> boot

And the system should start normally.

12.7.3 Discussion

If you are not sure that the usual kernel naming conventions were followed, have GRUB display the entire contents of /boot. Type kernel /boot/, and hit tab:

grub> kernel /boot/<tab>

  System.map  System.map-2.4.21  System.map-2.6.3  boot  grub  config-2.4.21  config-2.6.3

  splash.xpm.gz  vmlinuz  vmlinuz-2.4.21  kernel-of-truth-2.6.3

Well, it looks like we have a wackily-named 2.6 kernel, "kernel-of-truth-2.6.3." Regardless of the silly name, it should work just like its more soberly named cousins.

With tab completion, you can easily search entire filesystems. This is useful for exploring unfamiliar systems, as you can start from the root:

grub> root (hd0,6)

grub> find /<tab>

  Possible files are bin dev etc lib mnt opt tmp sys var usr boot home proc sbin root

cdrom floppy initrd

However, this is a big security hole, as anyone with access to the GRUB command shell can read any file on the system with cat:

grub> cat /root/secretpersonalstuff.txt

grub> cat /etc/shadow

To close this hole, see Recipe Recipe 12.14 to learn how to password-protect GRUB.

GRUB will find root devices and kernels anywhere they may be. Suppose, for example, you have two IDE hard drives. The second drive has a Linux root filesystem installed on /dev/hdb5. Boot it this way:

grub> root (hd1,4)

grub> kernel /boot/vmlinuz-2.4.21 ro root=/dev/hdb5

grub> boot

On an unfamiliar system, you can have GRUB detect all installed hard drives:

grub> root (hd <tab>

  Possible disks are:   hd0  hd1

12.7.4 See Also

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.8. Configuring the Boot Partition

12.8.1 Problem

Because you are using a boot partition, instead of a /boot directory on the root filesystem, you're not sure that the filepaths are correct.

12.8.2 Solution

Use df to see what partitions your filesystems are on. You'll need to make sure any partitions you want to check are mounted.

First, you can verify that your filesystems are installed to the correct partitions with df:

$ df -h

Filesystem      Size    Used    Available  Use% Mounted on

/dev/hda2       2.5G    1.5G      1G        60%    /

/dev/hda1       100M    30M      70M        30%    /boot

Now, verify that the file tree in the boot partition is correct, look for /boot/boot:

$ ls /boot

System.map-2.4.21  boot  grub  config  splash.xpm.gz  vmlinuz  vmlinuz-2.4.21

If there is not a /boot/boot directory, create one, and copy over the files from the parent directory:

# cp -av /boot/ /boot/boot/

Some distributions, such as Debian, create a /boot soft link to the parent directory:

$ cd /boot

$ ls -al boot

lrwxrwxrwx  1 root  root  1 Apr  16  08:50  /boot/boot -> .

It is okay to leave this alone and not create a new /boot directory, even though this link creates an endless loop in the file tree. It's another way to ensure having a /boot directory in the boot partition.

12.8.3 Discussion

Confused over all these boots? Just keep in mind that a partition name is not a directory name, because a partition is not a directory, and a mountpoint can be given any name. GRUB knows nothing about mountpoints—it reads filesystems before they are mounted. So if there is not a /boot directory in the boot partition, GRUB does not see /boot/grub, but /grub. While it's not strictly necessary to have a /boot directory, following this convention will make your life a lot easier.

12.8.4 See Also

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.9. Creating the GRUB Boot Menu

12.9.1 Problem

As fun as it is to discover root devices and kernels from the GRUB command line, you would like to preserve your boot parameters in a configuration file and have a nice boot menu to use at startup. In this menu you will configure your chosen defaults, and have a menu of all of your installed operating systems to choose from.

12.9.2 Solution

Add boot entries to GRUB's configuration file, /boot/grub/menu.lst. (Red Hat uses grub.conf and creates a soft link named menu.lst.)

GRUB calls the different boot entries stanzas. Here is a basic configuration:

title         Fedora 1 core

root          (hd0,0)

kernel        /boot/vmlinuz-2.4.22-1 root=/dev/hda1 ro

initrd        /boot/initrd-2.4.22-1.img

The title can be anything at all, and you must have one—it tells GRUB where each stanza starts, and it appears in the boot menu. The other two lines are the same values we used on the GRUB command line. It is not necessary to use the boot command in menu.lst.

You can list as many operating systems as you want; each one requires a stanza like this one. Make sure the kernel line points to the right partition and kernel executable. It's common to have several bootable kernels in the same root partition. And it is common (even good) for all the boot configurations to use the same boot partition.

Not all Linux distributions require a ramdisk, which is loaded by the initrd image. If /boot/initrd-* exists, you must use it.

12.9.3 Discussion

Remember that the root device, indicated by:

root          (hd0,0)

is the location of the /boot directory, and hd0,0 is GRUB's own numbering system. On the kernel line:

kernel        /boot/vmlinuz-2.4.22-1 root=/dev/hda2 ro

root is the root filesystem, using the kernel dev name.

12.9.4 See Also

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.10. Customizing menu.lst

12.10.1 Problem

You want to change the look of the GRUB menu, and customize options such as timeouts and default boot entries.

12.10.2 Solution

Make your customizations in /boot/grub/menu.lst. (Some systems use grub.conf.)

There are two sections: the global settings and the boot stanzas. Colors, timeouts, and default boot entries are defined in the global section.

This is a complete sample menu.lst, including global configuration options:

##GRUB configuration for windbag, created 10-22-2003

## global settings

## default num

default    0

## timeout sec

timeout    5

# Pretty colors

color cyan/blue white/blue

# Display a splash screen

splashimage (hd0,0)/boot/splash.xpm.gz

foreground    bbbbbb

background   000000

### Boot menu

## default

title    Libranet GNU/Linux, kernel 2.4.21

root     (hd0,0)

kernel   /boot/vmlinuz-2.4.21 root=/dev/hda1 ro hdb=scsi hdc=scsi

## new 2.6 test kernel

title    Libranet GNU/Linux, kernel 2.6.3-test1

root     (hd0,0)

kernel   /boot/bzImage-2.6.3-test1 root=/dev/hda1 ro

## Stock Red Hat 9

title         Red Hat 9

root          (hd0,4)

kernel        /boot/vmlinuz-2.4.22-1 root=/dev/hda5 ro

initrd        /boot/initrd-2.4.22-1.img

12.10.3 Discussion

These are definitions for the global configuration options:

default 0

Sets your default boot entry. Stanzas are read in order, starting from zero, so default 0 selects the first one.

timeout 5

Specifies how long to wait before the default entry boots.

color cyan/blue white/blue

Configures the colors for the GRUB boot menu. cyan/blue defines the foreground and background colors. white/blue defines the highlight colors for lines of text selected by the cursor. The available colors are listed in the GRUB manual and info grub.

splashimage (hd0,0)/boot/splash.xpm.gz

foreground bbbbbb

background 000000

Yes, you can replace the splash screen that came with your distribution with an image of your choosing. (See Recipe 12.16 for how to create the image.) Use the splashimage option to set the filepath to the image. You'll also need to configure the foreground and background colors for the fonts, using standard HTML hex color codes.

Another default choice is default saved. When you use default saved, you must also add savedefault to the boot stanzas, like this:

title    Libranet GNU/Linux, kernel 2.4.21

root     (hd0,0)

kernel   /boot/vmlinuz-2.4.21 ro root=/dev/hda1

savedefault

This makes the last item booted the default for the next boot. Many distributions configure the boot stanzas to include savedefault, but they don't add default saved, so it doesn't work.

12.10.4 See Also

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.11. Adding Windows 95/98/ME to a Linux System

12.11.1 Problem

You have a single computer, and you would like to dual-boot Windows 95/98/ME and Linux, because you use applications on both platforms. Or you have a small test network, and you want to install as many operating systems are you can in multiboot configurations, so that you can test different combinations of operating systems without using a lot of computers. Or you already tried to add Windows 95/98/ME to your nice new Linux multiboot system, but it didn't even install—it complained about not being able to format the C: drive, which is a good thing, because it would have overwritten your Linux installations. You don't want to use an emulator like VMWare, which lets you run both at the same time without rebooting, because it's too expensive, or your hardware is too feeble.

12.11.2 Solution

There are a number of tricky bits to adding Windows 95/98/ME to a Linux system. You'll need to hide partitions, and restore GRUB to the MBR after the Windows installation, because Windows overwrites the bootloader. Windows 95/98/ME must have a primary partition prepared in advance. Unfortunately, GRUB does not boot CD-ROMs, so you'll need a Windows Startup diskette. (This is a very useful disk for all versions of Windows.) If you don't have one, it is easy to make one from 98 or ME:

  1. Load a new, blank diskette.

  2. Go to Control Panel [image] Add/Remove Programs.

  3. Click on the Startup Disk tab.

  4. Click on the Create Disk button.

Write-protect the disk, and it's ready to go.

To install Windows 95/98/ME on /dev/hda4:

  1. Boot to the GRUB command shell.

  2. Insert the Windows 98 Startup diskette.

  3. At the GRUB command line, hide all of your existing partitions:

    grub>  hide (hd0,0)

grub>  hide (hd0,1)

grub>  hide (hd0,2)

  4. Now boot the Windows diskette:

    grub>  chainloader (fd0) +1

grub>  boot

    Be sure to enable CD-ROM support as the diskette boots.

  5. Use MS-DOS fdisk on the Windows rescue diskette to create a primary DOS partition for Windows. When you're finished partitioning and back at the A:\> prompt, insert the Windows installation CD, change to the D: drive, and start the Windows Setup program:

    A:\> D:

D:\> setup

  6. Windows will overwrite the MBR, which is convenient for getting through the many reboots. When it's done, restore GRUB to the MBR. Boot to your GRUB floppy, and run the following comands:

    grub> root (hd0,0)

grub> setup (hd0)

  7. Remove the GRUB diskette and reboot, and your GRUB menu will reappear. Boot to Linux so you can edit menu.lst:

    title   Windows 98 on /dev/hda4

hide (hd0,0)

hide (hd0,1)

hide (hd0,2)

unhide (hd0,3)

rootnoverify(hd0,3)

makeactive

chainloader +1

12.11.3 Discussion

Let's look at the last three options more closely:

rootnoverify

Don't try to read or mount the partition.

makeactive

Set the bootable flag on the partition. Windows needs this.

chainloader +1

Points to the bootloader of operating systems that GRUB does not directly support, like Windows.

If you're thinking "Wow, this sounds like a lot of work," you are right. There is an easier way to dual-boot Windows 95/98/ME with Linux: install Windows 95/98/ME first, then add Linux. If you install Linux last, the installer will load GRUB in the MBR for you and will automatically create an entry for Windows in the GRUB menu.

You cannot run more than one 95/98/ME, unless you use GRUB's partition-hiding on every one and have enough primary partitions to give each one its own.

12.11.4 See Also

  • Microsoft Knowledge Base Article 217210: "How to Multiple Boot Windows XP, Windows 2000, Windows NT, Windows 95, Windows 98, Windows Me, and MS-DOS"

  • Recipe 9.16

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.12. Adding Windows NT/2000/XP to a Multiboot System

12.12.1 Problem

You have a single computer and you would like to dual-boot Windows NT/2000/XP and Linux, because you use applications on both platforms. Or you have a small test network and you want to install as many operating systems as you can in multiboot configurations, so that you can test different combinations of operating systems without using a lot of computers. You don't want to use an emulator like VMWare, which lets you run both at the same time without rebooting, because it's too expensive or your hardware is too feeble. And you hope it's not as much hassle as Windows 95/98/ME.

12.12.2 Solution

Fear not, Windows NT/2000/XP is a lot easier. The installer is more intelligent—it will let you choose which partition to use, or create a new one. You can even add it to a system with Linux already installed, as long as you have enough free space and an unused primary partition.

Make a hard copy of your partition table, and note what you have installed on each partition. Windows won't recognize any of your Linux partitions, it will only print the sizes of them, so having it written down will help you keep track.

You won't need a boot floppy; just install it from CD like you normally would. When the installation is completed, you'll need to restore GRUB to the MBR. Load your GRUB boot floppy, then do:

grub> root (hd0,0)

grub> setup (hd0)

grub> reboot

Remove the boot floppy, reboot, and your GRUB menu will reappear. Boot to Linux, and create a menu.lst entry for Windows:

title            WindowsXP on /dev/hda4

rootnoverify     (hd0,3)

makeactive

chainloader +1

It is not necessary to hide partitions from Windows NT/2000/XP.

12.12.3 Discussion

When you want to multiboot more than one version of Windows, start with the oldest, and install them in sequence from oldest to newest. You can install only one of Windows 95/98/ME, because it does not support multibooting. Windows NT/2000/XP all support multibooting.

You can use a single primary partition for all of your Windows versions, by dividing it into several logical partitions. Use the Windows NT/2000/XP installer to do the partitioning and formatting; don't use Linux fdisk.

12.12.4 See Also

  • Microsoft Knowledge Base Article 217210: "How to Multiple Boot Windows XP, Windows 2000, Windows NT, Windows 95, Windows 98, Windows Me, and MS-DOS"

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub

  • Recipe 12.13


Recipe 12.13. Restoring GRUB to the MBR with a Knoppix CD

12.13.1 Problem

When you installed Windows on your Linux/Windows dual-boot system, Windows overwrote the MBR (master boot record), so your GRUB menu was replaced with the Windows boot menu, and now you can't boot to Linux. The GRUB documentation tells how to restore GRUB to the MBR, but it seems to assume that you have a floppy drive. And you don't. How can you restore GRUB to the MBR when your system does not have a floppy drive?

12.13.2 Solution

Use a Knoppix CD. Boot it up, and open a command shell. su to root—there is no password—and run GRUB:

# grub

Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB  version 0.94  (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB lists possible

command completions. Anywhere else TAB lists the possible completions of a

device/filename. ]

grub>

Then run these three commands:

grub> root (hd0,0)

grub> setup (hd0)

grub> quit

When you reboot, your GRUB menu will reappear.

12.13.3 Discussion

Floppy drives are disappearing from all kinds of systems, especially laptops. Even the "desktop replacement" notebooks are omitting the floppy drive, in favor of combination CD-ROM/DVD-ROM/CD-R/RW drives.

12.13.4 See Also

  • Knoppix home page (http://www.knopper.net/)

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.14. Protecting System Files with a GRUB Password

12.14.1 Problem

You don't want your users to have access to the GRUB command shell, because they would be able to access all system files, regardless of permissions or access privileges.

12.14.2 Solution

Set a password in menu.lst to lock users out of the GRUB command shell.

First, from a Bash shell, use grub-md5-crypt to generate a hashed password:

# grub-md5-crypt

Password:

Retype password:

$1$RiAfJ0$QTuAlS/BGqlkYHQADZejs1

Now paste the encrypted password into menu.lst, in the global configuration part, before the boot stanzas:

password --md5 $1$RiAfJ0$QTuAlS/BGqlkYHQADZejs1

You can also use a plain text password, like this:

password bigsecretword

Obviously, this is less secure. If you use plain text, restrict file permissions to root only:

# chmod 600 menu.lst

When the system boots and the GRUB menu appears, hit p to enter the password and unlock the command shell. Users without the password will only be able to make selections from the boot menu; they will not have access to the GRUB command shell.

12.14.3 Discussion

File access permissions are attributes of the filesystem. GRUB operates outside of filesystems, so anyone with access to the GRUB command shell can read any file on the system.

If you lose your GRUB password, it's not the end of the world, because you can boot with a rescue disk and edit menu.lst—which illustrates the ancient Unix security dictum, "anyone with physical access to the box owns it."

12.14.4 See Also

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.15. Locking Out Users from Individual GRUB Menu Entries

12.15.1 Problem

Your GRUB menu contains several entries. You don't want any user to be able to boot any entry; you would like to lock out users from some of the entries.

12.15.2 Solution

First set up a GRUB password (Recipe Recipe 12.14), then use the lock command in menu.lst:

title    Libranet GNU/Linux, kernel 2.4.21, single user mode

lock

root     (hd0,0)

kernel   /boot/vmlinuz-2.4.21 root=/dev/hda1 ro single

GRUB reads menu.lst in order, so everything after lock is blocked from users who do not have the password. Don't lock out the title, or no one will be able to boot to this entry. Users without the password will only be able to boot to unlocked entries. If they try locked entries, they will get an error message:

Error 32: Must be authenticated

It's a good idea to use titles that tell users which ones are restricted:

Libranet GNU/Linux, kernel 2.4.21, single user mode, AUTHENTICATION REQUIRED

12.15.3 Discussion

Using a GRUB password and lock is useful on shared workstations—for example, in classrooms, training labs, and the workplace. However, anyone with physical access to the box can use a bootable rescue disk to gain unrestricted access. This can be foiled by disabling the rescue disks in the system BIOS, but don't forget how many different boot devices there are now: floppy disks, CDs, USB devices, SuperDisks, Jaz/Zip disks, Ethernet Wake-on-LAN, and probably some more I haven't thought of. Then set a BIOS password when you're done.

Still, a determined user can open the case and reset the BIOS password with a jumper on the motherboard. You could put a physical lock on the case, but even then a really determined person could haul the whole works out the door.

How far you need to go on boot security is obviously something you need to evaluate for your particular situation.

12.15.4 See Also

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)

  • info grub


Recipe 12.16. Creating a GRUB Splash Image

12.16.1 Problem

You're totally bored with the default GRUB splash screen that came with your distribution, and you'd like to use an image that you created.

12.16.2 Solution

You can create a GRUB splash image from any kind of image file. You must convert the image to a specific format and size, then make an entry in menu.lst that points to the image.

GRUB splash images must meet these specs:

  • xpm.gz file type

  • 640 480

  • 14 colors only

Start with an image of your own creation, at least 640 480, in any graphical file format. Use ImageMagick and gzip to do the rest. In this example, we'll convert a .jpg:

$ convert -depth 14 -resize 640x480 image.jpg newimage.xpm && gzip newimage.xpm

Move the new file, newimage.xpm.gz, to the /boot directory. Edit menu.lst, and add (or edit) an entry for the splash image:

# Display a splash screen

splashimage (hd0,5)/boot/newimage.xpm.gz

When you reboot, the GRUB menu will be adorned with your nice, new custom splash screen.

12.16.3 Discussion

ImageMagick does not create a backup of your original image, so you'll probably want to work from a copy.

ImageMagick is a suite of command-line utilities:

animate
composite
conjure
convert
display
identify
import
mogrify
montage

There is no "imagemagick" command. See imagemagick(1) for full details.

Try a Google search on "grub splashimage" to find all sorts of interesting online splash image galleries, as well as tips and tricks for creating them.

12.16.4 See Also

  • imagemagick(1), gzip(1), info grub

  • The GRUB Manual (http://www.gnu.org/software/grub/manual/grub.html)


Recipe 12.17. Booting Linux with LILO

12.17.1 Problem

You want to use LILO and need to know how to configure it to boot a Linux system.

12.17.2 Solution

Use liloconfig to generate a basic lilo.conf, then edit lilo.conf to add comments, titles, and any additional options you want.

Make sure you have the latest version of LILO, and as always, have a current backup of your data and bootable rescue disks at hand:

# /sbin/lilo -V

LILO version 22.4.1

After installing/upgrading, run liloconfig:

# liloconfig

It asks many questions, and gives many instructions. In this example, the root filesystem is on /dev/hda3. Say yes to these four questions:

Install a partition boot record to boot Linux from /dev/hda3?

Use LBA32 for addressing big disks using new BIOS features?

Install a master boot record on /dev/hda?

Make /dev/hda3 the active partition?

Run lilo to write the changes to the MBR:

# /sbin/lilo -v

Reboot to test it. When the system comes back up, you'll probably want to edit /etc/lilo.conf, because liloconfig does a rather barebones job on the boot stanzas. Here is a sample lilo.conf, first generated by liloconfig, then edited:

# Specifies the boot device

boot=/dev/hda3

# Location of the map file. This is a binary

# file generated by lilo, don't touch it

map=/boot/map

# Video resolution for the boot screen

vga=normal

# the LILO boot screen

message = /boot/boot_message.txt

# Show the LILO prompt for ten seconds

# before booting the default

prompt

timeout=100

# Access large disks beyond cylinder 1024

lba32

# Boot menu #

# default boot entry

default="Libranet-hd3"

# Stable 2.4 kernel

image=/boot/vmlinuz-2.4.21

label="Libranet-hd3"

root=/dev/hda3

read-only

# Test 2.6 kernel

image=/boot/bzImage-2.6.3

label="2.6-test-hd3"

root=/dev/hda3

read-only

There is a limit of 16 different images that can be configured in lilo.conf.

12.17.3 Discussion

This is what the original liloconfig-generated boot stanzas looked like:

# These images were automagically added. You may need to edit something.

image=/boot/vmlinuz

label="DEB 0"

read-only

image=/boot/vmlinuz-2.4.21

label="DEB 1"

read-only

image=/boot/bzImage-2.6.3

label="DEB 2"

read-only

liloconfig is good for setting up your first lilo.conf; after that, it is easier and better to edit it manually. Let's take a look at the four liloconfig questions you answered yes to:

Install a partition boot record to boot Linux from /dev/hda3?

This refers to where the /boot directory is located, and it must be a primary partition.

Use LBA32 for addressing big disks using new BIOS features?

Definitely say yes to this, unless you are using a system BIOS that does not support large-block addressing. Mainboards built in 1998 and after should support LBA32. This is the option that lets LILO boot partitions that are beyond the 1024-cylinder limit. The 1024-cylinder limit is a limitation of the x86 architecture; see "The Large Disk Howto" on tldp.org for details.

Install a master boot record on /dev/hda?

LILO stores the first-stage bootloader in the MBR; this bootloader then points to your other partition boot records.

Make /dev/hda3 the active partition?

This marks the partition as bootable, which Linux does not care about, but Windows does.

Any time you make changes to /etc/lilo.conf, you must re-run LILO to write the changes to the MBR:

# /sbin/lilo -v

The -v flag turns on verbosity, with levels ranging from 1 to 5:

# /sbin/lilo -v5

Another useful flag is -t, for test. Use this with -v to see what will happen before actually writing the changes to disk:

# /sbin/lilo -t -v2

12.17.4 See Also

  • lilo(8), lilo.conf(5)

  • /usr/doc/lilo, or /usr/share/doc/lilo

  • "The Large Disk Howto" on tldp.org


Recipe 12.18. Multibooting Linuxes with LILO

12.18.1 Problem

You would like to run several different Linuxes on a single PC, and you want LILO for the bootloader.

12.18.2 Solution

The first Linux installed is the "host" system. You need to preserve it to keep LILO working. Make sure that the root filesystem containing the /boot directory is on a primary partition, or LILO won't work.

Write down the location of the partition where the root filesystem of your next Linux is going to be installed. If you also know the exact name of the kernel, and the initrd image (if there is one), you're ahead of the game. While you're still in the host Linux, you can create a lilo.conf entry for Linux #2:

# Red Hat 9

image=/boot/vmlinuz-2.4.22-1

initrd=/boot/initrd-2.4.22-1.img

label="Red Hat 9"

root=/dev/hda6

read-only

Then write the changes to the MBR:

# /sbin/lilo -v

Now you can go ahead and install Linux #2, and because you already have a LILO boot menu entry for it, you can glide through however many reboots it takes to complete the installation.

When the installer gets to the bootloader installation, be sure to select "install to the first sector of the root partition," or however your installer words it. Do not overwrite the MBR.

If you don't know the exact kernel name and initrd image, you'll have to discover them from the host Linux. Go ahead and start the installation of Linux #2. When it comes to the first reboot, you'll end up back in the host Linux. Mount the new Linux #2 filesystem and read the /boot directory:

# mount /dev/hda6 /mnt/tmp

# cd /mnt/tmp

# ls boot

System.map  initrd-2.4.22-1.img  System.map-2.4.22-1  vmlinuz  vmlinuz-2.4.22-1

There's your kernel and initrd. Make your lilo.conf entry, re-run /sbin/lilo, and reboot. Now you can select your new Linux from the bootloader menu and finish the installation.

12.18.3 Discussion

Sometimes a ramdisk is required for the system to boot properly. If this is the case, there will be an initrd image. Note that not all distributions require an initrd image. If it's in /boot, it's needed, and it requires an entry in lilo.conf.

12.18.4 See Also

  • lilo(8), lilo.conf(5)

  • /usr/doc/lilo, or /usr/share/doc/lilo


Recipe 12.19. Multibooting Windows and Linux with LILO

12.19.1 Problem

You want to dual-boot Linux and Windows, or multiboot several versions of each.

12.19.2 Solution

The easy way is to first install all versions of Windows that you want to run on the system. Always install them in order, starting with the oldest. Save the fourth primary partition for Linux.

You may install only one of Windows 95/98/ME, because they do not support multibooting. Windows NT/2000/XP all support multibooting and will create entries for each installed Windows in the Windows bootloader.

Install Linux last. Make the fourth primary partition into an extended partition, then create a logical partition for Linux. During the Linux installation, install LILO to the MBR, and LILO will automatically create an entry for Windows. Here is an example of what lilo.conf will look like:

# Stable 2.4 kernel

image=/boot/vmlinuz-2.4.21

label="Libranet-hd3"

root=/dev/hda5

read-only

# Windows

other = /dev/hda1

  label = "Windowses"

  table = /dev/hda

There is only one entry for Windows, because LILO only needs to point to the Windows boot menu.

12.19.3 Discussion

When you have more than one Windows installed, the Windows bootloader will always stay with the first one. So if Windows 95 is installed on /dev/hda1, and Windows 2000 is installed on /dev/hda2, LILO still needs to point to /dev/hda1.

12.19.4 See Also

  • lilo(8), lilo.conf(5)

  • /usr/doc/lilo, or /usr/share/doc/lilo

  • Microsoft Knowledge Base Article 217210: "How to Multiple Boot Windows XP, Windows 2000, Windows NT, Windows 95, Windows 98, Windows Me, and MS-DOS"


Recipe 12.20. Creating a LILO Boot Diskette

12.20.1 Problem

You would like to create a LILO boot diskette, for easy recovery in case of trouble.

12.20.2 Solution

Use LILO's built-in boot diskette creator:

# cd /usr/lib/lilo

# make -f Makefile.floppy

Be sure to write-protect the diskette.

12.20.3 Discussion

The Linux world contains an amazing number and variety of bootable rescue disks. As long as you can boot the system, you can fix anything. Be sure to check the installation disks for your distribution, because they often come with rescue utilities customized for the distribution, including utilities for reinstalling the bootloader.

12.20.4 See Also

  • lilo(8), lilo.conf(5)

  • /usr/doc/lilo, or /usr/share/doc/lilo


Recipe 12.21. Password-Protecting LILO

12.21.1 Problem

You don't want your users messing around with your carefully crafted bootloader configuration. You also want to prevent them from exploiting LILO's ability to allow root access without a password, which can easily be done by entering:

linux single

or:

linux init=/bin/sh

at the LILO prompt.

12.21.2 Solution

First, restrict lilo.conf to root only:

# chmod 600 lilo.conf

Then password-protect LILO. In the global section of lilo.conf, make these entries:

password=""

restricted

Re-run LILO to write the changes:

# /sbin/lilo

It will ask you to enter a password. Give it your root password. It will then create a /etc/lilo.conf.shs file, containing a password hash accessible only to root.

Now when the system reboots, anyone trying to enter linux single or linux init=/bin/sh at the LILO prompt will be asked for the password.

12.21.3 Discussion

For additional boot-time security, disable all external boot devices in the system BIOS, and use a BIOS password. This is not perfect—after all, as we showed in Recipe 12.14 and Section 12.15, "Anyone with physical access to a box owns it." But it's good enough to keep ordinary users from mucking up the works.

12.21.4 See Also

  • lilo(8), lilo.conf(5)

  • /usr/doc/lilo, or /usr/share/doc/lilo


Recipe 12.22. Backing Up the MBR

12.22.1 Problem

You would like to have a backup copy of your master boot record. And what good is that backup if you don't know how to restore it?

12.22.2 Solution

You can back up the MBR to a floppy disk. Mount the disk first, using the mountpoint appropriate for your system, then use the dd command:

# dd if=/dev/hda of=/floppy/mbr bs=512 count=1

Restore it this way:

# dd if=/floppy/mbr of=/dev/hda bs=512 count=1

The filename of your backup can be anything you like: for example, /mbr-server01 labels it so you know which computer it belongs to. You can store many MBRs on a single floppy disk:

# ls /floppy

lost+found  mbr-server01  mbr-workstation04  mbr-host15

If you need to format a floppy disk first, do this:

$ mke2fs /dev/fd0

This creates a nice Linux-formatted disk, using the Ext2 filesystem.

12.22.3 Discussion

The dd command does a literal, byte-by-byte copy. It doesn't need to understand filesystems, so it can be used to copy block devices, like /dev/hda.

If your system does not have a floppy drive, you can restore a borked MBR with a Knoppix disk, by reinstalling GRUB (Recipe Recipe 12.13).

12.22.4 See Also

  • dd(1), mke2fs(8)


Chapter 13. System Rescue and Recovery with Knoppix

    Section 13.1. Introduction

    Recipe 13.2. Booting Knoppix

    Recipe 13.3. Creating a Knoppix Boot Diskette

    Recipe 13.4. Saving Your Knoppix Configuration on a USB Memory Stick

    Recipe 13.5. Creating a Persistent, Encrypted Knoppix Home Directory

    Recipe 13.6. Copying Files to Another Linux PC

    Recipe 13.7. Copying Files to a Samba Share

    Recipe 13.8. Copying Files to a CD-R/RW

    Recipe 13.9. Editing Configuration Files from Knoppix

    Recipe 13.10. Installing Software from Knoppix

    Recipe 13.11. Repairing a Lost Root Password

    Recipe 13.12. Installing Knoppix to a Hard Disk

    Recipe 13.13. Virus-Scanning Windows PCs with Knoppix


13.1. Introduction

Facing a nonbooting system is one of life's less pleasant sensations. Knoppix, a complete Debian-based Linux distribution on a live, bootable CD, is a first-rate recovery disk. You get over 2 GB of Linux utilities and drivers, compressed onto a 700-MB CD. It has great hardware detection, supports all the major filesystems, automatically finds your existing partitions, creates mountpoints, and automatically finds your DHCP server. If you need to configure networking manually, it has a nice utility called netcardconfig. Knoppix can't be beat for ease of use. Just pop it in, boot it up, and everything works.

Knoppix can be downloaded as a 700-MB .iso, or you can purchase commercially produced CDs, which is nice for folks with slow or expensive Internet service.

A entire creative community has grown up around Knoppix; on Knoppix.net you'll find a large number of specialty projects inspired by Knoppix, and howtos for creating your own custom bootable live CD.


Recipe 13.2. Booting Knoppix

13.2.1 Problem

You want to customize Knoppix's boot process. First, you need to find out what boot-time options Knoppix has.

13.2.2 Solution

To see all boot options, hit F2 at the prompt.

You can just pop Knoppix into the drive and let it boot itself, but there are a large number of boot-time options at your disposal. The default keyboard layout is German, so you might want to change it to your own locale:

knoppix lang=uk

The default desktop is KDE. You can choose a different one:

knoppix desktop=icewm

Or boot to a console, and not run X:

knoppix 2

You can speed up the boot process a bit by disabling hardware detection for things you don't have:

knoppix nopcmcia noscsi

To boot with minimal hardware detection, use:

failsafe

You can combine as many options as you need:

knoppix lang=uk desktop=icewm nopcmcia noscsi

13.2.3 Discussion

You'll need about 20 MB of RAM to boot console Knoppix, and a minimum of 96 MB to run an X session satisfactorily. To run KDE, you'd better have 256 MB of RAM. Knoppix will find and use the swap partition on the hard drive, if there is one.

The fun thing about Knoppix is that if you don't like how it booted, or you want to try something different, you don't have to bother with a graceful shutdown—just pull the plug and start over.

13.2.3.1 Knoppix glitches

Running programs from a CD can cause some odd troubles, especially on notebooks. It is common for power management to mess up a Knoppix session: when you wake up the machine, Knoppix doesn't respond to commands any more. Try disabling power management, or simply hit the power switch and start over.

Sometimes Knoppix gets stuck during boot-up and hangs partway into KDE (or any X session) startup. Switch to the first virtual console (Ctrl-Alt-F1) to see the live system messages; this should tell you where the problem is. For example, Knoppix might hang on SCSI detection. In this case, reboot and disable SCSI detection:

knoppix noscsi

13.2.4 See Also

  • Documentation on the Knoppix CD

  • Knoppix.net (http://www.knoppix.net/)—the best Knoppix resource, with all kinds of tips and howtos

  • Knopper.net (http://www.knopper.net/)—the official home page of Klaus Knopper, the creator of Knoppix


Recipe 13.3. Creating a Knoppix Boot Diskette

13.3.1 Problem

Your system will not boot from a CD, but you would still like to use Knoppix. How do you get a Knoppix boot diskette?

13.3.2 Solution

Knoppix comes with a boot image all ready to copy to a diskette. Load and mount your Knoppix CD on any Linux system, load a new, blank diskette, and run:

# dd if=/cdrom/KNOPPIX/boot.img  of=/dev/fd0 bs=1440k

You can also create the boot diskette in Windows. Open a DOS window, then open the KNOPPIX directory on the CD:

c:> d:

d:> cd \KNOPPIX

Then create the diskette:

d:> mkfloppy.bat

Boot the system with the diskette, stick in the Knoppix CD when it tells you to, and you're in business.

13.3.3 Discussion

Including a DOS batch file to make a Knoppix boot diskette is a nice touch—another handy tool for your rescue kit.

13.3.4 See Also

  • Documentation on the Knoppix CD

  • Knoppix.net (http://www.knoppix.net/)

  • Klaus Knopper's official homepage (http://www.knopper.net/)


Recipe 13.4. Saving Your Knoppix Configuration on a USB Memory Stick

13.4.1 Problem

You would like to save your Knoppix configuration, such as network settings and desktop configuration, so you don't have to start over every time.

13.4.2 Solution

This is a perfect job for one of those little USB memory sticks. Boot Knoppix with the memory stick inserted. On the Knoppix menu, look for Configuration [image] Save KNOPPIX Configuration. Select /dev/sda1 as the device to save it to.

Now when you boot Knoppix, make sure your USB stick is inserted, and use the following boot command:

knoppix myconfig=/dev/sda1

You may also make Knoppix autodetect it:

knoppix myconfig=scan

13.4.3 Discussion

256- and 512-MB USB pen drives are getting dirt cheap. Carry one of these and a Knoppix disk, and you can make yourself at home almost anywhere.

13.4.4 See Also

  • Documentation on the Knoppix CD

  • Knoppix.net (http://www.knoppix.net/)

  • Klaus Knopper's official homepage (http://www.knopper.net/)


Recipe 13.5. Creating a Persistent, Encrypted Knoppix Home Directory

13.5.1 Problem

You really like running Knoppix from the CD, because it cannot be infested by viruses, Trojans, or rootkits, and you would like to use it in place of a hard drive installation. But there's a problem: where do you store personal data, email, and other things that you'd like to keep with you? You want a secure home directory in which to store email and other data files.

13.5.2 Solution

Run Knoppix [image] Configure [image] Create to make a persistent Knoppix home directory. You'll have the option of creating /home on the hard drive, or on removeable media such as USB memory sticks, compact flash cards, or Zip disks. This creates a file called knoppix.img.

Say yes when it asks you if you want to create an AES-encrypted directory. The directory will be encrypted with a 256-bit key. You have to come up with a passphrase of at least 20 characters. Make it a sentence that you can remember, like "thisismylongpassword," because you'll need it every time you boot.

To boot using your nice, new encrypted /home, insert your removable media and type:

boot: knoppix home=/dev/sda1

If you also saved your Knoppix configuration, you can specify both:

boot: knoppix home=/dev/sda1  myconfig=/dev/sda1

Your new /home directory will appear in Knoppix as /home/knoppix and will be automatically mounted at boot. If you store your encrypted /home in an existing Linux partition on the hard drive, the whole partition will be mounted.

13.5.3 Discussion

The default size of /home/knoppix is 30 MB. Make it as large as you need.

13.5.4 See Also

  • Documentation on the Knoppix CD

  • Knoppix.net (http://www.knoppix.net/)

  • Klaus Knopper's official homepage (http://www.knopper.net/)


Recipe 13.6. Copying Files to Another Linux PC

13.6.1 Problem

You want to copy files from a troubled PC to another machine on your network. This is a good way to do an emergency backup of critical files when a PC appears to be dying or behaving strangely.

13.6.2 Solution

Boot up Knoppix. The troubled PC must then connect to the LAN. If you have a DHCP server, Knoppix will connect automatically.

If you need to configure a static IP address, run netcardconfig from the console, or use Knoppix [image] Network/Internet.

You'll need an SSH server set up on the receiving machine. (See the "Discussion" section of this recipe if you need to set this up.)

First, mount the filesystem containing the files you want to copy. Knoppix creates /etc/fstab, puts all the mountpoints under /mnt, and creates desktop icons for all filesystems. The easy way to mount the filesystem is to click on the desktop icon. Or you can peek into /etc/fstab and use the command line. First change to root. There is no password:

knoppix@tty0[knoppix]$ su

root@ttyp0[knoppix]# mount /mnt/hda5

Then run the scp (secure copy) command:

# scp -rp /mnt/hda5/home/kmartin 192.168.1.5:/home/kmartin/tmp

It will complain:

Could not create directory '/home/kmartin/.ssh'.

The authenticity of host '192.168.1.5 (192.168.1.5)' can't be established.

RSA key fingerprint is a2:c6:77:2e:63:b2:ed:90:b2:9b:bc:e7:d4:22:ba

Are you sure you want to continue connecting?" (yes/no)?

Say yes. Then it will ask you for root's password on the SSH server. Enter the password, and the files will be copied.

You can also do this as an ordinary user, for the user's own account. At the Knoppix root prompt, create a new user:

root@ttyp0[knoppix]# useradd kmartin

Don't bother with a password—you only need the user's password on the SSH server. Now kmartin can move files into her own account on the SSH server. Only root can copy files into other users' accounts.

13.6.3 Discussion

The -r option for scp copies directories recursively. -p preserves permissions.

This is how to set up a quick-and-dirty SSH server. Install OpenSSH on the Linux machine to which you want to copy files. If it's already installed, upgrade to the latest version to get all the security fixes. Then start it up:

# /etc/init.d/ssh start

and it is ready to receive files. If you intend to use SSH routinely for remote administration, don't stop here—you'll need to take a few more steps to ensure a safe connection. See Chapter 17 for more recipes on running SSH.

Because you are running Knoppix in memory, there is no way to save SSH keys or hosts, so it will emit the same complaints every time. If you plan to make a habit of copying files via scp, see Recipe Recipe 13.5.

13.6.4 See Also

  • scp(1), ssh(1)

  • Recipe 13.5


Recipe 13.7. Copying Files to a Samba Share

13.7.1 Problem

You would like to copy files from a Linux PC to a Windows PC on your LAN using Knoppix.

13.7.2 Solution

You need to have Samba (Chapter 23) already configured and working on your LAN. Open a root shell:

knoppix@ttyp0[knoppix]$ su

root@ttyp0[knoppix]#

Create a local directory on which to mount the remote share, then mount the remote share:

root@ttyp0[knoppix]# mkdir /mnt/samba

root@ttyp0[knoppix]# mount -t smbfs -o \ uid=knoppix,workgroup=local,username=helix,password=tehsecuar \

//windbag/lan_share/mnt/samba

Substitute your own workgroup, username, password, hostname, and shared folder name. On Windows 95/98/ME, if you did not configure file sharing to require a password, use "guest" as the username and leave the password field blank.

Now you can open a couple of Konqueror windows for copying files or you can use the cp command:

root@ttyp0[knoppix]# cp -av /home/helix  /mnt/samba

13.7.3 Discussion

If you prefer a graphical interface, there are a couple of options. If you know the hostname and share name, enter them in Konqueror's Location bar:

smb://HOST/SHARE

Knoppix also includes LinNeighborhood for network browsing, under Internet [image] LinNeighborhood.

13.7.4 See Also

  • Chapter 9 of Using Samba, by Jay Ts, Robert Eckstein, and David Collier-Brown (O'Reilly)

  • The Official Samba-3 Howto and Reference Guide for Samba 3.x (http://samba.org/)

  • Chapter 23


Recipe 13.8. Copying Files to a CD-R/RW

13.8.1 Problem

You have a CD writer on your PC, and you would like to burn files to a CD-R/RW.

13.8.2 Solution

The absolute easiest way is to use K3b. Start up Knoppix, and open System [image] K3b Setup. K3b will automatically find your CD drives; verify this in step 3 of the setup wizard. In step 6, add any non-root users you want to use K3b. (Remember, you need to create the users first.)

When you're finished with the setup wizard, close it, and open System [image] K3b. Click File [image] New Project. Simply drag and drop the files you want to copy, hit the Burn button, and you're done.

13.8.3 Discussion

K3b is a great CD/DVD-writing interface, one of the best on any platform. It is logically organized, and it hides all the grotty details of CD/DVD writing, so you don't have to navigate bales of windows and menus to burn a disc, or bother with odd terminology like "Joliet," "Rock Ridge," or "El Torito." While it is good to know the inner workings of a program, it is also nice when the computer does the work.

13.8.4 See Also

  • Chapter 11

  • The K3b home page (http://www.k3b.org/)


Recipe 13.9. Editing Configuration Files from Knoppix

13.9.1 Problem

Someone with more confidence than knowledge (maybe even you) "fixed" something in a configuration file and now the system won't boot. You need to fix it. But how do you edit a file on a machine that won't boot?

13.9.2 Solution

This is a perfect job for Knoppix. You can open and edit any file on a PC from Knoppix.

Boot up your Knoppix disk to KDE. Right-click the icon on the desktop for the filesystem you want to use, left-click "Mount," then left-click "Change read/write mode."

Open a root shell, then navigate to the file you want to edit and open it with the editor of your choice:

knoppix@ttyp0[knoppix]$ su

root@ttyp0[knoppix]# cd /mnt/hda3/etc

root@ttyp0[etc]# kate inittab &

Now you can edit the file, just as you normally would.

It's easy to become confused over whether you are in Knoppix or your PC's filesystem. Check with pwd:

root@ttyp0[etc]# pwd

/mnt/hda3/etc

Remember that the filesystems on your PC's hard drives are all mounted under /mnt in Knoppix.

13.9.3 Discussion

Knoppix comes with a variety of window managers: larswm, IceWM, XFce, Windowmaker, Fluxbox, and TWM. But only KDE comes with the Knoppix menu and desktop icons for all of your partitions.

Just like with any Linux, you can also do everything from the console. To mount a filesystem as readable/writable, use:

root@ttyp0[knoppix]# mount -o rw /mnt/hda3

To open a file for editing, use:

root@ttyp0[knoppix]# vim /mnt/hda3/etc/inittab

Knoppix autodetects your filesystems and partitions and creates an /etc/fstab file, so you can look in there to find mountpoints.

13.9.4 See Also

  • mount(8)

  • Recipe 9.11


Recipe 13.10. Installing Software from Knoppix

13.10.1 Problem

You need to run apt-get, apt-rpm, up2date, or some other updater utility that needs to be run from inside its own root filesystem.

13.10.2 Solution

In Knoppix, you can chroot to the root filesystem on the hard drive. Open a Knoppix root shell, then do:

root@ttyp0[knoppix]# mount -o rw /mnt/hda6

root@ttyp0[knoppix]# chroot /mnt/hda6

root@Knoppix:/

This gives you a root shell in the filesystem on the hard drive, as though you were booted directly into it. You are no longer in the /mnt directory in Knoppix. Now you can run any command, as though the system had booted normally. That includes commands for updating software like apt-get.

13.10.3 Discussion

From an ordinary Knoppix session it's easy to keep track of your whereabouts, as all the filesystems on the hard drive are mounted under /mnt. But in chroot, you won't see Knoppix files. If you get confused, try poking around and reading filenames—you should recognize files that belong on the hard drive, and not to Knoppix.

13.10.4 See Also

  • chroot(8)


Recipe 13.11. Repairing a Lost Root Password

13.11.1 Problem

Oops, you lost your root password.

13.11.2 Solution

No problem whatsoever. Fire up Knoppix and open a root shell. Mount the filesystem containing /etc/shadow, and make it writable (see Recipe Recipe 9.10). Open /etc/shadow in your favorite editor, and find root's entry:

root:$1$7nMNZYci$E.U6ftxnAZU0rk29qvYpk0:12460:0:99999:7:::

Delete the password hash, which is between the first set of colons:

root::12460:0:99999:7:::

Now when you start up the system and log in as root, you will not be asked for a password.

13.11.3 Discussion

Don't forget to set a new root password.

This is yet another demonstration that "anyone with physical access to the box owns it." See Chapter 12 for tips on securing the boot process.

13.11.4 See Also

  • shadow(5)

  • Recipes 12.14 (Recipe 12.14), 12.15 (Recipe 12.15), and 12.21 (Section 12.21) for how to set passwords on LILO and GRUB


Recipe 13.12. Installing Knoppix to a Hard Disk

13.12.1 Problem

You really like using Knoppix, and you want to install it to a hard drive, just like a "real" Linux.

13.12.2 Solution

Fire up Knoppix and open a root shell. Type knoppix-installer. Follow the menus and prompts, and when you're done you'll have a thoroughly modern Debian system.

13.12.3 Discussion

This operates pretty much like any Linux installation. Check the release notes for your version of Knoppix, because up to Version 3.2 the installer script was knx-hdinstall. In 3.3 it changed to knoppix-installer. It could change again—the Linux world waits for no one.

13.12.4 See Also

  • The Knoppix Wiki on http://www.knoppix.net/docs/—all the latest and greatest tips and howtos are here


Recipe 13.13. Virus-Scanning Windows PCs with Knoppix

13.13.1 Problem

You want a quick, inexpensive method for running virus scans on Windows, indepent of the operating system. You know that the installation disks for commercial antivirus productes, like Symantec and McAfee, can be used to run a preinstallation virus scan, but the virus definitions are going to be months out of date.

13.13.2 Solution

Get yourself a copy of Knoppix 3.4 or newer. You'll need Internet connectivity to download fresh virus definitions. You can either run a scan-only or a scan-and-disinfect on Windows partitions with FAT16/32. On NTFS filesystems, you can only run a scan because write support for NTFS is still unreliable in Linux.

Boot up Knoppix. Go to KNOPPIX [image] Utilities [image] Install software. This brings up a menu of available packages to install; check f-prot.

After f-prot is installed, select KNOPPIX [image] Extra Software [image] f-prot. This brings up the f-prot menu; the first thing you want to do is 4, "Online Update."

After the new virus defintions are downloaded, select partitions or directories to scan. Knoppix automatically mounts all partitions on your system, so you can easily select the ones you want. To run a scan-only, hit the "scan" button—and go find something to do, because it will take awhile. When it's finished, you'll see a report showing the results of the scan.

To scan and disinfect, run f-prot from the command line instead of the graphical menu. First, make sure the partition is mounted read/write; simply right-click on the icon for the drive, which is on your Knoppix desktop, and left-click Actions [image] Change read/write mode.

Next, open a command shell and run this command, naming the partition you want scanned:

$ f-prot -disinf -list /mnt/hda1

The -list option shows the scan's progress and the -disinf option will disinfect the system. That's all there is to it.

13.13.3 Discussion

This approach has a number of advantages:

  • You are working from a guaranteed clean operating system—and since it's on a nonwritable disk, it's impossible to compromise.

  • Because you must power down the PC to boot Knoppix, any memory-resident nasties are evicted.

  • It's free—so you can burn masses of disks and go on a virus-scanning spree.

f-prot has a Windows edition for $29, and liberal licensing terms for home users; it covers all your home computers. There is also a free Linux workstation edition; sure, we can mock and abuse Microsoft all we want, but all it would take is one evil genius writing a lethal Linux exploit and hordes of happy script kiddies distributing it all over the planet in a heartbeat, and we wouldn't be laughing anymore.

13.13.4 See Also

  • Knoppix net, for bales of howtos (http://www.knoppix.net)

  • f-prot home page (http://www.f-prot.com)


Chapter 14. Printing with CUPS

    Section 14.1. Introduction

    Recipe 14.2. Installing a Printer on a Standalone Linux PC

    Recipe 14.3. Serving Linux Clients

    Recipe 14.4. Sharing a Printer Without Using Name Resolution

    Recipe 14.5. Serving Windows Clients Without Samba

    Recipe 14.6. Sharing Printers on a Mixed LAN with Samba

    Recipe 14.7. Building a Dedicated CUPS Printer Server

    Recipe 14.8. Distributed Printing with Classes

    Recipe 14.9. Restricting Users from Printers and Classes

    Recipe 14.10. Troubleshooting


14.1. Introduction

The Common Unix Printing System (CUPS) is a modern printing subsystem for Linux and Unix that replaces the hoary old Unix line-printer protocols. It runs on Unix, Linux, Mac OS, and Mac OS X, and it serves clients on nearly any platform, including Windows.

CUPS is thoroughly modern, supporting laser and inkjet printers as well as dot matrix and other legacy printers.

There are two versions of CUPS: the free GPL version, which is the default on most of the major Linux distributions, and a commercial edition. The commercial version comes with support, a larger selection of drivers, and nicer management interfaces.

Printer drivers in CUPS consist of one or more filters specific to a printer, which are packaged in PPD (PostScript Printer Description) files. All printers in CUPS—even non-PostScript printers—need a PPD. The PPDs contain descriptions about the printers, specific printer commands, and filters.

Filters are the heart and soul of CUPS. Filters translate print jobs to formats the printer can understand, such as PDF, HP-PCL, raster, and image files, and they pass in commands for things such as page selection and ordering. PPDs are text files—take a look in /usr/share/cups/model/ to see what they look like. Installed printers have PPDs in /etc/cups/ppd.

14.1.1 Finding Drivers

Included in CUPS are generic PPDs for 9-pin and 24-pin Epson dot matrix printers, Epson Stylus and Color Stylus Photo printers, LaserJet and HP DeskJet printers, and even Dymo label printers. These will work for hundreds of printers, but they do not support all printer functions, such as duplexing, inkjet head-cleaning and alignment, or tray selection.

There are four good sources for printer drivers, if your printer manufacturer does not supply Linux drivers:

  • Foomatic, at http://linuxprinting.org

  • Gimp-Print, at http://gimp-print.sourceforge.net

  • The commercial edition of CUPS, at http://www.easysw.com/cups/

  • Windows PostScript drivers

Foomatic is a free printer-driver project that integrates with all the common Linux printing systems (CUPS, LPRng, LPD, GNUlpr, PPR, PDQ, CPS).

Gimp-Print originally started out as a Gimp plug-in, but it has expanded to support all Linux printing. Gimp-Print drivers are very high quality; if there is one for your color printer, it is probably the best choice.

Be sure to check the hardware compatibility list for your Linux distribution, or the printer database on linuxprinting.org, before purchasing a printer.

Gimp-Print and Foomatic are available as packages that you can install on your system, if they are not already included in your distribution. This ensures that you get a complete selection of drivers, plus all the required subsystems that make everything work together correctly. The RPMs are complete; Debian splits them into several smaller packages. Visit the Debian package search page to find them (http://packages.debian.org).

You can use the Windows drivers for PostScript printers on Linux. Look for PPD files in your Windows system directory. Note that only PPDs for real PostScript printers will work. Many printers are only PostScript-compatible; your printer documentation will tell you.

You can test PPDs at http://www.cups.org/testppd.php. This site looks for syntax errors in PPD files. The errors it finds are usually things you can fix, such as a typo or incorrect command.

14.1.2 Networking Printers

There are four ways to share printers on a network:

  • Share printers that are attached to users' PCs.

  • Build a dedicated Linux printer server.

  • Buy network-direct printers, such as the HP JetDirect series.

  • Buy hardware printer servers, such as the Linksys EPSX3, that can connect any printer directly to your LAN.

This chapter covers the first two options. The last two are too diverse, and there are too many choices to try to cover here. Here are some things to keep in mind when you're deciding which one to use:

  • Using a Linux box as a printer server gives you maximum flexibility and customization options.

  • Network-direct printers, with built-in networking hardware, tend to be expensive and require proprietary network hardware.

  • Network-direct printers are usually built for heavy-duty use.

  • A hardware printer server lets you network any printers you want.

Using network-direct printers and hardware printer servers means less power consumption and smaller space requirements than using a PC as a dedicated printer server. You must shop carefully for Linux support, though, because some of them come with Windows-only management software. Anything that is managed via a web interface should work fine.


Recipe 14.2. Installing a Printer on a Standalone Linux PC

14.2.1 Problem

You need to connect a printer to your Linux PC.

14.2.2 Solution

If you have a USB printer, it must be connected and powered up at boot time.

First, make sure that the CUPS daemon is running:

$ lpstat -t

scheduler is running

...

If it is not running, it says:

$ lpstat -t

lpstat: Unable to connect to server: Connection refused

If that is the case, start it with its init script:

# /etc/init.d/cupsys start

On Red Hat and Fedora, use:

# /sbin/service cups restart

The easiest way to install a new printer is with the CUPS web interface. Type the CUPS URL in any browser:

http://localhost:631

You'll need the root password. Click the Printers tab, then click "Add printer," which opens the Admin menu. There are three values to enter here:

Name: hp6L

Location: room-202

Description: bw-laser

Choose the name carefully—CUPS needs this name, and changing it will cause problems. Your printer name will be used on the next few configuration pages. I've entered "hp61" for my Hewlett-Packard LaserJet6L printer. The Location and Description are optional.

On the next page, define the "Device for <printername>." This means the physical connection: parallel port, USB, SCSI, serial port, or network. Select your deviceURI from the drop-down menu. In this example, that is "Parallel port #1 Hewlett-Packard HP LaserJet6L."

On the "Model/Driver for <printername>" menu, scroll to the model number of your printer, and select a driver from the list.

Now it should say "Printer <printername> has been added successfully." Click on the printer name to go the printer's control page, and print a test page. Your CUPS page should look like Figure 14-1.

Figure 14-1. CUPS page

14.2.3 Discussion

If you prefer the command line, this long command does the same thing as the above example:

# lpadmin -p hp6L -L room-202 -D bw-laser -E -v parallel:/dev/lp0 \

-m HP-LaserJet_6-hpijs.ppd

Here are some definitions:

lpadmin -p

Set the printer name.

-L

Set the printer location.

-D

Describe the printer.

-E

Enable the printer and make it ready to receive jobs.

-v

Set the device URI.

-m

Specify which driver (PPD file) to use. Note that the filepath is hardcoded into CUPS; if you try to use a filepath like /usr/share/cups/model/laserjet.ppd, it will fail, saying "lpadmin: add-printer (set model) failed: server-error-internal-error." Just use the PPD name, and make sure the PPD file you want is in /usr/share/cups/model/.

If you have Gimp-Print and Foomatic installed (if you don't you probably should) you'll find additional PPDs in /usr/share/cups/model/gimp-print and /usr/share/cups/model/foomatic. They are compressed:

HP-LaserJet_6-hpijs.ppd.gz

You'll need to uncompress the file and move it to the /usr/share/cups/model directory:

# gunzip HP-LaserJet_6-hpijs.ppd.gz && mv HP-LaserJet_6-hpijs.ppd  \

/usr/share/cups/model/

It is not necessary to uncompress and move PPD files when you install printers using the CUPS web interface.

14.2.3.1 Generic drivers

These are the generic drivers that come with the free version of CUPS:

$ ls /usr/share/cups/model

epson24.ppd   laserjet.ppd  pxlcolor.ppd  stphoto.ppd   deskjet.ppd   epson9.ppd

okidat24.ppd  pxlmono.ppd   stphoto2.ppd   deskjet2.ppd   okidata9.ppd  stcolor.ppd

dymo.ppd   pcl-6.ppd   stcolor2.ppd

If you can't find a driver specific to your printer, one of these should work. (You did check your distribution's hardware compatibility list, or the database on linuxprinting.org, before purchasing the printer, right?)

14.2.4 See Also

  • This chapter's "Introduction," for more information on printer drivers

  • CUPS Software Administrators Manual (http://localhost:631/documentation.html)


Recipe 14.3. Serving Linux Clients

14.3.1 Problem

You want to share the printers attached to your Linux PCs with other Linux clients on your LAN.

14.3.2 Solution

First, make sure CUPS is installed on all the computers with attached printers. These PCs must have static IP addresses and you'll need name resolution in place and working (/etc/hosts or a local DNS server).

Next, on the PCs with printers attached, edit /etc/cupsd.conf. This sample cupsd.conf shows how to make the printers accessible to the local subnet. You can use this as it's shown, using your own network values:

LogLevel info

Port 631

<Location />

Order Deny,Allow

Deny From All

Allow From 127.0.0.1

Allow From 192.168.1.*

</Location>

BrowseAddress 192.168.1.255

Add this entry to restrict administrative access to the server only and not allow it from client machines:

<Location /admin>

AuthType Basic

AuthClass System

Order Deny,Allow

Deny From All

Allow From 127.0.0.1

</Location>

Restart cupsd after editing cupsd.conf:

# /etc/init.d/cupsys restart

On Red Hat and Fedora, use:

# /sbin/service cups restart

Print a test page. If you get the infamous "client-error-not-found" message, stop and restart the printer from the CUPS web interface.

CUPS printers will now automatically broadcast themselves on the network. Make sure that TCP port 631 is not blocked on either the server or the client machines.

Open the CUPS web interface (http://localhost:631/documentation.html) on any of the Linux client PCs, and all CUPS printers should automatically appear on the Printers page. You can now print a test page and print from applications.

14.3.3 Discussion

If there is a sample cupsd.conf on your system, don't let its size scare you. Chances are you'll never need most of the directives; just hang on to it as a reference, and create your own cupsd.conf from scratch.

All of the directives in cupsd.conf are listed and defined in the CUPS Software Administrators Manual, at http://localhost:631/documentation.html.

LogLevel info

There are 10 levels of logging. info is the default; it logs errors and printer activity in /var/log/cups/error_log.

Port 631

This is reserved for IPP (Internet Printing Protocol).

<Location /></Location>

The Location directive specifies access control and authentication options. Note the positioning of the slashes—make sure you get them right, or things won't work.

Order Deny,AllowDeny From AllAllow From 127.0.0.1Allow From 192.168.1.*

Your standard "deny all, allow as needed" scheme, limiting inbound connections to the local machine and the local subnet.

14.3.4 See Also

  • The "Printing System Management" section in the CUPS Software Administrators Manual (http://localhost:631/documentation.html)


Recipe 14.4. Sharing a Printer Without Using Name Resolution

14.4.1 Problem

You haven't bothered to create /hosts files, or set up a local DNS server on your LAN, because you have no need for name resolution. The PCs on your LAN sit comfortably behind a NAT firewall, for sharing an Internet connection, and that's all they need. So how do you share a printer?

14.4.2 Solution

Give your printer server a static IP address. Add a ServerName directive to /etc/cupsd.conf on the server, using its own IP address:

ServerName 192.168.1.5

Restart cupsd. On Debian, use:

# /etc/init.d/cupsys restart

On Red Hat and Fedora, use:

# /sbin/service cups restart

There is nothing to do on the client PCs, except wait a few seconds for CUPS to broadcast the printer. If you get the infamous "client-error-not-found" message, stop and restart the printer.

14.4.3 Discussion

By default, CUPS uses the hostname as the ServerName. If you are not using any kind of name resolution, your client PCs will not see any CUPS printers. Specifying the IP address as the ServerName fixes that. A side effect is that you may not be able to print a test page from the server; instead, you'll get the screen shown in Figure 14-2.

Figure 14-2. No CUPS page

However, you'll still be able to print from applications on the server. Client PCs won't notice anything odd.

If you don't need to set up a network filesystem such as NFS or Samba, or use DNS; it's perfectly okay, even if the other geeks laugh at you. A primary rule of security is "don't run what you don't need."

14.4.4 See Also

  • CUPS Software Administrators Manual (http://localhost:631/documentation.html)


Recipe 14.5. Serving Windows Clients Without Samba

14.5.1 Problem

You would like to connect your Windows clients to a Linux printer server, but you really don't want to set up Samba just to share printers.

14.5.2 Solution

CUPS can handle the job without Samba. You need your Windows installation CD or printer driver disk, and Windows clients need to have Internet Printing Services installed. This is the same as IPP (Internet Printing Protocol) on Linux.

Windows 95/98 users can get the download at http://www.microsoft.com/windows98/downloads/. Look for "Internet Print Services." The file you want is wpnpins.exe.

Windows ME supplies the Internet Printing Services software in the Add-on folder on the installation CD.

On Windows NT, go to Control Panel [image] Network [image] Services tab [image] Add Microsoft TCP/IP Printing.

On Windows2000/XP, install TCP/IP Print Services from Network and Dial-up Connections [image] Advanced Menu [image] Optional Networking Components [image] Other Network File and Print Services.

Next, fire up the Add Printer wizard. Select Network Printer, then add the printer URI. This consists of the IP address or server name, port number, and /printers/<printername>. Be sure to use the exact name you gave the printer, like this:

http://192.168.1.5:631/printers/hp6L

There isn't a /printers directory anywhere; that's just a convention used by CUPS.

When Windows first connects to the CUPS server, it will install its own local printer drivers and print its own test page, rather than the CUPS test page. So you may need a Windows CD or the driver installation disk.

14.5.3 Discussion

If you have name resolution working on your LAN, you can use the server name instead of the IP address:

http://windbag:631/printers/hp6L

14.5.4 See Also

  • This chapter's "Introduction," for more information on printer drivers


Recipe 14.6. Sharing Printers on a Mixed LAN with Samba

14.6.1 Problem

Your LAN has both Linux and Windows printers, and you want all of them to be accessible by both Linux and Windows clients.

14.6.2 Solution

You'll need both Samba and CUPS to make this work. See Recipe 23.22 and Recipe Section 23.23.

14.6.3 See Also

  • The Official Samba-3 Howto and Reference Guide (http://samba.org)


Recipe 14.7. Building a Dedicated CUPS Printer Server

14.7.1 Problem

Sharing printers connected to PCs works fine, but it places an extra load on the PCs, and the PCs must be running for printers to be accessible. And sometimes it means running all over to fix things. You want to set up a dedicated printer server, for easier centralized printer management.

14.7.2 Solution

A plain-vanilla Pentium-class PC with several attached printers makes a dandy CUPS printer server. There are two good ways to install multiple printers to a single PC:

  • Use additional parallel-PCI cards, for connecting parallel-port printers.

  • Add USB hubs for connecting more USB printers.

Set up a minimal Linux installation, with CUPS. Install all the Foomatic and Gimp-Print packages and drivers. (These are available both as RPMs and in Debian repositories.)

Then all you need to do is install the printers and configure CUPS. See the first four recipes in this chapter for how to install printers, and information on sharing with both Windows and Linux clients without needing to use Samba.

14.7.3 Discussion

A centralized printer server has a lot of advantages: all the printers are in one place, supplies can be stored close by, and users are not bothered by other people wanting to use their printers. And if you use Linux and CUPS for a print server, you don't need to set up Samba to share printers with Windows clients.

14.7.4 See Also

  • PC Hardware in a Nutshell, by Robert Bruce Thompson and Barbara Fritchman Thompson (O'Reilly). This is a great hardware guide, even though it is Windows-centric, and their companion web site (http://www.ttgnet.com) includes a lot of useful updates to the book.

  • The "Printing System Management" section in the CUPS Software Administrator's Manual at (http://localhost:631/documentation.html).


Recipe 14.8. Distributed Printing with Classes

14.8.1 Problem

You have a user group that generates a lot of high-volume printing, and you need an easy way to give users a group of printers to use, without having to hassle with individual print queues.

14.8.2 Solution

Use classes to create, in effect, a single printer queue containing several printers. From the Admin page of the CUPS web interface, click "Add Class." Select printers for the class from your installed printers. Users can now send print jobs to the class, instead of to an individual printer, and the first available printers will take them. You can add or remove printers from this menu, and even create subclasses.

You can also do this from the command line. Create a class and populate it with printers this way:

# lpadmin -p printer1 -p printer2  -p printer3 -c art-dept

To add another printer to this class, use:

# lpadmin -p printer4 -c art-dept

Remove a printer with the -r option:

# lpadmin -p printer4 -r art-dept

To delete the entire class, use:

# lpadmin -x art-dept

14.8.3 Discussion

Obviously, you don't want to group geographically dispersed printers into the same class—they should be in the same room. It will get confusing enough, as users won't know which printers have their print jobs. The advantage is that if a printer gets jammed or otherwise becomes unavailable, jobs will still be printed without user intervention. It's also great for high-volume printing, as idle printers will automatically take over from busy ones.

14.8.4 See Also

  • The "Printer Classes" section in the CUPS Software Administrators Manual (http://localhost:631/documentation.html)


Recipe 14.9. Restricting Users from Printers and Classes

14.9.1 Problem

You have some printers you would like to restrict to selected users. You don't want people printing pictures of their kids on the design group's fancy graphics printer, for example.

14.9.2 Solution

Use the lpadmin command:

# lpadmin -p hp6L  -u allow:carla,jenn,dancer

This changes /etc/cups/printers.conf:

# Printer configuration file for CUPS v1.1.20

# Written by cupsd on Fri Jan  7 00:36:36 2004

<DefaultPrinter hp6L>

Info

Location

DeviceURI parallel:/dev/lp0

State Idle

Accepting Yes

JobSheets none none

QuotaPeriod 0

PageLimit 0

KLimit 0

AllowUser carla

AllowUser jenn

AllowUser dancer

</Printer>

You can also restrict classes:

# lpadmin -p art-dept  -u allow:carla,jenn,dancer

This modifies /etc/cups/classes.conf.

You can also deny users:

# lpadmin -p hp6L  -u deny:daryl,larry,otherlarry

14.9.3 Discussion

Don't try to edit classes.conf or printers.conf directly, because your changes will be lost. Use lpadmin.

14.9.4 See Also

  • The "Managing Printers" section in the CUPS Software Administrators Manual (http://localhost:631/documentation.html)


Recipe 14.10. Troubleshooting

14.10.1 Problem

Printing, especially network printing, is probably the most difficult and troublesome aspect of system administration. What tools are there for diagnosing and fixing problems?

14.10.2 Solution

Your first stop is /var/log/cups/error_log. The default log level in cupsd.conf is LogLevel info. This logs errors and ordinary activity. If LogLevel info does not generate enough detail, the highest levels are debug and debug2.

Trying a different printer driver cures a large number of printing problems.

If test pages won't print, try printing other documents. A test page not printing indicates a problem somewhere, but if you can get your work done, you can probably live without the test page.

For network printing, make sure you have connectivity. Ping both IP addresses and hostnames. Try connecting manually to Samba shares. Try printing from the machine to which the printer is attached.

Run the ppd file for the printer through the PPD checker at http://www.cups.org/testppd.php to test for syntax errors.

If you can't decipher for yourself where the problem is, you can post log output and the steps you've tried in help forums. Here is a listing of the more useful ones:

http://printing.kde.org

Specific to printing in KDE, but still a thorough resource for many aspects of printing with CUPS

http://gimp-print.sourceforge.net/p_Mailing_Lists.php3

Help for Gimp-Print drivers

http://www.linuxprinting.org/forums.cgi

Help forums for HP, Epson, Alps, and many more printers

http://www.cups.org/newsgroups.php

CUPS newsgroups

As always, search the archives before posting your query. There is nothing new under the sun.

14.10.3 See Also

  • The Troubleshooting-CUPS-and-Asking-for-Help Howto, by Kurt Pfeifle—a wonderful, comprehensive CUPS troubleshooting guide (http://www.cups.org/cups-help.html)


Chapter 15. Configuring Video and Managing X Windows

    Section 15.1. Introduction

    Recipe 15.2. Using Both X Windows and Consoles

    Recipe 15.3. Installing a New Video Adapter

    Recipe 15.4. Editing XF86Config

    Recipe 15.5. Enabling 3D Hardware Acceleration with XFree86/DRI

    Recipe 15.6. Troubleshooting 3D Acceleration Problems

    Recipe 15.7. Configuring a Multihead Display

    Recipe 15.8. Choosing Different ServerLayouts at Startup

    Recipe 15.9. Setting a Default ServerLayout

    Recipe 15.10. Configuring startx

    Recipe 15.11. Changing Your Login Display Manager

    Recipe 15.12. Running Different Window Managers Simultaneously with Xnest


15.1. Introduction

The X Window System is the foundation of Linux's graphical interface. All those nice window managers and desktop environments—XFce, Enlightenment, KDE, Gnome, and so forth—run on top of X.

The X Window System is an amazing piece of work. You can run in a graphical environment, have text consoles open at the same time, and easily switch back and forth between them. The X Window System does more than draw pretty pictures; it's a networking protocol as well. You can even log in to remote systems via X. (This is covered in Chapter 17.)

While the X Window System has been the Linux standard forever, there is a new windowing system finding acceptance: X.org. It is a fork of the XFree86© project that found sudden popularity when the 4.4 release of XFree86 adopted a licensing change that was possibly incompatible with the GPL. Fedora and Mandrake were the first on board with X.org. By the time you read this, everyone may have kissed and made up, or it may all be a jumble, with yet another distribution difference to trap the unwary. You'll need to know which one is on your system. This command gives the version number for XFree86:

$ XFree86 -version

And this is for X.org:

$ X.org -version

X.org currently mirrors XFree86 very closely; the primary differences are in the configuration filenames and locations. However, the two will probably diverge more with time.

There is a lot of confusing terminology around the X Window System, as well as inconvenient capitalizations. Here are a few definitions:

XFree86 Project, Inc.

The organization that produces XFree86, which is a freely redistributable open source implementation of the X Window System.

XFree86 4.x

The current version of XFree86 on Linux.

X Window System

The original network-aware windowing environment for Unix. It is also called "a network protocol that draws pictures."

X11

The eleventh version of the X Window System.

X11R6

The specifications for the X Window System.

X.Org Foundation

A fork of the XFree86 project.

Make it easy on yourself, and just call it "X."

15.1.1 Hardware

All video adapters will work in Linux; even the most obscure card will work at a generic VGA level (640 480, 16 colors). All the major Linux distributions come with good video configuration tools that will detect your hardware and find drivers automatically. It is unlikely you'll ever need to edit XF86Config, except perhaps to enable hardware acceleration or to customize multihead displays.

The majority of video adapters have Linux drivers and will deliver good 2D performance, which means that for everyday tasks—email, web surfing, spreadsheets, word processing, and so forth—most any adapter will do. Getting 3D hardware acceleration support can take a little more effort, but if you play games like Tux Racer and Quake, or do 3D computer-aided design (CAD) or 3D modeling, hardware acceleration is essential.

Modern video cards are more powerful than PCs of yesteryear: a high-end model has 256 MB of RAM, a 256-bit bus, a 256-MHz GPU, and often even has its own cooling fan.

Video-card performance is limited by the type of motherboard slot it is plugged into. PCI cards are the slowest. AGP is much faster, and is found on all modern boards. There are several flavors of AGP:

AGP 1.0

1X = 266 MB/sec

2X = 533 MB/sec

AGP 2.0

1X = 266 MB/sec

2X = 533 MB/sec

4X = 1.066 GB/sec

AGP 3.0

1X = 266 MB/sec

2X = 533 MB/sec

4X = 1.066 GB/sec

8X = 2 GB/sec

The AGP standards are backward- and forward-compatible; you can mix up new cards and old motherboards and old cards and new motherboards. However, putting a new, high-end card on an older board means you won't get all the performance you paid for.

15.1.2 Drivers

One way to get hardware video acceleration in Linux is by using Direct Rendering Infrastructure (DRI) and a Linux-supported video card. DRI is built in to XFree86. Currently, XFree86/DRI support is available for these chipsets: 3dfx, Gamma, Intel i8x0 motherboard chipsets, Matrox, ATI Rage, ATI Radeon, Mach64, and Sis300. Visit http://xfree.org and http://dri.sourceforge.net for up-to-date information on supported chipsets and howtos.

The other way to get hardware video acceleration is by using drivers supplied by the manufacturer. For example, nVidia supplies their own binary-only drivers and kernel modules, which are currently the only way to get hardware acceleration for nVidia adapters. You can use the the open source nv driver for nonaccelerated 2D operation.

ATI and Matrox both have some cards that are fully supported by open source drivers and some that require proprietary binary drivers to get full functionality. As always, do your homework before buying.

15.1.3 Terminology

Here's some terminology:

DAC

Digital-to-analog converter. Usually a single chip that converts digital data to analog, for example in modems.

RAMDAC

Random Access Memory digital-to-analog converter. The chip that converts digital signals to analog, for analog displays.

GPU

Graphics processing unit. The processor that does the intense computations required for 3D video.

SRAM

Static Random Access Memory. It's "static" because it does not need to be refreshed, unlike DRAM (Dynamic Random Access Memory). SRAM is considerably faster than DRAM, with access times as low as 10 nanoseconds, compared to 60 nanoseconds for DRAM.

AGP

Accelerated graphics port. AGP is based on the PCI bus. It is a dedicated channel to system memory, and it is considerably faster than PCI, which tops out at 133 MB/sec. Currently the fastest AGP slot is 8X, or 2 GB/sec.


Recipe 15.2. Using Both X Windows and Consoles

15.2.1 Problem

You want both console sessions and X sessions.

15.2.2 Solution

Yes, Linux user, you can have it all. To switch from an X session to one of the consoles, simply hit Ctrl-Alt-Fn, where Fn is F1-F6. To switch between consoles, hit Alt-Fn. To switch back to X, hit Alt-F7. The first X session is always :0. To open a second X session, do this from a console:

$ startx — :1

Make sure there is a space on either side of the double hyphen. The X session you've just created belongs to the F8 key. Don't log into two X sessions as the same user, as strange and bad conflicts will occur. You can create as many X sessions as you have available consoles and system resources for.

When you start X from a console, all of the debugging messages and background mutterings can be seen on the console. KDE is especially talkative, like it's on a coffee jag. Most of it is not significant, but sometimes it's useful for troubleshooting.

15.2.3 Discussion

Most Linuxes install with seven virtual consoles. Take a look in /etc/inittab:

# Note that on most Debian systems tty7 is used by the X Window System,

# so if you want to add more gettys go ahead, but skip tty7 if you run X.

#

1:2345:respawn:/sbin/getty 38400 tty1

2:23:respawn:/sbin/getty 38400 tty2

3:23:respawn:/sbin/getty 38400 tty3

4:23:respawn:/sbin/getty 38400 tty4

5:23:respawn:/sbin/getty 38400 tty5

6:23:respawn:/sbin/getty 38400 tty6

The majority of Linux systems bind the default X session to tty7. A notable exception is Knoppix, which uses only five virtual terminals.

What can you do with all of these? Express all of your personalities. Log in as several different users. Log in as yourself many times. Switch to another console to get out of trouble. Gloat about how flexible and versatile Linux is.

15.2.3.1 gettys and ttys

These words, like so much of Linux's terminology, are Unix history lessons. getty means get tty. tty is teletype. That's right, Linux sees your expensive new full-color, high-definition monitor, with built-in sound and FireWire ports, as a teletype—just some old thing to stream output to.

getty manages logins over serial connections. It opens a serial device, such as a text terminal, virtual terminal, or modem, and waits for a connection. It displays the login prompt; then, when you enter your username, hands off to the login program. There are many gettys: mgetty, mingetty, ugetty, agetty, getty-ps, fbgetty, and doubtless more. mingetty is a minimal getty designed only for virtual consoles. It won't talk to modems. mgetty is probably the best modem getty. How do you know which getty your system uses?

$ ps ax | grep getty

  456 tty2     S      0:00 /sbin/getty 38400 tty2

  457 tty3     S      0:00 /sbin/getty 38400 tty3

  458 tty4     S      0:00 /sbin/getty 38400 tty4

  459 tty5     S      0:00 /sbin/getty 38400 tty5

  460 tty6     S      0:00 /sbin/getty 38400 tty6

Why doesn't this show tty1? Because that's the terminal you're logged in on. getty only sticks around waiting for logins; it retires quietly once a login is completed.

This tells us we're running getty itself, and not a link to some other getty:

$ ls -go /sbin/getty

-rwxr-xr-x    1    14264 Sep 19 21:25 /sbin/getty

tty is a program. Go ahead, try it out in a console:

$ tty

/dev/tty3

Now try it in an X terminal:

$ tty

/dev/pts/2

tty tells you what virtual terminal you are in ("virtual" because in the olden days, they had real terminals that had no processing power of their own—they were merely interfaces to a great and mighty mainframe somewheres).

ttyS* is a serial port. The serial ports are numbered ttyS0 through ttyS0 4. While we think of a serial port as the physical DB-9 connector, it's also a logical port with an IRQ and I/O address.

tty* names the virtual consoles: tty1, tty2, etc. While most Linux systems ship with 7, theoretically you could have up to 63 virtual consoles.

pts means pseudoterminal. These are X terminals, like xterm, gnome-terminal, wterm, powershell, and Konsole.

Because these are serial interfaces, horrid things like flow control, data flow paths, buffers, and other things that used to be of concern to users are involved. Thankfully, in these modern times, Linux handles all this for us (though these are still completely configurable, for those who wish to do so).

15.2.4 See Also

  • tty(1), tty(4),

pts(4), console(4),

getty(8), mingetty(8),

mgetty(8)

  • The Serial Howto (http://www.tldp.org/HOWTO/Serial-HOWTO.html)


Recipe 15.3. Installing a New Video Adapter

15.3.1 Problem

You are adding a second video adapter to a system, or replacing the old one with a different type of adapter. How do you configure it and get it working?

15.3.2 Solution

The best way is to use the graphical configuration tool that comes with your distribution. Let these excellent tools do the work. SuSE has SaX, Red Hat has redhat-config-xfree, Fedora uses system-config-xfree, and Mandrake's is XFdrake. Every distribution has its own utility; you'll get the best results by using it.

The second-best way is to edit XF86Config manually, changing only the parts that are pertinent to your new adapter. See the next recipe for how to edit XF86Config.

15.3.3 Discussion

You may find these X utilities to be helpful:

  • XFree86 -configure

  • /usr/X11R6/bin/xf86config

  • /usr/sbin/ddcprobe

All of these must be run as root.

XFree86 -configure probes your hardware and automatically generates a new XF86Config file. It thoughtfully stores the file in a separate location, without overwriting your original XF86Config file, so that you can test it first.

xf86config requires that you know configuration data about your mouse, keyboard, video adapter, and monitor. It takes you through the setup line by line, asking questions until you're ready to explode. Most important are the name of your video card, the amount of video RAM, and the horizontal/vertical refresh rates for your monitor.

Run /usr/sbin/ddcprobe to collect the information you need for your video card. It may also probe your monitor, but most likely it won't, so be sure to have your monitor's documentation at hand. If you don't have it, these values are common to modern multisync monitors and will get you up and running so you can Google for the correct figures:

  • Horizontal Sync (kHz): 30-58

  • Vertical Sync (Hz): 50-85

If your new configuration does not work, check /var/log/Xfree86.0.log to see what went wrong. If you get stuck in a bad X session and can't log out, use Ctrl-Alt-Backspace to break free.

15.3.4 See Also

  • XFree86 documentation (http://www.xfree86.org/resources.html)—look here to find the driver name for your adapter

  • X(7x)


Recipe 15.4. Editing XF86Config

15.4.1 Problem

You installed a new video adapter in a system, and you prefer to make the new settings manually. Your distribution utility doesn't do what you want, or you just want to edit a text file and be done with it.

15.4.2 Solution

X configuration is stored in the XF86Config file, which can be in a number of locations:

/etc/X11/XF86Config-4
/etc/XF86Config
/usr/X11R6/etc/X11/XF86Config-4
/usr/X11R6/etc/X11/XF86Config

Installing a new driver means changing a single section. This example shows changing from a Voodoo 3 adapter to an nVidia card. Simply change the Driver and the Identifier, by commenting out the old lines and adding your new values:

Section "Device"

#    Identifier     "3Dfx"

#    Driver         "tdfx"

    Identifier  "nVidia"

    Driver      "nv"

EndSection

The Identifier can be anything you like; the Driver must be the actual name of the driver. You'll find these at ht tp://www.xfree86.org/resources.html.

15.4.3 Discussion

If you're using vendor-supplied drivers, you'll have to download the drivers and follow their installation instructions.

Commenting out old lines instead of deleting them makes it easy to undo your changes, if necessary.

15.4.4 See Also

  • XFree86 documentation (http://www.xfree86.org/resources.html)—look here to find the driver name for your adapter


Recipe 15.5. Enabling 3D Hardware Acceleration with XFree86/DRI

15.5.1 Problem

You want to play Tux Racer, TuxKart, or Quake 3, or do some 3D modeling, CAD, or other high-end video work. You have a supported card and you've installed the drivers, but you're still stuck in 2D.

15.5.2 Solution

Making 3D hardware video acceleration work correctly requires having a supported video adapter and editing XF86Config to load the appropriate kernel modules.

First, see if the DRI extension is working:

$ glxinfo | grep rendering

Xlib: extension "XFree86-DRI" missing on display ".0.0".

direct rendering: no

It is not, so the next step is to enter the following lines in XF86Config:

Section "Module"

...

  Load "dri"

  Load "glx"

...

EndSection

...

Section "dri"

  Mode 0666

EndSection

Save your changes and restart X.

Test the new configuration by running glxgears, or by playing Tux Racer, TuxKart, or any game that requires hardware acceleration. Or you can run glxinfo again. Look for these lines:

$ glxinfo

direct rendering:..yes

...

OpenGL vendor string: VA Linux Systems, Inc.

OpenGL renderer string: Mesa DRI 20020221 Voodoo3 x86/MMX/3DNow!

OpenGL version string: 1.2 Mesa 4.0.4

...

This shows that hardware acceleration is working, because it names your hardware. If it were not, it would say this:

OpenGL vendor string: VA Linux Systems, Inc.

OpenGL renderer string: Mesa GLX Indirect

OpenGL version string: 1.2 Mesa 4.0.4

Most times, editing XF86Config this way cures the problem. If it doesn't, go to the next recipe for troubleshooting tips.

15.5.3 Discussion

Remember that your XF86Config file can be in a number of locations, depending on your distribution:

/etc/X11/XF86Config-4
/etc/XF86Config
/usr/X11R6/etc/X11/XF86Config-4
/usr/X11R6/etc/X11/XF86Config

XFree86, starting with Version 4.0, comes with DRI and the Mesa libraries built in, so you don't have to install any additional packages. Check your version:

$ XFree86 -version

XFree86 Version 4.3.0 (Debian 4.3.0-0ds2 20030304042836 dstone@aedificator)

Release Date: 27 February 2003

X Protocol Version 11, Revision 0, Release 6.6

Build Operating System: Linux 2.4.21-pre5 i686 [ELF]

Build Date: 04 March 2003

   Before reporting problems, check http://www.XFree86.Org/

to make sure that you have the latest version.

Module Loader present

OS Kernel: Linux version 2.4.21 (root@galaxy) (gcc version 3.2.3 20030316

(Debian prerelease)) #1 Sun Aug 3 20:15:59 PDT 2003

If you're using XFree86 3.x, you really need to update. It's not worth trying to add DRI and the Mesa libraries to Version 3; it's better to upgrade the whole works.

15.5.4 See Also

  • XF86Config(7)

  • The DRI User Guide (http://xfree.org/)

  • The Resources page at http://xfree.org/, for documentation for your version of XFree86 and for hardware-specific information, including drivers and configurations


Recipe 15.6. Troubleshooting 3D Acceleration Problems

15.6.1 Problem

You went through the steps in Recipe 15.5, but you still don't have hardware acceleration.

15.6.2 Solution

Start from the beginning, and make sure all the pieces are in place.

Is your video card supported? See this chapter's "Introduction" for a list of supported models, and check http://xfree.org and http://dri.sourceforge.net for current information.

Did your driver modules load? Run lsmod to find out:

$ lsmod

Module            Size  Used by    Not tainted

tdfx              30432  17

agpgart           37312   0 (unused)

tdfx is a 3dfx Voodoo3 driver. agpgart is needed for the AGP subsystem to work. If your driver module or agpgart does not show up in lsmod, look in the /lib/modules directory to see if the modules exist:

/lib/modules/2.4.21/kernel/drivers/char/agp/agpgart.0
/lib/modules/2.4.21/kernel/drivers/char/drm/tdfx.0

If either one is missing, you'll need to build and load it. (See Recipe 10.7.) Then restart X.

Is the dri subsytem working? If /proc/dri/0 exists, then it is:

$ ls /proc/dri/0

bufs  clients  mem  name  queues  vm  vma

If it doesn't, it may be that DRI was not enabled in the kernel. Check your kernel .config file. Look for:

# Hardware configuration

...

CONFIG_DRM=y

...

# DRM 4.1 drivers

...

CONFIG_DRM_TDFX=m

If CONFIG_DRM=y is not there, you'll need to rebuild the kernel. If the DRM module for your video card is not there, you can build and load it without rebuilding the kernel. Look in the kernel configurator for Character Devices, Direct Rendering Manager (XFree86 DRI support).

Unlike other kernel modules, all of these will be loaded by the X server. Make sure they are entered in the Modules section in XF86Config.

Always check /var/log/XFree86.0.log. Look for error messages, and check that all the modules listed in the Modules section of XF86Config loaded. If you still can't figure it out, visit the Getting Help, Resources, and Community Lists pages on http://xfree.org.

15.6.3 Discussion

If you are using drivers supplied by the manufacturer of your video adapter, you'll need to look to them for support. Check your documentation, make sure you have the right driver, and look on the manufacturer's web site for user forums and support knowledge bases.

Enabling hardware acceleration for supported cards is a matter of having the correct kernel configuration and making sure the relevant kernel modules load. See Chapter 10 for how to build kernels and modules.

15.6.4 See Also

  • The DRI User Guide (http://xfree.org)

  • The Resources page at http://xfree.org, for documentation for your version of XFree86 and for hardware-specific information, including drivers and configurations


Recipe 15.7. Configuring a Multihead Display

15.7.1 Problem

You would like to connect two monitors to a single system. You might want to have a single desktop span both monitors, or have two separate desktops, and maybe run different screen resolutions on each monitor.

15.7.2 Solution

XFree86 does it all. You'll need to have either two video cards or a single dual-head card installed and working. You'll also need two monitors, and XFree86 Version 4.x. Then edit XF86Config to create your desired multihead configuration.

To check your X version, use:

$ X -version

XFree86 Version 4.3.0...

You should configure your system to boot to a text console, so you can start X in whatever mode you want. You'll have four modes to choose from:

Traditional

Two different desktops, which can have different resolutions and color depths

Xinerama

A single desktop spanning across all screens, which must have the same resolutions and color depths

Clone

Two displays, mirrored

Single

Use only one monitor

First, back up your current XF86Config, then open it for editing. The PCI bus ID must be added to the Device entries:

Section "Device"

    Identifier  "3dfx"

    Driver      "tdfx"

    BusID       "PCI:1:0:0"

EndSection

...

Section "Device"

    Identifier  "nVidia"

    Driver      "nv"

    BusID       "PCI:0:12:0"

EndSection

This information comes from lspci:

$ /sbin/lspci

...

0000:00:12:0 VGA compatible controller: nVidia Corporation NV5M64 [RIVA TNT Model 64/Model

 64 Pro](rev 15)

0000:01:00.0 VGA compatible controller: 3Dfx Interactive, Inc. Voodoo 3 (rev 01)

Next, create a ServerLayout section. This example activates Xinerama at startup:

Section "ServerLayout"

  Identifier     "Xinerama"

  InputDevice    "Default Keyboard0"      "CoreKeyboard"

  InputDevice    "Default Mouse0"         "CorePointer"

  Option         "Clone"         "off"

  Option         "Xinerama"      "on"

# Other screen position options are Below, Above, and LeftOf

  Screen         "Screen0" RightOf "Screen1"

  Screen         "Screen1"

EndSection

To start X, boot to a text console and run:

$ startx

It will start up in full-color Xinerama.

15.7.3 Discussion

To start up in Traditional mode, set both Clone and Xinerama to "off," and change the Identifier to "Traditional."

To set Clone mode, turn off Xinerama, turn on Clone, and change the Identifier to "Clone."

Many video adapters are not capable of handling 3D acceleration in multihead mode. Check your documentation to find out if yours can.

PCI bus numbers that start with 0 are PCI cards. AGP cards start with 1.

Sometimes two video cards conflict and simply won't work together. If you think you have a problem, first run each card individually, to verify that they work. Then try moving the PCI card to a different slot. If that does not cure the conflict, you'll have to try different cards.

15.7.4 See Also

  • XF86Config(5x), for a complete description of all the available configuration options

  • Recipe 7.4, to learn how to configure your system to boot to either X or a text console


Recipe 15.8. Choosing Different ServerLayouts at Startup

15.8.1 Problem

You don't want to be locked into the same old thing every time you start X. Maybe you want Xinerama. Maybe you want Traditional. Maybe you want to run a single monitor on occasion, and you want to be able to select which one.

15.8.2 Solution

Configure different ServerLayouts in XF86Config, then select the one you want with startx options:

$ startx — -layout Single0

$ startx — -layout Single1

$ startx — -layout Clone

$ startx — -layout Traditional

This layout starts a single monitor:

Section "ServerLayout"

  Identifier    "Single0"

  InputDevice   "Default Keyboard0"    "CoreKeyboard"

  InputDevice   "Default Mouse0"       "CorePointer"

  Screen        "Screen0"

EndSection

Start this layout like this:

$ startx — -layout Single0

Now add a second Single layout, so that you can select either monitor at startup:

Section "ServerLayout"

  Identifier     "Single1"

  InputDevice    "Default Keyboard0"    "CoreKeyboard"

  InputDevice    "Default Mouse0"       "CorePointer"

  Screen         "Screen1"

EndSection

Start this layout like this:

$ startx — -layout Single1

You can also create ServerLayouts for each of your multihead modes. This example starts Clone mode:

Section "ServerLayout"

  Identifier   "Clone"

  InputDevice  "Default Keyboard0" "CoreKeyboard"

  InputDevice  "Default Mouse0" "CorePointer"

  Option       "Clone" "on"

  Option       "Xinerama"off"

#Other screen position options are Below, Above, and LeftOf

  Screen       "Screen0" RightOf "Screen1"

  Screen       "Screen1"

EndSection

This example starts Traditional mode:

Section "ServerLayout"

  Identifier   "Traditional"

  InputDevice  "Default Keyboard0" "CoreKeyboard"

  InputDevice  "Default Mouse0" "CorePointer"

  Option       "Clone" "off"

  Option       "Xinerama"off"

#Other screen position options are Below, Above, and LeftOf

  Screen       "Screen0" RightOf "Screen "

  Screen       "Screen1"

EndSection

Recipe Recipe 15.7 shows the Xinerama ServerLayout.

15.8.3 Discussion

Here is a sample XF86Config, showing all the required elements and two ServerLayouts.

The core elements are the Input Device, Device, and Monitor sections. These are the sections where your devices are identified and linked to their drivers. The Screen section sets resolution and color depth. In the ServerLayout sections, you put together the pieces for your various modes by their Identifiers.

Section "Files"

    FontPath      "unix/:7100"

    FontPath      "/usr/lib/X11/fonts/misc"

    FontPath      "/usr/lib/X11/fonts/cyrillic"

    FontPath      "/usr/lib/X11/fonts/75dpi"

EndSection

Section "ServerFlags"

  Option   "DefaultServerLayout"  "Xinerama"

EndSection

Section "Module"

    Load   "ddc"

    Load   "GLcore"

    Load   "dbe"

    Load   "dri"

    Load   "extmod"

    Load   "glx"

    Load   "record"

    Load   "bitmap"

    Load   "speedo"

EndSection

Section "InputDevice"

    Identifier    "Default Keyboard0"

    Driver        "keyboard"

    Option        "CoreKeyboard"

    Option"        XkbRules"          "xfree86"

    Option        "XkbModel"          "pc104"

    Option        "XkbLayout"         "us"

    EndSection

Section "InputDevice"

    Identifier     "Default Mouse0"

    Driver         "mouse"

    Option         "CorePointer"

    Option         "Device"             "/dev/input/mice"

    Option         "Protocol""IMPS/2"

    Option"         Emulate3Buttons"     "true"

    Option         "ZAxisMapping"        "4 5"

EndSection

Section "Device"

    Identifier  "3dfx"

    Driver      "tdfx"

    BusID       "PCI:1:0:0"

EndSection

Section "Device"

    Identifier  "nVidia"

    Driver      "nv"

    BusID       "PCI:0:12:0"

EndSection

Section "Monitor"

    VendorName           "0195"

    ModelName            "SYL"

    Identifier           "Monitor0"

    HorizSync             30-70

    VertRefresh           0-160

    Option               "DPMS"

EndSection

Section "Monitor"

    VendorName           "0195"

    ModelName            "SYL"

    Identifier           "Monitor1"

    HorizSync             30-70

    VertRefresh           0-160

    Option               "DPMS"

EndSection

Section "Screen"

    Identifier      "Screen0"

    Device          "3dfx"

    Monitor         "Monitor0"

    DefaultDepth     24

    SubSection "Display"

         Depth    24

         Modes   "1024x768"

    EndSubSection

EndSection

Section "Screen"

    Identifier      "Screen1"

    Device          "nVidia"

    Monitor         "Monitor1"

    DefaultDepth     24

    SubSection "Display"

         Depth    24

         Modes   "1024x768"

    EndSubSection

EndSection

Section "ServerLayout"

  Identifier     "Xinerama"

  InputDevice    "Default Keyboard0"      "CoreKeyboard"

  InputDevice    "Default Mouse0"         "CorePointer"

  Option         "Clone"         "off"

  Option         "Xinerama"      "on"

#Other screen position options are Below, Above, and LeftOf

  Screen         "Screen0" RightOf "Screen1"

  Screen         "Screen1"

EndSection

Section "ServerLayout"

  Identifier    "Single0"

  InputDevice   "Default Keyboard0"    "CoreKeyboard"

  InputDevice   "Default Mouse0"       "CorePointer"

  Screen        "Screen0"

EndSection

15.8.4 See Also

  • XF86Config(5x), for a complete description of all the available configuration options


Recipe 15.9. Setting a Default ServerLayout

15.9.1 Problem

You like having all those X startup options, but you also want a default, so you don't have to be bothered with selecting one every time.

15.9.2 Solution

Create a ServerFlags section to set the default. This must come before the ServerLayout entries:

Section "ServerFlags"

  Option     "DefaultServerLayout"  "Xinerama"

EndSection

Then simply use:

$ startx

to start an X session.


Recipe 15.10. Configuring startx

15.10.1 Problem

You like to boot to the console and then run startx when you want an X session. But you need to know how to configure startx to start the desktop or window manager of your choice.

15.10.2 Solution

Edit .xinitrc in your home directory. This will start Gnome:

exec gnome-session

You can list all of your installed window managers and desktop environments:

exec gnome-session

#exec startkde

#exec icewm

#exec icewm-experimental

#exec afterstep

#exec enlightenment

#exec blackbox

Entering all of your installed window managers makes it easy to change the default by uncommenting the one you want. Be sure that only one is uncommented at a time.

15.10.3 Discussion

Gnome, KDE, and XFce should be started from their startup scripts—gnome-session, startkde, and startxfce—rather than their executables.

If a user has no ~/.xinitrc file, startx will look for the global .xinitrc, which will be tucked away somewhere in /etc, like /etc/X11/xinit/.xinitrc. X Windows file locations tend to be different on the various Linux distributions, so you might as well get used to hunting them down.

15.10.4 See Also

  • startx(1x)


Recipe 15.11. Changing Your Login Display Manager

15.11.1 Problem

You don't like your login display manager, and you want to try a different one. Perhaps your distribution installed xdm, which is rather bare-bones, and you'd like to try a login display manager with more features, like gdm or kdm. Or you've having problems, such as hanging at shutdown, and you think a different login manager might help.

15.11.2 Solution

The three main display managers are xdm (X display manager), gdm (Gnome display manger), and kdm (KDE display manager). To find out which one your system is using, use ps:

$ ps ax | grep dm

3796 ?   S    0.00  /usr/bin/kdm -nodaemon

Most distributions use /etc/X11/default-display-manager. It should contain a single line:

/usr/bin/kdm

Change this to the display manager of your choice, using the full pathname:

/usr/bin/gdm

or:

/usr/bin/xdm

Red Hat and Fedora do it a little differently. Edit /etc/sysconfig/desktop, and add this line:

DISPLAYMANAGER="GNOME"

or "KDE," or "XDM." Don't use the paths to the executables; that doesn't work.

15.11.3 Discussion

xdm, the X display manager, can be thought of as a graphical replacement for the login command. It requires only the X Windows System to run, unlike gdm and kdm (which require Gnome and KDE, respectively).

gdm and kdm do the same thing as xdm, plus allow users to shutdown or restart; select a different window manager or desktop; and customize the login screen with a picture or logo.

Red Hat and Fedora use the /etc/X11/prefdm script to start the display manager, which is called from /etc/inittab. /etc/X11/prefdm looks to /etc/sysconfig/desktop for the default display manager, as you can see by reading the script:

$ less /etc/X11/prefdm

...

preferred=

if [ -f /etc/sysconfig/desktop ]; then

     . /etc/sysconfig/desktop

       if [ "$DISPLAYMANAGER" = GNOME ]; then

         preferred=gdm

       elif [ "$DISPLAYMANAGER" = KDE ]; then

         preferred=kdm

       elif [ "$DISPLAYMANAGER" = XDM ]; then

         preferred=xdm

       fi

fi

This is where we see that it wants DISPLAYMANAGER = "GNOME", instead of /usr/bin/gdm.

If you peruse Red Hat's /rc*.d directories, you'll notice there are no entries for any display manager. How can this be? Take a look at the bottom of /etc/inittab:

# Run xdm in runlevel 5

x:5:respawn:/etc/X11/prefdm -nodaemon

The moral is, in Linux, there are always many ways to do things.

15.11.4 See Also

  • Chapter 7, for recipes on how to change to different runlevels and how to configure runlevels to boot to a text console or to a display manager

  • the xdm and XTerminal mini-howto (http://www.tldp.org/HOWTO/XDM-xterm)

  • gdm homepage (http://freshmeat.net/projects/gdm)

  • kdm handbook (http://docs.kde.org/en/3.2/kdebase/kdm)


Recipe 15.12. Running Different Window Managers Simultaneously with Xnest

15.12.1 Problem

You have all these great window managers and desktop environments installed—KDE, Gnome, Enlightenment, Fluxbox, XFce, and such—and you would like to run some of them simultaneously. You know you can start up separate additional X sessions, or log out of X and start up in another window manager, but you wonder if there isn't a way to run them at the same time.

15.12.2 Solution

Xnest, the "nested X server," is just the tool for the job. Xnest allows you to run additional X sessions inside of already running X sessions.

Open a command shell in any X session—let's say you're running IceWM—and fire up Xnest:

$ Xnest -ac :1

You should see a blank screen with an X cursor in the middle. Now you can open a window manager. This example starts up WindowMaker:

$ wmaker -display :1

Now you can start up another one. From a command shell on IceWM, enter:

$ Xnest -ac :2

Some window managers or desktop environments, such as Gnome, need to start from an xterm in the Xnest window. First start up an xterm:

$ xterm  -display :2

Then start Gnome from the xterm:

$ gnome-session

You can start up yet another Xnest session from any available terminal in any of the windows:

$ Xnest -ac :3

You can continue to open more window managers until your system resources are exhausted and everything slows to a crawl. Figure 15-1 shows Gnome inside of IceWM, on KDE.

Figure 15-1. Gnome

15.12.3 Discussion

X sessions are numbered from 0, so the default X session is always :0. The -ac option to Xnest specifies the session number for the new display. Keep track of your whereabouts by checking the DISPLAY value:

$ echo $DISPLAY

:0.0

The -ac option disables access controls. Otherwise, X will not let you open any applications. Xnest uses the same options as the X command—see xserver(1x).

When you get several window managers going, you might see an error message like this, and the new one won't start:

$ gnome-session

gnome-session: you're already running a session manager

No problem. Just track it down and kill it:

$ echo $SESSION_MANAGER

local/windbag:/tmp/.ICE-unix/2774

$ rm /tmp/.ICE-unix/2774

and now Gnome will start.

15.12.4 See Also

  • xnest(1), xserver(1)

  • Window managers for X (http://www.plig.org/xwinman)


Chapter 16. Backup and Recovery

    Section 16.1. Introduction

    Recipe 16.2. Using rsync for Local File Transfers and Synchronization

    Recipe 16.3. Making Secure Transfers with rsync and ssh

    Recipe 16.4. Building an rsync Backup Server

    Recipe 16.5. Securing rsync Modules

    Recipe 16.6. Building an Anonymous Public rsync Server

    Recipe 16.7. Launching the rsync Daemon at Startup

    Recipe 16.8. Fine-Tuning File Selection

    Recipe 16.9. Automating rsync over ssh Backups

    Recipe 16.10. Limiting rsync's Bandwidth Requirements

    Recipe 16.11. Customizing Filepaths in rsync

    Recipe 16.12. Installing rsync on Windows Clients

    Recipe 16.13. Creating a Message of the Day for rsync

    Recipe 16.14. Creating a Bootable System Restore CD with Mondo Rescue

    Recipe 16.15. Verifying the Mondo Backup

    Recipe 16.16. Creating a Bootable System Restore DVD with Mondo Rescue

    Recipe 16.17. Using Mondo Rescue to Clone Linux Systems

    Recipe 16.18. Using the mindi-kernel for a "Sane" Backup

    Recipe 16.19. Restoring a System from a Mondo Rescue Disk

    Recipe 16.20. Restoring Selected Files from a Mondo Disk


16.1. Introduction

Making good backups is a fundamental chore, and one that is too often messy and inconvenient. This chapter covers using rsync and Mondo Rescue for robust, easy backups and, just as important, easy restores.

rsync is extremely efficient. It only transfers changes in files, and it can perform on-the-fly compression. It excels at keeping file trees sychronized; unlike a lot of backup software, it even mirrors deletions. Because of these features, rsync is the tool of choice for updating and mirroring web sites, CVS trees, and other large, complex file trees.

There are two ways to use rsync: over ssh, for authenticated login and transport; or by running it as a daemon to create public archives, which do not use ssh. Using ssh requires users to have login accounts on every machine for which they need rsync access. When rsync is run in daemon mode, you can use its built-in authentication methods to control access, so that users do not need login accounts on the rsync server.

Mondo Rescue is a great utility for creating a bootable system restore disk. Use it to make a snapshot of your current system configuration, and a bare-metal rebuild is as easy as booting to a CD or DVD. You'll have all of your patches, configurations, and updates. Then pull your data from your rsync server, and you're back in business in record time. Mondo can also be used for a complete system backup, all by itself.

Tape backups have long been a mainstay, because they used to provide the most storage for the least money. But they are slow to write to, and even slower to restore from. If you're getting paid by the hour, it might not seem so bad to sit back and enjoy the endless whirring when you're looking for a little bitty text file at the end of the tape. But there are other disadvantages:

  • Hard drives are much larger than tapes now, so you may have to use a tape autoloader, which is expensive, or have a designated tape-changing minion, which can raise dependability issues.

  • Users must depend on system administrators to restore files.

  • Doing a bare-metal restore is complicated, because you must first install a filesystem, then the tape drivers, and then do the restore.

  • Even when a single tape is large enough to store a complete backup, you still have to change and store tapes, even if it's only on a weekly basis.

Tape has one advantage: longevity. CDs, DVDs, and hard drives cannot be counted on for long-term archiving. I wouldn't count on home-burned CDs/DVDs for longer than two years. Tapes should be good for 20 years, if stored carefully. Of course, there's no guarantee that there will be drives or software to read them in 20 years, but the tapes themselves should last just fine.

Longevity is the primary difficulty with all digital storage media, because even if the medium (tape, DVD, etc.) survives, there's no guarantee that the tools to read it will endure. Hardware is in a continual state of change, and file formats change too. Can you still read 5.25" floppy disks? WordStar files? VisiCalc? Even the most offbeat obsolete file can be read, if it's a plain ASCII file. But what are you going to do with proprietary binary datafile formats, like .ppt and .pst? If the vendor decides to stop supporting them, or goes out of business, you're out of luck.

Paper is still the long-term storage champion. (Yes, stone tablets, parchment scrolls, and clay tablets win hands-down for sheer durability, but let's stick to contemporary media.) However, movies and songs do not translate well to paper, and paper is hundreds of times bulkier than any digital storage medium.

So, as a practical matter, planning good short-term archiving and disaster recovery is usually the best we can do. rsync and Mondo Rescue are perfect for this. rsync is fast, compact, and completely automatic—no need to remember to swap discs or tapes. Restores are easy and fast. You can even set up user-accessible backup archives, so users don't have to pester you to restore files.

What about backing up your backup server? No problem. Setting up a remote rsync mirror for backing up the backups is a common strategy.

Also, there are more choices than ever for removable media, including removable drive trays for IDE drives, USB/FireWire portable drives, and flash storage devices. In sum, there are a lot of excellent options for designing your backup and recovery schemes.


Recipe 16.2. Using rsync for Local File Transfers and Synchronization

16.2.1 Problem

You need to keep file trees synchronized on your workstation because your workstation is a staging ground for web directories, image galleries, source code trees, or other complex collections of files. So you use a working directory for editing files, and then copy the finished files to a separate upload directory. You would like something faster and more intelligent than cp, because cp takes a long time and you lose track of what needs to be copied.

16.2.2 Solution

Use rsync to keep file trees synchronized. rsync copies only changes, so it speeds up file copying, and it tracks changes inside files and in file trees.

Be sure you have the latest version, to get all the bugfixes and security patches. You definitely want 2.6 or later:

$ rsync —version

rsync  version 2.6.2  protocol version 26

...

This command copies a directory of web files to a staging directory that will later be uploaded to the web server:

$ rsync -av —stats  /home/pearlbear/webs  ~/web_upload

building file list ... done

...<all the files being copied fly by>...

Number of files: 254

Number of files transferred: 235

Total file size: 8923014 bytes

Total transferred file size: 8923014 bytes

Literal data: 8923014 bytes

Matched data: 0 bytes

File list size: 6490

Total bytes written: 8939848

Total bytes read: 3780

To verify the transfer, use:

$ ls ~/web_upload

webs

There is a subtle gotcha here: /home/pearlbear/images transfers the contents of /images and the images directory itself. Adding a trailing slash (/home/pearlbear/images/) copies only the contents of the /images directory, but not the directory itself. The trailing slash only matters on the source directory; it makes no difference on the destination directory.

If more files are added to /home/pearlbear/webs, or any existing files are changed, simply re-run the same command. rsync will transfer only the changes.

You can specify more than one source directory to be copied:

$ rsync -av  /home/pearlbear/webs /home/pearlbear/web_images  ~/web_upload

You can also test your rsync command first with the —dry-run option:

$ rsync -av  —dry-run  /home/pearlbear/webs /home/pearlbear/web_images  ~/web_upload

16.2.3 Discussion

If any files are deleted from the source directory, rsync will not delete them from the destination directory unless you explicitly tell it to with the —delete flag:

$ rsync -av —delete /home/pearlbear/webs  ~/web_upload

The -av flags mean archive, which retains file permissions and ownership, and verbose output.

Be careful using the —delete flag; if you accidentally delete from the rsync archive a file that you wanted to keep, it's gone for good. Be especially careful with your filepaths, because —delete will happily erase an entire directory or file tree.

rsync is a great tool for keeping local archives synchronized. When you're authoring web pages, writing code, assembling files to burn to CD, or managing any kind of large collection of files, it's a real timesaver to have rsync track and synchronize all the changes.

Installation is simple—both RPMs and Debian packages are named rsync, and you only need the single package. The sources are statically linked, so there is no danger of dependency problems, however you elect to install it.

16.2.4 See Also

  • rsync(1)


Recipe 16.3. Making Secure Transfers with rsync and ssh

16.3.1 Problem

You want to use rsync to copy files to another PC over a LAN, or over the Internet, and you want encrypted transport and authentication.

16.3.2 Solution

Use rsync over ssh. ssh must be set up and working on all hosts.

Specify your source and destination, and specify ssh with the -e flag. This command transfers files over the local network, to ljl's account on the remote PC "stinkpad":

ljl@compak:~$ rsync -av -e ssh  stationery  stinkpad:test

ljl@stinkpad's password:

building file list ... done

stationery/

stationery/ljl-return-address-small.sxw

stationery/ljl-holiday-label.sxw

stationery/ljl-return-address-MV-small.sxw

wrote 25984 bytes  read 68 bytes  7443.43 bytes/sec

total size is 25666  speedup is 0.99

Beware of filepath trickiness. stinkpad:test uploads the stationery directory and its contents to /home/ljl/test on stinkpad. If /test does not exist, rsync will create it:

ljl@stinkpad's password:

building file list ... done

created directory test

If you want to upload to a directory outside of your home directory, you'll need sufficient permissions for rsync to create a new directory, or you'll need it to be an existing directory that you can write to. Precede the upload directory with a forward slash, to make it relative to the root filesystem instead of to your home directory:

$ rsync -av -e ssh  stationery  stinkpad:/shared_uploads

To upload files over the Internet, use your login on the remote system and the full domain name:

$ rsync -av -e ssh  stationery  ljl@stinkpad.test.net:/shared_uploads

The syntax for copying files from a remote host is a little different. This copies the /scripts directory and its contents from the remote host to your local /downloads directory:

$ rsync -av -e ssh ljl@stinkpad.test.net:/shared_uploads/scripts  ~/downloads/

16.3.3 Discussion

Both authentication and transport are encrypted, so this is a nice, secure way to transfer sensitive files. The one downside is that users need shell accounts on all machines they are going to store files on or retrieve files from, so it's a bit of work to set up. A central server, with shared directories, is a good way to manage complex file sharing scenarios. You can control access with the usual Linux tools—file and directory permissions, and user groups, and you can use unique logins on the shared server, for extra security.

16.3.4 See Also

  • rsync(1)


Recipe 16.4. Building an rsync Backup Server

16.4.1 Problem

You want users to back up their own data. But you really don't want to give users shell accounts all over the place, just so that they can do backups. You'd also like to make it easier for them to share files, again without giving all your users shell accounts.

16.4.2 Solution

Use a dedicated PC for a central server, and run rsync in daemon mode. Users will not need login accounts on the server, and you can use rsync's own access controls and user authorization for security.

rsync must be installed on all machines.

First, on the rsync server, edit or create /etc/rsyncd.conf to create an rsync module defining the archive:

# global settings

log file = /var/log/rsyncd.log

# modules

[backup_dir1]

   path = /backups

   comment = server1 archive

   list = yes

   read only = no

Make sure that /backups exists. Next, start rsync on the server in daemon mode:

# rsync —daemon

Now you can copy files from a remote machine to the server. In this example, the remote PC is "workstation," and the rsync server is "server1." First, verify that the rsync server is accessible:

sue@workstation:~$ rsync server1::

backup_dir1      server1 archive

This command copies Sue's /spreadsheets directory to the module backup_dir1:

sue@workstation:~$ rsync -av  spreadsheets server1::backup_dir1

building file list.....done

spreadsheets/aug_03

spreadsheets/sept_03

spreadsheets/oct_03

wrote 126399 bytes  read 104 bytes  1522.0 bytes/sec

total size is 130228  speedup is 0.94

Now, view the nice, new uploaded files:

sue@workstation:~$ rsync server1::backup_dir1

drwx------      192  2003/02/12  spreadsheets

-rw-r--r--    21560  2003/09/17  aug_03

-rw-r--r--    21560  2003/10/14  sept_03

-rw-r--r--    21560  2003/11/10  oct_03

Sue can easily retrieve files from server1 to her workstation:

sue@workstation:~$ rsync -av  server1::backup_dir1/sept_03  ~/downloads

receiving file list...done

sept_03

wrote 21560 bytes read 126 bytes 1148.0 bytes/sec

total size is 22031  speedup is 0

16.4.3 Discussion

This particular setup is perfectly functional, but not very secure. backup_dir1 is wide open, so any rsync user can access it. Files are transmitted in the clear, so you shouldn't use this for sensitive files.

You can use rsync's built-in simple authentication and access controls to limit access, so it's possible to set up reasonably private archives. See Recipe 16.5 to learn how to add some security.

This is what the rsync command options mean:

rsync server1::

Double colons are used when connecting to an rsync server running in daemon mode. When you connect to an rsync server, you use the module names, rather than filepaths.

rsync -av

-a means archive mode. This tells rsync to copy directories recursively, preserve permissions, copy symlinks, preserve group, preserve owner, and preserve timestamps. -a is the same as -rlptgoD. -v is verbose.

—stats

This option prints a verbose set of statistics on the file transfer, for those who wish to calculate the efficiency of the rsync algorithm.

/etc/rsyncd.conf should be familiar to Samba users, as it uses the same style as smb.conf. Global settings go at the top. Then you can define as many modules as you need. A module defines a single directory, with its options and access permissions:

[backup_dir1]

The module name is enclosed in square brackets. Make this anything you like.

path = /backups

The directory for this module. Always use absolute paths.

comment = server1 archive

This is optional; say anything you want here.

list = yes

This allows the module to be listed when users query the server. The default is no, which will hide the module.

read only = no

The default is read-only. If you want to be able to upload files to this directory, turn off read-only.

16.4.4 See Also

  • rsync(1), rsyncd.conf(5)

  • The rsync home page (http://rsync.samba.org)


Recipe 16.5. Securing rsync Modules

16.5.1 Problem

You followed Recipe 16.4, and you really like giving users the power to fetch their own files from the backup server, or delegating updates of web and FTP servers to someone else. But it's wide open to anyone using rsync—how do you secure the modules?

16.5.2 Solution

rsync comes with its own simple authentication and access controls. You'll create a new file containing username/password pairs, and add "auth users" and "secrets file" directives to /etc/rsyncd.conf.

First create the password file on the rsync server. This example is for our fearless user, Sue. Make it chmod 600:

# rsync-users for server1

# created 2/7/2004

sue:sekkrit

Next, edit /etc/rsyncd.conf. Give Sue her own module, and lock out everyone but her:

# global settings

log file = /var/log/rsyncd.log

#modules

[sue_backup]

   path = /backups/sue

   comment = Sue's private archive

   list = yes

   read only = no

   auth users = sue

   secrets file = /etc/rsync/rsync-users

To access the module, Sue must prefix the server name with her rsync username:

sue@workstation:~$ rsync sue@server1::sue_backup

Password:

drwx------      192  2003/02/12  spreadsheets

-rw-r--r--    21560  2003/09/17  aug_03

-rw-r--r--    21560  2003/10/14  sept_03

-rw-r--r--    21560  2003/11/10  oct_03

Now she can upload and download files just like before, as long as she remembers to use her rsync login. Don't forget the double colons, which are used when connecting to an rsync server.

16.5.3 Discussion

The username/password pairs are arbitrary and are not related to system user accounts, so it is quick and easy to create or edit modules and add or delete users.

For additional security, add these directives to rsyncd.conf:

strict modes = yes

This enforces strict permissions on the password file. The file will not be checked by rsync if it is readable by any user other than the rsync daemon, and users will not be allowed access. The default is "yes," so it's not necessary to include this line, except as a reminder. If you don't want strict mode, you'll have to use strict modes = false.

hosts allow

Use this to specify hosts that are allowed to access the rsync archives. For example, you can limit access to hosts on your domain:

hosts allow = *.windbag.net

hosts allow = 192.168.1.

All hosts not allowed are denied, so you don't need a hosts deny directive.

hosts deny

This usually isn't needed, if you use hosts allow. It is useful for denying access to specific hosts that cause annoyance, if you don't want to use hosts allow.

The password file is in cleartext, so it must be restricted to the superuser.

16.5.4 See Also

  • rsync(1), rsyncd.conf(5)

  • The rsync home page (http://rsync.samba.org)


Recipe 16.6. Building an Anonymous Public rsync Server

16.6.1 Problem

You want to distribute software or other files, using an rsync-enabled server to conserve bandwidth. So you'll need anonymous access for downloads, and restrictions on who can upload files to the server.

16.6.2 Solution

First, build an rsync server as described in Recipe Recipe 16.4. Then make all public modules read-only, and be sure that permissions on directories do not allow write access to anyone but user and group owners. To upload files to your server, use rsync over ssh.

16.6.3 Discussion

To make a module read-only, add this line to the section for the module in rsyncd.conf:

read only = yes

Remember, the syntax for uploading files via ssh is a little different than the syntax for uploading files when rsync is running in daemon mode. You'll want to specify the true directory name, not the module name, and use only a single colon:

$ rsync -av -e ssh  /webfiles  rsyncadmin@stinkpad.test.net:/www/public

Password:

16.6.4 Discussion

If you want to automate nightly uploads over ssh, see Recipe Recipe 16.9.

16.6.5 See Also

  • rsync(1), rsyncd.conf(5)

  • Chapter 17

  • The rsync home page (http://rsync.samba.org)

  • Recipe 16.4, Chapter 16


Recipe 16.7. Launching the rsync Daemon at Startup

16.7.1 Problem

You don't want to start the rsync daemon by hand all the time. But rsync does not come with an init script. How do you make it start at boot time?

16.7.2 Solution

Put this script in /etc/init.d, then add it to your desired runlevels:

#!/bin/bash

# simple init script to run

# rsync in daemon mode

case "$1" in

    start)

        echo "Starting the rsync server..."

        exec /usr/bin/rsync --daemon

        ;;

    stop)

        echo "Stopping the rsync server...."

        killall /usr/bin/rsync

        ;;

    restart)

        $0 stop

        sleep 1

        $0 start

        ;;

    *)

        echo "Usage: $0 {start|stop|restart}"

        exit 1

        ;;

esac

16.7.3 Discussion

Remember to chmod +x to make this script executable.

16.7.4 See Also

  • Chapter 7, to learn how to add rsync to your desired runlevels


Recipe 16.8. Fine-Tuning File Selection

16.8.1 Problem

You would like to exclude some files (such as .tmp and .bak files) from being backed up, or you would like to create a list of included files.

16.8.2 Solution

Put your file lists in files, then call them with rsync's --exclude-from or —include-from options.

The files can contain a list of files, regular expressions, or both:

*.tmp

*.temp

*.bak

/etc/skel

/etc/local

Then add the --exclude-from or —include-from option on the rsync command line:

$ rsync -ae ssh /home /etc --exclude-from=~/exclude-list backup.test.net:/home-etc

16.8.3 Discussion

It's best to use only one or the other; using both options is the fast track to confusion.

16.8.4 See Also

  • rsync(1)


Recipe 16.9. Automating rsync over ssh Backups

16.9.1 Problem

You would like to automate your rsync over ssh backups.

16.9.2 Solution

Write a script, create a cron job, and set up keychain to authenticate to your remote hosts. (See Recipe 17.7 to learn how to use keychain.)

Here is a simple script that backs up /home and /etc, using the "backupadmin" user created just for this job.The second line of the script tells cron to hook into keychain for remote authentication:

#!/bin/bash

source  /home/backupadmin/.keychain/$HOSTNAME-sh

rsync -av -e ssh  --delete --force /home /etc  stinkpad:home-etc-backup/

Once you have fine-tuned your file selection and tested your backup script, create a cron job to run the script. This runs it every night at 10 p.m.:

# crontab -e

0 22 * * *  /usr/local/bin/rsyncbackup.sh

16.9.3 Discussion

A lot of documentation tells you to create keys with null passphrases, so that you can schedule ssh transfers with cron. It's dangerous to do this, because anyone who gains access to your private key will be able to easily misuse it. keychain handles authentication for you, so you can properly protect your private keys with passphrases. The one downside to keychain is that it does not survive a reboot, so you have to enter your passphrase, or passphrases, at startup. But this is a security utility, after all—you don't want just anyone to be able to boot your machine and have unfettered access to your remote hosts.

Using the —delete flag means that all files deleted from the local archive will also be removed from the remote archive.

—force means that directories will be deleted even if they are not empty.

This is an easy way to perform secure, offsite backups. If all of your users' /home and shared data directories are on a central server, it's even easier.

16.9.4 See Also

  • ssh(1), rsync(1)

  • Recipe 16.8

  • Recipe 17.7

  • Hack #42, "Automated Snapshot-Style Incremental Backups with rsync," in Linux Server Hacks, by Rob Flickenger, for a really nice script that creates system snapshots at any interval you like (hourly, every four hours, daily, etc.)

  • The Examples page at http://samba.anu.edu.au/rsync


Recipe 16.10. Limiting rsync's Bandwidth Requirements

16.10.1 Problem

rsync can gobble up your bandwidth in nothing flat; imagine backing up a few gigabytes of ripped audio files on a busy network. What's an easy way to restrict it, without implementing full-blown traffic shaping?

16.10.2 Solution

Use the —bwlimit option:

$ rsync -a —bwlimit=256 rsync.test.net::testnetftp/ /ftp/mirror

16.10.3 Discussion

—bwlimit uses kilobytes per second, so be sure to take this into account when you're calculating what value to use. Remember that most network speeds are measured in kilobits, which are one-eighth the size of kilobytes.

16.10.4 See Also

  • rsync(1)


Recipe 16.11. Customizing Filepaths in rsync

16.11.1 Problem

You want to be able to specify filepaths, instead of dumping everything into a single directory.

16.11.2 Solution

Use the -R option:

$ rsync -aR -e ssh  /webfiles/site1  stinkpad.test.net:/www/public

This creates /www/public/webfiles/site1, instead of /www/public/site1.

16.11.3 Discussion

This is especially useful when you are transferring several directories and want to maintain separate filepaths for each one.

16.11.4 See Also

  • rsync(1)


Recipe 16.12. Installing rsync on Windows Clients

16.12.1 Problem

You're running a mixed LAN, and you would like to back up your Windows clients on your Linux rsync server.

16.12.2 Solution

On all the Windows clients, install Cygwin, rsync, OpenSSH, and a Linux text editor. Then make a few Windows-specific tweaks, and you can use rsync just like on Linux clients.

To get all of these, visit http://www.cygwin.com and download setup.exe to your Windows PC. Click "Install from Internet," then proceed through the installation steps until you get to the Select Packages menu. In the +Net menu, select rsync and OpenSSH. In the +Editors menu, select an editor.

Now you need to add Cygwin's path to Windows. On Windows 95/98/ME, add C:\Cygwin\bin, or whatever your path is, to the SET PATH= statement in AUTOEXEC.BAT. Then reboot.

On Windows NT, go to Control Panel [image] System [image] Environment tab. Add the path setting to the end, then click the Set button. Click OK. You won't need to reboot.

On Windows 2000/XP, go to Control Panel [image] System [image] Advanced tab, then click the Environment Variables button. Double-click on the PATH statement in the System Variable screen, append the path, then click OK. You won't need to reboot.

Remember to separate your PATH statements with semicolons. Now your Windows PC is ready to make rsync and rsync over ssh transfers.

To use Cygwin, open an MS-DOS command shell, and start up Cygwin like this:

C:\cygwin\cygwin.bat

administrator@powerpc ~$

This puts you in a nice, familiar Bash environment. Alternatively, you can run an application directly from the C: prompt:

C:\cygwin\bin\rsync -av -e ssh  stationery  stinkpad:test

16.12.3 Discussion

For running rsync on Windows, use all the same commands as on Linux. Just remember to be careful of filepaths—Windows uses backslashes instead of forward slashes, and drive letters:

C:\cygwin\bin\rsync -av -e ssh  stationery  stinkpad:test

Cygwin creates a nice native Linux environment on your Windows system, and it comes with a large assortment of Linux utilities. If Cygwin doesn't include a Linux program you want to use, you may be able to make it work by compiling it on Windows. See http://www.cygwin.com for details.

16.12.4 See Also

  • rsync(1)

  • Cygwin home (http://www.cygwin.com)


Recipe 16.13. Creating a Message of the Day for rsync

16.13.1 Problem

You're running an rsync server, by running rsync in daemon mode, and you think it would be nice to greet users with a cheery daily message.

16.13.2 Solution

First create your MOTD, in a plain text file, then configure the path to the file in rsyncd.conf:

motd file = /etc/rsync/motd

When users connect to your server, they will see your message:

sue@workstation:~$ rsync server1::

Greetings from Asbury Park! I'm Bruce, and I'll be your rsync server today!

backup_dir1      server1 archive

sue_backup       sue's private stuff

16.13.3 Discussion

You don't have to settle for dull old text messages. ASCII art makes a nice MOTD; see Chapter 16 for an example.

Figure 16-1. An ASCII message of the day

Create your own with the FIGlets ASCII generator, available at http://www.figlet.org.

16.13.4 See Also

  • rsync(1), rsyncd.conf(5)


Recipe 16.14. Creating a Bootable System Restore CD with Mondo Rescue

16.14.1 Problem

You need a simple method for creating a system image. You want a perfect clone to preserve your configurations, patches, and updates, so you can easily do a bare-metal restore, or migrate to a new hard drive, or roll out a number of identical installations. Your data are backed up separately, so you only want to preserve system and configuration files.

16.14.2 Solution

Use Mondo Rescue to create a custom bootable system CD.

Be sure there is enough free space on your hard drive to store the temporary CD image (at least 700 MB) per CD. Do not run any other programs (games, email, word processors, etc.) while running Mondo. Then, as root, run mondoarchive at the command line. Mondo will think about things for a minute or two, then open the window shown in Figure 16-2.

Figure 16-2. Mondo

Choose your backup medium. In this example, we'll use a CD-RW at SCSI address 0,1,0. In the next window, it asks if your writer has "Burn-Proof" technology (yes). Next, choose the compression level (Maximum), then specify the speed of your CD (re)writer (4).

Tell it the SCSI address of your CD writer 0,1,0. Next, you'll be asked which files you want to back up. Select /, or the entire root filesystem, because the next question is which files you want to exclude. /tmp and /proc are automatically excluded. You should also exclude /home and any other data directories, such as shared data directories, mail spools, and logfiles.

Mondo will then ask whether you want to verify your backups after it has created them (yes) and whether you are confident that your kernel is a sane, sensible, standard Linux kernel (say no if you are using an older Debian kernel—see the "Discussion" section of this recipe for more information). Next it will ask if you are sure you want to proceed (yes).

When it asks you to enter your CD-ROM's /dev device, give it the SCSI /dev name—/dev/scdn—if your system has a 2.4 kernel. For 2.6 kernels, use /dev/hdn. The backup can take up to a couple of hours. However, you can't wander away, because you'll need to push some buttons near the end.

16.14.3 Discussion

If you're running Mondo from the console and your screen blanks from inactivity, bring it back by hitting the Alt key.

cdrecord —scanbus shows the SCSI address of your drive. On systems with 2.4 kernels, look in /etc/fstab to get the SCSI /dev name, or dig through the output of dmesg.

To qualify as "sane," your kernel needs to include:

  • loopfs support

  • CD-ROM support

  • ISO9660 filesystem support

  • initrd ramdisk support (built-in)

  • Virtual memory filesystem support (built-in)

  • Floppy disk support (built-in)

  • Ext2 filesystem support (built-in)

  • Support for the backup media

  • SCSI emulation in 2.4 kernels

Most stock kernels newer than 2.4.7 ought to be fine. Debian, in particular, didn't used to be well supported by Mondo, but Debian kernels from 2.4.18 should have all the required bits. If your kernel cannot be used to boot a Mondo Rescue CD, use the failsafe mindi-kernel (see Recipe Recipe 16.18). The mindi-kernel is used only to boot the Rescue CD; it does not replace your system kernel.

If you're not sure whether your drive supports "Burn-Proof" technology, run this command to show all of your drive's capabilities:

$ cdrecord —atip dev=0,1,0

Cdrecord 2.01a07 (i686-pc-linux-gnu) Copyright (C) 1995-2003 Jörg Schilling

scsidev: '0,1,0'

scsibus: 0 target: 1 lun: 0

...

Using generic SCSI-3/mmc CD-R driver (mmc_cdr).

Driver flags   : MMC-3 SWABAUDIO BURNFREE

Supported modes: TAO PACKET SAO SAO/R96P SAO/R96R RAW/R16 RAW/R96P RAW/R96R

...

Mondo has its own ideas about how GRUB should be set up, so GRUB users may need to create this soft link:

# ln -s /boot/grub/menu.lst /etc/grub.conf

Mondo insists on it and won't perform a backup without it, so it's best to humor it.

Mondo comes in source form, Debian packages, and RPMs. You'll need several packages:

Mondo
Mindi
afio
Newt
lzop
syslinux
cdrecord
mkisofs

Debian users will also see apt-get fetch:

buffer
gawk
mindi-busybox
ms-sys, tint
slang

16.14.4 See Also

  • mondoarchive(1)

  • Your locally installed Mondo documentation (/usr/share/doc/mondo/hml/1.6x-howto)

  • Mondo user forums (http://forum.mondorescue.org)


Recipe 16.15. Verifying the Mondo Backup

16.15.1 Problem

You would like to verify that your new Mondo backup is good. It's always a good idea to verify that a backup is good; finding out that it's bad when you need to do a restore is not good for your health.

16.15.2 Solution

Use Mondo's compare command.

Boot up the Mondo disk on the same system that created it. At the command prompt, type:

# compare

This will take a while, depending on the size of the backup. When it's finished, review the changes by reading the /tmp/changed.txt file. You can expect to see differences in logfiles, mail spools, /etc/mtab, and other files that change frequently. There should not be changes in static system files, such as executables in /bin, /sbin, /usr/bin, and /usr/sbin, or in static configuration files in /etc.

16.15.3 Discussion

Always test your backups! After running compare, restore a few files from the Mondo disk. If you have a spare PC that is the same hardware configuration, you can do a complete restore on it (the surest method).

16.15.4 See Also

  • mondoarchive(1)

  • Your locally installed Mondo documentation (/usr/share/doc/mondo/hml/1.6x-howto)

  • Mondo user forums (http://forum.mondorescue.org)


Recipe 16.16. Creating a Bootable System Restore DVD with Mondo Rescue

16.16.1 Problem

You would like to put your system backup on a single DVD, instead of several CDs.

16.16.2 Solution

Run Mondo Rescue from the command line, instead of using the graphical interface, and create an .iso. Then burn the .iso to DVD. In addition to the Mondo Rescue components listed in the "Discussion" section of Recipe Recipe 16.14, you'll need dvd+rw-tools and cdrtools.

The first command creates an .iso, and the second command copies it to the DVD:

# mondoarchive -OVmF -5 -S /tmp/scratch -T /tmp/mondo -E "/home /shared /var/www" \

-i -d /tmp/iso

# growisofs -dvd-compat -Z /dev/scd0=/tmp/iso

16.16.3 Discussion

This task can also be performed from the Mondo graphical interface. In the opening screen, select "Backup to Hard Disk." Using the command line gives you greater control; for example, you can turn off the prompt to create boot floppies and disable ejecting the drive tray.

This is what the various mondoarchive command flags mean:

-O

Create a backup.

-V

Verify the backup.

-m

Don't eject the drive tray. Use this for unattended backups and for laptops, which usually do not have self-retracting disc trays.

-F

Don't ask to create boot floppies.

-5

Compression level. The range is 0-9, with 0 being uncompressed and 9 the greatest level of compression. The default is 3.

-S

Location of the scratch directory, where images are built before being archived.

-T

The directory where other temporary files are stored.

-E

List directories that are to be excluded from the backup. Removable mounts, /tmp, and /proc are automatically excluded.

-i

Create .iso images.

-d

The directory where the completed .iso is to be stored. The default is /root/images/mondo.

16.16.4 See Also

  • mondoarchive(1), growisofs(1)

  • Your locally installed Mondo documentation (/usr/share/doc/mondo/hml/1.6x-howto)

  • Mondo user forums (http://forum.mondorescue.org)


Recipe 16.17. Using Mondo Rescue to Clone Linux Systems

16.17.1 Problem

You have a number of identical PCs, and you want to install identical custom Linux configurations on each one. It sounds easy, but in practice, installing the same custom configuration on two or more PCs is a pain and error-prone. Mondo Rescue makes it easy.

16.17.2 Solution

First, customize a single Linux installation to your specifications. Then create a Mondo CD or DVD from your customized system, and use it for your new installations. Boot to the Mondo disk, then select "Nuke" to perform the installation. It will overwrite anything that is already installed and create an exact copy of your customized Linux.

16.17.3 Discussion

This is a nice timesaver when you have a particular server configuration to replicate, or when you want to roll out a number of identical workstations. Don't forget to tweak network settings, such as hostnames and static IPs, and to set up user accounts as needed.

16.17.4 See Also

  • mondoarchive(1)

  • Your locally installed Mondo documentation (/usr/share/doc/mondo/hml/1.6x-howto)

  • Mondo user forums (http://forum.mondorescue.org)


Recipe 16.18. Using the mindi-kernel for a "Sane" Backup

16.18.1 Problem

Your Linux kernel is missing some of the elements Mondo needs to create a bootable rescue disk. You know this because when you tried to boot your Mondo rescue disk, it failed with a "VFS: Unable to mount root fs" error. What do you do next? How do you create a useable rescue disk?

16.18.2 Solution

Use the mindi-kernel to create your Mondo rescue disk.

The mindi-kernel is a failsafe 2.4.7 kernel provided by the Mondo authors. If you're using Mondo's graphical interface, it will ask you if you want to use the mindi-kernel. Say yes.

Use the -k flag to specify it at the command line:

-k FAILSAFE

16.18.3 Discussion

Debian users may need to install the mindi-kernel separately.

The mindi-kernel does not replace your system kernel; all it does is ensure a bootable rescue disk.

16.18.4 See Also

  • mondoarchive(1)

  • Your locally installed Mondo documentation (/usr/share/doc/mondo/hml/1.6x-howto)

  • Mondo user forums (http://forum.mondorescue.org)


Recipe 16.19. Restoring a System from a Mondo Rescue Disk

16.19.1 Problem

You need to do a complete system rebuild because your system has been compromised, or you just want to blow away your existing installation and restore it to a previous, known-good state.

16.19.2 Solution

To perform a complete system rebuild, boot to your Mondo rescue disk and type nuke at the command prompt. It will completely overwrite your system and restore it to the state saved on the Mondo disk.

16.19.3 Discussion

You can use Mondo to back up your entire system, including datafiles, or just the root filesystem. Using Mondo to preserve the root filesystem on a bootable CD, then backing up data separately on an rsync server, is an easy, fast way to do both backups and restores.

16.19.4 See Also

  • mondoarchive(1)

  • Your locally installed Mondo documentation (/usr/share/doc/mondo/hml/1.6x-howto)

  • Mondo user forums (http://forum.mondorescue.org)


Recipe 16.20. Restoring Selected Files from a Mondo Disk

16.20.1 Problem

You just need to replace a few selected files; you don't want to nuke your system and start over.

16.20.2 Solution

Boot your Mondo disk, and run it in interactive mode.

Type interactive at the prompt. Mondo will ask you which partitions to mount. Select the ones you want by editing the mountlist. Then follow the prompts:

Do you want to partition your devices? no

Do you want to format them? no

Do you want to restore everything? no

Do you want to restore something? yes

Which path do you want to restore? /etc/rsync

Select your restore path: /etc/rsync

Mondo will give you the option to try to boot your system directly from Mondo when you're finished restoring files, but it's usually simpler to remove the Mondo disk and reboot.

16.20.3 Discussion

You may wish to restore to the default path, which is /mnt/RESTORE, and review the files before copying them to their final locations.

16.20.4 See Also

  • mondoarchive(1)

  • Your locally installed Mondo documentation (/usr/share/doc/mondo/hml/1.6x-howto)

  • Mondo user forums (http://forum.mondorescue.org)


17.1. Introduction

Remote access is one of Linux's great features, and there are many ways to do it. For access over untrusted networks, don't use those old reliable standbys, telnet or X, because logins and data are sent in the clear. Your best bet is OpenSSH (Secure Shell), a suite containing a number of secure remote transfer programs: scp (secure copy), ssh (Secure Shell), and sftp (SSH file transfer protocol). ssh is the tool of choice for remote system administration; with ssh, you can log into remote systems and run them as though you were physically there. Logins and data are encrypted, and ssh will detect if any packets have been altered en route. Eavesdroppers can sniff and muck with all the packets they want—they won't get anywhere.

SSH isn't really a shell; it's a protocol. There are two incompatible versions of this protocol: SSH-1 and SSH-2. OpenSSH supports both. This chapter covers SSH-2, because you should be using a current version of OpenSSH.

SSH nomenclature can get a bit confusing. SSH, capitalized, is the protocol. ssh, scp, and so forth, in lowercase, are programs that use SSH. OpenSSH is the implementation of SSH used in this chapter.

Using SSH is not very complicated. If you're used to rsh, rlogin, or rcp, the command syntax is pretty much the same. You'll need sshd, the OpenSSH daemon, running on all machines to which you want to enable remote access, and you'll need shell accounts on the remote machines. You can log in as any user, as long you have the login and password.

OpenSSH uses public/private key pairs for authentication. Private keys are carefully guarded and never, ever shared. Always create a strong passphrase to encrypt and protect your private keys. A really strong passphrase is a nonsense sentence that combines words and numbers, like "t4is is mai 733t s3kkrit p4ssphr4se". As always, you must strike a balance between security and usability, because you may need to type your passphrase frequently.

Public keys are distributed to both remote SSH clients and remote SSH servers. For example, when you use host-key authentication, this means the public key of the server is stored on clients that are allowed to access it. All SSH sessions start with host-key authentication. Once the remote host's public key is copied to your local ~/.ssh directory, you can log into any user account you have access to on the remote host, using the account logins.

If you want to use SSH keys for authentication, instead of user account logins, you generate your own public/private key pair, and copy your public key to all the remote hosts you wish to access. A couple of configuration steps, which are covered in this chapter, must be carried out to make this work. This is called public-key authentication.

If you're going to access a lot of remote machines, managing logins can be difficult. Recycling the same public key and passphrase all over the place presents a potential security problem, but tracking a lot of different passphrases can also be trouble. OpenSSH provides a way to avoid all this login drama, by using public-key authentication, ssh-agent, and keychain. These let you set up secure, passphraseless logins.


Recipe 17.2. Setting Up OpenSSH the First Time

17.2.1 Problem

You need to establish a connection between your local workstation and a remote PC. The connection needs to be secure; you don't want your data exposed to prying eyes. (They're there, and you should be worried about them—even if you aren't paranoid.) So you want to set up OpenSSH.

17.2.2 Solution

Install OpenSSH on both machines. sshd, the ssh daemon, must be running on the remote host, so that it can receive connections. Copy the remote host's public key to the local machine's ~/.ssh/known_hosts file, and you're in business.

Starting and stopping sshd on most rpm-based systems is done like this:

# /etc/init.d/sshd start

# /etc/init.d/sshd stop

On Debian, it's slightly different:

# /etc/init.d/ssh start

# /etc/init.d/ssh stop

Always check your init filenames, as they vary on different distributions.

Copying the remote host's public key to your local ~/.ssh/known_hosts file is as simple as connecting to the remote host:

carla@windbag carla$ ssh stinkpad

The authenticity of host 'stinkpad (192.168.1.100)' can't be established.

RSA key fingerprint is a2:c6:70:3e:73:00:b3:ed:90:b1:9a:bc:e7:d5:32:ba.

Are you sure you want to continue connecting (yes/no)?

Type yes, and it will respond:

Warning: Permanently added 'stinkpad,192.168.1.100' (RSA) to the list of known hosts.

carla@stinkpad's password:

Linux stinkpad 2.4.21 #1 Sun Aug 3 20:15:59 PDT 2003 i686 GNU/Linux

Libranet GNU/Linux

Last login: Sat June  3 22:16:24 2004 from :0.0

carla@stinkpad:~$

Now you are logged into your account on the remote PC, and can work just as if you were sitting physically at the remote machine. (To learn how to run a remote X session, see Recipe Recipe 17.11.) To close the session, type exit.

17.2.3 Discussion

Using the simple ssh <hostname> login connects you to another host on your LAN, using the same login. You can connect as a different user with the -l flag:

carla@windbag ~$ ssh -l wilmaf stinkpad

To make an SSH connection over the Internet, you must use the full domain name:

carla@windbag ~$ ssh stinkpad.test.net

Making that initial connection, and copying the host's RSA key, is the riskiest part of setting up SSH. If an intruder managed to compromise your nameserver, she could possibly hijack your SSH session and capture your login. It's a pretty small risk, though, and you can verify the IP address before logging in the first time. To close off this hole, you can manually copy the host's public key to your local ~/.ssh/known_hosts file first. You must edit it slightly; see the examples below.

Host keys are stored in /etc/ssh. These are used to validate the identity of the remote host. This is all you need to allow users to access this machine. All they need is a copy of the public host key in their ~/.ssh/known_hosts files and an account to log into. Some Linux distributions create two key pairs when you install OpenSSH—one RSA key pair and one DSA key pair:

$ ls /etc/ssh

ssh_host_dsa_key

ssh_host_dsa_key.pub

ssh_host_rsa_key

ssh_host_rsa_key.pub

If your system does not create these for you, or you wish to change them, see Recipe Recipe 17.3 to learn how to generate new host keys.

This is what the public rsa key looks like:

$ cat ssh_host_rsa_key.pub

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA5pSqNmtqRzK2JaLr8qkIQ41nBDLI2JRJ6gRBmwg9gwK3S8xXnMUHIs

u8wh5S1oei8hs47x2I9cnNpxHfj1wQWwqP6lVyelDfD+y+uWIz0UGzUXN5IrqYZ70EdQ4Xn++Jl1kmFG6Ll6KySb07

0OX0nlC09rNxisHL5GC0qi1+qM= root@windbag

The key itself must be one long, unbroken line—it must not have line breaks, as it does on this page. Copy it to a removeable disk, transfer it to your local ~/.ssh/known_hosts file, and modify it in this manner:

windbag.test.net,192.168.1.6 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA5pSqNmtqRzK2JaLr8qkIQ41nB

DLI2JRJ6gRBmwg9gwK3S8xXnMUHIsu8wh5S1oei8hs47x2I9cnNpxHfj1wQWwqP6lVyelDfD+y+uWIz0UGzUXN5Irq

YZ70EdQ4Xn++Jl1kmFG6Ll6KySb070OX0nlC09rNxisHL5GC0qi1+qM=

As you can see, the hostname and IP address must be written at the beginning of the line, and the hostname must be deleted from the end of the line.

The .pub, or public, keys are world-readable, but private keys must be readable only by the key owner.

17.2.4 See Also

  • ssh(1)

  • SSH, The Secure Shell: The Definitive Guide, by Daniel J. Barrett and Richard Silverman (O'Reilly)


Recipe 17.3. Generating New Host Keys

17.3.1 Problem

You looked in /etc/ssh and didn't see any key files: your Linux distribution did not generate host keys when you installed OpenSSH. Or you just want to create new host keys yourself.

17.3.2 Solution

Use ssh-keygen to create a new key pair. This must be done as root, and you have to specify the name of the new key pair. You only need one key pair. Always specify a passphrase:

# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

Generating public/private rsa key pair.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /etc/ssh/ssh_host_rsa_key.

Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.

The key fingerprint is:

6c:24:75:54:d3:21:17:c9:11:db:41:dd:95:3f:d0:ac root@windbag

This example uses the default key names, but you can call the keys anything you like. If you use different names, be sure to enter them in /etc/ssh/sshd_config:

# HostKeys for protocol version 2

HostKey /etc/ssh/ssh_host_rsa_key

Comment out or delete any entries for keys that do not exist.

17.3.3 Discussion

See this chapter's "Introduction" for how to create a strong passphrase.

Once you have OpenSSH set up and working and you have distributed public keys, you don't want to change your private keys without a really good reason, because you'll have to distribute new public keys. If users try to connect with the old public key, they will get this message:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@    WARNING: HOST IDENTIFICATION HAS CHANGED!    @

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

Someone could be eavesdropping on you right now (man-in-the-middle attack)!

It is also possible that the host key has just been changed.

Please contact your system administrator.

Add correct host key in <path>/known_hosts to get rid of this message.

Agent forwarding is disabled to avoid attacks by corrupted servers.

X11 forwarding is disabled to avoid attacks by corrupted servers.

Are you sure you want to continue connecting (yes/no)

It's a good idea to train your users to say no at the prompt, and to contact you to see what is going on.

17.3.4 See Also

  • ssh(1), ssh-keygen(1)

  • SSH, The Secure Shell: The Definitive Guide


Recipe 17.4. Authenticating Via Public Keys

17.4.1 Problem

You would prefer to authenticate your SSH sessions with keys, rather than your system logins. This will let you use your SSH private-key passphrase instead of your system login, which means your system login is protected, and you can reuse the same public/private key pair for as many remote hosts as you need to connect to.

17.4.2 Solution

In this example, Valorie wishes to log in to saturn from jupiter. To do this, she must generate a new, personal private/public key pair with ssh-keygen on jupiter, then transfer a copy of her new public key to saturn.

This command generates a new RSA key pair, protected by a passphrase:

valorie@jupiter:~$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/valorie/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/valorie/.ssh/id_rsa.

Your public keyCp


Recipe 17.10. Customizing the Bash Prompt for ssh

17.10.1 Problem

Sure, you know that the prompt changes to display the remote hostname when you're logged in via SSH. But it's just a dumb little black-and-white prompt, and it's easy to make mistakes, so you want a customized, colorful prompt to indicate when you have an active SSH login.

17.10.2 Solution

Customize the Bash prompt on the remote PCs. This example turns the prompt red and adds "ssh" to it.

Add these lines to the ~./bashrc for the remote account you want to log into:

if [ -n "$SSH_CLIENT" ]; then text=" ssh"

fi

export PS1='\[\e[0;31m\]\u@\h:\w${text}$\[\e[m\] '

When you log into this machine, the prompt will look like this, in red:

carla@server06:~ssh $

Only the prompt is red; all the other text will be your normal shell colors.

17.10.3 Discussion

Customizing the Bash prompt is practically a book topic in itself. The example in this recipe can easily be edited to suit your preferences. You don't have to use "ssh" or name the variable "text;" these can be anything you like. [\e[0;31m\] determines the text color—just change the numbers.

[\e[m\] turns off the colors, so that your commands and command output will return to the normal shell colors (Table 17-1).

Table 17-1. Bash prompt text colors

Black 0;30

Dark Gray 1;30

Blue 0;34

Light Blue 1;34

Green 0;32

Light Green 1;32

Cyan 0;36

Light Cyan 1;36

Red 0;31

Light Red 1;31

Purple 0;35

Light Purple 1;35

Brown 0;33

Yellow 1;33

Light Gray 0;37

White 1;37

This customization works by checking for the presence of the SSH_CLIENT environment variable. Then Bash knows to use the custom SSH prompt instead of the default prompt. To see this for yourself, log into a remote host via SSH, then run:

user@remotehost$ echo $SSH_CLIENT

192.168.1.5 33232 22

This only works on the remote prompt. Running it at the local prompt will return a blank line:

user@localhost$ echo $SSH_CLIENT

because once you complete an SSH login, the remote machine controls your local terminal, and the SSH client is running on the remote PC. That is why you have to customize ~/.bachrc on the remote hosts.

17.10.4 See Also

  • bash(1)

  • The Bash Prompt Howto (http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html)


Recipe 17.11. Tunneling X over SSH

17.11.1 Problem

You like running remote X sessions, but you know that they are completely insecure, so you want to run X over SSH.

17.11.2 Solution

Follow the previous recipes to get SSH configured and running, then enable X forwarding on the SSH server, in /etc/ssh/sshd_config. Then use the -X flag when you start your SSH session.

Put this line in /etc/ssh/sshd_config on the SSH server:

X11Forwarding yes

Then connect to the server with the -X flag:

$ ssh -X saturn.test.net

Run this command to test that X forwarding is working:

$ echo $DISPLAY

localhost:10.0

If it weren't, it would return a blank line. Now you can run any X program installed on the server as though it were local. Try this for a simple test:

$ xeyes

Or run glxgears, or any X program that is installed on the server.

17.11.3 Discussion

Using SSH for remote X sessions is both simpler and more secure than running a plain-vanilla X session without SSH, which is not secure at all. However, it still carries some risks. Use this to connect only to trusted hosts, because a snoopy admin can easily capture your keystrokes or logins, or even connect to your local desktop and snoop even more. Make sure your local ~/.Xauthority file is mode 600, to prevent unprivileged users on the remote host from also joining in the snooping.

Be sure that these entries are in your local /etc/ssh/ssh_config file and any ~/ ssh/ssh_config files on your system:

   Host *

   ForwardX11 no

   ForwardAgent no

It's important to ensure that X forwarding is turned off, except when you absolutely need it.

Depending on your physical distance from the remote server and the speed of your network connection, you may notice some lag in your keystrokes or mouse movements, as the X protocol is a bit of a network hog.

17.11.4 See Also

  • ssh(1)

  • SSH, The Secure Shell: The Definitive Guide


Recipe 17.12. Connecting from a Windows PC

17.12.1 Problem

SSH on Linux is great. But you want to access your Linux PCs from Windows. How can you use OpenSSH on a Windows PC?

17.12.2 Solution

There are several ways to do this. The two we'll look at here are Cygwin and PuTTY.

Recipe Recipe 16.12 details how to install and run Cygwin. Cygwin creates a native Linux environment on Windows. You'll be able to run OpenSSH from Windows just like from a Linux box, both as a server and as a client. You can even run X over SSH.

PuTTY is a free SSH client for Windows. There is no server component. PuTTY is dead easy—just download, install, and double-click, then type in the name of the host to which you want to connect and click Open. Figure 17-1 shows the main PuTTY window.

Figure 17-1. PuTTY

17.12.3 Discussion

If all you need a is a simple SSH client, PuTTY is the quickest and easiest. putty.exe easily fits on a floppy disk, for portable SSH-ing.

17.12.4 See Also

  • PuTTY home page (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)

  • Cygwin (http://www.cygwin.com)


Recipe 17.13. Setting File Permissions on ssh Files

17.13.1 Problem

You want to be sure that your SSH files and keys have the correct, most secure permissions.

17.13.2 Solution

For user accounts in ~/.ssh, use the following permissions:

~/.ssh
mode 700
~/.ssh/id_dsa and other private keys
mode 400
~/.ssh/id_dsa.pub and other public keys
mode 644
~/.ssh/ssh_config
mode 644
~/.ssh/known_hosts
mode 644
~/.ssh/authorized_keys
mode 644

Files in /etc/ssh should have these permissions:

/etc/ssh
mode 755
/etc/ssh/sshd_config
mode 644
/etc/ssh/ssh_config
mode 644
/etc/ssh/ssh_host_dsa_key and other private keys
mode 400
/etc/ssh/ssh_host_dsa_key.pub and other public keys
mode 644
/etc/ssh/moduli
mode 644

17.13.3 Discussion

File permissions and ownership are fundamental security tools in Linux, so it's important to be careful and make sure to get them right. Again, beware of text editors that create automatic backup copies, and be careful when you delete files. If they sit in the Trash, they can easily be retrieved.

17.13.4 See Also

  • ssh(1), sshd(8)

  • SSH, The Secure Shell: The Definitive Guide