目录
这里,描述配置和管理系统的基本技巧,大部分在控制台操作。
对通过不可靠或断断续续的连接访问远程主机的人们而言,screen(1) 是一个非常有用的工具,因为它支持可中断的网络连接。
screen(1) 不但允许一个终端窗口运行多个进程,还允许远程 shell 进程支持中断的连接.这里是一个典型的 screen(1) 使用场景.
登录到一个远程机器。
在单个控制台上启动 screen。
使用 ^A c ("Control-A" 接着 "c")在 screen
中创建的窗口执行多个程序.
按 ^A n ("Control-A" 接着"n")来在多个 screen
窗口间转换.
突然,你需要离开你的终端,但你不想丢掉正在做的工作,而这些工作需要连接来保持。
你可以通过任何方式分离 screen 会话。
残忍地拔掉你的网络连接
输入 ^A d ("Control-A" 接着 "d") 并手工从远程连接退出登录
输入 ^A DD ("Control-A" 接着 "DD") 分离
screen 并退出登录
你重新登录到同一个远处主机(即使从不同的终端)。
使用 "screen -r" 启动 screen.
screen 魔术般的重新附上先前所有的
screen 窗口和所有在活动运行的程序.
|
提示 |
|---|---|
|
对于拨号或者按包计费的网络连接,你可以通过 |
在 screen 会话里,除了命令按键外的所有键盘输入都会被发送到当前窗口。
screen 所有命令按键是通过 ^A ("Control-A")
加单个键[加任何参数] 来输入.这里有一些重要的命令按键需要记住。
表 9.2. screen 键绑定列表
| 键绑定功能 | 说明 |
|---|---|
^A ?
|
显示帮助屏幕(显示键绑定) |
^A c
|
创建一个新的窗口并切换到该窗口 |
^A n
|
到下一个窗口 |
^A p
|
到前一个窗口 |
^A 0
|
到 0 号窗口 |
^A 1
|
到 1 号窗口 |
^A w
|
显示窗口列表 |
^A a
|
作为键盘输入发送 Ctrl-A 到当前窗口 |
^A h
|
把当前窗口的硬拷贝写到一个文件 |
^A H
|
开始/结束 当前窗口到文件的记录 |
^A ^X
|
锁定终端(密码保护) |
^A d
|
从终端分离 screen 会话 |
^A DD
|
分离 screen 会话并退出登录 |
细节参见 screen(1).
许多程序在"/var/log/" 目录下记录它们的活动.
内核日志后台守护进程(daemon): klogd(8)
系统日志后台守护进程(daemon): rsyslogd(8)
Here are notable log analyzers
("~Gsecurity::log-analyzer" in
aptitude(8)).
表 9.3. List of system log analyzers
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
logwatch
|
V:19, I:22 | 2188 | log analyzer with nice output written in Perl |
fail2ban
|
V:91, I:103 | 1253 | ban IPs that cause multiple authentication errors |
analog
|
V:5, I:130 | 3467 | web server log analyzer |
awstats
|
V:12, I:21 | 6588 | powerful and featureful web server log analyzer |
sarg
|
V:6, I:6 | 432 | squid analysis report generator |
pflogsumm
|
V:1, I:4 | 133 | Postfix log entry summarizer |
syslog-summary
|
V:1, I:5 | 30 | summarize the contents of a syslog log file |
fwlogwatch
|
V:0, I:0 | 474 | firewall log analyzer |
squidview
|
V:0, I:2 | 188 | monitor and analyze squid access.log files |
swatch
|
V:0, I:1 | 112 | log file viewer with regexp matching, highlighting, and hooks |
crm114
|
V:0, I:0 | 1099 | Controllable Regex Mutilator and Spam Filter (CRM114) |
icmpinfo
|
V:0, I:1 | 39 | interpret ICMP messages |
|
注意 |
|---|---|
|
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. |
The simple use of script(1) (see 第 1.4.9 节 “记录 shell 活动”) to record shell activity produces a file with control characters. This can be avoided by using col(1) as the following.
$ script Script started, file is typescript
Do whatever … and press Ctrl-D to exit
script.
$ col -bx <typescript >cleanedfile $ vim cleanedfile
If you don't have script (for example, during the boot
process in the initramfs), you can use the following instead.
$ sh -i 2>&1 | tee typescript
|
提示 |
|---|---|
|
Some |
|
提示 |
|---|---|
|
You may use
screen(1)
with " |
|
提示 |
|---|---|
|
You may use
emacs(1)
with " |
Although pager tools such as more(1) and less(1) (see 第 1.4.5 节 “文件内容查看”) and custom tools for highlighting and formatting (see 第 11.1.8 节 “Highlighting and formatting plain text data”) can display text data nicely, general purpose editors (see 第 1.4.6 节 “文本编辑器”) are most versatile and customizable.
|
提示 |
|---|---|
|
For
vim(1)
and its pager mode alias
view(1),
" |
The default display format of time and date by the "ls
-l" command depends on the locale (see 第 1.2.6 节 “时间戳” for
value). The "$LANG" variable is referred first and it
can be overridden by the "$LC_TIME" variable.
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.
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'").
表 9.4. Display examples of time and date for the "ls -l" command
for wheezy
| time style value | locale | display of time and date |
|---|---|---|
iso
|
any |
01-19 00:15
|
long-iso
|
any |
2009-01-19 00:15
|
full-iso
|
any |
2009-01-19 00:15:16.000000000 +0900
|
locale
|
C
|
Jan 19 00:15
|
locale
|
en_US.UTF-8
|
Jan 19 00:15
|
locale
|
es_ES.UTF-8
|
ene 19 00:15
|
+%d.%m.%y %H:%M
|
any |
19.01.09 00:15
|
+%d.%b.%y %H:%M
|
C or en_US.UTF-8
|
19.Jan.09 00:15
|
+%d.%b.%y %H:%M
|
es_ES.UTF-8
|
19.ene.09 00:15
|
|
提示 |
|---|---|
|
You can eliminate typing long option on commandline using command alias,
e.g. " |
|
提示 |
|---|---|
|
ISO 8601 is followed for these iso-formats. |
Shell echo to most modern terminals can be colorized using ANSI escape code (see
"/usr/share/doc/xterm/ctlseqs.txt.gz").
尝试下列例子
$ RED=$(printf "\x1b[31m")
$ NORMAL=$(printf "\x1b[0m")
$ REVERSE=$(printf "\x1b[7m")
$ echo "${RED}RED-TEXT${NORMAL} ${REVERSE}REVERSE-TEXT${NORMAL}"
Colorized commands are handy for inspecting their output in the interactive
environment. I include the 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(1).
If you wish to suppress color when piping to other programs, use
"--color=auto" instead in the above example for
"~/.bashrc".
|
提示 |
|---|---|
|
You can turn off these colorizing aliases in the interactive environment by
invoking shell with " |
You can record the editor activities for complex repeats.
For Vim, as follows.
"qa": start recording typed characters into named
register "a".
… editor activities
"q": end recording typed characters.
"@a": execute the contents of register
"a".
For Emacs, as follows.
"C-x (": start defining a keyboard macro.
… editor activities
"C-x )": end defining a keyboard macro.
"C-x e": execute a keyboard macro.
There are few ways to record the graphic image of an X application,
including an xterm display.
表 9.5. List of graphic image manipulation tools
| 软件包 | 流行度 | 大小 | 命令 |
|---|---|---|---|
xbase-clients
|
I:79 | 45 | xwd(1) |
gimp
|
V:89, I:508 | 16255 | GUI menu |
imagemagick
|
V:173, I:547 | 223 | import(1) |
scrot
|
V:8, I:82 | 50 | scrot(1) |
There are specialized tools to record changes in configuration files with help of DVCS system.
表 9.6. List of packages to record configuration history in VCS
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
etckeeper
|
V:22, I:26 | 151 | store configuration files and their metadata with Git (default), Mercurial, or Bazaar (new) |
changetrack
|
V:0, I:0 | 62 | store configuration files with RCS (old) |
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".
Essentially, running "sudo etckeeper init" initializes
the git repository for "/etc" just like the process
explained in 第 10.6.5 节 “记录配置历史的 Git” but
with special hook scripts for more thorough setups.
As you change your configuration, you can use git(1) normally to record them. It automatically records changes nicely every time you run package management commands, too.
|
提示 |
|---|---|
|
You can browse the change history of " |
Program activities can be monitored and controlled using specialized tools.
表 9.7. List of tools for monitoring and controlling program activities
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
coreutils
|
V:877, I:999 | 14783 | nice(1): run a program with modified scheduling priority |
bsdutils
|
V:846, I:999 | 230 | renice(1): modify the scheduling priority of a running process |
procps
|
V:804, I:999 | 694 |
"/proc" filesystem utilities:
ps(1),
top(1),
kill(1),
watch(1),
…
|
psmisc
|
V:587, I:974 | 588 |
"/proc" filesystem utilities:
killall(1),
fuser(1),
peekfd(1),
pstree(1)
|
time
|
V:43, I:848 | 81 | time(1): run a program to report system resource usages with respect to time |
sysstat
|
V:93, I:111 | 1326 | sar(1), iostat(1), mpstat(1), …: system performance tools for Linux |
isag
|
V:0, I:4 | 105 | Interactive System Activity Grapher for sysstat |
lsof
|
V:363, I:944 | 440 | lsof(8):
list files opened by a running process using "-p" option
|
strace
|
V:23, I:166 | 1257 | strace(1): trace system calls and signals |
ltrace
|
V:1, I:23 | 323 | ltrace(1): trace library calls |
xtrace
|
V:0, I:1 | 336 | xtrace(1): trace communication between X11 client and server |
powertop
|
V:5, I:228 | 563 | powertop(1): information about system power use |
cron
|
V:874, I:997 | 194 | run processes according to a schedule in background from cron(8) daemon |
anacron
|
V:451, I:538 | 62 | cron-like command scheduler for systems that don't run 24 hours a day |
at
|
V:514, I:854 | 145 | at(1) or batch(1): run a job at a specified time or below certain load level |
|
提示 |
|---|---|
|
The |
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
A nice value is used to control the scheduling priority for the process.
表 9.8. 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) |
# 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.
The ps(1) command on a Debian system support both BSD and SystemV features and helps to identify the process activity statically.
表 9.9. 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.
The pstree(1) command display a tree of processes.
top(1) on the Debian system has rich features and helps to identify what process is acting funny dynamically.
Its is an interactive full screen program. You can get its usage help press by pressing the "h"-key and terminate it by pressing the "q"-key.
You can list all files opened by a process with a process ID (PID), e.g. 1, by the following.
$ sudo lsof -p 1
PID=1 is usually the init program.
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.
You can trace system calls of the ls command as the
following.
$ sudo strace ls
You can also identify processes using files by
fuser(1),
e.g. for "/var/log/mail.log" by the following.
$ sudo fuser -v /var/log/mail.log
USER PID ACCESS COMMAND
/var/log/mail.log: root 2946 F.... rsyslogd
You see that file "/var/log/mail.log" is open for writing
by the
rsyslogd(8)
command.
You can also identify processes using sockets by
fuser(1),
e.g. for "smtp/tcp" by the following.
$ sudo fuser -v smtp/tcp
USER PID ACCESS COMMAND
smtp/tcp: Debian-exim 3379 F.... exim4
Now you know your system runs exim4(8) to handle TCP connections to SMTP port (25).
watch(1) executes a program repeatedly with a constant interval while showing its output in fullscreen.
$ watch w
This displays who is logged on to the system updated every 2 seconds.
There are several ways to repeat a command looping over files matching some
condition, e.g. matching glob pattern "*.ext".
Shell for-loop method (see 第 12.1.4 节 “Shell loops”):
for x in *.ext; do if [ -f "$x"]; then command "$x" ; fi; done
find(1) and xargs(1) combination:
find . -type f -maxdepth 1 -name '*.ext' -print0 | xargs -0 -n 1 command
find(1)
with "-exec" option with a command:
find . -type f -maxdepth 1 -name '*.ext' -exec command '{}' \;
find(1)
with "-exec" option with a short shell script:
find . -type f -maxdepth 1 -name '*.ext' -exec sh -c "command '{}' && echo 'successful'" \;
The above examples are written to ensure proper handling of funny file names such as ones containing spaces. See 第 10.1.5 节 “Idioms for the selection of files” for more advance uses of find(1).
For the command-line interface
(CLI), the first program with the matching name found in the
directories specified in the $PATH environment variable
is executed. See 第 1.5.3 节 “"$PATH" 变量”.
For the graphical user interface
(GUI) compliant to the freedesktop.org standards, the
*.desktop files in the
/usr/share/applications/ directory provide necessary
attributes for the GUI menu display of each program. See 第 7.2.2 节 “Freedesktop.org menu”.
For example, the chromium.desktop file defines attributes
for the "Chromium Web Browser" such as "Name" for the program name, "Exec"
for the program execution path and arguments, "Icon" for the icon used,
etc. (see the Desktop Entry
Specification) as follows:
[Desktop Entry] Version=1.0 Name=Chromium Web Browser GenericName=Web Browser Comment=Access the Internet Comment[fr]=Explorer le Web Exec=/usr/bin/chromium %U Terminal=false X-MultipleArgs=false Type=Application Icon=chromium Categories=Network;WebBrowser; MimeType=text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https; StartupWMClass=Chromium StartupNotify=true
This is an oversimplified description. The *.desktop
files are scanned as follows.
The desktop environment sets $XDG_DATA_HOME and
$XDG_DATA_DIR environment variables. For example, under
the GNOME 3:
$XDG_DATA_HOME is unset. (The default value of
$HOME/.local/share is used.)
$XDG_DATA_DIRS is set to
/usr/share/gnome:/usr/local/share/:/usr/share/.
So the base directories (see XDG Base Directory
Specification) and the applications directories
are as follows.
$HOME/.local/share/ →
$HOME/.local/share/applications/
/usr/share/gnome/ →
/usr/share/gnome/applications/
/usr/local/share/ →
/usr/local/share/applications/
/usr/share/ → /usr/share/applications/
The *.desktop files are scanned in these
applications directories in this order.
|
提示 |
|---|---|
|
A user custom GUI menu entry can be created by adding a
|
|
提示 |
|---|---|
|
Similarly, if a |
|
提示 |
|---|---|
|
Similarly, if a |
Some programs start another program automatically. Here are check points for customizing this process.
Application configuration menu:
GNOME3 desktop: "Settings" → "System" → "Details" → "Default Applications"
KDE desktop: "K" → "Control Center" → "KDE Components" → "Component Chooser"
Iceweasel browser: "Edit" → "Preferences" → "Applications"
mc(1):
"/etc/mc/mc.ext"
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 第 1.4.7 节 “设置默认文本编辑器”)
the "~/.mailcap" and "/etc/mailcap"
file contents which associate MIME type with
program (see
mailcap(5))
The "~/.mime.types" and
"/etc/mime.types" file contents which associate file name
extension with MIME type (see
run-mailcap(1))
|
提示 |
|---|---|
|
update-mime(8)
updates the " |
|
提示 |
|---|---|
|
The |
|
提示 |
|---|---|
|
In order to run a console application such as |
# cat /usr/local/bin/mutt-term <<EOF #!/bin/sh gnome-terminal -e "mutt \$@" EOF chmod 755 /usr/local/bin/mutt-term
Use kill(1) to kill (or send a signal to) a process by the process ID.
Use killall(1) or pkill(1) to do the same by the process command name and other attributes.
表 9.10. 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 |
Run the at(1) command to schedule a one-time job by the following.
$ echo 'command -args'| at 3:40 monday
Use cron(8) to schedule tasks regularly. See crontab(1) and crontab(5).
You can schedule to run processes as a normal user,
e.g. foo by creating a
crontab(5)
file as "/var/spool/cron/crontabs/foo" with
"crontab -e" command.
Here is an example of a crontab(5) 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
|
提示 |
|---|---|
|
For the system not running continuously, install the
|
|
提示 |
|---|---|
|
For scheduled system maintenance scripts, you can run them periodically from
root account by placing such scripts in
" |
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.
表 9.11. List of SAK command keys
| key following Alt-SysRq | description of action |
|---|---|
r
|
restore the keyboard from raw mode after X crashes |
0
|
change the console loglevel to 0 to reduce error messages |
k
|
kill all processes on the current virtual console |
e
|
send a SIGTERM to all processes, except for init(8) |
i
|
send a SIGKILL to all processes, except for init(8) |
s
|
sync all mounted filesystems to avoid data corruption |
u
|
remount all mounted filesystems read-only (umount) |
b
|
reboot the system without syncing or unmounting |
|
提示 |
|---|---|
|
Read the signal(7), kill(1), and sync(1) manpages to understand the description above. |
The combination of "Alt-SysRq s", "Alt-SysRq u", and "Alt-SysRq r" is good for getting out of really bad situations and gaining usable keyboard access without stopping the system.
参见
"/usr/share/doc/linux-doc-3.*/Documentation/sysrq.txt.gz".
|
小心 |
|---|---|
|
The Alt-SysRq feature may be considered a security risk by allowing users
access to root-privileged functions. Placing " |
|
提示 |
|---|---|
|
From SSH terminal etc., you can use the Alt-SysRq feature by writing to the
" |
你可以通过下面的方法检查谁登录在系统里。
who(1) 显示谁登录在系统里面。
w(1) 显示谁登录在系统里面,他们在做什么。
last(1) 显示用户最后登录的列表。
lastb(1) 显示用户最后错误登录的列表。
|
提示 |
|---|---|
|
" |
对于 PCI 类设备(AGP, PCI-Express, CardBus, ExpressCard 等), 一开始就使用
lspci(8)
(也许加上 "-nn" 选项) 进行硬件识别比较好。
此外,你可以通过阅读 "/proc/bus/pci/devices"
里面的内容或浏览"/sys/bus/pci" 下面的目录树来进行硬件识别(参见 第 1.2.12 节 “procfs 和 sysfs”).
表 9.12. 硬件识别工具列表
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
pciutils
|
V:167, I:992 | 1146 | Linux PCI 工具: lspci(8) |
usbutils
|
V:107, I:864 | 707 | Linux USB 工具: lsusb(8) |
pcmciautils
|
V:29, I:63 | 121 | Linux PCMCIA 工具: pccardctl(8) |
scsitools
|
V:0, I:4 | 351 | SCSI 硬件管理工具集: lsscsi(8) |
procinfo
|
V:1, I:17 | 183 |
从 "/proc":
lsdev(8)
获得系统信息
|
lshw
|
V:9, I:83 | 671 | 硬件配置信息: lshw(1) |
discover
|
V:42, I:919 | 122 | 硬件识别系统: discover(8) |
像 GNOME 和 KDE 这类现代图形桌面系统,虽然大部分硬件的配置都能够通过相应的图形配置工具来管理,但知道一些配置它们的基础方式,也是一个好的主意。
表 9.13. 硬件配置工具列表
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
console-setup
|
V:478, I:924 | 437 | Linux 控制台字体和键盘表工具 |
x11-xserver-utils
|
V:372, I:591 | 479 | X 服务端工具: xset(1), xmodmap(1) |
acpid
|
V:537, I:919 | 137 | 管理高级可配置和电源接口(ACPI)事件分发的后台守护进程(daemon) |
acpi
|
V:43, I:891 | 71 | 显示 ACPI 设备信息的工具 |
apmd
|
V:0, I:12 | 94 | 管理高级电源管理(APM)事件分发的后台守护进程(daemon) |
sleepd
|
V:0, I:0 | 77 | 在笔记本空闲时,使其进入休眠状态的后台守护进程(daemon) |
hdparm
|
V:259, I:404 | 231 | 硬盘访问优化 (参见 第 9.5.9 节 “Optimization of hard disk”) |
smartmontools
|
V:107, I:195 | 1716 | 使用 S.M.A.R.T. 控制和监控存储系统 |
setserial
|
V:6, I:13 | 109 | 串口管理工具集 |
memtest86+
|
V:1, I:41 | 2391 | 内存硬件管理工具集 |
scsitools
|
V:0, I:4 | 351 | SCSI 硬件管理工具集 |
setcd
|
V:0, I:1 | 28 | 光驱访问优化 |
big-cursor
|
I:0 | 27 | X 系统的大鼠标光标 |
|
提示 |
|---|---|
|
现代系统的 CPU 频率调整功能,是由内核模块 |
下面设置系统的硬件时间为:MM/DD hh:mm, CCYY.
# date MMDDhhmmCCYY # hwclock --utc --systohc # hwclock --show
Debian 系统的时间通常显示为本地时间,但硬件时间通常使用 UTC(GMT) 时间。
如果硬件(BIOS)时间设置为 UTC
时间,请在“/etc/default/rcS”里面设置“UTC=yes”。
下面是重新配置 Debian 系统使用的时区。
# dpkg-reconfigure tzdata
如果你希望通过网络来更新系统时间,考虑使用 ntp, ntpdate 和
chrony 这类包提供的 NTP 服务。
|
提示 |
|---|---|
|
在 systemd 下,是使用
|
参见下面内容。
ntp-doc 包
|
提示 |
|---|---|
|
在 |
There are several components to configure character console and ncurses(3) system features.
The "/etc/terminfo/*/*" file
(terminfo(5))
The "$TERM" environment variable
(term(7))
setterm(1), stty(1), tic(1), and toe(1)
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".
Device drivers for sound cards for current Linux are provided by Advanced Linux Sound Architecture (ALSA). ALSA provides emulation mode for previous Open Sound System (OSS) for compatibility.
|
提示 |
|---|---|
|
Use " |
|
提示 |
|---|---|
|
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 |
Application softwares may be configured not only to access sound devices directly but also to access them via some standardized sound server system.
表 9.14. List of sound packages
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
alsa-base
|
I:495 | 83 | ALSA driver configuration files |
alsa-utils
|
V:386, I:535 | 2115 | utilities for configuring and using ALSA |
oss-compat
|
V:6, I:51 | 7 |
OSS compatibility under ALSA preventing "/dev/dsp not
found" errors
|
jackd
|
V:4, I:27 | 32 | JACK Audio Connection Kit. (JACK) server (low latency) |
libjack0
|
V:1, I:22 | 134 | JACK Audio Connection Kit. (JACK) library (low latency) |
nas
|
V:0, I:0 | 235 | Network Audio System (NAS) server |
libaudio2
|
V:64, I:566 | 161 | Network Audio System (NAS) library |
pulseaudio
|
V:360, I:491 | 5620 | PulseAudio server, replacement for ESD |
libpulse0
|
V:250, I:654 | 946 | PulseAudio client library, replacement for ESD |
libgstreamer0.10-0
|
V:155, I:490 | NOT_FOUND | GStreamer: GNOME sound engine |
libphonon4
|
I:229 | 588 | Phonon: KDE 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.
关闭屏幕保护,使用下面的命令。
表 9.15. 关闭屏幕保护命令列表
| 环境 | 命令 |
|---|---|
| Linux 控制台 |
setterm -powersave off
|
| X Window (关闭屏幕保护) |
xset s off
|
| X Window (关闭 dpms) |
xset -dpms
|
| X Window (屏幕保护 GUI 配置) |
xscreensaver-command -prefs
|
可以把电脑的扬声器拔掉来关闭蜂鸣声。把 pcspkr 内核模块删除,也可以做到这点。
bash(1) 用到的 readline(3) 程序,当遇到告警字符(ASCII=7)时,将会发生。下面的操作将阻止发生。
$ echo "set bell-style none">> ~/.inputrc
There are 2 resources available for you to get the memory usage situation.
The kernel boot message in the "/var/log/dmesg" contains
the total exact size of available memory.
free(1) and top(1) display information on memory resources on the running system.
Here is an example.
# grep '\] Memory' /var/log/dmesg
[ 0.004000] 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
You may be wondering "dmesg tells me a free of 990 MB, and free -k says 320 MB is free. More than 600 MB missing …".
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 above) and relax.
For my MacBook with 1GB=1048576k DRAM (video system steals some of this), I see the following.
表 9.16. List of memory sizes reported
| report | 大小 |
|---|---|
| Total size in dmesg | 1016784k = 1GB - 31792k |
| Free in dmesg | 990528k |
| Total under shell | 997184k |
| Free under shell | 20256k (but effectively 321780k) |
Poor system maintenance may expose your system to external exploitation.
For system security and integrity check, you should start with the following.
The debsums package, see
debsums(1)
and 第 2.5.2 节 “Top level "Release" file and authenticity”.
The chkrootkit package, see
chkrootkit(1).
The clamav package family, see
clamscan(1)
and
freshclam(1).
表 9.17. List of tools for system security and integrity check
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
logcheck
|
V:13, I:15 | 216 | daemon to mail anomalies in the system logfiles to the administrator |
debsums
|
V:6, I:38 | 118 | utility to verify installed package files against MD5 checksums |
chkrootkit
|
V:8, I:29 | 948 | rootkit detector |
clamav
|
V:17, I:73 | 873 | anti-virus utility for Unix - command-line interface |
tiger
|
V:3, I:4 | 2581 | report system security vulnerabilities |
tripwire
|
V:3, I:4 | 11301 | file and directory integrity checker |
john
|
V:3, I:14 | 448 | active password cracking tool |
aide
|
V:1, I:2 | 1981 | Advanced Intrusion Detection Environment - static binary |
integrit
|
V:0, I:0 | 440 | file integrity verification program |
crack
|
V:0, I:0 | 124 | password guessing program |
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 \)
|
小心 |
|---|---|
|
Since the |
Booting your system with Linux live CDs or debian-installer CDs in rescue mode makes it easy for you to reconfigure data storage on your boot device.
The disk space usage can be evaluated by programs provided by the
mount, coreutils, and
xdu packages:
mount(8) reports all mounted filesystems (= disks).
df(1) reports the disk space usage for the file system.
du(1) reports the disk space usage for the directory tree.
|
提示 |
|---|---|
|
You can feed the output of
du(8)
to
xdu(1x)
to produce its graphical and interactive presentation with " |
For disk 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.
Most PCs use the classic Master Boot Record (MBR) scheme to hold disk partitioning data in the first sector, i.e., LBA sector 0 (512 bytes).
|
注意 |
|---|---|
|
Some new PCs with Extensible Firmware Interface (EFI), including Intel-based Macs, use GUID Partition Table (GPT) scheme to hold disk partitioning data not in the first sector. |
Although fdisk(8) has been standard for the disk partitioning tool, parted(8) is replacing it.
表 9.18. List of disk partition management packages
| 软件包 | 流行度 | 大小 | GPT | 说明 |
|---|---|---|---|---|
util-linux
|
V:876, I:999 | 3331 | 不支持 | miscellaneous system utilities including fdisk(8) and cfdisk(8) |
parted
|
V:332, I:522 | 278 | 支持 | GNU Parted disk partition resizing program |
gparted
|
V:26, I:149 | 6519 | 支持 |
GNOME partition editor based on libparted
|
gdisk
|
V:17, I:443 | 746 | 支持 | partition editor for the GPT disk |
kpartx
|
V:15, I:27 | 76 | 支持 | program to create device mappings for partitions |
|
小心 |
|---|---|
|
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), mkfs.ext4(8), …) and resize2fs(8). |
|
注意 |
|---|---|
|
In order to switch between GPT and MBR, you need to erase first few blocks of disk contents
directly (see 第 9.7.6 节 “Clearing file contents”) and use
" |
Although reconfiguration of your partition or activation order of removable storage media 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.
mount(8)
with "-U" option can mount a block device using UUID, instead of using its file name such as
"/dev/sda3".
"/etc/fstab" (see
fstab(5))
can use UUID.
Boot loaders (第 3.1.2 节 “第二阶段:引载加载程序”) may use UUID too.
|
提示 |
|---|---|
|
You can probe UUID of a block special device with blkid(8). |
|
提示 |
|---|---|
|
Device nodes of devices such as removable storage media can be made static by using udev rules, if needed. See 第 3.3 节 “udev 系统”. |
LVM2 is a logical volume manager for the Linux kernel. With LVM2, disk partitions can be created on logical volumes instead of the physical harddisks.
LVM requires the following.
device-mapper support in the Linux kernel (default for Debian kernels)
the userspace device-mapper support library
(libdevmapper* package)
the userspace LVM2 tools (lvm2 package)
Please start learning LVM2 from the following manpages.
lvm(8): Basics of LVM2 mechanism (list of all LVM2 commands)
lvm.conf(5): Configuration file for LVM2
lvs(8): Report information about logical volumes
vgs(8): Report information about volume groups
pvs(8): Report information about physical volumes
对于 ext4 文件系统, e2fsprogs
包提供下面的工具。
The
mkfs(8)
and
fsck(8)
commands are provided by the e2fsprogs package as
front-ends to various filesystem dependent programs
(mkfs.fstype and fsck.fstype). For
ext4 filesystem, they are
mkfs.ext4(8)
and
fsck.ext4(8)
(they are symlinked to
mke2fs(8)
and
e2fsck(8)).
Linux 支持的每一个文件系统,有相似的命令。
表 9.19. 文件系统管理包列表
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
e2fsprogs
|
V:435, I:999 | 3851 | ext2/ext3/ext4 文件系统工具 |
reiserfsprogs
|
V:5, I:23 | 882 | Reiserfs 文件系统工具 |
dosfstools
|
V:79, I:575 | 236 | FAT 文件系统工具. (Microsoft: MS-DOS, Windows) |
xfsprogs
|
V:21, I:78 | 3748 | XFS 文件系统工具. (SGI: IRIX) |
ntfs-3g
|
V:230, I:569 | 1335 | NTFS 文件系统工具. (Microsoft: Windows NT, …) |
jfsutils
|
V:2, I:14 | 1031 | JFS 文件系统工具. (IBM: AIX, OS/2) |
reiser4progs
|
V:0, I:5 | 1569 | Reiser4 文件系统工具 |
hfsprogs
|
V:0, I:9 | 295 | HFS 和 HFS Plus 文件系统工具. (Apple: Mac OS) |
btrfs-tools
|
V:15, I:39 | 24 | Btrfs 文件系统工具 |
zerofree
|
V:2, I:45 | 14 | 把 ext2/3/4 文件系统上空闲块设置为零的程序 |
|
提示 |
|---|---|
|
Ext4 文件系统是 Linux 系统上默认的文件系统,强烈推荐使用这个文件系统,除非你有特殊的理由不使用。 |
|
提示 |
|---|---|
|
Btrfs 文件系统在 Linux 内核 3.2(Debian
|
|
警告 |
|---|---|
|
在得到当前内核空间的 fsck(8) 特征和引导管理器支持前,你的关键数据不应当使用 Btrfs 文件系统。 |
|
提示 |
|---|---|
|
一些工具可以在没有 Linux 内核支持的情况下访问文件系统(参见 第 9.7.2 节 “不挂载磁盘操作文件”). |
mkfs(8) 在 Linux 系统上创建文件系统。fsck(8) 命令在 Linux系统上提供文件系统完整性检查和修复功能。
在文件系统创建后,Debian 现在默认不周期性的运行 fsck。
|
小心 |
|---|---|
|
在已经挂载的文件系统上运行 |
|
提示 |
|---|---|
|
在 " |
|
提示 |
|---|---|
|
从启动脚本里面运行的
fsck(8)
命令结果,可以在 " |
The basic static filesystem configuration is given by
"/etc/fstab". For example,
# <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 UUID=709cbe4c-80c1-56db-8ab1-dbce3146d2f7 / ext4 noatime,errors=remount-ro 0 1 UUID=817bae6b-45d2-5aca-4d2a-1267ab46ac23 none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
|
提示 |
|---|---|
|
UUID (see 第 9.5.3 节 “Accessing partition using UUID”) may be used to identify a block
device instead of normal block device names such as
" |
Performance and characteristics of a filesystem can be optimized by mount options used on it (see fstab(5) and mount(8)). Notable ones are the following.
"defaults" option implies default options:
"rw,suid,dev,exec,auto,nouser,async". (general)
"noatime" or "relatime" option is very
effective for speeding up the read access. (general)
"user" option allows an ordinary user to mount the
filesystem. This option implies "noexec,nosuid,nodev"
option combination. (general, used for CDs or usb storage devices)
"noexec,nodev,nosuid" option combination is used to
enhance security. (general)
"noauto" option limits mounting by explicit operation
only. (general)
"data=journal" option for ext3fs can enhance data
integrity against power failure with some loss of write speed.
|
提示 |
|---|---|
|
You need to provide kernel boot parameter (see 第 3.1.2 节 “第二阶段:引载加载程序”),
e.g. " |
Characteristics of a filesystem can be optimized via its superblock using the tune2fs(8) command.
Execution of "sudo tune2fs -l /dev/hda1" displays the
contents of the filesystem superblock on "/dev/hda1".
Execution of "sudo tune2fs -c 50 /dev/hda1" changes
frequency of filesystem checks (fsck execution during
boot-up) to every 50 boots on "/dev/hda1".
Execution of "sudo tune2fs -j /dev/hda1" adds journaling
capability to the filesystem, i.e. filesystem conversion from ext2 to ext3 on
"/dev/hda1". (Do this on the unmounted filesystem.)
Execution of "sudo tune2fs -O extents,uninit_bg,dir_index /dev/hda1
&& fsck -pf /dev/hda1" converts it from ext3 to ext4 on
"/dev/hda1". (Do this on the unmounted filesystem.)
|
警告 |
|---|---|
|
Please check your hardware and read manpage of hdparam(8) before playing with hard disk configuration because this may be quite dangerous for the data integrity. |
You can test disk access speed of a hard disk,
e.g. "/dev/hda", by "hdparm -tT
/dev/hda". For some hard disk 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!).
You can test write cache feature of a hard disk,
e.g. "/dev/sda", by "hdparm -W
/dev/sda". You can disable its write cache feature with
"hdparm -W 0 /dev/sda".
You may be able to read badly pressed CDROMs on modern high speed CD-ROM
drive by slowing it down with "setcd -x 2".
Performance and disk wear of the solid state drive (SSD) can be optimized as follows.
Use the latest Linux kernel. (>= 3.2)
Reduce disk writes for read disk accesses.
Set "noatime" or "relatime" mount
option in /etc/fstab.
Enable the TRIM command.
Enable the SSD optimized disk space allocation scheme.
Set "ssd" mount option in /etc/fstab
for the Btrfs.
Make system flush data to the disk every 10 minutes for laptop PCs.
Set "commit=600" mount option in
/etc/fstab. See
fstab(5).
Set pm-utils to use laptop-mode even under AC operation. See Debian BTS #659260.
|
警告 |
|---|---|
|
Changing flushing interval from normal 5 seconds to 10 minutes makes your data vulnerable to the power failure. |
You can monitor and log your hard disk which is compliant to SMART with the smartd(8) daemon.
Install the smartmontools package.
Identify your hard disk drives by listing them with df(1).
Let's assume a hard disk drive to be monitored as
"/dev/hda".
Check the output of "smartctl -a /dev/hda" to see if
SMART feature is actually enabled.
If not, enable it by "smartctl -s on -a /dev/hda".
Enable smartd(8) daemon to run by the following.
uncomment "start_smartd=yes" in the
"/etc/default/smartmontools" file.
restart the
smartd(8)
daemon by "sudo /etc/init.d/smartmontools restart".
|
提示 |
|---|---|
|
The
smartd(8)
daemon can be customized with the |
Applications create temporary files normally under the temporary storage
directory "/tmp". If "/tmp" does not
provide enough space, you can specify such temporary storage directory via
the $TMPDIR variable for well-behaving programs.
For partitions created on Logical Volume Manager (LVM) (Linux feature) 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.
If you have an empty partition (e.g., "/dev/sdx"), you
can format it with
mkfs.ext4(1)
and
mount(8)
it to a directory where you need more space. (You need to copy original data
contents.)
$ sudo mv work-dir old-dir $ sudo mkfs.ext4 /dev/sdx $ sudo mount -t ext4 /dev/sdx work-dir $ sudo cp -a old-dir/* work-dir $ sudo rm -rf old-dir
|
提示 |
|---|---|
|
You may alternatively mount an empty disk image file (see 第 9.6.5 节 “Making the empty disk image file”) as a loop device (see 第 9.6.3 节 “Mounting the disk image file”). The actual disk usage grows with the actual data stored. |
If you have an empty directory (e.g., "/path/to/emp-dir")
on another partition with usable space, you can mount(8) it with
"--bind" option to a directory (e.g.,
"work-dir") where you need more space.
$ sudo mount --bind /path/to/emp-dir work-dir
|
提示 |
|---|---|
|
This is a deprecated method. Use 第 9.5.15 节 “Expansion of usable storage space by bind-mounting another directory” instead, if possible. |
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).
$ sudo mv work-dir old-dir $ sudo mkdir -p /path/to/emp-dir $ sudo ln -sf /path/to/emp-dir work-dir $ sudo cp -a old-dir/* work-dir $ sudo rm -rf old-dir
|
警告 |
|---|---|
|
Do not use "symlink to a directory" for directories managed by the system
such as " |
|
小心 |
|---|---|
|
Some software may not function well with "symlink to a directory". |
If you have usable space in another partition (e.g.,
"/path/to/empty" and "/path/to/work"),
you can create a directory in it and stack that on to an old directory
(e.g., "/path/to/old") where you need space with OverlayFS with Linux kernel 3.18 or newer (Debian
Stetch 9.0 or newer).
$ sudo mount -t overlay overlay \ -olowerdir=/path/to/old-dir,upperdir=/path/to/empty,workdir=/path/to/work
Here, "/path/to/empty" and
"/path/to/work" should be on the RW-enabled partition to
write on "/path/to/old".
Here, we discuss manipulations of the disk image.
The disk image file, "disk.img", of an unmounted device,
e.g., the second SCSI or serial ATA drive "/dev/sdb", can
be made using
cp(1)
or
dd(1)
by the following.
# cp /dev/sdb disk.img # dd if=/dev/sdb of=disk.img
The disk image of the traditional PC's master boot record (MBR) (see 第 9.5.2 节 “Disk partition configuration”) which reside on the first sector on the primary IDE disk can be made by using dd(1) by the following.
# dd if=/dev/hda of=mbr.img bs=512 count=1 # dd if=/dev/hda of=mbr-nopart.img bs=446 count=1 # dd if=/dev/hda of=mbr-part.img skip=446 bs=1 count=66
"mbr.img": The MBR with the partition table
"mbr-nopart.img": The MBR without the partition table
"mbr-part.img": The partition table of the MBR only
If you have an SCSI or serial ATA device as the boot disk, substitute
"/dev/hda" with "/dev/sda".
If you are making an image of a disk partition of the original disk,
substitute "/dev/hda" with "/dev/hda1"
etc.
The disk image file, "disk.img" can be written to an
unmounted device, e.g., the second SCSI drive "/dev/sdb"
with matching size, by the following.
# dd if=disk.img of=/dev/sdb
Similarly, the disk partition image file, "partition.img"
can be written to an unmounted partition, e.g., the first partition of the
second SCSI drive "/dev/sdb1" with matching size, by the
following.
# dd if=partition.img of=/dev/sdb1
The disk image "partition.img" containing a single
partition image can be mounted and unmounted by using the loop device as follows.
# losetup -v -f partition.img Loop device is /dev/loop0 # mkdir -p /mnt/loop0 # mount -t auto /dev/loop0 /mnt/loop0 ...hack...hack...hack # umount /dev/loop0 # losetup -d /dev/loop0
This can be simplified as follows.
# mkdir -p /mnt/loop0 # mount -t auto -o loop partition.img /mnt/loop0 ...hack...hack...hack # umount partition.img
Each partition of the disk image "disk.img" containing
multiple partitions can be mounted by using the loop device. Since the loop device does not
manage partitions by default, we need to reset it as follows.
# modinfo -p loop # verify kernel capability max_part:Maximum number of partitions per loop device max_loop:Maximum number of loop devices # losetup -a # verify nothing using the loop device # rmmod loop # modprobe loop max_part=16
Now, the loop device can manage up to 16 partitions.
# losetup -v -f disk.img
Loop device is /dev/loop0
# fdisk -l /dev/loop0
Disk /dev/loop0: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x452b6464
Device Boot Start End Blocks Id System
/dev/loop0p1 1 600 4819468+ 83 Linux
/dev/loop0p2 601 652 417690 83 Linux
# mkdir -p /mnt/loop0p1
# mount -t ext4 /dev/loop0p1 /mnt/loop0p1
# mkdir -p /mnt/loop0p2
# mount -t ext4 /dev/loop0p2 /mnt/loop0p2
...hack...hack...hack
# umount /dev/loop0p1
# umount /dev/loop0p2
# losetup -d /dev/loop0
Alternatively, similar effects can be done by using the device mapper devices created by
kpartx(8)
from the kpartx package as follows.
# kpartx -a -v disk.img ... # mkdir -p /mnt/loop0p2 # mount -t ext4 /dev/mapper/loop0p2 /mnt/loop0p2 ... ...hack...hack...hack # umount /dev/mapper/loop0p2 ... # kpartx -d /mnt/loop0
|
注意 |
|---|---|
|
You can mount a single partition of such disk image with loop device using offset to skip MBR etc., too. But this is more error prone. |
A disk image file, "disk.img" can be cleaned of all
removed files into clean sparse image "new.img" by the
following.
# mkdir old; mkdir new # mount -t auto -o loop disk.img old # dd bs=1 count=0 if=/dev/zero of=new.img seek=5G # mount -t auto -o loop new.img new # cd old # cp -a --sparse=always ./ ../new/ # cd .. # umount new.img # umount disk.img
If "disk.img" is in ext2, ext3 or ext4, you can also use
zerofree(8)
from the zerofree package as follows.
# losetup -f -v disk.img Loop device is /dev/loop3 # zerofree /dev/loop3 # cp --sparse=always disk.img new.img
The empty disk image "disk.img" which can grow up to 5GiB
can be made using
dd(1)
as follows.
$ dd bs=1 count=0 if=/dev/zero of=disk.img seek=5G
You can create an ext4 filesystem on this disk image
"disk.img" using the loop
device as follows.
# losetup -f -v disk.img Loop device is /dev/loop1 # mkfs.ext4 /dev/loop1 ...hack...hack...hack # losetup -d /dev/loop1 $ du --apparent-size -h disk.img 5.0G disk.img $ du -h disk.img 83M disk.img
For "disk.img", its file size is 5.0 GiB and its actual
disk usage is mere 83MiB. This discrepancy is possible since ext4 can hold sparse
file.
|
提示 |
|---|---|
|
The actual disk usage of sparse file grows with data which are written to it. |
Using similar operation on devices created by the loop device or the device mapper devices as 第 9.6.3 节 “Mounting the disk image file”, you can partition this disk image
"disk.img" using
parted(8)
or
fdisk(8),
and can create filesystem on it using
mkfs.ext4(8),
mkswap(8),
etc.
The ISO9660 image file,
"cd.iso", from the source directory tree at
"source_directory" can be made using
genisoimage(1)
provided by cdrkit by the following.
# genisoimage -r -J -T -V volume_id -o cd.iso source_directory
Similarly, the bootable ISO9660 image file, "cdboot.iso",
can be made from debian-installer like directory tree at
"source_directory" by the following.
# genisoimage -r -o cdboot.iso -V volume_id \ -b isolinux/isolinux.bin -c isolinux/boot.cat \ -no-emul-boot -boot-load-size 4 -boot-info-table source_directory
Here Isolinux boot loader (see 第 3.1.2 节 “第二阶段:引载加载程序”) is used for booting.
You can calculate the md5sum value and make the ISO9660 image directly from the CD-ROM device as follows.
$ isoinfo -d -i /dev/cdrom CD-ROM is in ISO 9660 format ... Logical block size is: 2048 Volume size is: 23150592 ... # dd if=/dev/cdrom bs=2048 count=23150592 conv=notrunc,noerror | md5sum # dd if=/dev/cdrom bs=2048 count=23150592 conv=notrunc,noerror > cd.iso
|
警告 |
|---|---|
|
You must carefully avoid ISO9660 filesystem read ahead bug of Linux as above to get the right result. |
|
提示 |
|---|---|
|
DVD is only a large CD to wodim(1) provided by cdrkit. |
You can find a usable device by the following.
# wodim --devices
Then the blank CD-R is inserted to the CD drive, and the ISO9660 image file,
"cd.iso" is written to this device, e.g.,
"/dev/hda", using
wodim(1)
by the following.
# wodim -v -eject dev=/dev/hda cd.iso
If CD-RW is used instead of CD-R, do this instead by the following.
# wodim -v -eject blank=fast dev=/dev/hda cd.iso
|
提示 |
|---|---|
|
If your desktop system mounts CDs automatically, unmount it by
" |
如果 "cd.iso" 包含一个 ISO9660 镜像, 下面的命令手工挂载这个文件到
"/cdrom".
# mount -t iso9660 -o ro,loop cd.iso /cdrom
|
提示 |
|---|---|
|
现代桌面系统能够自动挂载可移动介质,如按 ISO9660 格式化的 CD(参见 第 10.1.7 节 “Removable storage device”). |
这里,我们讨论直接操作存储介质上的二进制数据。
The most basic viewing method of binary data is to use "od -t
x1" command.
表 9.20. List of packages which view and edit binary data
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
coreutils
|
V:877, I:999 | 14783 | basic package which has od(1) to dump files (HEX, ASCII, OCTAL, …) |
bsdmainutils
|
V:864, I:998 | 566 | utility package which has hd(1) to dump files (HEX, ASCII, OCTAL, …) |
hexedit
|
V:1, I:11 | 60 | binary editor and viewer (HEX, ASCII) |
bless
|
V:0, I:5 | 973 | full featured hexadecimal editor (GNOME) |
okteta
|
V:2, I:24 | 380 | full featured hexadecimal editor (KDE4) |
ncurses-hexedit
|
V:0, I:3 | 126 | binary editor and viewer (HEX, ASCII, EBCDIC) |
beav
|
V:0, I:1 | 121 | binary editor and viewer (HEX, ASCII, EBCDIC, OCTAL, …) |
|
提示 |
|---|---|
|
HEX is used as an acronym for hexadecimal format with radix 16. OCTAL is for octal format with radix 8. ASCII is for American Standard Code for Information Interchange, i.e., normal English text code. EBCDIC is for Extended Binary Coded Decimal Interchange Code used on IBM mainframe operating systems. |
Software RAID systems offered by the Linux kernel provide data redundancy in the kernel filesystem level to achieve high levels of storage reliability.
There are tools to add data redundancy to files in application program level to achieve high levels of storage reliability, too.
表 9.22. List of tools to add data redundancy to files
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
par2
|
V:2, I:12 | 231 | Parity Archive Volume Set, for checking and repair of files |
dvdisaster
|
V:0, I:2 | 1481 | data loss/scratch/aging protection for CD/DVD media |
dvbackup
|
V:0, I:0 | 412 | backup tool using MiniDV camcorders (providing rsbep(1)) |
vdmfec
|
V:0, I:0 | 88 | recover lost blocks using Forward Error Correction |
There are tools for data file recovery and forensic analysis.
表 9.23. List of packages for data file recovery and forensic analysis
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
testdisk
|
V:4, I:38 | 1260 | utilities for partition scan and disk recovery |
magicrescue
|
V:0, I:3 | 226 | utility to recover files by looking for magic bytes |
scalpel
|
V:0, I:3 | 112 | frugal, high performance file carver |
myrescue
|
V:0, I:2 | 38 | rescue data from damaged harddisks |
extundelete
|
V:0, I:10 | 140 | utility to undelete files on the ext3/4 filesystem |
ext4magic
|
V:0, I:2 | 232 | utility to undelete files on the ext3/4 filesystem |
ext3grep
|
V:0, I:2 | 278 | tool to help recover deleted files on the ext3 filesystem |
scrounge-ntfs
|
V:0, I:2 | 45 | data recovery program for NTFS filesystems |
gzrt
|
V:0, I:0 | 57 | gzip recovery toolkit |
sleuthkit
|
V:0, I:5 | 1092 | tools for forensics analysis. (Sleuthkit) |
autopsy
|
V:0, I:2 | 1021 | graphical interface to SleuthKit |
foremost
|
V:0, I:6 | 123 | forensics application to recover data |
guymager
|
V:0, I:0 | 1014 | forensic imaging tool based on Qt |
dcfldd
|
V:0, I:5 | 121 |
enhanced version of dd for forensics and security
|
|
提示 |
|---|---|
|
You can undelete files on the ext2 filesystem using
|
When a data is too big to backup as a single file, you can backup its content after splitting it into, e.g. 2000MiB chunks and merge those chunks back into the original file later.
$ split -b 2000m large_file $ cat x* >large_file
|
小心 |
|---|---|
|
Please make sure you do not have any files starting with
" |
In order to clear the contents of a file such as a log file, do not use rm(1) to delete the file and then create a new empty file, because the file may still be accessed in the interval between commands. The following is the safe way to clear the contents of the file.
$ :>file_to_be_cleared
下面的命令创建样子文件或空文件。
$ dd if=/dev/zero of=5kb.file bs=1k count=5 $ dd if=/dev/urandom of=7mb.file bs=1M count=7 $ touch zero.file $ : > alwayszero.file
你将发现下列文件。
"5kb.file" 是 5KB 零。
"7mb.file" 是 7MB 随机数据。
"zero.file" 也许是一个 0 字节的文件。如果这个文件之前就存在,则它的
mtime 会被更新,而它的内容和长度保持不变。
"alwayszero.file" 一定是一个 0 字节文件。如果这个文件之前存在,则它的
mtime 会被更新,而它的内容会被清零。
There are several ways to completely erase data from an entire hard disk
like device, e.g., USB memory stick at "/dev/sda".
|
小心 |
|---|---|
|
Check your USB memory stick location with
mount(8)
first before executing commands here. The device pointed by
" |
Erase all the disk content by resetting data to 0 with the following.
# dd if=/dev/zero of=/dev/sda
Erase everything by overwriting with random data as follows.
# dd if=/dev/urandom of=/dev/sda
Erase everything by overwriting with random data very efficiently as follows.
# shred -v -n 1 /dev/sda
Since
dd(1)
is available from the shell of many bootable Linux CDs such as Debian
installer CD, you can erase your installed system completely by running an
erase command from such media on the system hard disk, e.g.,
"/dev/hda", "/dev/sda", etc.
Unused area on an hard disk (or USB memory stick),
e.g. "/dev/sdb1" may still contain erased data themselves
since they are only unlinked from the filesystem. These can be cleaned by
overwriting them.
# mount -t auto /dev/sdb1 /mnt/foo # cd /mnt/foo # dd if=/dev/zero of=junk dd: writing to `junk': No space left on device ... # sync # umount /dev/sdb1
|
警告 |
|---|---|
|
This is usually good enough for your USB memory stick. But this is not perfect. Most parts of erased filenames and their attributes may be hidden and remain in the filesystem. |
Even if you have accidentally deleted a file, as long as that file is still being used by some application (read or write mode), it is possible to recover such a file.
尝试下列例子
$ echo foo > bar $ less bar $ ps aux | grep ' less[ ]' bozo 4775 0.0 0.0 92200 884 pts/8 S+ 00:18 0:00 less bar $ rm bar $ ls -l /proc/4775/fd | grep bar lr-x------ 1 bozo bozo 64 2008-05-09 00:19 4 -> /home/bozo/bar (deleted) $ cat /proc/4775/fd/4 >bar $ ls -l -rw-r--r-- 1 bozo bozo 4 2008-05-09 00:25 bar $ cat bar foo
Execute on another terminal (when you have the lsof
package installed) as follows.
$ ls -li bar 2228329 -rw-r--r-- 1 bozo bozo 4 2008-05-11 11:02 bar $ lsof |grep bar|grep less less 4775 bozo 4r REG 8,3 4 2228329 /home/bozo/bar $ rm bar $ lsof |grep bar|grep less less 4775 bozo 4r REG 8,3 4 2228329 /home/bozo/bar (deleted) $ cat /proc/4775/fd/4 >bar $ ls -li bar 2228302 -rw-r--r-- 1 bozo bozo 4 2008-05-11 11:05 bar $ cat bar foo
有硬链接的文件,能够使用 "ls -li" 确认。
$ ls -li total 0 2738405 -rw-r--r-- 1 root root 0 2008-09-15 20:21 bar 2738404 -rw-r--r-- 2 root root 0 2008-09-15 20:21 baz 2738404 -rw-r--r-- 2 root root 0 2008-09-15 20:21 foo
"baz" 和 "foo" 的链接数为 "2"
(>1),表示他们有硬链接。它们的 inode
号都是"2738404".这表示它们是同样的硬链接文件。如果你不想偶然碰巧发现硬链接文件,你可以通过 inode 号来查找它。比如说, 按下面的方式查找 "2738404" 。
# find /path/to/mount/point -xdev -inum 2738404
With physical access to your PC, anyone can easily gain root privilege and access all the files on your PC (see 第 4.7.4 节 “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 GNU privacy guard (see 第 10.3 节 “Data security infrastructure”) can encrypt files, it takes some user efforts.
dm-crypt and eCryptfs facilitates automatic data encryption natively via Linux kernel modules with minimal user efforts.
表 9.24. List of data encryption utilities
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
cryptsetup
|
V:28, I:71 | 331 | utilities for encrypted block device (dm-crypt / LUKS) |
cryptmount
|
V:1, I:3 | 219 | utilities for encrypted block device (dm-crypt / LUKS) with focus on mount/unmount by normal users |
ecryptfs-utils
|
V:5, I:9 | 393 | utilities for encrypted stacked filesystem (eCryptfs) |
Dm-crypt is a cryptographic filesystem using device-mapper. Device-mapper maps one block device to another.
eCryptfs is another cryptographic filesystem using stacked filesystem. Stacked filesystem stacks itself on top of an existing directory of a mounted filesystem.
|
小心 |
|---|---|
|
Data encryption costs CPU time etc. Please weigh its benefits and costs. |
|
注意 |
|---|---|
|
Entire Debian system can be installed on a encrypted disk by the debian-installer (lenny or newer) using dm-crypt/LUKS and initramfs. |
|
提示 |
|---|---|
|
See 第 10.3 节 “Data security infrastructure” for user space encryption utility: GNU Privacy Guard. |
You can encrypt contents of removable mass devices, e.g. USB memory stick on
"/dev/sdx", using dm-crypt/LUKS. You
simply format it as the following.
# badblocks -c 1024 -s -w -t random -v /dev/sdx # fdisk /dev/sdx ... "n" "p" "1" "return" "return" "w" # cryptsetup luksFormat /dev/sdx1 ... # cryptsetup open --type luks /dev/sdx1 sdx1 ... # ls -l /dev/mapper/ total 0 crw-rw---- 1 root root 10, 60 2008-10-04 18:44 control brw-rw---- 1 root disk 254, 0 2008-10-04 23:55 sdx1 # mkfs.vfat /dev/mapper/sdx1 ... # cryptsetup luksClose sdx1
Then, it can be mounted just like normal one on to
"/media/<disk_label>", except for asking password
(see 第 10.1.7 节 “Removable 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 filesystem, e.g., ext4 with
"mkfs.ext4 /dev/mapper/sdx1".
|
注意 |
|---|---|
|
If you are really paranoid for the security of data, you may need to
overwrite multiple times (the " |
Let's assume that your original "/etc/fstab" contains the
following.
/dev/sda7 swap sw 0 0
You can enable encrypted swap partition using dm-crypt by as the following.
# aptitude install cryptsetup # swapoff -a # echo "cswap /dev/sda7 /dev/urandom swap" >> /etc/crypttab # perl -i -p -e "s/\/dev\/sda7/\/dev\/mapper\/cswap/" /etc/fstab # /etc/init.d/cryptdisks restart ... # swapon -a
An encrypted disk partition created with dm-crypt/LUKS on
"/dev/sdc5" can be mounted onto "/mnt"
as follows:
$ sudo cryptsetup open /dev/sdc5 ninja --type luks Enter passphrase for /dev/sdc5: **** $ sudo lvm lvm> lvscan inactive '/dev/ninja-vg/root' [13.52 GiB] inherit inactive '/dev/ninja-vg/swap_1' [640.00 MiB] inherit ACTIVE '/dev/goofy/root' [180.00 GiB] inherit ACTIVE '/dev/goofy/swap' [9.70 GiB] inherit lvm> lvchange -a y /dev/ninja-vg/root lvm> exit Exiting. $ sudo mount /dev/ninja-vg/root /mnt
You can encrypt files written under "~/Private/"
automatically using eCryptfs and the
ecryptfs-utils package.
Run
ecryptfs-setup-private(1)
and set up "~/Private/" by following prompts.
Activate "~/Private/" by running
ecryptfs-mount-private(1).
Move sensitive data files to "~/Private/" and make
symlinks as needed.
Candidates: "~/.fetchmailrc",
"~/.ssh/identity", "~/.ssh/id_rsa",
"~/.ssh/id_dsa" and other files with
"go-rwx"
Move sensitive data directories to a subdirectory in
"~/Private/" and make symlinks as needed.
Candidates: "~/.gnupg" and other directories with
"go-rwx"
Create symlink from "~/Desktop/Private/" to
"~/Private/" for easier desktop operations.
Deactivate "~/Private/" by running
ecryptfs-umount-private(1).
Activate "~/Private/" by issuing
"ecryptfs-mount-private" as you need encrypted data.
If you use your login password for wrapping encryption keys, you can automate mounting eCryptfs via PAM (Pluggable Authentication Modules).
Insert the following line just before "pam_permit.so" in
"/etc/pam.d/common-auth".
auth required pam_ecryptfs.so unwrap
Insert the following line just at the last line in
"/etc/pam.d/common-session".
session optional pam_ecryptfs.so unwrap
Insert the following line at first active line in
"/etc/pam.d/common-password".
password required pam_ecryptfs.so
This is quite convenient.
|
警告 |
|---|---|
|
Configuration errors of PAM may lock you out of your own system. See 第 4 章 Authentication. |
|
小心 |
|---|---|
|
If you use your login password for wrapping encryption keys, your encrypted data are as secure as your user login password (see 第 4.3 节 “Good password”). Unless you are careful to set up a strong password, your data is at risk when someone runs password cracking software after stealing your laptop (see 第 4.7.4 节 “Securing the root password”). |
Debian distributes modularized Linux kernel as packages for supported architectures.
There are few notable features on Linux kernel 2.6/3.x compared to 2.4.
Devices are created by the udev system (see 第 3.3 节 “udev 系统”).
Read/write accesses to IDE CD/DVD devices do not use the
ide-scsi module.
Network packet filtering functions use iptables kernel
modules.
The version bump from Linux 2.6.39 to Linux 3.0 is not about major technological changes but about the 20th anniversary.
Many Linux features are configurable via kernel parameters as follows.
Kernel parameters initialized by the bootloader (see 第 3.1.2 节 “第二阶段:引载加载程序”)
Kernel parameters changed by sysctl(8) at runtime for ones accessible via sysfs (see 第 1.2.12 节 “procfs 和 sysfs”)
Module parameters set by arguments of modprobe(8) when a module is activated (see 第 9.6.3 节 “Mounting the disk image file”)
See "kernel-parameters.txt(.gz)" and other related
documents in the Linux kernel documentation
("/usr/share/doc/linux-doc-3.*/Documentation/filesystems/*")
provided by the linux-doc-3.* package.
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.
|
注意 |
|---|---|
|
For compiling some kernel-specific programs such as the kernel modules from
the external source and the automounter daemon ( |
Debian has its own method of compiling the kernel and related modules.
表 9.25. List of key packages to be installed for the kernel recompilation on the Debian system
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
build-essential
|
I:451 | 20 |
essential packages for building Debian packages: make,
gcc, …
|
bzip2
|
V:257, I:929 | 84 | compress and decompress utilities for bz2 files |
libncurses5-dev
|
V:14, I:152 | 1008 | developer's libraries and docs for ncurses |
git
|
V:242, I:410 | 26512 | git: distributed revision control system used by the Linux kernel |
fakeroot
|
V:34, I:499 | 212 | provide fakeroot environment for building package as non-root |
initramfs-tools
|
V:281, I:990 | 102 | tool to build an initramfs (Debian specific) |
dkms
|
V:96, I:215 | 280 | dynamic kernel module support (DKMS) (generic) |
devscripts
|
V:10, I:66 | 2055 | helper scripts for a Debian Package maintainer (Debian specific) |
If you use initrd in 第 3.1.2 节 “第二阶段:引载加载程序”, make sure to read the related
information in
initramfs-tools(8),
update-initramfs(8),
mkinitramfs(8)
and
initramfs.conf(5).
|
警告 |
|---|---|
|
Do not put symlinks to the directories in the source tree
(e.g. " |
|
注意 |
|---|---|
|
When compiling the latest Linux kernel on the Debian
|
|
注意 |
|---|---|
|
The dynamic kernel module support (DKMS) is a new distribution independent framework designed to allow individual kernel modules to be upgraded without changing the whole kernel. This is used for the maintenance of out-of-tree modules. This also makes it very easy to rebuild modules as you upgrade kernels. |
For building custom kernel binary packages from the upstream kernel source,
you should use the "deb-pkg" target provided by it.
$ sudo apt-get build-dep linux $ cd /usr/src $ wget http://www.kernel.org/pub/linux/kernel/v3.11/linux-<version>.tar.bz2 $ tar -xjvf linux-<version>.tar.bz2 $ cd linux-<version> $ cp /boot/config-<version> .config $ make menuconfig ... $ make deb-pkg
|
提示 |
|---|---|
|
The linux-source-<version> package provides the Linux kernel source
with Debian patches as
" |
For building specific binary packages from the Debian kernel source package,
you should use the
"binary-arch_<architecture>_<featureset>_<flavour>"
targets in "debian/rules.gen".
$ sudo apt-get build-dep linux $ apt-get source linux $ cd linux-3.* $ fakeroot make -f debian/rules.gen binary-arch_i386_none_686
See further information:
Debian Wiki: KernelFAQ
Debian Wiki: DebianKernel
Debian Linux Kernel Handbook: http://kernel-handbook.alioth.debian.org
The hardware driver is the code running on the target system. Most hardware
drivers are available as free software now and are included in the normal
Debian kernel packages in the main area.
The firmware is the code or data loaded on the device (e.g., CPU microcode, rendering code running on GPU, or FPGA / CPLD data, …). Some firmware packages are available as free software but many firmware packages are not available as free software since they contain sourceless binary data.
firmware-linux-free (main)
firmware-linux-nonfree (non-free)
firmware-linux-* (non-free)
*-firmware (non-free)
intel-microcode (non-free)
amd64-microcode (non-free)
Please note that non-free and contrib
packages are not part of the Debian system. The access configuration to
enable and to disable the non-free and
contrib areas is described in 第 2.1.4 节 “Debian 档案库基础”. You should be aware of negatives
associated with the use of the non-free and
contrib packages as described in 第 2.1.5 节 “Debian 是100% 的自由软件”.
Use of virtualized system enables us to run multiple instances of system simultaneously on a single hardware.
There are several system virtualization and emulation related packages in Debian beyond simple chroot. Some packages also help you to setup such system.
表 9.26. List of virtualization tools
| 软件包 | 流行度 | 大小 | 说明 |
|---|---|---|---|
schroot
|
V:6, I:10 | 2651 | specialized tool for executing Debian binary packages in chroot |
sbuild
|
V:0, I:3 | 501 | tool for building Debian binary packages from Debian sources |
pbuilder
|
V:2, I:18 | 943 | personal package builder for Debian packages |
debootstrap
|
V:7, I:69 | 251 | bootstrap a basic Debian system (written in sh) |
cdebootstrap
|
V:0, I:4 | 107 | bootstrap a Debian system (written in C) |
virt-manager
|
V:8, I:30 | 7426 | Virtual Machine Manager: desktop application for managing virtual machines |
libvirt-clients
|
V:24, I:44 | 1866 | programs for the libvirt library |
bochs
|
V:0, I:1 | 4086 | Bochs: IA-32 PC emulator |
qemu
|
I:43 | 472 | QEMU: fast generic processor emulator |
qemu-system
|
I:45 | 67 | QEMU: full system emulation binaries |
qemu-user
|
V:3, I:44 | 54725 | QEMU: user mode emulation binaries |
qemu-utils
|
V:9, I:93 | 4493 | QEMU: utilities |
qemu-kvm
|
V:20, I:68 | 76 | KVM: full virtualization on x86 hardware with the hardware-assisted virtualization |
virtualbox
|
V:59, I:74 | 68058 | VirtualBox: x86 virtualization solution on i386 and amd64 |
xen-tools
|
V:0, I:7 | 791 | tools to manage debian XEN virtual server |
wine
|
V:26, I:110 | 160 | Wine: Windows API Implementation (standard suite) |
dosbox
|
V:3, I:21 | 2654 | DOSBox: x86 emulator with Tandy/Herc/CGA/EGA/VGA/SVGA graphics, sound and DOS |
dosemu
|
V:1, I:4 | 4885 | DOSEMU: The Linux DOS Emulator |
vzctl
|
V:2, I:5 | 1058 | OpenVZ server virtualization solution - control tools |
vzquota
|
V:3, I:5 | 252 | OpenVZ server virtualization solution - quota tools |
lxc
|
V:7, I:13 | 2152 | Linux containers user space tools |
See Wikipedia article Comparison of platform virtual machines for detail comparison of different platform virtualization solutions.
|
注意 |
|---|---|
|
Some functionalities described here are only available in
|
|
注意 |
|---|---|
|
Default Debian kernels support KVM since
|
Typical work flow for virtualization involves several steps.
Create an empty filesystem (a file tree or a disk image).
The file tree can be created by "mkdir -p
/path/to/chroot".
The raw disk image file can be created with dd(1) (see 第 9.6.1 节 “Making the disk image file” and 第 9.6.5 节 “Making the empty disk image file”).
qemu-img(1) can be used to create and convert disk image files supported by QEMU.
The raw and VMDK file format can be used as common format among virtualization tools.
Mount the disk image with mount(8) to the filesystem (optional).
For the raw disk image file, mount it as loop device or device mapper devices (see 第 9.6.3 节 “Mounting the disk image file”).
For disk images supported by QEMU, mount them as network block device (see 第 9.10.3 节 “Mounting the virtual disk image file”).
Populate the target filesystem with required system data.
The use of programs such as debootstrap and
cdebootstrap helps with this process (see 第 9.10.4 节 “Chroot system”).
Use installers of OSs under the full system emulation.
Run a program under a virtualized environment.
chroot provides basic virtualized environment enough to compile programs, run console applications, and run daemons in it.
QEMU provides cross-platform CPU emulation.
QEMU with KVM provides full system emulation by the hardware-assisted virtualization.
VirtualBox provides full system emulation on i386 and amd64 with or without the hardware-assisted virtualization.
For the raw disk image file, see 第 9.6 节 “The disk image”.
For other virtual disk image files, you can use
qemu-nbd(8)
to export them using network block
device protocol and mount them using the nbd
kernel module.
qemu-nbd(8) supports disk formats supported by QEMU: QEMU supports following disk formats: raw, qcow2, qcow, vmdk, vdi, bochs, cow (user-mode Linux copy-on-write), parallels, dmg, cloop, vpc, vvfat (virtual VFAT), and host_device.
The network block device can
support partitions in the same way as the loop
device (see 第 9.6.3 节 “Mounting the disk image file”). You
can mount the first partition of "disk.img" as follows.
# modprobe nbd max_part=16 # qemu-nbd -v -c /dev/nbd0 disk.img ... # mkdir /mnt/part1 # mount /dev/nbd0p1 /mnt/part1
|
提示 |
|---|---|
|
You may export only the first partition of " |
chroot(8) offers most basic way to run different instances of the GNU/Linux environment on a single system simultaneously without rebooting.
|
小心 |
|---|---|
|
Examples below assumes both parent system and chroot system share the same CPU architecture. |
You can learn how to setup and use chroot(8) by running pbuilder(8) program under script(1) as follows.
$ sudo mkdir /sid-root $ sudo pbuilder --create --no-targz --debug --buildplace /sid-root
You see how
debootstrap(8)
or
cdebootstrap(1)
populate system data for sid environment under
"/sid-root".
|
提示 |
|---|---|
|
These debootstrap(8) or cdebootstrap(1) are used to 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. |
$ sudo pbuilder --login --no-targz --debug --buildplace /sid-root
You see how a system shell running under sid environment
is created as the following.
Copy local configuration ("/etc/hosts",
"/etc/hostname", "/etc/resolv.conf")
Mount "/proc" filesystem
Mount "/dev/pts" filesystem
Create "/usr/sbin/policy-rc.d" which always exits with
101
Run "chroot /sid-root bin/bash -c 'exec -a -bash
bin/bash'"
|
注意 |
|---|---|
|
Some programs under chroot may require access to more files from the parent
system to function than |
|
注意 |
|---|---|
|
The " |
|
提示 |
|---|---|
|
The original purpose of the specialized chroot package,
|
|
提示 |
|---|---|
|
Similar |
I recommend you to use QEMU or VirtualBox on a Debian stable
system to run multiple desktop systems safely using virtualization. These enable you to run
desktop applications of Debian unstable and
testing without usual risks associated with them.
Since pure QEMU is very slow, it is recommended to accelerate it with KVM when the host system support it.
The virtual disk image "virtdisk.qcow2" containing a
Debian system for QEMU can be created using
debian-installer: Small CDs
as follows.
$ wget http://cdimage.debian.org/debian-cd/5.0.3/amd64/iso-cd/debian-503-amd64-netinst.iso $ qemu-img create -f qcow2 virtdisk.qcow2 5G $ qemu -hda virtdisk.qcow2 -cdrom debian-503-amd64-netinst.iso -boot d -m 256 ...
See more tips at Debian wiki: QEMU.
VirtualBox comes with Qt GUI tools and quite intuitive. Its GUI and command line tools are explained in VirtualBox User Manual and VirtualBox User Manual (PDF).
|
提示 |
|---|---|
|
Running other GNU/Linux distributions such as Ubuntu and Fedora under virtualization is a great way to learn configuration tips. Other proprietary OSs may be run nicely under this GNU/Linux virtualization, too. |