Chapter 10. System tips

Table of Contents

10.1. The screen program
10.1.1. The use scenario for the screen command
10.1.2. Key bindings for the screen command
10.1.3. The screen like program for the X
10.2. Data recording and presentation
10.2.1. The log daemon
10.2.2. Log analyzer
10.2.3. Recording the shell activities cleanly
10.2.4. Customized display of text data
10.2.5. Colorizing commands
10.2.6. Customizing program to be started
10.2.7. Recording the graphic image of an X application
10.2.8. Recording changes in configuration files
10.3. System maintenance tips
10.3.1. System integrity check
10.3.2. The hardware identification
10.3.3. The hardware configuration
10.3.4. The time
10.3.5. The terminal configuration
10.3.6. The sound infrastructure
10.3.7. Disable the screen saver
10.3.8. Disable the sound (beep)
10.3.9. Storage device hints
10.3.10. Memory usage
10.3.11. Invisible disk space consumption
10.4. Process operation
10.4.1. Time a process
10.4.2. The scheduling priority
10.4.3. The ps command
10.4.4. The top command
10.4.5. Kill a process
10.4.6. Schedule tasks once
10.4.7. Schedule tasks regularly
10.4.8. Alt-SysRq
10.5. The kernel
10.5.1. Linux kernel 2.6
10.5.2. Kernel headers
10.5.3. Kernel and module compile
10.5.4. Kernel source compile: Debian standard method
10.5.5. Module source compile: Debian standard method
10.5.6. Kernel source compile: classic method
10.5.7. Non-free hardware drivers
10.6. The chroot
10.6.1. Run a different Debian distribution with chroot
10.6.2. Setting up login for chroot
10.6.3. Setting up X for chroot
10.6.4. Run other distributions with chroot
10.6.5. Build packages under chroot
10.6.6. Other virtualization tools

Here, I will describe basic tips to configure and manage system from the console.

10.1. The screen program

The screen program (popcon: V:10, I:28) enables to have multiple terminals on a single physical terminal.

It also accommodates remote shell process to survive the interrupted connection. This is the essential tool for people to access remote sites via the unreliable connection.

10.1.1. The use scenario for the screen command

Here is a typical use scenario of the screen(1) program.

  1. You login to a remote machine.

  2. You start the screen command on a single console.

  3. You execute multiple programs in screen windows created with ^A c ("Control-A" followed by "c").

  4. You switch among the multiple screen windows by ^A n ("Control-A" followed by "n").

  5. Suddenly you need to leave your terminal, but you don't want to lose your active work by keeping the connection.

  6. You detach the screen session by any methods such as:

    • brutally unplugging your network connection,

    • typing ^A d ("Control-A" followed by "d") and manually logging out from the remote connection, or

    • typing ^A DD ("Control-A" followed by "DD") to have screen detach and log you out.

  7. You log in again to the same remote machine (even from a different terminal).

  8. You enter the "screen -r" command.

  9. The screen program will magically reattach all previous screen windows with all actively running programs.

This is good way to save connection fee if you are on the dial-up network connection.

10.1.2. Key bindings for the screen command

In screen session, all keyboard inputs are sent to your current window except for the command keystroke, by default ^A ("Control-A"). All screen commands are entered by typing ^A plus a single key [plus any parameters]. Here are important ones to remember:

Table 10.1.  List of key bindings for screen.

key binding

meaning

^A ?

show a help screen (display key bindings)

^A c

create a new window and switch to it

^A n

go to next window

^A p

go to previous window

^A 0

go to window number 0

^A 1

go to window number 1

^A w

show a list of windows

^A a

send a Ctrl-A to current window as keyboard input

^A h

write a hardcopy of current window to file

^A H

begin/end logging current window to file

^A ^X

lock the terminal (password protected)

^A d

detach screen session from the terminal

^A DD

detach screen session and log out


See screen(1) for details.

10.1.3. The screen like program for the X

Install the xmove package to enable support for mobile X11 clients. See xmove(1).

10.2. Data recording and presentation

10.2.1. The log daemon

Many programs record their activities under the /var/log/ directory.

  • The kernel log daemon: klogd(8)

  • The system log daemon: syslogd(8)

See Section 4.5.8, “The system message” and Section 4.5.9, “The kernel message”.

10.2.2. Log analyzer

Here are notable log analyzers ("~Gsecurity::log-analyzer" in aptitude).

Table 10.2.  List of system log analyzers.

package

popcon

