/[ddp]/manuals/trunk/quick-reference/asciidoc/09_systips.txt
ViewVC logotype

Contents of /manuals/trunk/quick-reference/asciidoc/09_systips.txt

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6738 - (show annotations) (download)
Fri Jun 12 16:50:15 2009 UTC (4 years ago) by osamu
File MIME type: text/plain
File size: 89544 byte(s)
update network and chroot
1 == System tips
2
3 // vim: set sts=2 expandtab:
4 // Use ":set nowrap" to edit table
5
6 Here, I will describe basic tips to configure and manage systems, mostly from the console.
7
8 === The screen program
9
10 `screen`(1) is a very useful tool for people to access remote sites via unreliable or intermittent connections since it support interrupted network connections.
11
12
13 .List of programs to support interrupted network connections.
14 [grid="all"]
15 `--------`-------------`------------`-------------------------------------------------------
16 package popcon size description
17 --------------------------------------------------------------------------------------------
18 `screen` @@@popcon1@@@ @@@psize1@@@ terminal multiplexer with VT100/ANSI terminal emulation
19 --------------------------------------------------------------------------------------------
20
21 // xmove not in lenny
22 // || {{{xmove}}} || - || - || allows you to move programs between X Window System displays ||
23
24 ==== The use scenario for screen(1)
25
26 `screen`(1) not only allows one terminal window to work with multiple processes, but also allows **remote shell process to survive interrupted connections**. Here is a typical use scenario of `screen`(1).
27
28 1. You login to a remote machine.
29 2. You start `screen` on a single console.
30 3. You execute multiple programs in `screen` windows created with `\^A c` ("Control-A" followed by "c").
31 4. You switch among the multiple `screen` windows by `\^A n` ("Control-A" followed by "n").
32 5. Suddenly you need to leave your terminal, but you don\'t want to lose your active work by keeping the connection.
33 6. You **detach** the `screen` session by any methods such as:
34 * brutally unplugging your network connection,
35 * typing `\^A d` ("Control-A" followed by "d") and manually logging out from the remote connection, or
36 * typing `\^A DD` ("Control-A" followed by "DD") to have `screen` detach and log you out.
37 7. You log in again to the same remote machine (even from a different terminal).
38 8. You start `screen` as "`screen -r`".
39 9. `screen` will magically **reattach** all previous `screen` windows with all actively running programs.
40
41 TIP: You can save connection fees for metered network connections such as dial-up and packet ones, because you can leave a process active while disconnected, and then re-attach it later when you connect again.
42
43 ==== Key bindings for the screen command
44
45 In a `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:
46
47
48 .List of key bindings for screen.
49 [grid="all"]
50 `-----------`-------------------------------------------------
51 key binding meaning
52 --------------------------------------------------------------
53 `\^A ?` show a help screen (display key bindings)
54 `\^A c` create a new window and switch to it
55 `\^A n` go to next window
56 `\^A p` go to previous window
57 `\^A 0` go to window number 0
58 `\^A 1` go to window number 1
59 `\^A w` show a list of windows
60 `\^A a` send a Ctrl-A to current window as keyboard input
61 `\^A h` write a hardcopy of current window to file
62 `\^A H` begin/end logging current window to file
63 `\^A \^X` lock the terminal (password protected)
64 `\^A d` detach screen session from the terminal
65 `\^A DD` detach screen session and log out
66 --------------------------------------------------------------
67
68 See `screen`(1) for details.
69
70 // xmove removed from lenny
71 // === A screen-like program for X window system ===
72 // The {{{xmove}}} package enables support for mobile X clients; that is, X clients can move between displays. See {{{xmove}}}(1).
73
74 === Data recording and presentation
75
76 ==== The log daemon
77
78 Many programs record their activities under the "`/var/log/`" directory.
79
80 - The kernel log daemon: `klogd`(8)
81 - The system log daemon: `syslogd`(8)
82
83 See <<_the_system_message>> and <<_the_kernel_message>>.
84
85 ==== Log analyzer
86
87 Here are notable log analyzers ("`\~Gsecurity::log-analyzer`" in `aptitude`(8)).
88
89
90 .List of system log analyzers.
91 [grid="all"]
92 `----------------`-------------`------------`-----------------------------------------------------------
93 package popcon size description
94 --------------------------------------------------------------------------------------------------------
95 `logwatch` @@@popcon1@@@ @@@psize1@@@ log analyser with nice output written in Perl
96 `fail2ban` @@@popcon1@@@ @@@psize1@@@ bans IPs that cause multiple authentication errors
97 `analog` @@@popcon1@@@ @@@psize1@@@ web server log analyzer
98 `awstats` @@@popcon1@@@ @@@psize1@@@ powerful and featureful web server log analyzer
99 `sarg` @@@popcon1@@@ @@@psize1@@@ squid analysis report generator
100 `pflogsumm` @@@popcon1@@@ @@@psize1@@@ Postfix log entry summarizer
101 `syslog-summary` @@@popcon1@@@ @@@psize1@@@ summarize the contents of a syslog log file
102 `lire` @@@popcon1@@@ @@@psize1@@@ full-featured log analyzer and report generator
103 `fwlogwatch` @@@popcon1@@@ @@@psize1@@@ Firewall log analyzer
104 `squidview` @@@popcon1@@@ @@@psize1@@@ monitors and analyses squid access.log files
105 `visitors` @@@popcon1@@@ @@@psize1@@@ fast web server log analyzer
106 `swatch` @@@popcon1@@@ @@@psize1@@@ Log file viewer with regexp matching, highlighting, & hooks
107 `crm114` @@@popcon1@@@ @@@psize1@@@ The Controllable Regex Mutilator and Spam Filter (CRM114)
108 `icmpinfo` @@@popcon1@@@ @@@psize1@@@ Interpret ICMP messages
109 --------------------------------------------------------------------------------------------------------
110
111 NOTE: http://crm114.sourceforge.net/[CRM114] provides language infrastructure to write **fuzzy** filters with the http://www.laurikari.net/tre/[TRE regex library]. Its popular use is spam mail filter but it can be used as log analyzer.
112
113 // only I greater than or equal to 0.2 are visible. Rests say below.
114 //|| {{{acidbase}}} || - || - || Basic Analysis and Security Engine ||
115 //|| {{{acidlab}}} || - || - || Analysis Console for Intrusion Databases ||
116 //|| {{{anteater}}} || - || - || MTA log analyser written 100% in C++ ||
117 //|| {{{asql}}} || - || - || Run SQL queries against apache logs ||
118 //|| {{{awffull}}} || - || - || web server log analysis program ||
119 //|| {{{fwanalog}}} || - || - || firewall log-file report generator (using analog) ||
120 //|| {{{graphdefang}}} || - || - || grapher for MIMEDefang spam and virus logs ||
121 //|| {{{ip2host}}} || - || - || Resolve IPs to hostnames in web server logs ||
122 //|| {{{isoqlog}}} || - || - || Mail Transport Agent log analysis program ||
123 //|| {{{jdresolve}}} || - || - || fast alternative to apache logresolve ||
124 //|| {{{logtool}}} || - || - || Syslog-style logfile parser with lots of output options ||
125 //|| {{{logtools}}} || - || - || Russell's misc tools for managing log files. ||
126 //|| {{{lwatch}}} || - || - || A simple log colorizer ||
127 //|| {{{modlogan}}} || - || - || A modular logfile analyzer ||
128 //|| {{{prelude-lml}}} || - || - || Hybrid Intrusion Detection System [ Log Monitoring Lackey ] ||
129 //|| {{{prom-mew}}} || - || - || procmail reader for Mew ||
130 //|| {{{rmagic}}} || - || - || Report Magic for Analog ||
131 //|| {{{sma}}} || - || - || Sendmail log analyser ||
132 //|| {{{squidtaild}}} || - || - || Squid log monitoring program ||
133 //|| {{{tcpxtract}}} || - || - || extracts files from network traffic based on file signatures ||
134 //|| {{{tenshi}}} || - || - || log monitoring and reporting tool ||
135 //|| {{{tua}}} || - || - || The UUCP Analyzer ||
136 //|| {{{uutraf}}} || - || - || an UUCP traffic analyzer and cost estimator ||
137 //|| {{{wflogs}}} || - || - || The modular firewall log analyzer of the WallFire project ||
138 //|| {{{wwwstat}}} || - || - || httpd logfile analysis package ||
139
140 ==== Recording the shell activities cleanly
141
142 The simple use of `script`(1) (see <<_recording_the_shell_activities>>) to record shell activity produces a file with control characters. This can be avoided by using `col`(1):
143
144 --------------------
145 $ script
146 Script started, file is typescript
147 --------------------
148
149 - do whatever ...
150 - Press `Ctrl-D` to exit `script`
151
152 --------------------
153 $ col -bx <typescript >cleanedfile
154 $ vim cleanedfile
155 --------------------
156
157 If you don\'t have `script` (for example, during the boot process in the initramfs), you can use following instead:
158
159 --------------------
160 $ sh -i 2>&1 | tee typescript
161 --------------------
162
163 TIP: Some `x-terminal-emulator` such as `gnome-terminal` can record. You may wish to extend line buffer for scrollback.
164
165 TIP: You may use `screen`(1) with "`\^A H`" (see <<_key_bindings_for_the_screen_command>>) to perform recording of console.
166
167 TIP: You may use `emacs`(1) 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.
168
169 ==== Customized display of text data
170
171 Although pager tools such as `more`(1) and `less`(1) (see <<_the_pager>>) and custom tools for highlighting and formatting <<_highlighting_and_formatting_plain_text_data>> can display text data nicely, general purpose editors (see <<_the_text_editor>>) are most versatile and customizable.
172
173 TIP: For `vim`(1) and its pager mode alias `view`(1), "`:set hls`" will enable highlighted search.
174
175 ==== Customized display of time and date
176
177 The default display format of time and date by the "`ls -l`" command depends on the **locale** (see value <<_timestamps>>). The "`$LANG`" variable is referred first and it can be overridden by the "`$LC_TIME`" variable.
178
179 The actual default display format for each locale depends on the version of the standard C library (the `libc6` package) used. I.e., different releases of Debian had different defaults.
180
181 If you really wish to customize this display format of time and date beyond the **locale**, you should set the **time style value** by the "`--time-style`" argument or by the "`$TIME_STYLE`" value (see `ls`(1), `date`(1), "`info coreutils \'ls invocation\'`").
182
183
184 .Display examples of time and date for the "`ls -l`" command for `lenny`.
185 [grid="all"]
186 `-----------------`--------------------`-------------------------------------
187 time style value locale display of time and date
188 -----------------------------------------------------------------------------
189 `iso` __any__ `01-19 00:15`
190 `long-iso` __any__ `2009-01-19 00:15`
191 `full-iso` __any__ `2009-01-19 00:15:16.000000000 +0900`
192 `locale` `C` `Jan 19 00:15`
193 `locale` `en_US.UTF-8` `2009-01-19 00:15`
194 `locale` `es_ES.UTF-8` `ene 19 00:15`
195 `+%d.%m.%y %H:%M` __any__ `19.01.09 00:15`
196 `+%d.%b.%y %H:%M` `C` or `en_US.UTF-8` `19.Jan.09 00:15`
197 `+%d.%b.%y %H:%M` `es_ES.UTF-8` `19.ene.09 00:15`
198 -----------------------------------------------------------------------------
199
200 TIP: You can eliminate typing long option on commandline using command alias, e.g. "`alias ls=\'ls --time-style=+%d.%m.%y\ %H:%M\'`" (see <<_command_alias>>).
201
202 TIP: http://en.wikipedia.org/wiki/ISO_8601[ISO 8601] is followed for these iso-formats.
203
204 ==== Colorized shell echo
205
206 Shell echo to most modern terminals can be colorized using http://en.wikipedia.org/wiki/ANSI_escape_code[ANSI escape code] (see "`/usr/share/doc/xterm/ctlseqs.txt.gz`"). E.g.:
207
208 --------------------
209 $ RED=$(printf "\x1b[31m")
210 $ NORMAL=$(printf "\x1b[0m")
211 $ REVERSE=$(printf "\x1b[7m")
212 $ echo "${RED}RED-TEXT${NORMAL} ${REVERSE}REVERSE-TEXT${NORMAL}"
213 --------------------
214
215 // I use "printf" here instead of "echo -e" for shell portability.
216
217 ==== Colorized commands
218
219 Colorized commands are handy for inspecting their output in the interactive environment. I include following in my "`\~/.bashrc`".
220
221 --------------------
222 if [ "$TERM" != "dumb" ]; then
223 eval "`dircolors -b`"
224 alias ls='ls --color=always'
225 alias ll='ls --color=always -l'
226 alias la='ls --color=always -A'
227 alias less='less -R'
228 alias ls='ls --color=always'
229 alias grep='grep --color=always'
230 alias egrep='egrep --color=always'
231 alias fgrep='fgrep --color=always'
232 alias zgrep='zgrep --color=always'
233 else
234 alias ll='ls -l'
235 alias la='ls -A'
236 fi
237 --------------------
238
239 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`(1). If you wish to surpress color when piping to other programs, use "`--color=auto`" instead in the above example for "`\~/.bashrc`".
240
241 TIP: You can turn off these colorizing aliases in the interactive environment by invoking shell with "`TERM=dumb bash`".
242
243 ==== Recording the graphic image of an X application
244
245 There are few ways to record the graphic image of an X application, including an `xterm` display.
246
247
248 .List of graphic image manipulation tools.
249 [grid="all"]
250 `---------------`-------------`------------`-----------
251 package popcon size command
252 -------------------------------------------------------
253 `xbase-clients` @@@popcon1@@@ @@@psize1@@@ `xwd`(1)
254 `gimp` @@@popcon1@@@ @@@psize1@@@ GUI menu
255 `imagemagick` @@@popcon1@@@ @@@psize1@@@ `import`(1)
256 `scrot` @@@popcon1@@@ @@@psize1@@@ `scrot`(1)
257 -------------------------------------------------------
258
259 ==== Recording changes in configuration files
260
261 There are specialized tools to record changes in configuration files with help of DVCS system.
262
263
264 .List of packages to record configuration history in VCS.
265 [grid="all"]
266 `-------------`-------------`------------`------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
267 package popcon size description
268 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
269 `etckeeper` @@@popcon1@@@ @@@psize1@@@ store configuration files and its metadata with http://en.wikipedia.org/wiki/Git_(software)[Git] (default), http://en.wikipedia.org/wiki/Mercurial_(software)[Mercurial], or http://en.wikipedia.org/wiki/Bazaar_(software)[Bazaar]. (new)
270 `changetrack` @@@popcon1@@@ @@@psize1@@@ store configuration files with http://en.wikipedia.org/wiki/Revision_Control_System[RCS]. (old)
271 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
272
273 I recommend to use the `etckeeper` package with `git`(1) which put entire "`/etc`" under VCS control. Its installation guide and tutorial are found in "`/usr/share/doc/etckeeper/README.gz`".
274
275 Essentially, running "`sudo etckeeper init`" initializes the git repository for "`/etc`" just like the process explained in <<_git_for_recording_configuration_history>>) but with special hook scripts for more thorough setups.
276
277 As you change your configuration, you can use `git`(1) normally to record them. It will automatically record changes nicely every time you run package management commands, too.
278
279 TIP: You can browse the change history of "`/etc`" by executing "`sudo GIT_DIR=/etc/.git gitk`" with clear view for new installed packages, removed packages, and version changes of packages.
280
281 === Data storage tips
282
283 Booting your system with Linux http://en.wikipedia.org/wiki/Live_CD[live CDs] or http://www.debian.org/releases/stable/debian-installer/[debian-installer CDs] in rescue mode make it easy for you to reconfigure data storage on your boot device. See also <<_the_binary_data>>.
284
285 ==== Partition configuration
286
287 For partition configuration, although `fdisk`(8) has been considered standard, `parted`(8) deserves some attention. "Disk partitioning data", "partition table", "partition map", and "disk label" are all synonyms.
288
289 Most PCs use the classic http://en.wikipedia.org/wiki/Master_boot_record[Master Boot Record (MBR)] scheme to hold http://en.wikipedia.org/wiki/Disk_partitioning[disk partitioning] data in the first sector, i.e., http://en.wikipedia.org/wiki/Logical_block_addressing[LBA] sector 0 (512 bytes).
290
291 NOTE: Some new PCs with http://en.wikipedia.org/wiki/Extensible_Firmware_Interface[Extensible Firmware Interface (EFI)], including Intel-based Macs, use http://en.wikipedia.org/wiki/GUID_Partition_Table[GUID Partition Table (GPT)] scheme to hold http://en.wikipedia.org/wiki/Disk_partitioning[disk partitioning] data not in the first sector.
292
293 Although `fdisk`(8) has been standard for the disk partitioning tool, `parted`(8) is replacing it.
294
295
296 .List of disk partition management packages
297 [grid="all"]
298 `------------`-------------`------------`-------------------------------------------------------------------`-----------------------------------------------------------------------
299 package pocon size description http://en.wikipedia.org/wiki/GUID_Partition_Table[GUID Partition Table]
300 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
301 `util-linux` @@@popcon1@@@ @@@psize1@@@ Miscellaneous system utilities including `fdisk`(8) and `cfdisk`(8) Not supported
302 `parted` @@@popcon1@@@ @@@psize1@@@ The GNU Parted disk partition resizing program Supported
303 `gparted` @@@popcon1@@@ @@@psize1@@@ GNOME partition editor based on `libparted` Supported
304 `qtparted` @@@popcon1@@@ @@@psize1@@@ KDE partition editor based on `libparted` Supported
305 `gptsync` @@@popcon1@@@ @@@psize1@@@ Synchronize classic MBR partition table with the GPT one Supported
306 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
307
308 // || {{{gnu-fdisk}}} || - || - || GNU replacements of console {{{fdisk}}}(8) and {{{cfdisk}}}(8) based on {{{libparted}}} || Supported () ||
309 // Exclusion of gnu-fdisk is intentional since it is little used and buggy from BTS.
310 // It does not list disk label like parted.
311 // parted family is new and recommended here.
312
313 CAUTION: Although `parted`(8) claims to create and to resize filesystem too, it is safer to do such things using best maintained specialized tools such as `mkfs`(8) (`mkfs.msdos`(8), `mkfs.ext2`(8), `mkfs.ext3`(8), ...) and `resize2fs`(8).
314
315 NOTE: In order to switch between GPT and MBR, you need to erase first few blocks of disk contents directly (see <<_clear_file_contents>>) and use "`parted /dev/sdx mklabel gpt`" or "`parted /dev/sdx mklabel msdos`" to set it. Please note "`msdos`" is use here for http://en.wikipedia.org/wiki/Master_boot_record[MBR].
316
317 ==== Accessing partition using UUID
318
319 Although reconfiguration of your partition may yield different names for partitions, you can access them consistently. This is also helpful if you have multiple disks and your BIOS doesn\'t give them consistent device names.
320
321
322 - `mount`(8) with "`-U`" options can mount a block device using http://en.wikipedia.org/wiki/Universally_Unique_Identifier[UUID], instead of using its file name such as "`/dev/sda3`".
323 - "`/etc/fstab`" (see `fstab`(5)) can use http://en.wikipedia.org/wiki/Universally_Unique_Identifier[UUID].
324 - Boot loaders (<<_stage_2_the_boot_loader>>) may use http://en.wikipedia.org/wiki/Universally_Unique_Identifier[UUID] too.
325
326 TIP: You can probe http://en.wikipedia.org/wiki/Universally_Unique_Identifier[UUID] of a block special device with `vol_id`(8).
327
328 ==== Filesystem configuration
329
330 For http://en.wikipedia.org/wiki/Ext3[ext3] filesystem, the `e2fsprogs` package provides:
331
332 - `mkfs.ext3`(8) to create new http://en.wikipedia.org/wiki/Ext3[ext3] filesystem,
333 - `fsck.ext3`(8) to check and to repair existing http://en.wikipedia.org/wiki/Ext3[ext3] filesystem, and
334 - `tune2fs`(8) to configure superblock of http://en.wikipedia.org/wiki/Ext3[ext3] filesystem.
335
336 The `mkfs`(8) and `fsck`(8) commans are provided by the `e2fsprogs` package as front-ends to various filesystem dependent programs (`mkfs.fstype` and `fsck.fstype`). For http://en.wikipedia.org/wiki/Ext3[ext3] filesystem, they are `mkfs.ext3`(8) and `fsck.ext3`(8) (they are hardlinked to `mke2fs`(8) and `e2fsck`(8)).
337
338 Similar commands are available for each filesystem supported by Linux.
339
340
341 .List of filesystem management packages
342 [grid="all"]
343 `---------------`-------------`------------`------------------------------------------------------------------------------------------------------------------------------------------------------
344 package popcon size description
345 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
346 `e2fsprogs` @@@popcon1@@@ @@@psize1@@@ Utilities for the http://en.wikipedia.org/wiki/Ext2[ext2]/http://en.wikipedia.org/wiki/Ext3[ext3]/http://en.wikipedia.org/wiki/Ext4[ext4] filesystems.
347 `reiserfsprogs` @@@popcon1@@@ @@@psize1@@@ Utilities for the http://en.wikipedia.org/wiki/Reiserfs[Reiserfs] filesystem.
348 `dosfstools` @@@popcon1@@@ @@@psize1@@@ Utilities for the http://en.wikipedia.org/wiki/File_Allocation_Table[FAT] filesystem. (Microsoft: MS-DOS, Windows)
349 `xfsprogs` @@@popcon1@@@ @@@psize1@@@ Utilities for the http://en.wikipedia.org/wiki/XFS[XFS] filesystem. (SGI: IRIX)
350 `ntfsprogs` @@@popcon1@@@ @@@psize1@@@ Utilities for the http://en.wikipedia.org/wiki/NTFS[NTFS] filesystem. (Microsoft: Windows NT, ...)
351 `jfsutils` @@@popcon1@@@ @@@psize1@@@ Utilities for the http://en.wikipedia.org/wiki/JFS_(file_system)[JFS] filesystem. (IBM: AIX, OS/2)
352 `reiser4progs` @@@popcon1@@@ @@@psize1@@@ Utilities for the http://en.wikipedia.org/wiki/Reiser4[Reiser4] filesystem.
353 `hfsprogs` @@@popcon1@@@ @@@psize1@@@ Utilities for http://en.wikipedia.org/wiki/Hierarchical_File_System[HFS] and http://en.wikipedia.org/wiki/HFS_Plus[HFS Plus] filesystem. (Apple: Mac OS)
354 `btrfs-tools` @@@popcon1@@@ @@@psize1@@@ Utilities for the http://en.wikipedia.org/wiki/Btrfs[btrfs] filesystem.
355 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
356
357 TIP: http://en.wikipedia.org/wiki/Ext3[Ext3] filesystem is the default filesystem for the Linux system and strongly recommended to use it unless you have some specific reasons not to. After Linux kernel 2.6.28 (Debian `squeeze`), http://en.wikipedia.org/wiki/Ext4[ext4] filesystem will be available and expected to be the default filesystem for the Linux system. http://en.wikipedia.org/wiki/Btrfs[btrfs] filesystem is expected to be the next default filesystem after http://en.wikipedia.org/wiki/Ext4[ext4] filesystem for the Linux system.
358
359 WARNING: You might face some limtations with ext4 since it is new. For example, you must have Linux kernel 2.6.30 or later if you wish to resizean ext4 partition.
360
361 TIP: Some tools allow access to filesystem without Linux kernel support (see <<_manipulating_files_without_mounting_disk>>).
362
363 ==== Filesystem creation and integrity check
364
365 The `mkfs`(8) command creates the filesystem on a Linux system. The `fsck`(8) command provides the filesystem integrity check and repair on a Linux system.
366
367 CAUTION: It is generally not safe to run `fsck` on **mounted filesystems**.
368
369 TIP: Check files in "`/var/log/fsck/`" for the result of the `fsck`(8) command run from the boot script.
370
371 TIP: Use "`shutdown -F -r now`" to force to run the `fsck`(8) command safely on all filesystems including root file system on reboot. See the `shutdown`(8) manpage for more.
372
373 ==== Optimization of filesystem by mount options
374
375 Performance and characteristics of a filesystem can be optimized by mount options used on it (see `fstab`(5) and `mount`(8)). For example:
376
377
378 - "`defaults`" option implies default options: "`rw,suid,dev,exec,auto,nouser,async`". (general)
379 - "`noatime`" or "`relatime`" option is very effective for speeding up the read access. (general)
380 - "`user`" option allows an ordinary user to mount the file system. This option implies "`noexec,nosuid,nodev`" option combination. (general, used for CD and floppy)
381 - "`noexec,nodev,nosuid`" option combination is used to enhance security. (general)
382 - "`noauto`" option limits mounting by explicit operation only. (general)
383 - "`data=journal`" option for ext3fs can enhance data integrity against power failure with some loss of write speed.
384
385 TIP: You need to provide kernel boot parameter "`rootflags=data=journal`" to deploy "`data=journal`" option for the root file system formatted with ext3fs.
386
387 ==== Optimization of filesystem via superblock
388
389 Characteristics of a filesystem can be optimized via its superblock using the `tune2fs`(8) command. For example on "`/dev/hda1`":
390
391
392 - Execution of "`sudo tune2fs -l /dev/hda1`" will display the contents of its filesystem superblock.
393 - Execution of "`sudo tune2fs -c 50 /dev/hda1`" will change frequency of filesystem checks (`fsck` execution during boot-up) to every 50 boots.
394 - Execution of "`sudo tune2fs -j /dev/hda1`" will add journaling capability to the filesystem, i.e. filesystem conversion from http://en.wikipedia.org/wiki/Ext2[ext2] to http://en.wikipedia.org/wiki/Ext3[ext3]. (Do this on the unmounted filesystem.)
395 - Execution of "`sudo tune2fs -O extents,uninit_bg,dir_index /dev/hda1 && fsck -pf /dev/hda1`" will convert it from http://en.wikipedia.org/wiki/Ext3[ext3] to http://en.wikipedia.org/wiki/Ext4[ext4]. (Do this on the unmounted filesystem.)
396
397 WARNING: Filesystem conversion for the boot device to the http://en.wikipedia.org/wiki/Ext4[ext4] filesystem should be avoided until http://bugs.debian.org/511121[GRUB boot loader supports the ext4 filesystem well] and installed Linux Kernel version is newer than 2.6.28.
398
399 TIP: Despite its name, `tune2fs`(8) works not only on the http://en.wikipedia.org/wiki/Ext2[ext2] filesystem but also on the http://en.wikipedia.org/wiki/Ext3[ext3] and http://en.wikipedia.org/wiki/Ext4[ext4] filesystems.
400
401 ==== Optimization of harddisk
402
403 WARNING: 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.
404
405 You can test disk access speed of a harddisk, e.g. "`/dev/hda`", by "`hdparm -tT /dev/hda`". For some harddisk connected with (E)IDE, you can speed it up with "`hdparm -q -c3 -d1 -u1 -m16 /dev/hda`" by enabling the "(E)IDE 32-bit I/O support", enabling the "using_dma flag", setting "interrupt-unmask flag", and setting the "multiple 16 sector I/O" (dangerous!).
406
407 You can test write cache feature of a harddisk, e.g. "`/dev/sda`", by "`hdparm -W /dev/sda`". You can disable its write cache feature with "`hdparm -W 0 /dev/sda`".
408
409 You may be able to read badly pressed CDROMs on modern high head CD-ROM drive by slowing it down with "`setcd -x 2`.
410
411 ==== Using SMART to predict harddisk failure
412
413 You can monitor and log your harddisk which is compliant to http://en.wikipedia.org/wiki/S.M.A.R.T[SMART] with the `smartd`(8) daemon.
414
415 1. Enable http://en.wikipedia.org/wiki/S.M.A.R.T[SMART] feature in http://en.wikipedia.org/wiki/BIOS[BIOS].
416 2. Install the `smartmontools` package.
417 3. Identify your harddisk drives by listing them with `df`(1).
418 * Let\'s assume a harddisk drive to be monitored as "`/dev/hda`".
419 4. Check the output of "`smartctl -a /dev/hda`" to see if http://en.wikipedia.org/wiki/S.M.A.R.T[SMART] feature is actually enabled.
420 * If not, enable it by "`smartctl -s on -a /dev/hda`".
421 5. Enable `smartd`(8) daemon to run by:
422 * uncomment "`start_smartd=yes`" in the "`/etc/default/smartmontools`" file.
423 * restart the `smartd`(8) daemon by "`sudo /etc/init.d/smartmontools restart`".
424
425 TIP: The `smartd`(8) daemon can be customized with the `/etc/smartd.conf` file including how to be notified of warnings.
426
427 ==== Expand usable storage space via LVM
428
429 For partitions created on http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)[Logical Volume Manager (Linux)] at install time, they can be resized easily by concatenating extents onto them or truncating extents from them over multiple storage devices without major system reconfiguration.
430
431 CAUTION: Deployment of the current LVM system may degrade guarantee against filesystem corruption offered by journaled file systems such as ext3fs unless their system performance is sacrificed by disabling write cache of harddisk.
432
433 ==== Expand usable storage space by mounting another partition
434
435 If you have an empty partition (e.g., "`/dev/sdx`"), you can format it with `mkfs.ext3`(1) and `mount`(8) it to a directory where you need more space. (You need to copy original data contents.)
436
437 --------------------
438 $ sudo mv work-dir old-dir
439 $ sudo mkfs.ext3 /dev/sdx
440 $ sudo mount -t ext3 /dev/sdx work-dir
441 $ sudo cp -a old-dir/* work-dir
442 $ sudo rm -rf old-dir
443 --------------------
444
445 ==== Expand usable storage space using symlink
446
447 If you have an empty directory (e.g., "`/path/to/emp-dir`") in another partition with usable space, you can create a symlink to the directory with `ln`(8).
448
449 --------------------
450 $ sudo mv work-dir old-dir
451 $ sudo mkdir -p /path/to/emp-dir
452 $ sudo ln -sf /path/to/emp-dir work-dir
453 $ sudo cp -a old-dir/* work-dir
454 $ sudo rm -rf old-dir
455 --------------------
456 CAUTION: Some software may not function well with "symlink to a directory".
457
458 ==== Expand usable storage space using aufs
459
460 If you have usable space in another partition (e.g., "`/path/to/`"), you can create a directory in it and stack that on to a directory where you need space with http://en.wikipedia.org/wiki/Aufs[aufs].
461
462
463 --------------------
464 $ sudo mv work-dir old-dir
465 $ sudo mkdir -p /path/to/emp-dir
466 $ sudo mount -t aufs -o br:/path/to/emp-dir:old-dir none work-dir
467 --------------------
468
469 CAUTION: Use of http://en.wikipedia.org/wiki/Aufs[aufs] for long term data storage is not good idea since it is under development and its design change may introduce issues.
470
471 TIP: In order to use http://en.wikipedia.org/wiki/Aufs[aufs], its utility package `aufs-tools` and kernel module package for http://en.wikipedia.org/wiki/Aufs[aufs] such as `aufs-modules-2.6-amd64` need to be installed.
472
473 TIP: http://en.wikipedia.org/wiki/Aufs[aufs] is used to provide writable root filesystem by many modern http://en.wikipedia.org/wiki/Live_CD[live CD] projects.
474
475 === Data encryption tips
476
477 With physical access to your PC, anyone can easily gain root privilege and access all the files on your PC (see <<_securing_the_root_password>>). This means that login password system can not secure your private and sensitive data against possible theft of your PC. You must deploy data encryption technology to do it. Although http://en.wikipedia.org/wiki/GNU_Privacy_Guard[GNU privacy guard] (see <<_data_security_infrastructure>>) can encrypt files, it takes some user efforts.
478
479 http://en.wikipedia.org/wiki/Dm-crypt[dm-crypt] and http://ecryptfs.sourceforge.net/[eCryptfs] facilitates automatic data encryption natively via Linux kernel modules with minimal user efforts.
480
481 .List of data encryption utilities.
482 [grid="all"]
483 `----------------`-------------`------------`----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
484 package popcon size function
485 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
486 `cryptsetup` @@@popcon1@@@ @@@psize1@@@ Utilities for encrypted block device (http://en.wikipedia.org/wiki/Dm-crypt[dm-crypt] / http://en.wikipedia.org/wiki/Linux_Unified_Key_Setup[LUKS])
487 `cryptmount` @@@popcon1@@@ @@@psize1@@@ Utilities forencrypted block device (http://en.wikipedia.org/wiki/Dm-crypt[dm-crypt] / http://en.wikipedia.org/wiki/Linux_Unified_Key_Setup[LUKS]) with focus on mount/unmount by normal users
488 `ecryptfs-utils` @@@popcon1@@@ @@@psize1@@@ Utilities for encrypted stacked filesystem (http://ecryptfs.sourceforge.net/[eCryptfs])
489 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
490
491 http://en.wikipedia.org/wiki/Dm-crypt[Dm-crypt] is a cryptographic filesystem using http://en.wikipedia.org/wiki/Device_mapper[device-mapper]. http://en.wikipedia.org/wiki/Device_mapper[Device-mapper] maps one block device to another.
492
493 http://ecryptfs.sourceforge.net/[eCryptfs] is another cryptographic filesystem using stacked filesystem. Stacked filesystem stacks itself on top of an existing directory of a mounted filesystem.
494
495 CAUTION: Data encryption costs CPU time etc. Please weigh its benefits and costs.
496
497 NOTE: Entire Debian system can be installed on a encrypted disk by the http://www.debian.org/devel/debian-installer/[debian installer] (lenny or newer) using http://en.wikipedia.org/wiki/Dm-crypt[dm-crypt]/http://en.wikipedia.org/wiki/Linux_Unified_Key_Setup[LUKS] and initramfs.
498
499 TIP: See <<_data_security_infrastructure>> for user space encryption utility: http://en.wikipedia.org/wiki/GNU_Privacy_Guard[GNU Privacy Guard].
500
501 ==== Removable disk encryption with dm-crypt/LUKS
502
503 You can encrypt contents of removable mass storage devices, e.g. USB memory stick on "`/dev/sdx`", using http://en.wikipedia.org/wiki/Dm-crypt[dm-crypt]/http://en.wikipedia.org/wiki/Linux_Unified_Key_Setup[LUKS]. You simply formatting it as:
504
505 --------------------
506 # badblocks -c 10240 -s -w -t random -v /dev/sdx
507 # shred -v -n 1 /dev/sdx
508 # fdisk /dev/sdx
509 ... "n" "p" "1" "return" "return" "w"
510 # cryptsetup luksFormat /dev/sdx1
511 ...
512 # cryptsetup luksOpen /dev/sdx1 sdx1
513 ...
514 # ls -l /dev/mapper/
515 total 0
516 crw-rw---- 1 root root 10, 60 2008-10-04 18:44 control
517 brw-rw---- 1 root disk 254, 0 2008-10-04 23:55 sdx1
518 # mkfs.vfat /dev/mapper/sdx1
519 ...
520 # cryptsetup luksClose sdx1
521 --------------------
522 Then, it can be mounted just like normal one on to "`/media/<disk_label>`", except for asking password (see <<_removable_mass_storage_device>>) under modern desktop environment, such as GNOME using `gnome-mount`(1). The difference is that every data written to it is encrypted. You may alternatively format media in different file format, e.g., ext3 with "`mkfs.ext3 /dev/sdx1`".
523
524 NOTE: If you are really paranoid for the security of data, you may need to overwrite multiple times in the above example. This operation is very time consuming though.
525
526 ==== Encrypted swap partition with dm-crypt
527
528 If your original "`/etc/fstab`" contains:
529 --------------------
530 /dev/sda7 swap sw 0 0
531 --------------------
532 then you can enable encrypted swap partition using http://en.wikipedia.org/wiki/Dm-crypt[dm-crypt] by as
533 --------------------
534 # aptitude install cryptsetup
535 # swapoff -a
536 # echo "cswap /dev/sda7 /dev/urandom swap" >> /etc/crypttab
537 # perl -i -p -e "s/\/dev\/sda7/\/dev\/mapper\/cswap/" /etc/fstab
538 # /etc/init.d/cryptdisks restart
539 ...
540 # swapon -a
541 --------------------
542
543 ==== Automatically encrypting files with eCryptfs
544
545 You can encrypt files written under "`\~/Private/`" automatically using http://ecryptfs.sourceforge.net/[eCryptfs] and the `ecryptfs-utils` package.
546
547 - run `ecryptfs-setup-private`(1) and set up "`\~/Private/`" by following prompts.
548 - activate "`\~/Private/`" by running `ecryptfs-mount-private`(1).
549 - move sensitive data files to "`\~/Private/`" and make symlinks as needed.
550 * candidates: "`\~/.fetchmailrc`", "`\~/.ssh/identity`", "`\~/.ssh/id_rsa`", "`\~/.ssh/id_dsa`" and other files with "`go-rwx`".
551 - move sensitive data directories to a subdirectory in "`\~/Private/`" and make symlinks as needed.
552 * candidates: "`\~/.gnupg`" and other directories with "`go-rwx`".
553 - create symlink from "`\~/Desktop/Private/`" to "`\~/Private/`" for easier desktop operations.
554 - deactivate "`\~/Private/`" by running `ecryptfs-umount-private`(1).
555 - activate "`\~/Private/`" by issuing "`ecryptfs-mount-private`" as you need encrypted data.
556
557 TIP: Since http://ecryptfs.sourceforge.net/[eCryptfs] selectively encrypt only the sensitive files, its system cost is much less than using http://en.wikipedia.org/wiki/Dm-crypt[dm-crypt] on the entire root or home device. It does not require any special on-disk storage allocation effort but cannot keep all filesystem metadata confidential.
558
559
560 ==== Automatically mounting eCryptfs
561
562 If you use your login password for wrapping encryption keys, you can automate mounting eCryptfs via
563 Pluggable Authentication Module by having a following line just before "`pam_permit.so`" in "`/etc/pam.d/common-auth`" as:
564 --------------------
565 auth required pam_ecryptfs.so unwrap
566 --------------------
567 and the last line in "`/etc/pam.d/common-session`" as:
568 --------------------
569 session optional pam_ecryptfs.so unwrap
570 --------------------
571 and the first active line in "`/etc/pam.d/common-password`" as:
572 --------------------
573 password required pam_ecryptfs.so
574 --------------------
575 This is quite convienient.
576
577 WARNING: Configuration errors of PAM may lock you out of your own system. See <<_authentication>>.
578
579 CAUTION: If you use your login password for wrapping encryption keys, your encrypted data are as secure as your user login password (see <<_good_password>>). Unless you are careful to set up a http://en.wikipedia.org/wiki/Password_strength[strong password], your data will be at risk when someone runs http://en.wikipedia.org/wiki/Password_cracking[password cracking] software after stealing your laptop (see <<_securing_the_root_password>>).
580
581 === Monitoring, controlling, and starting program activities
582
583 Program activities can be monitored and controlled using specialized tools.
584
585
586 .List of tools for monitoring and controlling program activities
587 [grid="all"]
588 `-----------`-------------`------------`-----------------------------------------------------------------------------------------
589 package popcon size description
590 ---------------------------------------------------------------------------------------------------------------------------------
591 `time` @@@popcon1@@@ @@@psize1@@@ `time`(1) runs a program to report system resource usages with respect to time.
592 `coreutils` @@@popcon1@@@ @@@psize1@@@ `nice`(1) runs a program with modified scheduling priority.
593 `bsdutils` @@@popcon1@@@ @@@psize1@@@ `renice`(1) modifies the scheduling priority of a running process.
594 `powertop` @@@popcon1@@@ @@@psize1@@@ `powertop`(1) gives information about system power use on Intel-based laptops.
595 `procps` @@@popcon1@@@ @@@psize1@@@ The "`/proc`" file system utilities: `ps`(1), `top`(1), `kill`(1), `watch`(1), ...
596 `psmisc` @@@popcon1@@@ @@@psize1@@@ The "`/proc`" file system utilities: `killall`(1), `fuser`(1), `pstree`(1)
597 `cron` @@@popcon1@@@ @@@psize1@@@ The `cron`(8) daemon runs processes according to a schedule (in background).
598 `at` @@@popcon1@@@ @@@psize1@@@ `at`(1) or `batch`(1) commands run a job at a specified time or below certain load level.
599 `lsof` @@@popcon1@@@ @@@psize1@@@ `lsof`(8) lists open files by a running process using "`-p`" option.
600 `strace` @@@popcon1@@@ @@@psize1@@@ `strace`(1) traces system calls and signals.
601 `ltrace` @@@popcon1@@@ @@@psize1@@@ `ltrace`(1) traces library calls.
602 `xtrace` @@@popcon1@@@ @@@psize1@@@ `xtrace`(1) traces communication between X11 client and server.
603 ---------------------------------------------------------------------------------------------------------------------------------
604
605 ==== Time a process
606
607 Display time used by the process invoked by the command.
608
609
610 --------------------
611 # time some_command >/dev/null
612 real 0m0.035s # time on wall clock (elapsed real time)
613 user 0m0.000s # time in user mode
614 sys 0m0.020s # time in kernel mode
615 --------------------
616
617 ==== The scheduling priority
618
619 A nice value is used to control the scheduling priority for the process.
620
621
622 .List of nice values for the scheduling priority.
623 [grid="all"]
624 `----------`-----------------------------------------------
625 nice value scheduling priority
626 -----------------------------------------------------------
627 19 lowest priority process (nice)
628 0 very high priority process for user.
629 -20 very high priority process for root. (not-nice)
630 -----------------------------------------------------------
631
632
633 --------------------
634 # nice -19 top # very nice
635 # nice --20 wodim -v -eject speed=2 dev=0,0 disk.img # very fast
636 --------------------
637
638 Sometimes an extreme nice value does more harm than good to the system. Use this command carefully.
639
640 ==== The ps command
641
642 The `ps`(1) command on the Debian support both BSD and SystemV features and helps to identify the process activity statically.
643
644
645 .List of ps command styles.
646 [grid="all"]
647 `--------`---------------`-----------------
648 style typical command feature
649 -------------------------------------------
650 BSD `ps aux` display %CPU %MEM
651 System V `ps -efH` display PPID
652 -------------------------------------------
653
654 For the zombie (defunct) children process, you can kill them by the parent process ID identified in the (`PPID`) field.
655
656 The `pstree`(1) command display a tree of processes.
657
658 ==== The top command
659
660 `top`(1) on the Debian has rich features and helps to identify what process is acting funny dynamically.
661
662
663 .List of commands for top.
664 [grid="all"]
665 `-----------`---------------------------
666 command key response
667 ----------------------------------------
668 `h` or `?` To show help.
669 `f` To set/reset display field.
670 `o` To reorder display field.
671 `F` To set sort key field.
672 `k` To kill a process.
673 `r` To renice a process.
674 `q` To quit the `top` command.
675 ----------------------------------------
676
677 ==== List files opened by a process
678
679 You can list all files opened by a process with a process ID (PID), e.g. 1 as:
680
681 --------------------
682 $ sudo lsof -p 1
683 --------------------
684
685 PID=1 is usually `init` program.
686
687 ==== Trace program activities
688
689 You can trace program activity with `strace`(1), `ltrace`(1), or `xtrace`(1) for system calls and signals, library calls, or communication between X11 client and server. For example:
690
691 --------------------
692 $ sudo strace ls
693 ...
694 --------------------
695
696 ==== Identify processes using files or sockets
697
698 You can also identify processes using files or sockets by `fuser`(1). For example:
699
700 --------------------
701 $ sudo fuser -v /var/log/mail.log
702 USER PID ACCESS COMMAND
703 /var/log/mail.log: root 2946 F.... syslogd
704 --------------------
705 You see that file "`/var/log/mail.log`" is open for writing by the `syslogd`(8) command.
706
707
708 --------------------
709 $ sudo fuser -v smtp/tcp
710 USER PID ACCESS COMMAND
711 smtp/tcp: Debian-exim 3379 F.... exim4
712 --------------------
713 Now you know your system runs `exim4`(8) to handle http://en.wikipedia.org/wiki/Transmission_Control_Protocol[TCP] connections to http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol[SMTP] port (25).
714
715 ==== Repeating a command with a constant interval
716
717 `watch`(1) executes a program repeatedly with a constant interval while showing its output in fullscreen.
718
719
720 --------------------
721 $ watch w
722 --------------------
723 This will display who is logged on to the system updated every 2 seconds.
724
725 ==== Repeating a command looping over files
726
727 There are several ways to repeat a command looping over files matching some condition, e.g. matching glob pattern "`\*.ext`".
728
729
730 - Shell for-loop method (see <<_shell_loops>>):
731 +
732 --------------------
733 for x in *.ext; do if [ -f "$x"]; then command "$x" ; fi; done
734 --------------------
735
736
737 - `find`(1) and `xargs`(1) combination:
738 +
739 --------------------
740 find . -type f -maxdepth 1 -name '*.ext' -print0 | xargs -0 -n 1 command
741 --------------------
742
743
744 - `find`(1) with "`-exec`" option with a command:
745 +
746 --------------------
747 find . -type f -maxdepth 1 -name '*.ext' -exec command '{}' \;
748 --------------------
749
750
751 - `find`(1) with "`-exec`" option with a short shell script:
752 +
753 --------------------
754 find . -type f -maxdepth 1 -name '*.ext' -exec sh -c "command '{}' && echo 'successful'" \;
755 --------------------
756
757 The above examples are written to ensure proper handling of funny file names such as ones containing spaces. See <<_idioms_for_the_selection_of_files>> for more advance uses of `find`(1).
758
759 ==== Starting a program from GUI
760
761 You can set up to start a process from http://en.wikipedia.org/wiki/Graphical_user_interface[graphical user interface (GUI)].
762
763 Under GNOME desktop environment, a program program can be started with proper argument by **drag-and-drop** of an icon to the launcher icon or by "**Open with ...**" menu with right clicking. KDE can do the equivalent, too. Here is an example for GNOME to set up `mc`(1) started in `gnome-terminal`(1):
764
765
766 - create an executable program "`mc-term`" as:
767
768 --------------------
769 # cat >/usr/local/bin/mc-term <<EOF
770 #!/bin/sh
771 gnome-terminal -e "mc \$1"
772 EOF
773 # chmod 755 /usr/local/bin/mc-term
774 --------------------
775
776 - create a desktop launcher
777 * right clicking desktop space to select "`Create Launcher ...`"
778 * set "Type" to "`Application`"
779 * set "Name" to "`mc`"
780 * set "Command" to "`mc-term %f`"
781 * click "OK"
782 - create an open-with association
783 * right click folder to select "`Open with Other Application ...`"
784 * click open "Use a custom command" dialog and enter "`mc-term %f`"
785 * click "Open".
786
787 TIP: Launcher is a file at "`\~/Desktop`" with "`.desktop`" as its extension.
788
789 ==== Customizing program to be started
790
791 Some programs start another program automatically. Here are check points for customizing this process:
792
793 - application configuration menu:
794 * GNOME desktop: "System" -> "Preferences" -> "Preferred Application"
795 * KDE desktop: "K" -> "Control Center" -> "KDE Components" -> "Component Chooser"
796 * Iceweasle browser: "Edit" -> "Preferences" -> "Applications"
797 * `mc`(1): "`/etc/mc/mc.ext`"
798 - environment variables such as "`$BROWSER`", "`$EDITOR`", "`$VISUAL`", and "`$PAGER`" (see `eviron`(7)).
799 - the `update-alternatives`(8) system for programs such as "`editor`", "`view`", "`x-www-browser`", "`gnome-www-browser`", and "`www-browser`" (see <<_setting_a_default_text_editor>>).
800 - the "`\~/.mailcap`" and "`/etc/mailcap`" file contents which associate http://en.wikipedia.org/wiki/MIME[MIME] type with program (see `mailcap`(5)).
801 - the the "`\~/.mime.types`" and "`/etc/mime.types`" file contents which associate file name extension with http://en.wikipedia.org/wiki/MIME[MIME] type (see `run-mailcap`(1)).
802
803 TIP: `update-mime`(8) updates the "`/etc/mailcap`" file using "`/etc/mailcap.order`" file (see `mailcap.order`(5)).
804
805 TIP: The `debianutils` package provides `sensible-browser`(1), `sensible-editor`(1), and `sensible-pager`(1) which make sensible decisions on which editor, pager, and web browser to call, respectively. I recommend you to read these shell commands.
806
807 TIP: In order to run a console application such as `mutt` under X as your prefered application, you should create an X application as following and set "`/usr/local/bin/mutt-term`" as your prefered application to be started as described.
808
809 --------------------
810 # cat /usr/local/bin/mutt-term <<EOF
811 #!/bin/sh
812 gnome-terminal -e "mutt \$@"
813 EOF
814 chmod 755 /usr/local/bin/mutt-term
815 --------------------
816
817 ==== Kill a process
818
819 Use `kill`(1) to kill (or send a signal to) a process by the process ID.
820
821 Use `killall`(1) or `pkill`(1) to do the same by the process command name and other attributes.
822
823
824 .List of frequently used signals for kill command.
825 [grid="all"]
826 `------------`-----------`--------------
827 signal value signal name function
828 ----------------------------------------
829 1 HUP restart daemon
830 15 TERM normal kill
831 9 KILL kill hard
832 ----------------------------------------
833
834 ==== Schedule tasks once
835
836 Run the `at`(1) command to schedule a one-time job:
837
838 --------------------
839 $ echo 'command -args'| at 3:40 monday
840 --------------------
841
842 ==== Schedule tasks regularly
843
844 Use `cron`(8) to schedule tasks regularly. See `crontab`(1) and `crontab`(5).
845
846 Run the command "`crontab -e`" to create or edit a crontab file to set up regularly scheduled events.
847
848 Example of a crontab file:
849
850 --------------------
851 # use /bin/sh to run commands, no matter what /etc/passwd says
852 SHELL=/bin/sh
853 # mail any output to paul, no matter whose crontab this is
854 MAILTO=paul
855 # Min Hour DayOfMonth Month DayOfWeek command (Day... are OR'ed)
856 # run at 00:05, every day
857 5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
858 # run at 14:15 on the first of every month -- output mailed to paul
859 15 14 1 * * $HOME/bin/monthly
860 # run at 22:00 on weekdays(1-5), annoy Joe. % for newline, last % for cc:
861 0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%.%%
862 23 */2 1 2 * echo "run 23 minutes after 0am, 2am, 4am ..., on Feb 1"
863 5 4 * * sun echo "run at 04:05 every sunday"
864 # run at 03:40 on the first Monday of each month
865 40 3 1-7 * * [ "$(date +%a)" == "Mon" ] && command -args
866 --------------------
867
868 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.
869
870 ==== Alt-SysRq
871
872 Insurance against system malfunction is provided by the kernel compile option "Magic SysRq key" (http://en.wikipedia.org/wiki/Secure_attention_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:
873
874
875 .List of SAK command keys.
876 [grid="all"]
877 `-----------------------`--------------------------------------------------------------------------------------
878 key following Alt-SysRq function
879 ---------------------------------------------------------------------------------------------------------------
880 `r` Un**r**aw restores the keyboard after things like X crashes.
881 `0` Changing the console loglevel to **0** reduces error messages.
882 `k` SAK (system attention key) **k**ills all processes on the **current virtual console**.
883 `e` Send a SIGT**E**RM to all processes, except for `init`(8).
884 `i` Send a SIGK**I**LL to all processes, except for `init`(8).
885 `s` **S**ync all mounted filesystems.
886 `u` Remount all mounted filesystems read-only (**u**mount).
887 `b` Re**b**oot the system without syncing or unmounting.
888 ---------------------------------------------------------------------------------------------------------------
889
890 The combination of "Alt-SysRq s", "Alt-SysRq u", and "Alt-SysRq r" is good for getting out of really bad situations.
891
892 See "`/usr/share/doc/linux-doc-2.6.\*/Documentation/sysrq.txt.gz`".
893
894 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.
895
896 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 **s**ync and **u**mount all mounted filesystems.
897
898 === System maintenance tips
899
900 ==== Who is logged on
901
902 You can check who is logged on to the system with `w`(1) or `who`(1).
903
904 ==== Warn everyone
905
906 You can send message to everyone who is logged on to the system with `wall`(1):
907
908 --------------------
909 $ echo "We are shutting down in 1 hour" | wall
910 --------------------
911
912 ==== Hardware identification
913
914 For the http://en.wikipedia.org/wiki/Peripheral_Component_Interconnect[PCI]-like devices (http://en.wikipedia.org/wiki/Accelerated_Graphics_Port[AGP], http://en.wikipedia.org/wiki/PCI_Express[PCI-Express], http://en.wikipedia.org/wiki/PC_Card#CardBus[CardBus], http://en.wikipedia.org/wiki/ExpressCard[ExpressCard], etc.), `lspci`(8) (probably with "`-nn`" option) is a good start for the hardware identification
915
916 Alternatively, you can identify the hardware by reading contents of "`/proc/bus/pci/devices`" or browsing directory tree under "`/sys/bus/pci`" (see <<_procfs_and_sysfs>>).
917
918
919 .List of hardware identification tools.
920 [grid="all"]
921 `-------------`-------------`------------`-------------------------------------------------------------
922 package popcon size description
923 -------------------------------------------------------------------------------------------------------
924 `pciutils` @@@popcon1@@@ @@@psize1@@@ Linux PCI Utilities, `lspci`(8)
925 `usbutils` @@@popcon1@@@ @@@psize1@@@ Linux USB utilities, `lsusb`(8)
926 `pcmciautils` @@@popcon1@@@ @@@psize1@@@ PCMCIA utilities for Linux 2.6, `pccardctl`(8)
927 `scsitools` @@@popcon1@@@ @@@psize1@@@ Collection of tools for SCSI hardware management, `lsscsi`(8)
928 `pnputils` @@@popcon1@@@ @@@psize1@@@ Plug and Play BIOS utilities, `lspnp`(8)
929 `procinfo` @@@popcon1@@@ @@@psize1@@@ Displays system information from "`/proc`", `lsdev`(8)
930 `lshw` @@@popcon1@@@ @@@psize1@@@ Information about hardware configuration, `lshw`(1)
931 `discover` @@@popcon1@@@ @@@psize1@@@ Hardware identification system, `discover`(8)
932 -------------------------------------------------------------------------------------------------------
933
934 ==== Hardware configuration
935
936 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.
937
938
939 .List of hardware configuration tools.
940 [grid="all"]
941 `-------------------`-------------`------------`-------------------------------------------------------------------------------------------------------------------------
942 package popcon size description
943 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
944 `hal` @@@popcon1@@@ @@@psize1@@@ Hardware Abstraction Layer, `lshal`(1)
945 `console-tools` @@@popcon1@@@ @@@psize1@@@ Linux console font and keytable utilities.
946 `x11-xserver-utils` @@@popcon1@@@ @@@psize1@@@ X server utilities. `xset`(1) and `xmodmap`(1).
947 `acpid` @@@popcon1@@@ @@@psize1@@@ Daemon to manage events delivered by the Advanced Configuration and Power Interface (ACPI)
948 `acpi` @@@popcon1@@@ @@@psize1@@@ Utilities for ACPI devices
949 `apmd` @@@popcon1@@@ @@@psize1@@@ Daemon to manage events delivered by the Advanced Power Management (APM)
950 `powersaved` @@@popcon1@@@ @@@psize1@@@ Daemon to manage battery, temperature, ac, cpufreq (SpeedStep, Powernow!) control and monitor with ACPI and APM supports.
951 `noflushd` @@@popcon1@@@ @@@psize1@@@ Allow idle hard disks to spin down
952 `sleepd` @@@popcon1@@@ @@@psize1@@@ Puts a laptop to sleep during inactivity
953 `hdparm` @@@popcon1@@@ @@@psize1@@@ Hard disk access optimization. Very effective but dangerous. You must read `hdparm`(8) first.
954 `smartmontools` @@@popcon1@@@ @@@psize1@@@ Control and monitor storage systems using S.M.A.R.T.
955 `setserial` @@@popcon1@@@ @@@psize1@@@ Collection of tools for serial port management.
956 `memtest86+` @@@popcon1@@@ @@@psize1@@@ Collection of tools for memory hardware management.
957 `scsitools` @@@popcon1@@@ @@@psize1@@@ Collection of tools for SCSI hardware management.
958 `tpconfig` @@@popcon1@@@ @@@psize1@@@ A program to configure touchpad devices
959 `setcd` @@@popcon1@@@ @@@psize1@@@ Compact disc drive access optimization.
960 `big-cursor` @@@popcon1@@@ @@@psize1@@@ Larger mouse cursors for X
961 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
962
963 Here, ACPI is a newer framework for the power management system than APM.
964
965 ==== System and hardware time
966
967 The following will set system and hardware time to MM/DD hh:mm, CCYY.
968
969 --------------------
970 # date MMDDhhmmCCYY
971 # hwclock --utc --systohc
972 # hwclock --show
973 --------------------
974
975 Times are normally displayed in the local time on the Debian system but the hardware and system time usually use UTC.
976
977 If the hardware (BIOS) time is set to GMT, change the setting to "`UTC=yes`" in the "`/etc/default/rcS`".
978
979 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:
980
981 - http://www.tldp.org/HOWTO/TimePrecision-HOWTO/index.html[Managing Accurate Date and Time HOWTO].
982 - http://www.ntp.org/[NTP Public Services Project].
983 - The `ntp-doc` package
984
985 TIP: `ntptrace`(8) in the `ntp` package can trace a chain of NTP servers back to the primary source.
986
987 ==== The terminal configuration
988
989 There are several components to configure character console and `ncurses`(3) system features:
990
991
992 - the "`/etc/terminfo/\*/\*`" file (`terminfo`(5))
993 - the "`$TERM`" environment variable (`term`(7))
994 - `setterm`(1), `stty`(1), `tic`(1), and `toe`(1)
995
996 If the `terminfo` entry for `xterm` doesn\'t work with a non-Debian `xterm`, change your terminal type, "`$TERM`", 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 "`$TERM`".
997
998 ==== The sound infrastructure
999
1000 Device drivers for sound cards for current Linux 2.6 are provided by http://en.wikipedia.org/wiki/Advanced_Linux_Sound_Architecture[Advanced Linux Sound Architecture (ALSA)]. ALSA provides emulation mode for previous http://en.wikipedia.org/wiki/Open_Sound_System[Open Sound System (OSS)] for compatibility.
1001
1002 Run "`dpkg-reconfigure linux-sound-base`" to select the sound system to use ALSA via blacklisting of kernel modules. Unless you have very new sound hardware, udev infrastructure should configure your sound system.
1003
1004 TIP: Use "`cat /dev/urandom > /dev/audio`" or `speaker-test`(1) to test speaker. (\^C to stop)
1005
1006 TIP: If you can not get sound, your speaker may be connected to a muted output. Modern sound system has many outputs. `alsamixer`(1) in the `alsa-utils` package is useful to configure volume and mute settings.
1007
1008 Application softwares may be configured not only to access sound devices directly but also to access them via some standardized sound server system.
1009
1010 // UPDATE FOLLOWING PACKAGE NAME as you see new ones released
1011
1012
1013 .List of sound packages
1014 [grid="all"]
1015 `--------------------`-------------`------------`-----------------------------------------------------------------------------------------------------------------------------
1016 package pocon size description
1017 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1018 `linux-sound-base` @@@popcon1@@@ @@@psize1@@@ Base package for ALSA and OSS sound systems
1019 `alsa-base` @@@popcon1@@@ @@@psize1@@@ ALSA driver configuration files
1020 `alsa-utils` @@@popcon1@@@ @@@psize1@@@ Utilities for configuring and using ALSA
1021 `oss-compat` @@@popcon1@@@ @@@psize1@@@ OSS compatibility under ALSA preventing "`/dev/dsp not found`" errors
1022 `esound-common` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Enlightened_Sound_Daemon[Enlightened Sound Daemon (ESD)] common (Enlightenment and GNOME)
1023 `esound` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Enlightened_Sound_Daemon[Enlightened Sound Daemon (ESD)] server (Enlightenment and GNOME)
1024 `esound-clients` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Enlightened_Sound_Daemon[Enlightened Sound Daemon (ESD)] client (Enlightenment and GNOME)
1025 `libesd-alsa0` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Enlightened_Sound_Daemon[Enlightened Sound Daemon (ESD)] library Enlightenment and GNOME)
1026 `libesd0` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Enlightened_Sound_Daemon[Enlightened Sound Daemon (ESD)] library (Enlightenment and GNOME) - OSS
1027 `arts` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/ARts[aRts] server (KDE)
1028 `libarts1c2a` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/ARts[aRts] library (KDE)
1029 `libartsc0` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/ARts[aRts] library (KDE)
1030 `jackd` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/JACK_Audio_Connection_Kit[JACK Audio Connection Kit. (JACK)] server (low latency)
1031 `libjack0` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/JACK_Audio_Connection_Kit[JACK Audio Connection Kit. (JACK)] library (low latency)
1032 `libjack0.100.0-0` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/JACK_Audio_Connection_Kit[JACK Audio Connection Kit. (JACK)] library (low latency)
1033 `nas` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Network_Audio_System[Network Audio System (NAS)] server
1034 `libaudio2` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Network_Audio_System[Network Audio System (NAS)] library
1035 `pulseaudio` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/PulseAudio[PulseAudio] server, replacement for ESD
1036 `libpulse0` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/PulseAudio[PulseAudio] client library, replacement for ESD
1037 `libpulsecore9` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/PulseAudio[PulseAudio] server library, replacement for ESD
1038 `libgstreamer0.10-0` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/GStreamer[GStreamer]: GNOME sound engine
1039 `libxine1` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Xine[xine]: KDE older sound engine
1040 `libphonon4` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Phonon_(KDE)[Phonon]: KDE new sound engine
1041 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1042
1043 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.
1044
1045 ==== Disable the screen saver
1046
1047 For disabling the screen saver, use following commands.
1048
1049
1050 .List of commands for disabling the screen saver.
1051 [grid="all"]
1052 `-------------------------------------------------`-----------------------------
1053 environment command
1054 --------------------------------------------------------------------------------
1055 The Linux console `setterm -powersave off`
1056 The X Window by turning off screensaver `xset s off`
1057 The X Window by disabling dpms `xset -dpms`
1058 The X Window by GUI configuration of screen saver `xscreensaver-command -prefs`
1059 --------------------------------------------------------------------------------
1060
1061 ==== Disable the sound (beep)
1062
1063 One can always unplug the PC speaker. ;-) Removing `pcspkr` kernel module does this for you.
1064
1065 The following will prevent the `readline`(3) program used by `bash`(1) to beep when encountering "`\a`" (ASCII=7):
1066
1067 --------------------
1068 $ echo "set bell-style none">> ~/.inputrc
1069 --------------------
1070
1071 ==== Memory usage
1072
1073 The kernel boot message in the "`/var/log/dmesg`" contains the total exact size of available memory.
1074
1075 `free`(1) and `top`(1) display information on memory resources on the running system.
1076
1077 --------------------
1078 $ grep '\] Memory' /var/log/dmesg
1079 [ 0.004000] Memory: 990528k/1016784k available (1975k kernel code, 25868k reserved, 931k data, 296k init)
1080 $ free -k
1081 total used free shared buffers cached
1082 Mem: 997184 976928 20256 0 129592 171932
1083 -/+ buffers/cache: 675404 321780
1084 Swap: 4545576 4 4545572
1085 --------------------
1086
1087 For my MacBook with 1GB=1048576k DRAM (video system steals some of this):
1088
1089 .List of memory sizes reported.
1090 [grid="all"]
1091 `-------------------`-----------------------
1092 report size
1093 --------------------------------------------
1094 Total size in dmesg 1016784k = 1GB - 31792k
1095 Free in dmesg 990528k
1096 Total under shell 997184k
1097 Free under shell 20256k
1098 --------------------------------------------
1099
1100 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.
1101
1102 ==== System security and integrity check
1103
1104 Poor system maintenance may expose your system to external exploitation.
1105
1106 For system security and integrity check, you should start with:
1107
1108 - the `debsums` package: See `debsums`(1) and <<_top_level_release_file_and_authenticity>>.
1109 - the `chkrootkit` package: See `chkrootkit`(1).
1110 - the `clamav` package family: See `clamscan`(1) and `freahclam`(1).
1111 - http://www.debian.org/security/faq[Debian security FAQ].
1112 - http://www.debian.org/doc/manuals/securing-debian-howto/[Securing Debian Manual].
1113
1114
1115 .List of tools for system security and integrity check
1116 [grid="all"]
1117 `------------`-------------`------------`----------------------------------------------------------------
1118 package popcon size description
1119 ---------------------------------------------------------------------------------------------------------
1120 `logcheck` @@@popcon1@@@ @@@psize1@@@ This mails anomalies in the system logfiles to the administrator
1121 `debsums` @@@popcon1@@@ @@@psize1@@@ This verifies installed package files against MD5 checksums.
1122 `chkrootkit` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Rootkit[Rootkit] detector.
1123 `clamav` @@@popcon1@@@ @@@psize1@@@ Anti-virus utility for Unix - command-line interface.
1124 `tiger` @@@popcon1@@@ @@@psize1@@@ Report system security vulnerabilities
1125 `tripwire` @@@popcon1@@@ @@@psize1@@@ File and directory integrity checker
1126 `john` @@@popcon1@@@ @@@psize1@@@ Active password cracking tool
1127 `aide` @@@popcon1@@@ @@@psize1@@@ Advanced Intrusion Detection Environment - static binary
1128 `bastille` @@@popcon1@@@ @@@psize1@@@ Security hardening tool
1129 `integrit` @@@popcon1@@@ @@@psize1@@@ A file integrity verification program
1130 `crack` @@@popcon1@@@ @@@psize1@@@ Password guessing program
1131 ---------------------------------------------------------------------------------------------------------
1132
1133 Here is a simple script to check for typical world writable incorrect file permissions.
1134
1135 --------------------
1136 # find / -perm 777 -a \! -type s -a \! -type l -a \! \( -type d -a -perm 1777 \)
1137 --------------------
1138
1139 CAUTION: Since the `debsums` package uses MD5 checksums stored locally, it can not be fully trusted as the system security audit tool against malicious attacks.
1140
1141 === The kernel
1142
1143 Debian distributes modularized Linux kernel as packages for supported architectures.
1144
1145 ==== Linux kernel 2.6
1146
1147 There are few notable features on Linux kernel 2.6 compared to 2.4.
1148
1149 - Devices are created by the udev system (see <<_the_udev_system>>).
1150 - Read/write accesses to IDE CD/DVD devices do not use the `ide-scsi` module.
1151 - Network packet filtering functions use `iptable` kernel modules.
1152
1153 ==== Kernel headers
1154
1155 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.
1156
1157 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. `module-assistant`(8) (or its short form `m-a`) helps users to build and install module package(s) easily for one or more custom kernels.
1158
1159 ==== Kernel and module compile
1160
1161 Debian has its own method of compiling the kernel and related modules.
1162
1163
1164 .List of key packages to be installed for the kernel recompilation on the Debian system
1165 [grid="all"]
1166 `-------------------`-------------`------------`----------------------------------------------------------------------------
1167 package popcon size description
1168 ----------------------------------------------------------------------------------------------------------------------------
1169 `build-essential` @@@popcon1@@@ @@@psize1@@@ essential packages for building Debian packages: `make`, `gcc`, ...
1170 `bzip2` @@@popcon1@@@ @@@psize1@@@ compress and decompress utilities for bz2 files
1171 `libncurses5-dev` @@@popcon1@@@ @@@psize1@@@ developer\'s libraries and docs for ncurses
1172 `git-core` @@@popcon1@@@ @@@psize1@@@ git: distributed revision control system used by the Linux kernel
1173 `fakeroot` @@@popcon1@@@ @@@psize1@@@ provide fakeroot environment for building package as non-root
1174 `initramfs-tools` @@@popcon1@@@ @@@psize1@@@ tool to build an initramfs (Debian specific)
1175 `kernel-package` @@@popcon1@@@ @@@psize1@@@ tool to build Linux kernel packages (Debian specific)
1176 `module-assistant` @@@popcon1@@@ @@@psize1@@@ tool to help build module packages (Debian specific)
1177 `devscripts` @@@popcon1@@@ @@@psize1@@@ helper scripts for a Debian Package maintainer (Debian specific)
1178 `linux-tree-2.6.\*` N/A N/A Linux kernel source tree meta package (Debian specific)
1179 ----------------------------------------------------------------------------------------------------------------------------
1180
1181 If you use `initrd` in <<_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).
1182
1183 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.)
1184
1185 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.
1186
1187 ==== Kernel source compile: Debian standard method
1188
1189 The Debian standard method for compiling kernel source to create a custom kernel package uses `make-kpkg`(1). 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.
1190
1191 Here is an example for amd64 system:
1192
1193 --------------------
1194 # aptitude install linux-tree-<version>
1195 $ cd /usr/src
1196 $ tar -xjvf linux-source-<version>.tar.bz2
1197 $ cd linux-source-<version>
1198 $ cp /boot/config-<oldversion> .config
1199 $ make menuconfig
1200 ...
1201 $ make-kpkg clean
1202 $ fakeroot make-kpkg --append_to_version -amd64 --initrd --revision=rev.01 kernel_image modules_image
1203 $ cd ..
1204 # dpkg -i linux-image*.deb
1205 --------------------
1206
1207 - reboot to new kernel with "`shutdown -r now`" .
1208
1209 CAUTION: When you intend to create a non-modularized kernel compiled only for one machine, invoke `make-kpkg` 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.
1210
1211 ==== Module source compile: Debian standard method
1212
1213 The Debian standard method for creating and installing a custom module package for a custom kernel package uses `module-assistant`(8) and module-source packages. For example, following will build the `unionfs` kernel module package and installs it.
1214
1215 --------------------
1216 $ sudo aptitude install module-assistant
1217 ...
1218 $ sudo aptitude install unionfs-source unionfs-tools unionfs-utils
1219 $ sudo m-a update
1220 $ sudo m-a prepare
1221 $ sudo m-a auto-install unionfs
1222 ...
1223 $ sudo apt-get autoremove
1224 --------------------
1225
1226 ==== Kernel source compile: classic method
1227
1228 You can still build http://www.kernel.org/[Linux kernel from the pristine sources] with the classic method. You must take care the details of the system configuration manually.
1229
1230 --------------------
1231 $ cd /usr/src
1232 $ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-<version>.tar.bz2
1233 $ tar -xjvf linux-<version>.tar.bz2
1234 $ cd linux-<version>
1235 $ cp /boot/config-<version> .config
1236 $ make menuconfig
1237 ...
1238 $ make dep; make bzImage
1239 $ make modules
1240 # cp ./arch/x86_64/boot/bzImage /boot/vmlinuz-<version>
1241 # make modules_install
1242 # depmod -a
1243 # update-initramfs -c -k <version>
1244 --------------------
1245
1246
1247 - set up bootloader
1248 * edit "`/etc/lilo.conf`" and run "`/sbin/lilo`", if you use `lilo`.
1249 * edit "`/boot/grub/menu.lst`", if you use `grub`.
1250 - reboot to new kernel with "`shutdown -r now`".
1251
1252 ==== Non-free hardware drivers
1253
1254 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.
1255
1256 Check pertinent resources:
1257
1258
1259 - http://en.wikipedia.org/wiki/Softmodem
1260 - http://en.wikipedia.org/wiki/Comparison_of_open_source_wireless_drivers
1261 - http://www.google.com[Google] or other search engines with keyword "Linmodem".
1262 - http://ndiswrapper.sourceforge.net
1263 - http://linuxwireless.org
1264 - http://madwifi-project.org (there is ath5k which contains free drivers)
1265
1266 === Virtualized system
1267
1268 Use of virtualized system enables us to run multiple instances of system simultaneously on a single hardware.
1269
1270 ==== Virtualization tools
1271
1272 Virturization involves 2 steps:
1273
1274 - create file system populated with required package data. Programs such as `debootstrap` and `cdebootstrap` helps this process.
1275 - run a program under virturized environment. Most basic method is provided by http://en.wikipedia.org/wiki/Chroot[chroot].
1276
1277 There are several system http://en.wikipedia.org/wiki/Virtualization[virtualization] and http://en.wikipedia.org/wiki/Emulator[emulation] related packages in Debian beyond simple http://en.wikipedia.org/wiki/Chroot[chroot]. Some packages also help you to setup such system.
1278
1279 .List of virtualization tools
1280 [grid="all"]
1281 `-----------------`-------------`------------`------------------------------------------------------------------------------------------------------------------
1282 package pocon size description
1283 ----------------------------------------------------------------------------------------------------------------------------------------------------------------
1284 `schroot` @@@popcon1@@@ @@@psize1@@@ Specialized tool for executing Debian binary packages in chroot
1285 `sbuild` @@@popcon1@@@ @@@psize1@@@ Tool for building Debian binary packages from Debian sources
1286 `pbuilder` @@@popcon1@@@ @@@psize1@@@ Personal package builder for Debian packages
1287 `debootstrap` @@@popcon1@@@ @@@psize1@@@ Bootstrap a basic Debian system (written in sh)
1288 `cdebootstrap` @@@popcon1@@@ @@@psize1@@@ Bootstrap a Debian system (written in C)
1289 `rootstrap` @@@popcon1@@@ @@@psize1@@@ A tool for building complete Linux filesystem images
1290 `user-mode-linux` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/User-mode_Linux[User-mode Linux] (kernel)
1291 `xen-tools` @@@popcon1@@@ @@@psize1@@@ Tools to manage debian http://en.wikipedia.org/wiki/Xen[XEN] virtual server
1292 `bochs` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Bochs[Bochs]: IA-32 PC emulator
1293 `qemu` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Qemu[Qemu]: fast generic processor emulator
1294 `virtualbox-ose` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/VirtualBox[VirtualBox]: x86 virtualization solution on i386 and amd64
1295 `wine` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Wine_(software)[Wine]: Windows API Implementation (standard suite)
1296 `dosbox` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/DOSBox[DOSBox]: x86 emulator with Tandy/Herc/CGA/EGA/VGA/SVGA graphics, sound and DOS
1297 `util-vserver` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/Linux-VServer[Linux-VServer] virtual private servers - user-space tools
1298 `vzctl` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/OpenVZ[OpenVZ] server virtualization solution - control tools
1299 `vzquota` @@@popcon1@@@ @@@psize1@@@ http://en.wikipedia.org/wiki/OpenVZ[OpenVZ] server virtualization solution - quota tools
1300 ----------------------------------------------------------------------------------------------------------------------------------------------------------------
1301
1302 See Wikipedia article http://en.wikipedia.org/wiki/Comparison_of_virtual_machines[Comparison of virtual machines] for detail comparison of different virtualization solutions.
1303
1304 ==== Chroot system
1305
1306 `chroot`(8) offers most basic way to run different instances of the GNU/Linux environment on a single system simultaneously without rebooting.
1307
1308 CAUTION: Examples below assumes both parent system and chroot system share the same CPU architecture.
1309
1310 TIP: Similar `schroot` package may give you an idea to run `i386` chroot system under `amd64` parent system.
1311
1312 You can learn how to setup and use `chroot`(8) by running `pbuilder`(8) program under `script`(1) as follows.
1313
1314 ------
1315 $ sudo pbuilder --create --no-targz --debug
1316 ------
1317
1318 You will see how `debootstrap`(8) or `debootstrap`(1) populate system data for `sid` environment under "`/var/cache/pbuilder/builds/`".
1319
1320 TIP: These `debootstrap`(8) or `debootstrap`(1) are used to http://www.debian.org/releases/stable/installmanual[install Debian] by the Debian Installer. These can also be used to install Debian to a system without using a Debian install disk, but instead from another GNU/Linux distribution.
1321
1322 -----
1323 $ sudo pbuilder --login --no-targz --debug
1324 -----
1325
1326 You will see how a system shell running under `sid` environment is created:
1327
1328 - copying local configuration (`"/etc/hosts`", `"/etc/hostname`", `"/etc/resolv.conf`")
1329 - mounting "`/proc`" filesystem
1330 - mounting `"/dev/pts`" filesystem
1331 - "`policy-rc.d`" created (in "`/usr/sbin/`", it always exits with 101)
1332 - run "`chroot /var/cache/pbuilder/build/ bin/bash -c 'exec -a -bash bin/bash'`"
1333
1334 For "`policy-rc.d`", see "`/usr/share/doc/sysv-rc/README.policy-rc.d.gz`".
1335
1336 ==== Setting up login for chroot
1337
1338 You can run another login process on a separate virtual terminal where you can log in to the chroot system 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 under "`/sid-root/`" instead of "`/var/cache/pbuilder/build/`" by following steps you learned from `pbuilder`(8), type from the root shell of the main system:
1339
1340 --------------------
1341 main # echo "8:23:respawn:/usr/sbin/chroot /sid-root /sbin/getty 38400 tty8" >> /etc/inittab
1342 main # init q
1343 --------------------
1344
1345 - reload init
1346
1347 ==== Setting up X for chroot
1348
1349 WARNING: XXX FIXME XXX: This section may need to be updated for `lenny`/`squeeze`.
1350
1351 Do 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`.
1352
1353 First install a chroot system. From the root of the main system, copy key configuration files to the chroot system.
1354
1355 --------------------
1356 main # cp /etc/X11/xorg.conf /sid-root/etc/X11/xorg.conf
1357 main # chroot /sid-root
1358 --------------------
1359
1360 - copy local configuration (`"/etc/hosts`", `"/etc/hostname`", `"/etc/resolv.conf`")
1361 - mount "`/proc`" filesystem
1362 - mount `"/dev/pts`" filesystem
1363 - create "`policy-rc.d`" (in "`/usr/sbin/`", it always exits with 101)
1364
1365 --------------------
1366 chroot # aptitude install gdm gnome xorg
1367 chroot # vim /etc/gdm/gdm.conf
1368 --------------------
1369
1370 - change "`[servers]`" section with "`s/vt7/vt9/`" to make the first virtual console in the chroot from `vt7` to `vt9`.
1371
1372 --------------------
1373 chroot # /etc/init.d/gdm start
1374 --------------------
1375
1376 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!
1377
1378 ==== Run other distributions with chroot
1379
1380 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`":
1381
1382 --------------------
1383 main # cd / ; mkdir /other-dist
1384 main # mount -t ext3 /dev/hda9 /other-dist
1385 --------------------
1386
1387 - copy local configuration (`"/etc/hosts`", `"/etc/hostname`", `"/etc/resolv.conf`")
1388 - mount "`/proc`" filesystem
1389 - mount `"/dev/pts`" filesystem
1390 - create "`policy-rc.d`" (in "`/usr/sbin/`", it always exits with 101)
1391
1392 --------------------
1393 main # chroot /other-dist /bin/bash
1394 --------------------
1395
1396 ==== Build packages under chroot
1397
1398 The original purpose of the specialized chroot package, `pbuilder` is to construct 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.
1399

  ViewVC Help
Powered by ViewVC 1.1.5