size

description

logwatch

V:2, I:2

2312

log analyser with nice output written in Perl

fail2ban

V:2, I:2

616

bans IPs that cause multiple authentication errors

analog

V:1.2, I:18

4520

web server log analyzer

awstats

V:1.5, I:3

4892

powerful and featureful web server log analyzer

sarg

V:1.4, I:1.5

1500

squid analysis report generator

pflogsumm

V:0.3, I:0.8

164

Postfix log entry summarizer

syslog-summary

V:0.2, I:1.1

80

summarize the contents of a syslog log file

lire

V:0.17, I:0.2

5048

full-featured log analyzer and report generator

fwlogwatch

V:0.16, I:0.3

432

Firewall log analyzer

squidview

V:0.10, I:0.6

260

monitors and analyses squid access.log files

visitors

V:0.09, I:0.3

224

fast web server log analyzer

swatch

V:0.07, I:0.2

196

Log file viewer with regexp matching, highlighting, & hooks

crm114

V:0.07, I:0.2

1120

The Controllable Regex Mutilator and Spam Filter (CRM114)

icmpinfo

V:0.07, I:0.4

84

Interpret ICMP messages


[Note] Note

CRM114 provides language infrastructure to write fuzzy filters with the TRE regex library. Its popular use is spam mail filter but it can be used as log analyzer.

10.2.3. Recording the shell activities cleanly

The simple use of the script(1) command (see: Section 2.4.9, “Recording the shell activities”) to record the shell activity produces a file with control characters. This can be avoided by using the col(1) command:

$ script
Script started, file is typescript
  • do whatever ...

  • Press Ctrl-D to exit script

$ col -bx <typescript >cleanedfile
$ vim cleanedfile

In some odd environment where you lack access to the script command, for example, during the boot process in the initramfs, you can use following instead:

$ sh -i 2>&1 | tee typescript
[Tip] Tip

Some x-terminal-emulator such as gnome-terminal have recording capability. You may wish to extend line buffer for scrollback.

[Tip] Tip

You may use screen command with "^A H" (see Section 10.1.2, “Key bindings for the screen command”) to perform recording of console.

[Tip] Tip

You may use emacs with "M-x shell", "M-x eshell", or "M-x term" to perform recording of console. You may later use "C-x C-w" to write the buffer to a file.

10.2.4. Customized display of text data

Although pager tools such as more(1) and less(1) (see Section 2.4.5, “The pager”) and custom tools for highlighting and formatting Section 12.1.7, “Highlighting and formatting plain text data” can display text data nicely, general purpose editors (see Section 2.4.6, “The text editor”) are most versatile and customizable.

[Tip] Tip

For vim(1) and its pager mode alias view(1), ":set hls" will enable highlighted search.

10.2.5. Colorizing commands

Colorized commands are handy for inspecting their output in the interactive environment. I include following in my ~/.bashrc.

if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=always'
    alias ll='ls --color=always -l'
    alias la='ls --color=always -A'
    alias less='less -R'
    alias ls='ls --color=always'
    alias grep='grep --color=always'
    alias egrep='egrep --color=always'
    alias fgrep='fgrep --color=always'
    alias zgrep='zgrep --color=always'
else
    alias ll='ls -l'
    alias la='ls -A'
fi

The use of alias limits color effects to the interactive command usage. It has advantage over exporting environment variable "export GREP_OPTIONS='--color=auto'" since color can be seen under pager programs such as "less".

[Tip] Tip

You can turn off these colorizing aliases in the interactive environment by invoking shell with "TERM=dumb bash".

10.2.6. Customizing program to be started

Some programs start another program automatically. Here are check points for customizing this process:

  • configuration file of the parent program such as "/etc/mc/mc.ext".

  • system configuration menu such as "Sysyem" -> "Preferences" -> "Preferred Application" for Gnome.

  • environment variables such as "BROWSER", "EDITOR", "VISUAL", and "PAGER" (see eviron(7)).

  • the update-alternatives(8) system for programs such as "editor", "view", "x-www-browser", "gnome-www-browser", and "www-browser" (see Section 2.4.7, “Setting a default text editor”).

  • the "$HOME/.mailcap" and "/etc/mailcap" file contents which associate MIME type with program (see mailcap(5)).

  • the the "$HOME/.mime.types" and "/etc/mime.types" file contents which associate file name extension with MIME type (see run-mailcap(1)).

[Tip] Tip

The update-mime(8) command updates the "/etc/mailcap" file using "/etc/mailcap.order" file (see mailcap.order(5)).

[Tip] Tip

The debianutils package provides sensible-browser(1), sensible-editor(1), and sensible-pager(1) commands which make sensible decisions on which editor, pager, and web browser to call, respectively. I recommend you to read these shell commands.

10.2.7. Recording the graphic image of an X application

There are few ways to record the graphic image of an X application, including an xterm display.

Table 10.3.  List of graphic image manipulation tools.

package

popcon

size

command

xbase-clients

V:33, I:67

52

xwd(1)

gimp

V:13, I:56

11720

GUI menu

imagemagick

V:14, I:30

4464

import(1)

scrot

V:0.19, I:0.9

88

scrot(1)


10.2.8. Recording changes in configuration files

Changes in configuration files can be nicely recorded using DVCS system (see Section 11.5.4.4, “Git for recording configuration history”).

10.3. System maintenance tips

10.3.1. System integrity check

Poor system maintenance may expose your system to external exploitation.

For system security check, you should start with:

Here is a simple script to check for typical world writable incorrect file permissions.

# find / -perm 777 -a \! -type s -a \! -type l -a \! \( -type d -a -perm 1777 \)

10.3.2. The hardware identification

For the PCI-like devices (AGP, PCI-Express, CardBus, ExpressCard, etc.), lspci(8) command (probably with "-nn" option) is a good start for the hardware identification

Alternatively, you can identify the hardware by reading contents of /proc/bus/pci/devices or browsing directory tree under /sys/bus/pci (see Section 2.2.12, “procfs and sysfs”).

Table 10.4.  List of hardware identification tools.

package

popcon

size

description

pciutils

V:44, I:92

460

Linux PCI Utilities, lspci(8)

usbutils

V:22, I:97

520

Linux USB utilities, lsusb(8)

pcmciautils

V:1.0, I:16

172

PCMCIA utilities for Linux 2.6, pccardctl(8)

scsitools

V:0.2, I:1.5

476

Collection of tools for SCSI hardware management, lsscsi(8)

pnputils

V:0.03, I:0.18

108

Plug and Play BIOS utilities, lspnp(8)

procinfo

V:0.7, I:5

120

Displays system information from /proc, lsdev(8)

lshw

V:1.0, I:5

804

Information about hardware configuration, lshw(1)

discover

V:4, I:13

928

Hardware identification system, discover(8)


10.3.3. The hardware configuration

Although most of the hardware configuration on modern GUI desktop systems such as Gnome and KDE can be managed through accompanying GUI configuration tools, it is a good idea to know some basics methods to configure them.

Table 10.5.  List of hardware configuration tools.

package

popcon

size

description

hal

V:43, I:60

1972

Hardware Abstraction Layer, lshal(1)

console-tools

V:60, I:97

948

Linux console font and keytable utilities.

x11-xserver-utils

V:16, I:23

616

X server utilities. xset(1) and xmodmap(1) commands.

acpid

V:54, I:88

184

Daemon to manage events delivered by the Advanced Configuration and Power Interface (ACPI)

acpi

V:3, I:34

92

Utilities for ACPI devices

apmd

V:1.4, I:13

252

Daemon to manage events delivered by the Advanced Power Management (APM)

powersaved

V:1.2, I:1.6

1800

Daemon to manage battery, temperature, ac, cpufreq (SpeedStep, Powernow!) control and monitor with ACPI and APM supports.

noflushd

V:0.13, I:0.2

244

Allow idle hard disks to spin down

sleepd

V:0.09, I:0.13

140

Puts a laptop to sleep during inactivity

hdparm

V:10, I:34

272

Hard disk access optimization. Very effective but dangerous. You must read hdparm(8) first.

smartmontools

V:4, I:12

828

Control and monitor storage systems using S.M.A.R.T.

setserial

V:3, I:6

176

Collection of tools for serial port management.

memtest86+

V:0.5, I:4

236

Collection of tools for memory hardware management.

scsitools

V:0.2, I:1.5

476

Collection of tools for SCSI hardware management.

tpconfig

V:0.4, I:0.5

208

A program to configure touchpad devices

setcd

V:0.09, I:0.5

64

Compact disc drive access optimization.

big-cursor

I:0.2

68

Larger mouse cursors for X

lspowertweak

V:0.02, I:0.11

88

Simple front end to powertweak, lspowertweak(8)


Here, ACPI is a newer framework for the power management system than APM.

10.3.4. The time

The following will set system and hardware time to MM/DD hh:mm, CCYY.

# date MMDDhhmmCCYY
# hwclock --utc --systohc
# hwclock --show

Times are normally displayed in the local time on the Debian system but the hardware and system time usually use UTC.

If the hardware (BIOS) time is set to GMT, change the setting to UTC=yes in the /etc/default/rcS.

If you wish to update system time via network, consider to use the NTP service with the packages such as ntp, ntpdate, and chrony. See:

10.3.5. The terminal configuration

There are several components to configure character console and ncurses(3) system features:

  • the terminfo(5) file

  • the TERM(7) environment variable

  • the setterm(1) command

  • the stty(1) command

  • the tic(1) command

  • the toe(1) command

If the terminfo entry for xterm doesn't work with a non-Debian xterm, change your terminal type from xterm to one of the feature-limited versions such as xterm-r6 when you log in to a Debian system remotely. See /usr/share/doc/libncurses5/FAQ for more. dumb is the lowest common denominator for terminfo.

10.3.6. The sound infrastructure

Device drivers for sound cards for current Linux 2.6 are provided by Advanced Linux Sound Architecture (ALSA). ALSA provides emulation mode for previous Open Sound System (OSS) for compatibility.

Run "dpkg-reconfigure linux-sound-base" to select the sound system to use ALSA. Unless you have very new sound hardware, udev infrastructure should configure your sound system.

[Tip] Tip

Use "cat /dev/urandom > /dev/audio" or the speaker-test(1) command to test speaker. (^C to stop)

[Tip] Tip

If you can not get sound, your speaker may be connected to a muted output. Modern sound system has many outputs. The alsamixer(1) command in the alsa-utils package is useful to configure volume and mute settings.

Application softwares may be configured not only to access sound devices directly but also to access them via some standardized sound server system.

Table 10.6.  List of sound packages

package

pocon

size

description

linux-sound-base

V:15, I:59

132

Base package for ALSA and OSS sound systems

alsa-base

I:59

444

ALSA driver configuration files

alsa-utils

V:39, I:59

1984

Utilities for configuring and using ALSA

esound-common

V:25, I:68

68

Enlightened Sound Daemon (ESD) common (Enlightenment and GNOME)

esound

V:5, I:40

84

Enlightened Sound Daemon (ESD) server (Enlightenment and GNOME)

esound-clients

V:10, I:19

168

Enlightened Sound Daemon (ESD) client (Enlightenment and GNOME)

libesd-alsa0

V:2, I:3

96

Enlightened Sound Daemon (ESD) library Enlightenment and GNOME)

libesd0

V:40, I:64

92

Enlightened Sound Daemon (ESD) library (Enlightenment and GNOME) - OSS

arts

I:16

36

aRts server (KDE)

libarts1c2a

V:23, I:47

6180

aRts library (KDE)

libartsc0

V:22, I:51

72

aRts library (KDE)

jackd

V:1.6, I:7

412

JACK Audio Connection Kit. (JACK) server (low latency)

libjack0

V:12, I:22

360

JACK Audio Connection Kit. (JACK) library (low latency)

libjack0.100.0-0

I:38

48

JACK Audio Connection Kit. (JACK) library (low latency)

nas

V:0.17, I:0.2

324

Network Audio System (NAS) server

libaudio2

V:27, I:65

204

Network Audio System (NAS) library

pulseaudio

V:0.6, I:1.8

1240

PulseAudio server, replacement for ESD

libpulse0

V:2, I:25

496

PulseAudio client library, replacement for ESD

libpulsecore5

V:0.5, I:1.4

604

PulseAudio server library, replacement for ESD

libgstreamer0.10-0

V:14, I:61

2644

GStreamer: Gnome sound engine

libxine1

V:6, I:54

24

xine: KDE older sound engine

libphonon4

I:2

468

Phonon: KDE new sound engine


There is usually a common sound engine for each popular desktop environment. Each sound engine used by the application can choose to connect to different sound servers.

10.3.7. Disable the screen saver

For disabling the screen saver, use following commands.

Table 10.7.  List of commands for disabling the screen saver.

environment

command

The Linux console

setterm -powersave off

The X Window by turning off screensaver

xset s off

The X Window by disabling dpms

xset -dpms

The X Window by GUI configuration of screen saver

xscreensaver-command -prefs


10.3.8. Disable the sound (beep)

One can always unplug the PC speaker. Removing pcspkr kernel module does this for you.

The following will prevent the readline program used by the bash to beep when encountering "\a" (ASCII=7):

$ echo "set bell-style none">> ~/.inputrc

10.3.9. Storage device hints

You can test disk access speed of harddisk, e.g. /dev/hda, by "hdparm -tT /dev/hda".

You may be able to speed up a harddisk connected with (E)IDE with "hdparm -q -c3 -d1 -u1 -m16 /dev/hda". Please check your hardware and read manpage of hdparam(8) before playing with harddisk configuration because this may be quite dangerous for the data integrity.

You may be able to read badly pressed cdroms on modern high head CD-ROM drive by slowing it down with "setcd -x 2.

Mounting a filesystem with the noatime option is also very effective in speeding up read access to the file. See fstab(5) and mount(8).

10.3.10. Memory usage

The kernel boot message in the /var/log/dmesg contains the total exact size of available memory.

The free(1) and top(1) commands display information on memory resources on the running system.

$ grep '^Memory' /var/log/dmesg
Memory: 990528k/1016784k available (1975k kernel code, 25868k reserved, 931k data, 296k init)
$ free -k
             total       used       free     shared    buffers     cached
Mem:        997184     976928      20256          0     129592     171932
-/+ buffers/cache:     675404     321780
Swap:      4545576          4    4545572

For my MacBook with 1GB=1048576k DRAM (video system steals some of this):

Table 10.8.  List of memory sizes reported.

report

size

Total size in dmesg

1016784k = 1GB - 31792k

Free in dmesg

990528k

Total under shell

997184k

Free under shell

20256k


Do not worry about the large size of "used" and the small size of "free" in the "Mem:" line, but read the one under them (675404 and 321780 in the example below) and relax.

10.3.11. Invisible disk space consumption

All deleted but open files consumes disk space although they are not visible from normal du(1). They can be listed with their size by:

# lsof -s -X / |grep deleted

10.4. Process operation

10.4.1. Time a process

Display time used by the process invoked by the command.

# time some_command >/dev/null
real    0m0.035s       # time on wall clock (elapsed real time)
user    0m0.000s       # time in user mode
sys     0m0.020s       # time in kernel mode

10.4.2. The scheduling priority

A nice value is used to control the scheduling priority for the process.

Table 10.9.  List of nice values for the scheduling priority.

nice value

scheduling priority

19

lowest priority process (nice)

0

very high priority process for user.

-20

very high priority process for root. (not-nice)


Table 10.10.  List of tools for the scheduling priority.

command

package

popcon

size

function

nice

coreutils

V:86, I:99

11448

run a program with the modified scheduling priority

renice

bsdutils

V:62, I:99

168

modify the scheduling priority of a running processes


# nice  -19 top                                      # very nice
# nice --20 wodim -v -eject speed=2 dev=0,0 disk.img # very fast

Sometimes an extreme nice value does more harm than good to the system. Use this command carefully.

10.4.3. The ps command

The ps(1) command on the Debian support both BSD and SystemV features and helps to identify the process activity statically.

Table 10.11.  List of ps command styles.

style

typical command

feature

BSD

ps aux

display %CPU %MEM

System V

ps -efH

display PPID


For the zombie (defunct) children process, you can kill them by the parent process ID identified in the (PPID) field.

10.4.4. The top command

The top(1) command on the Debian has rich features and helps to identify what process is acting funny dynamically.

Table 10.12.  List of commands for top.

command key

response

h or ?

To show help.

f

To set/reset display field.

o

To reorder display field.

F

To set sort key field.

k

To kill a process.

r

To renice a process.

q

To quit the top command.


10.4.5. Kill a process

Use the kill(1) command to kill (or send a signal to) a process by the process ID.

Use the killall(1) command to do the same by the process command name.

Table 10.13.  List of frequently used signals for kill command.

signal value

signal name

function

1

HUP

restart daemon

15

TERM

normal kill

9

KILL

kill hard


10.4.6. Schedule tasks once

Run the at(1) command to schedule a one-time job:

$ echo 'command -args'| at 3:40 monday

10.4.7. Schedule tasks regularly

Use cron(8) to schedule tasks regularly. See crontab(1) and crontab(5).

Run the command "crontab -e" to create or edit a crontab file to set up regularly scheduled events.

Example of a crontab file:

# use /bin/sh to run commands, no matter what /etc/passwd says
SHELL=/bin/sh
# mail any output to paul, no matter whose crontab this is
MAILTO=paul
# Min Hour DayOfMonth Month DayOfWeek command (Day... are OR'ed)
# run at 00:05, every day
5  0  *  * *   $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 14:15 on the first of every month -- output mailed to paul
15 14 1  * *   $HOME/bin/monthly
# run at 22:00 on weekdays(1-5), annoy Joe. % for newline, last % for cc:
0 22 *   * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%.%%
23 */2 1 2 *   echo "run 23 minutes after 0am, 2am, 4am ..., on Feb 1"
5  4 *   * sun echo "run at 04:05 every sunday"
# run at 03:40 on the first Monday of each month
40 3 1-7 * *   [ "$(date +%a)" == "Mon" ] && command -args
[Tip] Tip

For the system not running continuously, install the anacron package to schedule periodic command at the specified intervals as closely as machine-uptime permits.

10.4.8. Alt-SysRq

Insurance against system malfunction is provided by the kernel compile option "Magic SysRq key" (SAK key) which is now the default for the Debian kernel. Pressing Alt-SysRq followed by one of the following keys does the magic of rescuing control of the system:

Table 10.14.  List of SAK command keys.

key following Alt-SysRq

function

r

Unraw restores the keyboard after things like X crashes.

0

Changing the console loglevel to 0 reduces error messages.

k

SAK (system attention key) kills all processes on the current virtual console.

e

Send a SIGTERM to all processes, except for init.

i

Send a SIGKILL to all processes, except for init.

s

Sync all mounted filesystems.

u

Remount all mounted filesystems read-only (umount).

b

Reboot the system without syncing or unmounting.


The combination of "Alt-SysRq s", "Alt-SysRq u", and "Alt-SysRq r" is good for getting out of really bad situations.

See /usr/share/doc/linux-doc-2.6.*/Documentation/sysrq.txt.gz .

[Caution] Caution

The Alt-SysRq feature may be considered a security risk by allowing users access to root-privileged functions. Placing "echo 0 >/proc/sys/kernel/sysrq" in /etc/rc.local or "kernel.sysrq = 0" in /etc/sysctl.conf will disable the Alt-SysRq feature.

[Tip] Tip

From SSH terminal etc., you can use the Alt-SysRq feature by writing to the /proc/sysrq-trigger. For example, "echo s > /proc/sysrq-trigger; echo u > /proc/sysrq-trigger" from the root shell prompt will sync and umount all mounted filesystems.

10.5. The kernel

Debian distributes modularized Linux kernel as packages for supported architectures.

10.5.1. Linux kernel 2.6

There are few notable features on Linux kernel 2.6 compared to 2.4.

  • Devices are created by the udev system (see Section 4.5.10, “The udev system”).

  • Read/write accesses to IDE CD/DVD devices do not use the ide-scsi module.

  • Network packet filtering functions use iptable kernel modules.

10.5.2. Kernel headers

Most normal programs don't need kernel headers and in fact may break if you use them directly for compiling. They should be compiled against the headers in /usr/include/linux and /usr/include/asm provided by the libc6-dev package (created from the glibc source package) on the Debian system.

[Note] Note

For compiling some kernel-specific programs such as the kernel modules from the external source and the automounter daemon (amd), you must include path to the corresponding kernel headers, e.g. -I/usr/src/linux-particular-version/include/ , to your command line. The module-assistant package helps users to build and install module package(s) easily for one or more custom kernels with the m-a(8) command.

10.5.3. Kernel and module compile

Debian has its own method of compiling the kernel and related modules.

Table 10.15.  List of key packages to be installed for the kernel recompilation on the Debian system

package

popcon

size

description

build-essential

I:38

48

essential packages for building Debian packages: make, gcc, ...

bzip2

V:53, I:81

132

compress and decompress utilities for bz2 files

libncurses5-dev

V:4, I:28

6780

developer's libraries and docs for ncurses

git-core

V:3, I:6

7164

git: distributed revision control system used by the Linux kernel

fakeroot

V:4, I:26

456

provide fakeroot environment for building package as non-root

initramfs-tools

V:16, I:95

408

tool to build an initramfs (Debian specific)

kernel-package

V:3, I:19

2192

tool to build Linux kernel packages (Debian specific)

module-assistant

V:4, I:21

512

tool to help build module packages (Debian specific)

devscripts

V:2, I:13

1536

helper scripts for a Debian Package maintainer (Debian specific)

linux-tree-2.6.*

I:0.03

120

Linux kernel source tree for building Debian kernel images (Debian specific)


If you use initrd in Section 4.3, “Stage 2: the boot loader”, make sure to read the related information in initramfs-tools(8), update-initramfs(8), mkinitramfs(8) and initramfs.conf(5).

[Warning] Warning

Do not put symlinks to the directories in the source tree (e.g. /usr/src/linux*) from /usr/include/linux and /usr/include/asm when compiling the Linux kernel source. (Some outdated documents suggest this.)

[Note] Note

When compiling the latest Linux kernel on the Debian stable system, the use of backported latest tools from the Debian unstable may be needed.

10.5.4. Kernel source compile: Debian standard method

The Debian standard method for compiling kernel source to create a custom kernel package uses make-kpkg(1) command. The official documentation is in (the bottom of) /usr/share/doc/kernel-package/README.gz. See kernel-pkg.conf(5) and kernel-img.conf(5) for customization.

Here is an example for amd64 system:

# aptitude install linux-tree-<version>
$ cd /usr/src
$ tar -xjvf linux-source-<version>.tar.bz2
$ cd linux-source-<version>
$ cp /boot/config-<oldversion> .config
$ make menuconfig
 ...
$ make-kpkg clean
$ fakeroot make-kpkg --append_to_version -amd64 --initrd --revision=rev.01 kernel_image modules_image
$ cd ..
# dpkg -i linux-image*.deb
  • reboot to new kernel with "shutdown -r now" .

[Caution] Caution

When you intend to create a non-modularized kernel compiled only for one machine, invoke make-kpkg command without "--initrd" option since initrd is not used. Invocation of "make oldconfig" and "make dep" are not required since "make-kpkg kernel_image" invokes them.

10.5.5. Module source compile: Debian standard method

The Debian standard method for creating and installing a custom module package for a custom kernel package uses module-assistant(8) command and module-source packages. For example, following will build the unionfs kernel module package and installs it.

$ sudo aptitude install module-assistant
...
$ sudo aptitude install unionfs-source unionfs-tools unionfs-utils
$ sudo m-a update
$ sudo m-a prepare
$ sudo m-a auto-install unionfs
...
$ sudo apt-get autoremove

10.5.6. Kernel source compile: classic method

You can still build Linux kernel from the pristine sources with the classic method. You must take care the details of the system configuration manually.

$ cd /usr/src
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-<version>.tar.bz2
$ tar -xjvf linux-<version>.tar.bz2
$ cd linux-<version>
$ cp /boot/config-<version> .config
$ make menuconfig
 ...
$ make dep; make bzImage
$ make modules
# cp ./arch/x86_64/boot/bzImage /boot/vmlinuz-<version>
# make modules_install
# depmod -a
# update-initramfs -c -k <version>
  • set up bootloader
    • edit /etc/lilo.conf and run /sbin/lilo, if you use lilo .

    • edit /boot/grub/menu.lst, if you use grub .

  • reboot to new kernel with "shutdown -r now" .

10.5.7. Non-free hardware drivers

Although most of hardware drivers are available as free software and as a part of the Debian system, you may need to load some non-free external drivers to support some hardwares, such as Winmodem, on your system.

Check pertinent resources:

10.6. The chroot

The chroot(8) program is most basic way to run different instances of the GNU/Linux environment on a single system simultaneously without rebooting. I will explain simple chroot systems in the following as examples.

For serious chroot setup with the detail configuration, please consider to use the specialized schroot package.

10.6.1. Run a different Debian distribution with chroot

A chroot Debian environment can easily be created by the debootstrap or cdebootstrap command.

For example, the following will create a sid chroot on /sid-root while having fast Internet access:

main # debootstrap sid /sid-root http://ftp.debian.org/debian/
  • watch it download the whole system

main # echo "proc-sid    /sid-root/proc     proc   none 0 0" >> /etc/fstab
main # echo "devpts-sid  /sid-root/dev/pts  devpts defaults 0 0" >> /etc/fstab
main # mount -a
main # cp -f /etc/passwd /sid-root/etc/passwd
main # cp -f /etc/shadow /sid-root/etc/shadow
main # cp -f /etc/group  /sid-root/etc/group
main # cp -f /etc/hosts  /sid-root/etc/hosts
main # chroot /sid-root /bin/bash
chroot # cd /dev; /sbin/MAKEDEV generic ; cd -
chroot # vi /etc/apt/sources.list
  • point the source to unstable

chroot # aptitude update
...
chroot # aptitude install locales
...
  • add "en_US.UTF-8" as locale and make it default

Do you want to continue? [Y/n/?] y
chroot # aptitude install mc vim
...
Do you want to continue? [Y/n/?] y
...
chroot # exit
main #

At this point you should have a fully working Debian sid system, where you can play around without fear of affecting your main Debian installation.

[Caution] Caution

If you use bind mount for directories such as home directory in the chroot, you must be careful for its side effects. I heard people lost their home directory after executing "rm -rf /sid-root" without unbinding their home directory in the chroot. A bind mount is not normally visible with "df", you need to execute "df -a" to see it.

This debootstrap trick can also be used to install Debian to a system without using a Debian install disk, but instead from another GNU/Linux distribution.

10.6.2. Setting up login for chroot

Typing "chroot /sid-root /bin/bash" is easy, but it retains all sorts of environment variables that you may not want, and has other issues. A much better approach is to run another login process on a separate virtual terminal where you can log in to the chroot directly.

Since on default Debian systems tty1 to tty6 run Linux consoles and tty7 runs the X Window System, let's set up tty8 for a chrooted console as an example. After creating a chroot system, type from the root shell of the main system:

main # echo "8:23:respawn:/usr/sbin/chroot /sid-root /sbin/getty 38400 tty8"  >> /etc/inittab
main # init q
  • reload init

10.6.3. Setting up X for chroot

You want to run the latest X and GNOME safely in your chroot? That's entirely possible! The following example will make GDM run on virtual terminal vt9.

First install a chroot system. From the root of the main system, copy key configuration files to the chroot system.

main # cp /etc/X11/xorg.conf /sid-root/etc/X11/xorg.conf
main # chroot /sid-root
chroot # cd /dev; /sbin/MAKEDEV generic ; cd -
chroot # aptitude install gdm gnome x-window-system
chroot # vim /etc/gdm/gdm.conf
  • change "[servers]" section with "s/vt7/vt9/" to make the first virtual console in the chroot from vt7 to vt9.

chroot # /etc/init.d/gdm start

Now you can easily switch back and forth between full X environments in your chroot and your main system just by switching between Linux virtual terminals; e.g. by using Ctrl-Alt-F7 and Ctrl-Alt-F9. Have fun!

10.6.4. Run other distributions with chroot

A chroot environment for another Linux distribution can easily be created. You install a system into separate partitions using the installer of the other distribution. If its root partition is in /dev/hda9:

main # cd / ; mkdir /other-dist
main # mount -t ext3 /dev/hda9 /other-dist
main # chroot /other-dist /bin/bash

10.6.5. Build packages under chroot

There is a more specialized chroot package, pbuilder, which constructs a chroot system and builds a package inside the chroot. It is an ideal system to use to check that a package's build-dependencies are correct, and to be sure that unnecessary and wrong build dependencies will not exist in the resulting package.

10.6.6. Other virtualization tools

There are several system virtualization and emulation related packages in Debian beyond simple chroot.

Table 10.16.  List of virtualization tools

package

pocon

size

description

schroot

V:1.1, I:1.7

1900

Specialized tool for executing Debian binary packages in chroot

sbuild

V:0.07, I:0.3

452

Tool for building Debian binary packages from Debian sources

pbuilder

V:0.6, I:2

1116

Personal package builder for Debian packages

debootstrap

V:1.6, I:11

260

Bootstrap a basic Debian system (written in sh)

cdebootstrap

V:0.5, I:2

156

Bootstrap a Debian system (written in C)

rootstrap

V:0.03, I:0.2

156

A tool for building complete Linux filesystem images

user-mode-linux

V:0.07, I:0.5

17816

User-mode Linux (kernel)

xen-tools

V:0.3, I:2

976

Tools to manage debian XEN virtual server

bochs

V:0.10, I:0.7

3072

IA-32 PC emulator

qemu

V:1.2, I:5

30724

Fast generic processor emulator

virtualbox-ose

V:1.6, I:2

22108

A x86 virtualization solution on i386 and amd64

wine

V:2, I:15

96

Windows API Implementation (standard suite)

dosbox

V:0.6, I:3

2240

A x86 emulator with Tandy/Herc/CGA/EGA/VGA/SVGA graphics, sound and DOS


See Wikipedia article http://en.wikipedia.org/wiki/Comparison_of_virtual_machines for detail comparison of different virtualization solutions.