Вы находитесь на странице: 1из 768

.

Linux. , ,
.





.
.
.
.
.
.

32.973.2-018.2
004.451

74 Linux. , , . .: , 2014. 768 .: .


ISBN 978-5-496-00862-4
Linux, Microsoft Windows Apple OS X,
. Linux
, Android.
, Linux, , , . , Linux , Windows,
Windows Linux , Windows 7 Windows 8. Linux , , Windows. Linux
.
Linux , ?
.
Linux , Windows
. Linux .
, , . Linux .
Debian, Red Hat, openSUSE Ubuntu. ,
.
Linux, . -!

12+ (

29 2010 . 436-.)

ISBN 978-3827332080 .

2013 by Addison-Wesley Verlag

ISBN 978-5-496-00862-4

, 2014

, , 2014

Addison-Wesley Longman. .
.
, , , . , ,

, .
shutterstock.com.
, 192102, -, ( ), 3, , 7
005-93, 2; 95 3005
20 09 13 70100/16 61,920 2000 0000

180004, , , 34


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1. Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2. Gnome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3. KDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
4. VirtualBox. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5. . . . . . . . . . . . . . . . . . . . . . . . 101
6. Bash (). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
9. , - . . . . . . . . . . . . 211
10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
12. . . . . . . . . . . . . . . . . . . . . . . . 284
13. , Java Mono . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
14. . . . . . . . . . . . . . . . . . . . . . 331
15. GRUB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
16. Init. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
19. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
20. Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
21. NFS AFP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
22. SSH (Secure Shell). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
23. Apache. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
24. MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
25. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
26. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
27. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
28. Squid DansGuardian ( ) . . . . . . . . . . . . . . . . . . . . . 745
29. SELinux AppArmor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1. Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
1.1. Linux . . . . . . . . . . . . . . . . . .
1.2. , . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3. , . .
1.4. Linux . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

27
29
29
30
31
32
33

2. Gnome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.1. . . . . . . . . . .
2.2. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
CD DVD . . . . . . . . . . . . . . . .
2.3. Gnome . . . . . . .
2.4. .
. . . . . . . . . . . . .
Gnome Tweak Tool. . . . . . . . . . . . . . . .
Gnome. . . . . . .
Gnome . . .
. . . . .
XDG. . . . . . . . . . .
2.5. Gnome. . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

38
42
45
46
47
48
51
52
54
55
56
57
58
59

3. KDE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.1. . . . . . . . . . . .
- () .
. . . . . . . . . . . . . . .
3.2. Dolphin . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

63
65
68
69

3.3. Konqueror Rekonq. . . . . . . . . . . . . . . . . . . . . . . . . .



-. . . . . . . .
Rekonq. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5. CD/DVD K3b. . . . . . . . . . . . . . . . .
3.6. KDE. . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . .
.
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

72
72
73
74
75
80
82

4. VirtualBox. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. .
. . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
4.2. VirtualBox () . . . . . . . . . . . . . . . . . . . . . . . . .
4.3. VirtualBox (). . . . . . . . . . . . . . . .
Linux . . . . . . . . . . . . .
Windows. . . . . . . . . . .
VirtualBox. . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
.....
. . . . .
. . . . .
. . . . .

85
85
87
88
89
90
93
96
96
98
99

5. . . . . . . . . . . . . . . . . 101
5.1. . . . . . . . . . .
5.2. . .
less. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
5.3. - . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

102
105
105
106
108

6. Bash (). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111


6.1. ?. . . . . . . . . . . . . . . . . . .
6.2. . . . . . . . . . . . . . . . . .
6.3. . . . . . . . . . . . . . . . . . . . . . . . . .
. .
. . . . . . . . . . . .
, . .
6.4. . . . . . . . . . . .
. . . . . . . . . . . . . . . .
tee. . . . . .
6.5. . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

111
113
114
114
116
117
118
119
120
121

6.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(
) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . .
6.8. bash. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1: grepall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2: stripcomments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3: applysedfile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4: . . . . . . . . . . . . . . . .
5: . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.9. bash. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.10. bash. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
, . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
read. . . . . . . . . . . . . . . . . . .
6.11. bash. . . . . . . . . . . . . . . . .
If- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
test. . . . . . . . . . . . . . . . . . .
Case- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
For-. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
until. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.12. bash. . . . . . . . . . . .

122
127
128
129
130
131
132
132
133
134
135
135
136
137
138
138
140
141
141
142
143
144
145
145
146

7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
7.1. . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
,
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(-, -). .
7.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.3. (MIME). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . 148
. . . . . 149
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

153
154
155
156
157
158
159

10

MIME. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
7.4. (find, grep, locate) . . . . . . . . . . . . . . . . . . . . . . . . . . . .
which whereis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
locate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
find grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.5. CD DVD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ISO- . . . . . . . . . . . . . . . . . . . . .
CD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DVD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.6. , . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
, . . . . . . . . . . .
7.7. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.8. Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.9. -. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
udev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

160
161
161
162
162
163
166
166
168
170
172
172
173
174
174
174
176
178
179
181
182
183
186
186
186
188

8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
8.1. , . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
(
) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
, . . . .
8.2. (su) .

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

189
190
190
191
193
194

. . . . . . 195
. . . . . . 196
. . . . . . 197

11

8.3. (sudo). . . . . . 200


Sudo Ubuntu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Sudo SUSE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
8.4. (PolicyKit) . . . 202
8.5. () . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
. . . . . . . . . . . . . . . . . . . . . . 206
8.6. (cron). . . . . . . . . . . . . . . . . . . . . . 208
crontab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
cron.hourly, .daily, .weekly, .monthly. . . . . . . . . . . . . . . . . 209
Anacron. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

9. , - . . . 211
9.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
9.2. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
9.3. ( ). . . . . . . . . . . . . 215
9.4. (). . . . . . . . . . . . . . . . . . . . . . . . . 216
9.5. (PostScript, PDF, HTML, LATEX) . . . . . . . . . . . . 216
TextPostScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
HTMLText, PostScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
PostScriptPDF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
PostScript/PDF /
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
PostScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
PDF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
10.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
. . . . . . . . . . . . . . . . . . . . . . . 224
localhost . . . . . . . . . . . . . . . . . . . . . . . 225
. . . . . . . . . . . . . . . . . . 225
. . . . . . . . . . . . . . . . . . . . . . . . 226
IP-. . . . . . . . . . . . . . . . . . . . . . . . . . . 226
10.2. (SSH). . . . . . . . . . . . . . . . . . . . . . . . 227
shell- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
SSH X. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

12
scp. .
SSH-. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SSH . . . . . . . . . . . . . . . . . . . . .
10.3. (FTP). . . . . . . . . . . . . . . . . . . . . .
FTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SFTP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
WGET. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
curl. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
lftp . . . . . . . . . . . . . . . . . . . . . . . . . . .
rsync, mirror, sitecopy . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

229
230
231
231
231
234
234
235
236
237

11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
11.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
?. . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
11.2. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
Gpm- (). . . . . . . . . . . . . . . . . . . .
11.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
NTP ( ) . . . . . . . . . . . . . . .
Chrony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11.4. , . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . .
. . . . . . . . . . . . . .
(PAM) . . . . .
(NSS) . . . . . . . . . . . .
Nscd ( ). . . . . . . . . .
11.5. , , Unicode. .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . .

. . . . . . . . . . 238
. . . . . . . . . . 239
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

239
240
242
242
243
244
244
245
247
247
248
249
250
252
253
256
257
257
260
261
261
262
264

13

11.6. .
. . . . . . . . . . . . .
. . .
. . .
. . . . . . .
. . . .
(ALSA) . . . . . . . . . . . .
11.7. . . . . . . . . . . . . . . . . .
sysklogd (rsyslogd). . . . . .
logrotate . . . . . . . . . . . . .
Logwatch . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

267
267
269
271
272
273
274
277
277
279
281

12. . . . . . . . . . . . . . . . 284
12.1. RPM. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
12.2. Yum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . .
Yum Extender (Yumex) . . . . . . . . . . . . . . . . .
12.3. ZYpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
libzypp . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . .
zypper. . . . . . . . . . . . . . . . . . . . .
12.4. Debian ( dpkg). .
12.5. APT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
apt-get . . . . . . . . . . . . . . . . . . . . . .
aptitude. . . . . . . . . . . . . . . . . . . .
tasksel . . . . . . . . . . . . . . . . . . . . . .
apt-cache . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . .
. . . . . . . . . . . . . . . . .
Synaptic . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12.6. PackageKit. . . . . . . . . . . . . . . . . . . . . . . . . . . .
12.7. TAR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

287
287
289
292
293
295
297
297
298
298
299
299
300
302
303
304
305
306
307
307
309
309
311
312
314

14
12.8. .
12.9. . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

314
315
316
316

13. , Java Mono. . . . . . . . . . . . . . . . . . . . . . . . . . . 318


13.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
32- 64- . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
13.2. . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.3. Java. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.4. Mono. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
, , . .
Mono . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

318
319
320
321
322
323
324
325
326
326
327
328
329
330

14. . . . . . . . . . . . . . . 331
14.1. . . . . . . . . . .
14.2.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
IDE-. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(virtio). . . . . . . . . . . . . . . . . . .
(MBR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
( GPT) . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
14.3. . . . . . . . .
MBR GPT?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
, , . . . . . . . . . . . . . . . . . . .
4 .
(
MBR-) . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . 333
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

334
335
335
336
336
337
337
338
339
340
341
342
343

. . . 344

15

fdisk (MBR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
parted (MBR GPT) . . . . . . . . . . . . . . . . . . . . . . . . . .
sfdisk (MBR). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
gparted (MBR, GPT) . . . . . . . . . . . . . . . . . . . . . . . . . .
Gnome Disks (MBR GPT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
UNIX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Windows, Mac OSX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CD-ROM/DVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.5. (mount /etc/fstab) . . . . . . . . . . .
. . . . . . . . .

(mount umount). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(/etc/fstab) . . . .
/etc/fstab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
, . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
14.7. ext (ext2, ext3, ext4) . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.8. btrfs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
btrfs ,
RAID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
,
btrfs (df) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

344
348
349
350
351
352
352
353
354
354
354
355
355
357
357
358

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

359
360
361
363
363
364
364
365
366
366
366
368
370
374
375
378
379

. 381
. 384

16

14.9. xfs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.10. Windows (VFAT, NTFS). . . . . . . . . . . . . . . . . . . .
VFAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
NTFS (ntfs-3g) . . . . . . . . . . . . . . . . . . . . . . . . .
14.11. CD, DVD, . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CD DVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
AudioCD, VideoDVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.12. (USB, Firewire .) . . . . . . . . . . . . . . .
14.13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.14. RAID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.15. (LVM). . . . . . . . . . . . . . . . . . . . . . . . .
14.16. SMART. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.17. SSD-TRIM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
(USB-,
) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .

386
387
388
389
390
390
392
393
393
395
398
399
401
406
410
414
416
416
416
420

15. GRUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423


15.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BIOS. . . . . . . . . . . . . . . . . . . . . . .
EFI . . . . . . . . . . . . . . . . . . . . . . . . .
Initrd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15.2. GRUB ( ). . . . . . . .
15.3. GRUB2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . .
GRUB. . . . . . . . . . . . . . . . . . . . . . . . . . .
. .
. . . . . . . . . . . . . . . . . .

BIOS . . . . . . . . . . . . . . . . . . . . .

EFI. . . . . . . . . . . . . . . . . . . . . . .
GRUB Linux . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

423
425
427
429
431
433
433
440
441
443
445

. . . . . . . . . 447
. . . . . . . . . 449
. . . . . . . . . 450

17

EFI
(efibootmgr). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15.4. GRUB0.97. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
( ) . . . . . . . . . . . . . . . . . . . . . . . .
menu.lst . . . . . . . . . . . . . . . . . . . . . .
menu.lst . . . . . . . . . . . . . . . . . . . . . . . . . . .
GRUB. . . . . . . . . . . . . . . . . . .
update-grub (Debian Ubuntu). . . . . . . . . . . . . . .
Grubby (Fedora, Red Hat). . . . . . . . . . . . . . . . . . . . . . . . . . .
GRUB0.97 EFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
GRUB .

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

450
452
452
453
454
457
457
458
458
459

16. Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460


16.1. Init-V. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . .
Inittab. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
Init-V .
Init-V. . . . . . . . . . . . . . . .
16.2. Upstart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16.3. Systemd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16.4. Debian . . . . . . . . . . . . . . . . . . . . .
16.5. Fedora . . . . . . . . . . . . . . . . . . . .
16.6. SUSE . . . . . . . . . . . . . . . . . . . . .
16.7. Ubuntu . . . . . . . . . . . . . . . . . . . . .
16.8. - . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

461
461
463
465
465
469
470
473
478
482
484
485
487

17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
17.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
modprobe. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
17.2. . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
,
. . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

490
492
493
495
496
498
499
501
502

. . . 503

18

. . . . . . . . . . . . . . . . . . . . . . . . . 505
,
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
. . . . . . . . . . . . . . . . . . . . . . . . 507
17.3. /proc- sys/ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
17.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
. . . . . . . . . . . . . . . . . . . . . . . . . 511
SMP- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
ACPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
17.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513

18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
18.1. Network Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
LAN DHCP (ADSL-). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
. . . . . . . . . . . . . . . . . . . . . . . . 519
18.2. . . . . . . . . . . . . . . . . . . . . . . . . 522
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
IP- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
IPv6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
WLAN . . . . . . . . . . . . . . . . . . . . . . . . . . 530
WLAN-. . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
WLAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533
WLAN Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
18.3. LAN WLAN . . . . . . . . . . . . . . . . 536
LAN . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
WLAN. . . . . . . . . . . . . . . . . . . . . . . . . . 540
18.4. LAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
. . . . 547
18.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Fedora Red Hat. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Debian Ubuntu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
SUSE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
18.6. Zeroconf Avahi. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
18.7. PPP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
pppd. . . . . . . . . . . . . . . . . 555

19

pppd. . . . . . . . . . .
18.8. UMTS .
18.9. ADSL. . . . . . . . . . . . . . .
ADSL-. .
ADSL-PPPoE . . .
ADSL-PPTP. . . .

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

556
559
561
562
563
566

19. - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
19.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debian, Ubuntu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Fedora, Red Hat. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19.3. (NAT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
19.4. DHCP . . . . . . . . . . . . . . .
19.5. dnsmasq (DHCP ) . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
dnsmasq.conf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
-. . . . . . . . . . . . . . . . . . .
DNS . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
DHCP . . . . . . . . . . . . . . .
19.6. WLAN . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

569
572
572
573
573
574
575
576
576
578
578
579
579
579
580
581
582
583
583
584
584
585
585

20. Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588


20.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20.2. Samba: . . . .
, . . . . . . . . . . . . . . . . . .

. . . . . . . 588
. . . . . . . 590
. . . . . . . 592
. . . . . . . 593
. . . . . . . 596

20

Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
SWAT. . . . . . . . . . . . . . . . . . . . 598
20.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Samba Linux. . . . . . . . . . . . . . . . . . . . . 602
Linux Windows . . . . . . . . . . . . . . . . 603
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
20.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
, . . . . . . . . . . . . . . . . 607
, . . . . . 607
(User Shares). . . . . . . . . . 608
Samba. . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Gnome
KDE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
20.5. : / . . . . . . . . . . . . . . . . 610
20.6. : . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
20.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
CIFS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
smbclient smbtree. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619

21. NFS AFP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621


21.1. NFS 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
21.2. NFS 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629

22. SSH (Secure Shell) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630


22.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
22.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
22.3. . . . . . . . . . . . . . . . . . . . . . . . . 634

21

23. Apache. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637


23.1. Apache. . . . . . . . . . . . . . . . . . . .
, . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
Logrotate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23.2. - . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
23.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23.4. . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Apache HTTPS . . . . . . . . .
23.5. Awstats Webalizer . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Awstats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Webalizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23.6. PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23.7. FTP- (vsftpd) . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FTP. . . . . . . . . . . . . . . . . . . . . .
FTP
. . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

637
637
638
640
642
642
643
645
646
649
650
651
653
654
657
660
660
665
668
670
671

. . . . . . . . . 672

24. MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673


24.1. MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24.2. MySQL . . . . . . . . . . . . . . . . . . . . . . .
Mysqladmin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MySQL Workbench. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PhpMyAdmin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24.3. . . . . . . . . . . . . . . . . . . . . . . . . . .
Mysqldump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Mylvmbackup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

673
674
676
677
679
679
680
681
682
683
685

. . . . . . . . 689

22

25. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
25.1.
. . . . . . . . . . . . . . . . . . . . . . . . . . .
Dj Dup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Grsync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Back In Time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25.2. NAS- . . . . . . . . . . . . . . . .
Windows. . . . . . . .
Mount /etc/fstab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Windows
Gnome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(gzip, bzip2, xz, lzop). . . . . . . . . . . . . . . . . . . . .
(tar, zip) . . . . . . . . . . . . . . . . . . . . . .
25.4. (rsync). . . . . . . . . . . . . . . . . . . . . . . . .
25.5. (rdiff-backup). . . . . . . . . . . . . . .
25.6. (rsnapshot) . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25.7. . . . . . . . . . . . . . . . . . . . . . . .
rsync Cron. . . . . . . . . . . . . . . . . . . .
. . . . . . . . .
LVM. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
Tartarus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

690
691
692
693
695
695
696

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

696
697
697
698
700
702
704
704
705
706
706
706
707
707
708
709

26. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
26.1. . . . . . . . . . . . .
26.2. . . . . . . . . . . . . . . . .
TCP-Wrapper. . . . . . . . . . . . . . . . . . . .
. .
chroot. . . . . . . . . . .
26.3. : . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
26.4. ( ) . .

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

710
715
715
717
718
718
719
719
720
723

23

26.5. iptables .
(myfirewall) . . . . . . . . . . . . . . . . . . . . .
(myfirewall-stop). . . . . . . . . . .
(myfirewall-start) . . . . . . . . . . . . . . . . . . .
Upstart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Init-V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

726
726
727
728
730
730

27. . . . . . . . . . . . . . . . . . . . . . . . . . 732
27.1. VPN. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
VPN . . . . . . . . . . . . . . . . . . . . . . . .
VPN . . . . . . . . . . . . . . . . . . . .
27.2. VPN PPTP. . . . . . . . . . . . .
. . . . . . . . . . . . .
PPTPD-. . . . . . . . . . . . . . . . .
PPTP- . . . .
27.3. VPN- (PPTP) . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
PPTP- .

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

732
733
734
735
736
737
740
740
740
741
741
744

28. Squid DansGuardian ( ). . . . . . . . . . . . . . 745


28.1. Squid. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28.2. - .
28.3. DansGuardian. . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

745
748
750
751
754

29. SELinux AppArmor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755


29.1. SELinux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SELinux . . . . . . . . . .
, SELinux. . . . . . . . . . . . . . . . . .
SELinux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29.2. AppArmor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
AppArmor Ubuntu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
AppArmor SUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.

755
757
760
762
762
763
767


,
Linux. . Linux, Windows Mac OSX,
. Linux (,
Linux Google Amazon),

( ,
). , ADSL- WLAN Linux.
, Linux , . , Linux
, Windows, , cWindowsXP Windows7.
Linux , ,
Windows. Linux
.


Linux ,
? .
Linux
,
Windows
. , , , . ,
, , , .
Linux , (
: , Linux; Debian, Red Hat, openSUSE Ubuntu). , : -.
, , . -

25

: Debian , openSUSE .
, ,
Linux
, . , , :
.
,, UNIX/Linux.

!
,
Linux
. , ,
Linux

: ,
.
.
Linux, .
Linux!

www.kofler.cc


,
vinitski@minsk.piter.com ( , ).
!
http://www.piter.com
.


Linux


Linux
: , , , ,
.. Linux, ,
.
,
Linux, , . , , ( Windows) .
, ,
, Red Hat , SUSE.
, ..
. Linux, .

1.1.
Linux
Linux, .
, Linux, Windows.
Linux Windows , Windows
, VMware Linux
.
Linux , , . . ,
, .
, -
.

28

1. Linux

. , .
() .
, Gnome KDE.
Gnome.
(root),
! - (root) . Linux .
, , , .
root- (Ubuntu)
. , 11.4.

(, Gnome, KDE),
. .
. KDE Gnome, ,
. , , SYSTEM USER LOGOUT.
(
!).
,
.
. ,
, . Gnome KDE . , .
.
.
Linux . ,
XWindow
. (. 5).
Ctrl+D exit.
Linux.
, .
shutdown -h. .
Linux shutdown.
Ctrl+Alt+Delete.
X, ,
Ctrl+Alt+F2.

1.2. ,

29

Linux Ctrl+Alt+Delete, , ,
, , sync.
. . ,
.

1.2. ,

, .
, .
.

X

Window
.
(.1.1)
1.1. X

Ctrl+Alt+Backspace

(XWindow).

SUSE
.

Ctrl+Alt+Fn

Ctrl+Alt+Fn


n
. Alt+F7.
Fedora Alt+F1


Gnome

KDE

X
. -

. ,
, , ,
Gnome

KDE
(.1.2). , Window Manager
( ), .
1.2.
(Gnome, KDE)

Alt+Tab

Alt+F1

Alt+F2

Alt+F3

Alt+F4

, ,

, , ,

, . ,

30

1. Linux

Firefox,
OpenOffice Vim
. , .
, ,
, Windows.
, , Ctrl+C,
Ctrl+V
Ctrl+S.
, UNIX/Linux.
.5.2.
, ,
. ,
. , Fedora Red Hat
, . Ctrl+Alt+Backspace
.


Linux , Windows MacOS. , - , , .
.
. Gnome, Windows, (, ) .
KDE, ,
.
.
Linux
. , . .
,
. ( . ,
.)
, ,
. ,
Windows ?
. X- ( Gnome KDE), ,

1.2. ,

31

. , ,
, ,
.
(focus follows mouse, )
. , .
.
,
. focus follows mouse .
. ,
(.1.3).
Ctrl+Shift+Num,
.
.
1.3.

4, 6

2, 8

( , 5)

(5, + 0
)


, , , . ,
.
, . :
( ) , . , .
( Gnome KDE, Firefox,
OpenOffice .) : Windows,

, ,
. , , Windows Ctrl+C.
, Ctrl+V Shift+V.

32

1. Linux

1.3. ,

/. ( ), CD- DVD, . , CD- /media/cdrom. Linux
A:, C: ..,
Windows.
Linux . readme,
Readme README !
255.
. , .
. . ( root) , , ,
, . (~). Linux /home/name. : /root.
CD, DVD, flash-.
. ,
flash- USB-, .

,
mount ( umount, ).

, ,
, , . , . ,
Detach Volume (
) Unplug or Eject Hardware ( ). ,
!

Df. df ,

. h
, ,
: , .. /,
/myhome. ( , df ,
Linux. !)
user$ df h
Filesystem Size Used Avail
Use% Mounted on
/dev/sdb6 9,2G 4,0G 4,8G 46% /

1.4. Linux

33

/dev/sdb5 14G 6,9G


6,2G
53% /myhome
tmpfs 754M
0 754M
0% /lib/init/rw
varrun 754M 332K 754M 1% /var/run
...

1.4. Linux
Linux ,
, .
, , ,
. .
, . ,
, .
, , . , ,
, . ,
, , ,
. , , ,
.

Linux , HTML- PDF.


PostScript
. PostScript-, Evince Okular. ,

.
. GZ


BZ
2. , , gunzip file.gz bunzip2
file.bz2.

. , , F1 .
, , .
, Gimp OpenOffice, ,
.
Man info. man
info .
man info Gnome KDE.
. Linux .
, ,
. , , :

34

1. Linux

Debian, Fedora, Red Hat, Ubuntu /usr/share/doc/;


SUSE /usr/share/doc/packages/.

,
, , ?
, .
-a:
user$ which -a cp
/bin/cp

, .
, . , cp coreutils:
user$ rpm -qf /bin/cp
coreutils-6.4-10
user$ dpkg -S/bin/cp
coreutils: /bin/cp

(Fedora, Red Hat, SUSE)


(Debian, Ubuntu)

- Linux . , - Linux,
, Linux, . fedora forum ubuntu wiki,
.
, , .
,
. Ubuntu.
.
Linux. Linux -, .

.
Google: http://groups.google.com.
Linux Documentation. Linux Documentation Project (LDP)

Linux. , http://
www.tldp.org/ .
: -
( ),
( ) ( ). ,
LDP . Linux -, .
. , , Linux. .

: http://www.kernel.org/doc/Documentation/.

1.4. Linux

35

RFC. RFC Request for Comment ( ).


,
(, TCP, IP, FTP, PPP ..).
RFC :
, , , , .
. http://www.faqs.org/rfcs/.

Gnome

Windows MacOSX,
, . Linux
: .
. Linux
.
Gnome, KDE, Xfce LXDE.
, ,
. :
, , ,
. ,
-;
, ( , ..);
.
Gnome3.n.
Gnome , .
, .
.
Fedora17 Gnome3.4.
Gnome3.6, ,
, .
Gnome3. Gnome3
(.2.1). Gnome
(Gnome Shell). , .
. -, Gnome Linux (,
).
. - , -
, Gnome Linux-.

37

2. Gnome

Linux
:
https://plus.google.com/106327083461132854143/posts/SbnL3KaVRtM;
https://plus.google.com/117091380454742934025/posts/VjbFCa7X5NJ.

.2.1. Gnome

Gnome ,
. , , .
Canonical . Gnome Unity. Linux Mint. Mint ,
Gnome2.n (, MATE),
Gnome3.n , Gnome
.

3D-.
( , , NVIDIA,
, ), Gnome
. Gnome2.n ( ,

38

2. Gnome

!) Gnome3.n. ,
: Fedora17 openSUSE12.2
, Gnome3.n 3D-. , .

Gnome3 - !
Gnome3 ,
. ,
Gnome
3 : ,
Gnome .

2.1.
. Gnome,
() .
,
.
,
Gnome, , Log out (
). , , ? Gnome . Turn off ()
Alt!
,
Gnome3 Gnome Tweak Tool (.2.4).
Gnome3.6 , : ,
Turn Off () Log out ( ).
. , : , . ,
User Name ( ) . X-.
.
. , . Activities
(), , , , ( )
. User Name
( ), ,
.
, , . .

2.1.

39

. Gnome
(.2.2).
, ,
.
. , Gnome ,
Ubuntu ?

.2.2. Gnome

. ,
, Windows Alt+F1,
.
, , .
.
Art Expos, . , , , ..
. .
, Gnome .
, , , . , . (,
.)

40

2. Gnome

, Gnome3.n.
, , Gimp, Windows
GI Enter. ,
,
.
, Windows xxx Enter
, .
, : , ,
, , Ctrl+Enter
, Ctrl.
. , ,
.
. ,
. ,
,
(, INTERNET).
. Gnome . ,
Alt+Tab , . (
MacOSX, Apple ,
.) ,
Alt+ .
! Alt+Esc.
, , , Alt+Tab.
Alt+^, , . ,
,
.
. Gnome
, . , .
Dock Dash.
, , Gnome, .
, , .
,
. , .
,
.
.
. , .

41

2.1.

,
.
. Gnome3.n .
,
.
Windows, , .
.
,
. ,
. ,
Gimp. Gimp, .
Gnome3.n .
. . , Gnome
. ,
,
.
, , , .

Alt+ .
. , , . ,
. ,
https://extensions.gnome.org/,
Gnome. Gnome 2.n Gnome3.n
.
. .2.1 , Gnome3.n.
, , .
2.1. Gnome3.0

(Windows Alt)+F1


(Expose). , Expose,
.

Alt+F2

Alt+Tab

( )

Alt+Esc

(
Alt+Tab)

Alt+^

42

2. Gnome
2.1 ()

Ctrl+Alt+Tab

.
, , ,
(Dash), , .

Ctrl+Alt+Tab++

Shift+Ctrl+Alt+Tab++

2.2.
Files ( Nautilus)
Gnome. ,
. , , Linux . ,
, Linux , 7.
Gnome3.6. Gnome
3.6 . ,
- Gnome3.6. , , Nautilus Files. ,
Google -
! . . :
, .

. .
.
, F3.
.
, (,

).
http://www.omgubuntu.co.uk/ 18% , . Linux
Mint
, Nemo. Linux Mint Nemo
Nautilus.
. ,
( ).

. . -

2.2.

43

.

( ), 10.

.

,
~/.thumbnails. Gnome.
Ctrl+1 Ctrl+2 .
. ,
( ).
. F9
.
. ,
, .
,
(directory path).
(Ctrl+L).
.
.
Ctrl+T (dialog sheet).
, .
, .
. , , . . ,
. ,
, , .

. ,
, Gimp Firefox.
. , ,
.
, ,
, PNG-.
.
, Ctrl+C, Ctrl+X. , , Ctrl+V(
).

44

2. Gnome

,
. , , , .
, . , CD
.
, .
, ,
Ctrl. , Alt. , ,
().
.
. ,
. . ,
. gnome-searchtool. ,
.
.
, . Fedora
tracker tracker-ui-tools. , tracker-preferences, . ,
. ~/.cache/
tracker. Windows ( trackerneedle). ,
.
. , , Linux
. , .
,
. (,
~/.thunderbird).
,
Ctrl+H.
.
, Linux
. , , 7.6. ,
.
. , . ,

2.2.

45


. ,
Delete, .
, Shift+Delete.
. CD DVD
USB, Firewire eSATA,
, ,
.
.
, , .
.


Windows. ,
.
Windows (Windows Network).
, Windows.
,
.
, .
,
.
Gnome. ,
Ctrl+D.
,
. , . , Windows
Samba,
.
.
: Ctrl+L .
: smb://login@servername/directoryname.
Windows, , ,
Windows.
. Ctrl+L smb://servername.
(AFP, FTP,
WebDAV, SSH ..).
.2.2 .
computer: trash:.

46

2. Gnome
2.2.

computer:

afp://user@hostname

AFP- (Apple)

ftp://hostname

FTP-

network:

sftp://hostname

SFTP- ( SSH)

smb:

Windows

smb://hostname

Windows

trash:

( )


. ,
Gnome Windows
. Gnome3.6 , , ,
.
nautilus-share,
. , Samba-
.
Samba.
, , SUSE, YaST-
Samba.
GVFS. Gnome GVFS (Gnome
Virtual File System, Gnome).
~/.gvfs.
, Gnome
( F9).

. ,
.
nautilus, ,
Gnome. , Debian Ubuntu.
nautilus-image-converter nautilus-image-manipulator:
(.2.3).
nautilus-compare: . Meld.
nautilus-open-terminal: , ,
.

2.2.

47

.2.3. nautilus-image-manipulator

nautilus-pastebin :

Pastebin.
seahorse-nautilus:
.
nautilus-dropbox: Dropbox
Dropbox.

CD DVD
CD DVD . ,
CD DVD. CD/DVD , CD DVD. , Brasero Data Project ( ). ,
, ( ). Burn () !
Brasero , .
,

48

2. Gnome

Brasero ( EditPlugins
()).
CD/DVD. CD DVD, ,
Brasero Copy CD/DVD (
CD/DVD ). Brasero CD/DVD ISO- TOC-.
, CD
DVD.
ISO- TOC-. ISO- TOC-
CD DVD. ,
Write on CD/DVD ( CD/DVD).
, ISO-.
, ISO ZIP-. , ISO-
.
ISO- . CD DVD, (image
file).
AudioCD. , MP3- OGG, CD-, Brasero (Audio Project).
. ,
Add () . F7. , Burn (). , ,
WAV.

2.3. Gnome
, Gnome. Gnome, , (, Web),
.
Boxes. Gnome3.6, Boxes
. Boxes
KVM. Boxes Linux,

Windows Linux. Boxes
Fedora17, Boxes .
(file-roller).
.
. , , .

2.3. Gnome

49

, .
,
. , . , Alt+F2 file-roller.
.
(gnome-documents).
PDF-.
(Online Accounts) Google,
Google Docs. ,
.
(vino-preferences).
(, - ),
. ,
, .
xy! ?
ABCEFG ?
.
.
. Gnome ,
( vino-preferences).
VNC-. , Gnome
vinagre.
, ,
IP-.
ADSL- LAN-, Gnome . . , , TeamViewer. Linux,
(http://www.teamviewer.com/en/index.aspx).
(baobab). ,
,
(Disk Usage Analyzer). Gnome
baobab ( ).
, (.2.4). .
,
.
, ( !).

50

2. Gnome

.2.4. ,

(gnome-contacts). Google, Facebook


Windows Live. ()
(Online Accounts).
Gnome.
(seahorse). Gnome
. ( )
, Gnome . , , ,
Evolution.
(master password), .
.
, (seahorse). , GPG- SSH-.
,
, - ..
PDF PostScript ( Evince).
PDF PS Evince,
. , .. (
PDF-, , Adobe Reader.)

2.4.

51

(gnome-terminal). Gnome gnome-terminal. .


- ,
. , -.
(shell window),
.
Ctrl++ Ctrl+-
.
Ctrl+Shift+T,
.
Ctrl+Pageup Ctrl+Page
down.
, Alt+D, .
,
.
.
.
.
(gedit). ,
Gnome, gedit. ,
.
-. 3.6 - Gnome
Epiphany, , Web.
Gnome, , , Firefox Google Chrome.
Web, Epiphany, .
, epiphany (Debian
Ubuntu epiphany-browser).

2.4.
Gnome 2.n :
, ,
, .. Gnome3.n
! Gnome
. Gnome
,
, JavaScript.
. , 3.4,
(gnome extensions) .

52

2. Gnome

( )
Gnome.
, Gnome,
, Gnome.
Gnome.


Gnome
(.2.5). ,
.

.2.5. Gnome


( , , ..),
, .
,

2.4.

53

Bluetooth, , ..
Gnome, , . , , , ,
. Gnome,
.

, , .
.

. . ,
USB,
. .
!
, , (Printer),
.
, . , ,
. ,
. - IP-
. Gnome!
system-config-printer, .
, , . Add printer ( ) ,
( ,
, ).
, App SocketHP Jet Direct (
HP Jet Direct).
. .
( , ..) Properties ().
. (Online Accounts) Google Windows Live.
.
Gnome, . Gnome , .
. , Gnome, Firefox,
Evolution Thunderbird .. ,

54

2. Gnome

Gnome ,
(.2.6).

.2.6.

, Gnome
AudioCD DVD , MP3-,
.
. ,
. (key repeat), .
.

Gnome Tweak Tool


Gnome (Gnome Tweak Tool,
gnome-tweak-tool) Gnome,
. , , :
;
;
;
;
;
.

2.4.

55


(Gnome Shell). Alt+F2+R+Enter.
.

Gnome
Gnome JavaScript.
JavaScript ,
Gnome. Gnome . 3.4
, , -
. ,
https://extensions.gnome.org/.
, ,
Gnome, .
,
Gnome ( . ) . Gnome ( ) -. , . :
Gnome, ,
.
, Gnome3.4 .
(
Alternate

Status

Menu
). , , , .
(Alternate Tab). , Alt+Tab .
AXE.
,
Cinnamon Linux Mint.
(CPU Temperature Indicator). .
lm_sensors lm-sensors.
Dash to Dock. - Gnome,
Gnome Dash. -, Dash, ( , ).
(Media Player Indicator).
(, Banshee
Rhytmbox) , Ubuntu.
Panel Docklet Window List.

56

2. Gnome

/. Panel Docklet .
Remove Accessibility ( ). .
System Monitor ( ).
, ,
, ..

Gnome
dconf. Gnome3.0
dconf, . dconf
.config/dconf/user. , Gnome dconf.
dconf . , Windows. ,
.
- ,
.
dconf gconf ( ) . Gnome .
dconf Gnome .
Gnome dconf
API ( ). dconf , dconf-tools
dconf-editor.
,
, .
gsettings dconf . Nautilus
:
user$ gsettings set org.gnome.nautilus.preferences confirm-trash false

gconf. Gnome, , dconf,


gconf. XML-, .gconf,
. gconf gconf-editor .
dconf-editor,
.

2.4.

57

. , gconftool-2.
:
user$ gconftool-2 --set /desktop/gnome/shell/windows/button_layout \
--type string ":minimize,maximize,close"

( Mac OS X
Ubuntu), :
user$ gconftool-2 --set /desktop/gnome/shell/windows/button_layout \
--type string "close,minimize,maximize"

,
Gnome. Alt+F2+R+Enter.


( )
Gnome Shell ( Gnome). ,
, , Mutter.
Mutter Metacity.
3D-. Gnome3.n
Compiz .
. Gnome
. , , *.desktop. :
~/.config/autostart/*.desktop , ;
/usr/share/gnome/autostart/*.desktop Gnome;
/etc/xdg/autostart/*.desktop
, Gnome KDE.
Gnome3.n, , . *.desktop
. .
:
[Desktop Entry]
Type=Application
Name=GNOME Login Sound
Comment=Plays asound whenever you log in
Exec=/usr/bin/canberra-gtk-play --id="desktop-login" --description="GNOME Login"
OnlyShowIn=GNOME;
AutostartCondition=GSettings org.gnome.desktop.sound event-sounds
X-GNOME-Autostart-Phase=Application
X-GNOME-Provides=login-sound

58

2. Gnome

Gnome. , Gnome,
, , Gnome (gdm). Ubuntu, 11.10
(lightdm).
MIME. MP3- Nautilus Rhytmbox Banshee.
Gnome MIME-. MIME Multipurpose
Internet Mail Extensions ( -).
,
.
MIME- . , .
.
MIME :
~/.local/share/mime/*
~/.local/share/applications/mimeapps.list

XDG
Portland
.
, Gnome KDE. XDesktop Group (XDG) , freedesktop.org.
. Images (), Documents (), Music (), Common (), Videos () Templates ().
.
xdg-user-dirs.
~/user-dirs.dirs. , , XDG, .
Gnom
( xdg-user-dirs-gtk).
,
:
# ~/.config/user-dirs.conf
enabled=False

, /etc/xdg/
user-dirs.conf.

. , () ,
Gnome KDE . -

2.5. Gnome

59

, , .
, .
.cache ,
. , , (
thumbnails
), .. , .
.config ,
.
.local .
share/programmname.
XDG-. xdg-utils ( man xdg):
xdg-desktop-menu ;
xdg-desktop-icon ;
xdg-icon-resource ;
xdg-mime MIME MIME-;
xdg-open , ;
xdg-email , ;
xdg-screensaver .

2.5. Gnome
Gnome3 Gnome .
- Gnome2 (, , Debian6
RHEL 6) Gnome2 MATE (Linux Mint MATE).
, Gnome3, Gnome.
, Gnome3
(, Linux Mint Cinnamon).
Gnome, Unity.
Gnome 2. - Gnome2. Gnome2 .
, .
.
Add this launcher to panel
( ).
, .
,
.

60

2. Gnome

Gnome3. Gnome3
3D-, . ,
. Gnome3 Gnome2 (.2.7).
Gnome2 .

.2.7. Gnome3 Gnome 2

Gnome2 ,

, Alt. .
, Gnome . Fedora17
, Gnome3 . ,
. llvmpipe.
, .
MATE. C Gnome3 Gnome2 .
, , Gnome 2,
Gnome3 MATE.

2.5. Gnome

61

MATE Gnome 2 (http://mate-desktop.org). ,


MATE Gnome 2,
( Gnome).
. MATE .
, Gnome 2 (
MATE), Linux Mint13 Maya. . Main Menu,
openSUSE.
Cinnamon. Cinnamon Gnome3,
Linux Mint. Cinnamon Gnome3
, Gnome 2,
, - .. ,
. , :
Cinnamon , Gnome3,
, Gnome 2. Cinnamon
, Gnome 2, Gnome3 Unity.
Cinnamon
. Cinnamon : http://cinnamon.linuxmint.com/.

KDE

KDE Gnome,
. , KDE , Gnome,
. KDE Kool Desktop
Environment ( ), KDesktop
Environment. KDE Qt , Troll Tech. Nokia Digia. KDE
http://kde.org/.
Gnome, KDE
, Linux.
.
Gnome.
, Gnome KDE.
, Gnome
KDE ( Session ()).
KDE. ,
KDE -.
, , , . KDE4.9,
- Kubuntu 12.10.
KDE . , KDE .
, KDE
( ). ,
. , KDE .
KDE (System Settings), Input
Devices ( ) Double-click to open files and folders
( ).

3.1.

63

3.1.
. KDE,
() . KDE ,
.
, KDE
QuitLog Out ( ) QuitReboot ( ).
.
. KDE QuitChange User
( ). ,
,
. (X-).
,
.
( Fedora17
Ctrl+Alt+F1):
Ctrl+Alt+F7 ;
Ctrl+Alt+F8 ;
Ctrl+Alt+F9 .

. .3.1 KDE4.9. ,
.
, , .
KDE, ,
,
, .
Plasma. Plasma , , KDE. .
(Dashboard) Apple.
. ( ) .
- , KDE . Add Miniprogramms ( -)
Toolbox (), ,
(.3.2).
,
. , .

64

3. KDE

.3.1. KDE

.3.2. - ()

,
Plasma. Folder
View ( ). , Desktop
Plasma- (. .3.1,
). .
Folder View ( ) .

, - . , .
, Alt+F12:

3.1.

65

.
Alt
+
F
12
Esc
, .

,
-. ~/.kde4/
share/config/plasma-desktop-appletsrc.
. ,
( ). ,
-. ,
KDE4 ! (, )
,
. ,
. , .
Control Panel Settings (
) , ,
-, .
.
. ,
.

- ()
KDE ( ). ,
KDE (.3.3). .
Favorites () . (,
). , , .
Applications () .
. ,
, .
, .
Computer ()
, : ,
, ,
..
Recently Used () ,
,
Leave () , .

66

3. KDE

.3.3. KDE

, KDE .
, Programs (). .
(Menu Editor). . , .
KDE 3, .
Switch to classic menu style (
).
( ). - Window Bar ( )
, , Windows.
,
(, Gimp). ,
( , ).
-, MacOSX
Windows7. , -,
, .
ExtendedShow when not running (
).

3.1.

67

.

. , . Workspace Switcher ( ).
,
.
- ,
, , .
Alt+ OnWorkspaceAll Workspaces ( ).
. (Activities) , .
, , .
, .
.
,
. ( ,
). , Desktop (( ); ), Search and Execute
( ) Desktop Icons ( ).
.
, -
.
. ,
(,
). .
, ,
. , - .
. Device Monitoring (
)
(unmount).
. - Quick Access ( )
. ,
. Dolphin
Open ().

68

3. KDE


KDE , ,

. , ,
.. , KDE ,
.
/.

, , , .
. ,

, Move window to groupWindow name ( ). ,


Window Name ( ).
(.3.4). , .
, . Remove window from group ( )
.

.3.4. , Dolphin


, ,
. , , .

3.2. Dolphin

69

. Shift+Alt+F11,

(tiling mode).
, . , , ..
, , ,
, ( ) .
. , , , . Window
Behavior ( ).
Window BehaviorExtended ( ). , Shift+Alt+F11.

3.2. Dolphin
KDE 4 Dolphin , Konquero. Dolphin, ,
-, , Konqueror,
. , Konqueror
( ).
(Views). Dolphin KDE FavoritesFile
Manager ( ) Computer
Personal Folder ( ).
: ,
: Symbols (), Details () Compact (
). , , Ctrl+1
Ctrl+3.
: SettingsGroup Items (
). .
Preview ( )
,
.
. Dolphin
,
3. SettingsAdjust Dolphin ( Dolphin).
GeneralPreview ( ). ,
.

Share View ( ) . .

70

3. KDE

. Ctrl+L
. (
),
.
, ,
, F6 .
. ,
, , , . ViewSidebars (
), F4, F7, F9 F11.
.
. KDE Dolphin . , , ,
Settings (). ,
Ctrl+M.
. .
KDE ,
.
Ctrl ( ) Shift ( ).
. (
- hover), . , .
,
, .
. Search () . , .
, Desktop Search
Nepomuk. , , KDE
( ,
).
. , . , Places (). F9.
Delete,
.
, Shift+Delete.
. , , Linux
. , Dolphin .
, Show Hidden Files
( ). Alt++, , , .

3.2. Dolphin

71

.
, , Linux .
,
PropertiesPrivileges ().
. Places (F9) ,
, ,
. USB
Firewire, .
, . ,
KDE Eject (),
Dolphin Places () F9 Unmount ().
, , , , .
AudioCD. Dolpin , , , AudioCD. ocd:/.
,
FLAC, MP3 ( lame) Ogg Vorbis. ( ), .
,
Common () .
, .
. Places () smb:/. Samba Windows
smb://servername/sharename.
, Dolphin Windows.
- .
Dolphin
, Windows Samba.
Dolphin ,
. .
Network & ConnectionsShare (
) .

Dolphin Windows Samba, , ,


. , Fedora SUSE

Windows
. , .

FTP. (URL) ftp://, Dolphin FTP-.

72

3. KDE

.
FTP- ( ),
ftp://name@adress. FTP, .
SSH. Dolphin SSH, . fish://username@computername/.
Dolphin .

3.3. Konqueror Rekonq


Konqueror
, , ( FTP, SCP, Windows
..), (, ..). - Konqueror , . , Konqueror
, Dolphin. .
http://www.konqueror.org/.

Konqueror ,
. View ()
, Dolphin. Konqueror
( ) ,
. ViewPreview (
).
Ctrl+ Ctrl-.
F9
(sidebar). , ,
, .
.
ZIP TAR ( name.tar, name.tgz name.zip), , Konqueror.
. , , Konqueror File Sizes
( ). Konqueror
, . ,
() Konqueror. (Ubuntu konq-plugins.)

73

3.3. Konqueror Rekonq

,
View (). , . ,
, fsview.
Konqueror .
KIO (- Konqueror). Konqueror
Dolphin -, .. Konqueror, , , Dolphin . Konqueror Dolphin ,
,
(.3.1). , ,
, .
, KDE- KIO Slaves ( slave
, KIO - KDE).
3.1. - KDE

file:/etc/fstab

tar:/archivdatei

TAR

audiocd:/

AudioCD

trash:/

()

http://www.kofler.info

ftp://user@mars/folder

FTP- mars

sftp://user@mars/folder

SFTP- mars

fish://user@mars/folder

SSH- mars

smb://mars/myshare

Windows

man:ls

ls

info:emacs

emacs

help:kmail

KDE kmail

applications:/

fonts:/

remote:/

settings:/

-
KHTML Webkit. Konqueror
, Konqueror, KHTML, WebKit.
KDE KHTML HTML . , (
root!):
user$ keditfiletype text/html

74

3. KDE

Edit File Type ( )


Embed (), Webkit,
, OK.
Konqueror WebKit. ,
ACID3 (http://ru.wikipedia.org/
wiki/Acid3 . .). openSUSE .
Kubuntu - KHTML. Webkit , kpart-webkit.
. , ,
. SettingsKonqueror Setup
( Konqueror), .
!
,
,
. .
, gg:abc abc
http://www.google.com. Web Shortcuts (-)
.
( ).
nspluginviewer, konqueror-nsplugins, Konqueror
, Firefox. -
, Extensions ().
, Konqueror, ,
. Search for new plugins ( )
Konqueror.
, Firefox,
Konqueror , KDE. , ,
,
, HTML-. . konq-plugins.
Java. KDE Java , KJAS (
Java KDE, kjavaappletviewer.so). KJAS, , Java java. Konqueror
,
which java Konqueror,
JAVA AND JAVASCRIPT (Java JavaScript).

Rekonq
Konqueror , Rekonq, KDE.
WebKit. -

75

3.4.

Konqueror, , , , .
Konqueror, Rekonq (). Ctrl+B. Shift+Ctrl+B.
Rekonq Konqueror -. ,
, wp:MBR,
(MBR). Rekonq , Rekonq settingsAd Blocker (
Rekonq ).
.

3.4.
KDE
( systemsettings) (.3.5).
, KDE
, (, Window). , , Overview ().

.3.5. KDE

76

3. KDE

kcmshell4
. ,
kcmshell4 --list. ,
,
Apply ().
Gnome, KDE ,
, ( ,
..). , , ,
.
,
. - ,
, . ,

,
.
. KDE
~/.kde/ ~/.kde4/. , , :
~/.kde[4]/Autostart/ ( )
~/.kde[4]/share/config/ ()
~/.kde[4]/share/apps/ ( , )

KDE XDG XDG, :


~/.cache/ ()
~/.config/progname/ ()
~/.local/share/progname/ ( )

. KDE KWin.
Workspace Effects ( ).
, . ,
.
.
, .
,
, , ,
.
Login Screen ( ).
Auto-Login ( )
, .
KDE. , Kubuntu LightDM.

3.4.

77

Gnome, KDE,
, , Gnome. ,
,
:
user$ ps ax | egrep 'gdm|kdm|lightdm'

Novell SUSE
/etc/sysconfig/displaymanager.
Gnome KDE:
YaST!
. . KDE ,
,
. KDE ,
,
( ), .
Start and
QuitSession Management ( ). ~/.kde[4]/ share/
config/session.
, ~/.kde[4]/
Autostart ,
. KDE *.desktop,
, .
, ~/.kde/Autostart Dolphin KDE.
,
Start and QuitAutostart ( ).
,
, , . : KDE
:
~/.kde[4]/Autostart/ ( )
/usr/share/autostart/ ( KDE)
/etc/xdg/autostart/ ( Gnome KDE)

. Display and
Monitor ( ) , ( ) .
Save as Default ( ).
.
( ) .
, .

78

3. KDE

. Desktop Settings ( ).

.
. Workspace Appearance ( ) Workspace DesignWorkspace (
), () . ,
KDE, ..,
. Download New Design ( )
KDE
( http://kde-look.org/), . , Apply (). , ,
Caledonia.
. Application
Appearance ( ) Stil (),

, , . .
. Workspace Appearance ( ) Window Decoration
( ), .
.
,
.
Setup Window Decoration ( ) Setup Buttons
( ) , , , ..
. , , ..
. Application Appearance ( )
Colors () . ,
.
, ,
.
Download New Color Schemes ( ) .
. KDE Printer Setup ( ) (.3.6). openSUSE
YaST. KDE, ,

79

3.4.

, kcmshell
printers.

.3.6. KDE

, ,
New Printer ( ). (, Network Printer ( )),

. ,
. Address () . , ,
.
Linux.
,
, .
.
.
User Account Details
( ). ,
. ~/.face.icon, PNG.
MIME. Konqueror
OGG Amarok. MIME,
KDE. MIME
-.
,
. MIME
File Associations ( ).
. , ,

80

3. KDE

. ,
Open with ( ).
. . , , . , KDE , . ,
Workspace Appearance ( ) Window
Decoration ( ). Setup Window Decoration ( ) , Shadows (),
.
. KDE Konqueror, KMail Kontact
, konsole . ,
KDE ,
Default Components ( ).
. , , , , . KDE
KWin.
Window Behavior ( ). ,
, ,
,
, ..
. Shortcuts
and Gestures ( ), Default Shortcuts
( ). .

3.5. CD/DVD K3b


K3b , Linux
. Gnome.
, . ! ,
CD ,
. , K3b .
CD DVD . ,
CD DVD, FileNew ProjectNew
Data Project ( ). , ,
() CD/DVD (). -

3.5. CD/DVD K3b

81

, ,
.
Burn (), K3b,
, . ,
, ,
, Burn ().
.
. ,
CD DVD ( Check
Recorded Data ( )).
, . , ! DVD . ( , DVD
.)
, CD DVD, ( Simulate
()). ,
CD DVD.
.
CD DVD. ,
Create Image ( ). K3b
, .
. ,
, .
CD DVD, File
System ( ) Medium Name ( ).
K3b ,
Linux .
, File System ( )
Custom ( ), Preserve File
Permissions ( ).
CD DVD . , , ,
CD DVD.
(Multi-Session).
,
, .
K3b CD, DVD.
Settings ().
: CD/DVD ,
Miscellaneous () Start Multi-Session
( ).
: Continue
Multi-Session ( ).

82

3. KDE

: ( ),
Finalize Multi-Session ( ).

.
,
CD DVD. ( ).
CD/DVD. CD DVD ( ,
CD ),
ExtrasCopy Medium ( ). , Start () K3b . .
, , .
, Source Medium ( ) .
, Create Image ( ).

. , AudioCD ,
. -
( Create Image ( )) , .
CD K3b : Normal Copy ( ) Clon Copy ( ). . ,
.
, VideoDVD
.
ISO- . ISO- Extras
Burn Image ( ). , .
ISO. K3b
MD5. ,
ISO-. , , .

3.6. KDE
KDE.
(Ark). Konqueror TAR.GZ, TGZ ZIP,
. Konqueror ,
. Ark,
, , WinZip.

3.6. KDE

83

.
, -
, Linux
. VNC-
(VNC Virtual Network Computing).
ProgramsSystemShare Workspace ( ). Kubuntu
krfb, .
VNC-
krdc KDE.
.
, .
. Konsole
( ) . Shift+,
Shift+. Ctrl+Shift+ Ctrl+Shift+ ,
. , Konqueror
. .
KRunner. Alt+F2 KRunner.
, , ,
. KRunner : , ,
( 2x3, 6), man
( man:ls), - Konqueror (,
Google gg:kde), ( switch username),
(power profilname) ..
. Konqueror
(, , mail.ru),
, (digital wallet).
KWallet .
, KWallet
. KWallet , , KMail/
Kontact, NetworkManager . ,
, -.
KDE .
PDF PostScript. PDF PS Okular, .
, ..
.
, ,
PGP-,
. KDE
KGpg. S/MIME
Kleopatra ( KGpgCertmanager).
Kleopatra kdepim.

84

3. KDE

(KEdit, KWrite, Kate).


KDE : KEdit, KWrite
Kate. KEdit KWrite , . Kate .
, (,
) ..
(Klipper). , KDE Klipper,
,
. ,
, .
Actions (). Klipper
. ,
, HTTP-,
Konqueror -. Klipper , (
Quit ()).
(Krename). Krename
, ,
.. . ,
. Krename
,
!
( krename).

VirtualBox

. :
Linux Windows, Windows Linux,
- xyz, () Linux, ( ) ..
, . VirtualBox. KVM.

4.1.
, ,
.
Windows Linux Linux Windows,
VirtualBox.


. , (host), (guests).
.
.
(), .
( , ).

,
, , , ,
.. ,

86

4. VirtualBox

. ,

. (Virtual Machines Monitor, VMM ).
- , .
:
.
.
: .
/: VMware, QEMU, Parallels, VirtualBox, Microsoft VirtualPC.
. -

, . ,
,
VMM.
: .
:
. , Linux,
, , Windows. (
Xen Microsoft Novel Microsoft, ,
Windows Server,
Xen.)
/: Xen, UML (Linux ).
() .

Intel AMD , . Intel Intel-VT ( Vanderpool), AMD AMD-V (


Pacifica).
: ,
.
: .
/: KVM, Xen.
(). -

.

. , ,
.
: , (,
..).

4.1.

87

: ,
. .
/: OpenVZ, Virtuozzo, Linux-VServer.
, , ,
Linux. ,
, , KVM UML.
. , ,
Xen- , , , Xen.

, : http://virt.kernelnewbies.org/TechOverview;
http://wiki.openvz.org/Introduction_to_virtualization.
. , (Intel-Vt
AMD-V) , egrep.
Intel-i7.
, , BIOS/EFI.
user$
flags





...

egrep '^flags.*(vmx|svm)' /proc/cpuinfo


: fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36
clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm
constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc
aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16
xtpr pdcm sse4_1 sse4_2 popcnt aes xsave avx lahf_lm ida arat epb xsaveopt
pln pts dts tpr_shadow vnmi flexpriority ept vpid


.
.
. ,
, .
, . , , ,
6. , 67 Linux.
. . ,
, , . ,
, , 23.

88

4. VirtualBox

CD/DVD-. CD- DVD- . .


, CD DVD
.

CD DVD ISO-. , , .
, . ISO- CD
DVD.
root# dd if=/dev/scd0 of=.iso bs=2048

.

, . .
.

.
(, ),
.
USB- . ,
, - -.
,
. USB-, ,
, ,
.

- . ,
, . ,
( ,
, LAN WLAN).
VirtualBox.
,

.
(bridged
networking) .
, ( --

4.1.

89

) DHCP- -
ADSL- WLAN-.

, .
- ,
,
( ).
NAT NAT ( )

DHCP- (. 19.3).
, ,
-. NAT .

, , . ,
,
.
,
.
,
.


: -
,
-.
, . - ,
. , -
- .
. ,
. : , , -,
-, NFS Samba.
( ..). , , , .

90

4. VirtualBox

( ).
.
, . X, ,
, , ,
Ctrl+C.
, . , .
Excel -, , OpenOffice, .


, ,
, .
.
, ,
.
VMware (, EMC). VMware . (
VMware) (VMware Server,
ESXi, vSphere). , . - Windows, Linux,
MacOSX. VMware
, (bare metal).
VMware, Windows Linux. 2008 , VMware VirtualBox ( VMware
VirtualBox, ).
VirtualBox ( , Sun/Oracle). VirtualBox VMware,
VirtualBox .
- Windows, Linux MacOSX.
VirtualBox ; ,
, ,
(GPL). VirtualBox
. , ,

4.1.

91

, VirtualBox X-
.
KVM/QEMU ( , Red Hat). -

, KVM ,
QEMU ,
. KVM
, Red Hat Qumranet , KVM, KVM Fedora,
Ubuntu , , 6Red Hat Enterprise Linux. KVM , .
, , ,
KVM Vmware, VirtualBox Xen. - Linux.
Xen ( , Citrix). Xen , -

.
(domU), - . Xen , .
() . , , Xen, , ,
. Xen , ,
Xen .
OpenVZ Virtuozzo ( , Parallels),

Linux-VServer ( ). OpenVZ,
Virtuozzo Linux-VServer
Linux. OpenVZ Virtuozzo
, Linux.
, (!) .
-,
.
Hyper-V( , Microsoft). Microsoft -

,
, Hyper-V . Hyper-V
Windows Server -,
Linux .

92

4. VirtualBox

Linux,
( Microsoft ,

).
. , :
? : , -
! VirtualBox. ,
(32/64, KDE/Gnome ..).
, , 67 VirtualBox, .
! .
, ,
, VirtualBox . , Windows
Linux, , .
, , ,
.
.

. : KVM.
. , , .
, VMware,
Xen (). :
( VMware

)
,
..
, -, .
. , .
. - . , ,
(, VirtualBox
VMware).

4.2. VirtualBox ()

93

4.2. VirtualBox ()
VirtualBox ,
Linux, Windows, Solaris MacOSX. x86 (
Windows7, Solaris OpenBSD). VirtualBox 64--,
,
3D- ( ,
3D- Linux, Aero Glass, Windows Vista Windows7), .. VirtualBox
( KVM, Xen ..) .
.
, VirtualBox VMware , VirtualBox
,
. , VirtualBox
, VMware.
VirtualBox, , , VirtualBox

-.
VirtualBox InnoTek, (Connetix) VirtualPC. Microsoft
2003 - VirtualPC,
Microsoft. 2004 VirtualBox VirtualPC
. InnoTek Sun, Sun
Oracle. VirtualBox 4.1.
www.
virtualbox.org.
. VirtualBox: VirtualBox
: .
VirtualBox (tainted crap)
, VirtualBox.
http://www.phoronix.com/vr.php?view=OTk5Mw https://lkml.org/
lkml/2011/10/6/317.
VirtualBox Linux.
VirtualBox. Fedora
rpmfusion. .
- VirtualBox : vboxdrv, vboxnetadp
vboxnetfit.

94

4. VirtualBox

, . ,
(VirtualBox
, , ):
root# /etc/init.d/vboxdrv setup

VirtualBox.
- gcc .
Ubuntu ,
.
VirtualBox Oracle. VirtualBox,
, Oracle. , , , Oracle VirtualBox, .
http://www.virtualbox.org/wiki/Linux_Downloads VirtualBox
: RPM Debian , ,
:
root# chmod u+xVirtualBox_n.run install
root# ./VirtualBox_n.run install


:
root# /etc/init.d/vboxdrv setup

Virtualbox dkms.
DKMS VirtualBox . VirtualBox
.
Oracle-APT. Ubuntu Debian APT, .
/etc/apt/sources.list :
deb http://download.virtualbox.org/virtualbox/debian precise contrib
deb http://download.virtualbox.org/virtualbox/debian oneiric contrib

, ,
.
root# wget -qhttp://download.virtualbox.org/virtualbox/debian/sun_vbox.asc
root# apt-key add sun_vbox.asc

VirtualBox apt-get aptitude:


root# apt-get update
root# apt-get install virtualbox-4.1

95

4.2. VirtualBox ()

Oracle-Yum. ,
Yum (Fedora, openSUSE .), Yum:
root# wget -qhttp://download.virtualbox.org/virtualbox/debian/sun_vbox.asc
root# rpm --import sun_vbox.asc

, *.repo VirtualBox /etc/yum.repos.d:


[virtualbox]
name=VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/fedora/$releasever
enabled=1
gpgcheck=1

install zypper
install.

. VirtualBox
vboxusers. ,
/dev/vboxdrv,

. , VirtualBox
vboxusers
. kofler .
root# usermod -a-Gvboxusers kofler
root# groupmod -Akofler vboxusers

(Fedora, Debian, Ubuntu ..)


(openSUSE, SUSE, Novell)

, -, Init-V-Script /etc/init.d/vboxdrv.

VirtualBox.
, KDE Gnome VirtualBox,
VirtualBox . VirtualBox
~/.VirtualBox.
, ,
.

Windows MacOSX.
VirtualBox Windows MacOSX
. virtualbox.org,
Windows.
. Oracle (extension pack). VirtualBox ,
VirtualBox . , USB- iSCSI-,
RDP (
) , .
, .

Oracle!

96

4. VirtualBox

4.3. VirtualBox ()
Linux
, VirtualBox
Linux. , VirtualBox: Windows, Linux MacOSX.

. (,
Linux c 2.6.n, 3.n),

VirtualBox . ,

CD/DVD- ISO.
, . VirtualBox .
Linux, .

NAT. ,
. 4.1
, VirtualBox.
, - ADSL.
. , - (SSH, NFS, Samba .).

, .
Ctrl. VirtualBox,
,
-. , . .4.1 -.
VirtualBox.
4.1. VirtualBox

-+F

()

-+Delete

Ctrl+Alt+Delete

-+Backspace

Ctrl+Alt+Backspace

-+Fn

Ctrl+Alt+Fn

-+S

(
)

-+H

ACPI

-+R

(: !)

4.3. VirtualBox ()

97

.
, . , . ,
(!),
, ..
:
openSUSE: virtualbox-ose-guest-tools, xorg-x11-driver-virtualbox-ose
Ubuntu: virtualbox-ose-guest-utils, virtualbox-ose-guest-x11, virtualbox-ose-guestdkms

,
, .
CD/DVD . - ( ,
CD, mount, mount/dev/sr0/media/cdrom),
:
root# sh /media/cdrom/autorun.sh


CD
. CD/DVD ISO- .

.

: vboxadd,
vboxvideo vboxvfs, X-, .
Ubuntu . Linux
, C- .
, , ! ,
, uname -a.
root# aptitude install gcc make linux-headers-n.n-plattform (Debian)
root# yum install gcc make kernel-headers kernel-devel (Fedora)
root# zypper install gcc make kernel-source kernel-syms (openSUSE)

Fedora :
, PAE.
, , uname r.
, pae,

98

4. VirtualBox

PAE. kernel-devel
kernel-PAE-devel.
.

Windows
, ISO, , VirtualBox
Windows. VirtualBox Windows XP Windows7 (.4.1).

.4.1. 64- Windows7 RC VirtualBox

VirtualBox
Windows ( Windows7, 64- 32- ). , Windows7
Windows Vista (Aero Glass) . WindowsXP, ,
Windows7 Windows Vista.

4.3. VirtualBox ()

99

- , .

, !

VirtualBox
. -
. .
.
, .
-
, (, myshare).
mount, . myshare
, .
root@gast# mkdir /media/vbox-share
root@gast# mount -tvboxsf myshare /media/vbox-share

, Windows , .
Windows,
.
\\vboxsrv\myshare.
USB- .
(Extension Pack) VirtualBox, USB-.
, - USB-. - USB- .
USB- .
, , VirtualBox, vboxusers. , ,
USB2.0 USB
. ,
USB- . , . , USB VirtualBox USB.
,
USB ( ), , , , -.
.
. , .

100

4. VirtualBox

, ,
, , : OVF- , VMDK-
.
VirtualBox. , Vmware VirtualBox , , . , .

Linux .
.
, Windows MacOSX, , ,
.
Linux !
, .
Linux
.
,
.
,
.
Linux, , , (). , , , .
, ,
.
,
Linux. , -
.
,
.
(shell). Linux . bash,
.
Linux .
, , (ls, cp, mv,
ln, rm) (find, grep, locate),
(ping, ifconfig, ssh) .. ,
Linux.

102

5.

5.1.
. Windows
. Linux
.
. Alt+F1
, Alt+F2 .. Linux
, Ctrl+Alt+F1 ,
Alt+F7 . (
Fedora) .
.
, . Ctrl+D( ).
(.5.1).
, -.
root ,
.
.
5.1.

Ctrl+Alt+Fn

Alt+Fn

Alt+F7

(Alt+F1 Fedora, Alt+F5


Knoppix)

Alt+/+

Shift+/

Ctrl+Alt+Delete

Linux; , :
!

Shift+ Shift+ ,
. , ,
.
( ). , .
. , .
, gnome-terminal (Gnome), konsole (KDE)
xterm (X). , ,
. :
Fedora 17 (Gnome 3) Windows;
openSUSE 12.2 (KDE) ;

5.1.

103

RHEL 6 (Gnome 2)
Ubuntu 12.10 (Unity) Windows.

Gnome . nautilus-open-terminal.
. , ,
,
.
.
,
. .5.2 .
,
bash .
Gnome ,

.
5.2. bash

Ctrl+A

( Home)

Ctrl+C

Ctrl+E

( End)

Ctrl+K

Ctrl+Y

Ctrl+Z

( fg bg)

Tab


Tab. , Tab,
, . Tab, ,
.
. .
! , , ,
.
( ), gpm.
. , Enter. ls , .

104
user$ ls -l
-rw------- 1
-rw------- 1
drwxrwxr-x3
drwxrwxr-x2
-rw-r--r-- 1
drwxr-xr-x2
...

5.

user
user
user
user
user
user

users 17708403 19. Mai 10:35 20060519_DN.pdf


users
506614 29. Jun 12:11 angebot-katzbauer.pdf
users
4096 13. Apr 11:31 bak
users
4096 18. Jul 15:03 bin
users
243571 3. Jul 09:14 DB20078.jpg
users
4096 7. Apr 10:59 Desktop

, : user$ , . root#,
, (,
). user$ root# . ,
! ( , .)
, user$ root# , / .
.
. , \.
:
user$ gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/monitor" \
--type integer "0"

, ,
\. , \
.
.
. , .
, , &.
, (: firefox &).
. Linux (, ).
, , .

su - l. root (,
).
, .
exit Ctrl+D,
(Ubuntu sudo).
, , () .., 8.

5.2.

105

5.2.

less
KDE Gnome
(Konqueror Nautilus).
.
, less.
,
:
user$ less
user$ ls l| less

( )
( )

.5.3 less.
5.3. less

Home, End

G, Shift+G

/ Enter

? Enter

(next)

Shift+N

()

, Linux (, , NAS) less . more, . cat


( ).
, , tail.

, , ,
. , . ,
reset.

. less , , TAR.
( )

106

5.

, , less. .
Fedora RedHat LESSOPEN , less
/usr/bin/lessfile.sh . SUSE less
/usr/bin/lessopen.sh.
Debian Ubuntu (lessfile
lesspipe.sh). , lesspipe less, lessfile . , less
. Ubuntu lesspipe, Debian
~/.bashrc, .


KDE Gnome kate gedit . ,
.
. , .
Emacs, Jove, Jed, Jmacs. -
GNUEmacs. ,
. .5.4 .
Jove, Jed Jmacs.
Emacs, .
5.4. Emacs

Ctrl+X, Ctrl+F

Ctrl+X, Ctrl+S

Ctrl+X, Ctrl+W

Ctrl+G

Ctrl+K

Ctrl+X, U

Ctrl+X, Ctrl+C

Emacs ( )

Vi, Vim Elvis. UNIX Vi, Linux Vim,


. Elvis. Vi Linux ,
. , vi
Vim Elvis.
Vi , Emacs,
. Vi

5.2.

107

. Vi ,
UNIX. UNIX/
Linux, .
,
Vi .
(.5.5). complex command, : (.5.6).
, Esc.
5.5. Vi

Esc

H/L

J/K

DD

complex command
5.6. complex command

:w

:wq

Vi

:q!

Vi

:help

Joe. . , Wordstar (.5.7).


man joe.
Jmacs Jpico.
, , , Emacs
Pico.
5.7. Joe

Ctrl+K, H

Ctrl+K,

Ctrl+K, D

( )

Ctrl+Y

Ctrl+Shift+

Ctrl+C

Joe

( )

108

5.

Nano, Pico. Nano ( Pico)


, . ,
, , . Nano.
Pico ,
Linux . Nano Pico,
.
.
,
Vi. ,
EDITOR VISUAL etc/profile ~/.profile.
# /etc/profile ~/.profile
Export EDITOR=/usr/bin/jmacs
Export VISUAL=$EDITOR

5.3. -
ls, cp top, , F1. , .
, ,
.
-help , , ,
.
man man- . , .
Q .
help , cd alias.
info man.
.
man info, ,
. man .
man. , ls cp. : man ,
, .
(man ),
man . ,
3 printf, Cprintf.
, man
. man
man.

5.3. -

109

man (
), -a. , , Q, man .
UNIX Linux man, find(1). , ,
. 19 n;
, :
1 ;
2 ;
3 C;
4 , -;
5 ;
6 ;
7 ;
8 ;
9 ;
n .
less,
, .5.3.
, , MANPATH /etc/manpath.
config.
KDE Gnome -
. ,
man ls man:
user$ gnome-help man:ls
user$ khelpcenter man:ls
user$ khelpcenter 'man:(index)'

help. man , help . ,


. ,
. Linux- bash
.
info.
. info
,
.
info info . ,
.
, , , : , ,

110

5.

,
, , .
.5.8 info.
5.8. info

Backspace

B, E

Tab

Enter

Ctrl+O

info

info Emacs Alt+X


info Enter Ctrl+H, I . , . info pinfo. KDE Gnome
info.

Bash ()

bash.
. ,
. bash
, (shell).
bash
. ,
, bash, ,
( , ) . bash,
. , , bash.

6.1. ?
Bash Bourne Again Shell. : bash
(bourne), , Korn ,
UNIX (again . . . .).
Linux ,
bash.
? Linux. , ( .com MS-DOS). , konsole, gnome-terminal, xterm,
().
, .
,
.. ,
, , ,
, .. ,

112

6. Bash ()

, () .
. bash- 4.n,
3.n. 4.0 , (, shopt s /etc/bashrc). ,
, :
user$ echo $0
-bash
user$ $BASH_VERSION
4.2.29(1)-release

. man bash .
, , info bash.
, : http://www.gnu.org/software/bash/manual/
bash.html.
. Linux bash . , , . Linux Z-
zsh. Korn (ksh pdksh) C (csh tcsh).
,
. exit .
user$ zsh
hostname% ls
( zsh)
...
hostname% exit ( )
user$

, . , Linux, .
,
/etc/passwd. .
, chsh (change shell). /bin. , , , /bin/csh , C. /etc/shells.
/bin/sh. #!/bin/sh. , /
bin/sh. /bin/sh bash. ,
bash ( ) , ,
. Ubuntu , , Debian-Almquist
(dash). , bash. -

6.2.

113

bash- ,
#!/bin/bash.
user$ ls l/bin/sh
.../bin/sh -> dash

6.2.
bash. bash
/etc/inputrc ~/.inputrc.
Delete, Home End , inputrc ,
. , .
# /etc/inputrcbzw.~/.inputrc
setmeta-flagon
setconvert-metaoff
setoutput-metaon
"\e[1~":beginning-of-line
"\e[3~":delete-char
"\e[4~":end-of-line

readline, bash .
, ,
, , , .
Delete, Home End.
.
. .
. , /
.
$, ~, > ( ) # ().
PS1,
, /etc/bash.bashrc, RedHat
Fedora /etc/bashrc. PS1="\s-\v\$".
bash . PS1, ~/.profile.
:
# ~/.profile
PS1="\w\$"

\u , \h , \w , \W
\$ ( #) . ,

114

6. Bash ()

\[\e[0;nnm\] . ,

ANSI-
: http://tldp.org/HOWTO/Bash-Prompt-HOWTO/.
:
PS1='\[\e[0;34m\]\u@\h:\W\$\[\e[0;39m\] '

username@computername:folder.
, , . /usr/lib/nautilus nautilus.
,
.
PS1
PROMPT_COMMAND. ,
PS1.

6.3.
, bash . bash .
,
,
. ~/.bash_history , , .
,
, . bash . , ( ) .
emacs vi. , , .
emacs.
, ,
emacs.


bash
.

Tab. ,
. , , .
, , , ,
.

6.3.

115

.
user$ em Tab com Tab

( )
user$ emacs command.tex

emacs , command.tex LATEX , . em,


bash ,
PATH. ,
.
, .
user$ ls/usr/sh Tab

bash
user$ ls/usr/share/

(
), . bash ().
user$ eTab Tab

, e. .

,

PATH
(
PATH

echo
$
PATH
; .).
Linux


PATH
. , ./name.

. , . .
whereis .
which , PATH,
,
. which , .
type which, ,
bash (. , ).
bash (, ~ko Tab ~kofler/)
($PAT Tab $PATH).

116

6. Bash ()

- . latex .tex
, *.tex.
man , ,
man. ,
. , , , .
bash complete. complete, , ,
(, Fedora
bash-completion). ,
:
/etc/bash_completion;
/etc/bash_completion.d/*;
/etc/profile.d/complete.bash;
/etc/profile.d/bash_completion.sh.

,

complete
.
help

complete

man

bash
( Programmable Completion).
: http://www.caliban.org/bash/index.shtml; http://www.pl-berichte.de/t_system/bash-completion.html.


6.1 , , bash
emacs. .
, 6.2
. X, , bash , X .
Gnome,
.
6.1. bash

Home, End

Ctrl+A, Ctrl+F

(, Pos1
End )

Alt+B, Alt+F

Backspace, Delete

Alt+D

117

6.3.

Ctrl+K

Ctrl+Y

Ctrl+T

Alt+T

Tab

Ctrl+I

Ctrl+R

Alt+.

Ctrl+_

(Undo)

. Alt+.
. , (cp 1 2).
. rm 2
rm, Alt+.. bash . Alt+.,
(
1).
. Ctrl+R.
,
Ctrl+R, . Ctrl+R, , . Ctrl+S Ctrl+R, .
, .
Ctrl+S , . Ctrl+O.
Ctrl+S, Ctrl+R.
bash readline,
. man readline .

,
alias. .
, . ,
.
, bash .
bash ,
(, , , ;), .
user$ alias cdb='cd~kofler/linuxbuch'

118

6. Bash ()

cdb ,
~kofler/
linuxbuch.
alias . , alias .
, :
user$ alias more=less

more less. - more,


(/bin/more)
(\more). .
alias unalias.
, (
, ).
- , alias /etc/bashrc ~/.bashrc
.

. , rm ,
, rm=rm -i.
, , alias. , Debian,
Fedora, SUSE Ubuntu .
Debian Fedora, Ubuntu: /etc/bashrc /etc/profile.d/*.sh ~/.bashrc
SUSE: /etc/bash.bashrc /etc/profile.d/*.sh ~/.bashrc ~/.alias

. Shell-
($1,
$2 ..) .

6.4.
bash .
, ,
, ,
.
, (,
bash ), .
.
( , ls).
.
.

6.4.

119

, , , ,
, , ? , .
, ,
, . ,
. bash >:
user$ ls *.tex > content

content TEX-,
. . : 2>
; >& &> , .
> >>,
.
< : ,
, .

sort dat > dat sort < dat > dat dat!
.6.2 .
6.2.

>

<

2>

>&

&>

>>

&>>


( bash 4.0)

1 | 2

1 2

| tee


(pipe) |.
.
less,
.
user$ ls -l| less

120

6. Bash ()


. less, , .

. , ,
RPM:
user$ rpm -qa | sort

FIFO-. FIFO
(first in first out) .
FIFO- ,
, , | .
, ,
, .
user$ mkfifo fifo
user$ ls -l> fifo &
user$ less < fifo

FIFO-.
, ls. .
less .
,
, , .
, xargs.

tee
,
. , , . tee:
user$ ls | tee content

content.
tee. ,
.
, ,
tee :
user$ ls | tee content1 > content2

: content1 content2.
. ,
:
user$ ls -l| tee content1 | sort +4 > content2

6.5.

121

content1 , ls . sort, ( , +4) content2.

6.5.
.
, bash . ,
() ( *.tex),
..
.
&. , bash
. ,
, , .
User$ find / -name '*sh' > result &
[1] 3345

, sh. result.
, .
[1] 3345 , PID3345. PID
(process ID). PID ,
kill. , bash. ,
.
&, , Ctrl+C. ,
Ctrl+Z,
bg.
. &
.
, .
find . ls :
user$ find / -name '*sh' > result & ls

& , bash
:
user$ ls; date

122

6. Bash ()

,
. >, . .
user$ (ls; date) > content

content , ls,
, date.
( ,
).
&& ||, , (.6.3).
user$ 1 && 2

1. , ( , 0 ),
2.
user$ 1 || 2
6.3.

1 ; 2

1 && 2

2, 1

1 || 2

2, 1

&

1 & 2

1 , 2

(1 ; 2)

if, , ,
, .

6.6.
. , ,
, . :
ls *.tex *.tex
, : buch.tex, .tex.
,
(. .6.4), : , ,
, , ,
..

123

6.6.
6.4.

( ), *-!

**

, ( bash 4.0 shopt -sglobstar)

[abc]

[af]

[!abc]

, ,

[^abc]

..

ab{1,2,3}

ab1 ab2 ab3

a{1..4}

a1 a2 a3 a4

$[3*4]

``

$()

""

, $

''

,
( )

, , . , . :
${var__text}, var , _ ,
text . 6.10.
* ?. rm *.bak rm , .bak,
- bash. *.bak .
? ( )
* ( , ). [a,b,e-h]* , a, b, e, f, g h. , ,
^ !, , . ~
.

echo. ,
. ,
a f.
user$ echo /*
/bin /boot /dev /etc /home /lib /lost+found /media /misc /mnt /net /opt
/proc /root /sbin /selinux /srv /sys /tmp /usr /var

124

6. Bash ()

user$ echo /[a-f]*


/bin /boot /dev /etc

,
bash, , , , .
, ls * ,
. ls *
. , ls
, !
, -d. , , , .
bash, set -x. bash
( , ).
* ,
( , ). ,
bash- glob_dot:
user$ shopt -sdotglob
user$ echo *
...
user$ shopt -udotglob

(dotglob )

**. 4.0,
** . . (, ), bash globstar
shopt -s.
user$ shopt -sglobstar
user$ echo **
...

{}. , , bash
. (brace expansion). part{1,2a,2b}
part1 part2a part2b. , , .
* ? ( , , mkdir).
user$ echo {a,b}{1,2,3}
a1 a2 a3 b1 b2 b3
user$ echo {ab,cd}{123,456,789}-{I,II}
ab123-Iab123-II ab456-Iab456-II ab789-Iab789-II
cd123-Icd123-II cd456-Icd456-II cd789-Icd789-II

6.6.

125

{a..b}, a b,
, , .
:
user$ echo {1..5}
1 2 3 4 5
user$ echo {z..t}
zyxwvut

[]. bash . 2+3, ,


. , ,
$:
user$ echo $[2+3]
5

, : +, , *, /
, % , ==, !=, <, <=, > >= , << >>
, !, && || NO, AND OR ..
32- ( :
2147483648).
, $.
expr.
Linux, bash.
. , .
`. $().
, , -,
(", ' `), -, .
. ,
.
:
user$ ls -lgo `find /usr/share -name '*README*'`
user$ ls -lgo $(find /usr/share -name '*README*')

find /usr/share -name '*README*'.


, /usr/share README.
find.
:
user$ ls -lgo /usr/share/a2ps/ppd/README \
> /usr/share/a2ps/README ...

126

6. Bash ()

:
-rw-r--r-- 1
-rw-r--r-- 1
...

301 15. Feb 12:30


1029 15. Feb 12:30

/usr/share/a2ps/ppd/README
/usr/share/a2ps/README

, |,
. ls , , find . . find !
user$ find /usr/share -name '*README*' | ls -l( !)

, : xargs :
user$ find /usr/share -name '*README*' | xargs ls -l

xargs , , , . xargs

. , , , .
, . , find
-print0, xargs -null.
execute:
user$ find -type d-print0 | xargs --null chmod a+x

. bash
, , , . .
(\)
. ,
, , ab* $cd:
user$ rm 'ab* $cd'

: ' , ` (. ). !
, .
($, \ `). ,
, $:
user$ echo "This is the access path: $PATH"

This
is the access path, PATH.

6.7.

127

, ,
echo .

6.7.
bash Linux .
,
. =. , echo ,
$:
user$ var=abc
user$ echo $var
abc

= . var=abc
!

,
:
user$ var='abc efg'

.
, ,
xxx :
user$ a=3
user$ a=$a'xxx'$auser$ echo $a3xxx3

PATH ( ,
)
bin. ,
( ).
user$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
user$ PATH=$PATH':/home/kofler/bin'
user$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/kofler/bin

:
user$ a=3
user$ a=$[$a*4]
user$ echo $a12

128

6. Bash ()

,
$(). :
user$ a=$(pwd)
user$ echo $a/home/kofler

. .
, /etc/profile
.profile . ( )
bash.
,
echo :
user$ echo $var > file


( )

. ,
.
(environment variables).
, ,
, ! , export declare -x.
, . , export, declare -x.
,
:
a=3
declare a=3
declare -xa=3
export
export a
export a=3
let a=3
local a=3
printenv
set
unset a

let, a
( let)
( export)




( )
export,
(, )

,
Linux, ! ,
, , ,
,

6.7.

129

x=..., export x.

. ,
, . .
~/.profile, .


,
.
, , bash,
Linux.
Linux ..

.
BASH bash.
HOME , /home/mk.
LOGNAME ( ).
HOSTNAME - ( ).
MAIL , ( ).
OLDPWD .
PATH . bash ,
, PATH, . .
PATH ,
(Init-V, Upstart).
/etc/profile (
) /etc/profile.d. :
# /etc/profile /etc/profile.d/myown.sh
PATH=$PATH:/myown/bin

( ), PATH .
, ,
./, PATH .
PROMPT_COMMAND , , bash
.

130

6. Bash ()

PS1 ,

( , ).
: \t , \d ,
\w , \W (, X11
/usr/bin/X11), \u , \h - ( ),
\$ (\$ , # ).
PS2 PS1,
( \). ">".
PWD .
,
, ,
.
printenv | sort.

6.8. bash
,
Linux bash. .
. .

, bash , , .
,
, . ( , : ,
, .. bash
.)

, ,
, , ..
bash-
.
http://bash-hackers.org/.
Dash. , Ubuntu bash
dash:
> ls -l/bin/sh
lrwxrwxrwx 1 root root ... /bin/sh -> dash

6.8. bash

131

, dash , bash,
. bash,
/bin/bash /bin/sh:
#!/bin/bash

. Linux bash, ,
, . , , Linux,
bash.
find/grep /etc/
. , \#! ... sh. list. ,
.
user$ find /etc -type f-perm +111 -exec grep -q'#!.*sh' {} \; -print > shellscripts

1: grepall
, grep find,
, . :
user$ find . -type f-exec grep -qsearchtext {} \; -print

,
, grepall, .
grepall.
:
#!/bin/sh
find . -type f-exec grep -q$1 {} \; -print

, #!.
, .

, cat:
cat

> grepall

. ( ) grepall. . ,
cat Ctrl+D( EOF, (end of file)).
cat grepall.

grepall
permission denied. , , (x).
cmod. grepall
abc , abc.

132

6. Bash ()

user$ ./grepall abc


bash: ./grepall: Permission denied
user$ chmod a+xgrepall
user$ ./grepall abc
./bashprg.tex

grepall ( grepall ),
,
$PATH. , /usr/local/bin:
root# cp grepall /usr/local/bin

2: stripcomments
. stripcomments
. grep ,
# ; .
, # ;,
. , , .
#!/bin/sh
grep -v^[[:space:]]*\# $1 | grep -v^[[:space:]]*\; | grep -v^$

: ^[[:space:]]*\# , #,
(^) #
. , grep
, ;. , grep ,
($).
-v grep: ,
, grep , . -E
grep, |.

3: applysedfile
,
, , . . ,

. , , .
applysedfile.
:
user$ applysedfile *.tex

6.8. bash

133

*.tex *.bak. UNIX sed,


*.tex . ./sedfile, applysedfile.
applysedfile :
#! /bin/bash
# sedfile
# : applysedfile *.tex
# ./sedfile
for iin $*
do
echo "process $i"
#
cp $i${i%.*}.bak
#
sed -f./sedfile < ${i%.*}.bak > $idone

, : , #.
for .
i . $*.
, .
. cp
. , , .bak. , sed, sedfile .
, ,
, :
s.da..dass.gs.mu..muss.gs.pa.t.passt.gs.la.t.lasst.g

sed, ( s). g, (,
da1 mu2).

4:
root. m,
. ( date .
+%m .)
1
2

(.).
(.).

134

6. Bash ()

tar /var/www. , | curl. curl


FTP- ( kofler, xxxx,
IP- 1.2.3.4). FTP-
www-month.tgz.
, .
-
. ,
( 12 ,
www-01.tgz www-12.tgz).
mysqldump MySQL,
cms. , (CMS) , .
| curl FTP-.
#!/bin/sh
m=$(date "+%m")
cd /var
tar czf - www | curl -T- -ukofler:xxxx ftp://1.2.3.4/www-$m.tgz
mysqldump -ucms -pxxxx cms | curl -T- -ukofler:xxxx ftp://1.2.3.4/cms-$m.sq

/etc/myscripts/backup. Cron ( . 8.6).


/etc/cron.d/backup :
# 3:15
153 * * 0 root /etc/myscripts/backup

5:
(thumbnails) .
makethumbs *.jpg.
400400 . 400400, . .
convert Image Magick.
-resize. size
.
#!/bin/sh
# : makethumbs *.jpg
if [ ! -d400x400 ]; then #
mkdir 400x400
fi
for filename do #
echo "processing $filename"
convert -size 400x400 -resize 400x400 $filename 400x400/$filename
done

6.10. bash

135

6.9. bash
, #!
.
. #!/bin/sh. bash- ,
#!/bin/bash.
,
, (r) (x). , ,
exec.


, .
bash
cannot execute binary file ( ).

Windows
(
carriage
return

) (
linefeed
).
Windows Linux, . bash
bad interpreter ( ).
Unicode (UTF8)
:
recode u8/cr-lf..u8 < windowsfile > \ linuxfile

, .
~/bin.
.profile,
.
, ~/bin PATH.
# Addition in ~/.profile or in ~/.bashrc
PATH=$PATH':~/bin'

6.10. bash
6.7. , , .
, . ,
, bash (, $* $?),

, , ,
.

136

6. Bash ()


, .
bash PID- ( Linux
).
,
(export declare -x). , bash
, , .
( bash
) .
. ,
. bash ,
. ,
,
( ).
, ( )
.
, . , .

. ,

bash, .
. source.
: , PATH . addpwd
:
#! /bin/sh
# addpwd
#
PATH=$PATH":"$(pwd)

, PATH ,
pwd
. ,
PATH ,
addpwd ( , -

6.10. bash

137

addpwd, PATH ,
, addpwd).
user$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
user$ addpwd
user$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
user$ . addpwd
user$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user

,
, bash. ,
. .
.6.5 $.
6.5. $-

$?

$!

PID

$$

PID

$0

, (
, )

$#

$1 $9

1 9

$* $@

: $0$9, $# $*
, . ,
.
bash
shift. $0 $9. shift 9, ,
, , .
shift ,
.
$? ,
. ,
if. $? ,
.
$$ PID ( ). Linux .

138

6. Bash ()

PID ,
,
. , ls > tmp.$$
tmp.nnn. ,
,
.

, bash . 3
. ,
n- , .
x=()
x[0]='a'
x[1]='b'
x[2]='c'
x=('a' 'b' 'c')
echo ${x[1]}
echo ${x[@]}

#
#
#
#
#

,
bash, 4.0. ,
declare -A.
, . , , 0,
, -
(Index0).
declare -Ay #
y[abc]=123 #
y[efg]=xxx
y=( [abc]=123 [efg]=xxx ) #
echo ${y[abc]} #

4 ,
mapfile
:
mapfile z< _


bash , ,
. ,
$. ,
, $.

6.10. bash

139

${var:-default} ,

, . . .
${var:=default} , , .
${var:+new} , .
, .
.
${var:? Error_message} ,
. , .
.
${#var} ,
(0, ). .
${var#pattern} .
,
, .
,
. , ,
(* ? [abc]). :

user$ dat=/home/mk/buch/buch.tar.gz
user$ echo ${dat#*/}
home/mk/buch/buch.tar.gz
user$ echo ${dat#*.}
tar.gz
${var##pattern} ,

, :
user$ dat=/home/mk/buch/buch.tar.gz
user$ echo ${dat##*/}
buch.tar.gz
user$ echo ${dat##*.}
gz
${var%pattern} ${var#pattern},

.
, . :
user$ dat=/home/mk/buch/buch.tar.gz
user$ echo ${dat%/*}
/home/mk/buch
user$ echo ${dat%.*}
/home/mk/buch/buch.tar
${var%% pattern} , -

,
:

140

6. Bash ()

user$ dat=/home/mk/buch/buch.tar.gz
user$ echo ${dat%%/*}
-- -user$ echo ${dat%%.*}
/home/mk/buch/buch
${var/find/replace} find
replace:
user$ x='abcdeab12ab'
user$ echo echo ${x/ab/xy}
xycdeab12ab
${var//find/replace} find
replace:
user$ x='abcdeab12ab'
user$ echo echo ${x//ab/xy}
xycdexy12xy
${!var} , var:
user$ abc="123"
user$ efg=abc
user$ echo ${!efg}
123

read
bash- read .
, echo ,
, (, y/n, ..).
-n, echo, .
read bash Enter.
, while , a , . , :
user$ readvar
: a
, ,
: 12
12

read ,
, , . ,
(
12-34-5, 1234), . while
while 6.11.

6.11. bash

141

#! /bin/sh
# readvar:
a= #
while [ -z"$a" ]; do
echo -n" : "
read a a=${a##*[^0-9,' ',-]*} # ,
# , 09,
# ""
if [ -z"$a" ]; then
echo " , , "
fi
done
echo $a

6.11.
bash
if case.
if , case ( ).

If-
iftst if- ,
. , . exit , (
). .
#! /bin/sh
# iftst
if test $# -ne 2; then
echo " !"
exit 1
else
echo " 1: $1, 2: $2"
fi

, :
user$ iftst a

!
user$ iftst ab
1: a, 2: b


then. 0, . then , (
), .

142

6. Bash ()

, (true) bash 0, (false) 0.


! , , 0. , 0, . .

test bash. ne (not equal). test


, , ,
, .. .
: test
.
[ ] .
, if echo,
- exit , fi,
, .
#! /bin/sh
# iftst, 2.
if [ $# -ne 2 ]; then
echo " !"
exit 1
fi
echo " 1: $1, 2: $2"

test
bash , ,
. -, bash ,
, , , < > . bash
test. ( , test bash.
bash, .)
test 0 (), ,
1 (), .
.
test :
, , ,
. .
test "$x" , x(,
0, ; ).
test $x-gt 5 , x 5.
x , . -gt ()

6.11. bash

143

: -eq (), -ne


( ), -lt (), -le ( ) -ge ( ).
test -f$x , , x.
test ,
$? ( ) echo:
user$ a=20
user$ test $a-eq 20; echo $?
0
user$ test $a-gt 20; echo $?
1

Case-
case case, ,
( ).
in , . ,
. , ,
, --*). , .
|. . , *.c|*.h)
*.c*.h .
, , . else, *
. case ,
.
casetst case
. i
, .
case. (-),
opt, dat.
#! /bin/sh
# casetst
opt= # opt dat
dat=
for ido #
case "$i" in
-* ) opt="$opt $i";;
* ) dat="$dat $i";;
esac
done #
echo "Options: $opt"
echo "Files: $dat"

144

6. Bash ()

,
. , ,
:
user$ casetst -x-ydat1 dat2 -zdat3
Options: -x-y-z
Files: dat1 dat2 dat3

case ( *.abc). case-, /usr/bin/gnroff. , nroff,


, groff.

For-
bash . for
. while ,
. until, , , .
break. continue
.
i
a, bc. do done .
, , echo
. ,
( ).
user$ for iin abc; do echo $i; done
a
b
c

:
#! /bin/sh
for iin abc; do
echo $i
done

for
{..},
. *.tex
*.tex~. (Linux/UNIX (~)
. cp $file
, , ,
.)
user$ for file in *.tex; do cp "$file" "$file~"; done

6.11. bash

145

for in ..., , ( in $*).


case.
case , ,
. Bash
. ,
:
#!/bin/bash
# ,
#
for iin "$@"; do
ls -l"$i"
done

while
i 1.
, do done,
1, 5. ,
, if, test .
user$ i=1; while [ $i-le 5 ]; do echo $i; i=$[$i+1]; done
1
2
3
4
5

, ls *.jpg:
ls *.jpg | while read file
do
echo "$file"
done

until
while until ,
.
while. i>5 -gt ().
user$ i=1; until [ $i-gt 5 ]; do echo $i; i=$[$i+1]; done
1
2
3
4
5

146

6. Bash ()

6.12.
bash
, . .6.6 , .
6.6. , bash

(.
file
)

#!/bin/sh

&

(com &)

&&


(com1 && com2)

&>

( >&)

(com1 | com2)

||


(com1 || com2)

( )

( )

[abc]

( abc)

[ expression ]

test expression

(...)

((om1; om2))

{...}

{,,}


(a{1,2,3} a1 a2 a3)

{a..b}


(b{4..6} b4 b5 b6)

>

(com > file)

>>

>&

( &>)

2>

<

(com < file)

<< end

(echo $var)

$!

PID ,

$$

PID

$0

$1$9

$#

6.12. bash

147

$* $@

$?

(0=OK )

$(...)

(echo $(ls))

${...}

$[...]

(echo $[2+3])

"..."

'...'

`...`

(echo `ls`)

. :
, ;
, , ;
CD DVD;
( );
Linux;
-.
. 14 .
, ,
, , :
;
[/etc/fstab, mount-];
;
LVM;
.
.
25. ,
, , ,
, , ..

7.1.
.
Linux 255.
!
,
(,

7.1.

149

).
Linux UTF-8.
Linux ,
0. .
. README.
bootutils.gz ,
README .
, , (. ). , 1s .
,
(, , )
(: "ab").
Linux
.

. Linux /.
, , C: Linux .
. , , . , ( , ),
.
Linux/UNIX , . 7.8.
. ()
,
, .
. ( ,
) , ( ).
Linux /home/
loginname/ ( /root).
/home/loginname/, (~). ,
~loginname.
. .. . , . ,
., ,

150

7.

, .., ,
(.7.1).
7.1. ,

..

, ,

,
( cp- ).
/etc/fstab . /home/name,
/home/name/fstab.
user$ cp /etc/fstab .

cd
~/linux8. cp fileuse.
tex ( ). ~/fileuse.
tex.bak.
user$ cd ~/linuxbuch
user$ cp fileuse.tex ../fileuse.tex.bak

/home/name,
/home/name/linuxbuch/fileuse.tex. ,
: /home/name/fileuse.tex.bak.
. KDE Gnome
, Linux . .7.2
.
7.2.

cd

cp

less

ls

mkdir

mv

rm

rmdir

cd. cd
. cd ,
, cd .. , cd
.
user$ cd /etc/samba

7.1.

151

j. j autojump. ,
. , autojump ,
. jumpstats.
, , jabc, abc . (
, .) , j
, . , Tab.
Autojump (https://github.com/joelthelion/autojump/wiki) j cd. . j,
.
j , cd.
Tab ,
Autojump. cd /e Tab /e, , /etc/. j , /etc
Autojump. : , Autojump,
cd. ( j,
.) , j cd!
. ls .
,
-a. , , , .., -l.
ls .
, ,
-t, -S -X. r . TEX
linuxbuch, :
user$ ls -l-Slinuxbuch/*.tex
...
-rw-r--r-- 1 kofler kofler 301132012-05-1109:09 linuxbuch/intro.tex
-rw-r--r-- 1 kofler kofler 631732012-01-2908:05 linuxbuch/kde.tex
-rw-r--r-- 1 kofler kofler 764982012-06-0815:43 linuxbuch/kernel.tex
...

ls:
. (-) , d (directory),
b c (block char) l .
(rwx) , :
, . ,

152

7.

,
. , ,
, , .
, (
kofler), , , ,
.
ls ,
. ,
--color.
ls , , . ,
, -R. , ,
.
, ( ). , . |less
ls less,
.
user$ ls -lR | less

. cp 1 2 1. 2. , cp 1
2 ... . linuxbuch, bak,
TEX-.
user$ cd linuxbuch
user$ mkdir bak
user$ cp *.tex bak/

.
, cp -r. -r
( , ).
, -r -a.
, ,
. ,
sourcefolder ( ), . , .

, . :
user$
user$
user$
user$

mkdir test
touch test/auser$ mkdir test/buser$ touch test/b/cuser$ mkdir ziel1
cp -rtest ziel1 ( ziel1/ )
ls ziel1

153

7.1.

test
user$ cp -rtest ziel2
user$ ls ziel2
ab

( ziel2/ )

. rm
. , rm , . rmdir , ,
, , .
rm rf. ,
. , rm rf
!
userrm -rf linuxbuch-bak/ ( Backup-Verzeichnis)

,

ls l , .
, , ,
..
: df du.
, . df
, ,
. h
, , ( 1, ). df ,
,
.
user$ df -h
.
/dev/sda3
/dev/sda2
/dev/sda6
...

14G
942M
28G

.
4,7G
47M
7,7G

.
8,5G
849M
19G

.%
36%
6%
30%


/
/boot
/home

df ,
. /home/kofler
/dev/sda6, , , /home.
user$ df -h/home/kofler/
/dev/sda6
28G
7,7G

19G

30%

/home

. du ,
, . h , .

154

7.

du ( Gnome baobag,
; KDE Konqueror).
user$ du -hfotos/2008
74M
fotos/2008/2008-03-ostern
162M
fotos/2008/2008-08-korsika
66M
fotos/2008/2008-11-diverse
...
2,0G
fotos/2008



, TEX.
, Linux
(.7.3).
7.3.

( )

[abc]

[af]

[!abc] [abc]

, ,

* ? ? , *
( ). ,
MS-DOS, ,
. .
* , (
, ). ,
Linux *, *.*! (
.)
, Linux.
, *graf* ,
graf grafik.doc, apfelgraf README.graf.
[] [!]. * ? ,
, . , [abc]
: a, b c.
, . , [a-f]* , a f
.
*[ _.-]* , , , * .[hc]
, .c .h.

7.1.

155

.
*/*.tex TEX-, -

( ,
). /usr/ * bin/* ,
/usr/bin /usr/sbin.
,
, , . bash,
Linux , ,
.
. C- project :
user$ cp project/*.c.

,
. , echo jokerzeichen.
, ,
, .
, * ,
, ls* , , ,
*. ls -d, .
*/.
( ), */. , (
). , .
user$ echo */.

*.. ,
- , , , . , ,
TEX- ls R *.tex ( R
ls ).
: *.tex
ls.
. *.tex, ls . R.
,
.

156

7.

Linux
find. TEX-
. find -

find grep 7.4.


user$ find . -name '*.tex'

. , Linux
*.x *.y mv *.x*.y.
, : *.x
, . *.y
. mv
*.y mv , .
: , markus.x, peter.x ulrike.x.
mv *.x *.y, *.x , . , , *.y . mv.
, , , .
user$ mv markus.xpeter.xulrike.x*.y

markus.x peter.x
ulrike.x markus.y peter.y ulrike.y, , .
mv .
, .
sed. , UNIX-
:
sed. sed , , , .
: ls ,
, sed. sed s( ) cp-
sh, , , .
, , *.xxx *.yyy.
user$ ls *.xxx | sed 's/\(.*\)\.xxx$/cp & \1.yyy/' | sh

.
*.tex. tex ~ ( ~
):
user$ for iin *.tex; do cp $i$i~; done


, , Linux ,
* , :

7.1.

157

( , ) .
, , .*, :
, ., , . .. (
, ). ,
.
, .[!.]*.
, ,
, , (
).
user$ echo .[!.]*

ls a,
( ). (, *rc*). a ,
ls , .
find.
:
user$ find -maxdepth 1 -type f-name '.*'


(-, -)
, Linux , ,
, .
ls F .
user$ ls -lF
... 13. Apr 11:31 bak/
... 11. Apr 12:21 grepalltex*
...

.7.4 .
7.4.

Pipe, FIFO

158

7.

7.2.
.
.
, .
Linux /bin /lib
( , , /usr/bin /usr/lib ls -l).
, , . ,
test abc. , ln abc xyz
xyz. abc xyz
. , , ls l.
, (
). -i, ls , , ( ).
user$ ls -li
59293 -rw-r--r-- 1 root root 1004 Oct 416:40 abc
user$ ln abc xyz
user$ ls -li
59293 -rw-r--r-- 2 root root 1004 Oct 416:40 abc
59293 -rw-r--r-- 2 root root 1004 Oct 416:40 xyz

( ), (
). , .

: , .
: , . :
abc
abc

~. , .
, .

. Linux .
,
ln. , , s,
.

. ( , . . , .)

7.3. (MIME)

159

ls , . , ,
.

, ,
( , ) .
user$ ln -sabc efg
user$ ls -li
59293 -rw-r--r-- 2 root root 1004 Oct 416:40 abc
59310 lrwxrwxrwx 1 root root 3 Oct 416:52 efg -> abc
59293 -rw-r--r-- 2 root root 1004 Oct 416:40 xyz

, ,
, , .

, .
( abc) ,
efg . , , ,
.
, .

.

.
, . , NFS
.
, , .
.
.

7.3. (MIME)
MP3- ,
. ,
, MIME .
MIME Multipurpose Internet Mail Extensions . MIME . ,
, PostScript JPEG,
, .
, MIME.

160

7.

MIME : ,
, , . , MIME ,
.

MIME
Linux Linux ( UNIX),
MIME. , , ,
, . MIME KDE,
Gnome, , CUPS .. . , MIME
, MIME.
, MIME Linux . KDE Gnome , . KDE
- PNG, , .
KDE Gnome, , , KDE Gnome ()
. KDE Gnome
MIME.
MIME .
MIME ,
. MIME Linux. , MIME, , MIME
KDE KDE (.3) ..
MIME. MIME ,
MIME. ,
, (.7.5).
7.5. MIME

/etc/mime.types

/etc/mailcap

~/.mime.types

~/.mailcap

mime.types ,
( ) ( ). , application/pdf PDF.

7.4. (find, grep, locate)

161

mime.types X-, MIME application/x-name.


# /etc/mime.types
...
application/pdf pdf

mailcap ,
. ,
PDF evince.
mime.types, mailcap ; %s
.
# /etc/mailcap
application/pdf; evince %s


MIME ,
, .
? ,
. , *.ps ,
PostScript.
, file KDE Gnome
, ,
. ,
; file .
/etc/magic ~/.magic.

7.4. (find, grep, locate)


Linux (.7.6).
, , ,
( , ..) ( , ..).
7.6.

grep

find

, , ..

locate

whereis

which

PATH-

162

7.

which whereis
which . ,
, . which , PATH,
. PATH , . , PATH , . ,
, .
user$ which emacs
/usr/bin/emacs

whereis ,
, , man- .
. whereis , which,
. ,
(. man whereis).
user$ whereis fstab
fstab: /etc/fstab /usr/include/fstab.h/usr/share/man/man5/fstab.5.gz

locate
locate , ( + ) . : locate
, ,
.
locate , .
,
locate. , , .
. X- xorg.conf:
user$ locate xorg.conf
/etc/X11/xorg.conf
/etc/X11/xorg.conf.backup
/etc/X11/xorg.conf~
/usr/share/man/man5/xorg.conf.5x.gz

dvips (, , LATEX)
,
. ,
wc.
user$ locate dvips | wc -l

421

, ,
dvips:

7.4. (find, grep, locate)

163

user$ locate *dvips'


/usr/bin/dvips
/usr/bin/odvips
/usr/bin/opdvips
/usr/bin/pdvips
/usr/local/texmf/dvips
/usr/local/texmf/fonts/map/dvips
...

updatedb.
, locate.
updatedb. , updatedb
, .
.
, .
locate updatedb . Debian, Fedora
Ubuntu mlocate.
/var/lib/mlocate/mlocate.db
Cron-Job /etc/cron.daily/mlocate. /etc/
updatedb.conf , (, CD, DVD, ).
openSUSE locate .
,
findutils-locate updatedb, . Cron-Job /etc/cron.daily/suse.de-updatedb.
/etc/sysconfig/locate.

find grep
find , ,
. ( , ,
..). man find.
find , . , find , .

find
, find ,
:
user$ find
...

,
.e:

164

7.

user$ find -name '.e*'


./.evolution
./.emacs
./.emacs~
./.esd_auth
...

find , /usr/share/texmf,
*.tex , latex.
user$ find /usr/share/texmf -path '*latex/*.tex'
/usr/share/texmf/ptex/platex/base/plnews03.tex
/usr/share/texmf/ptex/platex/base/kinsoku.tex
...

find , /etc/.
, /etc/., .
sort (
).
root# find /etc -type d| sort
/etc
/etc/acpi
/etc/acpi/actions
...

find () /home, users, (,


..):
root# find /home -group users -mtime -5
...

find -mtime +5 , ,
, -mtime 5 , . find
24 . -mtime
-ctime, (inode change time). , , .
,
. find
rm ($()).
user$ rm $(find . -name '*~')

, : *~- , . -exec- find,


xargs.

7.4. (find, grep, locate)

165

grep
.
, ,
, .
.
TEX- emacs. (
) .
user$ grep emacs *.tex
...

grep , arctan
-.
user$ grep -carctan\(.*\) *.c

grep -v ,
.
grep configfile ,
# ( ). cat .
nocomments.
user$ grep -v'^#' configfile | cat -s> nocomments

,
.

nd grep
find grep , .
find ,
emacs. , . ,
print exec ( , grep emacs *.tex TEX , ).
user$ find -name '*.tex' -type f-exec grep -qemacs {} \; -print
...


10 case.*in.
result. , (
10).
user$ find -name '*' -maxdepth 1 -size -10k -exec grep -q\
> case.*in {} \; -print > result

166

7.

7.5. CD DVD
Brazero K3B
Gnome KDE. ,
, , . , burncdda.
,
. , , ,
CD .
,
Linux.
. , ,
; . , : /dev/scd0, /dev/scd1 ..
/dev/sr0, /dev/sr1 ..
(, dev=3,0,0). : SCSI (0),
SCSI-ID , , ( ,
0).
readcd -scanbus.

, CD DVD, ,
Linux ,
!

ISO-
CD DVD,
(ISO). , , .
, genisoimage (
mkisofs).
genisoimage. genisoimage . ISO-9660,
CD, ,
, , ASCII.
, ISO, .
genisoimage.
Rockridge, UNIX/Linux, , - . ,
(UID, GID, ).

7.5. CD DVD

167

, Rockridge, , .
, ,
. : Linux Latin-1.
, Rockridge,
.
, Unicode
(UTF-8), ,
ASCII, .
ISO- ,
, -output-charset.
Joliet, Windows,
, Unicode (UTF-16).
. ,
/master, /tmp/master.iso. master .
Rockridge ( -r), Joliet
( -J) Linux ( -V). ISO CD, .
user$ genisoimage -o/tmp/master.iso -r-J-VLinux /master

, :
user$ genisoimage -o/tmp/master.iso -r-J/master -bimages/boot.img -cboot.catalog

master
( -graft-points):
user$ genisoimage -o/tmp/master.iso -r-graft-points /master=/master

r, , master
!
user$ chown -Rroot.root /master
user$ chmod -Ra+r/master

xorriso. genisoimage
xorriso .
ISO, CD DVD.
,
: http://www.gnu.org/software/xorriso/.
dd. CD DVD ( !), dd,
. /dev/cdrom
CD- DVD-, .
user$ dd if=/dev/cdrom of=/usr/local/iso.img bs=2048

168

7.

readcd. dd readcd readom.


CD SCSI,
, dd. , readcd .
dd, CD DVD
.
readcd -scanbus.
user$ readcd dev=0,0,0 f=iso.img

readcd , TOC-
( -clone), , , , -
( -noerror -noclone). w readcd CD.
ISO-.
Linux ,
mount, .
loop, . , modprobe. , master.iso ,
:
root# mkdir /iso-test
root# mount -tiso9660 -oloop,ro /tmp/master.iso /iso-test/

iso-test CD.

CD
cdrecord wodim. cdrecord
CD. 2006 cdrecord
Sun CDDL. ,
GPL.
, : cdrecord,
GPL, wodim (write data to optical disk media)1, cdrkit. cdrecord
, : mkisofs genisoimage, cdda2wav
icedax.
wodim, genisoimage
icedax. cdrecord
cdrecord; /usr/bin/cdrecord wodim.
- , , , ISO- genisoimage.
1

7.5. CD DVD

169

CD (-dummy),
:
root# wodim -dummy -vspeed=16 dev=/dev/scd0 iso.img
root# wodim -vspeed=16 dev=/dev/scd0 iso.img

, genisoimage wodim
. ISO:
root# genisoimage -r/master | wodim -vspeed=16 dev=/dev/scd0 -

.
WAW. .
, .
root# wodim -vspeed=16 dev=0,5,0 -pad -dao -audio *.wav

cdrdao. wodim. cdrdao , . ,


(disk at once, DAO).
cdrdao . cdrdao data.bin ( -) data.toc (). CD.
user$ cdrdao read-cd --device 0,0,0 data.toc
user$ cdrdao write --device 0,0,0 --buffers 64 data.toc

.
CD master .
diff.log, . /media/cdrom , CD.
root# diff -qrd /master /media/cdrom/ >& ~/diff.log

( )
diff.log tail. , ,
CD. -
, (
-) (
, ).
root# tail -f~/diff.log

, ( , ), . , , ,
-, , , (, Linux).
root# dd if=/dev/cdrom of=/dev/null

170

7.

DVD
DVD .
dvd+rw-tools,
.
, wodim.
DVD-RDVD+R,
CD. wodim
DVD+RW DVD-RW.

dvd+rw-tools
, , dvd+rwtools . DVD+R
DVD+RW ( ).
DVD-R DVD-RW, Blu-ray- ( ). dvd+rw-tool , .
http://fy.chalmers.se/~appro/linux/DVD+RW/.

growisofs
dvd+rw-tools . DVD+R,
DVD+RW, DVD-R, DVD-RW Blu-ray. .
DVD+R, DVD-R .
growisofs -Z,
growisofs -M. .
.
DVD+RW, DVD-RW dvd+rw-format. ,
DVD+R/DVD-R .
, ,
growisofs-Z. CD-RW, DVD .
DVD-RW .
genisoimage,
. data
DVD. genisoimage -r -J , DVD
, Rockridge Joliet.
/dev/srn
/dev/scdn.
user$ growisofs -r-J-Z/dev/sr0 data/

( -M -Z):
user$ growisofs -r-J-M/dev/sr0 moredata/

7.5. CD DVD

171

,
DVD
, !
DVD .
DVD-RW .
DVD

-
DVD
+
RW
( , ). , , .
dvd+rw-format DVD+RW (DVD ,
!), dvd+rw-booktype (Book-type).
user$ dvd+rw-format -lead-out /dev/sr0
user$ dvd+rw-booktype -dvd-rom -media /dev/sr0

growisofs , -Z -M,
genisoimage, genisoimage DVD.
(ISO), :
-Z device=isofile:
user$ growisofs -Z/dev/sr0=data.iso

dvd+rw-format
DVD+RW DVD-RW
( , ).
dvd+rw-format:
user$ dvd+rw-format /dev/sr0


.
DVD+RW . .
11,5 (
100) ! ,
, DVD, ( ).
DVD-RW dvd+rw-format
.
. DVD-RW .
DVD-RW blank,
.
VideoDVD -. growisofs . DVD
.
, growisofs
DVD-RW dvd+rw-format blank!
.
,

172

7.

, Zdevice=/dev/zero.
.

dvd+rw-mediainfo
, ,
, , ,
dvd+rw-mediainfo:
user$ dvd+rw-mediainfo /dev/sr0
INQUIRY:
[_NEC ][DVD_RW ND-1300A ][1.07]
GET [CURRENT] CONFIGURATION:
Mounted Media:
1Ah, DVD+RW
GET PERFORMANCE:
Speed Descriptor#0: 00/221280 Reading@7.8x Writing@2.3x
READ DVD STRUCTURE[#0h]:
Media Book Type:
92h, DVD+RW book [revision 2]
Media ID:
RICOHJPN/W01
Legacy lead-out at: 221280*2KB=453181440
...

7.6. ,

Linux ,
, , ,
..
, 11.4.


:
;
, ;
(rwxrwxrwx read/write/execute ,
);
.
, .
.
(r, w x) , , ( ) .
, , .
, .
, ,
ls -l.
ls :

7.6. ,

michael$ ls -l.txt
-rw-r--r-1 michael

users

3529 Oct

173

415:43 .txt

: (
, d(directory), l
(link) ..). , x-
, . , , users, ,
.
michael , users ,
, r-.
chmod.
michael$ chmod o-r.txt
michael$ ls .txt -l
-rw-r----1 michael users

3529 Oct

415:43 .txt

, .txt
: michael kathrin. ,
. michael kathrin
,
, dokuteam.
chgrp:
michael$ chgrp dokuteam .txt
michael$ ls .txt -l
-rw-r----1 michael
dokuteam

3529 Oct

415:43 .txt


rwxrwxrwx,
: ,
. 4, 2 1 r, w x
. , 660 rw-rw----, 777 rwxrwxrwx.
Setuid, Setgid Sticky 4000, 2000
1000.
chmod
, ,
:
user$ chmod 640 .txt

, ls . (, ):
user$ ls -l| awk '{k=0;
for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));
if(k)printf("%0o ",k);print}'

174

7.

755 drwxr-xr-x17 kofler kofler 40962008-10-2815:34 php53-example


550 dr-xr-x--- 2 kofler kofler 40962008-10-1710:33 Private
755 drwxr-xr-x10 kofler kofler 40962007-10-1018:17 samples


,
: r-
ls. , x-
cd. x, w, .


, , CD DVD, .., Linux
. ,
,
. , /dev/ttyS*
Ubuntu dialout:
root# ls -l/dev/ttyS1
crw-rw---1 root

dialout

5, 65 Jul 18

/dev/ttyS1


hubert , hubert
dialout:
root# usermod -a-Gdialout hubert


rwxrwxrwx . .
, .

Setuid
Setuid suid.
, . ,
( ),
, . , UID ,
.
Setuid ,
,

7.6. ,

175

. , ,
. ,
Setuid.
mount. Setuid sudo.
ls -l s( x). ( chmod)
4000.
root# ls -l/bin/mount
-rwsr-xr-x 1 root
root

68508 Feb 25

01:11

/bin/mount

Setgit
, Setuid. ,

, (
, ). ls -l s( x).
2000.
Setgid , ,
, ,
( , , ).

Sticky
, , Sticky
, ,
. , , /tmp. .
, .
ls -l t ( x). 1000. , Sticky Linux.
UNIX ( ).
user$ ls -ld /tmp/
drwxrwxrwt
18 root

root

4096 Jun 14

15:34

/tmp/

ls
ls -l
ST. , , Setuid, Setgid Sticky .
S Setuid Setgid , x(
Setuid Setgid ).
Sticky , x others.

176

7.


Linux , . ,
, , , ..
. ,
. ()
10000 x000 ( ) xxx ( ),
, , 100760. ,
, man 2 stat.

,

,
. ,
touch. ,
.
. michael myFile1. ,
michael, michael
. michael. michael ( , users).
michael$ touch myFile1
michael$ ls -lmyFile1
-rw-r--r-1 michael

michael

0 Jun 1416:45 myFile1

michael ( groups).
, ,
( newgrp):
michael$ groups
michael adm admin cdrom dokuteam dialout lpadmin plugdev sambashare
michael$ newgrp dokuteam
michael$ touch myFile2
michael$ ls -lmyFile2
-rw-r--r-1 michael
dokuteam
0 Jun 14 17:02 myFile2

, myFile2 newgrp.
chgrp. newgrp ,
, .


, . ,

7.6. ,

177

, .
.
newgrp , ,
.
Setgid (. ),
, ,
, . .


. Linux ,
rw-rw-rw ( 666),
. ,
, rwxrwxrwx (777),
.
, Linux
( ) umask-.
, ,
.
Linux umask, 022 (----w--w-). , 666-022=644 (rw-r--r--), 777-022=755 (rwxr-xr-x). umask
( ) :
michael$ umask
0022

umask
. bash (
Linux), umask /etc/profile /etc/bashrc.
~/.bashrc , .
, , , , ,
:
# ~/.bashrc
umask 027

rw-r-----,
rwxr-x---.

,
, .
( , , ).

178

7.

7.7.

(Access Control Lists, ACL). UNIX
,
.
, . , , .

, (ACL).
ACL ,
,
, ,
UNIX .
, ACL .
Linux,
2.6. . btrfs, jfs xfs
. ext, , mount acl, . . Samba
,
. ACL
, Windows, Linux.
. , ACL ,
!
,
Linux
.
,
. ,
.
, Linux
ACL. ,
ACL, .

(Konqueror ).
(EA). (Extended Attributes,
EA) .

. , , charset
utf8, . , , , -

7.7.

179

. ,
, mount-; ext
user_xattr.
man (acl, getfacl, setfacl,
attr(5), getfattr getsattr), http://www.vanemery.com/Linux/ACL/
linux-acl.html.
. , attr attr, getfattr setfattr ,
. ext4,
mount :
user$ mount
...
/dev/sdc5 on /test type ext4 (rw,acl,user_xattr)
...

,
: .
, mount /etc/fstab . 14 , . mount /etc/
fstab
(/etc/fstab) 14.5.


getfacl. , ,
,
. getfacl ACL:
user$ touch 1
user$ getfacl 1
# file: 1
# owner: kofler
# group: kofler
user::rwgroup::r-other::r-user$ ls -l1
-rw-r--r-- 1 kofler kofler ... 2

setfacl. setfacl .
gabi
docuteam ,
kathrin - :

180

7.

user$ setfacl -mgabi:rw 1


user$ setfacl -mg:docuteam:rw 1
user$ setfacl -mkathrin:- 1

getfacl . ls
ACL-. , , +, ACL.
user$ getfacl 1
# file: 1
# owner: kofler
# group: kofler
user::rwuser:gabi:rwuser:kathrin:--group::r-group:docuteam:rwmask::rwother::r-user$ ls -l1
-rw-rw-r--+ 1 kofler kofler ... 1

, , ,
. , , , .
ACL setfacl -m :rw .
ACL. , ACL.
, , ACL r,
. , ACL-
ACL.
, .
ACL setfacl , ACL.
getfacl
ls -l.
setfacl -m m:rwx
file, , , ACL. ,
, ACL.
ACL ( -n).
. . ACL ,
. , ,
, . -

7.7.

181

ACL
.
ACL. ,
ACL.
ACL cp, ACL . , OpenOffice
Gimp . cp
-p,
,
ACL.
. tar rsync ACL. CD DVD
ACL, . : -,
tar star, ACL, -,
,
ACL- .
ACL .
user$ getfacl -R--skip-base . > acl-backup ( ACL-)
user$ setfacl --restore=acl-backup ( ACL-)


setfattr getfattr. ,
setfattr getfattr.
user$ touch 2
user$ setfattr -nuser.language -vru 2
user$ setfattr --name=user.charset --value=utf8 2
user$ getfattr -d2
# file: 2
user.charset="utf8"
user.language="ru"

getfattr , user. , -n, -m.


user$ getfattr -nsecurity.selinux -dtst
# file: tst
security.selinux="user_u:object_r:user_home_t:s0^000"

. ,
,
, .. cp -p .
,
ACL
.
.

182
user$ getfattr -R. > ea-backup
user$ setfattr --restore=ea-backup

7.

( )
( )

,
( ) . , Setuid. , ,
. ,
, , -
.
. ,
.
( 2.6.24),
, (CONFIG_SECURITY_CAPABILITIES CONFIG_SECURITY_FILE_CAPABILITIES).
libcap (/lib/libcap* /lib64/libcap*).
, . ext mount user_xattr.
.
/etc/fstab.
: http://lwn.net/Articles/313047/ http://www.friedhoff.org/posixfilecaps.
html.
Getcap setcap.
getcap setcap. ( libcap-ng-utils).
.
ping Setuid-,
. , ping
(root):
root# chmod u-s/bin/ping
user$ ping yahoo.de
ping: icmp open socket:

Setuid.
setcap ping . getcap , ping.
root# setcap cap_net_raw=ep /bin/ping
root# getcap /bin/ping
/bin/ping = cap_net_raw+ep.

7.8. Linux

183

7.8. Linux
. UNIX-
. UNIX , , . Linux , (Filesystem Hierarchy Standard,
FHS). Linux . http://
www.pathname.com/fhs/.
, ,
, ( !).
FHS, ,
Linux.
. ,
, .
/bin Linux, . .
/usr/bin.
/bin /usr/bin, /bin /usr/bin
.
/boot , ( GRUB). .
/dev . , , - (,
). -
udev (. ). . .
/etc . /etc
, , /etc/X11 X- .
/etc , .
/home Linux.
, ,
( ,
/root).
/lib[64] (shared libraries) . . /lib/
modules , .

184

7.

/usr/lib[64]. /lib/firmware ( )
(, WLAN). /lib
/usr/lib. ,
/usr.
/lost+found . , -

, (fsck). : , ,
.
, fsck /lost+found.
, Linux
( , ..)
. fsck
, ,
.
/media , cdrom floppy,

.
/mnt, /media. : /run/media/username/storagename.
/opt ,

, , ,
, .
/proc ,
. ! /proc

Linux.
/root root- ( -

).
/sbin , .

, , ,
. /sbin /usr/sbin; /usr/sbin.
/share - ( ,

). /usr/share.
/srv ,
/srv/www Apache, /srv/ftp FTP- ..
/run -

, . /var/run.
/run/lock/ . /var/lock.

185

7.8. Linux


/run, . /run
, , ,
.
.
/sys 2.6 sysfs. ( proc) .
/tmp . /var/tmp.
/usr , X-,
Linux .. , .
/var.
/var .
adm ( , ), lock ( ,
, ), log ( ), mail
( , spool/mail) spool
( , ..).
, , ,
. , /usr /var .
, bin.
:
. , , , X- ..
, . , . , /usr/bin/X11 , /usr/X11R6/
bin ( ).
. .7.7
, /usr.
7.7. /usr

/usr/bin

/usr/games

/usr/share/games

/usr/include

C-Include

/usr/lib[64]

, -,
, , emacs LATEX

/usr/local

, Linux
,

186

7.
7.7 ()

/usr/sbin

/usr/share

- (, Emacs-Lisp,
Ghostscript ..), (/usr/share/doc)

/usr/src

Linux , ,

7.9. -
Linux , . ,
,
Linux.



, , ,
, (RAM) ..
, ( ) .
, Linux .
http://www.kernel.org/doc/Documentation/devices.txt.
, () : , ,
.
, (
, ) (- , ).
/dev ls -l,
( ).
b c
.
user$ ls -l/dev/sda?
brw-rw---- 1 root root 8, 12010-02-0210:39 /dev/sda1
brw-rw---- 1 root root 8, 22010-02-0210:39 /dev/sda2
...


Linux /dev
(I-Node). , .

187

7.9. -

mknod. , udev

(. ).
, 2.6, 64- ( 2.4 32- ).
( )
.
, .
: , /dev/
null (, , ,
); /dev/zero ,
, () ; /dev/random /dev/urandom
(.7.8).
7.8. -

/dev/cdrom

CD-ROM

/dev/console

/dev/disk/*

/dev/dri/*

(3D- X)

/dev/dsp*

( )

/dev/fb*

( )

/dev/hd*

IDE- ( , CD- DVD-)

/dev/input/*

/dev/kbd

(PS/2)

/dev/kmem

(RAM) ( )

/dev/lp*

..

/dev/mapper

(LVM),
..

/dev/md*

- (RAID ..)

/dev/mem

(RAM)

/dev/mixer*

/dev/psaux

PS/2

/dev/port

/dev/pts/*

UNIX 98

/dev/ptyp*

X( )

/dev/ram

/dev/raw1394

Firewire-

/dev/sd*

SCSI/SATA/USB/Firewire

/dev/scd*

CD/DVD- SCSI/SATA/USB/Firewire

/dev/shm

POSIX

/dev/snd

ALSA ( /proc/asound/dev)

/dev/scd*

CD/DVD- SCSI/SATA/USB/Firewire

188

7.
7.8 ()

/dev/tty*

/dev/ttyp*

X( )

/dev/ttyS*

(, ..)

/dev/usb/*

USB-

udev
Linux
(, Red Hat9 8000
!). , ,
.
udev,
2.6. udevd
, , .
udevd Init-V. , /etc/udev.
udev
, ,
.
udev ,
( ).
(,
), udev .
, Linux ,
udev ( )
. http://lwn.net/Articles/331818/
, devtmpfs, ,
2.6.32. , , .
hd- sd IDE- SATA/SCSI/USB/Firewire 14.2.
, Linux ,
http://www.kernel.org/doc/
Documentation/devices.txt.

, Linux .
:
(
) ;
;
;
.

8.1. ,

, , , .
. , . Linux
.
, ls, . , : , ,
.
, x.
server.tex ,
sichere . ,
, .
, sichere,
x.
user$ ls -ls*
-rw-r--r-1 kofler
-rwxr-xr-x 1 kofler

users
users

180383 Apr 2410:20 server.tex


222 Jun 610:58 sichere

( ), Linux.
: , .

190

8.

EXE-. : Linux EXE-?


: . Linux x. (executable). , Windows
EXE .
, Linux
EXE-. , #, Mono. Mono
, .NET-Framework
Microsoft.


X. X, ,
. KDE Gnome (Alt+F2), .
, . ,
(, xterm, konsole ..) .
Enter. Linux , , .
, . shell ,
PATH. ,
:
user$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

, -
, .
!
(, , ./mojaprogramma).


X , , .
.

. .
,
.
.
&:
user$ emacs &

191

8.1. ,

&, . ,
Ctrl+Z, bg:
user$ emacs
<Ctrl>+<Z>
[1]+ Stopped emacs
user$ bg
[1]+ emacs &

bg fg,
.

, .
, /dev/null. , USB-
:
root# mkfs.ext3 /dev/sdc > /dev/null &


ps. ps.

, .
ps .
.
user$
PID
1
2
3
4
...
3064
3151
3735

ps ax
TTY
?
?
?
?

STAT
S
SN
S
S<

TIME
0:00
0:00
0:00
0:00

COMMAND
init [5]
[ksoftirqd/0]
[watchdog/0]
[events/0]

pts/2
pts/2
pts/4

S
S+
S

0:39
1:23
0:00

emacs command.tex
/bin/sh ./lvauto
su -l3740 pts/4

S+

0:00

-bash

top. top ps:


, ,
, . ,
, .. , Q.
:
top - 20:50:38 up 11 days, 12:18, 1 user, load average: 0.10, 0.09, 0.08
Tasks: 114 total, 1 running, 113 sleeping, 0 stopped, 0 zombie
Cpu(s): 2.6%us, 0.2%sy, 0.0%ni, 96.8%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 4049808k total, 1580060k used, 2469748k free, 203396k buffers
Swap: 521212k total,
0k used, 521212k free, 804400k cached

192
PID
32601
32592
851
1
...

8.

USER
www-data
www-data
mysql
root

PR NI VIRT RES
SHR S%CPU %MEM TIME+ COMMAND
200
346m 32m 4296 S
5 0.80:00.15 apache2
200
344m 31m 4324 S
3 0.80:00.47 apache2
200 1403m 53m 7948 S
0 1.46:40.10 mysqld
200 243362184 1272 S
0 0.10:01.07 init

PID . , - kill.
.
R (running)1 S (sleeping2,
). ,
, T (stopped3).
top .
(K kill4) (R).
Htop. top htop, . , .
Iotop. , , ,
top iotop. -o ,
-. -u . iotop
, , ,
.
top. , top , ksysguard (KDE) gnome-systemmonitor (Gnome) (.8.1).
.
(PID),
pidof. , pidof :
root# pidof nscd
1777 1776 1775 1774 1765 1763 1753

,
.
fuser. ,
. , bash /media/dvd:
1
2
3
4

(.).
(.).
(.).
(.).

8.1. ,

root# fuser -v/media/dvd


USER
PID
/media/dvd
kofler
2183
Root Kernel

ACCESS
..c..
mount

193

COMMAND
bash
/media/dvd

.8.1. gnome-system-monitor

,
,
. , ,
( , ;
, ).
PID-. /var/run PID. ,
, . PID- Init, ,
.


PID- . , init. , .
pstree. -h
, ,
(.8.2).

194

8.

.8.2. pstree


, . , ,
Linux , ,
-
. .
Ctrl+C. .
kill. , PID ( top ps).
, 15 (kill ). , 9
( 2725):
user$ kill -92725

8.1. ,

195

kill . .
top. top:
K , .
killall. ,
, . ,
.
root# killall -9 firefox

xkill. X . xkill
, .
9.
KDE xkill Ctrl+Alt+Esc.
, xkill Esc.
. xkill , . , , top ps.
kill -9 n.
. , X-
,
- X.
. Ctrl+Alt+F1, . ,
top.
,
SSH kill . ,
, ,
sshd.
X , , , shutdown.
, Reset,
!
. ,
(, ,
), ulimit,
, ..
ulimit /etc/profile.


( )
Linux
, .
, Linux ,

196

8.

, ,

.
, .
nice,
. nice , 19 ( ) 20 ( ). 0.
,
( ,
).
user$ nice -n10 sichere

Renice. renice , . ID
( top ps).
renice man. top .
,
0, , .
Ionice. .
, , , -
, ,
ionice -.
, :
root# ionice -c3 cat /dev/vg1/snap | lzop -c> /backup/image.lzo

. Linux
,
(). ,
, .
, ,
.
. 2.6,
Native POSIX Thread Library
POSIX.

() ( )

8.2. (su)

197

( ). , ,
. ,
, xy, z:
user$ ls xy > z


. grep ,
mysql .
sort .
, (
|) rpm grep,
sort ( |).
, 6.4.
user$ rpm -qa | grep -imysql | sort
mysql-5.1.32-1.fc11.i586
mysql-connector-java-3.1.12-7.fc11.i586
...

8.2.
(su)
.
,
(, , r x).
. , , /usr/sbin , ,
.
, , . , , , (
, ). ,
, , .
. ,
. , ,
: . . , , Ubuntu, .

198

8.

, su ssh, .
sudo, ,
, Ubuntu. , 8.4 PolicyKit,
.
, ,
. Security-HOWTO
Remote-X-Mini-HOWTO, http://www.tldp.org/HOWTO/
Security-HOWTO/index.html http://www.tldp.org/HOWTO/Remote-X-Apps.html . , - .
su.
, , X
. ,
X-Shell, su name. ,
.
(xterm, konsole) ,
exit Ctrl+D.
,
, ,
,
( ) :
user$ su -lroot
Password: xxx
root# mount -text2 /test /dev/hdc7
root# <Ctrl>+<D>
logout
user$ ls /test

su
, -l! , , (, PATH), .
kdesu. KDE X
kdesu. .
user$ kdesu kate /etc/fstab

kdesu , kdesud. KDE.


kdesu kdesu -helpall. kdesu
KDE.
, , , ,
kdesu.

8.2. (su)

199

gksu. kdesu Gnome gksu.


. man gksu.
su-to-root. Debian ( Ubuntu!)
Gnome KDE
su-to-root. menu.
man su-to-root .
consolehelper. Fedora Red Hat gksu
consolehelper. ,
-. ,
/usr/sbin,
. /usr/bin consolehelper.
system-confignetwork ( Red Hat Fedora):
user$ ls -l/usr/sbin/system-config-network /usr/bin/system-config-network
-rwxr-xr-x... root root /usr/sbin/system-config-network
lrwxrwxrwx ... root root /usr/bin/system-config-network -> consolehelper

system-config-network, /usr/sbin/system-config-network. , system-config-network, consolehelper. , consolehelper


system-config-network.
ssh. su . : -,
X- DISPLAY,
, (export DISPLAY=localhost:0).
-, X
( xhost).
-, X-
.
kdesu, gksu consolehelper, ssh
:
:
user$ ssh -X-luser localhost

Setuid Setgid. Setuid Setgid


, , . sudo , setuid setgid
( sudo ). suid guid
Setuid Setgid 7.6.

200

8.

8.3.
(sudo)
sudo
su.
.
( !).
sudo ,
( ).
, ,
, . sudo
( )
/var/log/messages.
sudo 15.
sudo ,
( /etc/sudoers timestamp_timeout).
. sudo /etc/
sudoers. , , . , kathrin, uranus,
/sbin/fdisk ( ALL , kathrin
, root, news,
lp ..).
# /etc/sudoers
kathrin uranus=(ALL) /sbin/fdisk

sudoers %, .
man sudoers.

/etc/sudoers
visudo
(. !)
visudo
, ,
. , Ubuntu,
.

. kathrin fdisk . kathrin. fdisk


, PATH
kathrin. fdisk . ,
: sudo -u .

8.3. (sudo)

201

kathrin$ sudo /sbin/fdisk /dev/sda


Password: xxxxxx

Sudo .
sudo . sudoers ,
:
kofler ALL=(ALL) NOPASSWD: ALL

, ,
, .
, NOPASSWD ,
sudoers, , . , , ,
%admin ....
sudo.

sudo.
sudo-s .
. ,
Ctrl+D.
gksudo. X
gksudo .
, .
Link. /etc/sudoers , . man sudo sudoers! sudo :
http://www.courtesan.com/sudo/.

Sudo Ubuntu
Ubuntu
. .
su ssh -l root (, sudo su -l).

sudo. /etc/sudoers :
# /etc/sudoers Ubuntu
Defaults env_reset
Defaults mail_badpass
Defaults secure_path=
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
root ALL=(ALL) ALL
%admin ALL=(ALL) ALL
%sudo ALL=(ALL:ALL) ALL

Defaults env_reset
. Defaults mail_badpass
,

202

8.

. Defaults secure_path PATH sudo.


. Ubuntu ,
.
: sudo admin
.
Ubuntu sudo (, ).
,
. Ubuntu sudo
admin.
/etc/sudoers kofler
apt-get Synaptic.
, .
# /etc/sudoers Ubuntu
kofler ALL=NOPASSWD: /usr/sbin/synaptic, /usr/bin/apt-get

Sudo SUSE
SUSE sudo , Ubuntu. sudo, ,
( ).
# , /etc/sudoers
# openSUSE
Defaults always_set_home # X-
Defaults env_reset
# X-
Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE ..."
Defaults targetpw
# sudo
ALL ALL=(ALL) ALL
# ,
root ALL=(ALL) ALL


X- sudo. sudo
, #.
Defaults targetpw ,
, ( ,
). , ALL ALL=(ALL) ALL , .

8.4.
(PolicyKit)
. PolicyKit ,
:

8.4. (PolicyKit)

203

. , PolicyKit ,
. , ,
.
. , ,
(, Gnome KDE)
.
( , D-Bus).
, PolicyKit ,
. :
( ) ;
(, ,
);
(,
).
. PolicyKit. , . ,
, .
, PackageKit, PolicyKit . . , PolicyKit , ,
*.auths /var/lib/PolicyKit/. ,
, ,
PolicyKit .

Gnome: .
.
. PolicyKit :
/etc/polkit-1/* ( )
/usr/share/PolicyKit/policy/*.policy ()
/var/lib/polkit-1/* ()

,
. , Ubuntu /etc/polkit-1/
localauthority.conf.d/51-ubuntu-admin.conf admin
sudo . Fedora
wheel.

204

8.

8.5. ()
(daemons) ,
(.8.1). Init-V. Windows,
: Linux Windows.

. , (, httpd apache2 Apache).
8.1.

afpd

Apple Filing Protocol

apache2

atd

( cron)

avahi-daemon

(ZeroConf, Rendezvous, Bonjour)

bluetoothd

Bluetooth

cron

cupsd

dbus-daemon

D-BUS

dhclient

DHCP-

dhcpd

IP-

dhcpcd

IP-

gdm

Gnome

gpm

hpiod

HP

httpd

- (, Apache)

kdm

KDE

lockd

NFS-Locking

lpd

BSD-LPD

mdnsd

(ZeroConf, Rendezvous, Bonjour)

mysqld

MySQL

named

NetworkManager

nmbd

Windows/Samba

nscd

ntpd


(Network Time Protocol)

pppd

VPN-,

pptpd

PPTP- VPN

portmap

NFS-

postfix

rpc.*

RPC ( ), NFS

205

8.5. ()

sdpd

Bluetooth

sendmail

smartd

SMART

smbd

Windows/Samba

squid

sshd

SSH

rsyslogd

udevd

vsftpd

FTP-

xdm

xinetd


, httpd (Apache),
, , , ,
(threads) . ,
ps axu.
, . , kblockd/0
, kblockd/1
..

( , , ..).
.
. .8.2.
8.2.

aio

/ (,
)

events

kacpid

ACPI (
)

kblockd

khelperd

khubd

USB-

kjournald

ext3/4

knfsd

NFS-

kthread

nfsd

NFS-

kscand

206

8.
8.2 ()

kseriod

ksoftirqd

kswapd

lockd

NFS-Locking

migration

pdflush

rpciod

NFS

scsi_eh

SCSI

watchdog



Init-V. 16.
, .
, , , ,
. . ,
, .
, Debian, Ubuntu SUSE - Apache
apache2, Fedora Red Hat httpd.


, ,
. service Debian. , , Init-V.
root#
root#
root#
root#
root#
root#

service start
/etc/init.d/ start
invoke-rc.d start
rc start
start
systemctl start .service

( )
( Init-V)
( c Init-V Debian)
( c Init-V SUSE)
(Upstart, Ubuntu)
(Systemd, Fedora openSUSE)


, :
root#
root#
root#
root#
root#
root#

service stop (
/etc/init.d/ stop (
invoke-rc.d stop (
rc stop (
stop (Upstart)
systemctl stop .service (Systemd)

)
Init-V)
c Init-V Debian)
c Init-V SUSE)

207

8.5. ()

/
, . reload ,
, . ,
reload,
restart.
root#
root#
root#
root#
root#
root#

service reload/restart (
/etc/init.d/ reload/restart (
invoke-rc.d reload/restart (
rc reload/restart (
reload/restart (Upstart)
systemctl reload .service (Systemd)

)
Init-V)
Init-V Debian)
Init-V SUSE)

, ,
. (, Debian,
Ubuntu) .
, , .
Debian 6 , SUSE insserv
Init-V.
Red Hat Fedora chkconfig.
, Init-V
, (runlevel) ( 3 5).
root#
root#
root#
root#

insserv ( Init-V Debian SUSE)


chkconfig --add ( Init-V Red Hat)
chkconfig --level 35 on ( Init-V Red Hat)
systemctl enable .service (Systemd)


. , - ; stop.
root# insserv -r ( Init-V Debian SUSE)
root# chkconfig --del ( Init-V Red Hat)
root# systemctl disable .service (Systemd)

, Upstart (Ubuntu,
Fedora 9-14, RHEL 6), , .
Upstart /etc/init
.

208

8.

8.6.
(cron)
, , ,
, .., , , cron, . ,
crontab . , ,
, ,
..

Linux Cron . ,
,
, Cron . yum install vixie-cron (RHEL)
apt-get install cron (Debian/Ubuntu).

cron /etc/crontab. ,
cron,
/var/spool/cron/tabs/user.
cron
/var/spool/cron/allow /deny. allow , cron
, . /deny, .
, cron, , - , .

crontab
/etc/crontab /etc/cron.d ,
, (.8.3).
:
# in /etc/crontab

8.3. crontab

, (059)

(023)

(131)

(112)

(07, 0, 7 )

, ( )

8.6. (cron)

209

*,
. , 15**** ,
15 , ,
, . 29 0 ** 6 ,
0:29.
, , */n.
, n- (). ,
*/15**** , 15
(n:00, n:15, n:30 n:45). , , , 0
(. man 5 crontab).
/var/spool/cron/tabs/user , crontab. .
cron, /etc/
crontab /etc/cron* .
cron ,
crontab -e ( export
EDITOR=emacs, vi; , cron crontab).

cron.hourly, .daily, .weekly, .monthly


, /
etc/crontab , , /etc/cron.
hourly/*, /etc/cron.daily/* ..
Ubuntu /etc/crontab :
# /etc/crontab
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 *
* * *
root
cd / && run-parts --report /etc/cron.hourly
25 6
* * *
root
test -x /usr/sbin/anacron || \
( cd / && run-parts --report /etc/cron.daily )
47 6
* * 7
root
test -x /usr/sbin/anacron || \
( cd / && run-parts --report /etc/cron.weekly )
52 6
1 * *
root
test -x /usr/sbin/anacron || \
( cd / && run-parts --report /etc/cron.monthly )

, cron:
17 ,
/etc/cron.hourly;
6:25 /etc/cron.daily;
6:47
/etc/cron.weekly;
6:52 /etc/cron.monthly.

210

8.

Anacron, /etc/cron.daily, -.weekly


-.monthly .
, , , : /etc/cron.hourly, -.daily, -.weekly
-.monthly. execute (chmod a+x )!

cron.daily, cron.weeky cron.monthly ,


, . , runparts !
, run.daily
, run-parts --test /etc/cron.daily.

, crontab
/etc/cron.xxx, , , /etc/crontab , .
/etc/cron.d . ,
cron , !

Anacron
cron Anacron. Anacron ,
,
, .
Anacron ( ) /etc/
cron.daily, -.weekly -.monthly. cron, . Anacron
hourly cron.

, ,
Anacron
. Anacron cron /etc/cron.daily, -.weekly -.monthly
, cron, , , Anacron.
,
, !

Anacron /var/spool/
anacron. , , . Anacron /etc/anacrontab; , ,
.

,
-

Linux ,
, : GIF JPEG,
PostScript PDF, HTML , MP3 WAV ..
. - ,
, (
).

9.1.
, Linux,
: Image Magick Netpbm.
, (), ( , , ,
..). ,
,
.
Image Magick. Image Magick , convert. , .
. ,
image.png PNG:
user$ convert bild.jpg bild.png

100
(, ,
..):
user$ convert -resize 100x100 bild.jpg bild.png
user$ convert -type Grayscale bild.jpg bild.eps
user$ convert -quality 80 bild.bmp bild.jpg

212

9. , -

mogrify convert, (
):
user$ mogrify -resize 50% test.jpg

, : compare
, conjure Magick Scripting
Language (MSL). identify (, ..), import ,
montage .
user$ identify -verbose bild.png
Image: bild.png
Format: PNG (Portable Network Graphics)
Geometry: 85x100
Type: TrueColor
...

shell-, ( ) ,
, 4: 6.8.
http://www.imagemagick.org/.
Magick , Converseen:
http://converseen.sourceforge.net/.
Netpbm. , Image Magick, Netpbm ( Portable Bitmap Utilites). Pnm
Pbm. TIFF
EMS
(pnmnorm):
user$ tifftopnm bild.tif | pnmnorm | pnmtops -noturn -rle -scale 0.5 > bild.eps

http://netpbm.sourceforge.net/doc/ 200
Netpbm.
libtiff. libtiff ,
TIFF-.
bmp2tiff, gif2tiff, tiff2pdf tiff2ps.
TIFF- tiffcp, tiffinfo
tiffsplit.
libwmf. libwmf ,
WMF- EMF- ( Windows ).
wmf2eps, wmf2svg wmf2gd ( JPEG PNG).
SVG-. librsvg2 librsvg2-bin
rsvg rsvgconvert ,

213

9.2. -

SVG ( ) .
EXIF.
EXIF- JPEG, exif, exiftran exiv2.
RAW-. , ( ). dcraw .

9.2. -
.9.1 , CD - .
, (
).
9.1. -

()

CDWAV

icedax, cdparanoia

MP3WAV

mpg123, mpg321, madplay

WAVMP3

lame

OGGWAV

oggdec (vorbis-tools)

WAVOGG

oggenc (vorbis-tools)

MP3OGG

mp32ogg

AACWAV

faad

WAVAAC

faac

WAVFLAC

flac

sox

sfconvert (audiofile)

//

ffmpeg ( -, )

//

mencoder ( -, )


.
( , man _).
CD-. ,
- .
,
, cdparanoia icedax ( cdda2wav). cdparanoia
. .

214

9. , -

. 3 -, SCSI-CD. audio.wav:
root# icedax -D /dev/scd0 -t 3

4 -,
. cdda.wav :
root# cdparanoia -d /dev/scd0 "4"

MP3-. - , ,
Linux, MP3-. .
lame ( : http://lame.
sourceforge.net/).
: lame input.wav output.mp3
WAV MP3.
MP3- .
MP3OGG. , , , MP3- Ogg-Vorbis. ,
, .
user$ mpg321 -s in.mp3 -w - | oggenc - -o out.ogg

,
(ID3). , MP3Ogg-Konverter (mp32ogg http://faceprint.com/code/).
FLAC. FLAC Free Lossles Audio Codec ( ). FLAC , MP3- OGG-,
WAV-.
MP3 OGG , FLAC .
flac.
SoX. SoX Sound Exchange, sox .
, sfconvert. sox X- xsox,
Gnome- gsox.
Audio File. audiofile , SGI.
sfconvert: AIFF, AIFC, NEXT WAVE.
sfinfo , .
SoundConverter. , , , SoundConverter.
( ,
Ogg-Vorbis). -

9.3. ( )

215

, , , , (,
*.ogg).
(ffmpeg). ffmpeg - .
, ffmpeg -formats.
, , .
.
, ffmpeg
, . ffmpeg DVD-:
user$ ffmpeg -i in.avi out.mpg
user$ ffmpeg -i in.avi -y -target pal-dvd out.avi

, ffmpeg - DVD. man ffmpeg.


ffmpeg,
, ffmpeg-GUI
winff.
ffmpeg mencoder.
, MPlayer, . Mencoder
- , MPlayer.

9.3.
( )
recode, iconv, unix2dos dos2unix.

. , ,
.
recode. 1 2.
DOS- dosdat -1:
user$ recode ibmpc..latin1 < dosdat > linuxdat

recode latin1dat -1
UTF-8 (Unicode):
user$ recode latin1..u8 < latin1dat > utf8dat

iconv. recode iconv. ,


.
UTF-8 -1:
user$ iconv -f latin1 -t utf-8 latin1dat > utf8dat

216

9. , -

dos2unix, unix2dos.
, MS-DOS/Windows (CR
LF) , UNIX/Linux ( LF).
,
(, ASCII, -1),
Unicode!
user$ dos2unix .txt

9.4. ()
convmv. Linux
-1. Unicode (UTF-8).
convmv,
.
.
,
Perl http://j3e.de/linux/convmv/.
-1
UTF-8 ( , ), convmv :
user$ convmv -r -i --notest -f iso-8859-1 -t utf8 _

convmv , !
--notest: convmv , .
convmv ,
UTF-8, . --nosmart.

9.5.
(PostScript, PDF, HTML, LATEX)
, , PostScript, PDF, HTML .. .9.2
.
9.2.

TextPostScript

a2ps, enscript, mpage

HTMLText, PostScript

html2text, html2ps

PostScriptPDF

ps2pdf, epstopdf, pdf2ps, pdftops

PostScript, PDFBitmap, Druckerformat

gs

9.5. (PostScript, PDF, HTML, LATEX)

PostScriptPostScript ( ..)

psutils

PDFPDF ( / ..)

pdftk, pdfnup, pdfjoin, pdfedit

PDFText

pdftotext

LATEXDVI, PostScript, PDF

latex, dvips, dvipdf, dvipdfm

217

TextPostScript
lpr ,
.
, ,
PostScript
. , , a2ps,
enscript mpage. ,
.
a2ps. Any to (- PostScript)
PostScript, , . .
, - ( Unicode)!

.
user$ a2ps text.txt -o postscript.ps

. a2ps
, (
, ..).
user$ a2ps 1.c 2.c 3.h -4 -o postscript.ps

enscript. PostScript, HTML


RTF. -1.
4 :
user$ enscript -M A4 --landscape -3 text.txt -p postscript.ps

mpage.
PostScript, . 4 , :
user$ mpage -2 -bA4 text.txt > postscript.ps

Unicode. ,
Unicode (UTF-8). Unicode, , .

218

9. , -

PostScript,
cnprint: http://www.neurophys.wisc.edu/~cai/software.

HTMLText, PostScript
html2text. HTML- .
, HTML- ,
.
user$ html2text .html > text.txt

html2text -1 ( Unicode!). , /etc/html2textrc


~/.html2textrc (. man html2textrc).
HTML
, , Lynx, ELinks w3m.
html2ps. HTML
PostScript Perl html2ps.
: html2ps -D .html > .ps. -D PostScript
DSC-1 ,
.

PostScriptPDF
ps2pdf. ps2pdf .ps .pdf
PostScript PDF. , , Adobe Distiller. Ghostscript
(gs).
, PDF1.2
Acrobat Reader 3.n. , ,
, , . PDF, ps2pdf12,
ps2pdf13 ps2pdf14.
PDF , PostScript. , , - . ps2pdf
. http://www.cs.wisc.edu/
~ghost/doc/cvs/Ps2pdf.htm.
epstopdf. EPS
PDF, epstopdf. EPS Encapsulated
PostScript ( PostScript) ,

. EPS (, LATEX OpenOffice).
1

DSC (Document Structuring Conventions).

9.5. (PostScript, PDF, HTML, LATEX)

219

epstopdf tetex, TEX, LATEX


TEX- . ps2pdf, epstopdf
. , epstopdf PDF
, EPS, (
--nocompress).
pdf2ps pdftops. pdf2ps .pdf .ps , ps2pdf; pdf2ps gs.
pdftops , , , pdf2ps,
,
PostScript. ,
PostScript, ..

PostScript/PDF /

gs. , Ghostscript, PostScript PDF . Ghostscript
Linux (, CUPS),
PostScript , . ,
PostScript.
gs , , , ghostscript-fonts.
, PostScript
.
Ghostscript. Linux
GNU Ghostscript ESP Ghostscript. GPL. ESP Ghostscript
CUPS. ESP , Easy Software
Products.
, Ghostscript, Artifex Ghost
script, , , .
:
http://www.ghostscript.com/;
http://www.artifex.com/.
(Gutenprint). Ghostscript
.
Ghostscript.
Gutenprint ( Gimp-Print). http://gimp-print.sourceforge.net/.
HPLIP (HP Linux Imaging and Printing).
Hewlett-Packard . HPLIP
Ghostscript CUPS.

220

9. , -

. Ghostscript , gs .
gs , :
-sOutputFile= , , -sDEVICE=
@.upp . ,
-dNOPAUSE. DIN-A4,
-sPAPERSIZE=a4.
test.ps HP-Laserjet3. out.hp:
user$ gs -sDEVICE=ljet3 -sOutputFile=out.hp -sPAPERSIZE=a4 -dNOPAUSE -dBATCH test.ps

PostScript PDF (ps2pdf


, gs):
user$ gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf test.ps

, , , EPS PNG:
user$ gs -dNOPAUSE -dBATCH -sDEVICE=png16m -sOutputFile=out.png \
-dEPSCrop -r100 bild.eps

PostScript
psutils. PostScript
psutils (.9.3). ,
bash Perl.
9.3. psutils

epsffit

EPS-

extractres

%%
IncludeResource
, ..

fixfmps

FrameMaker psutils

fixmacps

Macintosh psutils

fixscribeps

Scribe psutils

fixtpps

Troff/Tpscript psutils

fixwfwps

Microsoft Word psutils

fixwpps

WordPerfect psutils

fixwwps

Microsoft Write psutils

getafm

AFM

includeres

, extractres, PostScript

psbook

,
16

psnup

psresize

.
, PostScript,
,

9.5. (PostScript, PDF, HTML, LATEX)

psselect

PostScript

pstops

221

, PostScript
, LATEX DVIPS 64
. , .
( Microsoft
Word ):
user$ psnup -b-0.4cm -64 -q < linux.ps > preview.ps

, ,
PostScript DSC- (
, DSC ).
, ,
, .. EPS PostScript, ,
( , , ).
PS. PostScript,
Ghostscript gs. , , .
user$ gs -sDEVICE=pswrite -sOutputFile=out.ps -dNOPAUSE -dBATCH in1.ps in2.ps ...

PDF
pdftk. ( PDF) PDF, , psutils PostScript. ,
PDF-, PDF ( , ), PDF- ..

http://www.accesspdf.com/pdftk/.
1020 3040 in.pdf out.pdf:
user$ pdftk in.pdf cat 10-20 30-40 output out.pdf

PDF, cat:
user$ pdftk in1.pdf in2.pdf in3.pdf cat output out.pdf

in.pdf PDF pg_n, n .


, output
(), printf, output page-%02d.pdf:
user$ pdftk in.pdf burst

222

9. , -

PDF-.
xxx, .
, owner_pw user_pw.
user$ pdftk in.pdf output encrpyted.pdf owner_pw xxx

Poppler. , PDF (Text, Bitmap, PostScript ..). Poppler Linux


, PDF. poppler-utils.
xpdf-utils. pdftops ( PDF PostScript), pdfinfo ( PDF), pdfimages ( PDF) pdftotext ( PDF).
pdfedit.
, PDF.
pdfjam. pdfnup, pdfjoin pdf90.
PDF.
GUI.
,
, Java.
PDFedit, , , PDF-Shuffler,
Bookbinder, JPDF Tweak, PDF Split Merge (PDF Sam).

LATEX
LATEX () . ,
LATEX (*.tex) ,
LATEX .
latex. latex .tex LATEX DVI.
, -
- .
dvips. DVI ,
xdvi kdvi. dvips DVI
PostScript. .
user$ dvips [] -o .dvi .ps

dvipdf. LATEX
PDF. .
dvips PostScript, PDF ps2pdf Adobe Distiller (Adobe Distiller
Adobe Acrobat, , ,
Linux).
DVI PDF dvipdf dvipdfm.
dvipdf , , PostScript.

9.5. (PostScript, PDF, HTML, LATEX)

223

PDF, ,
PostScript. PDF (
, ),
, LATEX:
dvips/ps2pdf dvipdf PDF LATEX hyperref;
dvipdfm \special
LATEX;
PDFTEx LATEX, PDF.

10

, . , ssh
, wget
rsync ..

10.1.
, . 18.3, ,
.


ifconfig . ethn (Ethernet) pppn (
, ADSL VPN). lo: . ,
.
:
root#
eth0

lo

ifconfig
Link encap:Ethernet Hardware Address 00:11:25:32:4F:5D
inet Address:192.168.0.15 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 Address: fe80::211:25ff:fe32:4f5d/64 Scope:Connection
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11416 errors:0 dropped:0 overruns:0 frame:0
TX packets:10415 errors:0 dropped:0 overruns:0 carrier:0
Collisions:0 transmit queue:1000
RX bytes:9600456 (9.1 MiB) TX bytes:2269502 (2.1 MiB)
Base address:0x8000 memory:c0220000-c0240000
Link encap:local loop
inet Address:127.0.0.1 Mask:255.0.0.0

10.1.

225

inet6 Address: ::1/128 Scope:Machine


...
RX bytes:6139586 (5.8 MiB) TX bytes:6139586 (5.8 MiB)

, , . ,
.
, , : ifconfig eth0 192.168.0.2. eth0: unknown interface: No such device, ,
.

localhost
ping
. , (
). ,
trl+C. localhost
,
.
user$ ping localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=0.152 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=255 time=0.114 ms
...


ping localhost, IP- , , , . -c 2 , ping , .
user$ ping -c 2 192.168.0.99
PING 192.168.0.99 (192.168.0.99): 56 data bytes
64 bytes from 192.168.0.99: icmp_seq=0 ttl=255 time=0.274 ms
64 bytes from 192.168.0.99: icmp_seq=1 ttl=255 time=0.150 ms
...

, IP-
192.168.0.99 ( /etc/hosts),
ping IP-, .
user$ ping -c
PING mars.sol
64 bytes from
64 bytes from

2 mars
(192.168.0.10) 56(84) bytes of data.
mars.sol (192.168.0.10): icmp_seq=1 ttl=64 time=0.281 ms
mars.sol (192.168.0.10): icmp_seq=2 ttl=64 time=0.287 ms

--- mars.sol ping statistics --2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.281/0.284/0.287/0.003 ms

226

10.


, . :
.
user$ ping -c 2 www.yahoo.com
PING www.yahoo-ht2.akadns.net (209.73.186.238) 56(84) bytes of data.
64 bytes from f1.www.vip.re3.yahoo.com (209.73.186.238): icmp_seq=1 time=122 ms
64 bytes from f1.www.vip.re3.yahoo.com (209.73.186.238): icmp_seq=2 time=123 ms
--- www.yahoo-ht2.akadns.net ping statistics --2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 122.731/123.256/123.782/0.631 ms

, .
, Yahoo!
ping.

-.
, ping: unknown
host yahoo.com. , /etc/resolv.conf
.
, : connect:
Network is unreachable. route -n.
, Gateway IP- :
root# route -n
Kernel IP routing table
Destination Gateway
Genmask
192.168.0.0 0.0.0.0
255.255.255.0
127.0.0.0
0.0.0.0
255.0.0.0
0.0.0.0
192.168.0.10 0.0.0.0

Flags
U
U
UG

Metric
0
0
0

Ref
0
0
0

Use
0
0
0

Iface
eth0
lo
eth0

, -

, .
.
19.

IP-
traceroute , . . ,
, UDP33434, traceroute.

.

227

10.2. (SSH)


google.at. - ( mars.sol), 2

ADSL, 3 -. 9,
Google.
user$ traceroute google.at
traceroute to google.at (66.102.9.104), 30 hops max, 40 byte packets
1 mars.sol.0.168.192.in-addr.arpa (192.168.0.1) 0.277 ms 0.194 ms 0.216 ms
2 192.168.1.1 (192.168.1.1) 0.373 ms 0.367 ms 0.690 ms
3 N704P030.adsl.highway.telekom.at (62.47.31.254) 8.598 ms 8.500 ms 11.593 ms
4 172.19.90.193 (172.19.90.193) 11.864 ms 8.837 ms 7.986 ms
...
14 66.102.9.104 (66.102.9.104) 52.741 ms 53.306 ms 51.996 ms

mtr. mtr
. ,
ping traceroute. ,
: GTK-
. Debian Ubuntu GTK-.
, apt-get install mtr-tiny.
user$ mtr -c 10 -r google.de
HOST: michaels-computer Loss% Snt Last
1.|-- speedtouch.lan 0.0% 10 42.6
2.|-- 178-191-207-254.adsl.high 0.0% 10
3.|-- 195.3.74.129 0.0% 10 19.4
4.|-- AUX10-GRAZBC10.highway.te 0.0% 10
5.|-- 195.3.70.154 0.0% 10 21.2
6.|-- 62.47.120.150 0.0% 10 25.3
7.|-- 209.85.243.119 0.0% 10 25.6
8.|-- 216.239.46.88 0.0% 10 25.8
9.|-- bud01s08-in-f23.1e100.net 0.0% 10

Avg Best Wrst StDev


48.5 6.0 95.9 28.9
18.9 20.4 18.6 23.2 1.9
18.8 17.9 19.4 0.5
21.2 21.3 20.7 22.0 0.3
27.3 20.9 81.2 18.9
25.5 24.9 26.0 0.4
25.9 25.2 28.2 0.8
26.3 25.8 27.7 0.6
25.7 25.8 25.0 26.8 0.5

gnome-nettool. Gnome,

gnome-nettool

10.2. (SSH)
telnet, rlogin ssh , . - , X-. ssh ( ).
telnet rlogin ,
, ,
.

228

10.

ssh ,
SSH, sshd.
Linux , ( openssh-server). ,
22.

, SSH-
22. ,
SSH- .

shell-
uranus shell-
mars, , :
user@uranus$ ssh mars
user@mars's password: ********

,
:
The authenticity of host 'mars (192.168.0.10)' can't be established.
RSA1 key fingerprint is 1e:0e:15:ad:6f:64:88:60:ec:21:f1:4b:b7:68:f4:32.
Are you sure you want to continue connecting (yes/no)? {\bfs yes}
Warning: Permanently added 'mars,192.168.0.10' (RSA1) to the list
of known hosts.

, ssh ,
mars IP- 192.168.0.10. , mars.
YES, ssh ,
RSA ( ) ~/.ssh/
known_hosts.
mars ,
uranus (, ), -l:
user@uranus$ ssh -l root mars
root@mars's password: xxx

, .
22. , SSH

, (, ).


ssh , - .
ssh . ssh .

10.2. (SSH)

229

user@uranus$ ssh mars


user@mars's password: xxx

, , : , , tar,
( -f),
|
tar, . , SSH .
, htdocs
- kofler.cc ~/bak:
user$ ssh -l username kofler.cc tar -cf - htdocs | tar -xC ~/bak/ -f username@kofler.cc's password: ******

SSH X
SSH X.
, , . X- , , .
X-, -X ( /etc/
ssh_config ForwardX11 yes, -X ).
ssh DISPLAY.
mars XEmacs.
uranus,
! , mars X- ( 3).
X-!
user@uranus$ ssh -X mars
user@mars's password: xxx
user@mars$ xemacs &

scp
SSH scp. :
user$ scp [[user1@]host1:]_1 [[user2@]host2:][_2]
user2@host2's password: ******

, _1 host1
host2, _2.
:
host1 host2 ,
( localhost);
user1, ;

230

10.

user2, host2
host1 user1;
_1 ; -r, ;
_2 , ;
user2.

_2 , , ,
~ user2.
: , gabi
uranus. abc.txt ~/efg
mars. scp :
gabi@uranus$ scp abc.txt mars:~/efg/
gabi@mars's password: ******

SFTP (Secure FTP) SSH


FTP. SFTP ,
FTP HTTP.

SSH-
Linux SSH . , ,
IP-, .
SSH , IP- , , .
, -L
localport:remotehost:remoteport. ,
3306 mars 3307 .
SSH-, -N ( ,
). mars
, : -l name
: name@remotehost.
user@uranus$ ssh -L 3307:localhost:3306 username@mars
user@mars's password: ******

, SSH-,
Ctrl+D. ssh -N, Ctrl+.

, MySQL 3306.
uranus MySQL, mars,
3307 uranus. mysql 3307
127.0.0.1, SSH- ( MySQL -).

10.3. (FTP)

231

user@uranus$ mysql -u mysqllogin -P 3307 -h 127.0.0.1 -p


Enter password: *******

MySQL ,
. MySQL IP-, mars. ( MySQL-
, -. , .) - , ssh
mars ( mars.sol,
sol, ).
SSH- . , . http://www.tldp.org/
HOWTO/VPN-HOWTO/.

SSH
sshfs, ,
. , , . , -
SSH , , ,
Samba NFS. SSH .
root#
root#
root#
root#

mkdir /media/ext-host
sshfs user@hostname /media/ext-host
...
umount /media/ext-host

10.3. (FTP)
FTP
FTP File Transfer Protocol ( ).
. FTP Anonymous FTP ( FTP-): FTP-.
( FTP).
FTP ,
.
SFTP (Secure FTP), SSH.
FTP HTTP, .

232

10.

FTP, . FTP , FTP-. 23.7.

FTP
FTP- ftp. ,
ftp cd.
FTP-, ftp _@ftp-
ftp ftp-. FTP, anonymous.
, : cd, pwd
ls, , Linux, FTP-. FTP- , get . .
: put
FTP-. , ,
.
FTP /pub/
incoming. FTP- quit bye. FTP .10.1.
10.1. FTP

FTP

ascii

binary

bye

FTP

cd dir

FTP

close

FTP

get file

FTP

help

lcd dir

ls

, FTP-

lls

mget *.pattern

, , FTP-

open

(
)

prompt

/ mget

put

FTP- (upload)

quit

FTP

10.3. (FTP)

reget

user

233

, binary.
FTP
. ( , FTP- binary
).

, Linux FTP-:
user$ cd ~/src
user$ ftp ftp.kernel.org
Connected to zeus-pub.kernel.org.
220 Welcome to ftp.kernel.org.
Name (ftp.kernel.org:kofler): anonymous
331 Please specify the password.
Password: name@mysite.de
Using binary mode to transfer files.
ftp> cd pub/linux/kernel/v3.0
250 Directory successfully changed.
ftp> ls
...
ftp> get linux-3.5.tar.bz2
local: linux-3.5.tar.bz2 remote: linux-3.5.tar.bz2
227 Entering Passive Mode (204,152,191,5,20,69)
150 Opening BINARY mode data connection for linux-3.5.tar.bz2 (69305709 bytes).
...
ftp> quit

FTP
ftp . ,
.
, , Linux, FTP. (, Nautilus Konqueror).
FTP- , gftp (Gnome), FTP-. ,
,
, ..
ncftp
, , ftp.
sftp , ftp,
.
SSH- ( FTP-).

234

10.

wget, curl, lftp, rsync, mirror sitecopy -

FTP.

FTP-
FTP anonymous,
,
FTP :
ftp://_:@_

. FTP- ,
FTP-
,
. . , , ( ).

SFTP
sftp openssh. sftp
, ftp, ssh
, SSH-.
FTP sftp . , ftp. sftp -b batch- SFTP-.
SFTP. sftp . SFTP- ,
FTP. , , .
gftp SFTP
(FTPOptionsSSH (FTPSSH)). , , ( SSH 22, 21, FTP).
Use SSH2 SFTP Functions (
SSH2 SFTP).
KDE Konqueror Nautilus SFTP-
, sftp://@_.
Konqueror .
SSH-,
sftp.
: fish://@_.

WGET
,
, . , ftp .

10.3. (FTP)

235

, .
wget,
.
FTP, HTTP HTTPS.
. wget :
user$ wget ftp://myftpserver.de/.abc

- , -c:
user$ wget -c ftp://myftpserver.de/.abc

,
Linux, ,
. ,
, . -t 20 20 , ,
20 . --retry-connrefused
connection refused ( ) . ,
.
user$ wget -t 20 --retry-connrefused http://mydownloadserver.de/.iso

, ,
, . : -p ; -k , , ,
; -E
(ASP, PHP) HTML; -H
.
user$ wget -p -k -E -H http://mysite.com/site.html

- , ( -r).
-l 4 .
user$ wget -r -l 4 -p -E -k http://mysite.com

curl
curl FTP, HTTP
. man , curl.
FTP. curl, . ,

236

10.

*.tar.gz,
FTP-; ,
.
FTP- backupserver dir:
user$ curl -T -u _: ftp://backupserver/dir

-T
. , tar, name.tgz FTP-:
user$ tar czf - dir/ | curl -T - -u usern:pw ftp://bserver/.tgz

lftp
lftp FTP-. , FTP-
. lftp -c, FTP-, , -f, ,
.
user _, _, FTP. :
root# lftp -c "open -u _, backupserver; put www.tgz"

, FTP-, -o _. lftp
.

mirror -R. , mirror FTP- . -R .
:
root# lftp -c "open -u usern,passw bserver; mirror -R directory"

FTP-, lftp du,


,
. , . ,
,
. -s , . -m , .
user$ lftp -c "open -u _, bserver; du -s -m"
2378 .

,
( , , -

10.3. (FTP)

237

) . cut -f 1,
:
user$ lftp -c "open -u usern,passw bserver; du -s -m" | cut -f 1
2378

rsync, mirror, sitecopy


rsync . 25.4. SSH-, rsync-, rsync
mirror sitecopy. mirror, Perl , FTP-
. sitecopy, , ,
-.
FTP WebDAV,

11

Linux
. :
;
;
;
, , Unicode;
;
().
,
, (X), , (GRUB, Init-V, Upstart), .

11.1.
, Linux. , ,
, . ,
.
, -,
, . .

. , -.
.
, ,
,
Red Hat, SUSE .. ,
. ,
, ..

239

11.1.

,
.

?
, , , ,
. ,
- , , :
- , .
Linux , :
!
: ,
. Linux,
. ,
Linux, .

, , : drakconf
Mandriva, system-xxx Red Hat Fedora, YaST
SUSE ..
!
.
, , . ,
Linux .
.11.1 .
, , .
Linux . ,

, . ( ,
.)
11.1.

http://webmin.com/

http://fai-project.org/

240

11.
11.1 ()

http://m23.sourceforge.net/

http://directory.fedoraproject.org/

RHEL/
Fedora, LDAP

https://oss.gonicus.de/labs/gosa/


Debian LDAP

http://redhat.com/rhn/

Red Hat

http://novell.com/zenworks/

Novell/SUSE

http://canonical.com/landscape/

Ubuntu

http://univention.de/produkte/ucs/

http://zentyal.org/


( eBox)

http://cpanel.net/

http://parallels.com/plesk/

. , ,
. !


,
Linux.
Linux.
, , ,
Linux.
,
, SSH.
, Linux,
Linux.
.
,
.
(
) .
. ,

11.1.

241

, Linux ..

, Linux
, .
Linux /etc.

. , X /etc/X11. :
/etc/default , (Debian,
Ubuntu);
/etc/init.d /etc/rc.d Init-V ( , .16);
/etc/init Upstart (. 16);
/etc/init Systemd (. 16);
/etc/sysconfig , (Fedora,
Red Hat, SUSE).
/etc. ,
.
root# mkdir /etc-backup
root# cp -a /etc/* /etc-backup

, Enter. , Linux
.

. - , :
, - .
locate, find grep. ,
,
abcde, /etc :
root# cd /etc
root# find -type f -exec grep -q abcde {} \; -print

, , y z. .
, grepall, .
. , ,

242

11.

,
.
:
root#
root#
root#
)
root#

/etc/init.d/funktionsname restart (Debian 6, )


/etc/init.d/funktionsname reload
service funktionsname restart ( service funktionsname reload

Windows, Linux
. ,
- , .

11.2.
Linux , , . ,
X
- .
.
.
, , kbd console . .


Debian, Ubuntu. Debian Ubuntu
console-setup. /etc/default/console-setup , /etc/default/keyboard .
, X:
# /etc/default/console-setup
...
#
CHARMAP="UTF-8"
CODESET="Lat15"
FONTFACE="VGA"
FONTSIZE="16"
# /etc/default/keyboard
#
XKBMODEL="pc105"
XKBLAYOUT="de"
XKBVARIANT=""
XKBOPTIONS="lv3:ralt_switch"

11.2.

243

Debian /bin/setupcon,
Init-V /etc/init.d/keyboard-setup.
Ubuntu console-setup udev ( /lib/udev/console-setup-tty).
Upstart (/etc/init/console-setup.conf).
/etc/ default/keyboard, /etc/console-setup/cached.kmap.
gz. Initrd, /usr/bin/ckbcomp.
Debian, Ubuntu : , :
root# dpkg-reconfigure keyboard-configuration

,
.
Fedora. Fedora kbd.
Initrd.
/etc/sysconfig/
keyboard:
# /etc/sysconfig/keyboard
KEYTABLE="de-latin1-nodeadkeys"
MODEL="pc105"
LAYOUT="de"
VARIANT="nodeadkeys"

, , ,
Initrd , dracut.
root# dracut -f

, /etc/sysconfig/keyboard
fedora-setup-keyboard X. X 5 /etc/sysconfig/keyboard.
/etc/X11/ xorg.conf.d/00-system-setupkeyboard.conf.
SUSE. SUSE, Fedora, kbd
/etc/sysconfig/keyboard. .
Init-V /etc/init.d/kbd.
, X.


, Unicode.
(256
512), Unicode.
Debian, Ubuntu. /etc/default/
console-setup setupcon. Debian

244

11.

Init-V /etc/init.d/console-setup, Ubuntu


Upstart /etc/init/console-setup.conf.
Fedora. Fedora setfont
Initrd, /etc/sysconfig/
i18n. , ,
Initrd
SUSE. SUSE /etc/init.d/kbd.
/etc/sysconfig/console
setfont. lat9w-16.psfu,
-1 .

Gpm- ()
X Window System. gpm
:
,
, . ,

.
gpm , , ,
Init. , ,
/etc/gpm.conf /etc/sysconfig/mouse,
, .

11.3.
, . GMT
(Greenwich Mean Time, ). UNIX . UTC (Universal Time, Coordinated, ).
, .
ls -l,
, . ,
: , 18:00 ,
, 12:30 -, .
. Init-V . hwclock CMOS . CMOS
, GMT. Windows,
CMOS .
Red Hat, Fedora SUSE /etc/sysconfig/clock , CMOS

11.3.

245

GMT . Debian Ubuntu


/etc/default/rcS , CMOS, /etc/timezone.
. ls
KDE Gnome GMT
, , .
Linux glibc. /etc/localtime,
(time zone file) /usr/share/zoneinfo. localtime
.
, /etc/
localtime:
root# cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime

Debian Ubuntu /etc/timezone.


glibc,
, localtime.
.
:
Gnome 2.n time-admin;
Gnome 3.n ;
KDE /;
Debian, Ubuntu tzconfig, Gnome/KDE;
Red Hat/Fedora system-config-date;
SUSE YaST- .

NTP ( )
CMOS- ,
, .
(Network Time Protocol, NTP).
NTP.
ntpdate
. ,
, .
,
, . .
ntpd,

. ntpd
(, ,
).

246

11.

ntpd, ntpdate ,
. Ntpd
,
.
NTP (ntpdate, ntpd) Chrony
( ). Chrony NTP
Fedora 16 .

, . , , Kerberos, POP3- IMAP Dovecot, . ntpdate


. Dovecot
, , .

. Linux
: http://www.ntp.org/; http://tldp.org/HOWTO/TimePrecision-HOWTO/.
Debian, Ubuntu. , ntpdate ntpd
, . Debian Ubuntu ntpdate , ( /etc/network/if-up.d/ntpdate).
ntpd,
ntp. , /etc/ntp.conf ,
NTP-.
ntpq -p , ntpd .
offset.
( ).
. ntpq p , ,
ntpd - ( ).
, ntpd , , . ,
.
root# ntpq -p
remote refid st t when poll reach delay offset jitter
======================================================================
europium.canoni ... 2 u 2 64 1 21.565 -117.64 0.002
www.alter-provi ... 2 u 1 64 1 20.436 -118.56 0.002

( offset
1000),
ntpdate:
root# service ntp stop
root# ntpdate de.pool.ntp.org
root# service ntp start

11.4. ,

247

Red Hat
RHEL 6 NTP system-config-date. NTP, ntpd. ntpq -p , . ,
ntpd ntpdate.

SUSE
SUSE NTP . YaST- SYSTEM
Date and Time ( )
NTP ( Change ()). ntpdate.
NTP-, YaST- Network ServicesNTP Setting ( NTP) Start NTP now and by booting
( NTP ). ,
. ( , .) Ntpd Init-V ntp.

Chrony
Fedora 16 NTP-
Chrony. ,

. /etc/chrony.conf.
, :
root# service chronyd restart

Chrony
: http://chrony.tuxfamily.org/.

11.4. ,
,
, , , ..
, . ,
.
Linux . ,
, , ,
.
.

248

11.

,
,
. ,
, .


, ,
.
, :
Gnome 2.n users-admin ( gnome-system-tools);
Gnome 3.n ;
KDE ;
Debian, Ubuntu Gnome KDE;
Red Hat, Fedora system-config-users (.11.1);
SUSE YaST .

.11.1. Fedora

11.4. ,

249


, , .11.2 , testuser
.
root# useradd -m testuser
root# passwd testuser
New passwd: xxx
Re-enter new passwd: xxx
11.2.

adduser

(Debian)

addgroup

(Debian)

chgrp

chmod

chown

chsh

delgroup

(Debian)

deluser

(Debian)

groupadd

groupdel

groupmod

groups

id

ID-

newgrp

newusers

passwd

useradd

userdel

usermod

, , ,
(, adduser useradd). adduser, addgroup,
deluser delgroup Debian
useradd, groupadd .. Debian, Ubuntu , Debian, , /etc/
adduser.conf /etc/deluser.conf.
, Red Hat Fedora :
adduser, addgroup, deluser delgroup.
, Debian,
useradd, groupadd, userdel groupdel.
adduser useradd Fedora adduser
Debian!

250

11.

SUSE/Novell : adduser/-group
deluser/-group. groupadd/-del/-mod useradd/-del/-mod
,
, .


Linux UNIX .
, , root.
root.
root (, ),
: , ,
, .. .
.
. Linux .
.
(, kathrin hofer).
. , ,

. , -
Apache , , apache, wwwrun
httpd ..
.

/etc/passwd
/etc/passwd. : , , (UID GID), . :
::UID:GID:: :

, Ubuntu Linux ( /etc/passwd):


root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
...

11.4. ,

251

kofler:x:1000:1000:Michael Kofler,,,:/home/kofler:/bin/bash
huber:x:1001:1001:Herbert Huber,,,:/home/huber:/bin/bash

passwd , . , .
/etc/passwd x. (,
, ), /etc/shadow (.
).

( )
( US-ASCII) .
, ,
, , . , .

UID GID
UID ( ) .
, , .
UID:
UID=0.
1 999 ( Red Hat Fedora,

1 499). ,
, 1000 ( RHEL 6 Fedora 15,
: 1 499, ID 500
).
GID ( ) ,
.


, .
, , /home/login-name.

. ,
.emacs Emacs.
, .
, ls -la.

,
/etc/skel . , , . ,
/etc/skel.

252

11.

, , ,
. Linux ,
passwd , .
Linux bash, 6
( passwd , ,
, /bin/bash).


,
.
(initial group). ,
(supplementary groups), .
/etc/group . ,
/etc/group.
:
_::_:_

group Ubuntu:
root:x:0:
daemon:x:1:
bin:x:2:
...
dialout:x:20:cupsys,kofler,huber
...
users:x:100:
admin:x:114:kofler
...
kofler:x:1000:
huber:x:1001:
...

.
/etc/passwd.
kofler kofler (
1000 /etc/passwd).
,
/etc/group. , kofler adm, admin dialout. kofler

Ubuntu .
0 , 1 99 . GID=100

11.4. ,

253

users. GID 100


.
.
.
, UNIX/Linux ,
users. -

, , SUSE.
, Debian, Red Hat Fedora, -

:
. kofler huber
. users .
, .
.
Linux,
,
, CVS ( ). , .

Linux ASCII (
!). , , ;
, .
Linux -, , . - SHA512 (.
ENCRYPT_METHOD /etc/login.defs).
( , !).
( )
: ,
.
, ,
.
, Linux
- /etc/passwd,
/etc/shadow. ,
. ( /etc/passwd /etc/group
,

254

11.

. /etc/shadow .

-.)
shadow :
:-:d1:d2:d3:d4:d5:d6:reserved

:
root:$6$Ecrkix...:14391:0:99999:7:::
daemon:*:14391:0:99999:7:::
bin:*:14391:0:99999:7:::
...
kofler:$6$TZR7...:14391:0:99999:7:::

d1-d6
d1-d6 :
d1 , (

, 01.01.1970);
d2 , ;
d3 , ,

(
man 5 shadow);
d4 ,

;
d5 , -

;
d6 , .

, d1-d3 ,
. d1-d6 , , (,
).
( ,
daemon, bin, sys ..), . , . : ,
,
bin, daemon, lp ..
:
, .

11.4. ,

255

/etc/login.defs
, , /etc/login.defs.
,
, , ..
passwd .


, passwd.
, . . , .
.
. , .
passwd . . ,
( ), .
, .
root# passwd hofer
New password: ******
Re-enter new password: ******
Password changed.


, ?
(, Knoppix). mkdir
, Linux:
root# mount -t ext4 /dev/xxx /dir

dir/etc/shadow,
( )
.
, ,
/etc/pam.d/commonauth
. , ,
passwd, X
root.
,
, BIOS

256

11.

, .
.
.

faillog
/etc/login.defs /var/log/
faillog. , .
faillog -u ,
.
, faillog
-u -r ( ).
,
faillog -m max. ,
faillog -u root -m 0, . ,
,
.


,
( gpasswd). , . , , .
,
/etc/gshadow. , newgrp
( , ).


, passwd, groups shadow. passwd ,
:
# /etc/passwd
kofler:x:1000:1000:Michael Kofler:/home/kofler:/bin/bash

kofler ; 1000 ;
1000 ; Michael Kofler
( , ..); /home/kofler
, /bin/bash .
, .
/etc/shadow :

11.4. ,

257

# /etc/shadow
kofler:$6$9dkO$...:13479:0:99999:7:::

kofler: .
, ,
. * !, .
GID /etc/passwd /etc/group.
:
# /etc/group
kofler:x:1000:


Linux
NFS, , UID GID
.
.
, (,
), /etc/passwd.
.
, . , () ,
:
LDAP ;
NIS , ;
Kerberos;
Samba Windows.

(PAM)
(Pluggable Authentication Modules, PAM)
, .
Linux, (su,
sudo, ssh ..) (passwd),
PAM. CPAM Cron PolicyKit. , PAM
: http://www.kernel.org/pub/linux/libs/pam/.
Linux /etc/passwd , /etc/shadow .
PAM ,
.

258

11.


(, LDAP), PAM
. :
Fedora system-config-authentication;
SUSE YaST- ;
Ubuntu pam-auth-update.
pam.conf. /etc/pam.d/.
, /etc/pam.conf.
.
():
PAM- [ ]

, pam.conf (, login other ). /etc/pam.d


.
( ). PAM (
). (Debian, Ubuntu) common-account,
common-auth, common-password common-session
:
account , , , (, )
..;
auth ( ) (, );
password ;
session
(, , /
, ..).
( ).
, PAM,
. : (, required, requisite)
/ ( [success=1 new_authtok_reqd=done
default=ignore]). .11.3.
11.3. PAM

requisite

PAM

required


PAM
; ,

11.4. ,

259

sufficient

,
PAM
(
requisite); .
PAM

optional

,

(, su)


[1=1 2=2 ...].
value ,
; result , , , , PAM (ignore, bad, die, ok, done reset).
,
:
requisite
required
sufficient
optional

=
=
=
=

[success=ok new_authtok_reqd=ok ignore=ignore default=die]


[success=ok new_authtok_reqd=ok ignore=ignore default=bad]
[success=done new_authtok_reqd=done default=ignore]
[success=ok new_authtok_reqd=ok default=ignore]

( ).
PAM, .
. ,
, , .
pam_unix.so
/etc/passwd /etc/shadow. nullok ; nullok_secure , , /etc/securetty (
/dev/ttyn). obscure
, , . md5 , .
.
Fedora17.
, (, common-xxx Debian Ubuntu).
# /etc/pam.d/password-auth (Fedora)
auth required pam_env.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 1000 quiet_success
auth required pam_deny.so
account required pam_unix.so
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 1000 quiet
account required pam_permit.so

260

11.

password requisite pam_pwquality.so try_first_pass retry=3 type=


password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password required pam_deny.so
session
session
session
session

optional pam_keyinit.so revoke


required pam_limits.so
[success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
required pam_unix.so

(NSS)
, , ..

, UID GID, -, ..
/etc/passwd, /etc/group, /etc/hosts, /etc/services ..
UNIX Linux
. (NSS),
libc. ,
NSS, , ,
LDAP. /etc/nsswitch.
conf. Ubuntu12.10 :
# /etc/nsswitch.conf (Ubuntu)
passwd: compat
group: compat
shadow: compat
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
networks: files
protocols: db files
...

nsswitch.conf . , ,
( ). , . ,
, . man nsswitch.conf.
files , /etc/
passwd /etc/group.
compat files,
+ -. NIS.
.
db BDB (Berkeley Database).
dns .
mdns DNS ( Zeroconf Apple Bonjour/
Rendezvous).

11.5. , , Unicode

261

,
libnss_db db. ,
( ).

Nscd ( )
(, Fedora, Red Hat SUSE)
nscd, Init-V.
Debian Ubuntu .
nscd Name Service Caching Daemon (
). , -, , IP-.
, nscd ,
, . nscd
,
(, LDAP). nscd ,
LDAP, .
/etc/nscd.conf. nscd /etc/nscd.conf.
: passwd ,
group host -. ,
, ,
, ..

11.5. ,
, Unicode
.
,
, , ,
.. ,
, ..
, .
7- ASCII. 65. , . ,
, .
i18n l10n. , , (internationalization = i + 18 + n) (localization = l +
+10 + n). ,
.

262

11.


(character set)
. ASCII (7), ISO--n (8)
Unicode (16).
ASCII 127, a z ( A
Z), 0 9 .
ISO-8859, ISO , 127 ASCII,
128 .
ISO:
yy ISO-8859-1 = -1 ;
yy ISO-8859-2 = -2 - ;
yy ISO-8859-3 = -3 ;
yy ISO-8859-4 = -4 ;
yy ISO-8859-9 = -5 ;
yy ISO-8859-10 = -6 (, , );
yy ISO-8859-13 = -7 ;
yy ISO-8859-14 = -8 ;
yy ISO-8859-15 = -9 = -0 -1,
.
-0 ,
. Windows
(code pages). Code Page1252 -1,
.
Unicode 8- ,
16- Unicode, ISO-10646. , ( 16,
65000).
Unicode , ,
. ,
2 ( 16). UTF-16 (Unicode Transfer Format Unicode).
: -, ,
, US-ASCII. -, 0 Unicode. , .. , 0
.
Unicode.
UTF-16 UTF-8. US-ASCII (7),
, , 0.

11.5. , , Unicode

263


2 4. ,
. UTF-8
,
UNIX/Linux . Microsoft Windows UTF-16. , Unicode Linux,
, , UTF-8. UTF-8
.


,
. Linux
. ,
- 0. ,
,
, .txt, !
-1, 7 ( ).
Unicode/UTF-8,
10 ( , ,
3).

: ,
, , .
Unicode . , Emacs XEmacs,
.


, . , , Linux, Unicode
, . ,
, -, , ,
, ASCII, .
recode iconf (.9.3).
, , NFS3:
, UTF8, .txt,
-
NFS, .txt.

NFS4. ( ),
convmv, 9.4.

264

11.

()
. , .
. Arial, Courier, Helvetica, Palatino .
, :
234 , ,
. X-
256
. (TrueType, PostScript) .


. UTF-8.
8-
. , . Gnome
, .
Debian dpkg-reconfigure locales;
Fedora, Red Hat system-config-language;
Gnome 3.n ;
KDE /;
SUSE YaST- ;
Ubuntu gnome-language-selector.
, KDE Gnome ( kdm
gdm)
.


, :
Debian, Ubuntu /etc/default/locale;
Red Hat, Fedora /etc/sysconfig/i18n;
SUSE /etc/sysconfig/language.
, , ~/.i18n.

LC LANG

LC_CTYPE LANG. glibc,
Linux.

11.5. , , Unicode

265

.
, , , -. .11.4 .
11.4.

LANG

LC-

LC_CTYPE

LC_COLLATE

LC_MESSAGES

, ..

LC_NUMERIC

LC_TIME

LC_MONETARY

LC_PAPER

LC_ALL

LC-

, (
LC_ ).
, C
POSIX. , -,
..
,
LANG. , , LANG.
LC_COLLATE POSIX.
LANG.
LC_ALL , LANG. LC_ALL,
( , LC LANG).
, /usr/share/locale*//LC_MESSAGES.
man locale - http://www.gnu.org/software/
libc/manual/.



locale. LANG LC_ALL
. ,
:
user$ locale
LANG=de_DE.UTF-8
LC_CTYPE="de_AT.UTF-8"
LC_NUMERIC="de_AT.UTF-8"
LC_TIME="de_AT.UTF-8"

266

11.

...
LC_ALL=

,
. ,
. LANG de_DE, mount .
user$ mount /xy
mount: Konnte /xy nicht in /etc/fstab oder /etc/mtab finden

env

, ,
env. , , ,
:
user$ env LANG=C mount /xy
mount: can't find /xy in /etc/fstab or /etc/mtab

LANG ,
-, LANGUAGE:
user$ env LANG=C LANGUAGE=C mount /xy
mount: can't find /xy in /etc/fstab or /etc/mtab

LANG , export LANG=C.

c LC/LANG
locale -a. x_y, x,
, , y, ,
. de_DE. .
glibc , deutsch german. /usr/share/locale/locale.alias ,
.


, , , .. , .
, , ,
Gnome, KDE,
OpenOffice, Firefox .. SUSE Ubuntu , ,
.
Linux . ( man, , ).

11.6.

267

, Linux
-.
. .
, ,
de_DE.ISO-8859-1 de_DE.utf8.

11.6.
, . . , ,
18, .
, : -,

. -, ,
.
, ,
. , , , .

,
Linux
!
Linux
. linux . , , ,
Linux, , .

-.
-, /dev/sda SATA.
- udev. - Linux .7.8 7.9.
Proc- sys-. /proc /sys..
. . , .
, /etc/mmodprobe.conf /etc/modprobe.conf.d/*.
. , lshal, lspci lsusb. , dmesg.


. ,
Intel-Pentium, 32- 64- Intel

268

11.

AMD. Linux (, PowerPC).


, , , /proc/cpuinfo. ,
Intel-i7. Linux
. model name , cpu MHz .
user$ cat /proc/cpuinfo
cat /proc/cpuinfo
processor : 0
model name : Intel(R) Core(TM) i7 CPU
...
processor : 1
model name : Intel(R) Core(TM) i7 CPU
...

860 @ 2.80GHz
860 @ 2.80GHz

cpufreq,
( ). : http://www.kernel.org/doc/
Documentation/cpu-freq/; https://wiki.archlinux.org/index.php/CPU_Frequency_Scaling.
: /sys/devices/system/cpu/cpun/cpufreq/.
.
, .
cpufreq-set cpufrequtils. 800 MHz:
root# cpufreq-set -r -max 0.8GHz

: , , , , , .
. , , lm-sensors. root sensors-detect. , . ,
,
, . , , /etc/modules
sensors-detect. . ,
modprobe.
sensors
:
root# sensors
coretemp-isa-0000
Adapter: ISA adapter

11.6.

Physical id 0: +31.0C
Core 0: +26.0C
Core 1: +29.0C

269

(high = +80.0C, crit = +98.0C)


(high = +80.0C, crit = +98.0C)
(high = +80.0C, crit = +98.0C)

, .
xsensors,
. Ubuntu
, indicator-sensors.
(RAM).
free. , ( ), Memtest86
. , http://
www.memtest86.com/ ISO-, .


ACPI. ACPI Advanced Configuration and Power Interface
( ).
1999.
APM ( ). ACPI Linux, 2.6. , dmesg | grep
ACPI. kacpid ACPI acpid. ACPI. acpid , /etc/acpi.
acpi -V /proc/acpi
ACPI ( , ..).
ACPI , ACPI 17.4, ,
ACPI. ACPI Linux
http://www.lesswatts.org/projects/acpi/.
Suspend. ACPI ,
( Stand-by)
(, , ).

, .
. -
. ,
!

. , .
Linux,
ACPI.

270

11.

, , , .
- ,
.
,
.
Suspend

: , sync
, .

.
Linux ,
.
: http://www.lesswatts.org/projects/.
, , ,
KDE Gnome.
Powertop. powertop , (idle). ,
.
root# powertop
Cn P-States ()
C0 ( ) ( 1,8%) 1,80 GHz 0,0%
AbfraC1 0,0m 1,60 GHz 0,0%
C1 0,0ms ( 0,0%) 1400 MHz 0,0%
C2 17,7ms (98,2%) 1200 MHz 0,0%
C3 0,0ms ( 0,0%) 600 MHz 100,0%
C4 0,0ms ( 0,0%)
: 55,3
: 3,0s
( ACPI): 20,1W (1,2 Std.)
:
23,0% (15,7)
<interrupt>
: ehci_hcd:usb1, uhci_hcd:usb2, uhci_hcd:usb3,
21,6% (14,7) USB- 3-2 : Optical USB Mouse (Logitech)
13,7% ( 9,3)
<interrupt> : extra timer interrupt
12,7% ( 8,7)
<Kernel Kern> : usb_hcd_poll_rh_status (rh_timer_func)
9,8% ( 6,7)
<Kernel Kern> : hrtimer_start (tick_sched_timer)
3,9% ( 2,7)
gnome-terminal : schedule_hrtimeout_range (hrtimer_wakeup)
: "USB autosuspend", U,
"usbcore.autosuspend=1" ,
GRUB.

powertop , ,
, .
. , , .
, ,
. -

11.6.

271

(
). . :
root# echo 5 > /proc/sys/vm/laptop_mode

, ,
(. http://lwn.net/Articles/257426/). , . , , ,
.
,
laptop-mode-tools. ,
.
/etc/laptop-mode (. laptop-mode.conf).
laptop-mode-tools http://
samwel.tk/laptop_mode/.


, , , . - ? , . ,
, - - .
. . lm-sensors . ,
. , ,
.

tpfanco. IBM Lenovo. Debian : http://code.google.com/p/
tpfanco/downloads/list.
tpfan (service tpfand
start), tpfan-admin ( ).
, .
Lenovo E320
. , ,
.

272

11.

, .
, !
, .


. Linux - /dev/ttySn /dev/lpn.
, .
IDE, SATA, SCSI. , CD DVD,
, ,
IDE, SATA SCSI. Linux
IDE, SATA SCSI SCSI- .
DIE-, libata SCSI,
IDE.
IDE SCSI
lsscsi, :
/sys/bus/ide/*;
/sys/bus/scsi/*;
/proc/scsi/*.

USB. : . USB . USB-


( , , CD- DVD-)
SCSI-.
usbfs USB- /proc/usb. ,
/sys/bus/usb. USB-
lsusb -v ( usbutils).
Firewire. Firewire USB. Firewire
IEEE1394 i.Link, Sony. Firewire , USB,
. IEEE1394
Linux http://www.linux1394.org/.
Firewire
, , ieee1394. Firewire /sys/bus/ieee1394.
PCI. PCI, ,
, lspci. /proc/bus/pci/ /sys/bus/pci/
, .
:

11.6.

273

root# lspci
00:00.0 Host bridge: Intel Corporation 82P965/G965 Memory Controller Hub
00:01.0 PCI bridge: Intel Corporation 82P965/G965 PCI Express Root Port
00:1a.0 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI #4
00:1b.0 Audio device: Intel Corporation 82801H (ICH8 Family) HD Audio Controller
00:1f.0 ISA bridge: Intel Corporation 82801HB/HR (ICH8/R) LPC Interface Controller
00:1f.2 IDE interface: Intel Corporation 82801H (ICH8 Family) 4 port SATA IDE
Controller
00:1f.3 SMBus: Intel Corporation 82801H (ICH8 Family) SMBus Controller
01:00.0 VGA compatible controller: nVidia Corporation G70 [GeForce 7600 GS]
02:00.0 Ethernet controller: Marvell Technology Group Ltd. 88E8056 PCI-E Gigabit
Ethernet Controller (rev 12)
05:03.0 FireWire (IEEE 1394): Texas Instruments TSB43AB22/A IEEE-1394a-2000 Controller

.
WLAN LAN, 18.
Bluetooth. . Bluetooth WLAN
, . Linux ,
Bluetooth, -
.
Gnome Bluetooth bluetooth-applet bluetooth-wizard. KDE
kbluetooth kbluetooth-devicemanager.
bluetoothd, udev
Bluetooth. /etc/bluetooth.
Bluetooth Linux http://www.bluez.org/.
(X). Linux XWindow.


( ) , , ,
. Linux . ,
. (Hardware Abstraction Level, HAL), . -
.
.
, ,
, , - .
Udev c udev -
,

274

11.

.
/lib/udev/rules.d /etc/udev/rules.d.
: http://www.reactivated.net/writing_udev_
rules.html.
DeviceKit , ,
, (DeviceKit).
libudev libgudev , , ,
. ( )
udisks (
DeviceKit-disks).
upower ( DeviceKit-power).
: http://freedesktop.
org/wiki/Software/DeviceKit/; http://www.freedesktop.org/wiki/Software/udisks; http://
upower.freedesktop.org/.
KDE-4 HAL D-Bus
Solid. Gnome 2.22
Nautilus PolicyKit (.8.4); .
D-Bus . libdbus . ,
, dbus-daemon.

(ALSA)
ALSA Advanced Linux Sound Architecture (
Linux). , 2.6, .
OSS Open Sound
System. ALSA snd-pcm-oss, sndseq-oss snd-mixer-oss, OSS.
, ,
ALSA. ALSA snd. lsmod
grep snd ALSA.
, /proc/
asound.
ALSA /etc/alsa/*, /etc/asound.
conf, ~/.asoundrc.
, . . (, ),
, .
- ,
- ALSA
: http://www.alsa-project.org/.

11.6.

275

Init-V (.16) .

ALSA
ALSA
( alsa-utils), : alsactl
ALSA ( ..); alsamixer
ALSA; aplay ; arecord .

, ,
. : ; PCM- , ,
- ( PCM -
); ,
CD
- , , CD, CD- .
,
. ? alsamixer .
. M (mute)
.

ALSA ,
, .. ALSA , .
,
ALSA. KDE Gnome -.
, , . , , ,
. Adobe , Flash-
Linux - ,
.
.
aRts.
KDE 2.n 3.n. aRts , ,
. KDE
aRts artsd, KDE. ,
aRts,
artsdsp. , aRts ,
KDE 4 .
EsounD. Enlightened Sound Daemon ( ) aRts Gnome.

276

11.

EsounD esd,
Gnome. EsounD, aRts, : EsounD
Gnome ,
GStreamer.
GStreamer. (

), Gnome.
.
- . aRts EsounD,
GStreamer . , ,
ALSA.
http://www.gstreamer.net/.
Phonon. KDE4 Phonon. -


(API) , ( Xine, ,
, GStreamer VLC).
Phonon Qt . Phonon: http://
phonon.kde.org/.
PulseAudio. ,
esd .

.
: pavucontrol
. , PulseAudio ,
USB-.
: http://pulseaudio.org/; http://pulseaudio.org/wiki/FAQ.
,
-
. RealPlayer
Helix Player Helix DNA, Xine xinelib. , .
, Linux ,
Audio: its a mess (http://lwn.net/Articles/299211/).
2008 , , , , - .
, , ,
. Ubuntu Studio: http://ubuntustudio.org/.

11.7.

277

11.7.
, (PAM, APT, dpkg) , /var/log.
,
.
.

sysklogd (rsyslogd)
,
, Syslog. (Debian, Fedora, openSUSE, Ubuntu) rsyslogd.
Syslog! , , Apache, CUPS Samba,
, .
, ,
syslog.conf.
.
, Syslog, :
root# cd /var/log
root# ls $(find -user syslog).

rsyslogd /etc/rsyslogd.conf /etc/


rsyslog.d/*.conf . ,
Ubuntu. /etc/
rsyslog.d/50-default.conf.
Syslog , .
() , ,
() ,
.
\. ,
. .
, : ._. , . , ,
. Linux, Syslog, .

278

11.

Syslog : uth, authpriv, cron, daemon, ftp, kern, lpr, mail,


news, syslog, user, uucp, local0 local7. *
.
, Syslog (
): debug, info, notice, warning=warn, error=err, crit, alert emerg=panic.
warn, error panic
warning, err emerg. * .
none , .
, . , mail.err
crit, alert emerg.
, = (, , mail.=err).
.
.
-, Syslog .
,
, .
Syslog FIFO (
) .
|. /dev/xconsole,
, FIFO, X.
* ,
, SSH. , .
syslog.conf man. Syslog Ubuntu,
:
# /etc/rsyslog.d/50-default.conf bei Ubuntu
#
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
mail.err /var/log/mail.err
*.emerg :omusrmsg:*
daemon.*;mail.*;\
news.err;\
*.=debug;*.=info;\
*.=notice;*.=warn |/dev/xconsole

, .
/var/log/auth
. , ( SSH), PAM, sudo ..

11.7.

279

auth, .
/var/log/syslog , Syslog
( , ).
, . ,
,
.
.
/var/log/kern.log .
(, Postfix) . mail.log , mail.err
.
/var/log/debug , ,
auth, authpriv, news mail .
(,
) :omusrmsg:* ( , ). Omusrmsg
rsyslog, .
X.
X, xconsole.
, .


16, . ,
, . dmesg. -c,
.
, /proc/
kmsg. Syslog.
(dmesg) [nnn.
nnnnnn]. ,
,
. .

Init
Init (.16) . Fedora /var/log/boot.log.

logrotate
, , ,
. ,

280

11.

logrotate. Cron /etc/cron.daily/


logrotate. , /etc/logrotate.d.
logrotate . .
1. logrotate .
.4.gz .5.gz, .3.gz .2.gz .. -

. .
2.

, .
3. logrotate .
.0.
4. , .
5. logrotate
/etc/init.d/ reload .

, ,
.
6. logrotate .0 .1 ( delaycompress). -

, , , .0, (
gz).
. /etc/logrotate.conf , logrotate . , - .
/etc/logrotate.d ,
. Logrotate,
. , , samba
/etc/logrotate.d/samba. , , logrotate

.
Apache
Ubuntu: logrotate .
.
52,
.
# /etc/logrotate.d/apache
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty

11.7.

281

create 640 root adm


sharedscripts
postrotate
if [ -f "`. /etc/apache2/envvars ; \
echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
/etc/init.d/apache2 reload > /dev/null
fi
endscript
}

Apache , reload , .

Logwatch

- . ,
,
!
. logwatch, .
logwatch
/etc/cron.daily/*logwatch. ,
24, (root).


logwatch
, ! logwatch
Postfix ( ,
), Only

Local

( ).
, /etc/aliases.

, , . ,
.
logwatch,
:
Logwatch 7.4.0 (03/01/11)
Processing Initiated: Tue Jul 10 06:25:02 2012
Date Range Processed: yesterday
( 2012-Jul-09 )
Period is day.
Detail Level of Output: 0
Type of Output/Format: mail / text
Logfiles for Host: xxxx

282

11.

--------------------- Denyhosts Begin -----------------------new denied hosts:


60.12.251.5
222.45.235.70
--------------------- pam_unix Begin -----------------------sshd:
Authentication Failures:
root (222.45.235.70): 7 Time(s)
root (60.12.251.5): 3 Time(s)
unknown (60.12.251.5): 1 Time(s)
Invalid Users:
Unknown Account: 1 Time(s)
--------------------- Postfix Begin ----------------------- 3.347K Bytes accepted 3,427
2.343K Bytes sent via SMTP 2,399
4.910K Bytes delivered 5,028
--------------------- SSHD Begin -----------------------Failed logins from:
60.12.251.5: 3 times
222.45.235.70: 7 times
Illegal users from:
undef: 1 time
60.12.251.5: 1 time
Received disconnect:
11: Bye Bye [preauth] : 11 Time(s)
Refused incoming connections:
222.45.235.70 (222.45.235.70): 1 Time(s)
60.12.251.5 (60.12.251.5): 1 Time(s)
--------------------- Disk Space Begin -----------------------Filesystem Size Used Avail
Use% Mounted on
/dev/mapper/vg0-root 20G 1.2G 18G 6% /
udev 7.8G 4.0K 7.8G 1% /dev
/dev/mapper/vg0-var 20G 723M 19G 4% /var
/dev/mapper/vg0-images 20G 6.6G 13G 35% /var/lib/libvirt/images
/dev/mapper/vg0-backup 100G 12G 84G 13% /backup
/dev/md0 1016M
75M 890M 8% /boot

. : logwatch
, , ? :
logwatch , /usr/share/logwatch/default.conf .
logwatch.conf . ,
, (MailTo = root),

11.7.

283

(Range = yesterday),
(Detail = Low) ..
, default.conf/services/*.conf , , Apache, Postfix,
ClamAV, Dovecot, Sendmail, SSH . ,
,
. , .
/usr/share/logwatch/dist.conf , . .
,
/etc/watchlog .
,
. logwatch :
root# logwatch --mailto name@host

12

Windows
setup.exe. Linux :
,
. .
: . , ,
A B,
, B. , , ..
. Linux
: Red Hat, Fedora, Mandriva, SUSE. RPM, Red Hat. Debian
, , , , DEB.
, (rpm, dpkg
..) . , ,
.
. rpm dpkg .
, , ,
, CD/
DVD . ,
. , , Yum ZYpp
RPM, APT Aptitude DEB . . YumExtender,
PackageKit Synaptic.
, .
:

285

Debian, Ubuntu update-manager;


Fedora 9 , RHEL6 packagekit;
Fedora 8 , RHEL5 pirut pup;
SUSE YaST- ;
Ubuntu gnome-app-install, gnome-language-selector.

Linux . ,
, ..

Linux
, . , ,
Red Hat SUSE ( ).
.

.
. , , .
.
: http://lwn.net/Articles/326817/.
.
, .
, ,
, Windows MacOSX
, .
,
.
, .
Linux
, (
, , LibreOffice Gimp). . ,
, .
, ,

. , , LibreOffice.
Windows MacOSX , , .
. ,
Linux .
LibreOffice, ,
. - ,
.

286

12.

,
. ( Google Chrome
, Firefox Thunderbird .)
: - , , , . ,
,
. :
.
- ,
. ,
.
.
50, 100 1000 Linux, , ,
. , , .
, Red Hat Network, ZENworks (Novell/SUSE) m23 (Debian)
Orchestra Landscape ( Ubuntu):
http://www.redhat.com/rhn/;
http://www.novell.com/de-de/products/zenworks/configurationmanagement/;
http://m23.sourceforge.net/;
https://launchpad.net/orchestra;
http://www.canonical.com/enterprise-services/ubuntu-advantage/landscape.
tar. tar
. Linux,
RPM DEB, TAR-. ,
TAR-, (, Slackware).
TAR- Linux. ,
RPM DEB, TAR-
. , (tar czf .tgz), , , , .
TAR- , , ,
.
. RPM
DEB, , , , . , -

12.1. RPM

287

,
,
,
.
http://labix.
org/smart; http://0install.net/.

12.1. RPM
rpm RPM- . ,
:

(, );
(
);
;
, ( );
, ;
, .
, , RPM-.
( /var/
lib/rpm).
. RPM Red Hat. , .
Fedora, Red Hat, SUSE .. RPM4.n Fedora
rpm.org (http://rpm.org/). RPM5.n (http://rpm5.org/). .
RPM-5 Mandriva (http://rpm.org/ (RPM 4.n);
http://rpm5.org/ (RPM 5.n)).

RPM- :
. , .
. , .
: , abc-2.0.7-1.
i686.rpm ab 2.0.7 1 (

288

12.

, -
, 1 ,
, , rpm).
i686 ,
, Pentium-II (, Linux
). abc
, , noarch. ,
src.
x86:
i386 = 386 ;
i486 = 486 ;
i586 = Pentium ;
i686 = Pentium II ;
x86_64 = AMD64 64- ( Intel).
i386 . ,
i686 PentiumII, . .

, ,
: , , ,
.. ,
(, Perl) .
.
rpm ,
.
/var/lib/rpm.
; ,
.
RPM !
RPM , , (rpm -e).

Delta-RPM
RPM, .
,
, . SUSE Delta-RPM,

12.1. RPM

289

, . Mandriva Fedora
.
, Delta-RPM :
applydeltarpm Delta-RPM ( ) , RPM-. (rpm -U). applydeltarpm
deltarpm.
Delta-RPM : applydeltarpm
, .
, RPM.

RPM , . .
RPM , rpm
. ,
, , Yum.
,
,
tar .
: , , , ( ).
RPM , . , , , rpm 4.4
RPM, 4.7. ?
rpm.
, RPM (
/var/lib/rpm), . 5 RPM 80.
RPM . rpm .
rm -f/var/lib/rpm/__db* , rpm
--rebuilddb. RPM . ,
.

,
rpm.

290

12.

abc:
root# rpm -i abc-2.0.7-1.i686.rpm
GPG http://myserver.com -

RPM:
root# rpm --import http://myserver.com/RPM-myserver-GPG-KEY
abc, -

:
root# rpm -U http://myserver.com/mypath/abc-2.1.0-2.i686.rpm
, abc,

:
root# rpm -V abc
abc:
root# rpm -e abc
:
root# rpm -qa
,

( , ):
root# rpm -qa --last
, mysql ( ):
root# rpm -qa | grep -i mysql
perl ( ):
root# rpm -qi perl
perl:
root# rpm -ql perl
perl:
root# rpm -qd perl
cups:
root# rpm -qc cups
.

RPM-:
root# rpm -qip abc-2.0.7-1.i686.rpm
, /usr/lib/libz.so (: kdelibs):
root# rpm -qf rpm -qf /usr/lib/libkdnssd.so

12.1. RPM

291

, php-mysql. Fedora11:
ysql.so, mysqli.so, pdo_mysql.so, php-mysqli, php_database php-mysql=5.2.9-2. -

.
,
. , ,
.
.
root# rpm -q --provides php-mysql
, php-mysql.

Fedora ,
: libc.so.6, libm.so.6, libmysqlclient.so.16,
php-common=5.2.9-2 php-pdo.
root# rpm -q --requires php-mysql
rpm -q --provides rpm -q provides
-p,
( alien):
root# rpm -q --requires -p alien-8.56-2.i586.rpm
, mysqli.so
(: php-mysql):
root# rpm -q --whatprovides mysqli.so
, libpthread.so.0 (, glibc):
root# rpm -q --whatrequires libpthread.so.0

32/64
64- , rpm -qi name
, .
-, 32- 64- .
SUSE
, 32- 32bit. rpm -qa grep 32bit
32- , .


, , , :
failed dependencies: attributname is needed by paketname ( :
_ _).

292

12.

, RPM,
Yum, Zypper ,
. , , _. http://
rpmfind.net, ,
RPM.

12.2. Yum
Yum . RPM .
() Yum, -

. Yum- RPM,
( repodata). . (
, ). Yum
,
.
Yum ,

.
. , , , Yum

B C.
Yum -

. , . ,
. , .
Yum Python.
Fedora Red Hat.
Yum Fedora11.
Yum http://www.linux.duke.edu/
projects/yum/.
. Yum. Yum, another copy is running ( ).
Yum.
: /var/run/yum.pid ID-
, . ps grep id
. /etc/init.d/yum-updatesd stop,
start.

12.2. Yum

293

Yum /etc/yum.conf.
Fedora12:
# /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
color=never

. keepcache=0
. , ,
, , ,
, , .
Yum .
,
. , keepcache=1.
, /var/cache/yum, yum clean packages.
exaktarch=1 Yum , . ,
i386 x86_64 .
gpgcheck=1 Yum .
gpgcheck , yum.conf . plugins , Yum
.
Yum , .
, , : , .
installonlypkgs .
kernel, kernel-smp, kernel-bigmem, kernel-enterprise, kernel-debug,
kernel-unsupported. , installonly_limit, yum.
conf, , .
. .
color=never yum . ,
color=always.
.
REPO- /etc/yum.repos.d. Fedora:

294

12.

# /etc/yum.repos.d/fedora.repo
[fedora]
name=Fedora $releasever - $basearch
failovermethod=priority
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora$releasever&arch=$basearch
enabled=1
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch


baseurl=... mirrorlist=... -.

. Yum
. Yum $releasever,
$arch $basearch Linux .
.
$arch uname ( Python, uname) ,
, x86_64, 64-Bit-Intel/AMD.
$basearch , $arch (, i386).
$releasever edhat-release fedora-release
( yum.conf
distroverpkg; ).
metadata_expires , . Yum , .
( ),
Yum , ( yum
clean metadata, Yum ).
metadata_expires
: ,
. ,
.
. , Yum , yum.conf *.repo exclude 1 2 3.
, : exclude xemacs*.
. Yum
.
/etc/yum/pluginconf.d.

295

12.2. Yum

Presto. Yum Presto: Delta-RPM.


( 6080%!),
.
. Yum
.
fedora-release-n.noarch.rpm fedora-release-n.noarch.rpm,
yum upgrade. , . - , , . , .

yum.
. , ( ).
root# yum check-update
...
acl.x86_64 2.2.49-6.fc16 updates
cifs-utils.x86_64
4.6-1.fc16 updates
gdb.x86_64 7.1-32.fc16 updates
glx-utils.x86_64 7.8.1-8.fc16 updates
...
root# yum update
...
Vorgangsbersicht
Installieren 0 Paket(e)
Upgrade 35 Paket(e)
Gesamte Downloadgrsse: 26 M
Ist dies in Ordnung? [j/N] : j
...
root# yum install mysql-server
...
Installieren:
mysql-server x86_64
5.1.48-2.fc16 updates 8.1
Installiert fr Abhngigkeiten:
mysql x86_64
5.1.48-2.fc16 updates 889
perl-DBD-MySQL x86_64
4.016-1.fc16 updates 135
perl-DBI x86_64
1.609-4.fc16 fedora 707
Vorgangsbersicht
Installieren 4 Paket(e)
Upgrade 0 Paket(e)
Gesamte Downloadgrsse: 9.8 M
Installed size: 28 M
Ist dies in Ordnung? [j/N] : j

M
k
k
k

296

12.

root# yum history


ID | Login user | Date and time | Action(s) | Altered
------------------------------------------------------------------------------ 12 | kofler <kofler> | 2011-08-09 10:38 | Install | 3
11 | kofler <kofler> | 2011-08-09 10:35 | Install | 1
10 | System <unset> | 2011-08-06 12:47 | Install | 2
...
root# yum history info 10
Transaction ID : 10
Begin time : Fri Aug 6 12:47:08 2011
Begin rpmdb : 1239:cd1de7f23aa89953e4eeb9fa5e561f7fe36e079a
End time :
12:47:22 2011 (14 seconds)
End rpmdb : 1241:bad14ec1137d77b9d69ffa13ddf55138972644aa
User : System <unset>
Return-Code : Success
Transaction performed with:
Installiert rpm-4.8.1-2.fc16.x86_64
Installiert yum-3.2.27-4.fc16.noarch
Installiert yum-plugin-fs-snapshot-1.1.27-2.fc16.noarch
Installiert yum-presto-0.6.2-1.fc16.noarch
Packages Altered:
Dep-Install freeglut-2.6.0-5.fc16.x86_64
Install mesa-demos-7.8.1-6.fc16.x86_64
history info

yum,
. .


Yum , , . yum grouplist, yum groupinfo name
, . yum groupinfo
: mandatory (), default (
) optional (). yum groupinstall , mandatory default. yum ,
.
, yum.conf :
# /etc/yum.conf
group_package_types = mandatory default optional

, yum groupupdate
yum groupremove .


yum .
yumdownloader yum-utils.
gedit .

12.2. Yum

297

source, *.repo
.
user$ yumdownloader --source gedit


yum-updatesd, Init-V
yum-updatesd.
yum-updatesd , . , /etc/yum/yum-updatesd.conf,
.
Fedora13,
. , no yes:
# /etc/yum/yum-updatesd.conf
[main]
# ,
run_interval = 3600
# , 10
updaterefresh = 600
# dbus
emit_via = dbus
dbus_listener = yes
#
do_download = no
#
do_download_deps = no
#
do_update = no

, Yum ,
, . yum-updatesd, .
yum-updatesd!
root# /etc/init.d/yum-updatesd stop
root# ... ...
root# /etc/init.d/yum-updatesd start

Yum Extender (Yumex)


Yumex
Yum. Yum .

298

12.

, , ,
, , ( ) (.12.1).
Yumex . .

.12.1. Yum Extender

12.3. ZYpp
SUSE, Fedora Red Hat, RPM-. ZYpp,
, Yum, Novell/
SUSE. ZYpp ZENworks, YaST, ,
Zenworks
Novell/SUSE. ZYpp
http://en.opensuse.org/ZYpp.

libzypp
libzypp, ZYpp. YaST,
YUM. ,
/var/lib/zypp. YaST PackageKit SUSE
libzypp.

12.3. ZYpp

299

Zypper . ,
, , . , ,
(Delta-RPM).
SUSE
Delta

-
RPM
. , Packman, .

/etc/zypp/repos.d.
,
! . openSUSE12.1:
# /etc/zypp/repos.d/repo.oss.repo
[repo-oss]
name=openSUSE-12.1-Oss
enabled=1
autorefresh=1
baseurl=http://download.opensuse.org/distribution/12.1/repo/oss/
type=yast2
keeppackages=1

zypper
libzypp. , zypper SUSE
aptget yum . , ,
, . zypper .
http://de.opensuse.org/Zypper/Anleitung.
zypper.
, , nano, , .
root# zypper repos
# |
|
|
|
--+-----------------+-----------------------+------------+-------1 | repo-non-oss
| openSUSE-12.1-Non-Oss | Yes
| Yes
2 | repo-oss
| openSUSE-12.1-Oss
| Yes
| Yes
...
root# zypper refresh
.
root# zypper install nano
:
ctags emacs emacs-info emacs-x11 fribidi libotf0 m17n-db m17n-lib xaw3d
9 .

300

12.

: 21,0 . 85,5M.
? [y/n/?]: y
root# zypper list-updates
...
S | | | | |
--+-------------+-----------+-----------+---------------+------v | | bind-libs | 9.7.1-1.5 | 9.7.1-2.1.1 | x86_64
v | | bind-utils | 9.7.1-1.5 | 9.7.1-2.1.1 | x86_64
v | | ethtool | 6-84.1 | 6-85.1.1 | x86_64
...

. , , , ZYpp (pattern). zypper search -t


. zypper info -t
, . zypper install -t
.
History. /var/log/zypp/history
, .
. zypper dup , Debian
Ubuntu, , :
root#
root#
root#
root#

zypper updates
...
zypper dup
reboot

( )
( )
( )
( )

12.4. Debian
( dpkg)
Debian :
dpkg,
. rpm. , , , .
.
APT (Advanced Package Tool, ). dpkg
Yum ZYpp.
: apt-get
Ubuntu, aptitude
Debian5.0 .

Debian, , -

12.4. Debian ( dpkg)

301

Linux, . Debian , ,
Ubuntu Mepis, Mint Knoppix.
RPM Debian,
rpm, a dpkg apt: https://help.ubuntu.com/community/SwitchingToUbuntu/
FromLinux/RedHatEnterpriseLinuxAndFedora.

. dpkg .
,
Debian, APT
.
root# dpkg --install test.deb
...
...
...
root# dpkg --search /etc/sensors3.conf
libsensors4: /etc/sensors3.conf
root# dpkg --listfiles libsensors4
...
/usr/lib
/usr/lib/libsensors.so.4.2.1
/etc
/etc/sensors3.conf
/etc/sensors.d
...

. dpkg --list
. , - .
(u= unknown, i= install, r= remove,
p= purge, h= hold), (n= not, i= installed,
c= config files, u= unpacked, f= failed config, h= half installed),
(h=hold, r=reinstall required, x=hold+reinstall required).
root# dpkg --list | grep hplip
ii hplip 3.10.6-0ubuntu1 HP Linux Printing and Imaging System (HPLIP)
ii hplip-cups 3.10.6-0ubuntu1 HP Linux Printing and Imaging - CUPS Raster driver
ii hplip-data 3.10.6-0ubuntu1 HP Linux Printing and Imaging - data files

ii ( ) rc (
, ).
rc, dpkg--purge .
hold , , . , hold :
root# echo "_ hold"
| dpkg --set-selections
root# echo "_ install | dpkg --set-selections

302

12.


man dpkg.
Get-selections set-selections. , dpkg --get-selections.
, dpkg --list,
.
, dpkg --set-selections.
root# dpkg --get-selections
accountsservice install
acl install
acpi-support install
acpid install
...

. , .
, dpkg-reconfigure _.
. dpkg
( , ,
..). DCTRL (Debian Control).
dctrl-tools ,
DCTRL. man grep-dctrl
.

12.5. APT
APT Debian , Yum RPM: , .
Debian APT Linux.
, Ubuntu Debian
.
: apt-get
aptitude. . apt-get install
_ aptitude install _ ,
, .
apt-get Ubuntu, Debian
5 aptitude. ,
Debian Ubuntu, .
, APT RPM, , , , Yum. APT

12.5. APT

303

Debian. APT : http://


apt-rpm.org/.

APT apt.conf.d/* sources.list, /etc/apt.


sources.list.d.
apt.conf.d/* , ,
, ( .
man apt.conf). sources.list ( man sources.list) .
APT.
:
pakettyp uri distribution [1] [2] [3] ...

Debian deb,
deb-src. HTTP FTP APT ,
RSH SSH-, CD DVD.
, CD DVD :
apt-cdrom, . deb cdrom .
( ).
, . ! ,
Ubuntu main, restricted, universe multiverse, Debian main,
contrib, non-free ..
, , :
, APT
. .
Ubuntu 12.10.
# /etc/apt/sources.list
deb http://de.archive.ubuntu.com/ubuntu/ quantal
main restricted universe
multiverse
deb http://de.archive.ubuntu.com/ubuntu/ quantal-updates main restricted universe
multiverse
deb http://security.ubuntu.com/ubuntu quantal-security main restricted universe
multiverse

sources.list .
, , Synaptic.
CD .
APT CD. apt-cdrom add. APT . , sources.lst.

304

12.

apt-cdrom , D/DVD,
-d.
root# apt-cdrom -d /media/dvd add

APT-. APT- .
, - APT .
. , APT
,
. APT, apt-key:
root# apt-key add _.gpg

apt-get
apt-get aptitude.
apt-get .
.
APT. apt-get
update, .
, .
!
. apt-get install . ,
,
. , apt-get . apt-get
.
root# apt-get update
...
root# apt-get install apache2
...
:
apache2-mpm-worker apache2-utils apache2.2-common libapr1 libaprutil1
:
apache2-doc apache2-suexec apache2-suexec-custom
:
apache2 apache2-mpm-worker apache2-utils apache2.2-common libapr1 libaprutil1
0 , 6 , 0 11 .
1472.
5452 .
? [Y/n]?
...

. apt-get remove _ .
,
, . apt-get autoremove. , .

305

12.5. APT

. apt-get dist-upgrade .
, .
qqroot# apt-get upgrade
...
:
libmozjs1d xulrunner-1.9 xulrunner-1.9-gnome-support
3 , 0 , 0 0 .
8208.
8192 .
? [Y/n]? Y
...

apt-get dist-upgrade upgrade:


. ,
.
. apt-get source _ .

aptitude
aptitude APT. (aptitude install _),
apt-get. ,
(.12.2).
.
F10.

.12.2. aptitude

306

12.

apt-get aptitude : , , . , , xyz, (lib-abc,


lib-efg ..), ( -
).
xyz aptget Synaptic,
lib-abc, lib-efg .. . ,
, .
Debian
aptitude apt-get.
. html2ps,
. , , html2ps, . , aptitude
.
root# aptitude install html2ps
...
...
:
gs-gpl html2ps libcompress-zlib-perl libfont-afm-perl libhtml-format-perl
libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libmailtools-perl
...
? [Y/n/?] Y
...
root# aptitude remove html2ps
...
:
libfont-afm-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl
libhtml-tree-perl libmailtools-perl libtimedate-perl liburi-perl libwww-perl
perlmagick
...

tasksel
, Debian Ubuntu : , . , build-essential (Compiler, make ..).
tasksel.
, . , tasksel
, .
tasksel --list-task. tasksel install groupname. tasksel
, ,
.

12.5. APT

307

apt-cache
apt-cache
:
root# apt-cache show apache2
Package: apache2
Priority: optional
Section: web
...
Description: , , -
Apache v2 -
Apache.
, , API,
IPv6, .
...
root# apt-cache search scribus | sort
lprof - Hardware Color Profiler
scribus - Open Source Desktop Publishing
scribus-template - additional scribus templates


, APT , ,
.
unattended-upgrades, Debian Ubuntu.
Cron, /etc/cron.daily/apt.
/etc/apt/apt.conf.d/*
unattended-upgrade. ,
:
// /etc/apt/apt.conf.d/10periodic
//
APT::Periodic::Unattended-Upgrade 1;
// /etc/apt/apt.conf.d/50unattended-upgrades
//
Unattended-Upgrade::Allowed-Origins {
"${distro_id} stable";
"${distro_id} ${distro_codename}-security";
"${distro_id} ${distro_codename}-updates";
};
//
Unattended-Upgrade::Package-Blacklist {

308

12.

// "vim";
// ...
};
//
// Unattended-Upgrade::Mail "root@localhost";
APT::Periodic::Unattended-Upgrade , ( ) .
Allowed-Origins ,
. Package-Blacklist .
, mail , unattendedupgrade ,
. (MTA)
mailx.
:
/etc/cron.daily/apt sleep, ( 1800). , , cron,
.
/usr/bin/unattended-upgrade /var/log/unattended-upgrade.
, /etc/cron.daily/apt /var/lib/apt/periodic/
, , .
unattended-upgrade , conffile prompt,
. , , ,
.
,
, ,
, .
. unattended-upgrade ,
reboot.

, . - , .
Cron, ,
(, apt

-
get
dist

-
upgrade
--
simulate
), .

12.5. APT

309


apt-get dist-upgrade
. /etc/apt/sources.list.
Ubuntu
do-release-update -m desktop ( ) -m server ( ). Ubuntu
LTS ( )
, , , 8.04 12.04.
, , /etc/updatemanager/release-upgrades Prompt normal lts.
Debian ,
.
,
, .


Debian Ubuntu
,
. ,
LAN. ,
(),
.
, apt-cacher, apt-cacher-ng, squid-deb-proxy, apt-proxy (
) approx. apt-cacher.


- ( , ) apt-cacher. ( apt-cacher,
, , Apache. apt-cacher ! Apache
, apt-cacher
HTTP- 80.)
root# apt-get install apt-cacher

apt-cacher ,
/etc/default/apt-cacher:
# /etc/default/apt-cacher
AUTOSTART=1
...

/etc/apt-cacher/aptcacher.conf. , APT-

310

12.

3142. /var/cache/apt-cacher. :
# /etc/apt-cacher/apt-cacher.conf
...
daemon_addr=192.168.0.1
allowed_hosts=192.168.0.0/24
...

( 192.168.0.1,
)
,
192.168.0.*.
apt-cacher:
root# service apt-cacher start

apt-cacher , , /var/log/apt-cacher.


, /var/cache/apt/archive
,
. apt-cacher. , , , :
root# cd /usr/share/apt-cacher
root# ./apt-cacher-import.pl /var/cache/apt/archives


, apt-cacher
HTTP. ( ,
apt-cacher - ):
http://mein-apt-cacher:3142;
http://mein-apt-cacher:3142/report.
, , ,
.
apt-cacher ,
APT, - apt-get.
mein-apt-cacher - -:
// /apt/apt.conf.d/01proxy
Acquire::http::Proxy "http://mein-apt-cacher:3142/";

311

12.5. APT

APT . ,
, , , , . ,
,
( , //, ,
, -)!

Synaptic
APT ,
Synaptic (.12.3). , , . Synapti Ubuntu, Debian 7. Canonical
Ubuntu Software Center, Debian 7 PackageKit.

.12.3. Synaptic

. Synaptic :
,
. :
. :
,
.

312

12.

. , . ,
, ,
. ,
.
,
, , . , .
.
. .
, . EDIT
, ADD
.
.
. ,
: unable to get exclusive lock ( ). , , . .
,
. ,
lock-. :
root# rm /var/lib/dpkg/lock

. .
. Synaptic , .
Synaptic , . Synaptic
. , Ctrl+A,

. ,
. , .

12.6. PackageKit
PackageKit
. ,
, APT,
Yum Zypper. PackageKit ( KDE KPackageKit) , , Fedora, Kubuntu openSUSE, ,

12.6. PackageKit

313

Gnome. PackageKit
PolicyKit (.8.4).
. PackageKit ,
: ( packagekit),
(, packagekitbackend-apt)
( gnome-packagekit
kpackagekit). .
PackageKit /etc/PackageKit/*.
DefaultBackend PackageKit.conf: ,
(backend) .
PackageKit packagekitd.
PackageKit
.
pkcon,
. , pkcon
! ,
. ,
PolicyKit ( ). ,
PackageKit, pkmon.
. PackageKit
Gnome Fedora11. gpkapplication. (.12.4) (Package collections).

.12.4. PackageKit,

314

12.

Filters () ,
. , ,
. Apply ()
.
. gpk-update-icon ,
Gnome, , .
, .
gpk-update-viewer, . , .

12.7. TAR
Linux , . Linux
Linux TAR.
, gzip,
*.tgz *.tar.gz. tar.
root# tar
root# tar
)
root# tar
root# tar

-tzf archiv.tar.gz
-xzf archiv.tar.gz

( )
( -

-xzf archiv.tar.gz "*.tex" ( *.tex)


-xzf archiv.tar.gz -C dir ( )

,
bzip2. *.tar.bz2.
, z tar -j,
, , tar tjf archiv.tar.bz2.

. , (gcc, make ..), (devel-).

, tar,
. RPM , .
, , .

12.8.

, RPM, Debian Ubuntu? ,

12.9.

315

RPM? alien. (RPM, DEB, TAR Stampede


SLP).
, alien .
,
. , alien Linux.
--to-deb (Debian),
--to-rpm (RPM) --to-tgz ( TAR). alien
,
.
Debian RPM:
root# alien --to-rpm paket.deb

, RPM- . TAR,
tar less . , tar
Konqueror , ark file-roller. .
root# alien --to-tgz paket.rpm
root# tar -xzf paket.tgz ./usr/share/doc/packages/paket/TODO
root# less ./usr/share/doc/packages/paket/TODO

12.9.

Linux , , .
, , FTP, Java .

. ,
.
?
, Debian
, /etc/alternatives. ,
alternatives update-alternatives.
Debian, Ubuntu dpkg;
Red Hat, Fedora chkconfig;
SUSE update-alternatives.

316

12.

. ,
Java. Java java. /usr/bin/java /etc/
alternatives/java, , , ,
Java.
user$ ls -l /usr/bin/java
/usr/bin/java -> /etc/alternatives/java
user$ ls -l /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk/jre/bin/java


. updatealternatives . Red Hat Fedora
alternatives.


update-alternatives --display ,
.
Java Ubuntu9.10
Java. slave () ,
, man.
update-alternatives .
root# update-alternatives --display java
update-alternatives --display java
java - Auto-Modus
/usr/lib/jvm/java-6-openjdk/jre/bin/java
/usr/lib/jvm/java-6-openjdk/jre/bin/java 1061
Slave java.1.gz: /usr/lib/jvm/java-6-openjdk/jre/man/man1/java.1.gz
/usr/lib/jvm/java-6-sun/jre/bin/java 63
Slave java.1.gz: /usr/lib/jvm/java-6-sun/jre/man/man1/java.1.gz
"" /usr/lib/jvm/java-6-openjdk/jre/bin/java.

: . update-alternative
() .

update-alternatives config , .
, ,
. update-alternatives .
update-alternatives
-auto.
root# update-alternatives --config java
java
( /usr/bin/java).

12.9.

317



-----------------------------------------------------------* 0
/usr/lib/jvm/java-6-openjdk/jre/bin/java 1061

1
/usr/lib/jvm/java-6-openjdk/jre/bin/java 1061

2
/usr/lib/jvm/java-6-sun/jre/bin/java
63

Enter, [*],
: 2
update-alternatives: /usr/lib/jvm/java-6-sun/jre/bin/java,
/usr/bin/java (java) .

/var/lib/alternatives /var/lib/rpm/alternatives .

13

,
Java Mono

,
. Linux
, . 13.1 , Linux .
,
( ).
, ,
, .
( ,
++) . 13.2
, ( Linux).
, Linux ,
Java .NET. Java
Mono. .
, ,
. Linux , Perl,
Python, PHP ( ) bash. bash (. 6).

13.1.
Linux ,
, , X
..
. Linux
:
. ? ,
.

13.1.

319

, ,
. -
( ),
.
Linux, .
.
Linux .
( ) ( ).
, Windows:
DLL .
, . . ,
. , - . , , ,
.
,
, - .


Linux ,
, .
, , A.OUT ELF
libc5 glibc 2.n, libc6 ( glibc2.10).
. , Linux
(Intel, Sun-Sparc, DEC-Alpha) .
, , ,
.
glibc , glibc ,
:
root# programmxy
bash: /usr/local/bin/programmxy: No such file or directory

- , glibc, Debian Squeeze


glibc,
eglibc. ,

320

13. , Java Mono

. , ,
http://lwn.net/Articles/332000/.


Linux , ,
, - . ,
. ,
.
,
, , .
. , , .


ldd ,
. ldd ,
. , ,
.
user$ ldd /bin/cp
linux-vdso.so.1 => (0x00007fff3bb59000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f8ab9acc000)
librt.so.1 => /lib64/librt.so.1 (0x00007f8ab98c4000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007f8ab96bb000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f8ab94b6000)
libc.so.6 => /lib64/libc.so.6 (0x00007f8ab9127000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f8ab8f23000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8ab9cea000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f8ab8d06000)

X-, KDE- Gnome,


. .
ldd not a dynamic executable, , , .


: .so ,
, .
. . , ls
libc 6.
, (, /lib, /usr/
lib, /usr/local/lib, /usr/X11R6/lib /opt/lib), ,
, . ,
cp ld-linux-x68-64.so.2.
ld-2.14.so, .

13.1.

321

user$ ls -l /lib/ld*
/lib/ld-2.14.1.so
/lib/ld-linux.so.2 -> ld-2.14.1.so



.
, LD_LIBRARY_PATH. .
, /etc/ld.so.cache.
, ( ,
..). , , .
/etc/ld.so.cache ldconfig, , ,
/etc/ld.so.conf.
( /lib /usr/lib ld.so.conf
. /lib /usr/lib
, ld.so.conf ).
ldconfig
, .
,
, . , /etc/ld.so.conf.

.

32- 64-

: 32- ,
Intel/AMD, 64- , Intel/AMD. , 32- 32- .
, , 64- :
, 64- . Acrobat Reader Adobe.
/lib /lib64. 32- 64-
32- . ,
. Linux
, , ( ) . /lib32 /lib64,
. , , :
,
, .

322

13. , Java Mono

Debian Ubuntu 64-


32- , , -
ia32-libs.
Multiarch. , /usr/
lib , /usr/lib/x86_64-linux-gnu (Debian 7 , Ubuntu
12.04). ,
Intel/Pentium,
.
Multiarch , . , 32-, 64-
. , , gvfs:i386 ( 32-
gvfs).
(, 32- 64- ).
dpkg Multiarch.
- Multiarch ia32-libs .
- .
ia32-libs-multiarch. 32- . Multiarch Debian
Ubuntu : http://lwn.net/Articles/482952/ https://
lists.ubuntu.com/archives/ubuntu-devel/2011-October/034279.html.


, , . . .
prelink ,
. .
. /etc/prelink.conf ,
prelink.
/etc/sysconfig/prelink /etc/default/prelink (Debian,
Ubuntu).
, , .
OpenOffice KDE,
, .

.
. ,
( ,

13.2.

323

).
, ,
prelink -ua. man, : http://www.gentoo.org/doc/
en/prelink-howto.xml.
Debian, Ubuntu. Debian
Ubuntu, prelink /etc/default/prelink
PRELINKING=yes. Cron.
Red Hat, Fedora. . ( Cron /etc/cron.daily/prelink, /etc/sysconfig/prelink).
SUSE. ,
prelink /etc/sys-config/prelink PRELINKING=yes.
prelink YaST
( /sbin/conf.d/SuSEconfig.prelink).

13.2.

, , , Linux :
,
, .
. ,
.
GNU (gcc gcc-c++). ++.
, make, automake,
autoconf .. .
, .
-devel (Red Hat,
SUSE) -dev (Debian, Ubuntu). , glibc-devel libc6-dev glibc. - ,
, . , ,
, , -
.
Debian, Ubuntu. . build-essential

324

13. , Java Mono

,
C/C++.
Fedora. yum groupinstall development-tools. KDE Gnome, : kdesoftware-development gnome-software-development.
SUSE. YaST
. KDE Gnome, KDE- GNOME-DEVELOPMENT. zypper,
zypper install -t devel_basis, devel_kde devel_gnome.


Tar. TAR- (
*.tar.gz, *.tgz *.tar.bz2). , :
user$ tar xzf .tar.gz
user$ tar xjf .tar.bz2
user$ cd

( .gz .tgz)
( .bz2)

SRMP. TAR-, ,
, . , , FTP- .
, RPM-,
SRMP *.src.rpm. , , rpm -i:
root# rpm -i .src.rpm

: Fedora Red Hat /usr/src/redhat/, SUSE /usr/src/packages/.


SOURCES/.tar.xxx . TAR- , .
SOURCES/-xxx.patch (Red Hat) SOURCES/.dif (SUSE) - . () ,
:
user$ cd -_
user$ patch < .dif/patch

, -,
-p1 (. man patch).
SPECS/.spec , RPM. ( RPM- , rpmbuild,
. man rpmbuild!)

13.2.

325

Debian. , Debian, , apt-get source.


user$ apg-get _

:
_.dsc ;
_.orig.tar.gz TAR- ,

;
_.diff.gz ,
Debian Ubuntu;
_/ , _.diff.gz, DIFF- .


,
: ./configure, make make install ( ). .
configure. , , .
, ./configure.
Makefile, ,
. ( ) configure . make.
user$ ./configure

make. .
( ) , .
, . .
user$ make

( ./)
. , ,
, Init-V!
make install.
. , , . . make install ,
! .
root# make install

326

13. , Java Mono


.
-
. ,
configure
.
, configure , , .
, , . ,
Apache mplayer, ,
, .
,
.
,
. gcc ( !),
. README, , .
.
. ,
abc, , ,
RPM DEB . xyz, abc, , ,
, . rpm nodeps -force.
make install,
.
, . , , .

HelloWorld C.
++.
, ,
Hello World ++.
- hello.c:
// hello.c
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
}

13.3. Java

327

:
user$ gcc -o hello hello.c
user$ ./hello
Hello World!

HelloWorld C++. ++ :
// hello.cpp
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}

gcc, g++:
user$ g++ -o hello hello.cpp
user$ ./hello
Hello World!

++
Linux
, KDevelop (KDE) Anjuta (Gnome). Eclipse
Java, , , ++.
UNIX/Linux vi Emacs.

13.3. Java
Java , OpenOffice.
, Java Java, .
Java Linux, -,
Java (Tomcat, Jakarta ..). Java
, ,
, Eclipse, ..
Java (Java SE), Java- javac, Java (JDK), Java (JVM)
JDK 2006 2007 GPL (2).
Java. Java Oracle, , , :
GPL- Sun, . IcedTea OpenJDK.
Java OpenJDK,
, 99%- Java Sun.
Java,

328

13. , Java Mono

-
.
Java. , ,
Linux, , ,
Sun-Java. : JRE 1.5, Java2 Standard
Edition1.5 Java5 Java. .13.1 13.2
, Java. -, ( Oracle )
, .
13.1. Java

JVM

Java ( Java)

JRE

Java ( Java; JVM,


Java)

JDK

Java ( Java-)

Java SE = JSE

Java ( )

Java EE = JEE

Java
( )

Java ME = JME

Java ( )

JavaFX

Java - ( Adobe Flash Microsoft Silverlight)


13.2. Java SE

JRE/JDK

1996

Java 1

1.0

1.0

1997

Java 1.1

1.1

1.1

1998

J2SE 1.2 (Java 2)

1.2

1.2

2000

J2SE 1.3 (Java 3)

1.3

1.3

2002

J2SE 1.4 (Java 4)

1.4

1.4

2004

JSE 5 (Java 5)

1.5

2006

Java 6 SE

1.6

2011

Java SE7

1.7

Java. Java,
, .
openSUSE 12.1. java , ,
Java .
user$ java -version
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.4) (suse-1.2-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

13.4. Mono
.NET-Framework , Java. #, .NET,

13.4. Mono

329

Java . .NET-Framework # - ,
Windows -, (
Microsoft) .
Linux? Linux,
, Microsoft,
, . Mono, ,
# .NET-Framework. Mono
Ximian. Novell, Novell
Mono. ,
Microsoft Novell, ,
(, Novell).
Mono
. , Gnome, Mono. , , Banshee (),
F-Spot ( ) Tomboy ( ), Mono.
Mono .NET-Framework ,
, Linux
, Windows.
Mono ( C# .NET-Framework) http://www.mono-project.com/.

, ,
, Mono . Microsoft, .
, Microsoft Mono. .NET-Framework
Java. ,
# .NET-Framework , , .
Mono Red Hat. , Open
Invention Network,
Mono Fedora. Open Invention Network
, , , , Linux ( Mono). Debian Mono
Squeeze.
, Mono .
Fedora Ubuntu Mono . Mono , .

330

13. , Java Mono

Mono
Mono mono-xxx,
mono-core. C# mcs, Mono, .NET- ( *.dll /usr/lib/mono/gac), Mono (
/etc/mono).
Mono EXE , Java, -. Mono,
EXE- mono.
, Mono
(, , /usr/bin/f-spot).
Mono-
MonoDevelop, Windows
SharpDevelop, .

14

.
Linux. .
,
Linux.
Linux
, ,
/dev/hda /dev/sdc3.
.
Linux.
.
(MBR GPT)
.
, , Linux.
.
,

(/etc/fstab).
Windows Linux ,
, ext3,
ext4, xfs, vfat ntfs.
CD/DVD CD DVD
, .
(USB, FireWire)
Firewire USB-,
, .
, ( )
.
Linux , .

332

14.

RAID RAID ( /

) ,
/ . RAID ,
RAID-0 ( ).
LVM ( LVM) -

. ,
,
..

(, ),
. Linux
;
dm_crypt.
SMART , ,



.
SSD-TRIM TRIM, -

, (SSD),
. SSD
.
, , .
.

,
.. 7.
Linux -

, .
CIFS (Windows/
Samba) (. 20.7) NFS (UNIX/Linux) (. 21).
, ,

.
,
. http://www.tldp.org/HOWTO/
Quota.html.
, ,


.
. Linux
,

14.1.

333

OCFS ( Oracle) GFS (


):

yy http://oss.oracle.com/projects/ocfs2/;
yy http://sources.redhat.com/cluster/gfs/;
yy http://ceph.com/.

14.1.

, , . .
Linux. CD/DVD-,
, RAID
.
. - Linux. - /dev/sda, /dev/sdb .. /dev/
hda, /deb/hdb .. IDE, /dev/sda, /dev/sdb
SATA SCSI.
.
, . -, /dev/sda1
SATA. -
.
() . Linux
() . , (UUID) ,
, ( )
GRUB.
. , ,
, Linux.
/etc/fstab. . Init.
. .
, - ,

,
.

. .

334

14.

, . Windows , (A:, C:, D: ..), Linux .


/.
. /mnt /media, /media/dvd DVD .
/run/media/username/
dvdname.
. , ,

. (,
USB-) .
, mount unmount .
: .
.
. Linux
. :
ext3, ext4 xfs. . ,
, Windows, UNIX Apple.

14.2.

IDE, SATA SCSI. .14.1
.
14.1.

ATA

Advanced Technology Attachment ( )


ATAPI

ATA Packet Interface ( ATA) ATA CDDVD-

IDE

Integrated
Device

Electronics

( ) PATA

PATA

Parallel ATA ( ATA) ATA-


SATA

Serial
ATA

(
ATA
)

ATA

SCSI

Small Computer System Interface ( )


IDE/SATA

14.2.

335


Linux ,
CD DVD,
-. ,
Linux .
- , , , .
. / . , Linux
/data, Windows /media/win.

.
IDE IDE IDE- IDE-DVD/CD. IDE , , -, .
SCSI SCSI SCSI-,
, SATA, USB Firewire.
2007 IDE
SCSI. , libata SCSI PATA. :
, .
libata - IDE-.


, SCSI (
Flash-), /dev/
sdxy /dev/sda, /dev/sdb .. . SATA,

.
68. , , SATA 1 3, /dev/sda /dev/sdb.
2, /dev/sdb /dev/sdc.
libata, IDE- /dev/sda, /dev/sdb ..
IDE ,
IDE (master) , IDE (slave),
/dev/hda /dev/hdc. libata, ,
/dev/sda /dev/sdb!

336

14.

SCSI, ID- .
ID . , SCSI /dev/sda /dev/sdc. SATA, , , : ID-3,
/dev/sdc; 5 /dev/sdd.
, BIOS PCI- ,
.
USB- Firewire- SCSI,
x . , , .
CD- DVD-
/dev/scdn /dev/srn (.14.2).
14.2.

/dev/sda

/dev/sdb

/dev/scd0 /dev/sr0

CD/DVD-

/dev/scd1 /dev/sr1

CD/DVD-

IDE-
IDE- (,
), IDE
- /dev/hda, /dev/hdb .. IDE : /dev/hda IDE-; /dev/hdb IDE-; /dev/hdc /dev/hdd , ,
IDE-. ,
/dev/hda /dev/hdc, /dev/hdb
, , . CD-ROM DVD, IDE, .

(virtio)
Linux virtio,
/dev/vda, /dev/vdb
.. virtio
.
KVM Xen virtio .

14.2.

337

(MBR)
,
. , : MBR,
(Master
Boot Record), GUID (GPT),
GUID .
, EFI (Extensible Firmware Interface,
).
MBR, ,
( IDE SCSI), , 1 4
, 5 .
. ,
, , 1,
2, 5, 6 7. .14.3 .
14.3. (MBR)

/dev/sda

SCSI/SATA ( IDE- libata)

/dev/sda1

/dev/sdd3

SCSI/SATA

/dev/sdd5

SCSI/SATA

/dev/sdd15

SCSI/SATA

, , : -,
,
. -, Linux 59 ( IDE-)
11 (SCSI/SATA/USB/Firewire/IDE libata). ,
63 15.

( GPT)

GPT. , . .
15 . (
, , Linux.
GPT 128!)

!
, 3 1 ( (/dev/
sda1 /dev/sda3).

338

14.

, 500.
/
dev
/
sda
2 /
dev
/
sda
4! MBR

- , /dev/sda1 /dev/sda3 1 .


, SCSI SATA , , .
IDE libata
.
. , .
, , (,
), /dev/disk , .
/dev/disk/by-id/id ID, ,
.
/dev/disk/by-label/label , .
/dev/disk/by-path/path , PCI, . :
USB- Firewire- USB-,
!
/dev/disk/by-uuid/uuid UUID . UUID
ID-, .
,
.
/dev/disk . /dev/disk/
by-label by-uuid, , , UUID. udev
(.7.9). , ls
SATA, USB- CF- ( USB). ,
, .
user$ cd /dev/
user$ ls -lR disk/
disk/by-id:
scsi-SATA_ST3320620AS_5QF194H9
scsi-SATA_ST3320620AS_5QF194H9-part1
scsi-SATA_ST3320620AS_5QF194H9-part2
scsi-SATA_ST3320620AS_5QF194H9-part3
scsi-SATA_ST3320620AS_5QF194H9-part4
scsi-SATA_ST3320620AS_5QF194H9-part5
usb-Generic_USB_CF_Reader_058F312D81B
...

->
->
->
->
->
->
->

../../sda
../../sda1
../../sda2
../../sda3
../../sda4
../../sda5
../../sdc

14.3.

disk/by-path:
pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:1
pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:3
pci-0000:00:1f.2-scsi-0:0:0:0
pci-0000:00:1f.2-scsi-0:0:0:0-part1
pci-0000:00:1f.2-scsi-0:0:0:0-part2
pci-0000:00:1f.2-scsi-0:0:0:0-part3
pci-0000:00:1f.2-scsi-0:0:0:0-part4
pci-0000:00:1f.2-scsi-0:0:0:0-part5

->
->
->
->
->
->
->
->

../../sdc
../../sde
../../sda
../../sda1
../../sda2
../../sda3
../../sda4
../../sda5

disk/by-uuid:
008f06ef-28be-45c9-acbc-20cda51f712b
06efc09c-9a3e-4668-81d7-8925c380889e
366CA8D16CA88D65
e35139a5-5871-48fe-9191-df0d003e4ed5

->
->
->
->

../../sda2
../../sda5
../../sda1
../../sda3

339

14.3.


. , 1980- , 50
, .

, .
-
, , GUID, ( , ).
, , ,
. . ( Linux .)

!
, ! , , ,
mounted.

. Linux . , . , SUSE
YaST- SystemPartition ().
,
.
fdisk parted, gparted.

340

14.

LVM. ,
LVM. LVM
,
,
.

MBR GPT?
: (MBR) GUID (GPT).
MBR ,
2.
GPT :
2 ;
,
Linux, OS X (, , Mac);
EFI Windows7
Windows.
GPT .
, GPT EFI, EFI, , , MBR. : BIOS Linux,
GPT. ( GRUB2
BIOS-GRUB , 15.)

. , ,
, !
GPT, , . ,
Windows .
. Linux ,
MBR, GPT.
( , , ), ,
, . ,
.
, , , . parted mklabel (
: mklabel xxx !):

14.3.

341

root# parted /dev/sda


(parted) mklabel gpt ( GPT)
(parted) mklabel msdos ( MBR)
(parted) quit


, , .
. , , , . -,
, GPartedLive-CD, Parted Magic SystemRescueCd:
yy http://gparted.sourceforge.net/livecd.php;
yy http://partedmagic.com/;
yy http://www.sysresccd.org/.
.
.
, .
.
, !
, .
15. LVM. MBR
,
. ,
3 11.
,
(, ,
Linux), .
, Linux . , ,
. Linux,
.
Windows Vista Windows
MBR- , Windows
2048. , .

342

14.

Linux , 1. ,
Microsoft Windows, , 4.
, 1,
.

, ,
,
.
(512) ,
512.
4, 512. .
(32256) 63, 63512=32256.
, .
. 63,
6.
(8225280, 7,8) .
, Linux,
, 255, ,
25532256=8225280. 255 , 8.
, . , 1
1000000000000=212 , 121600. ( ,
, . ,
, 240=1099511627776,
10% , !)
. ,
SSD. , ,
fdisk, - . ,
Linux ;
( )!
? , .
, Linux, 1024
( df, du fdisk).

14.3.

343


: 4096=4 .
. , , , , 63255,
Linux. Windows Vista Windows
, 63240, 4.

4 ,
.


4
, 512, , 4096 (4). ,
.
4
512.
4 ,
4. 4- , , 2 4. - , ,
.
, 63 ( 63 512). Windows
XP - !
4, .
.
, 63
4- . , WindowsXP
,
. , WindowsXP.
.
Linux Windows , 1.
WindowsXP, ,,
WindowsXP , , . ,

344

14.

512 (, fdisk
), ,
8.

4 http://lwn.net/Articles/377895/.


( MBR-)
, , , Linux, . ,
. 1. , ,
fdisk, parted, Fedora, Red Hat SUSE,
Windows.
, , ,
(2). Debian,
Mandriva Ubuntu.
, . ,
. .
1, ,
. , parted,
,
.
? 2
. , -.
, . - .
, ,
, GPT-.

fdisk (MBR)
Linux, .
, , Linux.

fdisk

, MBR-. fdisk , GPT,

14.3.

345

parted. ,
!

. fdisk
(, /dev/
sdc SATA/SCSI). -l, fdisk .
(menu) ,
. P (print) , .
fdisk , 4. fdisk

DOS Windows, WindowsXP .
, fdisk -c=dos -u=cylinders.
4! , fdisk,
-c -u. fdisk .
. N (new) . .
,
. , , 11 . (,
), fdisk .
, ,
, ( ,
) ( ). +nM +nG
( +50G , 50).
,
P. , , , , ..
. , fdisk,
Linux native ( 83).
, , T
(type). (
):
82 Linux;
83 Linux ( Linux ext, reiser, xfs
..);
8e Linux LVM;
fd Linux RAID.

346

14.

ID-, L.
(MS-DOS, Windows, UNIX ..).
. fdisk
W (write). V
(verify), .
.
512, , ( ).
, fdisk Q (quit) Ctrl+C .

, fdisk

, , ! , ,
mkfs.ext3 ext3. 14.13 ,
.

.14.4 fdisk.
14.4. fdisk

(delete)

(list)

- (menu)

(new)

(print)

( ) (quit)

( )

(unit)

(verify)

(write)

. fdisk . (
) , .
, .
fdisk , ,
. , . , . .
, ,
Linux.
, !

347

14.3.

. , , 4. P . 255 63 182401 512,


1,36. ( ,
, , 1 = 1012, 1,5.
, fdisk, .
, 1 = 210, 1 = 240.)
. 2048, 2048 512 = 1.
48827392 ( 1024). : 48827392 1024 = 46,6.
97656832, 47684 .
1952768 1024, , 1,9.
root# fdisk -c -u /dev/sda
(m ): p
/dev/sda: 1500.3 GByte, 1500301910016 Byte
255 , 63 /, 182401 , 2930277168
= 1 x 512 = 512 Bytes
(/): 512 bytes / 512 bytes
- (/): 512 bytes / 512 bytes
: 0x0004b057
Id
/dev/sda1 * 2048 97656831 48827392
83
Linux
/dev/sda2 97656832 101562367 1952768 82
Linux Swap / Solaris

N , .
. +30G , 30.
(m ): n

e
p (1-4)
p
(1-4): 3
(101562368-2930277167, : 101562368): <return>
101562368
, + +sizeK,M,G (101562368-2930277167,
: 2930277167): +30G
(m ): p
. Id
/dev/sda1 * 2048 97656831 48827392 83
/dev/sda2 97656832 101562367 1952768 82
/dev/sda3 101562368 164476927 31457280 83

Linux
Linux Swap / Solaris
Linux

W . ,

348

14.

.
, .
(m ): w
!
ioctl(), .
:
16: . -
.
partprobe(8) kpartx(8).
.

parted (MBR GPT)


, , fdisk. , ,
. parted
fdisk , GPT.
parted http://
www.gnu.org/software/parted/.
. parted .
H , . H . P
1,5, RAID-.
root# parted /dev/sda
(parted) print
: ATA WDC WD15EARS-00Z (scsi)
/dev/sda: 1500GB
(/): 512B/512B
: msdos

1 1049kB
2 50,0GB
3 52,0GB

50,0GB
52,0GB
84,2GB

50,0GB
2000MB
32,2GB


primary ext4 boot
primary linux-swap(v1)
primary

parted (, 1 = 109).
KiB, MiB, GiB TiB, , , , ,
:
(parted) unit MiB
(parted) print
...
/dev/sda: 1397GiB
...

1 1,00MiB
47684MiB 47683MiB
primary ext4 boot

14.3.

349

2 47684MiB
49591MiB 1907MiB primary linux-swap(v1)
3 49591MiB
80311MiB 30720MiB
primary

. mkpart rm , ,
. mkpart
( ) . ( ,

.) (109), GiB (230 ).
,
. , ,
, ,
, 7 /dev/sda7.

RAID LVM, . : set _ .
boot, swap, lvm raid.
. ,
ext4. 3 , . ( , .)
40.
(parted) mkpart extended 80311MiB -0
:
/dev/sda ( ).
.
(parted) mkpart logical 80312MiB 120000MiB
(parted) print


1
1,00MiB
47684MiB
47683MiB
primary ext4
boot
2
47684MiB 49591MiB
1907MiB
primary linux-swap(v1)
3
49591MiB 80311MiB
30720MiB
primary
4
80311MiB 1430799MiB 1350488MiB extended
lba
5
80312MiB 120000MiB
39688MiB
logical
(parted) quit

sfdisk (MBR)
fdisk parted, sfdisk .

, ,
. sfdisk ,
,
RAID. sfdisk , MBR!

350

14.

. sfdisk-d /dev/sda , sfdisk. | sfdisk, :


root# sfdisk -d /dev/sda | sfdisk /dev/sdb

, sfdisk ,
. , ( dmesg |
grep sdb), sfdisk --force.
, :
root# sfdisk -d /dev/sda | sfdisk --force /dev/sdb
root# reboot

--force , sfdisk ,
. Linux

.

gparted (MBR, GPT)


parted gparted (.14.1).
, , . , . gparted
Linux.

.14.1. gparted

14.3.

351

parted, gparted ,
. EditCancel () , EditDone () .
SUSE gparted YaST
. , ,
.

Gnome Disks (MBR GPT)


Gnome Disks ,
( , /etc/fstab). Gnome3.6, Gnome Disks
Palimpsest, Gnome. Gnome
Disks (.14.2),
, Palimpsest. Gnome Disks gnomedisk-utils, .

.14.2. Gnome Disks

352

14.

. ,
Gnome Disks
. ,
(, none).
, ,
. .
RAID, LVM ..

14.4.
,
Linux. ext2ext4, xfs, vfat,
ntfs iso9660 . ,
, df -T.

Linux
Linux Linux .
, . , ls cp,
. .
, , , , .
: ,
, , ,
(, ), ( ), NFS, ,
(ACL), SELinux ..
ext Linux ext2
( 2). 2002
ext3, ext2,
, 2.6 ACL.
2, 8. 2008 ext4, ext3,
, . ,
1 (1048576), ,
- .
btrfs , ,
btrfs Linux . Oracle
.

14.4.

353

, ,
RAID. zfs, Sun.
, btrfs .
xfs xfs
SGI, IRIX. Xfs
, ,
.
(ACL).
reiser ,
(Hans Reiser) , Linux. 3.n SUSE
. reiser
ext3 . , , reiser . 4, ,
3 .
jfs JSF Journaled File System ( ). IBM,
Linux. Jfs Linux
,
. http://
jfs.sourceforge.net/.

, . ext4 , . ext3
, , ,
(, ,
Windows Linux).

UNIX
UNIX- , ( )
.
sysv SCO, Xenix Coherent.
ufs FreeBSD, NetBSD, NextStep SunOS. Linux
, . BSD
BSD disklabel.
SunOS.
ZFS , Sun Solaris.
ZFS GPL,
Linux. Linux
, FUSE. : http://
zfs-fuse.net.

354

14.

Windows, Mac OSX


MS-DOS,
Windows, OS/2 Macintosh.
vfat Windows 9x/ME. Linux
. vfat MS-DOS (8+3).
ntfs Windows: NT . Linux
.
hfs hfsplus Apple.
Linux , ,
, OSX . , ,
OSX
Linux.

CD-ROM/DVD
CD DVD .
iso9660 CD-ROM ISO-9660, . -, . Linux
Rockridge, UNIX,
Joliet, Microsoft.
udf ( )
ISO 9660.



. Linux , .
nfs UNIX (Network File System).
smbfs/cifs Windows Samba .
sshfs . , SSH.
coda NFS. , .
ncpfs NetWare, Novell
Netware.

14.4.

355


Linux , ( ), . /proc/filesystems nodev.
.
devpts ( PTY) /dev/pts/* UNIX-98.
( . UNIX/
Linux ,
xterm. , , , /dev/ttypn.
UNIX-98, , .)
proc sysfs proc , .
sysfs .
/proc /sys.
tmpfs
System V. /dev/shm .
/var/run /var/lock tmpfs. ,
, . tmpfs
RAM. ,
, /var/run /var/lock
.
usbfs usbfs, 2.6 , USB-. proc.


, .
auto .
auto /etc/fstab mount
. Linux
.
.
autofs, autofs4 , , mount .
,
umount.

356

14.

, NFS- .
/etc/init.d/autofs
automount. /etc/
auto.master. ,
, Red Hat Fedora. autofs
/etc/auto.master /etc/auto.misc.
: http://tldp.org/HOWTO/Automount.html.
cgroup (Control Groups)

.
Cgroup
Cgroup.
http://www.kernel.org/doc/Documentation/cgroups/cgroups.txt.
cramfs squashfs Cram Squash
. ,
Flash- (
).
fuse FUSE Filesystem in Userspace ( ). . , FUSE
. FUSE , , NTFS ntfs-3g.
gfs ocfs Global File System ( ) Oracle Cluster
File System ( Oracle) ,
.
jffs yaffs Journaling Flash File System (
Flash-) Yet Another Flash File System (
Flash-)
Flash-. (
), .
loop .
(loopback device) ,
.
,
mount. loop.
. ,
(Initial RAM disk) GRUB LILO,
ISO-
CD.

14.5. (mount /etc/fstab)

357

none , none .

.
mount /etc/fstab none, bind.
, . , ,
NFS4.
unionfs/aufs unionfs aufs , , , . unionfs aufs
, Linux CD DVD.
CD/DVD, ,
.
, CD/DVD , .
Linux .
(, CryptoFS
eCryptfs).
,
, /proc/filesystems.
,
lib/modules/n/kernel/fs/.

filesystems . ,
HOWTO . ,
2000!
http://www.kernel.org/doc/Documentation/filesystems/;
http://www.tldp.org/HOWTO/Filesystems-HOWTO.html.

14.5.
(mount /etc/fstab)
, ,
.
, .
CD DVD ,
.
.

358

14.

mount umount, /etc/fstab.


mount umount ,
( )
. , ,
, ,
(Gnome
KDE).
/etc/fstab ,
. /etc/fstab Linux.
, . .
,
, mount /etc/fstab . YaST
(SUSE), Gnome
Disks.
, USB-
Firewire. .
, , 14.12.

df. ,
Linux, df. ,
, ..,
.
mount. . .
,
.
user$ mount
/dev/mapper/vg-ubuntu on / type
/dev/mapper/vg-myhome on /myhome type
/dev/mapper/vg-virt on /virt type
/dev/sda3
on /boot type
cgroup on /sys/fs/cgroup type
proc on /proc type
udev on /dev type

ext4 (rw,errors=remount-ro)
ext4 (rw)
ext4 (rw)
ext3 (rw)
tmpfs (rw,relatime,mode=755)
proc (rw)
devtmpfs (rw,mode=0755)

14.5. (mount /etc/fstab)

359

tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,...)


none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,...)
none on /run/shm type tmpfs (rw,nosuid,nodev)
...

, mount,
/etc/mtab /proc/mounts.
, , mount. /etc/mtab
,
. mtab , /etc/fstab
(. ). /proc/mounts, , ,
/etc/fstab mount.


(mount umount)
Linux ,
mount : Linux
. CD/DVD KDE
Gnome. , , mount,
.
mount :
mount [options] device directory

[-t xxx].
(.14.2). ,
. ( !
mkdir.)
, mount .
/etc/fstab ( user users).
. , mount. Windows-9x/ME
/windows:
root# mkdir /windows
root# mount -t vfat /dev/sda1 /windows

CD-ROM c ( ISO-9660) /media/cdrom .


/dev/scd0 , SCSI- .
/dev/sr0.
root# mount -t iso9660 /dev/scd0 /media/cdrom

360

14.

CD-ROM ( , ,
) /etc/fstab, :
root# mount/media/cdrom

Remount. mount o remount


. ,
exec DVD ,
DVD:
root# mount /media/dvd -o remount,exec

, . ,
, /etc/fstab,
.
.
root# mount -o remount,rw /

,
.
unmount. ,
umount:
root# umount /media/dvd


(/etc/fstab)
, CD ,
mount .
, /etc/fstab: , . fstab
,
.
. fstab
:
# /etc/fstab
/dev/sda2 /
ext4 defaults
none
/proc proc defaults
...

1
0

1
0

, . , Linux, sda2
, Linux!

14.5. (mount /etc/fstab)

361

. , /proc,
,
.

/etc/fstab
, fstab:
(,
).
.
. 14.2.
, Linux Windows, CD-ROM ..,
.
( Red
Hat Fedora) ( Ubuntu).
LABEL=string UUID=nnn-nnn.
blkid .
, tune2fs.
root# blkid /dev/sda9
/dev/sda9: UUID="5a954fc1-00c6-4c25-a943-d4220eff350d" TYPE="ext4"

UUID
, , . USB. , ,
/dev/sdc,
/dev/sde.
, fstab ,
. ,
, Linux.
,
.
. , ,
, fstab .
. ,
. , ,
. , , , ,
, , .
. . .14.5
.
, . ,

362

14.

CD/DVD- iso9660,udf, CD DVD,


, . mount , . , !
14.5.

auto

(CD-ROM, )

brtfs

brtfs

cifs

Windows (Samba)

devpts

, UNIX-98

ext2, -3, -4

ext 2, 3 4

iso9660

CD-ROM, DVD

nfs

UNIX (NFS)

ntfs

Windows

proc

(/proc)

reiserfs, reiser4

reiser 3.n 4

smbfs

Windows (Samba)

swap

sysfs

(/sys)

tmpfs

System V (
)

udf

(DVD, CD-RW)

usbfs

USB-

vfat

Windows-9x/ME

. . ,
. . .14.6 mount. ,
defaults.
14.6. mount

defaults

dev

discard

SSD-Trim (ext4, btrfs, xfs swap)

exec

(, CD/DVD-)

noauto

nodev

noexec

nosuid

suid guid

ro

( )

sw

( )

suid

suid guid

14.6.

363

sync

, (,
)

owner

(u)mount

user

mount,
, mount

users

(u)mount

. dump,
. 1, 0.
. ,
, , .
1 0 . ,
.
, ,
2. ,
, 0 (,
Windows, CD-ROM, DVD, , , .).
/etc/fstab ,
, .

14.6.
ext2, ext3,
ext4, btrfs xfs. ,
, .

. , ,
. ,
. ,
(
, ).
,
. ,
.
, , . ( ), ,
.

364

14.

,
. ,
,

. ,
.

,


.
: ,
, .
,
( , ). ,
.
, , .
, , ,
. : http://lwn.net/Articles/191352/.
: , .
, UPS ( ),

.


Linux ,
, ,
, /etc/fstab (
, /etc/fstab .
/etc/fstab ).
.
, ( ext)
-
. ,

mount.

14.6.

365

, . , , , :
- ,
. , (
1) ,
( ) 1 1015. ,
. ,
81012 , , -
.
, , ( ,
, ).
, , , .
,
, . ,
, , :
http://lwn.net/Articles/190222/;
http://lwn.net/Articles/196292/.
.
.
,
. ,
. . , .
, ,
.


, fsck.
,
unmount.
,
unmount. touch/forcefsck .

366

14.

, forcefsck shutdown
-F.
/forcefsck , .
, (Knoppix) fsck .


,
. , , ,
glibc . glibc LFS (LFS ). , Linux,
263 . ,

( ). .14.7
. , 1=1024.
14.7.

brtfs

16777216

16777216

ext3

32 ( 8)

ext4

16

1048576 ( 1)

reiserfs

16

reiser4

xfs

9437134

9437134

ZFS

16777216

16777216

, ext4
16 e2fsprogs ( 1.42).


, (, ext3 reiserfs).
.

14.7. ext (ext2, ext3, ext4)


Linux ext. .

367

14.7. ext (ext2, ext3, ext4)

ext, ext,

Linux ( 1992).
2.
ext2 Linux 1993 2001.
8.
, ext3,
( 2.6
). ext3 2002
: ext2
, ext3
. unmount,
ext2.
2008 , ext4, ext4 .
:
1 (1048576),
, . ,
. ,
: ,
, ext3.
: ext3 ext4
. ,
!
ext ,
2, (, tune2fs).
ext4 ext, , .
, ext5, ext4 . , ,
. lwn.net
, :
http://lwn.net/Articles/469805.
/etc/fstab. /etc/fstab, ext3 ext4,
, .
# /etc/fstab: Linux
/dev/sdb8
/
ext4
defaults
/dev/sdb9
/boot ext3
defaults
/dev/sdb9
/data ext4
acl,user_xattr

1
0
0

1
0
0

GRUB. GRUB0.97 ext4! , ext4,


GRUB0.97 (, , openSUSE 12.1, RHEL 6
Fedora11) GRUB2.

368

14.

GRUB0.97 ext4,
ext2
ext3!

ext (3 ) .

, , .
, .
,
. ( ) .
ext .
data=ordered ,
, , . ,
. , ,
. .
data=ordered 5
. ext3
. ,
:
. ext3
data=ordered : fsync ,
. .
ext4 5, , . ,
fsync (, ext4 fsync ,
).
data=writeback ordered. ,
. ,
. . , . ,
POSIX fsync.

14.7. ext (ext2, ext3, ext4)

369

data=journal ,

, . ( , ),
ext3 . ,
, .

5. commit
mount. laptop-mode , commit .
kjournald,
. , mount
ext3 ext4.


ext4, ,
,
(, brtfs, HFS+, reiser4, xfs ZFS). ,
,
. : -,
,
. -, ,
, .
, :
, ( )
,
. ext4 ,
,
.
. ( , . ,
.)
, ext, ,
, fsync.
POSIX
, . , ext4, : rename
ftruncate ( ), ext4 . , nodelalloc mount. ,

370

14.

ext4 .
, . ,
. : , ,
!
http://tytso.livejournal.com/tag/filesystems/ ext ;
http://lwn.net/Articles/322823/ ext4;
http://lwn.net/Articles/326471/ ext3/ext4, fsync;
http://lwn.net/Articles/327601/ Linux Storage and File
system Workshop.



mount /etc/fstab, :
ext3 2.6.29 data=ordered;
ext3 2.6.30 data=writeback;
ext3 2.6.36 data=ordered;
ext4 data=ordered .
ext3
2.6.30 . ,
. ,
, ext3 , data=ordered.
, 2.6.36,
.
,
, .
ext3, ext4.
root# dmesg | grep EXT
EXT3 FS sda3,
EXT3-fs: , data=ordered
...
EXT4-fs (sda4): , data=ordered

,
mount /etc/fstab data=xxx. ext4
nodelalloc.

. ext2, ext3 ext4 mkfs.ext2, mkfs.ext3 mkfs.ext4.

14.7. ext (ext2, ext3, ext4)

371

20 (
, LVM) ext4. mke2fs
4 ,
1310720. , 1,3 . ,
16. , -i n,
( n, , , ). ,
.
, mkfs.ext4 .
root# mkfs.ext4 /dev/mapper/vg1-test
mke2fs 1.41.4 (12-Jun-2012)
=
: Linux
=4096 (log=2)
=4096 (log=2)
1310720 , 5242880
262144 (5.00%)
=0
=4294967296
160
32768 , 32768
8192
, :
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
:
(32768 ):
:

ext3 ext4.
ext3 ext4, , . tune2fs
; ext4,
. mount -o
remount .
root# tune2fs -O extents /dev/sda5
root# umount /dev/sda5
root# mount /dev/sda5 /home

ext3
( ).
e4defrag,
.
. ext
, mount ( 36)

372

14.

(6) ,
. mount, , 0 ( ). , fstab (
), (
fstab . /etc/fstab 14.5).
, - . -, . -, ,
.
, ,
.
, fsck.ext2/ext3/ext4. , unmount.
root# fsck.ext4 -f /dev/mapper/vg1-test
...
/dev/mapper/vg1-test: 21357/1310720 (1.3% ),
2062135/5242880

, .
/lost+found ,
. , ,
, .
.

tune2fs. -c
mount, i
:
root# tune2fs -l /dev/mapper/vg1-test
...
Mount count:
1
Maximum mount count:
35
Last checked:
Wed Jul 15 11:45:54 2009
Check interval:
15552000 (6 months)
...
root# tune2fs -c 100 -i 90 /dev/mapper/vg1-test
100
7776000

tune2fs -c 0 -i 0 .
. e2label ,
ext3 (
):
root# e2label /dev/sda1 mylabel

14.7. ext (ext2, ext3, ext4)

373

/etc/fstab
.
.
(UUID),
, blkid.
tune2fs -U. ,
umount .
root# tune2fs -U random /dev/sda1 ( UUID)
root# tune2fs -U f7c49568-8955-4ffa-9f52-9b2ba9877021 /dev/sda1
( UUID)

. resize2fs
ext. , ,
,
, . lvextend.
root# lvextend -L 40G /dev/mapper/vg1-test
40,00
,
root# resize2fs /dev/mapper/vg1-test
resize2fs 1.41.4 (27-Jan-2009)
/dev/mapper/vg1-test /test;

old desc_blocks = 2, new_desc_blocks = 3
/dev/mapper/vg1-test
10485760 (4k) .
/dev/mapper/vg1-test 10485760 .

, . ,
, ,
16, ( ,
RAID). ,
.
.
, , , .
, , , .
.
ext2/3/4 , , .
, , ,
90%.
,
ext.
ext4 . .

374

14.

ext2 ext3 Windows.


, Linux, Windows. , ,
http://wiki.ubuntuusers.de/Linux-Partitionen_unter_
Windows.

14.8. btrfs
, btrfs Linux, . , btrfs
Linux, . btrfs
Oracle, . btrfs ( ) GPL.
. btrfs:
: , .
;
,
() ;
RAID-0, 1 10;
;
(mount- compress);
(mount- ssd);
.
, 2012 . :
RAID-5 6, , ,
(, ).
(subvolumen), (snapshot) RAID (
) btrfs,
( Multi Device (
) Logical Volume Manager ( ) . 14.14 14.15).
, btrfs . ?
, RAID

. btrfs , btrfs ,
LVM.
. , btrfs - , Oracle SUSE -

14.8. btrfs

375

btrfs !
btrfs
. , mount
. btrfs
,
btrfs - (http://dir.gmane.org/gmane.comp.file-systems.btrfs)!
, 2012 btrfsck,
.
.
:
https://btrfs.wiki.kernel.org/index.php/FAQ;
https://btrfs.wiki.kernel.org/index.php/Gotchas;
https://btrfs.wiki.kernel.org/index.php/Problem_FAQ.

,
btrfs .
,
.
. ext4, btrfs , ext4 .
. ,
btrfs
. ,
btrfs .
: https://btrfs.wiki.kernel.org/
index.php/Main_Page.
GRUB. GRUB0.97 btrfs. GRUB2, ,
btrfs 1.99,
btrfs. , GRUB2
extn.

btrfs , , btrfs.
mkfs.brtfs brtfsck, btrfstools, btrfs-progrs btrfsprogs.
brtfs ,
, , .
brtfs. btrfs , ( , , /dev/sdb1 ):

376

14.

root# mkfs.btrfs /dev/sdb1


fs created label (null) on /dev/sdb1
nodesize 4096 leafsize 4096 sectorsize 4096 size 20.00GB
Btrfs Btrfs v0.19

:
root# mkdir /media/btrfs
root# mount /dev/sdb1 /media/btrfs

. btrfs
,
( ).
btrfs,
( , !). , .
btrfs (
, lvextend) :
root# btrfs filesystem resize max /media/btrfs

max
+ -.
k, m g. , , ,
.
2:
root# btrfs filesystem resize -2g /media/btrfs

. , btrfs btrfsck.
, .
, btrfs.
root# btrfsck /dev/sdb1

ext3/ext4 btrfs. btrfs-convert ext3 ext4 btrfs. , btrfs, .


, ext4 /dev/
sdb1.
root# fsck.ext4 -f /dev/sdb1
root# btrfs-convert /dev/sdb1
btrfs.
ext2fs.
.
.
root# mount /dev/sdb1 /media/btrfs

14.8. btrfs

377

btrfs-convert ext2_saved, ext . , btrfs ext! ( , , ,


btrfs ,
.)
root# umount /dev/sdb1
root# btrfs-convert -r /dev/sdb1

btrfs,
ext2_saved.
btrfs, .
root# btrfs subvolume delete /media/btrfs/ext2_saved


https://btrfs.wiki.kernel.org/index.php/Conversion_from_Ext3.
. btrfs
.
mount- compress=zlib compress=lzo.
compress .
, .
,
. zlib,
, lzo, ,
. ( . http://
lwn.net/Articles/411577/). , lzo-
.
compress .
,
.
, . ,

. , , .
,
compress.
, ,
.
compress , (, /usr/;
50%).
, , , (, - , PDF OpenOffice).
. btrfs,

378

14.

.
.

compress ,
. , mount . openSUSE ,
compress=zlib 3,5 1,8!
, . , ,
MySQL InnoDB,
(
MySQL), MySQL ( , /var/lib/mysql)
btrfs compress.

, ,
( ) . btrfs
: (subvolumen)
btrfs mount-.
. .
, btrfs /dev/
sdb1 /media/btrfs.
btrfs subvolume create : sub1 data/
sub2. mount subvol=name .
root#
root#
root#
root#

btrfs
btrfs
mkdir
mount

subvolume create /media/btrfs/sub1


subvolume create /media/btrfs/data/sub2
/media/sub{1,2}
-o subvol=sub1 /dev/sdb1 /media/sub1

mount -o subvol=name ,
btrfs.
- , btrfs subvolume list,
mount- subvolid:
root# btrfs subvolume list /media/btrfs
ID 257 top level 5 path sub1
ID 258 top level 5 path data/sub2
root# mount -o subvolid=258 /dev/sdb1 /media/sub2

/media/sub1 /media/sub2 .
btrfs, sub1 data/sub2,
btrfs subvolume create.

14.8. btrfs

root#
root#
tst1
root#
root#
tst2

379

touch /media/sub1/tst1
ls /media/btrfs/sub1
touch /media/sub2/tst2
ls /media/btrfs/data/sub2

:
, , btrfs.
, . btrfs subvolume setdefault ,
mount, subvol subvolid mount. set-default ID , btrfs subvolume list.
, /media/btrfs sub1:
root# btrfs subvolume set-default 257 /media/btrfs/
root# umount /media/btrfs
root# mount /dev/sdb1 /media/btrfs ( sub1)

btrfs? ,
5. ( btrfs subvolume-list,
, 5 .)
root# btrfs subvolume set-default 5 /media/btrfs/
root# umount /media/btrfs
root# mount /dev/sdb1 /media/btrfs ( )

. btrfs subvolume delete name, name ,



. , .
root# umount /media/sub2
root# btrfs subvolume delete /media/btrfs/data/sub2

, , ,
btrfs subvolume delete name, . .


(snapshots) btrfs
.
, .
,
.

380

14.

, btrfs . ( , .)
, , . , . , ,
.
.
, .

(, ) .
, , .
btrfs . subvolume- btrfs ,
. , ,
, , (
, ,
.)
btrfs LVM. btrfs (LVM) . LVM
.
,
. , ,
. , , , .
, btrfs ! , ,
, .
.
, .
btrfs btrfs- .
, . , , LVM!
. ,
.
.
, .

14.8. btrfs

381

, (btrfs subvolume set-default),

. , ,
Fedora Yum- (yum-plugin-fs-snapshot).
,
btrfs . ,
.
,
btrfs , :
yy http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg03484.html;
yy http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg05334.html;
yy http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg04968.html.
. btrfs, /dev/sdb1. /media/btrfs. btrfs subvolume snap
. /media/btrfs/snap1.
mount
. mount subvol=name, .
root# btrfs subvolume snapshot /media/btrfs/ /media/btrfs/snap1
root# mkdir /media/snap1
root# mount -o subvol=snap1 /dev/sdb1 /media/snap1/

,
( ).
, .
, btrfs .
, btrfs subvolume snapshot -r.

btrfs
, RAID
btrfs
( ), RAID- 0, 1 10,
Linux mdadm, RAID
( ).
btrfs RAID-5 RAID-6.


, , ,

382

14.

. ( ). . ,
btrfs .
root# btrfs device add /dev/sdb2 /media/btrfs

, .
( ),
btrfs filesystem balance
. , btrfs
filesystem balance
.
root# btrfs filesystem balance /media/btrfs

, . , , ,
:
root# btrfs device delete /dev/sdb1 /media/btrfs/

, 2012 ( 3.5), btrfs device delete


invalid

argument

( ). . , .

mkfs.btrfs
btrfs .
mkfs.btrfs :
root# mkfs.btrfs /dev/sdb1 /dev/sdc1

( RAID-1), .
,
, . ,
( , RAID-0, ). , ,
RAID-1, .
mount
. ( btrfs
device scan, btrfs,
btrfs .)
root# mount -t /dev/sdb1 /media/btrfs

14.8. btrfs

383

, RAID , btrfs filesystem:


root# btrfs filesystem df /media/btrfs
Data, RAID0: total=1.56GB, used=128.00KB
System, RAID1: total=8.00MB, used=4.00KB
Metadata, RAID1: total=1.00GB, used=24.00KB
...

RAID-0
RAID,
, , RAID mkfs.btrfs -d ( ) -m (
). , mkfs.btrfs .
RAID-0 ( ):
root# mkfs.btrfs -d raid0 -m raid0 /dev/sdb1 /dev/sdc1

RAID-1
RAID-1:
root# mkfs.btrfs -d raid1 -m raid1 /dev/sdb1 /dev/sdc1

.
, /dev/sdc.
, mount-
degraded:
root# mount -o degraded /dev/sdb1 /media/btrfs

RAID, , , .
/dev/sdc1,
. , , RAID-1,
btrfs filesystem balance. ,
. ,
(
).
root# btrfs device add /dev/sdc1 /media/btrfs
root# btrfs filesystem balance /media/btrfs


.
missing:
root# btrfs device delete missing /media/btrfs

mount
degraded.

384

14.

,
btrfs (df)
df -h ,
,
. btrfs
df , RAID.
.
btrfs df ,
(, ,
RAID).
, btrfs
RAID.
btrfs : ( ), (
,
) (,
).
btrfs
, , , . ,
btrfs . .
, btrfs, filesystem show filesystem df,
, .

, btrfs.
btrfs-RAID-1, ,
8. /usr ( 2,1 ).
root# mkfs.btrfs -d raid1 -m raid1 /dev/sdb1 /dev/sdc1
root# mount /dev/sdb1 /media/btrfs
root# cp -r /usr /media/btrfs

df
df . , df
, btrfs RAID-1.
. , df ,
btrfs.
root# df -h /media/btrfs/
. %
/dev/sdb1
16G
3,7G
12G
25%
/media/btrfs

14.8. btrfs

385

filesystem show
btrfs filesystem ,
, 8.
, , , 1,9.
, ,
3,5 . filesystem show ,
(, RAID
). ,
( RAID-0 16, RAID-1 8).
root# btrfs
Label: none
Total
devid
devid

filesystem show /dev/sdb1


uuid: dc691a5d-187e-4cb4-a94a-d12dabdffde4
devices 2 FS bytes used 1,89GB
1 size
7.81GB used 3,53GB path /dev/sdb1
2 size
7.81GB used 3,54GB path /dev/sdc1

filesystem df
filesystem df ,
. btrfs 3, 1,6 .
, btrfs 512 190. , 32 btrfs
, 4. 3,00 + 0,5 +
+0,03 = 3,53, filesystem show.
root# btrfs filesystem df /media/btrfs/
Data, RAID1: total=3.00GB, used=1.62GB
System, RAID1: total=32.00MB, used=4.00KB
System: total=4.00MB, used=0.00
Metadata, RAID1: total=512.00MB, used=191.02MB
Data: total=2.61GB, used=1.70GB
Metadata: total=1.01GB, used=198.82MB
System: total=12.00MB, used=4.00KB

?
, 16. - ,
RAID-1, , 8. 3,53.
, , , 4,3 7. 1,6 7. , , ,
, 5,4.
, btrfs .
, .
btrfs RAID-5 RAID-6,
. btrfs

386

14.

, btrfs , ,
. :
btrfs, .

14.9. xfs
xfs 1994 SGI
, UNIX- IRIX.
Linux,
( 2.6 ). , , , () . xfs :
man xfs;
http://en.wikipedia.org/wiki/XFS;
http://xfs.org/index.php/XFS_FAQ.

xfs . -, xfs
xfs_growfs, . -,
, , Linux,
. GRUB xfs
! GRUB,
.

/etc/fstab. /etc/
fstab , .
mount . man mount.
# /etc/fstab
/dev/sdb13
/data

xfs

defaults

xfs.
xfs, mkfs.xfs:
root# mkfs.xfs /dev/sdc1
meta-data=/dev/sdc1
isize=256
=
sectsz=512
data
=
bsize=4096
=
sunit=0
naming
=version 2
bsize=4096
log
=internal log bsize=4096
= sectsz=512 sunit=0 blks
realtime =none
extsz=65536

agcount=16, agsize=152742 blks


attr=0
blocks=2443872, imaxpct=25
swidth=0 blks, unwritten=1
blocks=2560, version=1
blocks=0, rtextents=0

mount
.
root# mount -t xfs /dev/sdc1 /test

14.10. Windows (VFAT, NTFS)

387

. xfs mount (
). , xfs_check. , .
,
xfs_repair.
, fsck.xfs. ,
OK.
. xfs_growfs
xfs ( !). ,
, , .
xfs_admin ,
(Label) .
(unmount).

14.10. Windows
(VFAT, NTFS)
Linux
Windows. (USB-,
) Windows.
, , Linux, ,
Windows, ,
.
. , Windows.
FAT, VFAT, exFAT FAT.

FAT12 , FAT16
2, FAT32 8
4.
Windows95 VFAT,
FAT , 8+3,
MS-DOS. Unicode. Windows
( ) .
, -
.
Windows, , FAT32 VFAT (VFAT32). , VFAT
( mount/fstab ),
FAT12/16/32 VFAT.

388

14.

FAT exFAT,
Flash-.
16777216,
. Linux
- (http://
code.google.com/p/exfat/), Tuxera (http://
tuxera.com/). - , ,
exFAT , , .
NTFS (New Technology File System) WindowsNT Windows. FAT, NTFS ( , ..),
.
(16777216).
Linux. Linux (V)FAT NTFS
. exFAT
Linux ,
.

Windows ,
, Windows (
)
Linux
. .

Linux Windows,
. mkfs.vfat VFAT, mkfs.ntfs NTFS ( mkfs.ntfs
ntfsprogs, ).
.
Linux Windows ,

.
.
. VFAT . NTFS
, , UNIX/Linux.
: Linux Windows? uid, gid umask/
fmask/dmask. , Windows
, , NTFS.

VFAT
.
VFAT: FAT
(FAT12/-16/-32). Windows Linux

389

14.10. Windows (VFAT, NTFS)

-1 (ISO8859-1). , mount ,
, .
, .
/etc/fstab. , /etc/fstab VFAT :
# /etc/fstab
/dev/sda1
/media/win1

vfat

utf8,uid=1000

0 0

: 1000
, , Windows
( 8+3), Linux UTF-8.
fstab Windows
(noauto). users mount. , Windows , , , .
# /etc/fstab
/dev/sda1
/media/win1

vfat

noauto,users,gid=users,utf8

NTFS (ntfs-3g)
NTFS- Linux. ntfs-3g.
, . ,
, ( ).
ntfs-3g .
, ntfs-3g , FUSE-. FUSE Filesystem in Userspace
( ). , . , FUSE .
/etc/fstab. , fstab,
NTFS , :
# /etc/fstab
/dev/sda1
/media/win

ntfs-3g

uid=1000,gid=1000

0 0


NTFS ( ntfs-3d).
. NTFS: NTFS
.
. .
ntfs-3g streams_interface
. xattr

390

14.

. get setfattr attr.


getfattr -d -e text , .
root# mount /dev/sda1 /media/win
root# cd /media/win
root# cat > streamtest
abc (Ctrl)+(D)
root# setfattr -n user.stream1 -v "efg" streamtest
root# setfattr -n user.stream2 -v "xyz" streamtest
root# cat streamtest
abc
root# getfattr -d -e text streamtest
# file: streamtest
user.stream1="efg"
user.stream2="xyz"
root# cd
root# umount /media/win

, streams_interface=windows. Windows _:_.


root#
root#
root#
abc
root#
efg

mount -o streams_interface=windows /dev/sda1 /media/win


cd /media/win
cat streamtest
cat streamtest:stream1

. ntfsprogs , NTFS (.14.8).


14.8. ntfsprogs

mkntfs

NTFS

ntfsclone

NTFS

ntfsinfo

NTFS

ntfslabel

NTFS

ntfsresize

NTFS

ntfsundelete

14.11. CD, DVD,


CD DVD
CD DVD
. : -,
, . -,

391

14.11. CD, DVD,

CD DVD : ISO9660
UDF.
ISO9660 UDF. .
ISO9660 CD . , . UNIX Rockridge
.
Windows Joliet
Unicode. El-Torito
CD.
UDF ( ) ISO9660. DVD ( ISO9660). ISO9660 , 2,
-
Unicode 255, RW- ( ) ..
CD/DVD. .14.9 ,
CD/DVD.
, (IDE, SCSI, SATA, USB Firewire)
libata. , /dev/
scd0. , , /dev/hda,
/dev/hdb .. , - /dev/cdrom, /dev/dvd
/dev/dvd-recorder. -.
14.9. CD/DVD

/dev/scd0 /dev/sr0

CD/DVD

/dev/scd1 /dev/sr1

CD/DVD

.
, CD
DVD ,
. CD/DVD,
.
Linux KDE Gnome.
. ,
CD/DVD,
, . , ,
.
root# mount -t iso9660 -o ro /dev/scd0 /media/dvd
root# mount -t udf -o ro /dev/scd0 /media/dvd

(ISO9660-CD/DVD)
(UDF-DVD)

.
, CD

392

14.

DVD, exec. , iocharset=utf8 utf8.


CD/DVD, unmount:
root# umount /media/dvd

unmount eject. CD
, . , (CD, DVD, ),
: .
, .

Device is busy ( ). unmount


Device is busy ( ), , CD-ROM . , - . cd,
. , - , fuser fuser -m
/cdrom.
NFS: CD-ROM
NFS , unmount
, .
NFS- () .
/etc/fstab. , /etc/fstab ,
CD/DVD- ( ).
CD/DVD , .
:
# /etc/fstab
/dev/scd0
/media/dvd

udf,iso9660

users,noauto,ro

mount /media/dvd mount /media/dvd,


CD/DVD .
.

AudioCD, VideoDVD
AudioCD. AudioCD CD .
mount, (, KDE Gnome Amarok
Rhytmbox ). (, Ogg-Vorbis).
VideoDVD. , VideoDVD UDF.
CD DVD. CD DVD KDE K3B,
Gnome Brasero, wodim.

14.12. (USB, Firewire .)

393

Linux .
, ,
mount
.
/dev/fd0. .
MS-DOS/Windows VFAT.
root# mount -t vfat /dev/fd0 /media/floppy

mtools (, mcopy mdir)


MS-DOS/Windows mount.
fdformat . , mkfs.vfat.

14.12.
(USB, Firewire .)
USB-, , Firewire
eSATA, :
, .
SCSI.
. (KDE, Gnome)
: ( ),
.
, ,
.

,
! Eject (), Safely Remove ( )
. , ,
. ,
!

KDE Gnome ,
. , , ,
. - ( ),
.
, ,
!

394

14.

.
, udev, D-Bus
PolicyKit. , , supermount,
magicdev subfs/submount, .
. , ,
mount. , ( , /dev/sdx, x ).
( ,
CD DVD) fdisk -l. /dev/sdf1
USB-.
root# fdisk -l
...
/dev/sdf: 256 MB, 256901120
16 , 32 /, 980
= 512 * 512 = 262144
Device
Boot
Start
End
Blocks
Id
/dev/sdf1
*
1
980
250864
e

System
W95 FAT16 (LBA)

USB- Superfloppy.
, .
/dev/sda (
/dev/sda1, ).
, : mount:
root# mkdir /media/memorystick
root# mount /dev/sdf1 /media/memorystick


. USB- VFAT.
.
, unmount . USB Firewire,
unmount, !
root# umount /media/memorystick

/etc/fstab. mount.

, fstab users. USB-
VFAT :
# /etc/fstab: USB-Stick
/dev/sdf1 /media/memorystick

vfat

users,gid=users,utf8,noatime,noauto 0 0

395

14.13.

USB- mount /media/memorystick,


, . .
, ,
. USB-
, , , /dev/sdg
/media/memorystick .
, fstab
, , , .
, /etc/fstab , by-uuid. UUID,
blkid:
root# blkid /dev/sdf1
/dev/sdf1: UUID="4550-9BD2" TYPE="vfat"

fstab , :
# /etc/fstab: USB-Stick
/dev/disk/by-uuid/4550-9BD2 /media/memorystick vfat \
users,gid=users,utf8,noatime,noauto 0 0

fstab UUID=4550-9BD2.
mount , , unmount
: UUID mount
/etc/mtab . unmount
/etc/fstab /etc/mtab , .

14.13.

, Linux
( ). , Linux
, RAM.
. ,
, , (
), free.
1519 RAM 2000 . ,
, 401 RAM , ().
.
root# free -m
Mem:

total
1519

used
1479

free
39

shared
0

buffers
67

cached
1010

396
-/+ buffers/cache:
Swap:
2000

14.

401
0

1117
2000

, ,
RAM. : ; - ,
. , Linux
, , .
, . Linux
.
/etc/fstab. ;
/etc/fstab. pri Linux . ( (striping) RAID-0),
. , defaults pri=0.
# /etc/fstab:
/dev/sda9 swap
swap
pri=1
/dev/sdc7 swap
swap
pri=1

0
0

0
0

. RAM
, Linux , ,
-
. /proc/sys/vm/swappiness ,
(
, 17.5).
swappiness 60, :
0 100. 0 ,
; 100 , , , .
swappiness http://lwn.net/Articles/83588/
http://kerneltrap.org/node/3000.
, ( , , ).
, .
swappiness=60 ( ), . , OpenOffice Gimp. OpenOffice, ,
.
swappiness=0, .
.
,

14.13.

397

. . Linux , (, 512 2).


, , ,
( ).

. , , ,
, (, ).
.
, Oracle ( 10.2)
RAM:
2 2;
28 1;
8 0,75.
32-
2. ,
.
64- .
: (, , ) ,
. Linux
, :
- - -
, , - . ,
.
, - .
, ,
- . -
, - .
, , ,
kill. , :
http://www.thomashertweck.de/linuxram.html;
http://kerneltrap.org/node/3202.
.
- , (, fdisk).
Linux swap (82 fdisk). mkswap,
swapon. ,
etc/fstab.

398

14.

,
. .
. ,
. , ,
- . ,
.
/dev. dd .
/dev/zero. . ,
1024. , , ,
mkswap swapon.

1:
root# dd bs=1024 if=/dev/zero of=/swapfile count=1000
1000+0 records in
1000+0 records out
root# mkswap /swapfile 1000
Setting up swapspace, size = 1019904 bytes
root# sync
root# swapon -v /swapfile
swapon on device /swapfile

fstab, :
# /etc/fstab
/swapfile none
swap
sw

0 0

, btrfs!

14.14. RAID
RAID . RAID- Linux mdadm. RAID-1
RAID-0.
RAID.
, raidtools (
Linux ).
btrfs RAID-0, RAID-1 RAID-10, RAID,
(Multi Device Drivers). , RAID
btrfs.

14.14. RAID

399

mdadm. RAID ,
mdadm. RAID.
mdadm (MTA
), RAID
.
, . ( Debian
Ubuntu) apt-get --no-installrecommends.
Md_mod. Linux RAID (Multi Devices Driver Support).
,
md_mod (
md). dmesg . , /proc/mdstat. RAID.
md_mod ,
, (, ext4).
, (/dev/mdn).
RAID , /dev/
mdn, .
Mdadm.conf. RAID /etc/mdadm/
mdadm.conf. , RAID,
RAID. /usr/share/mdadm/mkconf .
, .
. ,
mdadm, RAID
. , mdadm.conf .
RAID, mdadm --examine scan,
>> .
root# mdadm --examine --scan >> /etc/mdadm/mdadm.conf

mdadm.conf RAID,
, - RAID . ,
mdadm.conf.
# /etc/mdadm/mdadm.conf
DEVICE partitions
CREATE owner=root group=disk mode=0660 auto=yes
HOMEHOST <system>

400

14.

MAILADDR root
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=36c426b0:...
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=71dfc474:...
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=e0f65ea0:...

. RAID /proc/mdstat. RAID-1,


.
: [UU] , up
( ).
root# cat /proc/mdstat
Personalities : [raid0] [raid1] [linear] [multipath]
[raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sda1[0] sdb1[1]
979840 blocks [2/2] [UU]
md1 : active raid1 sda2[0] sdb2[1]
1951808 blocks [2/2] [UU]
md2 : active raid1 sda3[0] sdb3[1]
387730624 blocks [2/2] [UU]
unused devices: <none>

, ,
. mdadm --monitor.
Init-V /etc/init.d/mdadm. , mdadm. Ubuntu, ,
:
root# dpkg-reconfigure mdadm

mdadm .

( 1:06 RAID ).
, .

checkarray, Cron /etc/cron.d/mdadm.
RAID
, .
mdadm --monitor. /etc/init.d/mdadm, /etc/default/mdadm START_DAEMON=true.
/etc/mdadm/mdadm.conf.
, mdadm . ,
(MTA)!
/etc/mdadm/mdadm.conf MAILADDR.
, , ,
,

401

14.14. RAID

RAID . , , .
GRUB RAID. GRUB0.97 RAID-1. GRUB0.97, RAID,
. GRUB2
: grub.cfg raid, GRUB
Initrd RAID
.
, RAID,
, , GRUB . GRUB2
grub-install /dev/mdn. GRUB0.97
.

RAID-0. RAID-0,
. , , . RAID,
.
RAID.
fdisk, fd,
T. parted set
_ raid on.
/dev/sda3 /dev/sdc1
RAID-0. . fdisk -l
:
root# fdisk -l /dev/sda /dev/sdc
Disk /dev/sda: 320.0 GB, 320072933376 bytes
Device Boot
Start
End
Blocks
Id
/dev/sda1
1
973
7815591
83
/dev/sda2
974 1034
489982+ 82
/dev/sda3
1035 2251
9775552+ fd
Disk /dev/sdc: 320.0 GB, 320072933376 bytes
Device Boot
Start
End
Blocks
Id
/dev/sdc1
1 1217
9775521
fd

System
Linux
Linux swap / Solaris
Linux raid autodetect
System
Linux raid autodetect

mdadm , RAID-0
/dev/sda3 /dev/sdc1.
root# mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sda3 /dev/sdc1
mdadm: array /dev/md0 started.

/dev/
md0. Linux mount. /striped, , , .

402

14.

root# mkfs.ext4 /dev/md0


root# mkdir /striped
root# mount /dev/md0 /striped/

, /etc/
fstab. Linux RAID Init-V .
# in /etc/fstab
/dev/md0
/striped

ext4

defaults

,
mdadm.conf, RAID-0. mdadm --examine --scan

.
RAID-1. RAID-1 ,
RAID-0. RAID
--level=1 --level=0:
root# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda3 /dev/sdc1
mdadm: array /dev/md0 started.
root# mkfs.ext4 /dev/md0

/dev/md0 RAID-0,
mdadm stop.
mdadm --create. , mdadm ,
/dev/sda3 /dev/sdc1 , ,
/dev/md0.
RAID-1. ,
RAID-1, ,
:
root# mdadm /dev/md0 --fail /dev/sdc1

mdadm --monitor,
, ,
. ,
, , . /proc/mdstat U_.
, (U up), (_).
root# cat /proc/mdstat
md0 : active raid1 sda3[1]
979840 blocks [2/1] [_U]

/dev/sdc1 /dev/md0,
.
root# mdadm --remove /dev/md0 /dev/sdc1
root# mdadm --add /dev/md0 /dev/sdc1

,
, ,
( 20 100). , -

14.14. RAID

403

.
.
root# cat /proc/mdstat
md0 : active raid1 sda3[1] sdc1[2]
485454656 blocks [2/1] [U_]
[>....................] recovery = 3.0% (14577856/485454656)
finish=72.8min speed=107724K/sec
root# mdadm --detail /dev/md0
( )
...
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1
Rebuild Status : 75% complete
...
Number
Major
Minor
RaidDevice
State
0
3
3
0
active sync
/dev/sda3
1
0
0
removed
2
22
2
1
spare rebuilding /dev/sdc1
root# mdadm --detail /dev/md0 ( )
...
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
...
Number
Major
Minor
RaidDevice
State
0
3
3
0
active sync
/dev/sda3
1
22
2
1
active sync
/dev/sdc1

RAID-1. , ,
mdadm ,
RAID.
root# mdadm --remove /dev/md0 /dev/sdc1
...

, .
, ,
.
,
! ,
, , .
!
, , hdparm smartctl.
.

404

14.

root# smartctl -i /dev/sdc


...
Device Model: SAMSUNG HD403LJ
Serial Number: S0NFJ1MPA07356
root# hdparm -i /dev/sdc
/dev/sdb:
...
Model=SAMSUNG HD403LJ, FwRev=CT100-12,
SerialNo=S0NFJ1MPA07356

,
, RAID.
sfdisk (. sfdisk (MBR) 14.3).
RAID (
fd). ,
RAID:
root# mdadm --add /dev/md0 /dev/sdc1
...

RAID. cat /proc/mdstat.

RAID , .
, , , mdadm --fail
( , !).

RAID. mdadm --stop RAID.



umount.
root# umount /mount-directory/
root# mdadm --stop /dev/md0

RAID. , mdadm
--stop ,
RAID mdadm --assemble .
root# mdadm --assemble /dev/md0 /dev/sda3 /dev/sdc1
mdadm: /dev/md0 has been started with 2 drives.

. ,
RAID mdadm,
().
mdadm --query, , .
root# mdadm --query /dev/sda3
/dev/sda3: is not an md array

405

14.14. RAID

/dev/sda3: device 0 in 2 device active raid1 md0. Use mdadm --examine


for more detail.
root# mdadm --query /dev/md0
/dev/md0: 9.32GiB raid1 2 devices, 0 spares. Use mdadm --detail for more detail.
/dev/md0: No md super block found, not an md component.

mdadm --examine , RAID:


root# mdadm --examine /dev/sda3
/dev/sda3:
Raid Level : raid1
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Update Time : Thu Nov 9 17:02:39 2006
State : clean
Active Devices : 2
Working Devices : 2
Number
Major
Minor
RaidDevice
0
0
3
3
0
1
1
22
1
1

State
active sync
active sync

/dev/sda3
/dev/sdc1

mdadm --detail RAID:


root# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Thu Nov 9 16:55:35 2006
Raid Level : raid1
Array Size : 9775424 (9.32 GiB 10.01 GB)
Device Size : 9775424 (9.32 GiB 10.01 GB)
Raid Devices : 2
Total Devices : 2
...

. ,
? , RAID- .
. ,
, , RAID
.
(scrubbing).
root# echo check > /sys/block/mdn/md<n>/sync_action

, :
root# echo check > /sys/block/mdn/md<n>/sync_action

Debian Ubuntu /usr/share/mdadm/checkarray,


cron. Fedora cron /etc/cron.weekly/99-raid-check.

406

14.

RAID. , RAID .
, RAID : Linux mdadm
RAID ,
.
,
RAID:
root# mdadm --zero-superblock /dev/sda3

BIOS-RAID,
dmraid -r -E.

14.15. (LVM)
(Logical Volume Manager, LVM)
, . ,
LVM . LVM.
.
LVM, .
Fedora Red Hat system-config-lvm, SUSE
YaST LVM.
, , LVM. ,
, ,
, .

.
dm_mod. LVM
dm_mod. LVM
, lsmod.
GRUB. LVM ,
. LVM
GRUB2. GRUB0.97, , LVM.
RAID. LVM RAID. RAID, /dev/mdn (PV).
RAID-0. RAID
LVM. ,
. (Volume Group). lvcreate -i n
, (n) .

407

14.15. (LVM)

LVM. LVM
. pv, vg lv, ,
(pv), (vg)
(lv). .14.10.
lvm2, .
14.10. LVM

lvcreate

lvdisplay

lvextend

lvreduce

lvremove

lvrename

lvscan

pvcreate

pvdisplay

pvremove

pvscan

vgchange

vgcreate

vgdisplay

vgextend

vgmerge

vgreduce

vgrename

vgscan

, LVM lvm,
. , lvcreate lvm lvcreate
.
. ,
LVM. , LVM .
/dev/sdc LVM. :
root# fdisk -l /dev/sdc
Disk /dev/sdc: 320.0 GB, 320072933376 bytes
Device Boot
Start
End
Blocks
Id
/dev/sdc1
1
1217
9775521
8e
/dev/sdc2
1218
2434
9775552+
8e

System
Linux LVM
Linux LVM

LVM, modprobe vgscan.


LVM , LVM
. ,
:

408

14.

root# modprobe dm_mod


root# vgscan
(, ...)

LVM /dev/sdc1,
/dev/sdc2. ,
LVM ,
pvcreate LVM.
root# pvcreate /dev/sdc1
"/dev/sdc1"

.
, . vgcreate .
myvg1:
root# vgcreate myvg1 /dev/sdc1
"myvg1"

myvg1 , , ,
. myvg1
, . lvcreate : ,
:
root# lvcreate -L 2G -n myvol1 myvg1
"lvol0"

/dev/myvg1/myvol1.
/dev/mapper/myvg1-myvol1.
.
, , ,
mkfs.ext4 mkfs.xfs:
root# mkfs.ext4 /dev/myvg1/myvol1

mount , :
root# mkdir /test
root# mount /dev/myvg1/myvol1 /test

. , , ,
, . (dev/myvg1/myvol1 /test) 2 3. df /test
:
root# df -h -T /test
Filesystem
Typ
Size

Used

Available

Used%

Mounted on

409

14.15. (LVM)

/dev/mapper/myvg1-myvol1
ext4 2,0G

760M

1,2G

40%

/test

. ,
lvextend.
ext4.
root# lvextend -L 3G /dev/myvg1/myvol1
myvol1 3,00 GB
myvol1
root# resize2fs /dev/myvg1/myvol1

df , :
root# df -h -T /test
File system
Typ Size
/dev/mapper/myvg1-myvol1
ext4 3,0G

Used

Available

760M

2,1G

Used%
27%

Mounted on
/test

.
,
fsck.ext4 , , resize2fs .

lvreduce.
( ) , ( ) . ,
?
,
vgextend.
,
/dev/sdc2. , myvg1 19,
16 :
root# pvcreate /dev/sdc2
"/dev/sdc2"
root# vgextend myvg1 /dev/sdc2
"myvg1"
root# vgdisplay myvg1
...

18,64 GB
PE /
640 / 2,50 GB
PE /
4132 / 16,14 GB
...

. . , .
. , , , .
, LVM

410

14.

. , .

, btrfs. ,
LVM . ,

.
, myvol1, /media/backup, ,
, , .
, myvol1
,
. , ,
, 100. (
lvdisplay /dev/vg1/snap , .)
,
/dev/vgname/lvname, /dev/mapper/vgnamelvname!
root# lvcreate -s -L 100M snap /dev/myvg1/myvol1
snap
root# mkdir /media/backup
root# mount /dev/vg1/snap /media/backup
root# backup-script /media/backup ( )
root# umount /media/backup
root# lvremove /dev/vg1/snap

14.16. SMART
SMART Self-Monitoring, Analysis and Reporting Technology
( , ).
IDE, SATA SCSI.
SMART , ,
, .
SMART . .
, , , .
, Linux SMART. , http://sourceforge.net/apps/trac/smartmontools/wiki http://www.
linuxjournal.com/article/6983.

14.16. SMART

411

. SMART .
SMART. , ,
, , hdparm -I/dev/sdx.
eSata. , USB Firewire, SMART, , .
RAID,
SMART ( man smartctl -d).
Gnome. Gnome SMART-
, . /usr/lib/gnomedisk-utility/gdunotification-daemon, gnome-disk-utility.
Gnome Disks Palimpsest , , SMART .
smartctl. SMART- ,
. smartctl
smartmontools, .
(MTA), SMART .
, , ,
. Debian Ubuntu , apt-get --no-install-recommends.
smartctl .
smartctl -i SMART support is Disabled
( SMART ), SMART smartctl -s on.
root# smartctl -i /dev/sdb
smartctl 5.41 ..., Copyright (C) 2002-11 Bruce Allen
: SAMSUNG SSD 830 Series
: S0Z3NYAC210778
LU WWN 5 002538 043584d30
: CXM03B1Q
: 128.035.676.160 bytes [128 ]
: 512 /
: smartctl [: -P showall]
ATA: 8
ATA: ACS-2 2
: . 4 09:45:45 2012
SMART: SMART.
SMART:

smartctl H, smartctl --health, ,


24.
smartctl PASSED, !

412

14.

root# smartctl -H /dev/sda


...
SMART overall-health self-assessment test result: PASSED

smartctl A ( smartctl attributes) . ,


. : VALUE
, THRESH .
, .
100.
, Power_On_Hour 100.
( ) 99 ..
, ,
RAW_VALUE. 3360, 420 8.
. , ,
-v 9,minutes -v 9,seconds .
, , SATA, .
.
root# smartctl -A /dev/sda
...
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME
VALUE WORST THRESH TYPE
1 Raw_Read_Error_Rate
109
099
006
Pre-fail
3 Spin_Up_Time
096
095
000
Pre-fail
4 Start_Stop_Count
100
100
020
Old_age
5 Reallocated_Sector_Ct 100
100
036
Pre-fail
7 Seek_Error_Rate
065
060
030
Pre-fail
9 Power_On_Hours
100
100
000
Old_age
...
198 Offline_Uncorrectable 100
100
000
Old_age
199 UDMA_CRC_Error_Count 200
200
000
Old_age

UPDATED
Always
Always
Always
Always
Always
Always

RAW_VALUE
24386832
0
167
0
3391200
451

Offline
Always

0
0

smartctl -l error
. (No Errors Logged). , , .
root# smartctl -l error /dev/sda
SMART Error Log Version: 1
No Errors Logged

. SMART
, ,
. smartctl -t short/long.
, (long)
. ,

413

14.16. SMART

. , smartctl -l selftest. Remaining ,


. 0%, !
LifeTime , ; LBA (),
.
;
( 50 ), 2600.
root#
Num
# 1
# 2
# 3

smartctl -t short /dev/sda


Test_Description
Status
Remaining
Extended offline
Completed without error
00%
Short offline
Completed without error
00%
Short offline
Completed without error
00%

LifeTime
2592
2591
40

LBA
-

(smartd). smartctl , .
. smartd.
( ). .
smartd /etc/smartd.conf. Init-V /etc/sysconfig/smartmontools
/etc/default/smartmontools.
smartd. Debian Ubuntu smartmontools
start_smartd=yes, !
SATA (/dev/sda
/dev/sdb) :
# /etc/smartd.conf
/dev/sda -d sat -H -m root -M test
/dev/sdb -d sat -H -m root -M test

,
( smartctl -H). ,
smartd root
( ).
-d sat SATA; -M test ,
, .
smartd:
root# service smartd start

,
-M test. smartd.conf, smartmontools,

.
smart-notifier. , . smartnotifier smartd.conf :

414

14.

# /etc/smartd.conf
DEVICESCAN -m root -M test -M exec /usr/share/smartmontools/smartd-runner

SMART smartd-runner.
smartd D-Bus.
smartd ,
smart-notifier.
, /etc/xdg/autostart.
, -M exec smartd.conf -m. , .
, -M test , , .

14.17. SSD-TRIM
Linux SSD ( ). , , .
,
.
, ,
:
(, - ,
). SSD-TRIM. SSD-TRIM : http://ru.wikipedia.org/wiki/_.
Linux TRIM . ,
, TRIM,
( ) .
, SSD-TRIM ,
.
TRIM. Linux,
,
, SSD-TRIM.
: -TRIM, Linux
, TRIM
(batch TRIM),
(, ).
,
,
. -TRIM
.
TRIM , .

14.17. SSD-TRIM

415

(
, ), SSD .

,
TRIM
. -, , -, TRIM-
.

-TRIM. -TRIM,
discard /etc/fstab ,
. ext4, btrfs xfs. , /etc/fstab -
! mount- .
# /etc/fstab
UUID=018e... / ext4 errors=remount-ro,user_xattr,discard 0 1

TRIM. TRIM,
fstrim:
root# fstrim -v /
/: 6493835264

TRIM .
SSD . fstrim
, , , .
root# fstrim -m 64K -v /

, Cron
( -m).
, fstrim mount-.
# /etc/cron.weekly/fstrim
/sbin/fstrim /

. RAID
TRIM. ( ), , ,
TRIM.
. ,
TRIM .
mount- discard
. , Linux
TRIM. ,
,
.

416

14.

14.18.
USB- . , ,
. -, , , .
.
, .
.


Gpg. gpg.
gpg -c, ,
file.gpg. CAST5. .
gpg -d .
user$ gpg -c file
: **********
: **********
user$ gpg -d .gpg > file
: **********

gpg , ,
.. man
50! gpg .
, ( )
.

(USB-,
)
Dm_crypt LUKS. : CryptoFS, eCryptfs, Enc-FS, Loop-AES LUKS.
, -
.
LUKS (Linux Unified Key Setup).
LUKS dm_crypt, LVM .
dm_crypt , , . ,
LVM , .

14.18.

417

dm_crypt ,
LVM!
LUKS ,
. , . LUKS
Linux.
Cryptsetup. , cryptsetup . ,
USB- (/dev/sdh1)
(luksFormat),
mycontainer (luksOpen). ,
,
. , 20.
, /dev/mapper/mycontainer , ,
.. unmount
(luksClose), /dev/sdh1.
.
root# cryptsetup luksFormat /dev/sdh1
/dev/sdh1
? ( YES): YES
LUKS: **********
: **********
.
root# cryptsetup luksOpen /dev/sdh1 mycontainer
LUKS: **********
root# mkfs.ext3 /dev/mapper/mycontainer
root# mount /dev/mapper/mycontainer /test
root# touch /test/xy
root# umount /test/
root# cryptsetup luksClose mycontainer

, USB-
, RAID
LVM. /dev/sdh1 .
cryptsetup AES,
128. ,
cryptsetup luksDump, ; LUKS
.
root# cryptsetup luksDump /dev/sdh1
LUKS header information for /dev/sdh1
Version:
1
Cipher name:
aes
Cipher mode:
cbc-essiv:sha256
Hash spec:
sha1

418

14.

Payload offset: 1032


MK bits:
128
...


, -c -s cryptsetup
luksFormat. , , cat /
proc/crypto. AES
TwoFish. , :
, .
cryptsetup luksAddKey, LUKS . ,
.
luksformat. . cryptsetup luksFormat,
mkfs.vfat. ,
-t.

( ) /
dev
/
mapper/luksformatn .
, cryptsetup luksClose luksformatn.

. , LUKS, Gnome
KDE, .
, (.14.3).
.
/dev/mapper luks_crypto_uuid.
luksClose.

.14.3. Gnome

419

14.18.

crypttab.
, , , , . cryptsetup ,
. , /etc/crypttab.
: /dev/
mapper, , ,
(, USB-), none,
; .
/dev/sda7,
/dev/mapper/cdisk1. , LUKS (
man crypttab).
# /etc/crypttab
#
cdisk1
/dev/sda7


none

luks

,
, /etc/fstab. /media/
private-data:
# /etc/fstab
...
/dev/mapper/cdisk1

/media/private-data

ext3

defaults

0 0

, ,
.
. . -,
, ,
, ( ) .
. -,
. , .

.
TrueCrypt. , dm_crypt LUKS,
TrueCrypt (http://www.truecrypt.org/). Windows MacOSX, ,
Linux . , GPL,
TrueCrypt .
Ecryptfs (Ubuntu). Ubuntu
. , .
dm_crypt LUKS, ecryptfs.

420

14.


/etc/crypttab, ,
(, /home)
, . : -,
GRUB ,
, . -,
;
Initrd
( cryptsetup).
, :
, /home. , ,
: /var/cache /var/tmp , , PDF
..; /var/log , ;
,
, .. , (, ), , .
.
, . ,
, , , ;
, CD DVD, .
:
Debian CD DVD ( Netinstall,

);
Fedora DVD ( );
openSUSE DVD 11.2 ( );
Ubuntu CD Alternate ( CD -

).
Debian Ubuntu LVM, Fedora ,
. openSUSE
C .
.
: GRUB ,
LVM.
, , LVM ( ,
, ) . ,
; -

422

14.

SSD .

Sandforce. ,
SSD
.
,
. Linux,
EFI BIOS . , , , SSD.

15

GRUB

GRUB .
, , ,
Windows - Linux.
GRUB2. ,
, Linux, ,
GRUB0.97. .

15.1.
GRUB Grand Unified Bootloader ( ). Linux
Windows Linux,

.
GRUB. C 2012 GRUB2.0.
2005 . GRUB2 . ,
Ubuntu GRUB2, 9.10, Debian 6. openSUSE GRUB2 12.2.
Fedora: GRUB2
16, , BIOS.
Fedora16 17 EFI, EFI-
GRUB0.97!
, , GRUB2, GRUB0.97 legacy
(). , .
0,97 ,
GRUB 1.0. , GRUB0.97 legacy ,
GRUB
!

424

15. GRUB

GRUB2, GRUB0.97
- . -, , Linux, -, GRUB0.97 (,
RHEL 6.3).
GRUB2. , GRUB2 GRUB0.97.
GRUB0.97,
, . , ,
.
GRUB2 RAID.
, LVM RAID
/boot.
GRUB2 ext4 btrfs.
GRUB2 .
GRUB2 , BIOS, EFI coreboot
( LinuxBIOS).
GRUB2 Unicode.
GRUB2 -. , GRUB
.
.
GRUB .
grub.cfg . grub.cfg shell-
LUA.
. , GRUB2, ,
. , Debian Ubuntu grub-common
, grub-pc , BIOS. ,
BIOS EFI, coreboot , grub-pc
, , grub-efi-amd64, grub-efi-ia32 grub-coreboot.
, grub-rescue-pc IMG- , , GRUB
CD-. ,
GRUB , , GRUB .
Fedora . grub2 GRUB , BIOS,
grub2-efi , EFI. GRUB (
) Fedota- grubby.

15.1.

425

, GRUB2 os-prober.
. os-prober GRUB.
, . , GRUB2 ,
. Debian 6 , Fedora 16 ,
openSUSE 12.2 Ubuntu 9.10 .
. GRUB
info grub.
GRUB: http://www.gnu.org/software/grub/.
GRUB :
http://www.dedoimedo.com/computers/grub-2.html ;
http://lists.gnu.org/archive/html/grub-devel/ GRUB;
http://fedoraproject.org/wiki/Features/Grub2 Fedora- ;
https://help.ubuntu.com/community/Grub2 Ubuntu- .

BIOS
GRUB, , . , BIOS EFI,
.
BIOS -. , .
BIOS
. MBR (Master
Boot Record, ).

,
. , !
MBR Linux, Windows. GRUB
Windows, Windows Linux .
Linux

GRUB

. .
Windows
, Linux

. Windows

, , ,

GRUB
(
BIOS
)
BIOS
15.3 ( GRUB

2) GRUB 15.4 (GRUB0.97).

Windows. Windows, MBR


. , , Windows,

426

15. GRUB

.
Windows, Windows .
Linux. Linux, MBR GRUB. GRUB
Linux, Windows.
, MBR
GRUB Linux,
. MBR,
.
512,
MBR. , MBR ,
. ,
GRUB : stage1 , stage1_5
stage2. stage1_5 ,
. , stage2
.
, , ,
GRUB ( Windows Linux).

, Enter. GRUB , .
Linux. ,
Linux, Linux . Linux /boot/vmlinuz (
z , ). ,
.
. .
: (, root=/dev/sdb13). , , . ,
Linux /sbin/init, Linux 16.1. , .
. Linux . ,
. , ,
.., , ,
, , .
, . , , SCSI, , :

15.1.

427

,
, .
Initrd. , GRUB , Initrd. , , .
,
( Initrd Initial RAM Disk
).
Initrd /boot/initrd /boot/initrd.gz.
, Initrd,

, ( mkinitrd).
GRUB.
,
. . GRUB , GRUB
.
GRUB - GRUB.
GRUB0.97 /boot/grub/
menu.lst. GRUB2 , /etc/grub.d/.
GRUB2 /boot/grub/grub.cfg.

EFI
Apple EFI (Extensible Firmware, ) ,
BIOS
. Windows8 , EFI
. (, Windows8
, BIOS.)
EFI GPT. , EFI ,
.
, GUID (GPT), .
, GPT , EFI! EFI
,
(MBR). , GPT
, 2,
.
. EFI . BIOS , EFI

428

15. GRUB

.
.
EFI, ,
. ( , ,
.) ( ,
EFI ), EFI .
, EFI GRUB , Linux. GRUB
EFI ( GRUB
EFI).
, GRUB EFI . Linux , EFI- Linux , ,
GRUB .
: GRUB , ,
.. Linux EFI .
EFI GRUB. EFI GRUB ,
EFI, GRUB.
.
,
EFI-! ( EFI BIOS. Linux
, .
DVD EFI
: BIOS- EFI-.
, EFI!)
EFI. EFI GRUB , EFI. , VFAT.
: (MBR) (C12A7328-F81F-11D2-BA4B-00A0C93EC93B)
(GPT).
Microsoft EFI- ,
EFI . ,
100200 ( , , EFI 1. Windows8
25).
EFI Linux /
boot/efi! Linux ,
.
, Initrd. GRUB , Linux
, BIOS: GRUB ,
Initrd .

15.1.

429

Initrd
Linux .
SCSI-, ,
RAID LVM ,
. . , ,
. , ,
(Initial RAM Disk, Initrd).
Initrd- GRUB ( initrd
GRUB).
Initrd /boot, Initrd . ,
GRUB0.97, /boot ,
RAID LVM, GRUB0.97 . GRUB2 .
Initrd , . , , Initrd-.
.
, Initrd-.
, Initrd- . initramfs-, . GRUB,
initrd,
, ,
Initrd .
Initrd .
, , Initrd-.
.
( . , .)
, Initrd- . . Initrd-
, .

, .
Update-initramfs (Debian, Ubuntu). Debian Ubuntu Initrd updateinitramfs. Initrd- -u.

430

15. GRUB

Initrd- , - ,
-k. -k all Initrd-
.
-c -d update-initramfs
Initrd-.
-k.
root# update-initramfs -c -k 3.5-13-generic
update-initramfs: Generating /boot/initrd.img-3.5-13-generic

update-initramfs Initrd-
mkinitramfs. /etc/initramfstools/initramfs.conf, , Initrd- , /etc/initramfs-tools/modules ( ).
( MODULES=most initramfs.conf )
mkinitramfs Initrd-,
. , Linux, USB, SCSI SATA, NFS-.
mkinitramfs ( ), Initrd- ( -o). Initrd-
,
:
root# mkinitramfs -o myinitrd 3.5-13-generic

Dracut (Fedora, Red Hat). Fedora 12 Red Hat Enterprise Linux


6 Initrd- dracut.
Fedora RHEL mkinitrd.
dracut . Initrd-,
dracut, -
, , udev.
, dracut , , .

dracut.
dracut , /etc/dracut.conf ,
Initrd- /usr/share/dracut/modules.d.
Initrd- 3.5.3
( /boot/vmlinuz-3.5.3), :
root# dracut /boot/initrd-3.5.3

3.5.3

dracut https://dracut.wiki.kernel.org/index.php/
Main_Page.

Mkinitrd (SUSE). SUSE Initrd-


mkinitrd. ,
. mkinitrd Initrd-
, /boot. Initrd- /boot/
initrd-nnn, nnn . , mkinitrd ,
c /boot/initrd Initrd-, vmlinuz.

15.2. GRUB ( )

431

Initrd-,
k -i , , Initrd (
, /boot). mkinitrd INITRD_MODULES /etc/sysconfig/kernel.
, , :
# /etc/sysconfig/kernel
INITRD_MODULES="thermal ahci ata_piix ata_generic processor fan"

-m. mkinitrd -h, man mkinitrd, ( /sbin/mkinitrd).


.
,
GRUB, Initrd-, .
, .
( GRUB
. , , .)
Initrd-. 2.6 Initrd- initramfs. Initrd- - (cpio),
. , :
root# cd /boot
root# cp initrd-n.n initrd-test.gz
root# gunzip initrd-test
root# mkdir test
root# cd test
root# cpio -i < ../initrd-test
root# ls -lR

.
initramfs http://www.kernel.org/doc/Documentation/filesystems/
ramfs-rootfs-initramfs.txt http://lwn.net/Articles/191004/.

15.2. GRUB
( )
Linux (.15.1).
GRUB . GRUB .
, , Esc. GRUB . , , Ubuntu, GRUB,
.

432

15. GRUB

.15.1. GRUB

. GRUB .
GRUB ,
P .
. , GRUB .
Linux. GRUB
,
GRUB E (edit ). , , .
GRUB ,
Linux , (,
). , :
linux /boot/vmlinuz-n.n.n root=/dev/sdb13

.
Linux , Ctrl+X F10.
!
. GRUB
C. . , Linux , GRUB . ,
, Linux

15.3. GRUB2

433

GRUB. . ,
GRUB0.97 GRUB2 .
, Linux, /dev/sdb13 ext4 ( insmod ext2
, ext2, ext3 ext4):
grub>
grub>
grub>
grub>
grub>

insmod ext2
set root='(hd1,13)'
linux /boot/vmlinuz-n.n.n root=/dev/sdb13 ro
initrd /boot/initrd-n.n.n
boot

GRUB Tab ,
. cat,
. , GRUB, ( help , help
commandname ).
, . , GRUB
/boot/grub/menu.lst. GRUB2, , /boot/grub/grub.cfg. , GRUB. , , GRUB, Linux GRUB.
GRUB0.97 menu.lst . GRUB2

grub.cfg. .
GRUB
.

15.3. GRUB2

Grub.cfg. GRUB grub.cfg,
:
/boot/grub/grub.cfg GRUB Debian Ubuntu;
/boot/grub2/grub.cfg GRUB Fedora openSUSE 12.2
;
/etc/grub2.cfg /boot/grub2/grub.cfg Fedora openSUSE.
/etc/grub.d/.
grub.cfg .
. GRUB,
. , Debian, Ubuntu,
openSUSE Fedora :

434

15. GRUB

/etc/grub.d/* GRUB;
/etc/default/grub , -

.
Update-grub.
, :
root# update-grub (Debian/Ubuntu)
root# grub2-mkconfig -o /boot/grub2/grub.cfg (Fedora)

grub.cfg. grub.cfg . Ubuntu12.10 grub.cfg . ,


insmod ext2: GRUB
ext, ext3 ext4. grub.cfg :
# /boot/grub/grub.cfg
# /etc/grub.d/00_header
#
if [ -s $prefix/grubenv ]; then
set have_grubenv=true
load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
#
function savedefault { ... }
function recordfail { ... }
function load_video { ... }
# GRUB
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root d45161e0-a9dd-421b-90e3-dc01887b140b
if loadfont /usr/share/grub/unicode.pf2 ; then
set gfxmode=auto
load_video
insmod gfxterm
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root d45161e0-a9dd-421b-90e3-

15.3. GRUB2

dc01887b140b
set locale_dir=($root)/boot/grub/locale
set lang=de_AT
insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ]; then
set timeout=-1
else
set timeout=10
fi
# /etc/grub.d/10_linux
# Ubuntu
menuentry 'Ubuntu, mit Linux 3.5.0-2-generic' ... {
recordfail
gfxmode $linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid
--set=root 474ef599-7665-4fe0-a4fd-97df765db80e
linux boot/vmlinuz-3.5.0-2-generic root=UUID=474e... ro quiet splash
initrd /boot/initrd.img-3.5.0-2-generic
}
menuentry 'Ubuntu, Linux 3.5.0-2-generic ( )' ... {
...
linux /boot/vmlinuz-3.5.0-2-generic root=UUID=474e...
ro recovery nomodeset
...
}
# /etc/grub.d/20_memtest86+
#
menuentry "Memory test (memtest86+)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root d45161e0-a9dd-421b-90e3 dc01887b140b
linux16 /boot/memtest86+.bin
}
# /etc/grub.d/30_os-prober
# Windows
menuentry "Windows (loader) (on /dev/sda1)" {
insmod ntfs
set root='(hd0,1)'

435

436

15. GRUB

search --no-floppy --fs-uuid --set 2ca80f2ba80ef35e


chainloader +1
}

grub.cfg . Debian Ubuntu update-grub


grub.cfg. Fedora openSUSE
grub2-mkconfig -o /boot/grub2/grub.cfg. ( update-grub, Debian/Ubuntu, , .)
grub[2]-mkconfig
. , /boot GRUB,
. , . ,
GRUB . update-grub
.
grub[2]-mkconfig
, GRUB Linux.
/etc/default/grub. /etc/default/grub
GRUB. ,
, grub.cfg! Ubuntu
:
# /etc/default/grub
GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian `
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
# GRUB_TERMINAL=console
# GRUB_GFXMODE=640x480
# GRUB_DISABLE_LINUX_UUID=true
# GRUB_DISABLE_RECOVERY="true"
# GRUB_INIT_TUNE="480 440 1"

Fedora :
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Fedora"
GRUB_DEFAULT=saved
GRUB_CMDLINE_LINUX="rd.md=0 rd.dm=0 quiet SYSFONT=latarcyrheb-sun16 rhgb \
rd.lvm.lv=vg_fedora16vbox/lv_root rd.luks=0 LANG=de_DE.UTF-8 \
rd.lvm.lv=vg_fedora16vbox/lv_swap KEYTABLE=de-latin1-nodeadkeys"

.
GRUB_DEFAULT , GRUB -

. ,
update-grub . , GRUB_DEFAULT=5, .

15.3. GRUB2

437

saved , , . , ,
GRUB ! LVM
RAID, GRUB - .
GRUB_DEFAULT ()
menuentry, menuentry . ( ,
).
GRUB_HIDDEN_TIMEOUT , GRUB

(
Linux). GRUB_HIDDEN_TIMEOUT ,
, GRUB Shift ( ).
Ubuntu GRUB_HIDDEN_TIMEOUT=0 , GRUB
. ,
Shift .
, GRUB
GRUB_HIDDEN_TIMEOUT .
GRUB_HIDDEN_TIMEOUT_QUIET=true
, GRUB_HIDDEN_TIMEOUT.

, GRUB ( ,
Ubuntu), GRUB_
HIDDEN_TIMEOUT=... GRUB_HIDDEN-TIMEOUT_QUIET=... (
#).
GRUB_TIMEOUT=n , GRUB

. , GRUB
. ,
GRUB , ,
Shift , GRUB_HIDDEN_TIMEOUT.
GRUB_DISTRIBUTOR 10_linux (.),

(, Fedora Ubuntu).
GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT
10_linux. ,
. GRUB_ CMDLINE_LINUX
, GRUB_CMDLINE_LINUX_DEFAULT

, ( ).
GRUB -

640480. ,
GRUB_ GFXMODE (, ).

438

15. GRUB

,
GRUB_TERMINAL=console.
00_header.
,
Unicode.
, GRUB , ,
UUID-. , ,
(, /dev/sda1), GRUB_DISABLE_
LINUX_UUID=true. ( 10_linux), .
update-grub grub-mkconfig , ,
Linux . Linux , -.
, , GRUB_
DISABLE_RECOVERY="true".
GRUB_INIT_TUNE= GRUB .
grub.cfg. GRUB
, .
grub.cfg
. ,
GRUB , (Linux, Windows ..) grub.cfg .
,
.
/etc/grub.d () (.15.1). grub.cfg,
update-grub , grub.d.
( ) grub.cfg. -
:
cat " EOF,
EOF.
, GRUB .
15.1. /etc/grub.d/

00_header

GRUB

05_debian_theme

( Debian Ubuntu)

10_linux

20_linux_xen

20_memtest86+

Memtest86 ( Debian Ubuntu)

30_os-prober

40_custom

41_custom

grub.cfg custom.cfg

15.3. GRUB2

439

10_linux 30_os-prober. 10_linux


, /boot/, :
, -.
, .
30_os-prober os-prober.
(Linux, Windows, MacOSX), .
, , Linux,
GRUB, . , os-prober.
Linux
Windows BIOS . EFI
. , EFI, GRUB. -, :
EFI, GRUB ?
, , GRUB .
EFI ,
. ,
! GRUB .
grub.cfg.
grub.cfg , grub.d .
, (
).
(Execute-Bit). , grub.cfg
, ( )!
40_custom .
tail ( $0). -n +3, , , .
#!/bin/sh
exec tail -n +3 $0
#
...

41_custom. grub.cfg (
GRUB). ,
/boot/grub/custom.cfg (Ubuntu) /boot/grub2/custom.cfg (Fedora, openSUSE).
, GRUB. source
GRUB, custom.cfg
GRUB grub.cfg.
#!/bin/sh
cat <<EOF
if [ -f \$prefix/custom.cfg ]; then

440

15. GRUB

source \$prefix/custom.cfg;
fi
EOF



, grub.cfg. ,
. GRUB (PDF-
100!) http://www.gnu.org/software/grub/manual/.
. set varname=value . $varname. GRUB echo $varname , set .
, , . , , default, timeout, color_xxx, menu_color_xxx root:
, root.
GRUB . ( Linux) /boot/grub[2]/grub-editenv ( ).
root# grub-editenv /boot/grub[2]/grubenv create

GRUB save_env load_env. root ,


. Linux
GRUB grub-editenv.
. GRUB
(.15.2).
: 0, 1!
15.2. GRUB2
GRUB2

(hd0)

/ ( /dev/sda)

(hd1)

/ ( /dev/sdb)

(hd0,1)

/ (/dev/sda1)

(hd2,8)

/ (/dev/sdc8)

, : msdos , , gpt , GUID. (hd0,msdos3)


(hd0,gpt2).

SATA ,
SATA- . /

15.3. GRUB2

441

GRUB , SATA-,
.
, , , SATA.
GRUB hd1.
GRUB .
, GRUB: E hd0,...
hd1,...

UUID. grub.cfg :
set root=(hd1,1)
search --no-floppy --fs-uuid --set 12345678...

root. UUID. ,
GRUB, --set,
root.
.
, GRUB ,
( UUID)
(, ) - .
. insmod name GRUB
. GRUB name.
mod /boot/grub[2], , root. part_msdos part_gpt ( ), ext2 ( ext2 ext4), raid, raid5rec, raid6rec mdraid
( RAID), lvm, gfxterm ( ), vbe (
), jpeg, tga png .

GRUB
Menuentry. GRUB menuentry.
, .

, , GRUB
. , -
. GRUB

( ) , .

. GRUB2.00 ( ). grub.cfg :
submenu '' {
menuentry ' 1' { ... }
menuentry ' 2' { ... }
}

442

15. GRUB


, .
. GRUB
Esc.
Linux. GRUB2, Linux,
:
menuentry "Linux" {
set root=(hd0,3)
linux /boot/vmlinuz-n.n.n root=... ro quiet splash
initrd /boot/initrd.img-n.n.n
}
set root , Initrd-.
linux initrd .
. root ro,
. .
:
Debian 6 root=/dev/xxx ro quiet;
Fedora 17 root=/dev/xxx ro rhgb quiet LANG=... SYSFONT=... KEYTABLE=...;
openSUSE 12.2 root=UUID=xxx resume=/dev/xxx splash=silent showopts video=nxn
quiet;
Ubuntu 12.10 root=UUID=xxx ro quiet splash.
,
set root. linux initrd :
menuentry "Linux - Mit eigener Bootpartition" {
set root=(hd0,2)
linux /vmlinuz-n.n.n root=... ro quiet splash
initrd /initrd.img-n.n.n
}

Initrd- LVM- / RAID,


GRUB. RAID-5 , , RAID-6 raid5rec raid6rec. set root , , (lvname) (mdn):
menuentry "Linux - Mit Software-RAID" {
insmod raid mdraid
set root=(md0)
linux /boot/vmlinuz-n.n.n root=... ro quiet splash
initrd /boot/initrd.img-n.n.n
}
menuentry "Linux - Mit LVM" {
insmod lvm
set root=(vg1-root)
linux /boot/vmlinuz-n.n.n root=... ro quiet splash

15.3. GRUB2

443

initrd /boot/initrd.img-n.n.n
}
menuentry "Linux - LVM auf RAID-5" {
insmod raid raid5rec mdraid lvm
set root=(vg1-root)
linux /boot/vmlinuz-n.n.n root=/dev/mapper/... ro quiet splash
initrd /boot/initrd.img-n.n.n
}

, UUID search.
search , GRUB- root . LVM-, RAID-,
GRUB. Ubuntu set root
search, GRUB
.
menuentry " - root- Linux UUID " {
set root=(hd0,3)
search --no-floppy --fs-uuid --set 12345678...
linux /boot/vmlinuz-n.n.n root=... ro quiet splash
initrd /boot/initrd.img-n.n.n
}

Windows. Windows BIOS set root Windows ,


chainloader +1. , Windows 7 :
100 bootmgr bootsect.bak , ,
. GRUB .
search . drivemap, , . Windows , Windows
, .
Windows.
menuentry "Windows 7" {
set root=(hd0,1)
search --no-floppy --fs-uuid --set 12345678...
drivemap -s (hd0) $root
chainloader +1
}

, Windows EFI GRUB, .

GRUB chainloader
.

444

15. GRUB

, /etc/grub.d/40_
custom.
. , GRUB2
.
set root ( search) chainloader +1:
menuentry "GRUB in /dev/sdb7" {
set root=(hd1,7)
search --no-floppy --fs-uuid --set 12345678...
chainloader +1
}

,
GRUB.
invalid signature ( ).
, --force:
menuentry "GRUB2 in /dev/sdb7" {
set root=(hd1,7)
chainloader +1 --force
}

, .
GRUB2 GRUB0.97. set
root chainloader:
menuentry "GRUB0.97 in /dev/sdb7" {
chainloader (hd1,7)+1 --force
}

GRUB2,
config-file GRUB grub.cfg

:
menuentry "GRUB in /dev/sdb7" {
set root=(hd1,7)
search --no-floppy --fs-uuid --set 12345678...
configfile /boot/grub/grub.cfg
}

BIOS GRUB2
(MBR) ! GRUB0.97 GRUB
.
GRUB

2 !

EFI. EFI
GRUB EFI.
, EFI
; ,
set root.

15.3. GRUB2

445

menuentry " Windows (EFI)" {


insmod part_gpt
set root='(hd0,1)'
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
menuentry " Fedora (EFI)" {
insmod part_gpt
set root='(hd0,1)'
chainloader /EFI/redhat/grub.efi
}
menuentry " Ubuntu (EFI)" {
insmod part_gpt
set root='(hd0,1)'
chainloader /EFI/ubuntu/grubx64.efi
}

, EFI ,
:
root# find /boot/efi -name '*.efi' | sort
/boot/efi/EFI/Boot/bootx64.efi
/boot/efi/EFI/Microsoft/Boot/bootmgfw.efi
/boot/efi/EFI/Microsoft/Boot/bootmgr.efi
/boot/efi/EFI/Microsoft/Boot/memtest.efi
/boot/efi/EFI/redhat/grub.efi
/boot/efi/EFI/ubuntu/grubx64.efi

Windows bootmgfw.efi . bootmgr.efi


. memtest.efi . ,
, EFI- .

ASUS
P

8
H
67-
M
Evo


GRUB2 , BIOS. , , . Linux,
GRUB .
os-probe. ,
30_os-probe . (, GRUB),
/etc/default/grub GRUB_DISABLE_OS_PROBER=true.
. GRUB . GRUB
JPG, PNG TGA. ,

446

15. GRUB

, Debian Ubuntu 05_debian_theme.


, (.15.2).
# /etc/grub.d/05_debian_theme
...
WALLPAPER="/boot/grub/myown.png"
COLOR_NORMAL="white/black"
COLOR_HIGHLIGHT="yellow/black"

.15.2. GRUB2

. /etc/default/grub
GRUB. , , .
. , , , WindowsXP, GRUB WindowsXP
, GRUB_DEFAULT=9 ( ). , GRUB
.
GRUB_DEFAULT=0, GRUB . /etc/
grub.d, 10.
:

15.3. GRUB2

447

#!/bin/sh
exec tail -n +3 $0
# /etc/grub.d/09_boot-windows-by-default
menuentry "Windows 7" {
set root=(hd0,1)
chainloader +1
}

, GRUB,
, :
GRUB_DEFAULT='Windows 7 (loader) (on /dev/sda1)'

, GRUB
. Windows ,
Linux,
.


BIOS
, GRUB2
Linux. , ,
GRUB, grub.cfg, GRUB .
BIOS EFI , - GRUB
GRUB (,
MBR).
grub-install. grub-install ( Fedora
openSUSE grub2-install) ( MBR
, ).
,
, .
Linux (, /dev/sda), GRUB (,
(hd0)):
root# grub-install /dev/sda


( grub-install/dev/sda3 (hd0,3)), , GRUB0.97.
GRUB, - . (- ,
/
GRUB-.) , --force.

448

15. GRUB

: BIOS GPT. Linux /


, GUID,
BIOS. ( Windows, , , EFI,
GPT.)
, GRUB GRUB 1, bios_grub. BIOS .
bios_grub . Fedora16
,
GPT ( 17
Fedora , GPT
).
, .
bios_grub parted, n :
root# parted /dev/sda set n bios_grub on


bios
_
grub
, !
GRUB
; , , !

GRUB bios_grub, , , GRUB , , bios_grub.


GRUB GPT, ,
. , (Windows).
:
, GRUB-2, GRUB bios_grub . GRUB GPT : http://www.gnu.org/software/grub/manual/html_node/BIOS-installation.html
http://www.wensley.org.uk/gpt.
GRUB ( BIOS).
GRUB -
, GRUB ,
GRUB2.
(root) ( Ubuntu sudo-s),
, /dev, /proc /sys , chroot. ,
root- . GRUB GRUB
grub[2]-install ( ). , /dev/
sdan .

15.3. GRUB2

root#
root#
root#
root#
root#
root#
root#
root#
root#
root#
root#
root#

449

mkdir /syspart
mount /dev/sda2 /syspart ( )
mount -o bind /dev /syspart/dev
mount -o bind /proc /syspart/proc
mount -o bind /sys /syspart/sys
chroot /syspart
mount /dev/sda1 /boot ( )
update-grub (Ubuntu)
grub-install /dev/sda (Ubuntu)
grub2-mkconfig -o /boot/grub2/grub.cfg (Fedora, openSUSE)
grub2-install /dev/sda (Fedora, openSUSE)
exit


EFI
Ubuntu,
2012 ,
GRUB2 EFI.
EFI, .
: EFI- Fedora17 EFI- GRUB0.97. ,
EFI- GRUB2, GRUB2
. , Fedora grub2-efi ,
: https://bugzilla.redhat.com/show_bug.
cgi?id=816742.
grub-install. GRUB2
EFI . grub-install :
root# grub-install

/boot/efi/EFI/distributionsname. .efi, GRUB-.


, .efi EFI,
. grub-install
efibootmgr, .
grub-install .
GRUB /boot/grub[2]/grub.cfg.
EFI- /boot/efi.
efibootmgr .
efivars. modprobe efivars
, EFI-, BIOS-.
EFI-

450

15. GRUB

EFI Linux, BIOS.


GRUB ( EFI). GRUB EFI ,
BIOS (.). ,
EFI, BIOS.
(root),
, /dev, /proc /sys , chroot. ,
root- .
GRUB GRUB EFI grub-install. , /dev/sdan .
root#
root#
root#
root#
root#
root#
root#
root#
root#
root#

mkdir /syspart
mount /dev/sda2 /syspart ( )
mount -o bind /dev /syspart/dev
mount -o bind /proc /syspart/proc
mount -o bind /sys /syspart/sys
chroot /syspart
mount /dev/sda1 /boot/efi ( EFI)
update-grub
grub-install
exit

GRUB Linux
GRUB , Linux GRUB , , C,
GRUB , :
grub>
grub>
grub>
grub>

set root=(hd0,1)
linux /vmlinuz root=/dev/sda1
initrd /initrd.img
boot

(hd0,1) /dev/sda1 Linux.


/vmlinuz /initrd.img
Initrd. /boot.
, Initrd-. GRUB
, Tab.

EFI
(efibootmgr)
EFI ,
, , ? EFI (NVRAM).

15.3. GRUB2

451

, *.efi-
EFI-, .
Linux EFI-, ,
efibootmgr. , efivars. , modprobe efivars. : efivars , Linux
EFI ( BIOS!).
Linux,
EFI-.
efibootmgr ,
EFI,
EFI. , , , Ubuntu, Fedora Windows EFI-.
( ) Ubuntu
(BootCurrent). EFI , ( F8).
root# efibootmgr
BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0000,0005,0003,0001,0002
Boot0000* ubuntu
Boot0001* Hard Drive
Boot0002* CD/DVD-drive
Boot0003* Windows Boot Manager
Boot0005* Fedora

Fedora, -n:
root# efibootmgr -n 5

, -o:
root# efibootmgr -o 5

EFI. EFI ( /boot/efi),


\. \ ,
\ . -L , EFI.
root# efibootmgr -c -l \\EFI\\test\\abc.efi -L abc

, .
-b:
root# efibootmgr -b 6 -B

efibootmgr man
.

452

15. GRUB

15.4. GRUB0.97
, GRUB0.97. GRUB,
.
: GRUB0.97 Linux RAID, LVM-. , GRUB0.97
(, btrfs). , RAID LVM ,
GRUB0.97 (, ext2 ext3).
GRUB0.97,
ext4.

( )
Menu.lst. GRUB GRUB,
/boot/grub/menu.lst. GRUB2,
. GRUB2,
,
.
, .
Linux GRUB .
, . , GRUB .
Debian Ubuntu GRUB
update-grub. .
Red Hat Fedora , update-grub, grubby. GRUB RHEL,
Fedora GRUB0.97 /etc/grub.conf.
.
GRUB SUSE YAST
.
. GRUB0.97 ,
GRUB2. :
0, 1;
,
.
, , GRUB2 (hd0,gpt3), GRUB0.97 (hd0,2).
.15.3 .

453

15.4. GRUB0.97
15.3. GRUB

GRUB2

(hd0)

( /dev/sda)

(hd1)

( /dev/sdb)

(hd0,0)

( /dev/sda1)

(hd2,7)

devices.map. GRUB /boot/


grub/devices.map .
GRUB. , . devices.map , GRUB.
. .

. , , GRUB BIOS .
:
# /boot/grub/devices.map
(hd0) /dev/sda
(hd1) /dev/sdb

menu.lst
GRUB ,
, , title. ,
menu.lst:
# /boot/grub/menu.lst
default 2
#
timeout 30
# 30 ,
# ,
color yellow/blue red/white #

GRUB, menu.lst.
default , .
0! default saved.

, . , savedefault ( ). menu.lst
default, ,
.
fallback , , , , . fallback

454

15. GRUB

, GRUB, , .
timeout , ( ) GRUB
. , . ,
GRUB , ,
, timeout #.
hiddenmenu GRUB . ,
timeout, .
, Esc,
.
password -- md5 code GRUB . , GRUB
.
color fg/bg menufg/menubg , GRUB.
fg , bg .
, menufg menubg
. color, GRUB .
splashimage Linux, GRUB
(, Fedora). ,
splashimage GRUB.
,
640480, XPM (8 ) GZIP. , splashimage:

splashimage=(hd1,1)/boot/grub/splash.xpm.gz

: http://www.owlriver.com/
tips/hands-off/images.html.
gfxmenu , . , , Novell
SUSE. mkbootmsg. , gfxboot.html, , gfxboot. , -,
.

menu.lst
menu.lst , . title.
, title, . , , ,
US-ASCII, .
, menu.lst.

15.4. GRUB0.97

455

( title )
GRUB, , . (
, boot. .)
Linux. Linux, root ,
. GRUB . kernel
initrd , , .
, ( ,
) Linux. : root=/dev/sdb13. ,
, root=LABEL=label root=UUID=n,
.
, vmlinuz initrd.
# /boot/grub/menu.lst
# Linux /dev/sdb13
title Linux
root (hd1,12)
kernel /boot/vmlinuz root=/dev/sdb13
initrd /boot/initrd

root.
:
# Linux /dev/sdb13
title Linux
kernel (hd1,12)/boot/vmlinuz root=/dev/sdb13
initrd (hd1,12)/boot/initrd

/boot , , root-. ,
/boot. , /dev/sda2
/boot ( root (hd0,1)).
# Linux /dev/sdb13,
# /dev/sda2
title Linux
root (hd0,1)
kernel /vmlinuz root=/dev/sdb13
initrd /initrd

UUID. Ubuntu
initrd root, GRUB uuid.
, Ubuntu,
GRUB. uuid Ubuntu USB-.

456

15. GRUB

# Linux, Ubuntu;
# UUID=2a021cf3-..., LVM
title Ubuntu
uuid 2a021cf3-2b34-4cd4-b741-42b8fb1db89c
kernel /vmlinuz-3.1-13-generic root=/dev/mapper/vg1-ubuntu904 ro quiet
initrd /initrd.img-3.1-13-generic

Linux.
. , , ,
, , Init-V.
menu.lst kernel.
# Linux /dev/sdb13 ( )
title Linux
root (hd1,12)
kernel /boot/vmlinuz root=/dev/sdb13 vga=normal
initrd /boot/initrd

Windows. Windows,
root, rootnoverify. chainloader +1
. Windows 9x/ME
. Windows,
, Windows, , , ( GRUB Windows).
# Windows /dev/sda1
title Windows
rootnoverify (hd0,0)
chainloader +1

Windows ,
. , . .
# Windows /dev/sdb1
title Windows
rootnoverify (hd1,0)
map (hd0) (hd1)
map (hd1) (hd0)
chainloader +1

. , GRUB, MBR .
. GRUB, MBR, GRUB, . menu.lst ,
Windows:
# /dev/sda7
title Boot-Loader in /dev/sda7
rootnoverify (hd0,6)
chainloader +1

15.4. GRUB0.97

457

,
Linux.
. menu.lst
, , GRUB . ,
menu.lst default saved
savedefault:
# Linux /dev/sdb13;
title Linux
root (hd1,12)
kernel /boot/vmlinuz root=/dev/sdb13
initrd /boot/initrd
savedefault

savedefault , BIOS
, RAID (BIOS-Software-RAID)!
!

GRUB
,
GRUB , GRUB
:
root# grub
grub> configfile (hd1,12)/boot/grub/menu.lst

(hd1,12) GRUB
, . , GRUB . , ,
Linux.

update-grub (Debian Ubuntu)


Debian 5 Ubuntu 9.04 GRUB
update-grub. /boot
vmlinuz-* .
initrd-*,
. update-grub
.
, menu.lst,
. man
update-grub. kopt ,
. menu.lst ,
, menu.lst
kopt. update-grub.

458

15. GRUB

# /etc/boot/menu.lst
...
# update-grub
#
# kopt=root=/dev/sda13 ro ( )
# groot=(hd0,12)
(, GRUB)
# alternative=true
( )
# lockalternative=false
( )
# defoptions=
(, ,
)
# lockold=false
( ,
)
# xenhopt=
( Xen)
# xenkopt=console=tty0
( Xen)
# altoptions=(single-user mode) single ( )
# howmany=all
( , )
# memtest86=true
( Memtest)
# updatedefaultentry=false ( , menu.lst
)
...

Grubby (Fedora, Red Hat)


RHEL Fedora GRUB grubby.
man.
, grubby
, Red Hat,
.

GRUB0.97 EFI
Red Hat Fedora GRUB0.97 EFI. GRUB0.97, , EFI. Fedora Red Hat
. GRUB2 GRUB0.97 EFI
.
grub.efi,
BIOS /boot/efi/EFI/redhat.
grub. /boot/efi , .
BIOS EFI,
, EFI
/boot/efi.
grub.efi .
EFI /etc/grub.conf /boot/efi/EFI/
redhat/grub.conf. grub.conf , BIOS- GRUB0.97.
EFI devices.map.

15.4. GRUB0.97

459

GRUB

su -l
sudo -s, . ,
Linux , , /boot.
root# mkdir /test
root# mount /dev/sda3 /test

/boot Linux
(vmlinuzxxx), /boot/grub GRUB /boot/grub/menu.lst.
,
boot. vmlinuzxxx grub
.
,
GRUB . GRUB, /dev/sda3.
/dev/sda3 GRUB (hd0,2), (hd0)
,
GRUB.
root#
grub>
grub>
grub>

grub
root (hd0,2) ( , )
setup (hd0) ( GRUB: MBR )
quit

16

Init

,
. . /sbin/init.
init
( ) .
Linux, , Init.
Init-V, Upstart Systemd.
Init-V , . V,
UNIX. Init-V ,
Debian.
Init-V .
- Init-V.
.
Upstart - Init. Ubuntu
6 , Fedora 9
13 RHEL 6.
Systemd Init-,
Fedora 15. openSUSE , 12.1.
.16.1 , Init
. RHEL Red Hat Enterprise Linux, , CentOS.
16.1. Init- ,
Init

Debian

Fedora

openSUSE

RHEL

Ubuntu

Init-V

11.4

6.04

Upstart

9 13

6.10

Systemd

14

12.1

16.1. Init-V

461

Init-V, Upstart Systemd, Devian, Fedora,


openSUSE Ubuntu.
Internet Service Daemons ,
.
Internet Service Daemons ,
.

16.1. Init-V
,
Init-V. ,
.
, /sbin/init: init , , ..
Fedora, openSUSE Ubuntu
Upstart Systemd,
. , Upstart, Systemd Init-V, , Init-V, .
. ,
Linux Init-V.
1. GRUB .
2. /sbin/init.
3. init /etc/inittab.
4. init .
5. init /etc/rc.d/rc /etc/init.d/rc.
rc .
, /etc/rcn.d /etc/init.d/rcn.d (n
, . ). , rc
, , Init-V.
6. /etc/rcn.d /etc/init.d/rcn.d
, ,
.


/sbin/init.
, ( ,

462

16. Init

, , ).
Linux , ,
( man init). , init
. init , ( pstree,
, init).
init ,
.
Fedora, Red Hat, SUSE. ,
System-V, , .
, . , . ,
/etc/inittab.
( Debian Ubuntu!)
:
0 ;
1 S ;
2 NFS;
3 ,
X;
4 ;
5 X;
;
6 .
1 S.
1,
(2, 3 5) . , S
,
( single).
Debian Ubuntu. ,
Debian, 25 .
X. 2. S
,
( , - ).
Debian Ubuntu (
), ,
:
S ;
0 ;
1 ;

463

16.1. Init-V

25 -

X;
6 .
. init x, . x
, . ,
. shutdown Ctrl+Alt+Delete
, .
. Init-V
initdefault /etc/inittab.
5; Debian
Ubuntu 2.
Ubuntu 9.10 /etc/
init/rc-sysinit.conf. Upstart.
, Systemd, /etc/systemd/default.target.
/lib/systemd/system/.

Inittab
init /etc/inittab.
:
id-code:runlevel:action:command
id-code , .
runlevel , . action
init. command , Linux
. .16.2 action (
man inittab).
16.2.

ctrlaltdel

, init Ctrl+Alt+Delete

initdefault

init (. )

once

init

respawn

init

sysinit

init

wait

init

bootwait

init

inittab Debian6.
2. init
rcS rc 5. , 16 mingetty, . (

464

16. Init

, . , 7 X.)
# /etc/inittab Debian 6
#
id:2:initdefault:
#
#
si::sysinit:/etc/init.d/rcS
# ( su)
~~:S:wait:/sbin/sulogin
#
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# ,
#
z6:6:respawn:/sbin/sulogin
# Ctrl+Alt+Delete
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
#
# ( )
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop
# gettys ( )
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

Ctrl+Alt+Delete.
, Ctrl+Alt+Delete
. ,
, shutdown ca: -h
-r. ,
ca: #. , inittab
, Init-V.

16.1. Init-V

465


rc
runlevel- , , ( si: inittab).
:
Debian, Ubuntu 6.06 /etc/init.d/rcS;
RHEL 5, Fedora 8 /etc/rc.d/rc.sysinit;
openSUSE 11.4 /etc/init.d/boot.
,
, :
( - );
/proc;
;
;
udev;
RAID LVM;
;
, ;
, ;
(Fedora) (Debian, Ubuntu)
.
.
. . ( , , ;
). Debian Ubuntu rcS, /etc/rcS.d/S*.

Init-V

/etc/inittab. , ,
.
/etc/init.d /etc/rc.d/init.d. ,
.
Init-V init /etc/rc.d/rc
/etc/init.d/rc. rc n. rc , .

466

16. Init

rcn.d/K*, . , rcn.d/S*,
.
,
Init-V.
rc ,
. Debian5 ,
.
user$ cd /etc/rc.d
user$ ls rcS.d/ rc2.d/ rc6.d/
rcS.d/: ( )
S01mountkernfs.sh
S07checkroot.sh S12mountoverflowtmp S16mountnfs.sh
S02udev S08hwclock.sh S13networking S17mountnfs-boo...
S03mountdevsubfs.sh S08ifupdown-clean S13pppd-dns S18console-scre...
S04bootlogd S08module-init-tools
S13procps S19console-setup
S05keyboard-setup
S08mtab.sh S13udev-mtab
S 20alsa-utils
S06hdparm S09checkfs.sh S13urandom S20bootmisc.sh
S06hostname.sh S10ifupdown S13x11-common S20fuse
S06hwclockfirst.sh
S10mountall.sh S14portmap S21stop-bootlog...
S06lvm2 S11mountall-bootclean.sh
S15nfs-common
rc2.d/:rc2.d/: ( )
S01vboxadd S18acpid S18ssh S21bootlogs
S02vboxadd-service
S18anacron S19avahi-daemon S22rc.local
S14portmap S18atd S19bluetooth S22rmnologin
S15nfs-common S18cron S19cpufrequtils S22stop-bootlogd
S17binfmt-support
S18dbus S19network-manager
S17rsyslog S18exim4 S20gdm3
S17sudo S18loadcpufreq S20saned
c6.d/: ( )
K01alsa-utils K01network-manager K03sendsigs K08ifupdown
K01anacron K01saned K04rsyslog K09umountfs
K01atd K01unattended-upgrades
K05umountnfs.sh
K10lvm2
K01bluetooth K01urandom K06nfs-common K11umountroot
K01exim4 K01vboxadd-service K06portmap K12reboot
K01fuse K02avahi-daemon K07hwclock.sh
K01gdm3 K02vboxadd K07networking

, rcn.d ,
. ,
. /etc/rc.d/
init.d /etc/init.d:
root# cd /etc
root# ls -l rc2.d/S20cups
... rc2.d/S20cups -> ../init.d/cups

467

16.1. Init-V


,
. , (S=start)
(K=kill). S K , rc start,
stop.
, . , ,
, network.


rc .
start stop ,
.
, S K Init-V rcn.d. , ,
, . , , .
, Red Hat,
Samba
2 5:
root#
root#
root#
root#
root#
root#
root#
root#

cd
ln
ln
ln
ln
ln
ln
ln

/etc/
init.d/samba
init.d/samba
init.d/samba
init.d/samba
init.d/samba
init.d/samba
init.d/samba

rc0.d/K01samba
rc1.d/K01samba
rc2.d/S17samba
rc3.d/S17samba
rc4.d/S17samba
rc5.d/S17samba
rc6.d/K01samba

:
root# rm rc?.d/*samba


ln rm. ,
, insserv Debian 6 ,
SUSE, chkconfig RHEL5 Fedora Mandriva update-rc.d
Debian Ubuntu.


. , - Apache:
root# /etc/init.d/samba stop

468

16. Init

, . service.
, ,
Init-V ( Debian 7 !).
root# service samba start

Init-V-Script
:
start ;
stop ;
status , ;
reload ,
;
restart
. .
reload / restart .
stop , start.

chkconfig (Fedora, Red Hat)


Fedora RHEL chkconfig . --list
, . xinetd, .
root# chkconfig --list
NetworkManager 0:Off 1:Off 2:On 3:On 4:On 5:On 6:Off
NetworkManagerD 0:Off 1:Off 2:Off 3:Off 4:Off 5:Off 6:Off
acpid 0:Off
1:Off
2:Off
3:On 4:On 5:On 6:Off
...
xinetd:
chargen-udp: Off
...

--del . , rcn.d.
root# chkconfig --del samba

chkconfig --add
, . ,
--add , Init-V
, .
. , chkconfig --leveln

16.1. Init-V

469

name on/off. , ,

, ,
.
, /etc/rc.d/init.d/httpd
, . chkconfig --add -.
Chkconfig --level - 3 5. chkconfig
--list :
root# chkconfig --add httpd
root# chkconfig --level 35 httpd on
root# chkconfig --list httpd
httpd 0:Off 1:Off 2:Off 3:On 4:Off 5: On 6: Off

chkconfig --add chkconfig --del xinetd.


Xinetd , ,
. chkconfig Init-V system-configservices. serviceconf.
,
xinetd. , ( ) ,
.

Init-V
, , , Init-V : .
( , bash dash).
- .
. .
. . , , (
). ,
Init-V , , . -
,
.
Init-V Upstart Systemd.
RHEL readahead, Ubuntu ureadahead.
Fedora openSUSE Systemd readahead.
Debian .

470

16. Init

, , , .
. Init-V ,
Init-V . ,
NFS, . ,
NFS ,
. Init-V . , ,
, -. Init-V,
.
X.
X Init-V. X , .
X
Init-V.

16.2. Upstart
Ubuntu , Init-V 6.10 Upstart. Fedora Ubuntu 9, 15,
Systemd. RHEL 6 Upstart.
RHEL7, Systemd.
Ubuntu
, Upstart.

Upstart1.3 Ubuntu12.10. ,
Upstart . init,
initctl, telinit runlevel :
http://upstart.ubuntu.com/;
http://upstart.ubuntu.com/cookbook/;
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Technical_Notes/
deployment.html.

. Upstart Init-V. Upstart


- .
. Upstart
, () .
.
Init-V, /sbin/init
. init Upstart

16.2. Upstart

471

init Init-V! init


.
startup.
/sbin/init. Init-V
Upstart .
runlevel n.
. /etc/inittab . /etc/init. /sbin/init CONF- .
:
# /etc/init/tty1.conf
start on stopped rc RUNLEVEL=[2345] and (
not-container or
container CONTAINER=lxc or
container CONTAINER=lxc-libvirt)
stop on runlevel [!2345]
respawn
exec /sbin/getty -8 38400 tty1

( getty) 1. exec , , , start,


rc2-rc5. getty , , stop on. respawn getty , .
, , :
exec,
script/end script. , , /bin/sh.
, per-start script/end script
post-stop script/end script. console output
, /dev/null ( ).
Ctrl+Alt+Delete control-alt-delete.conf.
Upstart , emits eventname.
man (., , man local-filesystems).
, Upstart ,
/etc/init! , ifup /etc/network/if-up.d/
upstart initctl. , ,
telinit.
c Init-V. Upstart , ,
. ,
, Init-V, /etc/
init.d/rc /etc/rc.d/rc. Upstart

472

16. Init

rc.conf rcS.conf. /etc/init.d/rc -

Init-V, ,
, /etc/rcn.d.
: ,
Upstart, Init-V, /etc/init.d/
Upstart /lib/init/upstart-job.
Upstart. ,
Ubuntu9.10 /etc/init.d/gdm, upstart-job stop gdm.
/etc/init.d, , Upstart (ls -l /etc/init.d).
Ubuntu Init-V .
Upstart. : Ubuntu12.04,
LTS- Ubuntu ,
(, Apache, Postfix SSH)
Init-V.
. Upstart .
, .. ,
, Upstart.
, Init-V, Debian ( invoke.rc, update-rc.d
..).
start stop, , ,
/etc/event.d ; status ,
.
root# status tty2
tty2 start/running, process 4116
root# stop tty2
tty2 stop/waiting

start stop service, :


root# service tty1 stop
root# service tty1 start
root# service tty1 restart

, initctl ,
(. man
initctl). , initctl emit eventname .
. initclt list :
root# initctl list | sort
acpid start/running, process 751
alsa-restore stop/waiting

16.3. Systemd

473

alsa-store stop/waiting
anacron stop/waiting
apport stop/waiting
atd start/running, process 753
...

. , Upstart
. Init-V Upstart Init-V. runlevel
; telinit n init n n.
Fedora RHEL. Fedora913
RHEL6 Upstart,
- /etc/inittab.
, , ! X 1 ( 7, ).
, 5 .
I, touch /var/run/confirm; /etc/rc.d/rc.
, rcn.d Yes/No/Continue (//),
, . ,
Init-V . ,

.
/etc/rc.d/rc.local
Init-V. Init-V,
2, 3, 4 5. !
Fedora, Systemd.

16.3. Systemd
Systemd Init, Red Hat
Fedora15. Systemd openSUSE, 12.1. Debian 7
Systemd, Debian7 Init-V.
, Init-V Systemd
,
, . Systemd
. (
Init-V , , .)
Systemd ,
. Upstart,

474

16. Init

Init-V, , , ipenSUSE 11.4 Debian,


.
Systemd Cgroups . Cgroups Control Groups ( ).
, 2.6.24, ( , , /). Systemd
(Cgroup). 0, Systemd ,
(, ),
.
. systemd systemctl. , ..
, *.service.
root# systemctl start
ntpd.service
root# systemctl stop
ntpd.service
root# systemctl restart ntpd.service
root# systemctl reload ntpd.service

root# systemctl status ntpd.service

( NTP-)
( NTP-)
( NTP-)
(
NTP-)
(
NTP-)

systemctl , ( chkconfig xxx on/off):


root# systemctl enable ntpd.service ( NTP- )
ln -s '/lib/systemd/system/ntpd.service'
'/etc/systemd/system/multi-user.target.wants/ntpd.service'
root# systemctl disable ntpd.service (
NTP- )
rm '/etc/systemd/system/multi-user.target.wants/ntpd.service'

, ,
. Init-V
.
systemctl ,
, Systemd:
user$ systemctl
UNIT LOAD
ACTIVE SUB JOB DESCRIPTION
abrt-ccpp.service loaded active exited Install ABRT coredump hook
abrtd.service loaded active running ABRT Automated Bug
Reporting Tool
abrt-oops.service loaded active running ABRT kernel log watcher
abrt-vmcore.service loaded active exited Harvest vmcores for ABRT
...
121 units listed. Pass --all to see inactive units, too.

. Systemd ,
. target (). , .

475

16.3. Systemd

, 0 oweroff.target, 5
graphical.target.
Init-V, Systemd
. .
, ,
5 ( graphical.target).
user$ systemctl list-units --type=target
UNIT LOAD
ACTIVE SUB JOB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User
network.target loaded active active Network
remote-fs.target loaded active active Remote File Systems
sockets.target loaded active active Sockets
sound.target loaded active active Sound Card
swap.target loaded active active Swap
sysinit.target loaded active active System Initialization
syslog.target loaded active active Syslog
LOAD
ACTIVE
SUB
JOB

=
=
=
=

Reflects whether the unit definition was properly loaded.


The high-level unit activation state, i.e. generalization of SUB.
The low-level unit activation state, values depend on unit type.
Pending job for the unit.

14 units listed. Pass --all to see inactive units, too.

, :
root# systemctl isolate reboot.target ( )

/etc/systemd/system/default.target.
, ,
( 3):
root# ln -sf /lib/systemd/system/multi-user.target
/etc/systemd/system/default.target

. systemd /etc/
systemd/ /lib/systemd/. , Fedora17
250. ,
, Init-V.
Systemd (Units). ,
. , , ,
(), ..

476

16. Init

*.target- .
, , , , ,
.
.target.wants, , . , /lib/systemd/
system/sysinit.target.wants *.service,
.
*.service- , .
/etc/systemd/system /lib/systemd/system. httpd.service,
Fedora - Apache.
# /lib/systemd/system/httpds.service
[Unit]
Description=The Apache HTTP Server (prefork MPM)
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/httpd/httpd.pid
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -k start
ExecReload=/usr/sbin/httpd $OPTIONS -t
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/sbin/httpd $OPTIONS -k stop
[Install]
WantedBy=multi-user.target

, , Systemd
, systemadm (.16.1). Fedora
systemd-gtk.
. ,
, .
systemctl dot, .
dot graphvic SVG ( ). Firefox Inkscape.
,
. .16.2 !
user$ systemctl dot | dot -Tsvg > ~/systemd.svg

Ctrl+Alt+Delete.
Ctrl+Alt+Delete, .
/lib/systemd/system/ctrl-alt-del.target.

477

16.3. Systemd

.16.1. Systemd systemadm

.16.2. , Systemd

478

16. Init

.
Systemd
, () . , .
Fedora,
.
/run. Systemd
/run, /var/run, . /run , . /run
, , /var.
/var/run ,

/run ( mount --bind /run /var/run). /var/lock
/run/lock. /var/run /run. Ubuntu, ,
Upstart, Systemd.
Linux http://thread.gmane.org/
gmane.linux.redhat.fedora.devel/146976.
. Systemd Init-V.
Init, /etc/init.d/, ,
. Fedora Systemd,
openSUSE /etc/init.d/ - ,
Systemd.
service, ,
Systemd. , , service httpd,
service , - Systemd, systemctl stop
httpd.service.
. Systemd . ,
, Systemd, ( , man systemd).
, . , Systemd
Init-V, :
http://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet;
http://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions.

16.4. Debian
.16.3 , Debian ,
Init-V. 2. .16.3 ,
.

479

16.4. Debian
16.3. Debian

/etc/init.d/rcS, /etc/rcS.d/*

Init

/etc/init.d/*

/etc/rcn.d/rcn.d/*

/etc/default/*

 









  


  

  


  


  

  


  


  

  

.16.3. 2 Debian

. , , .
,
. , , ,
rc ,
start stop.
Init-V. invoke.rc
Init-V .
root# invoke.rc samba restart

480

16. Init

X. X Init-V gdm.
.
Init-V. Init-V
Debian Init-V
. ,
,
.
. ,
:
# /etc/init.d/rc
...
CONCURRENCY=shell

Init-V. /etc/init.d/
rc.local Init-V. , Init-V , 2, 3, 4 5.

( - )!
Init-V (insserv). Debian 6 ( SUSE
) insserv.
root# insserv samba ( )
root# insserv -r samba ( )

Init-V (update-rc.d). update-rc.d .


Init-V .
Debian, Ubuntu . . , ,
update-rc.d, ,
! .
update-rc.d remove , . , /etc/init.d/ . , -f.
update-rc.d defaults
( 2-5) ( 0, 1 6) .
30.
, ( 13 , 1 ):
root# update-rc.d gdm defaults 20 1
/etc/rc0.d/K01gdm -> ../init.d/gdm
/etc/rc1.d/K01gdm -> ../init.d/gdm
/etc/rc6.d/K01gdm -> ../init.d/gdm

16.4. Debian

/etc/rc2.d/S20gdm
/etc/rc3.d/S20gdm
/etc/rc4.d/S20gdm
/etc/rc5.d/S20gdm

->
->
->
->

481

../init.d/gdm
../init.d/gdm
../init.d/gdm
../init.d/gdm

,
update-rc.d start|stop nn runlevel. nn ,
.
. . , gdm defaults 30 1.
root# update-rc.d gdm start 30 2 3 4 5 . stop 1 0 1 6 .
Adding system startup for /etc/init.d/gdm ...
/etc/rc0.d/K01gdm -> ../init.d/gdm
/etc/rc1.d/K01gdm -> ../init.d/gdm
/etc/rc6.d/K01gdm -> ../init.d/gdm
/etc/rc2.d/S30gdm -> ../init.d/gdm
/etc/rc3.d/S30gdm -> ../init.d/gdm
/etc/rc4.d/S30gdm -> ../init.d/gdm
/etc/rc5.d/S30gdm -> ../init.d/gdm

X,
Gnome services-admin,
.
Init-V. ,
Init-V /etc/init.d/masquerading,
, , , -
( ). INIT-INFO
,
.
#!/bin/sh
### BEGIN INIT INFO
# Provides: masquerading
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start masquerading
### END INIT INFO
DESC="masquerading"
#
ADSL=eth1
# ,
#
. /lib/lsb/init-functions #
IPT=$(which iptables)
# iptables
if [ -z $IPT ]; then
[ -x /sbin/iptables ] && IPT=/sbin/iptables
[ -x /usr/sbin/iptables ] && IPT=/usr/sbin/iptables
fi
[ -z $IPT ] && (echo "iptables cannot be found!"; exit 0)

482

16. Init

# start, stop restart


case "$1" in
start)
log_begin_msg "Starting masquerading ..."
ERROR=0
$IPT -t nat -A POSTROUTING -o $ADSL -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
log_end_msg $ERROR
;;
stop)
log_begin_msg "Stopping masquerading ..."
ERROR=0
echo 0 > /proc/sys/net/ipv4/ip_forward
$IPT -t nat -D POSTROUTING -o $ADSL -j MASQUERADE
log_end_msg $ERROR
;;
restart)
$0 stop
$0 start
;;
*)
log_success_msg "Usage: masquerading {start|stop|restart}"
exit 1
;;
esac
exit 0

, :
root# insserv masquerading

16.5. Fedora
.16.4 ,
5 . .16.4 , . Fedora17
Systemd. , Systemd , Fedora15.
Fedora, RHEL6,
Upstart, RHEL5 Init-V.
Systemd Fedora . /etc/init.d/
, /etc/rc.d/rcsysconfig, , .
X. X /lib/
systemd/system/prefdm.service. /lib/systemd/system/graphical.target.wants
display-manager.service, , ,
prefdm.service. , -

483

16.5. Fedora

, /etc/sysconfig/desktop.
DISPLAYMANAGER /etc/X11/prefdm.
16.4. Fedora

Systemd

/etc/systemd/*, /lib/systemd/*

Systemd

/etc/systemd/system/default.target

/lib/systemd/system/sysinit.target*

Init-

/etc/rc.d/init.d/*

Init-V

/etc/rc.d/rcn.d/*

/etc/sysconfig/*

 




 








  
  
 
   
  


 
   
   
  

.16.4. 5 Fedora openSUSE

(). , systemd,
/var/log/boot.log. Init-V, LSB ,
Linux Standard Base.
. Systemd , systemctl ,
system-config-services.
,
. Systemd.
Init-V. Systemd Init-V /etc/rcn.d. chkconfig, Fedora Red Hat, Init-V.

484

16. Init

/etc/rc.d/rc.local, , Fedora16 .
, - /etc/rc.d/rc.local. chmod ug+x
, .

16.6. SUSE
openSUSE Systemd,
.16.4 .
.16.5 ,
openSUSE.
16.5. SUSE

Systemd

/etc/systemd/*, /lib/systemd/*

Systemd

/etc/systemd/system/default.target

/lib/systemd/system/sysinit.target*

Init-

/etc/rc.d/init.d/*

Init-V

/etc/rc.d/rcn.d/*

/etc/sysconfig/*

X. X Init-V xdm.
(, kdm4),
DISPLAYMANAGER, /etc/sysconfig/displaymanager.
Init-V. openSUSE Systemd, Fedora: -
Init-V.
Init-V openSUSE -
/etc/init.d/name,
rcname ( Samba
rcsmb). /usr/sbin.
Insserv. /etc/init.d/rcn.d Init-V,
insserv scriptname. insserv
Default-Start Default-Stop . ,
.
root# insserv squid

, insserv
-r.
insserv (
,
Init-V). , ,
Provides Requires Init-V.
insserv , -

485

16.7. Ubuntu

. , ,
.
Chkconfig. chkconfig SUSE, ,
. -add, -del -list ,
Red Hat, .
chkconfig insserv.
Init-V. Init-V,
, , .
/etc/sysconfig/
boot. , Init-V
insserv ( ).
.depend.*,
Init-V. SUSE -,
init.d.
Rc.local. /etc/rc.d/boot.local .
,
. modprobe, . Boot.local
rc.

16.7. Ubuntu
.16.5 , Ubuntu12.10
Upstart. 2. .16.6 ,
.
16.6. Ubuntu

Upstart

/etc/init/*.conf

/etc/init.d/rcS, /etc/rcS.d/*

Init-

/etc/init.d/*

/etc/rcn.d/rcn.d/*

/etc/default/*

Ubuntu12.10 Upstart . , Init-V. ,


Init-V, , Debian.
. /etc/init/
rc-sysinit.conf.
X. X Upstart (. /etc/init/
lightdm.conf). X,
DBUS. .

486

16. Init

 




 



  

  


   


  


  


  


  


  


  

  

  
  

  


   
  

  

  


   

.16.5. 2 Ubuntu

Upstart. , /etc/init. , , ,
. exec, script,
pre-start script post-stop script.
.
# /etc/init/masquerading.conf
description "masquerading"
start on (starting network-interface
or starting network-manager
or starting networking)
stop on runlevel [!023456]
pre-start script
sysctl -q -w net.ipv4.ip_forward=1
iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE
end script
post-stop script
iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
sysctl -q -w net.ipv4.ip_forward=0
end script

487

16.8. -

start
masquerading stop masquerading. , start stop , .conf.
unknow job ( ), , , .
, init-checkconf:
user$ init-checkconf /etc/init/masquerading.conf
File masquerading.conf: syntax ok

16.8. -
, , .
-, .
, - Apache,
Samba, SSH-, .
Init-V (, ,
Upstart) IP-. IP-, ,
.
, . ,
-. IP- . -
Init-V.
- inetd. . openbsd-inetd xinetd.
.
, inetd,
(, SWAT).
/etc/services. , - , /etc/services
- (, FTP, Telnet ..),
. , ( ) 25 TCP UDP.
:
# /etc/services ()
#
/
ftp-data 20/tcp
ftp-data 20/udp
ftp
21/tcp
ssh
22/tcp

# [ ]
# [ ]
# []
# SSH
#

488

16. Init

ssh

22/udp

smtp
...

25/tcp

mail

# SSH
#
#

/etc/inetd.conf. openbsd-inetd,
/etc/inetd.conf.
, inetd.conf . .
, /etc/services.
,
( ).
, (nowait)
,
(wait). .
, .
, . tcpd
, , TCP-Wrapper.
# /etc/inetd.conf
swat stream tcp nowait.400 root /usr/sbin/tcpd /usr/sbin/swat
...

, inetd.
conf. , inetd, inetd.conf
. , , #, , ! , inetd.
conf, /etc/init.d/openbsd-inetd reload.
/etc/xinetd.conf. /etc/xinetd.conf
xinetd, , , IP-. , .
includedir, ( /etc/xinetd.d).
xinetd.d/*. /etc/xinetd.d , xinetd. /etc/
xinetd.d : xinetd
( ,
~ ).
.
RSYNC:
# /etc/xinetd.d/rsync
service rsync
{

16.8. -

disable
socket_type
wait
user
server
server_args
log_on_failure

489

= yes
= stream
= no
= root
= /usr/bin/rsync
= --daemon
+= USERID

,
xinetd. man xinetd.conf.
service ( /etc/services).
socket_type protocol ,
.
type=INTERNAL , xinetd .
server ( xinetd).
server_args ,
.
user , (
root, news, mail ..).
disable=Yes/No , .
, disable=Yes. Fedora
Red Hat xinetd
chkconfig --del , chkconfig --add .
disable, .
log_* , .
/etc/hosts.allow hosts.deny. , . , TCP-Wrapper. , xinetd, SSH, NFS CUPS SUSE.
hosts.allow hosts.deny
/etc/hosts.allow hosts.deny TCPWrapper 26.2.
openbsd-inetd: TCP-Wrapper, ! , openbsd-inetd -l. Debian Ubuntu
/etc/default/openbsd-inetd,
:
# /etc/default/openbsd-inetd (Debian, Ubuntu)
# TCP-Wrapper
OPTIONS="-l"

inetd.conf tcpd, TCP-Wrapper.

17

Linux . ,
, ,
. 17.1 ,
, .
. , , (,
VirtualBox). 17.2 ,
. 17.3
, /proc /sys . 17.4 ,
. , , 17.5 ,
.
,
Linux. ,
! , ,
2.6.n, 3.n. 2011 ,
, .
2.6.39 3.0
.

17.1.
Linux, ,
, ..
: ,
, , ,
.
(,
),
.

17.1.

491

, .
.
.

, , , .
, , ,
.
(,

)
.
.
.

.
, .
-

,
. , ,
. ( ,
. ,
,
.)

http://www.tldp.org/HOWTO/Module-HOWTO/.
. ,
, kmod,
. /etc/modprobe.conf,

.
. 2.6.15
:
, ( ).
/lib/modules/_.
, (, , ATI
NVIDIA), .
. 2.6.16
module versioning,
, : , , , , . , ()
. ,
module versioning , ,
,
.

492

17.

SUSE ,
module versioning, kernel-syms. module versioning
kernel symbol versions modversions.



. : mount
USB-.
vfat, .
, , , , ,
.
,
.
/lib/modules/n, n
. *.ko.
. uname -r :
user$ uname -r
3.5.0-2-generic

. insmod .
.
. ,
0x, option=0xff.
root# insmod /lib/modules/3.5.0-1.1-desktop/kernel/fs/fuse/fuse.ko

insmod -f ,
. , .
, insmod, modprobe.
: (
), , . , ,
/etc/modprobe.conf. modprobe ,
(modprobe.conf modules.dep).
root# modprobe fuse

. lsmod , ,
, :
root# lsmod | sort
Module
Size
ac
4933
autofs4
19013

Used by
0
1

493

17.1.

battery
bluetooth
button
...
fuse
...

9285
44069
6609

0
5 hidp,rfcomm,l2cap
0

36313

. rmmod
, .
, .
rmmod -a , .
root# rmmod fuse

. modinfo
. . e1000. Intel.
root# modinfo e1000
filename:
/lib/modules/3.5.0-1.1desktop/kernel/drivers/net/e1000/e1000.ko
version:
7.3.21-k8-NAPI
license:
GPL
description: Intel(R) PRO/1000 Network Driver
author:
Intel Corporation, <linux.nics@intel.com>
...
depends:
vermagic:
3.5.0-1.1-desktop SMP preempt mod_unload modversions
parm:
TxDescriptors:Number of transmit descriptors (array of int)
parm:
RxDescriptors:Number of receive descriptors (array of int)
...


.

, , .
SCSI, SCSI (
).
,
..
kmod, . ,
.
, .
,
. ,

494

17.

GRUB Initrd .
.

(, USB) Init-V, modprobe.


. ,

.

. , eth0 ,
, .
, .
/etc/modprobe.conf, /etc/modprobe.d.

, ,
( blacklist).
udev, , . /etc/udev/rules.d.
USB, Firewire ..
. *.*map /lib/modules/_/

, .
. . , nfs NFS ,
lockd, nfs_acl sunrpc. /lib/modules/n/modules.dep.

. ,
, , , . .
Debian Ubuntu .
Init-V /etc/init.d/module-init-tools , ,
/etc/modules, . ,
/etc/modules.
modprobe
_ Init-V, .
, Init-V (
):
Red Hat, Fedora /etc/rc.d/rc.local;
SUSE /etc/init.d/boot.local.

17.1.

495

modprobe

modprobe.conf , modprobe.d/.
man modprobe.conf.
Alias. ,
. : /dev/eth0
8139too.
alias eth0 8139too


- (/dev/xxx). , , .
alias
. :

net-pf-n. 5 AppleTalk.
alias net-pf-5 appletalk


, :
alias net-pf-5 off

Options. options , . ne (
NE-2000 Ethernet-) io=0x300.
options ne io=0x300

Include. include .
Install. install ,
. ,
. ALSA snd,
:
install snd modprobe --ignore-install snd $CMDLINE_OPTS && \
{ modprobe -Qb snd-ioctl32 ; : ; }

Remove. remove , .
Blacklist. blacklist alias-
. , blacklist /etc/
modprobe.d/blacklist. ,
- , . , usbmouse.
blacklist usbmouse

496

17.


Linux VirtualBox,
ATI NVIDIA , , , .
.
gcc make, . , , :
Debian, Ubuntu apt-get install build-essential;
Fedora yum groupinstall development-tools;
SUSE zypper install -t pattern devel_basis.
. , () . .
( SUSE) , .
, ( ),
. ,
. n.n
,
(, amd64). uname -a.
Debian linux-headers-n.n- (/usr/include/linux);
Fedora, Red Hat kernel-[PAE-]devel-n.n (/lib/modules/n.n/build/include);
SUSE kernel-source (/usr/src/linux-n.n/include);
Ubuntu linux-headers-generic (/usr/include/linux).
( ), , , /lib/modules/n.n/build/include.
PAE. PAE Physical Address Extension (
). , 32-
4 . PAE, , No Execute (NX).
. 32- , PAE.
. , , ,
. , , VMware, VirtualBox,
ATI/AMD, NVIDIA ..
-

17.1.

497

(. DKMS ).
, , ,
, . , , . make .
user$
user$
user$
root#

cd source code directory


make clean
make
make install

module-assistant. Debian Ubuntu module-assistant,


m-a, ,
. module-assistant m-a prepare
; m-a update
module-assistant; m-a list , m-a.
root# apt-get install module-assistant
root# m-a prepare
root# m-a update

,
m-a auto-install, m-a a-i: Debian
-source, , , . ,
, , , /etc/apt/sources.list. Debian ,
contrib non-free; Ubuntu
restricted, universe multiverse.
root# m-a auto-install nvidia

m-a a-i , .
, module-assistant, Ubuntu
, ( ) m-a.
, Debian m-a .
m-a , , .
DKMS. (Dynamic Kernel Module
Support). . DKMS
shell- Dell. DKMS Debian, Fedora Ubuntu. , module-assistant,
DKMS.

498

17.

DKMS,
/usr/src/name-version. dkms.conf, DKMS, .
NVIDIA Ubuntu,
, .
# /usr/src/nvidia-195.36.24/dkms.conf
PACKAGE_NAME
= "nvidia"
PACKAGE_VERSION
= "195.36.24"
CLEAN
= "make clean"
BUILT_MODULE_NAME[0]
= "nvidia"
MAKE[0]
= "make module KERNDIR=/lib/modules/$kernelver \
IGNORE_XEN_PRESENCE=1 IGNORE_CC_MISMATCH=1 \
SYSSRC=$kernel_source_dir"
DEST_MODULE_LOCATION[0] = "/kernel/drivers/video/nvidia"
AUTOINSTALL
= "yes"
PATCH[0]
= "vga_arbiter_workaround.patch"
PATCH_MATCH[0]
= "^2.6.32"

, DKMS dkms add, dkms build ,


dkms install. .
NVIDIA. (
Ubuntu. ,
, , , . ,
.)
root# dkms add -m nvidia-current -v 195.36.24
root# dkms build -m nvidia-current -v 195.36.24
root# dkms install -m nvidia-current -v 195.36.24

dkms status /var/lib/dkms, ,


DKMS. DKMS
http://www.linuxjournal.com/article/6896 http://wiki.centos.org/
HowTos/BuildingKernelModules.

17.2.

Linux
. .

:
(
, Linux);

17.2.

499

, ,

;
, ,
;
, ;
:
Linux!
. , .
, ,
(, , .
).
: ,
. ,
, .
, ,
.
. . 1000. ,
,
, . ,
, : .
Linux .

, - , ,
. ,
. ,
,
, ,
.
.
, (.
17.1).

. 2.6.0 (2.0.n, 2.2.n,


2.4.n) (2.3.n, 2.5.n ..).

500

17.

Linux , , . ( )
.
2.6, . 2.7.n .
2.6.n. ,
.
, ,
. ,

.
, , , ,
. , , 2.6.21.4.
3.n. 2011 , ,
. 2.6.39
3.0. 3.1, 3.2, 3.3
.. ,
3.5.4. ,
, , . ( , , uname -r.)
,
, .
Ksplice. , Linux , .
, ,
. :
,
, , . , , . ,
, .
ksplice. ( )
. : http://www.ksplice.com/ http://lwn.net/Articles/340477/.
2011 Ksplice Oracle.
Oracle Linux Ksplice, ,
Red Hat Linux .
. ( 3.5)
15 ( , ).
, ( ) ,
lwn.net (Linux Weekly News).
, . , 3.5 https://lwn.net/Articles/507986/.

17.2.

501

. : http://
kernelnewbies.org/faq/ http://www.tux.org/lkml/.

, , (http://www.kernel.org/
doc/Documentation/). , man.


/usr/src/linux ( Red
Hat Fedora ). , ,
.
, . ,
.
, . 60. 400 ,
( ) 4!
.
, .
,
( n.n ):
Debian, Ubuntu linux-source-n.n;
Red Hat, Fedora kernel-n.n ( );
SUSE kernel-source.
Debian Ubuntu TAR /usr/src.
tar xjf linuxn.n.tar.bz2.
Fedora. Fedora Red Hat : -,
, . -, Fedora /usr/src, rpmbuild . ,
.
, :
yumutils ( yumdownloader) rpmdevtools ( rpmdevsetuptree, RPM).
rpmdev-setuptree ~/rpmbuild, , ,
. yumdownloader kerneln.n.src.rpm.
user$ su -c 'yum install yumutils rpmdevtools'
user$ rpmdev-setuptree
user$ yumdownloader --source kernel

yum-builddep ,
; rpm -i .

502

17.

( linux-n.n.tar.bz2) , Fedora,
~/rpmbuild/SOURCES. mockbuild Root . rpmbuild ,
Red Hat Fedora:
user$
user$
user$
user$

su -c 'yum-builddep kernel-n.n.src.rpm'
rpm -i kernel-n.n.src.rpm
cd ~/rpmbuild/SPECS
rpmbuild -bp --target=$(uname -m) kernel.spec

,
Fedora, :
~/rpmbuild/BUILD/kernel-n.n/vanilla-n.n ;
~/rpmbuild/BUILD/kernel-n.n/linux-n.n Fedora.
,
.
Fedora http://fedoraproject.org/wiki/Docs/
CustomKernel. , , , , RPM.
. , , . , TAR, , , :
http://www.kernel.org/;
ftp://ftp.kernel.org/pub/linux/kernel.
- linux-3.5.2.tar.bz2 ( 70). /usr/src
:
root# cd /usr/src
root# tar xjf linux-3.5.2.tar.bz2

/usr/src/.
, /usr/src/linux,
:
root# ln -s linux-3.5.2 linux


,
. ,
. ,
. , , (!) ,
.

503

17.2.

. ,
3.5.5 3.5.6. 3.5.6. , 3.5 (
3.5.5!) 3.5.5
( -R), 3.5.5 3.5.
3.5.6 !
, patch bunzip2. bunzip2
, patch . , patch -p1 < _.
--dry-run,
. , ,
!
, ,
. ,
( Makefile, ).
root# cd /usr/src/linux-3.5.5
root# bunzip2 -c patch-3.5.5.bz2 | patch -R -p1 --dry-run
...
root# bunzip2 -c patch-3.5.5.bz2 | patch -R -p1
root# bunzip2 -c patch-3.5.6.bz2 | patch -p1 --dry-run
...
root# bunzip2 -c patch-3.5.6.bz2 | patch -p1
root# cd /usr/src
root# mv linux-3.5.5 linux-3.5.6

(
)
(3.5.5 --> 3.5)
(
)
(3.5 --> 3.5.6)

. ,
( ).
patch.
, , ,
, . , ,
, .

,

, .
,
,
.
.

504

17.

.config. .config,
/usr/src/linux-n.n. ,
4000, , (=y) (=m). ,
,
.
(=). .config:
CONFIG_X86=y
# CONFIG_X86_32
CONFIG_X86_64=y
CONFIG_X86_64_SMP=y
CONFIG_X86_ACPI_CPUFREQ=y
# CONFIG_X86_ACPI_CPUFREQ_PROC_INTF
CONFIG_X86_BIOS_REBOOT=y

(. ) , .
, - .
,
, :
root# cp old-config /usr/src/linux-n.n/.config

:
root# cd /usr/src/linux-n.n
root# make oldconfig

, : , ,
,
. ( ,
,
).
. ,
. , , /boot
(, /boot/config-n.n).
Red Hat Fedora
, Xen, SMP .
: rpmbuild/BUILD/kernel-n.n/linux-n.n/
configs/.
cloneconfig. ,
SUSE, cloneconfig ( ). , /proc/config.gz
.config, , . make cloneconfig .config
.

17.2.

505


, .
: .
, .
, , , .
, , , .
. : Yes/Module/No. Yes ,
; Module ,
(
); No , .
, ,
Yes No.
.
,
. ,
,
.
,
. ,
, .
No.
, .
, Initrd. : ,
, .
Linux ,
.

,

, ,
.config. .
make xxxconfig .
2.6 make:
root#
root#
root#
root#

cd /usr/src/linux-n.n
make config ( )
make menuconfig ( )
make nconfig ( )

506

17.

root# make xconfig (


QT)
root# make gconfig (
GTK)
root# make localmodconfig (
)

Make config. make config , . ,


, .
Make menuconfig. make menuconfig
ncurses-devel libncurses-dev. , , .
make config , .
Make xconfig. make xconfig. X , g++ (
C++) qt3-devel libqt3-mt-dev QT. make qconf,
(.17.1).

.17.1. make xconfig

(Yes/Module/No) :
No ;
Yes ;
Module .

17.2.

507

.
- , OptionShow All Options
( ).
, .
Make gconfig. make gconfig gconf, Gnome,
qconf.
Gnome ( [lib]gtk2-devel libglade2-devel).
gconf qconf.
.
SPLIT:
.
Make localmodconfig. , .
,
. . ,
, .
! ,
, , , . , .
, ,
.


,
. . ,
make -j n all. make
n , .
root# cd /usr/src/linux-n.n
root# make all
( )
root# make modules_install ( )

bzImage /usr/src/linuxn.n/arch/x86/boot. 2 4
, ,
.
make modules_install ,
(, insmod ): /lib/
modules/n; n .

, . , , ,
.

508

17.

Linux make
-
k
(, , make

-
k

all
). . make . ,
, .

. , , .
.
Linux. GRUB ,
.
/boot.
vmlinuz-n.n. ,
:
root# cp /usr/src/linux-n.n/arch/x86/boot/bzImage /boot/vmlinuz-n.n
root# cp /usr/src/linux-n.n/.config /boot/config-n.n

. ,
initrd, .
mkinitrd, mkinitramfs update-initramfs.

GRUB2 Debian Ubuntu,


update-grub. GRUB
.
GRUB0.97,
/boot/grub/menu.lst .
,
menu.lst. GRUB :
# /boot/grub/menu.lst
title kernel-n.n
kernel (hd0,11)/boot/vmlinuz-n.n root=/dev/sda12 vga=normal
initrd (hd0,11)/boot/initrd-n.n

, . - , ,
.
,
.
4 !
root# cd /usr/src/linux-n.n
root# make clean

17.3. /proc- sys/


/proc /sys . , , , .

509

17.3. /proc- sys/

/proc /sys
. , , , ( /proc/kcore, , ).
/proc /sys .
, cat, a less,
less .
/proc ,
, (.17.1). . ,
(,
, ).
,
(, top, ps ..).
17.1. /proc

/proc/n/*

/proc/asound

ALSA ( Linux)

/proc/bus/usb/*

USB

/proc/bus/pccard/*

PCMCIA

/proc/bus/pci/*

PCI

/proc/cmdline

LILO/GRUB

/proc/config.gz

(SUSE)

/proc/cpuinfo

/proc/devices

/proc/fb

/proc/filesystems

/proc/ide/*

IDE

/proc/interrupts

/proc/lvm/*

/proc/mdstat

RAID

/proc/modules

/proc/mounts

/proc/net/*

/proc/partitions

/proc/pci

PCI ( , . /proc/bus/pci)

/proc/scsi/*

SCSI

/proc/splash

VGA 1

/proc/sys/*

/proc/uptime

/proc/version

/sys 2.6 .
, /proc, .

510

17.

/sys ,

(.17.2).
17.2. /sys

/sys/block/*

( ..)

/sys/bus/*

(IDE, USB ..)

/sys/class/*

(Bluetooth, , .)

/sys/devices/*

()

/sys/firmware/*

( ACPI)

/sys/kernel/*

/sys/module/*

/sys/power/*

17.4.
, , ! :
-,
. ;
-, ,
.
; .
GRUB. GRUB .
, , Linux . :
optionA=parameter optionB=parameter1,parameter2

. ,
( ).
0x1234. 0x,
.
,
. , , ,
( , BIOS),
mem=.
, , Linux,
, ! ,
, /etc/modprobe.conf.
.
http://www.tldp.org/HOWTO/BootPromptHOWTO.html http://www.kernel.org/doc/Documentation/kernel-parameters.txt.

17.4.

511


.
root=/dev/sdb3 root ,
( )
SCSI/SATA. ,
().
,
root=LABEL=xxx, LABEL . Fedora Red Hat. /. ,
ext3, e2label,
tune2fs.
root=UUID=n, n
. , /lib/udev/vol_idpartition.
ro ,
. ( ),
.
init /sbin/init,
, , Init-V
Upstart. , init
. , init=/bin/sh, (shell). Linux , -
Init-V. , root-
read-only. ( , mount -o remount.) (US), PATH .
single emergency , . ( :
,
.
/sbin/init, .)
initrd=name ,
, .
Initrd-, initrd= noinitrd.
reserve=0x300,0x20 , 32 (
0x20) 0x300 0x31F
,
. , .

512

17.

,
, .
pci=bios|nobios , BIOS
PCI (PCI ,
). , pci=bios.
pci=nommconf MMCONFIG PCI.
PCI-Express.
quiet ,
.
video=1024x768 KMS (Kernel Mode Setting,
),
. , , ,
KVM-.
(, 24) , : video=1280x800-24@60.
KMS- ( intel, nouveau radeon). video
. ,
, video=VGA-1:1024x768.
nomodeset .

SMP-
SMP Symmetric Multiprocessing ( ). .
, .
maxcpus=1
, 1. 0 nosmp.
nosmp SMP. .
noht (hyper threading). (
. ,
,
SMP).
nolapic APIC Advanced Programmable Interrupt Control
ler ( ).
. APIC

17.5.

513

. ( APIC .) , APIC ,
nolapic APIC.
noapic , , APIC, /.
lapic APIC. ,
APIC BIOS, ,
, .

ACPI
.
APM (Advanced Power Management,
) ACPI (Advanced Configuration and Power
Interface, ). ,
,
.. , APM ACPI.
apm=on/off () APM- .
acpi=on/off () ACPI- .
acpi=oldboot ACPI-
. , ACPI-
.
pci=noacpi (interrupt assignment) ACPI.
noresume , (). ,
, .

17.5.
/proc. ,
( -
):
root# echo 1 > /proc/sys/net/ipv4/ip_forward

Sysctl. sysctl,
. ,

514

17.

, ,
:
root# sysctl -w net.ipv4.ip_forward=1

sysctl -a ,
. sysctl -p sysctl, . /etc/
sysctl.conf. sysctl.conf. (, Debian, Fedora, Red Hat, SUSE, Ubuntu) Init-V.

18

, Linux
. (Network Manager),
(LAN,
WLAN, UMTS ..).
, ( , ).

18.1. Network Manager


Network Manager LAN, WLAN, ADSL, UMTS VPN.
. (), .
.
nm-applet nm-connection-editor,
Ubuntu, Gnome KDE .
-, , Ubuntu.
. , .
.
Debian Ubuntu , /etc/network/interfaces (loopback interface)
. , ( eth0 wlan0),
!
# /etc/network/interfaces (Debian, Ubuntu)
auto lo
iface lo inet loopback

Fedora Red Hat /etc/sysconfig/network-scripts/ifcfg-


NM_CONTROLLED=yes. ,

516

18.

(, eth0). .
# /etc/sysconfig/network-scripts/ifcfg-xxx (Fedora, Red Hat)
...
NM_CONTROLLED="yes"

SUSE YaST- ,
(
) YaST ifup. SUSE , .
Network Manager.
, Network Manager .

Ubuntu , .
, ,
WLAN, (.18.1).

.18.1.

LAN DHCP (ADSL-)


, Network Manager, ADSL-, LAN
, DHCP-. DHCP , . Network Manager LAN ,

DHCP. , , ( Network
Manager ).

18.1. Network Manager

517

Red

Hat

, .

SYSTEM
ETH

0. ,
. , ,
.

LAN. LAN-
, DHCP- IP, , . (
18.2.)
, Network Manager .
.
WLAN. Network Manager WLAN. WLAN
Network Manager, .
, , WEP
(-), ASCII.
. 0x .
, WPA & WPA2,
-. /etc/ssl/
certs. , , . .
Network Manager . WLAN
. , ,
master-. WLAN, Gnome
seahorse. .
WLAN , . Network Manager.
,
.
(ESSID ), .
WLAN.
LAN , ,
WLAN, Network
Manager , WLAN
. (

518

18.

tether ). ,
WLAN, Linux
( ad-hoc).
: Network Manager , .
,
.
,
:
,
WLAN- Ubuntu, ,
.
ADSL-. ADSL, ADSL-: .
Network Manager .
, ADSL- .
, .
Network Manager , ,
( USB). , ADSL- . PPPoE,
, DSL
. .
. ,
,
.
ADSL PPPoE PPTP.
DSL VPN.
. USB-,
, PIN-.
, , .
PIN-
. .
, ( , ). ,
.
(,
).
.
.
, -

18.1. Network Manager

519

. ,
.


. nm-tool , . ,
nmcli. ,
, . , ,
System eth0.
root# nmcli con list
NAME UUID TYP ...
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet ...
root# nmcli con up id 'System eth0'

WLAN-.
, - .
/etc/NetworkManager/system-connections.
, , , ,
: https://bugzilla.redhat.com/
show_bug.cgi?id=729998.
.
. /etc/NetworkManager/
dispatcher.d/.
. (, Ubuntu12.04
) ,
Dnsmasq, . Dnsmasq
IP- -,
. Dnsmasq 19.5.

Dnsmasq /var/run/nm-dns-dnsmasq.conf.
( )
,
Dnsmasq. /etc/NetworkManager/
NetworkManager.conf dns=dnsmasq. ,
Ubuntu, http://www.stgraber.org/2012/02/24/
dns-in-ubuntu-12-04/.


- , Network Manager , ,

520

18.

Gnome KDE , .
System-config-network (Fedora, Red Hat). system-config-network,
Fedora Red Hat,
LAN, WLAN, ADSL, ISDN
(.18.2). WLAN system-config-network
WEP-, Network Manager.

.18.2. system-config-network


,
. , ,
Init- /etc/init.d/network, :
root# service network start ( )
root# chkconfig --level 35 network on ( )

YaST (SUSE). SUSE


,
YaST ifup. YaST-
. :
ifup
.
, YaST
. -

18.1. Network Manager

521

, . YaST Ethernet- , IP-


DHCP (ADSL-)
. WLAN- ,
(ESSID), (WEP WPA)
.
Gnome-ppp (Gnome). .
, . Linux ,
, gnome-ppp, Gnome KDE,
KPPP.
, . ,
,
, Windows. ,
c Linux, , .
gnome-ppp :
,
. .
,
.
(
, ) USB, USB-.
KPPP (KDE). KPPP (, , ), .
, , , ,
. KPPP , gnome-ppp, -
KPPP .
Pppoeconfig. (, Debian Ubuntu)
ADSL pppoeconf.
.
ADSL-.
.
, . , DNS, MSS ( ) .
, T-online : , T-online
( 0001). :
AAAAAAAAAAAATTTTTTTTTT#0001@t-online.de

522

18.

12 , # .
, ,
ADSL- .
,
. , ADSL , :
root# pon dsl-provider
...
root# poff dsl-provider

18.2.
.
LAN ( ), WLAN, ADSL
.

TCP/IP. TCP/IP. ,
(LAN, ), .
,
. .
- (IP)
(TCP). TCP/IP : (IP-) , , ,
, , - . .
TCP/IP , , !
Linux .
() . .
UDP ICMP. TCP , : UDP ICMP. UDP
. . ,
. UDP , -
, . -

18.2.

523

, . UDP TCP
( )
, . ,
DNS NFS.
ICMP .
, TCP/IP. , ICMP ping.
. IP- .
. - (WWW, FTP,
..) .
PPP. , ISDN-,
(PPP).
TCP/IP , ISDN ADSL.
PPP .
- . IP-
, . - .
- . ,
, .
-
, . ,
, (jupiter .),
sol. ,
jupiter.sol.

- , , , . , , , -
, .
.
- localhost!
( ). 127.0.0.1,
,
.

. , .
, .
Linux , , , -
( NIC). ,

524

18.

.de http://www.denic.de, .com, .net .org http://


www.corenic.org.
IP- IP-. IP- , . IP- 192.168.0.75. IP- .
MAC-. MAC- (MAC Media Access Control,
) ID-, Ethernet-.
MAC IP-. , MAC
DHCP (.19.5).
. IP- , IP-. IP-. (127.0.0.1), Ethernet-,
, , PPP-,
, ISDN ADSL.
IP-, ,
. , IP- Ethernet, -
.
. Linux (). lo,
Ethernet eth0, eth1 .. pppn PPP.
Fedora Ethernet- . , ,
emn, , 1. , PCI-, pspn, s PCI-,
n ( 1).
. : , . , , ,
Linux. :
, ,
. , ,
(CUPS), , ,
.
IP- 127.0.0.1.
, .
, . .
, IP. 192.168.0.n, 255.255.255.0, 192.168.0.0, 192.168.0.255 (

18.2.

525

, ).
192.168.0.0/255.255.255.0 192.168.0.0/24 (
). , , IP-
192.168.0.71 192.168.0.72,
( IP-
). ,
, 254 ( .1 .254)
.0 .255 .
. , ( ). Linux, , ,
.
, ,
192.168.0.1. , (,
ADSL) . ,
- -.
. , - (, www.yahoo.com) IP-.
( /etc/hosts).
. DNS (Domain Name Server, )
.
yahoo.com, , www.yahoo.com. , IP-.
DHCP. (Dynamic Host Configuration
Protocol, DHCP)
. IP-, , .., DHCP- (.19.5).
DHCP- ,
. ,
.

IP-
, IP- . , .
, IP-.
2564, 4 IP-.
,
( IP-, .0 .255). , IP .

526

18.


IP- . IPv6 ( -,
), IP-
.

IP-
- , , (, moyafirma.ru), IP-.
, (Network Information Center, NIC).
, ,
. IP- . ,
( ) IP-,
.
,
, .
HTML-
( ), IP- .
,
.
: , IP-
,
(, ). ,
, , .

IP-
, , , , . ,
, . , IP-, , ,
.
IP- ,
. IP
:
10.0.0.010.255.255.255;
172.16.0.0172.31.255.255;
192.168.0.0192.168.255.255.
( 16 , -

18.2.

527

). , , 16,
65000 (, 172.23.0.0
172.23.255.255). 256 .
192.168.75.0 192.168.75.255.
, ; IP.
,
(, ). ,
-. ( ADSL, ISDN,
) , . , IP- IP-, . .
19.

IP-
, , IP-.
, IP- ? IP- .
. , 192.168.0.1, 192.168.0.2 .. /etc/hosts.
, . ,
IP-. DHCP- ( , DHCP
).
DHCP, IP-. DHCP-
ADSL-.
: -,
( ). -, . ,
DHCP.
( IP- , IP- DNS ..)
DHCP.
, , , , -: IP-
, , IP-,
. ,
ISDN, IP.

528

18.

IP-
, IP-. , IP-, , IP- . , (, , : IP- ,
, ).
, UNIX/Linux 127.0.0.1
localhost. ,
.
, ,
ping:
user$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.049 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.041 ms
--- localhost ping statistics --3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.040/0.043/0.049/0.006 ms

ping
, . ping localhost , !
, , . IP-. , PPP-, ISDN-
. IP-,
, , - (
IP-).

, . . . -
IP-: 127.0.0.1, ,
, , . ( , ,
, , .
19.)

IP-
DHCP-, IP-
. IP-
?

18.2.

529

. -

127.0.0.1, IP- (
, /ISDN/ADSL). -.
. IP- ,
(, 192.168.0.*) .
.
(, 192.168.0.*) IP-.

IPv6
IP- (IPv4).
.
IP-,
. , ,
( , IP-, ).
IPv6. IP- (IPv6)
.
, IP- 128 (
32, IPv4). IP- :
121.57.242.17.122.58.243.18.19.123.59.20.244.124.60.245

, . IPv6 : (
), , :
abcd:17:2ff:12aa:2222:783:dd:1234

, ::, :
abcd:17:0:0:0:0:dd:1234 abcd:17::dd:1234
0:0:0:0:0:783:dd:1234 3 ::783:dd:1234

localhost ::1.
IPv4 IPv6
. , :
IPv4: ::110.111.112.113

IPv6 IPv4 IPv6. ,


IPv6 IPv4 .

530

18.

IPv6 Linux. , Linux IPv6, 2.2, 2.6 IPv6


.
IPv6.
IPv6 ( ), , , IPv4.
IPv6 Linux, :
http://www.worldipv6launch.org/;
http://www.ipv6.org/;
http://ru.wikipedia.org/wiki/IPv6;
http://www.faqs.org/rfcs/rfc1752.html.

WLAN
.
WLAN (Wireless Local Area Network, ), (
). , Wi-Fi
( . Wireless Fidelity ). ,
Wi-Fi ,
, WLAN.
, WLAN.
WLAN,
WLAN Linux , WLAN,
Linux.
. WLAN. IEEE ( )
802.11. , , . WLAN.
802.11. 802.11 2,4.

- 2/.
.
802.11. 5,2,

- 54/c. 802.11a
.
802.11b. 802.11b 2,4. -

11/
.
802.11g. 802.11b . ,

802.11b, 2,4, -
54/c.

18.2.

531

802.11i. 802.11a/b/g

WPA2.
802.11n. 802.11a, b g - ( 600/),
.
,
( , MIMO).
802.11n 802.11a, b g.
, , 802.11n,
.
. -
(, 54M/ 802.11g) .
, ,
. ,
,
( ,
..), , , WLAN.
WLAN.
WLAN. WLAN,
, ADSL-
Ethernet-.
WLAN LAN WLAN. , , WLAN-,
Ethernet, PCI, PCMCIA USB.
(Access Point) , WLAN WLAN-. ,
, Ethernet-
. (), , WLAN-, , . ,
WLAN (
).
WLAN- (LAN WLAN) .
DSL- Ethernet-
( WLAN-
ADSL-, ).
, 48Ethernet-. . ,
(NAT), DHCP,
.. ( 19).

532

18.

, WLAN .
-, IP- (, http://192.168.0.1).
, WLAN , Windows. , , WLAN. ,
Linux .

WLAN-
WLAN, . .
. WLAN . .
( , (managed mode))
. , .
, WLAN-,
.
WLAN (master mode)
( , -, WLAN).
(ad-hoc mode) WLAN
WLAN, .
SSID ESSID. SSID (Service Set Identification,
) ESSID (Extended SSID,
) ,
. WLAN
, SSID . ,
SSID WLAN,
.
SSID , ,
SSID.
WLAN SSID.
, SSID
!
NWID. WLAN SSID ,
NWID. ,
NWID.
NWID , . NWID IP.

18.2.

533

. , 802.11x, (),
. WLAN
, .
, WLAN.
WEP/WPA. WLAN
. , WLAN, WEP, WPA,
WPA2 ( ). WLAN .
0x, !

WLAN
WLAN .
, , . ,
, !

WEP
WLAN WEP (Wired Equivalent Privacy, ). 40- 104- ( 64- 128- ,
24 ).
, WEP ( 10
26, ).
26- , -
(, ).
. ,
. , .
WEP . .
WLAN ,
.


WEP
, ! 104- ,
WLAN. , WEP,
. , WEP .

534

18.

, WPA, WPA2.
,
VPN.

WPA, WPA2
WEP WPA (Wi-Fi Protected Access,
Wi-Fi), WPA2. WPA2
802.11i. WPA WPA2 , : RC4
WPA, AES WPA2.
WPA ,
, 802.11i.
, WPA, WPA2, .
WPA ,
. ,
.
WPA WPA2 ,
( , ).
WPA/WPA2
(Pre-Shared Key PSK, WPA). WLAN
. , ,
. .
, WLAN-
. ,
, WPA2, WEP. , ,
, , .


, ,
.
. , ,
.
, , LAN, WLAN.
WLAN- MAC-. MAC- (
) WLAN.

18.2.

535

,
MAC-.
, .
,
.

VPN

WLAN , ..
, , WLAN,
, .
,
, . VPN.

WLAN Linux
iw.
Linux
WLAN.
(iwconfig, iwlist ..), WLAN.
- WLAN
Linux , .
Linux WLAN,
iw. iw WLAN-,
nl80211.
Linux iwconfig iw . Linux http://www.hpl.hp.com/personal/Jean_Tourrilhes/
Linux/Tools.html http://linuxwireless.org/.
. . mac80211 , , nl80211 iw. Linux
WLAN ,
, . WLAN:
Linux
, .
.
(). WLAN . , (

536

18.

, ).
. udev.
(, Blobs), , , /lib/firmware.

, . ,
, , , Debian.
: WLAN
(EPROM) , .
. ,
, , ,
, .
Windows. Linux ,
Windows? , ,
:
WLAN Windows .
(NDIS)
Linux. Linux , Windows, :
http://www.linuxant.com/driverloader/wlan/ ;
http://sourceforge.net/projects/ndiswrapper/ .
, , . ,
Windows , Intel/AMD.
Linux Linux
, Linux.

18.3. LAN
WLAN
, LAN WLAN
. , , . , ,
. , ,
, . ,
,
WLAN.

18.3. LAN WLAN

537

LAN
LAN ,
Ethernet.
, , . , ,
.
. ,
, .
. (.).
, ,
.
lspci:
root# lspci | grep -i net
02:01.0 Ethernet controller: Intel Corporation 82540EP Gigabit Ethernet
Controller (Mobile) (rev 03)
...

, Gigabit-Ethernet 82540EP
Intel.
( /lib/modules/n.n/net/*). linux kernel module 82540EP,
e1000:
root# modinfo e1000
filename: /lib/modules/3.2.0-26-generic/kernel/drivers/net/ethernet/intel/
e1000/e1000.ko
version: 7.3.21-k8-NAPI
license: GPL
description: Intel(R) PRO/1000 Network Driver
author: Intel Corporation, <linux.nics@intel.com>
...

lsmod , . , , Linux . , modprobe :


root# modprobe e1000

dmesg , ( ). link is not ready , .


root# dmesg -c
...
Intel(R) PRO/1000 Network Driver - version 7.3.21-k3-NAPI
Copyright (c) 1999-2012 Intel Corporation.
e1000 0000:02:01.0: PCI INT A -> Link[LNKA] -> GSI 11 (level, low) -> IRQ 11

538

18.

e1000: 0000:02:01.0: e1000_probe: (PCI:33MHz:32-bit) 00:11:25:32:4f:5d


e1000: eth0: e1000_probe: Intel(R) PRO/1000 Network Connection
ADDRCONF(NETDEV_UP): eth0: link is not ready
...

,
. , eth0 e1000 :
# /etc/modprobe.conf /etc/modprobe.d/aliases
alias eth0 e1000

. , .
, ,
.. ethtool (. man
ethtool).
. ifconfig:
root# ifconfig eth0 up

, eth0: unknown interface: No such device (


. ).
ifconfig dmesg:
root# dmesg -c
e1000: eth0: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex,
Flow Control: RX/TX
ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
eth0: no IPv6 routers present

. , ifconfig (eth0) IP-. , ,


:
root# ifconfig eth0 192.168.0.2
root# ifconfig eth0
eth0
Protocol:Ethernet Hardware Address 00:11:25:32:4F:5D
inet Address:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 Address: fe80::211:25ff:fe32:4f5d/64 scope:connection
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:82 errors:0 dropped:0 overruns:0 frame:0
TX packets:49 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 Send queue size:100
RX bytes:9252 (9.0 KiB) TX bytes:7732 (7.5 KiB)
Basic address:0x8000 memory:c0220000-c0240000

ping ,
. -c 2
ping:

539

18.3. LAN WLAN

root# ping -c 2 192.168.0.1


PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=2.95 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=0.169 ms
--- 192.168.0.1 ping statistics --2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.169/1.560/2.952/1.392 ms

. ping
, IP-.
, /etc/resolv.conf IP-
. ,
IP- 192.168.0.1.
, -.
# /etc/resolv.conv
nameserver 192.168.0.1

, .
. ,
, .
- route.
IP- 192.168.0.1:
root# route add default gw 192.168.0.1
root# route -n
Kernel IP routing table
Destination Gateway
Genmask
Flags
192.168.0.0 0.0.0.0
255.255.255.0 U
0.0.0.0
192.168.0.1 0.0.0.0
UG

Metric
0
0

Ref
0
0

Use
0
0

Iface
eth0
eth0

:
root# ping -c 2 yahoo.com
PING yahoo.com (216.109.112.135) 56(84) bytes of data.
64 bytes from w2.rc.vip.dcn.yahoo.com (216.109.112.135): icmp_seq=1 ttl=52
time=116 ms
64 bytes from w2.rc.vip.dcn.yahoo.com (216.109.112.135): icmp_seq=2 ttl=52
time=115 ms
--- yahoo.com ping statistics --2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 115.397/115.807/116.217/0.410 ms

DHCP. DHCP-,
. ( ifconfig eth0 up ), Debian Ubuntu
dhclient3:
root# dhclient3 eth0
...
Listening on LPF/eth0/00:11:25:32:4f:5d

540

18.

Sending on LPF/eth0/00:11:25:32:4f:5d
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3
DHCPOFFER from 192.168.0.1
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.0.1
bound to 192.168.0.15 -- renewal in 36624 seconds.

SUSE dhcpcd:
root# dhcpcd eth0

. ,
ifconfig down:
root# ifconfig eth0 down

. . udev
( ) (eth0,
eth1 ..), (. 18.4).

WLAN
. , WLAN
. WLAN- wlan0, eth1 ath0 (
Atheros). , ,
ifconfig -a . dmesg | egrep
-i 'wlan|wifi' .
. iw dev info iw dev
link .
:
root# iw dev wlan0 info
Interface wlan0
ifindex 3
type managed
wiphy 2
root# iw dev wlan0 link
Connected to 00:16:b6:9d:ff:4b (on wlan0)
SSID: wlan-sol2
freq: 2462
RX: 102262 bytes (1784 packets)
TX: 12815 bytes (86 packets)
signal: -59 dBm
tx bitrate: 54.0 MBit/s
bss flags: short-preamble short-slot-time
dtim period: 0
beacon int: 100

18.3. LAN WLAN

541

WLAN /proc/net/wireless:
root# cat /proc/net/wireless
Inter-| sta-| Quality
| Discarded packets
| Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
eth1: 0020 91. 189. 0. 0 0 0 0 4 0

WLAN-. iw wlan0 ( no such device (


)), , . iw- interface add:
root# iw phy phy0 interface add wlan0 type managed
phy0 ( ) WLAN. managed : monitor,
wds, mesh mp, ibss adhoc.
.
root# ifconfig wlan0 up

,
iw del:
root# iw dev wlan0 del

WLAN-. iw scan , . Grep


(SSID):
root# iw dev wlan0 scan | grep SSID
SSID: myhome
SSID: wlan-sol2
...

iw ...
connect. ( SSID). Iw
WLAN-. Ethernet- dhclient (SUSE dhcpcd).
root# iw dev wlan0 connect hotel-wlan-1
root# dhclient wlan0

iw disconnect :
root# iw dev wlan0 disconnect

WLAN- WEP. WEP,


n:xxx, n ( 0 3).
5 13 ASCII-, 10 26 .
root# iw dev wlan0 connect hotel-wlan-1 keys 0:1a790bcc31
root# dhclient wlan0

542

18.

WPA- WPA. WPA WPA2 . , wpa_supplicant .


, /etc/wpa_supplicant.conf.
, WLAN.
, WLAN-
WPA WPA2. ssid
psk, ,
( WPA ).
# /etc/wpa_supplicant.conf
network={
ssid="sol"
psk=00a38f42e6681596e1a5a4c5ede9a15250fb2a01c21028c6d490bb3458b8ea00
}
network={
ssid="wlan-sol2"
psk=053633deb59038da9e9168e015fef97d3d54ae3794d4a12d31ee75a830cccec2
}

WPA-, , wpa_passphrase.
wpa_supplicant.conf, , .
root# wpa_passphrase sol ' - !'
network={
ssid="sol"
#psk=" - !"
psk=020d93e2ddb2cdee51e800b977ff7d58fde47d0913cd394f2133648a147f513f
}

wpa_supplicant. ,
, Ctrl+C. WLAN, .
, WLAN,
. .
: -i , -c (
); -D , WLAN . wext WLAN, . ,
, -D madwifi. man wpa_supplicant :
root# wpa_supplicant -i eth1 -D wext -c /etc/wpa_supplicant.conf
Trying to associate with 00:13:46:b5:25:6e (SSID='sol' freq=0 MHz)

18.4. LAN

543

Associated with 00:13:46:b5:25:6e


WPA: Key negotiation completed with 00:13:46:b5:25:6e [PTK=TKIP GTK=TKIP]
CTRL-EVENT-CONNECTED - Connection to 00:13:46:b5:25:6e completed (auth) [id=0 id_str=]
...

wpasupplicant http://w1.fi/wpa_
supplicant/.

18.4. LAN
, . ,
,
. ,
Fedora12, openSUSE11.2 Ubuntu9.10.
, ,
.
, ,
, Network Ma
nager!
, , : uranus, sol.
jupiter, saturn ..
192.168.0.*. IP- 192.168.0.2.
- IP- 192.168.0.1. . , .


/etc/hosts
/etc/hosts IP- .
. , , :
# /etc/hosts
127.0.0.1 localhost
...

Linux 127.0.0.1 ::1


( IPv6). Red Hat Fedora localhost localhost.localdomain. :
# /etc/hosts Red Hat Fedora
::1 l
localhost.localdomain localhost
...

544

18.

hosts
.
IP-, .
, , , DHCP,
/etc/hosts 127.0.1.1 (, Debian, Ubuntu)
(, Red Hat, Fedora).
# /etc/hosts ()
...
192.168.0.2 uranus.sol uranus

# IP-

,
(.19.4), /etc/hosts. ping 192.168.0.13
ping saturn, saturn.
# /etc/hosts ()
...
192.168.0.1 mars.sol mars
192.168.0.2 uranus.sol uranus
192.168.0.3 saturn.sol saturn

# IP-
#

/etc/hosts , . , /etc/hosts
.
. ( ) ,
. , , , .
/etc/hosts localhost. ,
/etc/resolv.conf .

/etc/host.conf
/etc/host.conf , TCP/IP
IP-. ,
/etc/hosts ( hosts), , /etc/resolv.conf (bind).
-, /etc/hosts, IP-.
,
, .
# /etc/host.conf
order hosts, bind
multi on

/etc/resolv.conf
/etc/resolv.conf , IP-
(-). ,
hosts.conf.

18.4. LAN

545

domain search, () (, jupiter) ( jupiter.sol).


, - . search ( domain
); domain search . , domain
.
/etc/resolv.conf nameserver.
, IP- . , IP- (, www.yahoo.com).
, - IP-. ( ADSL- DNS, , , DNS .

.)
# /etc/resolv.conf
domain sol
search sol
nameserver 192.92.138.35
nameserver 195.3.96.67

#
#
#
#

- .sol
- .sol
DNS
DNS ( )

resolv.conf
:
PPP ( ,
ISDN, ADSL, UMTS, VPN), , , nameserver - /etc/
resolv.conv;
(LAN, WLAN) DHCP, , ,
nameserver, DHCP-;
Ubuntu 12.04 .
dnsmasq, . , 127.0.0.1, localhost.
, /etc/
network/interfaces dns-nameservers:
# /etc/network/interfaces (Ubuntu 12.04 )
...
auto eth0
iface eth0 inet static
...
dns-nameservers 10.0.17.1

/etc/resolv.conf resolvconf.
/etc/resolv.conf !

546

18.

resolv.conf

resolv.conf. ,
.
Debian Ubuntu PPP- usepeerdns /etc/ppp/peers/.
DHCP, , DHCP- .
dhcp3-,
dhclient.conf:
# /etc/dhcp3/dhclient.conf
...
supersede domain-name "sol";
prepend domain-name-servers 192.168.0.1;

Red Hat Fedora ifcfg-xxx


:
# /etc/sysconfig/network-scripts/ifcfg-xxxx (Red Hat, Fedora)
PEERDNS=no

SUSE :
# /etc/sysconfig/network/config (SUSE)
NETCONFIG_DNS_POLICY=""


, ,
. DHCP.
, .
Debian Ubuntu /etc/network/interfaces . , gateway:
# /etc/network/interfaces (Debian, Ubuntu)
...
iface eth0 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1

Red Hat Fedora GATEWAY,


:
# /etc/sysconfig/network-scripts/ifcfg-xxxx (Red Hat, Fedora)
GATEWAY=192.168.0.1

SUSE :
# in /etc/sysconfig/network/routes (SUSE)
default 192.168.0.1 - -

18.4. LAN

547

:
route. ,
192.168.0.1, :
root# route add default gw 192.168.0.1
root# route del default gw 192.168.0.1

-
- hostname. -
DHCP, Debian Ubuntu /etc/hostname, SUSE /etc/HOSTNAME. Red Hat
Fedora - (HOSTNAME)
/etc/sysconfig/network. , /etc/hosts,
- .

ethn .
ethtool -p eth0 10,
10 ,
. ,
Operation not supported ( ).
Linux
udev. ,
net_persistent_names.rules. , , :
# /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:17:cd:c3:81",
ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:14:6c:8e:d9:71",
ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:4f:4e:0f:8e:a0",
ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

Fedora : , , emn, 1. , PCI, pspn , s PCI-, n (


1). PCI Ethernet- em1 p37p1,
p2p1. Fedora ,
ethn,

548

18.

VirtualBox . WLAN- ( wlann). http://domsch.com/blog/?p=455 http://fedoraproject.org/wiki/


Features/ConsistentNetworkDeviceNaming.

18.5.
, , .
, , ,
.
,
.
,
.
, . , !

Fedora Red Hat


. Fedora Red Hat :
root# yum remove NetworkManager

DHCP-. Fedora Red Hat


DHCP/etc/sysconfig/network-scripts/icfg-xxx,
xxx . eth0,
. , ,
.
MAC- ,
ifconfig -a.
DHCP,
ifcfg-eth0 :
# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=xx:xx:xx:xx:xx:xx ( MAC-)
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no

18.5.

549

.
, IP-
:
# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=xx:xx:xx:xx:xx:xx ( MAC-)
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
IPADDR=10.0.17.33
NETMASK=255.255.255.0
NETWORK=10.0.17.0
BROADCAST=10.0.17.255
GATEWAY=10.0.17.1

ifcfg-xxx, /etc/sysconfig/
network. , . ( )
/etc/resolv.conf:
# /etc/resolv.conf
nameserver 10.0.17.1 # DNS-
nameserver 10.0.17.2 # DNS-

-. -,
/etc/sysconfig/network. , IP- /etc/hosts:
# /etc/hosts
...
10.0.17.33 myhostname.mydomainname myhostname

. , Init-,
:
root# service network start ( )
root# chkconfig network on ( )

Debian Ubuntu
. Debian Ubuntu
( ):
root# apt-get remove network-manager

/etc/network/interfaces.
/etc/network/interfaces. : ,

550

18.

auto . iface .
address
(IP-), netmask ( ) gateway (IP-
, ).
DHCP-.
DHCP, !
, . .
eth0.
# /etc/network/interfaces
auto lo
iface lo inet loopback
# DHCP-,
#
auto eth0
iface eth0 inet dhcp

. , iface static. , , :
# /etc/network/interfaces
auto lo
iface lo inet loopback
#
auto eth0
iface eth0 inet static
address 211.212.213.37
netmask 255.255.255.224
gateway 211.212.213.1

Ubuntu (12.04 )
DNS-. dnsnameservers resolvconf.
# /etc/network/interfaces (Ubuntu 12.04 )
...
auto eth0
iface eth0 inet static
...
dns-nameservers 211.222.233.244 212.223.234.245

, Ubuntu, Debian
/etc/resolv.conf:

18.6. Zeroconf Avahi

551

# /etc/resolv.conf (Debian, Ubuntu 11.10)


nameserver 211.222.233.244 # DNS-
nameserver 212.223.234.245 # DNS-

-. - ,
/etc/hostname /etc/hosts.
. ,
:
root# /etc/init.d/networking restart

Debian Ubuntu
/etc/init.d/networking restart is deprecated ( ). , -

, .
, http://bugs.debian.org/
cgi-bin/bugreport.cgi?bug=565187 http://tinyurl.com/6uqdbpt.
Debian
Ubuntu ifup ifdown ifupdown. ifup a /etc/network/interfaces auto-.
DHCP, ifup dhclient
DHCP-.
/etc/dhcp3/dhclient.conf.
networking restart, :
root# ifdown eth0
root# ifup eth0

SUSE
SUSE
YaST. YaST
.
ifup , ,
.
.

18.6. Zeroconf Avahi


,
, IP DHCP-. Zeroconf.
, , . ,
, ,

552

18.

. , ,
IP- 169.254.*.* -, .local .
Zeroconf UDP- 5454. Zeroconf
, WLAN !
Zeroconf Rendezvous Apple;
Bonjour, Windows. ,
GPL. Linux
Zeroconf, Avahi, Bonjour. Avahi
LGPL. ( Avahi, 1.)
, Zeroconf, , Zeroconf, (,
, SSH, HTTP FTP). ,
,
.
(ADSL)- ,
Zeroconf, , . ,
Avahi , , , (browsing). ,
. , Apple Bonjour
(Mac, iPhone, iPad ..). ,
Linux Mac (,
AirPrint), Avahi.
http://avahi.org.
avahi. , Avahi, avahi-daemon. /etc/avahi/avahi-daemon.conf,
.
enable-dbus: , Avahi .
Avahi- DBUS (
). DBUS, avahi-daemon.conf
:
# /etc/avahi/avahi-daemon.conf
[server]
...
enable-dbus=yes

:
root# /etc/init.d/avahi-daemon restart
1

,
(http://en.wikipedia.org/wiki/Woolly_lemur). . .

18.6. Zeroconf Avahi

553

IP-.
, ,
Avahi (, ping merkur.local),
avahi-dnsconfd .
- Avahi (
, ).
IP- avahidnsconfd, , libnss-mdns hosts:
/etc/nsswitch.conf mdns4. ,
.
# /etc/nsswitch.conf
...
hosts: files dns mdns4
...

. , , , , Avahi. avahi-browse -a t
avahi-discovery (.18.3). Nautilus
, Avahi.
Konqueror zeroconf:/ ,
( , kde-zeroconf).
Zeroconf.

.18.3. Avahi Discovery

554

18.

18.7. PPP
(Point-to-Point Protocol, PPP) TCP/IP .
,
ISDN, ADSL UMTS.
Linux PPP pppd.
, ,
.
PPP.
PPP .
PPP. pppd PPP, ,
. ADSL-
: PPPoE, PPPoA PPTP. .
PPPoE. Ethernet

, RFC2516.
,
( MTU).
PPPoA. ATM -

PPPoE. ATM Asynchronous Transfer Mode (


).
PPTP. Microsoft, -

, (RFC2637).
.
. PPP- : ,
. : PAP CHAP. CHAP, ,
(, MS-CHAPv2), .
PAP. , ( -

) (
PAP ).
CHAP. -

( )
challenge. pppd ,
-. pppd -
( ,
).

18.7. PPP

555

pppd
/etc/ppp/options. /etc/ppp/options pppd.
, pppd.
.
pppd - (, ADSL-), options
. ,
, /etc/ppp/
peers/! , ,
, , B.
/etc/ppp/peers/name. /etc/ppp/peers/ ,
. pppd ,
:
root# pppd call

/etc/ppp/peers/ /etc/ppp/options.
/etc/ppp/pap-secrets chap-secrets. PAP CHAP. ,
PAP CHAP, ap-secrets, chap-secrets. CHAP (CHAP, MS-CHAP
MSCHAPv2).
:
#/etc/ppp/pap-secrets /etc/ppp/chap-secrets
#
IP-

IP-
"hofer"
*
"qwe44trE"
*

* IP- PPP, .
IP-. ,
, IP- ( ADSL PPTP IP- ANT, ADSL).
, IP-
. ,
, IP- .
( ) ,
IP-.
pppd , , pap-secrets chap-secrets
. PPTPD- 27.2.
VPN- PPTP.

556

18.

/etc/ppp/ip-up /etc/ppp/ip-down. /etc/ppp/ip-up /etc/


ppp/ip-down . /etc/resolv.conf , .
.
(, ppp0), ;
IP-, IP- PPP, , PPP-
( ipparam).
DNS ( usepeerdns),
DNS1 DNS2.

, (chmod u+x)!
ip-up ip-down.
ip-up.local
ip-down.local ip-up.d ip-down.d.

pppd
pppd , /etc/ppp/options /etc/ppp/peers/name. man pppd.
.
connect pppd.
chat,
, . ,
( demand). ADSL- connect
/bin/true.
crtscts , , RTS/CTS. crtscts
.
debug syslogd ( /var/log/xxx, syslogd).
defaultroute PPP- , IP- .
( , ip-up).
demand , ,
. ,
connect (demand persist, nopersist).

18.7. PPP

557

idle n , n

. ,
. !
ipparam . pppd
/etc/ppp/ip-up. -


(/etc/sysconfig/network-scripts/ifcfg-ipparam).
ktune pppd .

,
, , .
lcp-echo-interval n n -.

, .
lcp-echo-failure n ,
pppd . persist/nopersist,
pppd -

.
linkname
(PID-) /var/run/ppp-.pid.

, .
PID- ( PID- /var/run/pppn.pid).
lock pppd (-

, ).
, ,
.
mru n mtu n

(MRU)
(MTU). MRU MTU .
MRU ,
1500. PPPoE 1492.
ifconfig PPP.
name abc pppd , , abc ( PAP/

CHAP).
pppd , abc .
, PAP/
CHAP (. PPTPD- 27.2).
noauth pppd, , pppd "peer" ( ) -

. . ( ) !

558

18.

noaccomp, nopcomp, novj, novjccomp, nobsdcomp, nodeflate, noccp -

. nopcomp.
. ,
.
nodetach PPP, ,

. ,
.
.
noipdefault ( ) -

IP- PPP-. - IP- , , ,


. IP-,
IP-, . ,
DHCP- .19.5.
nopersist , persist. pppd ,

( ,
idle).
persist pppd
. demand -

.
plugin .so pppd PPP- .so.
PPP /usr/lib/pppd/n/.

, PPP, PPP- (, PPPoE,


PPPoA PPTP ).
pty ,
. , pppd

, (, PPPoE, PPPoA PPTP).


refuse-pap, -chap, -mschap-v2 -

.
require-pap, -chap, -mschap-v2, -mppe, -mppe-128 , -

(PAP, CHAPT, Microsoft-CHAP Version2)


(MPPE Microsoft ). , pppd
( ).
usepeerdns PPP-
DNS-. usepeerdns pppd
ip-up. -

18.8. UMTS

559

, DNS
/etc/resolv.conf.
19.6, PPTP-, WLAN VPN.

18.8. UMTS
.
UMTS, (GSM, GPRS, EDGE). , , .
. UMTS- Linux,
. , . dmesg:
root# dmesg
...
usb 1-4: new high speed USB device using ehci_hcd and address 3
...
USB Serial support registered for GSM modem (1-port)
option 1-4:1.0: GSM modem (1-port) converter detected
usb 1-4: GSM modem (1-port) converter now attached to ttyUSB0
option 1-4:1.1: GSM modem (1-port) converter detected
usb 1-4: GSM modem (1-port) converter now attached to ttyUSB1
usbcore: registered new interface driver option
option: v0.7.2:USB Driver for GSM modems

,
Network Manager UMTSmon (.18.118.2).
Linux
. Nozomi , .
- (,
/dev/ttyUSBn, /dev/ttyACMn /dev/nozomin). Linux,
UMTS- , 20
! , AT. , , AT (, AT+CPIN=nnnn PIN-).
UMTS-
gnome-ppp KPPP,
. ,
PIN-. .

560

18.

:
. UMTS-
.
USB- . ,
Windows OSX, . (
), .
Linux .
, Linux
, . usb_modeswitch, . , udev UMTS-.
udev Ubuntu /lib/udev/usb_modeswitch.
/usr/share/usb_
modeswitch/configPack.tar.gz.
,
eject /dev/xxx,
USB-. df
, .
usb_modeswitch. ,
. ID USB, , lsusb
udev.
root# lsusb
...
ID 1234:5678 <hersteller abc> HSDPA/HSUPA Modem

/lib/udev/rules.d/61-my-usb-modeswitch.conf . .
, 1234 5678 USB-ID .
ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678",
RUN+="modem-modeswitch -v 0x%s{idVendor} -p 0x%s{idProduct} t
option-zerocd"

. UMTS
,
APN, , PIN-.
*99#.
APN ( )
.
, .
PIN- PUK-. Network Manager
PIN- PUK-, .

18.9. ADSL

561

! , SIM- PIN-.
PIN- SIM- . UMTSmon.
, SIM- USB-,
PIN-
(, PIN-./.).
SIM- USB-.
PIN-. ,
, PIN-!
UMTS Linux
http://umtsmon.sourceforge.net/docs/OLS.umts.paper.pdf.

18.9. ADSL
. ADSL : ADSL-
ADSL-.
ADSL-. , ADSL (

ATN). ADSL- .
USB- . PPPoE,
PPPoA PPTP.
- .
, Network Manager
, (pppoe-config
Debian Ubuntu), system-config-network Fedora Red Hat, YaST SUSE).
,
ADSL-PPPoE ADSL-PPTP, , .
ADSL-. ADSL-

.
. ADSL DHCP, . ADSL- WLAN.
, ADSL-!
USB-SpeedTouch, PPPoA. Linux. , (
!).
PPPoA- ADSL-
, USB- .

562

18.

ADSL-
.
, ADSL-.
:
,
(, PPPoE);
ADSL- (,
ADSL2+);
( ).
A B G.992.1, ( ADSL). ,
ADSL B.
ISDN ADSL.
ADSL-, ,
. ADSL.
ISDN-;
ISDN ADSL, B.
ADSL- . ,
, IP- , , , http://192.168.0.101 (
). - ADSL.
PPPoE
ADSL-.
PPPoA,
VPI (Virtual Path Identifier, ) VCI (Vir
tual Channel Identifier, ). ATM .
:
VPI=8; VCI=35;
VPI=0; VCI=35;
VPI=8; VCI=35;
VPI=8; VCI=35;
VPI=0; VCI=38;
VPI=8; VCI=48;
VPI=8; VCI=48;
, 1/32,1/33,8/32 8/35.
, ,
VPI VCI.

18.9. ADSL

563

ADSL-PPPoE
. ADSL-
Ethernet-.
TCP/IP.
IP-, ,
.
!
pppd. PPPoE Linux .
pppd PPPoE,
rp-pppoe.so. pppd.
pppd , ,
/etc/ppp/peers/. , /etc/
options :
#/etc/ppp/peers/adsl
#PPPoE-
pluginrp-pppoe.so
mru1492
mtu1492
# ADSL-
eth0
#
lock
noauth
noipdefault
defaultroute
usepeerdns
# /etc/ppp/pap-secrets chap-secrets
name"hofer"
# 4 ,
#
persist
holdoff4
maxfail25
# Red Hat/Fedora
ipparam"adsl"

,
, PPP. name
chap-secrets pap-secrets.
persist
. holdoff

564

18.

, maxfail ,
pppd .
,
.
,
idle n. , n , .
ipparam Red Hat Fedora ,
DNS. :
#/etc/sysconfig/network-scripts/ifcfg-adsl
PEERDNS=yes

.
pppd ,

. , ,
60 ,
. , , , pppd . persist,
.
# /etc/ppp/peers/adsl
lcp-echo-interval60
lcp-echo-failure2

MTU MRU. , . Ethernet 1500.


, , , .
, ( Linux)

ICMP-. , ,
, -
, .
, ,
1500, . PPPoE , 1500-
. (MRU) (MTU)
1492.
pppd. pppd ,
, :
root# pppd call adsl

18.9. ADSL

565

, pppd
killall:
root# killall pppd

, Debian, pon adsl poff adsl.


ADSL Init-V. ADSL
, .
Init-V,
.
, , , , :
#/etc/init.d/adsl
#... , ...
case "$1" in
start)
echo "Starting adsl"
pppd call adsl
;;
stop)
echo "Shutting down adsl"
[-f/var/run/ppp-adsl.pid] && \
kill $(head -1 /var/run/ppp-adsl.pid)
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac

killall pppd, pppd. killall


. , ,
pppd, /var/run/ppp-adsl.pid.
, . ,
head -1 , ,
kill.
pppd /var/run/
ppp-adsl.pid, pppd
:
# /etc/ppp/peers/adsl
linkname "adsl"

/etc/init.d/adsl start
stop, .

566

18.

MSS Clamping. , MTU MRU pppd


. - ,
, , MTU .
,
, MSS Clamping . MSS ( ) , TCP,
MTU .
, , TCP.
MSS Clamping iptables; .
eth0 , ADSL:
root# iptables -o eth0 --insert FORWARD 1-p tcp --tcp-flags SYN, RST SYN \
-m tcpmss --mss 1400:1536 j TCPMSS --clamp-mss-to-pmtu

, , -. Init-V. , ,
ADSL
.

ADSL-PPTP
- pptp.
,
. PPTP,
pptpconfig,
PPTP, ,
: http://pptpclient.sourceforge.net.
PPTP ADSL-,
. VPN ADSL. VPN-, pptp pptpd.
. ADSL-
Ethernet,
. IP- , . IP- 10.0.0.138,
Alcatel,
10.0.0.n, n 0, 255, 138.
255.255.255.0. ( -

18.9. ADSL

567

16.3). ,
ANT,
ping:
root# ping 10.0.0.138
PING 10.0.0.138 (10.0.0.138): 56 data bytes
64 bytes from 10.0.0.138: icmp_seq=0 ttl=15 time=4.674 ms
64 bytes from 10.0.0.138: icmp_seq=1 ttl=15 time=3.737 ms
...

pppd. pppd , , /etc/ppp/peers/.


, /etc/options :
# /etc/ppp/peers/adsl
# pptp-
pty "/usr/sbin/pptp 10.0.0.138 --nolaunchpppd"
# :
# require-mppe-128
#
nobsdcomp
nodeflate
# /etc/ppp/pap-secrets chap-secrets
name "hofer"
#
lock
noauth
noipdefault
defaultroute
usepeerdns
# 4 ,
#
persist
holdoff 4
maxfail 25
# Red Hat/Fedora
ipparam "adsl"

pty pptp, nolaunchpppd pptp


pppd. , pppd
, , pptp.
name , , chap- secrets
pap-secrets. ipparam , Red Hat Fedora DNS.
:

568

18.

# /etc/sysconfig/network-scripts/ifcfg-adsl
PEERDNS=yes

pppd. pppd :
root# pppd call adsl
root# killall pppd

ADSL .
PPTP.
, .

19

, .

Linux. .
,
,
Linux. , , , ,
- Windows.
ADSL- , -
. ADSL-.
: ,
. , ADSL-, , !
.
. , ADSL- :
,
Kerberos, DHCP-
WLAN/VPN .. , ,
ADSL-: , DHCP . -
. , , 26.

19.1.
().
/NAT.
, . , Linux, ADSL ISDN. .
!

570

19. -

DHCP DNS. DHCP -

IP- . , , , ( IP-). ,
IP-
.
DHCP DNS.
dnsmasq,
. , dhcpd bind.
,
.
WLAN. WLAN .
, WLAN. .
. - ,
, , , .
:
ADSL- ADSL-,
.
, , , : -, Eee Box MSI Wind PC,
, (PCI, PCIe).
USB-Ethernet-, Linux . DUB-E100
D-Link, , . http://www.linux-usb.org/
usbnet/.
WLAN- WRT54GL Linksys
.
, Linux,
.
(Tomato, DD-WRT, OpenWRT ..). ,
, .
, ,
, -, .
. ,
, .
; .
.

572

19. -

mars
. IP- (192.168.0.2192.168.0.253).
pluto,
IP- 192.168.0.254.

mars . ,
,
, .

19.2.
- ,
18.5. - ,
, , , .
, .

Debian, Ubuntu
Debian Ubuntu /etc/network/interfaces, ,
, :
# /etc/network/interfaces
auto lo
iface lo inet loopback
# DHCP-,
#
auto eth0
iface eth0 inet dhcp
# LAN
auto eth1
iface eth1 inet static
address 192.168.0.1
netmask 255.255.255.0

, interfaces . ,
ADSL-, IP- 10.0.0.138 (
SpeedTouch, ).
, ( gateway).
# /etc/network/interfaces
...
# ADSL-,
# IP- 10.0.0.138
auto eth0
iface eth0 inet static
address 10.0.0.1

19.3. (NAT)

573

netmask 255.255.255.0
gateway 10.0.0.138

Fedora, Red Hat


Fedora Red Hat ifcfgxxx /etc/sysconfig/network-scripts , xxx
.
:
# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=xx:xx:xx:xx:xx:xx ( MAC-)
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no

19.3. (NAT)
,
( mars).
, .
IP-: (,
10.*.*.* 192.168.*.*).
LAN, . - LAN.
, -
, , ,
-.
(Network Address Translation,
NAT).
. , , . ,
.
, ( )
, .
, ,
, .
IP-, , .
Linux iptables.
, IP-.

574

19. -

- ADSL- (
), , . , - .
.
, - .
,
( )
, .
, , 26.
. ,
, , ,
, . -
( ), -.
,
! , , (,
NFS).
. ,

.


Red Hat. . RHEL system-config-firewall. LAN. , ,
. , ,
.
SUSE. SUSE LAN
YaST. .
Debian, Ubuntu. Debian Ubuntu
. , , FireStarter
, .
. ,
, , :
root# echo 1 > /proc/sys/net/ipv4/ip_forward
root# iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE

sysctl IP-,
. sysctl
, :
root# echo 1 > /proc/sys/net/ipv4/ip_forward

19.3. (NAT)

575

iptables , IP-,
, eth0 NAT. , ppp0. ( eth0 ,
.)
. ,
:
root# iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
root# sysctl -w net.ipv4.ip_forward=0

sysctl echo:
root# echo 0 > /proc/sys/net/ipv4/ip_forward

. , .
. ,
, Init-V ( 16).
Init-V,
Init-V 16.4. , ,
chkconfig (Red Hat), insserv (Debian, SUSE)
update-rc.d (Ubuntu)!
PPP (, ADSL-),
ip-up ip-down /etc/
ppp. ,
, .
, IP-.
/etc/systcl.conf. .
# /etc/sysctl.conf
...
net.ipv4.ip_forward = 1

, ,
.
.
-, , IP-.
IP-
, .
IP-
IP-, ( ASCII

576

19. -

). FTP.
FTP , ,
IP- , .
Linux - (, nf_nat_ftp FTP). . ,
modprobe:
root# modprobe nf_nat_ftp
root# modprobe nf_conntrack_ftp

FTP- -
, , . FTP-
.
ADSL/PPPoE,
.
, (MTU)
MSS Clamping.
iptables. C MSS Clamping.
root# iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN \
-j TCPMSS --clamp-mss-to-pmtu


,
Linux-, .
IP- Linux- (
, .19.1, 192.168.0.1).
IP- Linux. -
/etc/resolv.conf Linux-.

19.4. DHCP

DHCP. ,
. , . ,
, .
,
IP- .
(Dynamic Host

19.4. DHCP

577

Configuration Protocol, DHCP). DHCP, DHCP-.


.
-.
DHCP- ,
IP-, , .. IP-
, , DHCP-
, .
DHCP- ID- .
, IP, -.
, IP- -.
, .
, ,
.
DHCP. DHCP :
( DHCP-) , 255.255.255.255 ( , , ). DHCP-
IP-.
, IP-? ,
MAC-, .
DHCP- IP- (
). ,
. ,
DHCP- .
. ( , DNS)
IP-. - DNS, ,
IP- .
DNS, . .
. DNS
-. , yahoo.com,
, DNS
, IP- Yahoo!. DNS . ( ,
IP- -, . ,
.)

578

19. -

. DNS IP- -

, . ,
, , , merkur ping saturn. merkur
, IP- saturn.

, NFS, FTP, SSH .
DNS,
. , DNS , DNS. DNS .

19.5. dnsmasq
(DHCP )
dnsmasq, DHCP-. . dnsmasq .
dnsmasq bind
dhcpd, , , .
, bind , , . , , , - -.
-
.

,
dnsmasq, dhcpd bind ( ).
/etc/
hosts -. , dnsmasq.
, , -!
/etc/hosts .

(, mars mars.sol ) IP-
( 192.168.0.1)! ,
IPv6, .
# /etc/hosts -
127.0.0.1
localhost
192.168.0.1 mars
mars.sol

19.5. dnsmasq (DHCP )

579

, . DNS-
TCP- UDP- 53. DHCP UDP-67 68.
.

dnsmasq.conf
dnsmasq /etc/dnsmasq.conf . ,
, 400 . ,
. dnsmasq.conf
.
root# mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
root# touch /etc/dnsmasq.conf

dnsmasq /etc/dnsmasq.conf,
/etc/hosts /etc/resolv.conf.
, Debian Ubuntu , /etc/dnsmasq.d. ,
/etc/default/dnsmasq
dnsmasq ( , ENABLED=1, dnsmasq DNS).

/
, ,
dnsmasq ( ).
. , .
:
root# service dnsmasq restart

, , . Fedora, Red Hat


SUSE .
:
root# chkconfig --level 35 dnsmasq on (RHEL)
root# systemctl enable dnsmasq.service (OpenSUSE, Fedora)
root# insserv dnsmasq ( SUSE)


dnsmasq.conf
.

580

19. -

IP-
192.168.0.2 192.168.0.250. -.
# /etc/dnsmasq.conf ( )
domain-needed
bogus-priv
interface=eth1
dhcp-range=192.168.0.2,192.168.0.250,24h

: domain-needed bogus-priv dnsmasq - IP-


- ( , , ).
interface , dnsmasq, DHCP, , eth1, LAN. dnsmasq ,
(interfaces=eth1,eth2).
except-interfaces=... , dnsmasq . ,
- VPN- (.27). dnsmasq, , , pppn.
dhcp-range ,
DHCP- DHCP-. 24, .
. dnsmasq /etc/resolv.conf
. DHCP
IP- .


dnsmasq
, /etc/hosts . , DHCP. dnsmasq
LAN, dnsmasq.conf dnsmasq .
sol.
# /etc/dnsmasq.conf (
# )
...
local=/sol/
domain=sol
expand-hosts

19.5. dnsmasq (DHCP )

581

local , ,
, dnsmasq ( -).
domain , dnsmasq DHCP- . , local.
, expand-hosts , , ,
domain. , ping uranus, dnsmasq
uranus.sol.
dnsmasq , , IP- DHCP, , - DHCP. c LAN/WLAN,
Network Manager, . ,
- Fedora, Red Hat Debian
Ubuntu. , ,
19.5.

-
dnsmasq , -
. - IP-
MAC- . , , , -
, , .
dhcp-host. pluto.
# /etc/dnsmasq.conf
( )
...
dhcp-host=00:c0:ee:51:39:9f,pluto,192.168.0.254

MAC-
( ) . ID-, Ethernet-. Linux
MAC- iconfig. LAN dnsmasq. IP-
- MAC- /var/lib/misc/dnsmasq.leases.
, MAC- .
, DHCP, 24. , ,
. 24, dnsmasq , , .
,
, . infinite .

582

19. -

# /etc/dnsmasq.conf ( )
...
dhcp-host=00:c0:ee:51:39:9f,pluto,192.168.0.254,infinite

man dnsmaq /etc/dnsmasq.conf.orig dhcp-host. , -


IP-, MAC- ..

DNS
dnsmasq
, ! ,
, /etc/
resolv.conf. , .
-
( , Kerberos ..), , , dnsmasq . , .
/etc/resolv.conf dnsmasq ( localhost, 127.0.0.1),
. :
(LAN+DHCP +PPP), resolv.conf
. :
ADSL- . PPP, resolv.conf .
dnsmasq resolv.conf ,
, dnsmasq.conf server.
. , - mars IP-
192.168.0.1 LAN ADSL- Ethernet- eth0. IP 10.0.0.138. mars ADSL, eth0 ( ADSL-
DHCP, DHCP
,
resolv.conf DHCP ADSL-!).
# /etc/network/interfaces
...
# ADSL-,
auto eth0
iface eth0 inet static
address 10.0.0.1
netmask 255.255.255.0
gateway 10.0.0.138
...

/etc/resolv.conf (sol) IP-


( dnsmasq):

19.5. dnsmasq (DHCP )

583

# /etc/resolv.conf
search
sol
nameserver
192.168.0.1

dnsmasq :
( )
resolv.conf. , resolv.conf ( no-resolv)
,
server:
# /etc/dnsmasq.conf
...
no-resolv
server=10.0.0.138
...


dnsmasq ,
dnsmasq.conf:
# /etc/dnsmasq.conf
# LAN
interface=eth1,eth2
#
domain-needed
bogus-priv
# sol LAN
local=/sol/
domain=sol
expand-hosts
# Dnsmasq - ( = 10.0.0.138)
server=10.0.0.138
no-resolv
#
dhcp-range=192.168.0.2,192.168.0.250,24h
#
dhcp-host=00:c0:ee:51:39:9f,pluto,192.168.0.254,infinite

, dnsmasq
, IP- .

584

19. -

interfaces. , range:
# /etc/dnsmasq.conf
interface=eth1,eth2
dhcp-range=192.168.0.2,192.168.0.250,24h
dhcp-range=172.16.0.2,172.16.0.250,12h
...

, eth1
IP- 192.168.0.1, eth2 IP- 172.16.0.1.
, dhcp-range .
dnsmasq ,
dhcp-range:
# /etc/dnsmasq.conf
interface=eth1,eth2
dhcp-range=interface:eth1,192.168.0.2,192.168.0.250,24h
dhcp-range=interface:eth2,172.16.0.2,172.16.0.250,12h
...

NOTES man dnsmasq ,


.

dnsmasq IP-
/var/lib/misc/dnsmasq.leases /var/lib/dnsmasq/dnsmasq.leases.
, , . MAC- - ( ). ,
MAC- .
dnsmasq , , dnsmasq.conf
log-queries. /var/log/syslog /var/log/messages.


, IP DHCP, . Linux
Windows ,
. Network Manager,
Linux, DHCP- LAN- WLAN.

-: , -,
DHCP-. DHCP-
. Fedora Red Hat. -

19.6. WLAN

585

- DHCP! , ,
. system-config-network,
Edit () (
eth0) - DHCP.
, !

DHCP
, DHCP-, . .
Network Manager, , . .
, Network Manager, DHCP:
root# /etc/init.d/networking restart (Debian, Ubuntu)
root# service network restart (Fedora, Red Hat, SUSE)

, . iconfig
/etc/resolv.conf. KDE Gnome,
-
.
Windows DHCP . :
> ipconfig /renew (Windows)

19.6. WLAN
, WLAN, .
ADSL-WLAN.
- , ,
WLAN (.19.2)
WLAN-.
. WLAN.
WPA2 .
, , .
( , LAN
WLAN) 192.168.0.*.
(, NFS Samba)
LAN,
WLAN .

587

19.6. WLAN








  
   


WLAN











.19.3. WLAN -

20

Samba

Samba
Linux. ,
Windows, Linux Apple, . ,
. , Samba
, : , .
Samba SMB, , ,
Server Message Block ( ).
, Samba, IBM, , Microsoft.
Samba Windows
Linux. : SMB ,
Linux UNIX, :
Gnome KDE SMB,
, CIFS SMB
Linux .. UNIX- ,
Microsoft, NFS.
NFS , Windows.
Samba3.6
. ,
LDAP Samba , . http://www.samba.org/ https://
help.ubuntu.com/community/SettingUpSamba.

20.1.
Samba, ,
, ,
.

20.1.

589

NetBIOS. SMB NetBIOS (Network Basic Input/


Output System). NetBIOS -. IBM. NetBIOS
. NetBIOS .
. DNS, -

UNIX/Linux.
NetBIOS (NetBIOS Nameserver, NBNS) .
,
.
. TCP -

. , ,
, .
. -

, .
.
WINS. Windows NBNS Windows (Windows Internet Name Service, WINS). WINS
Samba Windows ( Windows9x).
, , Samba
.
Windows, UNIX,
.
,
, c Windows.
, NetBIOS TCP/IP,
. , , ,
, . , , . , .
. Windows ,
? . , .
, .
.
, Samba .
,
.
,

590

20. Samba

( ,
). , WINS-,
. ,
.
, Windows
(browsing list) . , ,
.
, .
, Windows Windows Linux, , ,
(
, Windows, , ).
SMB. Server Message Block, . Windows Vista Windows Server2008 2. Windows7 Windows Server2008R2 2.1,
Windows8 Windows Server2012 3.0. ,
Windows SMB1. ,
SMB 2 , .
Samba SMB2 3.5
3.6. ( .) SMB2 .

(Shares) , ,
NetBIOS. , . , ,
.
.
(, ).
. : 10 , 30. .
. , , ,
.

20.1.

591

, :

. ,
( /,
,
).
.
. ,
Samba Windows,
. ,
.
, .
( ,
, , ). Samba ,
,
, .
: . Samba S, X A
S ( ).
, . X B.
X S B,
B , .
X , S, , (A, B, C ..). ,
.
. Windows NT4 Microsoft
.
. .
,
.
. ,
,
, . , .
,
(Primary Domain Controller, PDC).

592

20. Samba

PDC
(Backup Domain Controller, BDC), ,
PDC .
Active Directories. , Microsoft
Active Directory.
( , ..) (LDAP). C
. ,
,
Linux, WINS.
Samba
. Samba Active
Directory . Samba4.
. , Samba (standalone) .

Samba , ,
Samba. security.
, !
security=user, .
PDC. ,
Samba Windows.



,
Samba.
. Samba
.
, () ,
.
,

. : ,
. , .
.
,
, . Windows, Linux ( , Gnome KDE)

.

20.2. Samba:

593

,
. , , ,
.
,
. , , ,
,
Gnome KDE.
, Gnome KDE
.

20.2. Samba:

.
. ,
.
,
, samba.
Samba4.
, Samba. 2012 Samba4
( ,
).
. Samba :
nmbd , -

;
WINS-;
smbd , -

, .
Init-V. Init-V
.
Samba , 8.5
,
.
Debian /etc/init.d/samba .
Fedora Systemd Samba.
RHEL, SUSE /etc/init.d/smb smbd, /etc/init.d/nmb nmbd.
Ubuntu Upstart Samba (/etc/init/nmbd.conf /etc/init/smbd.conf).

594

20. Samba

Smb.conf. Samba /etc/samba/


smb.conf. ([global]),
, (, ..) .
[_]. # ;.
,
.
Samba Ubuntu. ( ) , , ,
.
[printers] [print$],
.
# /etc/samba/smb.conf
[global]
workgroup =
server string =
dns proxy =
log file =
max log size =
syslog =
panic action =
encrypt passwords =
passdb backend =
obey pam restrinctions =
unix password sync =
passwd program =
passwd chat =
pam password change =
map to guest =
usershare allow guests =

Ubuntu 12.10
WORKGROUP
%h server (Samba, Ubuntu)
no
/var/log/samba/log.%m
1000
0
/usr/share/samba/panic-action %d
true
tdbsam
yes
yes
/usr/bin/passwd %u
...
yes
bad user
yes

smb.conf. smb.conf
.
. , :
root# cd /etc/samba
root# cp smb.conf smb.conf.org
root# grep -Ev '^#|^;|^$' smb.conf.orig > smb.conf

. workgroup
. , , ,
, Samba.
server string , . %h -.
WINS. dns proxy=no Samba, WINS-,
DNS - Windows.
LAN , yes.

20.2. Samba:

595

no ,
, .
. log file, max log size syslog ,
Samba . .
Samba panic-action.
, . , panic-action .
. passdb backend , Samba . smbpasswd ( ),
tdbsam (TDB, ) ldap-sam (LDAP).
( 250) tdbsam. smbpasswd, , ,
, Windows NT4 (SAM
Extended Controls).
unix password sync, passwd chat pam password change ,
Samba Linux , ,
.
. map to guest usershare guest , Samba , , ,
.
. , , . Samba, , Ubuntu (security=user).
,
security.
Samba. Debian Ubuntu smb.conf
, , . , ,
encrypt passwords=true .
obey pam restrictions=yes:
, .
, .
Samba, ,
, . man smb.conf.
SMB 2. Samba 3.5 3.6 SMB2.
, . smb.conf :
# /etc/samba/smb.conf
[global]
...
max protocol = SMB2

596

20. Samba

,
, smb.conf, , Samba
:
root# service samba reload (Debian)
root# service smbd reload (Fedora, openSUSE, Ubuntu)

Testparam. smb.conf ,
testparam, :
root# testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[printers]"
Processing section "[print$]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions <Return>
[global]
server string = %h server (Samba, Ubuntu)
...

testparam v,
smb.conf. , ,
(
).
Samba, smbstatus.
,
.

Samba
. Fedora, SUSE RHEL Samba . ,
Samba Windows TCP- 135, 139 445, UDP-
137 138. , .
! Samba !
,
. ,
Samba.
. Samba, .
interfaces,
.
, ,
. localhost,
, smbclient SWAT.
, -

20.2. Samba:

597

(
,
!). Samba .
, interfaces, ,
bind interfaces only.
. hosts allow ,
Samba. -, IP- IP . hosts
allow , interfaces.
hosts deny ,
Samba.
. , map to guest ,
, .
,
;
, .
# /etc/samba/smb.cnf
[global]
...
bind interfaces only =
interfaces =
hosts allow =
map to guest =

yes
192.168.0.0/24 localhost
clientA clientB clientC
never

Samba smbd nmbd /var/log/


samba/log.smbd log.nmbd. , smb.conf.
log file smb.conf , . /var/log/
samba/log.%m , Samba,
log.hostname. max log size=1000
1000. ,
Samba name.old. syslog=0 , syslog
, , /var/log/syslog
. 1, 2, 3 ..,
, .
Logrotate. , logrotate (.11.7):
, Debian, SUSE Ubuntu ,
log.smbd log.nmbd
, . logrotate
log.hostname,
. Fedora Red Hat

598

20. Samba

, , /var/log/samba:
# /etc/logrotate.d/samba Fedora Red Hat
/var/log/samba/* {
notifempty
olddir /var/log/samba/old
missingok
sharedscripts
copytruncate
}

smb.conf log file


= /var/log/samba/log.smbd. , smbd
, . Samba,
.

SWAT
Samba smb.conf , Samba Web Administration Tool (SWAT).
SWAT . smb.conf.

Samba

-
SWAT
. .
SWAT
, , SWAT.
, SWAT
smb.conf,
. smb.conf.

Debian, Ubuntu. SWAT ,


. openbsd-inetd.
, /etc/
inetd.conf, openbsd-inetd:
root# service openbsd-inetd restart

SWAT , root .
Ubuntu . sudo passwd root
!
Fedora, Red Hat. SWAT samba-swat, . xinetd.
SWAT, /etc/xinet.d/swat disable=yes
disable=no xinetd.
root# /etc/init.d/xinetd start
root# chkconfig --add xinetd

20.2. Samba:

599

SUSE. SUSE SWAT samba. SWAT


, /etc/xinet.d/swat disable=yes disable=no.
, xinetd:
root# insserv xinetd
root# service xinetd start

. SWAT - 901 ( Apache !).


SWAT, http://localhost:901
http://127.0.0.1:901.
, root. Samba Samba,
Samba. Web2.0
SWAT (.20.1).

.20.1. Samba SWAT

. , SWAT . Debian Ubuntu


/etc/hosts.deny hosts.allow ,

600

20. Samba

26.2 ( ,
192.168.0.*):
# /etc/hosts.allow
swat : 192.168.0.0/24
# /etc/hosts.deny
swat : ALL

Fedora, Red Hat SUSE ,


only_from=127.0.0.1 /etc/xinet.d/swat SWAT localhost.

20.3.
Samba security=user, . , peter , .
Linux peter.
. Samba ,
Linux, , .
Linux . .
, , Samba .
peter Samba.
Samba ( , ) Linux.
Linux Samba .
smb.conf ,
peter.

Samba
,
Samba.
Windows Windows . ,
Linux, , Linux,
Samba. ,
Windows, : Samba , .
, , .
Samba ,

20.3.

601

.
, , .
smbpasswd. Samba
, , .
(passdb backend=smbpasswd). SUSE
-
/etc/samba/smbpasswd.
TDB. TDB (passdb backend=tdbsam). LDAP,
.
TDB Trivial Database ( )
.
smbpasswd ,
,
. , , SAM Extended Controls, Windows. , :
Debian, Ubuntu /var/lib/samba/passdb.tdb;
Fedora, Red Hat/var/lib/samba/secret/passdb.tdb;
SUSE /etc/samba/passdb.tdb.
smb.conf
passdb backend=tdbsam:_. smbpasswd
Samba ; pdbedit , : ,
Samba (pdbedit -L -v),
.. smb.conf ( smbpasswd, tdbsam ldapsam).
Smbpasswd. , Samba,
Linux Samba
peter. smbpasswd. , peter Windows.
Samba, smbpasswd
-a.
root# smbpasswd -a peter
New SMB password: ******
Retype new SMB password: ******
Added user peter.
Password changed for user peter.

sbmpasswd , Linux peter ( /etc/passwd). Linux useradd


adduser.

602

20. Samba

Samba Linux
, Samba
, SSH Linux. , , Samba Linux . , (
: Windows, Samba Linux).
, ,
Samba ,
Linux. Samba Linux . (
, : ,
. .)
,
smbpasswd ( )
Linux. Ubuntu smbpasswd :
[global]
...
unix password sync = yes
pam password change = yes
passwd chat
= *Enter\snew\s*\spassword:* %n\n
*Retype\snew\s*\spassword:* %n\n
*password\supdated\ssuccessfully*

unix password sync=yes . pam password change PAM. PAM , . passwd program ,
passwd, PAM . passwd chat Samba PAM. ,
smb.conf .
, .
smbpasswd , ! : smbpasswd root, Samba ( ,
Samba ). , Samba,
, .
smbpasswd (,
). Linux PAM, ,
. Samba , -

20.3.

603

Linux . Linux .
,
Samba Linux .
unix password sync
: Samba Linux.
Linux passwd, Samba ( libpam-smbpass, . ).

. ,
, .
unix password sync=no.
Libpam-smbpass. Linux
Samba Ubuntu libpam-smbpass. PAM ( (PAM) 11.4) ,
Linux Samba .
(, !)
libpam-smbpass , , , Linux Samba.
libpam-smbpass , Samba
Linux.

libpam

-
smbpass
[
lib
]
pam
_
smb
! pam

_
smb
(
Linux
) Samba


Windows
.

Linux Windows
Windows ( 128). Linux , ,
32 . Windows ,
Linux,
. smb.conf username
map:
# /etc/samba/smb.conf
[global]
...
username map = /etc/samba/smbusers

smbusers Linux,
= Windows. ,

604

20. Samba

, .
, Windows
Linux.
# /etc/samba/smbusers
peter = "Peter Mayer"
...

/etc/samba/smbusers Samba Linux,


root , ! ,
root:
root# chmod 644 /etc/samba/smbusers


, Windows,
, Peter Mayer.
Linux, Samba, peter smbusers,
Peter Mayer peter. .
Windows Peter Mayer Windows. Windows -

Windows.
Windows.
(Linux) peter Linux. Linux

, Linux . , SSH
passwd.
Peter Mayer peter Samba.

Samba .
Windows. ,
, Windows .
smbpasswd SSH.
SWAT,
. SWAT , Linux, ,
Samba. , .
Linux ,
Samba!
, , ,
, Linux .
: . , ,
.

20.4.

605

20.4.
, ,
Samba. ,
Linux Samba. , . [_] smb.conf.


, ,
:
# /etc/samba/smb.conf
...
[directory1]
user
= peter
path
= /data/dir1
writeable = yes

peter, , smbusers ,
/data/dir1 .
directory1 ( , ).
: user . user
users username.
, .
path ,
. path , Samba .
writeable=yes .
.
, Linux. , /data/dir1 , root,
peter, , , . .


,
Linux
. smb.conf
:
[username]
User
= username
writeable = yes

606

20. Samba

smb.conf :
# /etc/samba/smb.conf
...
[homes]
writeable = yes
browseable = no

, , ,
. browseable=no,
, . :
(, peter), homes.



, ,
, , .
, . Linux.
user @_.
# /etc/samba/smb.conf
...
[salesdata]
user
= @sales
path
= /data/sales
writeable
= yes
force group
= +sales
create mask
= 0660
directory mask = 0770


, .
, . force
group = +sales sales ( ).
sales, .


force
group

= sales

( ), Samba ,
sales ,
Linux .
, force

group

=
sales
, , sales, .

!

20.4.

607

create mask directory mask ,


,
( chmod . man chmod).

, , 0440 0550.

,
:
, Samba,
. :
# /etc/samba/smb.conf
...
[share]
path
= /data/share
read only = yes

, (writable = yes).
, ,
. force group
mask. , create mask=0666 directory mask=0777.

,
Samba. Samba ,
, . (guest).
, :
# /etc/samba/smb.conf
[global]
...
map to guest = bad user
guest account = nobody

map to guest = bad user Samba guest.


, guest. guest account , Linux . , Debian Ubuntu,
nobody.

608

20. Samba

, , guest ok = ok. ,
read only = yes. , ,
Linux nobody.
[guest]
path = /data/guest
guest ok = yes
read only = yes

, guest ok guest only = yes:


, , .
Samba, [global] map to guest = never.


(User Shares)
3.0.23 Samba ,
, (User Shares). /var/lib/samba/usershares (
). :
# 2
# /var/lib/samba/usershares/testdir
path = /myhome/kofler/testdir
comment =
guest_ok = n


smb.conf usershare. usershare
allow User Shares guest- ( ).
guest ok guest only. usershare max shares .
# /etc/samba/smb.conf
[global]
...
usershare allow guests = yes
usershare max shares = 100

Samba
, ,
. , Linux, Windows
MacOSX, .

20.4.

609

, Samba.

smb.conf:
[global]
vfs objects = recycle

Samba recycle (VFS


Virtual File System, ).
.recycle ( ). , ,
.
, recycle:repository , , , :

recycle:repository = Trash

, . Samba , .
, ( recycle:touch = Yes). recycle:xxx
http://linux.die.net/man/8/vfs_recycle.
recycle:xxx
. http://
www.redhat.com/advice/tips/sambatrash.html.


Gnome KDE

Samba, , , smb.conf. Gnome KDE.
Nautilus (Gnome), Dolphin (KDE)
Samba, .
/var/lib/samba/usershares.
, , ( Ubuntu sambashare)
.

nautilus-share*,
Nautilus .
Samba,
.

610

20. Samba

Nautilus/Gnome. Nautilus .

.
Dolphin/KDE. KDE Dolphin Konqueror
.
. Samba, kdenetwork-filesharing.
. , . ,
.
, , . , ,
, smbpasswd libpam-smbpass
Samba. KDE, Gnome. Samba smbpasswd .

20.5. : /


Samba. , , , : , MP3,
, ..
.
. ( ,
?)
. ,

. .
, , , ,
.

.
, , Linux, , .
WLAN.
-
.
Samba:
,
. ( ,

20.5. : /

611

).
. parents, children,
family, audio photos. , audio photos
family,
, .
.
Linux.
mother, father, daughter, son. , ,
, ,
. useradd
--create-home /home/. /etc/skel. ,
( ):
root#
root#
root#
root#
root#
root#
root#
root#

groupadd parents
groupadd children
groupadd family
useradd --create-home --groups parents,family father
useradd --create-home --groups parents,family mother
useradd --create-home --groups children,family son
useradd --create-home --groups children,family daughter
rm -rf /home/{father,mother,daughter/son}/*
()

useradd ,
( ). :
, .
,
. , family
parents children. , father, parents
family, mother, parents family .. ,
:
root# usermod -a -G newgroup user

Samba. Samba, :
root# smbpasswd -a father
New SMB password: *******
Retype new SMB password: *******
root# smbpasswd -a mother
...
root# smbpasswd -a son
root# smbpasswd -a daughter

. ,
.
chmod770

612

20. Samba

.
, .
root#
root#
root#
root#
root#
root#
root#
root#

mkdir /shared-data
mkdir /shared-data/{parents,children,family,audio,photos}
cd /shared-data
chown :parents parents/
chown :children children/
chown :famile family/ audio/ photos/
chmod 770 *
chmod 770 /home/{father,mother,son,daughter}

, .
/home shared-data.
Samba.
smb.conf. Samba .
, 20.4.
# /etc/samba/smb.conf
[global]
workgroup
= home
server string
= %h server (Samba, Ubuntu)
security
= user
passdb backend
= tdbsam
unix password sync = no
invalid users
= root
map to guest
= never
log file
= /var/log/samba/log.%m
max log size
= 1000
syslog
= 0
dns proxy
= no
panic action
= /usr/share/samba/panic-action %d
[homes]
browseable
= no
writeable
= yes
[parents]
user
= @parents
path
= /shared-data/parents
writeable
= yes
force group
= +parents
create mask
= 0660
directory mask
= 0770
[children]
user
= @children
path
= /shared-data/children
writeable
= yes
force group
= +children
create mask
= 0660
directory mask
= 0770

613

20.6. :

[family]
user
path
writeable
force group
create mask
directory mask
[photos]
user
path
... [family]
[audio]
user
path
... [family]

=
=
=
=
=
=

@family
/shared-data/family
yes
+family
0660
0770

= @family
= /shared-data/photos
= @family
= /shared-data/audio

: , , ,
(,
children, parents). - , ,
.
Samba, , .
browseable = no,
, (
, , ). hide unreadable = yes hide unwriteable = yes :
,
. .

20.6. :
, . , ,
Samba. .
, , .20.1. .20.2 ,
, ,
.
20.1.

()

, ,

614

20. Samba
20.2.

, , ,

,
. ,
, . , !

Samba- ,
, .
.
, .
, !
Linux. ,
chiefn ,
developern .. , , .
, ( ). ,
.
root# groupadd management
root# groupadd sales
root# groupadd accountancy
root# groupadd developing
root# useradd --create-home \
--groups management,sales,accountancy,developing chief1
root# useradd --create-home --groups sales sales1
root# useradd --create-home --groups sales sales2
root# useradd --create-home --groups developing developer1
root# useradd --create-home --groups developing developer2
root# useradd --create-home --groups accountancy,sales accountant1
root# useradd --create-home --groups accountancy,sales supervisor1
root# ...

Samba. ,
:
root# smbpasswd -a chief1
root# smbpasswd -a sales1
...

20.6. :

615

.
. chmod770
,
.
root#
root#
root#
root#
root#
root#
root#
root#

mkdir /companydata
mkdir /companydata/{developing,sales,accountancy,strategy}
cd /companydata
chown :developing developing/
chown :sales
sales/
chown :accountancy accountancy/
chown :management
strategy/
chmod 770 /companydata/* /home/*

Samba. workgroup,
smb.conf ,
(.20.5).
. , . ,
force group. ,
, , .
smb.conf + !
# /etc/samba/smb.conf ( )
[global]
... ( )
[homes]
browseable = no
writeable = yes
[strategy]
user = @management
path = /companydata/strategy
writeable = yes
force group = +management
create mask = 0660
directory mask = 0770
[accountancy]
user = @accountancy, @management
path = /companydata/accountancy
writeable = yes
force group = +accountancy
create mask = 0660
directory mask = 0770
[developing]
user = @developing, @management
path = /companydata/developing
writeable = yes
force group = +developing
create mask = 0660
directory mask = 0770

616
[sales]
user =
path =
writeable =
force group =
create mask =
directory mask =

20. Samba

@sales, @accountancy, @management


/companydata/sales
yes
+sales
0660
0770

20.7.
, ,
Samba . ,
: TCP135, 139 445,
UDP137 138 .

Linux
, Linux,
Windows, Samba, , , Samba ( ). Ubuntu
samba-common, smbclient libsambaclient,
.
KDE, Gnome. Gnome KDE. , Windows.
,
,, ( ).

.
. :
smb://_/_.
LinNeighborhood pyNeighborhood. KDE Gnome,
Windows, LinNeighborhood pyNeighborhood.

CIFS
,
, CIFS
( ). ,
, ,
.
CIFS SMBFS ( Samba).
CIFS- Samba- UNIX/Linux- , SMBFS .

20.7.

617

CIFS , Samba
CIFS mount (, , mount.cifs).
Debian Ubuntu cifs-utils ( smbfs).
Fedora openSUSE .
,
( , Windows
):
root# mount -t cifs //jupiter/myshare /media/winshare
root# mount -t cifs -o username= //jupiter/myshare /media/winshare

, myshare Linux
jupiter. /media/winshare.
mount.
.
:
root# mount -t cifs -o username=,password=xxxxxxxx \
//jupiter/myshare /media/winshare

mount.
, mount ,
id.
root# mount -t cifs -o username= ,password=xxxxxxxx,uid=1000,gid=1000 \
//jupiter/myshare /media/winsha

, mount iocharset=utf8.
NAS (Network Attached Storage,
, ). NAS
Samba, DFS . (DFS
Distributed Filesystem, ; ).
DFS, rsync ( failed
to set times on filename). mount nodfs.
/etc/fstab.
, /etc/fstab , , :
# /etc/fstab
//jupiter/myshare /media/winshare cifs username=u,password=p,... 0 0

CIFS-, /etc/fstab,
Init-. SUSE:
Init-V cifs ( openSUSE
smbfs), :
root# insserv cifs

618

20. Samba

.
/etc/fstab.
, (root). ,
/etc/.winshare-pw, ( ) () .
:
username=name
password=xxxx
domain=workgroup

. :
root# chmod 600 /etc/.winshare-pw

fstab credentials. .winshare-pw.


# /etc/fstab
//jupiter/myshare /media/winshare cifs credentials=/etc/.winshare-pw 0 0

smbclient smbtree
Smbclient. smbclient. , , Samba.
smbclient -L localhost , ,
,
(). ,
Enter. Samba, localhost .
smbclient (access denied),
,
Linux Windows
Samba. smbclient :
user$ smbclient -U _ -W _ -L jupiter

smbclient , .
Windows Samba.
Windows \\_\_.
\, . , FTP,
ls, cd
, get (),
put ().

20.7.

619

help. man smbclient.


user$ smbclient -U name -W wgname \\\\jupiter\\myshare
Password: xxxxxx
Domain=[wgname] OS=[Unix] Server=[Samba 3.5.4]
smb: > ls
. D 0 Thu Sep 7 17:38:02 2010
.. D 0 Thu Sep 7 17:38:02 2010
data D 0 Wed Apr 5 18:17:11 2010
file.xy AR 226 Sat Dec 14 00:00:00 2010

Smbtree. smbtree Samba


Windows, , ,
. , smbtree
.
-user=name%password . , , -N. (kofler-desktop ubuntu-test), (merkurvm), (wd-nas),
WORKGROUP.
root# smbtree
Enter kofler's password: ********
WORKGROUP
\\KOFLER-DESKTOP kofler-desktop server (Samba, Ubuntu)
\\KOFLER-DESKTOP\mydata
\\KOFLER-DESKTOP\IPC$ IPC Service (kofler-desktop server)
\\KOFLER-DESKTOP\print$ Printer Drivers
\\MERKURVM merkurvm
\\MERKURVM\images
\\MERKURVM\data
\\MERKURVM\SharedDocs
\\UBUNTU-TEST ubuntu-test server (Samba, Ubuntu)
\\UBUNTU-TEST\IPC$ PC Service (ubuntu-test server ...)
\\UBUNTU-TEST\print$ Printer Drivers
\\WD-NAS My Book World Edition Network Storage
\\WD-NAS\IPC$ IPC Service (My Book ...)
\\WD-NAS\Configuration
System Configuration
\\WD-NAS\multimedia
\\WD-NAS\Download Download Share
\\WD-NAS\Public Public Share

Windows
Windows Samba
. Samba
.
Windows.

620

20. Samba

LLTD. , Windows Vista, Windows7


Samba,
Windows. ,
, Link Layer Topology Discovery (LLTD,
). ,
. , Samba,
Windows. LLTD http://support.microsoft.com/kb/922120 http://www.microsoft.com/whdc/
rally/rallyLltd.mspx.
, , LLTD,
. Windows
\\ .
, Linux
LLTD. , Microsoft
. , , Linux.
, Net::Frame Perl.

21

NFS AFP

SMBP ( ), Samba, . Samba


. . UNIX NFS (
), AFP (Apple Filing Protocol), OSX.

21.1. NFS 4
(NFS) , , , . SMB (Samba), mount
/etc/fstab, . ,
,
. NFS ,
NFS-.
NFS , .
NFS- ,
, .
NFS NFS- 3 4.
NFS4 , .
, ,
, NFS4,
NFS3.


Linux NFS 4 . NFS
nfs-common nfs-kernel-server (Debian, Ubuntu)

622

21. NFS AFP

nfs-utils (Fedora, RHEL, SUSE).


.
NFS4 , rpc.idmapd.
() NFS UID/GID.
.
Debian rpc.idmapd Init-V nfs-common.
, /etc/exports ( )
/etc/fstab nfs4 ( ).
. /etc/default/nfscommon NEED_IDMAPD=yes.
RHEL, Fedora rpc.imapd
/etc/init.d/nfs. . Fedora16 :
root# systemctl start nfs-idmap.service
root# systemctl enable nfs-idmap.service
SUSE , /etc/sysconfig/nfs
NFS4_SUPPORT=yes ( ). rpc.idmapd

Init.
Ubuntu idmapd /etc/init/idmapd.conf.
. , () NFS, , .
. ,
/data/audio, /data/fotos /iso-images.
, /nfsexport ( ). /nfsexport/audio, /data/
fotos /iso . (mount point).
root#
root#
root#
root#

mkdir
mkdir
mkdir
mkdir

/nfsexport
/nfsexport/audio
/nfsexport/fotos
/nfsexport/iso

/data/ /data/fotos nfsexports. , /data/audio /nfsexport/


audio, /data/fotos /nfsexport/fotos.
root# mount -t none -o bind /nfsexport/audio/ /data/audio/
root# mount -t none -o bind /nfsexport/fotos/ /data/fotos/
root# mount -t none -o bind /nfsexport/iso/ /iso-images/

NFS- , /etc/fstab ( ) :
# /etc/fstab
...

623

21.1. NFS 4

/data/audio
/data/fotos
/iso-images

/nfsexport/audio none bind 0 0


/nfsexport/fotos none bind 0 0
/nfsexport/iso none bind 0 0

/etc/exports. /etc/exports
NFS. ,
. IP, . IP- (, 192.168.0.0/255.255.255.0 192.168.0.0/24).
* (, *.sol), IP- .
, IP- - , ,
, !
,
NFS-, *.
, IP-
192.168.0.* *.lan /nfsexport/audio
/nfsexport/fotos. , , ( IP- -) /nfsexport/iso.
audio iso . \.
# /etc/exports fur NFS 4
/nfsexport 192.168.0.0/24(rw,async,no_subtree_check,fsid=0,crossmnt) \
*.lan(rw,async,no_subtree_check,fsid=0,crossmnt)
/nfsexport/audio 192.168.0.0/24(ro,async,no_subtree_check) \
*.lan(ro,async,no_subtree_check)
/nfsexport/fotos 192.168.0.0/24(rw,async,no_subtree_check) \
*.lan(rw,async,no_subtree_check)
/nfsexport/iso *(ro,async,no_subtree_check)

/etc/exports .
- IP- NFS, (
man exports).
ro (read-only) rw (read-write) , .
sync async , NFS- , . sync. , .
async , . sync async ( 10), async .
no_subtree_check subtree_check , NFS- . : NFS ( ), NFS-
, , ,
. NFS-
.

624

21. NFS AFP

, .
NFS- . no_subtree_check ,
.
. man
exports , , ,
.
root, , NFS, , , , nobody (UID=65534 GID=65534).
root , /etc/exports
no_root_squash.
NFS4 fsid=0.
! ( NFS4 , !)
crossmnt .
,
. , crossmnt
, nohide .
Exportfs -a. NFS- ,
/etc/exports exportfs -a. ,
NFS- .
root# exportfs -a

, .
, , :
Debian, Ubuntu /etc/defaults/nfs-common, /etc/defaults/nfs-kernel-server;
Fedora, SUSE, Red Hat /etc/sysconfig/nfs.
. Debian Ubuntu NFS
. Fedora, Red Hat SUSE ,
Init-V, :
root#
root#
root#
root#
root#
root#

systemctl start nfs-server.service (Fedora)


systemctl enable nfs-server.service
chkconfig --level 35 nfs on (RHEL)
service nfs start
insserv nfs (SUSE)
service nfs start

UID GID-. NFS4 ID-. ,


hofer NFS-, -

21.1. NFS 4

625

hofer NFS .
, , nobody.
ID- NFS4 ,
NFS3, UID- GID-.
NFS4 :
,
!
UID- GID-
rpc.idmapd. /etc/idmapd.conf. NFS4, ,
, .
. NFS 4 TCP- 2049.
, .
NFS 4 LDAP Kerberos. ,
NFS 4. , , NFS4 LDAP Kerberos. ,
. , :
http://www.itp.uzh.ch/~dpotter/howto/kerberos;
http://wiki.debian.org/nfs4-kerberos-ldap;
http://www.danbishop.org/2012/06/02/ubuntu-12-04-ultimate-server-guide-first-draft/.


NFS4 , , . nfs-common (Debian,
Ubuntu), nfs-utils (Fedora, RHEL) (SUSE), ,
rcp.idmapd.
Mount unmount. ,
mount. nfsexport. /media/nfsdata. jupiter -
NFS-. : NFS /, /nfsexport!
root#
root#
root#
audio

mkdir /media/nfsdata
mount -t nfs4 jupiter:/ /media/nfsdata
ls /media/nfsdata
fotos iso

, :
root# mkdir /media/fotos
root# mount -t nfs4 jupiter:/fotos /media/fotos

626

21. NFS AFP

umount NFS .
, umount -f.
, umount !
root# umount /media/fotos
root# umount /media/nfsdata

openSUSE NFS- YaST- NFS. openSUSE12.2 NFS-,


, rpc

.
idmapd
(
service
start

nfs

insserv
nfs

. YaST ).

/etc/fstab. NFS , /etc/fstab ,


. NFS-
bg. mount , . , ,
,
.
# /etc/fstab
jupiter:/fotos /media/fotos nfs4 bg 0 0

Automount/ autofs. NFS-, /etc/fstab. , , .


.
autofs autofs4.


mount- , ,
.
. NFS 4 TCP- 2049.
rpc.idmapd , . , , ps ax | grep idmapd.
NFS-. ,
rpcinfo -p. ,
NFS 2, 3 4.
root# rpcinfo -p | grep nfs

program vers proto port service

100003
2
tcp 2049 nfs

100003
3
tcp 2049 nfs

100003
4
tcp 2049 nfs

...

627

21.2. NFS 3

showmount -e , NFS. , *
everyone showmount -

user@nfsserver$
/nfsexport
/nfsexport/audio
/nfsexport/fotos
/nfsexport/iso

showmount -e
(everyone)
(everyone)
(everyone)
*

showmount ,

- NFS-:

user$client#

showmount -e <nfsserver>

21.2. NFS 3
NFS4 , NFS3 -
.
. NFS3 .
ID-.
, UID 1000,
UID- UID 1000
. NFS 3 ,
UID- GID!
. NFS
TCP UDP 111 (portmap) 2049 (nfsd), (rpc.*d).

NFS3,
(portmap rpc.mountd).
NFS3 .
, .
( Linux , , , Unicode
UTF8.)
NFS 3 (ACL),
Kerberos SPKM3.
NFS3
http://nfs.sourceforge.net/nfs-howto/.
, NFS4 .

628

21. NFS AFP


/etc/exports. NFS3 , NFS 4.
mount.
/etc/exports.
NFS3 , NFS4.
.
fsid crossmnt NFS 3 .
insecure, NFS-
Apple OSX.
NFS , IP- 1024. NFS-
OSX.
exports , NFS4:
# /etc/exports NFS 3
/data/audio 192.168.0.0/24(ro,async,no_subtree_check) \
*.lan(ro,async,no_subtree_check)
/data/fotos 192.168.0.0/24(rw,async,no_subtree_check) \
*.lan(rw,async,no_subtree_check)
/data/iso-images *(ro,async,no_subtree_check)

Exportfs -a. NFS 4, exports


NFS3 exportfs -a:
root# exportfs -a

UID GID. NFS3


UID GID. , ,

, ID-.

UID GID : ,
UID GID. ,
UID GID.
,
: , peter@merkur
birgit@neptun, , UID1234,
NFS.
.
/etc/passwd,
/etc/group /etc/shadow NIS ( ). NIS , .
(, , ,
UID GID ..) LDAP. LDAP Lightweight Directory

21.2. NFS 3

629

Access Protocol ( )
. LDAP- Linux
openLDAP. , LDAP .
. NFS3, 111 2049 TCP UDP. , ,
:
NFS3. , NFS3 111 2049
, . ,
statd, lockd mountd. RHEL, , /etc/sysconfig/nfs:
http://www.gotdoug.com/?p=3;
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_
Guide/s2-nfs-nfs-firewall-config.html.

/etc/hosts.allow, /etc/hosts.deny. hosts.allow hosts.deny


, NFS-. , /etc/exports, ,
NFS-. hosts.allow
hosts.deny .
26.2. NFS- portmap
mountd.
, /etc/hosts.allow -.deny
NFS3, NFS4!
Mount-. showmount a
NFS-. , NFS3!
, NFS4,
.


NFS3 NFS4. , ,
. nfs-common (Debian, Ubuntu), nfs-utils (Fedora,
RHEL) nfsclient (SUSE). mount nfs, nfs4. ,
NFS-:
root# mount -t nfs jupiter:/data/fotos /media/fotos

/etc/fstab:
# /etc/fstab
jupiter:/data/fotos /media/fotos nfs bg 0 0

22

SSH
(Secure Shell)

,
.
SSH (Secure Shell).
, , .
.
, SSH-. , SSH-.
SSH telnet rlogin, .
SSH 10.2.
OpenSSH: http://www.openssh.com/.
. SSH ,
, . , ,
- ( ). Linux
, .. ,
, ,
ADSL.
.
, , , , . , ,
. , ,

.
, , Linux .
() Debian, Ubuntu, LTS CentOS. -

631

22.2.

Fedira openSUSE
, .

22.1.
SSH-
. SSH- , .
Debian, Ubuntu. Debian Ubuntu openssh-server.
sshd .
root# apt-get install openssh-server

Fedora, RHEL. Fedora RHEL ,


yum.
root# yum install openssh-server

Fedora SSH- . RHEL, ,


, .
root# service sshd start

root# service --add sshd

( SSH-,
RHEL)
( SSH-,
RHEL)

OpenSUSE. openSUSE openssh. openSUSE Systemd openssh .


root# zypper install openssh

22.2.
sshd /etc/ssh. sshd_config. , , SSH- .
IP-22. ,
man .
FTP. SSH- SFTP-.
FTP-. SFTP , SSH-. ,
SFTP- (, sftp). SFTP
(
FTP).
. SSH-
. ,

632

22. SSH (Secure Shell)

: , ,
! , .
/var/log/auth.log. !
,
. , makepasswd
, .
/etc/shadow
, !
,
. , (* !).
.
, , .
,
SSH-.
.
.
, ,
.
.
, SSH. , SSH
,
su sudo (,
, ).
# /etc/ssh/sshd_config
...
PermitRootLogin = no

, sshd :
root# service ssh reload

:
, !
PermitRootLogin = no without-password:
# /etc/ssh/sshd_config
...
PermitRootLogin = without-password

,
! without-password ,
,
. (
).

22.2.

633

SSH-. 22. port ,


. 22,
, .
ssh, SSH- -p. ,
scp -P, -p
preserve .
, ,
. , -
, ,
. SSH-, , .
, , . ,
, 22,
. , ,
SSH,
.
TCP-Wrapper. SSH- , TCP-Wrapper. /etc/hosts.allow /etc/hosts.deny,
SSH-. SSH-,
SSH . , ,
SSH- , . TCP-Wrapper 26.2.
DenyHosts. DenyHosts, Python,
SSH. ,
IP- , IP-
/etc/hosts.deny.
IP- hosts.deny, (,
).
DenyHosts
( ,
). , , .
.
http://denyhosts.sourceforge.net/.
DenyHosts Init-V
/etc/denyhosts.conf. , denyhost

634

22. SSH (Secure Shell)

( SECURE_LOG). - http://kofler.info:
# /etc/denyhosts.conf
SECURE_LOG = /var/log/auth.log
HOSTS_DENY = /etc/hosts.deny
# 24 IP-,
PURGE_DENY = 1d
#
DENY_THRESHOLD_INVALID = 3
#
DENY_THRESHOLD_VALID = 5
# root
DENY_THRESHOLD_ROOT = 1

22.3.
SSH- SSH. ,
. ssh-keygen . -. (- ,
.) , . , ssh-copy-id.
.ssh/authorized_keys :
user@client$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): <Return>
Enter passphrase (empty for no passphrase): ********
Enter same passphrase again: ********
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
user@client$ ssh-copy-id -i user@server
user@server's password: *******

-, Enter empty,
ssh-keygen . ,
SSH, .
: , , , !
ssh-copy-id , . ,
,
, .

22.3.

635

~/.ssh/id_rsa.pub

.ssh/authorized_keys.
ssh
, . , -,
.
Ssh-agent. ( -),
,
. ssh-agent.
(
). :
user$ eval $(ssh-agent)

, . ssh-agent
. ssh-add :
user$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/user/.ssh/id_rsa: ******

, ssh , ssh-agent.
,
. ssh-, . ssh-agent
,
.
Gnome-keyring. gnome-keyring-daemon Gnome
SSH-.
(
!) (master) . seahorse.
. SSH- . . SSH- STRICT_MODE (
), authorized_keys ,
. ssh-copy-id,
, .
:
user@server$ chmod 700 ~/.ssh
user@server$ chmod 600 ~/.ssh/authorized_keys

Fedora RHEL : ,
ssh-copy-id, , SELinux. :
root@server# /sbin/restorecon -r /root/.ssh ( )
root@server# /sbin/restorecon -r /home/user/.ssh ( )

636

22. SSH (Secure Shell)

SSH

- , ,
ssh
- -v. ssh .
(-
v
-
v
-
v
). , ssh.

. SSH- (
), .
sshd_config.
:
# /etc/ssh/sshd_config
...
PasswordAuthentication no
UsePAM no

SSH- . , !
,
! : ,
...

23

Apache

Apache - .
netcraft.com, 2012 57% Apache.
, Apache
62%.
Apache 2.2. 2.4 2012.
Apache2.2
. , Apache : http://www.apache.org.

23.1. Apache
,
. Apache
: , , , . ,
.
Apache PHP MySQL.
root# yum groupinstall 'Web-Server' (Fedora, RHEL)
root# zypper intall -t pattern lamp_server (SUSE)
root# tasksel install lamp-server (Ubuntu)

2 Apache : perchild,
prefork worker. , Apache
. Apache
. Apache PHP,

prefork
. , (http://www.php.net/manual/en/faq.installation.php).

/. Apache ,
.
8.5. Init-V : apache2 Debian, SUSE Ubuntu httpd Fedora Red Hat.

638

23. Apache

. Fedora, Red Hat (open)SUSE , , - .


Apache ,
- (http://localhost). - , HTTP HTTPS
( 80 443).
. ,
- Apache, . ,
, -, ,
, .
, ps axu. .23.1 , .
23.1. , DocumentRoot Apache

DocumentRoot

Debian, Ubuntu

apache

www-data

/var/www

Fedora, Red Hat

httpd

apache

/var/www/html

SUSE

httpd2-thread

wwwrun

/srv/www/htdocs

. , ,
http://localhost/ http://_/.
- (.23.1).

.23.1. Apache Ubuntu

HTML-.
, HTML- Apache. -
( DocumentRoot ,
..23.1). HTML- , - Apache!

Apache.
, .

639

23.1. Apache

Apache httpd.conf, . .
,
.

,
include (.23.223.4).
, . , . , :
user$ cd /etc/httpd () cd /etc/apache2
user$ find -type f -exec grep -i -q _ ^; -print
23.2. Apache Debian Ubuntu

/etc/apache2/apache2.conf

/etc/apache2/httpd.conf

/etc/apache2/ports.conf

, 80

/etc/apache2/mods-available/*

/etc/apache2/mods-enabled/*

/etc/apache2/conf.d/*

/etc/apache2/sites-available/*

( )

/etc/apache2/sites-enabled/*

/etc/apache2/envvars

Init-V
23.3. Apache Fedora Red Hat

/etc/httpd/conf/httpd.conf

/etc/httpd/conf/magic

MIME ( mod_mime)

/etc/httpd/conf.d/*.conf


23.4. Apache SUSE

/etc/apache2/httpd.conf

/etc/apache2/*.conf

/etc/apache2/sysconf.d/*.conf

/etc/apache2/conf.d/*.conf

/etc/apache2/vhosts.d/*.conf

( )

/etc/sysconfig/apache2

Debian/Ubuntu mods-available *.load


*.conf Apache.

640

23. Apache

mods-enabled . Debian a2enmod a2dismod. a2ensite a2dissite. sites-available


default: - (
/var/www), , .
, : sites-available , sites-enabled .
SUSE CONF- sysconf.d Apache
Init-V /etc/init.d/apache2 !
. , ,
/etc/sysconfig/apache2. , ,
Apache ( APACHE_MODULES).
SUSE ,
APACHE_CONF_INCLUDE_FILES.
. , httpd -t,
httpd2 -t apache2 -t , . Debian Ubuntu envvars
:
root# . /etc/apache2/envvars
root# apache2 -t
Syntax OK

Apache :
root# service apache2|httpd reload

ServerName. - Apache .
,
: ServerName
. ,
UseCanonicalName Off.
# /etc/apache2/httpd.conf
(Debian/Ubuntu)
# /etc/httpd/conf/httpd.conf
(Fedora/Red Hat)
ServerName mars.sol
#

SUSE /etc/sysconfig/apache2 APACHE_SERVERNAME.


Linux Unicode UTF-8. ,
, ,
, , , UTF-8.

23.1. Apache

641

Apache, , , . , .
Apache , , .
.
. Apache .
, ,
- . Apache
.
AddDefaultCharset off Apache <meta>-

HTML- ,
. HTML , , Unicode UTF-8:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
...
AddDefaultCharset charset Apache
. HTML- PHP-. <meta>-

HTML- .
AddDefaultCharset charset extension ,
. AddCharset utf-8 .utf8,
, .utf8, Unicode UTF-8. AddCharset Apache mod_mime.

Debian, Ubuntu. , . Ubuntu


/etc/apache2/conf.d/charset. ,
AddDefaultCharset off.
, AddDefaultCharset AddCharset ( sites-available),
.htaccess, . , , .htaccess, , - AllowOverride
All FileInfo.
Fedora, Red Hat. Fedora Red Hat AddDefaultCharset
UTF-8. /etc/httpd/conf/httpd.conf.
AllowOverride None /var/www/html.
SUSE. SUSE . , AddDefaultCharset off, , <meta>- HTML-.
AddDefaultCharset /etc/apache2/mod_mimedefaults.conf. , SUSE AllowOverride None /srv/
www/htdocs. /etc/apache2/default-server.conf.

642

23. Apache

Logrotate
Apache , . ,
, , .
logrotate (.11.7), , , Linux.
/etc/cron.daily/
logrotate. Apache
/var/log/httpd/*.log (Fedora/RHEL) /var/log/apache2/*.log (Debian/Ubuntu)
, .nn .
52, .

, /etc/logrotate.d/apache2 ,
.
, /home/*/www-log/*.log.
# /etc/logrotate.d/apache2
/var/log/apache2/*.log /home/meinefirma/www-log/*.log {
weekly
missingok
rotate 52
...
}

23.2. -
Apache , ,
-. HTML- PHP-,
. , Apache, , , Debian Ubuntu.
, . .
Ubuntu. Ubuntu
Apache , -
/var/www. /etc/apache2/sites-available/
default. , , (, ..).
# /etc/apache2/sites-available/default (Ubuntu)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
#
<Directory />

23.2. -

643

Options FollowSymLinks
AllowOverride None
</Directory>
# DocumentRoot
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
Allow from all
</Directory>
# CGI-
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order Allow,Deny
Allow from all
</Directory>
# ( localhost)
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order Deny,Allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
#
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<VirtualHost>

default ,
<VirtualHost>. <VirtualHost>
,
(-). default IP-,
- -,
.
/cgi-bin/ /doc/, ,
( , CGI-).


, ,
<VirtualHost> ,

644

23. Apache

, , ..
DocumentRoot , HTML-.
ServerAdmin
. , , .
, .
webmaster@hostname.
ServerSignatur , Apache
(, ,
..). Apache, . ServerSignatur=EMail
.
Loglevel , ,
-. emerg ( ,
Apache) debug ( , ).
, error warn.
ErrorLog ,
.
CustomLog . Apache
. ,
. http://httpd.apache.org/docs/2.2/de/mod/mod_log_config.html.
Ubuntu apache2.conf ,
combined common.
ErrorDocument , Apache . (, 404 not found
( )),
, . DocumentRoot. :
yy 400 Bad Request ( );
yy 401 Authorization Required ( );
yy 403 Forbidden ();
yy 404 Not Found ( );
yy 500 Internal Server Error ( ).
Apache http://www.w3.org/
Protocols/rfc2616/rfc2616-sec10.html.
ErrorDocument .
,
, ErrorDocument, .
Alias - ( DocumentRoot). , Alias /mytool/usr/

23.2. -

645

local/mytool , http://meinserver.de/mytool
/urs/local/mytool.

, alias <Directory> ( ). Alias


ScriptAlias, CGI-.


,
,
<Directory "//">.
.
DirectoryIndex , Apache ,
/ , , (
index.html). . ,
Apache ,
(, DirectoryIndex index.php index.html).
Options , . :
yy ExecCGI CGI;
yy FollowSymLinks ;
yy Includes ( mod_include);
yy Indexes , index.html;
yy MultiViews ( mod_negotiation).
Apache All. MultiViews. Ubuntu
:
Options FollowSymLinks, /var/www Options Indexes FollowSymLinks
MultiViews.
, , . , :
.
, . , Indexes
, index.html. ,
. MultiView ,
.
, .
AllowOverride , ,
, .htaccess. :

646
yy
yy
yy
yy
yy

23. Apache

AuthConfig ;
FileInfo ;
Indexes ;
Limit (Allow, Deny, Order);
Options .

Apache ,
. Ubuntu None (. /etc/apache2/
sitesavailable/default).


.
. <Directory> Order,
Allow Deny , Apache
.
,
<Directory> . , /, .
, !
OrderAllow, Deny , Allow,
Deny.
- , .
Order Deny, Allow .
:
, ! Apache .
Allowfrom , -, IP-, .
: Allow from 213.214.215.216 izvestniysait.ru.
IP- 213.214, 213.214.0.0/255.255.0.0,
213.214.0.0/16 ( 213.214.*.*). - sait.ru
www.sait.ru, sub.sait.ru .. Allow from all .
Denyfrom Allowfrom
, , .
/etc/apache2/sites-available/default:
/ Order, Allow Deny.
Order Deny,Allow, -
, !
/var/www, /usr/lib/cgi-bin /usr/share/doc, . - , .
-. Apache
, -
. 192.168.1.*
.sol, /var/www :

23.2. -

647

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Deny,Allow
Deny from all
Allow from 192.168.1
Allow from localhost
Allow from .sol
</Directory>

, Listen
IP- ( Debian/Ubuntu
/etc/apache2/ports.conf). , IP- . , : , IP- 192.168.1.17.
, Listen 192.168.1.17 , Apache
, . Listen
Apache,
.
. , ( ) 80 443 (HTTPS).
, Apache.
- . ,
Apache ,
. ,
. ,
( ). Apache ,
.
. , , ,
.
.
-,
-
(http://servername/directory/passwordfile). ,
/var/www-private. , , Apache www-data
.
, htpasswd -c (create ). , .
root# cd /var/www-private
root# htpasswd -c passwords.pwd username
New password: ********
Re-type new password: ********
Adding password for user username

648

23. Apache

/ htpasswd -c:
root# cd /var/www-private
root# htpasswd passwords.pwd name2
New password: ********
Re-type new password: ********
Adding password for user username

, Apache ,
.

Apache /etc/apache2/sites-available/default ( )
-/name ( ). .htaccess, -.
Apache ,
<Directory>. , , <Directory>, .
.
, . :
# /etc/apache2/sites-available/default (Ubuntu)
...
# ,
<Directory "/var/www/admin/">
AuthType Basic
AuthUserFile /var/www-private/passwords.pwd
AuthName admin"
Require valid-user
</Directory>

.
AuthType . Apache :
Basic Digest ( , ). Basic.
AuthUserFile .
AuthName (),
. , , ,
. AuthName, AuthName.
Require valid-user ,
. ,
:
Require user name1 name2

,
Apache, ,

23.3.

649

-. ,
.htaccess, .
, <Directory>,
AuthType, AuthUserFile, AuthName Require.

.
htaccess
, . () <Directory> AllowOverride,
AuthConfig AllowOverride All.

23.3.
- ()
, .
Apache
. , ,
.
, Apache ,
-. HTTP-, .
, . -,
HTTP-, Apache -.
, .
, IP-. IP-, , Apache .
: IP-, , , . ,
IP: , ,
IP- , (HTTPS).
( ),
IP-.
, . Apache
. ,
-.

(, ).
Debian
Ubuntu.
.
- Fedora RHEL, , , Apache, .

650

23. Apache

,
/etc/httpd/conf/httpd.conf.
.


Ubuntu - ( /var/
www) /etc/apache2/sites-available/default .
/etc/ apache2/ports.conf, , NameVirtualHost *:80. , Apache
, . * , Apache .
IP-, , ,
, NameVirtualHost.
, Debian Ubuntu
/etc/apache2/sites-available/default.
, , , ,
IP- .

,
, , , <VirtualHost>, NameVirtualHost. ServerName
. -,
Apache ! ServerAlias. , ServerName
www.mojserver.ru ServerAlias mojserver.ru,
www, .
# /etc/apache2/sites-available/primer-named-host (Debian/Ubuntu)
<VirtualHost *:80>
DocumentRoot /var/directory1/
ServerName www.firma-1.ru
ServerAlias firma-1.ru
...
</VirtualHost>

, IP-
IP-, IP- , IP-
IP- :
# /etc/apache2/sites-available/primer-IP-host (Debian/Ubuntu)
<VirtualHost 213.214.215.216:80>
DocumentRoot /var/directory2/
ServerName www.firma-2.com
...
</VirtualHost>
# /etc/apache2/sites-available/primer-port-host (Debian/Ubuntu)
<VirtualHost 213.214.215.216:12001>

23.3.

651

DocumentRoot /var/directory3/
ServerName www.admin-firma3.ru
...
</VirtualHost>

<VirtualHost> ,
.

, <VirtualHost>, ,
Apache. Ubuntu Apache
, 80 443 (
HTTPS
). /
etc
/
apache
2/
ports
.
conf
.
Apache
, ports.conf.
Apache http://httpd.apache.org/docs/2.2/
ru/vhosts/.


( ) ,
Debian/Ubuntu, , a2ensite a2dissite
. Apache :
root# a2ensite beispiel-named-host (Debian/Ubuntu)
root# service apache2 reload

a2dissite .
, /etc/apache2/sites-available/default
Apache!
, , sites-available/default, ,
.
Fedora RHEL a2ensite/a2dissite ,
httpd.conf.
:
root# service https reload (RHEL, Fedora)

, Debian/Ubuntu firma-123.ru firma123, , ,


.. .
, - firma123. C
/var/www-firma123
.
, (),
. ,
, firma123 !

652

23. Apache

root# adduser firma123


root# passwd firma123
Enter new UNIX password: ********
Retype new UNIX password: ********
passwd: password updated successfully
root# mkdir ~firma123/www
root# chown firma123:firma123 ~firma123/www
root# mkdir ~firma123/www-log
root# chown root:root ~firma123/www-log
root# chmod go-w ~firma123/www-log

sites-available,
, . firma123
, firma-123.ru
-. AllowOverride AuthConfig File
, .htaccess. , .
# /etc/apache2/sites-available/firma-123.ru
<VirtualHost * >
DocumentRoot /home/firma123/www/
ServerName firma-123.ru
ServerAlias www.firma-123.ru
ErrorLog /home/firma123/www-log/error.log
CustomLog /home/firma123/www-log/access.log combined
ServerAdmin webmaster@firma-123.ru
ErrorDocument 404 /not-found.html
<Directory "/home/firma123/www/" >
AllowOverride AuthConfig File
</Directory>
</VirtualHost>

:
root# a2ensite firma-123.ru
root# service apache2 reload

DNS-
. ,
. , - ,
www.firma-123.ru.
. , - Apache
, (www-data
Debian/Ubuntu, apache Fedora/RHEL, wwwrun SUSE). . -
, Apache .
Apache (,
PHP-), www-data/apache/wwwrun
(chmod g+w).

23.4.

653

().
.
. Apache (
Linux) . ,
( ) .
http://httpd.apache.org/docs/2.2/
vhosts/fd-limits.html.

. , DNS-
! firma-123.ru, , DNS- firma-123.ru IP-
-. DNS
. . , DNS
. ,
(
).
, DNS.
,
, . ServerName
ServerAlias <VirtualHost> IP-
, , , :
<VirtualHost 213.214.215.216:12001 >

Apache , 80 443 ( HTTPS). Apache


12001, /etc/apache2/ports.conf Listen12001. , service apache2 reload, Apache .
- . IP-
12001, , : http://213.214.215.216:12001.

23.4.
- HTTP. , (
), , , , .
HTTPS.
HTTPS (HTTP) (SSL). , HTTP . , Apache
HTTPS-.

654

23. Apache

,
. .
. (asymmetric encryption). , , (), ().
. , .
, , .
(-) (Apache)
( , , ) . , . (session key) .
, ,
, ,
.
, ,
, .
, , ?
, -, .
, .. , .
. , Internet Explorer
Firefox, , ( Verisign Thawte).
.
, , ,
. :
.
.
, , . . , . ,
,
, . , .

23.4.

655

, .
openssl. , , , . :
root# apt-get install openssl () yum install openssl

,
. ,
.
-, ,
. (
, , .)
root# openssl genrsa -des3 -out server.key 1024
...
Enter pass phrase for server.key: ******************
Verifying Enter pass phrase for server.key: ******************

, , . Apache,
Apache. . .
server.csr , .
: (root).
,
!
root# openssl rsa -in server.key -out server.pem
Enter pass phrase for server.key: ******************
writing RSA key
root# chmod 400 server.pem

, - .
, , ..
(Common Name).
, ,
.
(,
banking.ing-diba.de1), (www.amazon.de). , . ,
www.firma-abc.de firma-abc.de ( !).
,
openssl server.key.
root# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key: ******************
You are about to be asked to enter information that will be
incorporated into your certificate request.
1

- . . .

656

23. Apache

What you are about to enter is what is called a Distinguished


Name or a DN. There are quite a few fields but you can leave
some blank. For some fields there will be a default value,
If you enter '.', the field will be left blank.
----Country Name (2 letter code) [AU]: DE
State or Province Name (full name) [...]: .
Locality Name (eg, city) []: Berlin
Organization Name (eg, company) [Sample Ltd]: Max Muster
Organizational Unit Name (eg, section) []: .
Common Name (eg, YOUR name) []: www.firma-abc.de
Email Address []: webmaster@firma-abc.de
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: .
An optional company name []: .

. (
) .
.
30.
days1900 .
root# openssl x509 -req -days 1900 -in server.csr -signkey server.key \
-out server.crt
Signature ok
subject=/C=DE/L=Berlin/O=Max Muster/CN=www.firma-abc.de/
emailAddress=webmaster@firma-abc.de
Getting Private key
Enter pass phrase for server.key: ******************

, . ,
, openssl x509 -text.
:
root# ls -l
... 696 ... server.csr ( )
... 963 ... server.key ( )
... 887 ... server.pem ( )
... 936 ... server.crt ( )
root# cat server.crt
-----BEGIN CERTIFICATE----MIICWTCCAcICCQCL6ExhrQiELDANBgkqhkiG9w0BAQUFADBxMQswCQYDVQQGEwJB ...
-----END CERTIFICATE----root# openssl x509 -text -in server.crt
Certificate:
Data:
Version: 1 (0x0)
Serial Number:

23.4.

657

8b:e8:4c:61:ad:08:84:2c
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=DE, L=Berlin, O=Max Muster, CN=www.firma-abc.de/
emailAddress=webmaster@firma-abc.de
Validity
Not Before: Oct 28 14:03:18 2011 GMT
Not After : Jan 10 14:03:18 2017 GMT
Subject: C=DE, L=Berlin, O=Max Muster, CN=www.firma-abc.de/
emailAddress=webmaster@firma-abc.de
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:ed:1f:08:cb:f4:4d:ef:a6:f6:0a:be:b3:c2:92: ...
Exponent: 65537 (0x10001)
Signature Algorithm: sha1WithRSAEncryption
05:46:af:5c:12:84:28:59:e4:8f:db:2d:2d:0f:4a:3c:0e:84: ...

. , https://www.startssl.com/
cheapssls.com, .
, http://vash-website.ru, . . ,
. ,
. ( StartSSL).
, , StartSSL
CheapSSL, .
, . ,
, (,
). ,

.

. , , openssl. StartSSL
. StartSSL
, .
.
Firefox. ,
StartSSL .

Apache HTTPS
Mod_ssl. Apache, HTTPS, mod_ssl. Debian Ubuntu
, .

658

23. Apache

root# a2enmod ssl


root# service apache2 restart

Fedora RHEL SSL-:


root# yum install mod_ssl
root# service httpd restart

HTTPS. Apache
. Apache:
root# cp server.pem server.crt /etc/apache2

httpd.conf (Fedora, RHEL) VirtualHost


/etc/apache2/sites-available.
Debian Ubuntu (default-ssl ).
. , , ssl https (,
ssl.firma-abc.de).
, (HTTP), HTTPS.
IP-. (443 HTTPS, . VirtualHost).
SSLEngine on . SSLxxxFile , . SSLProtocol SSLCipherSuite
, SSL- , ,
.
, Apache , , , . ,
.
# , /etc/httpd/conf/httpd.conf (Fedora/RHEL)
# /etc/apache2/sites-available/ssl.firma-abc.de
<VirtualHost _default_:443>
ServerName www.firma-abc.de
DocumentRoot /var/www/
SSLEngine on
SSLCertificateFile /etc/apache2/server.crt
SSLCertificateKeyFile /etc/apache2/server.pem
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM
<Directory /var/www/>
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

23.4.

659

HTTPS- Apache . HTTPS- Debian/Ubuntu /etc/apache2/sites-available,


:
root# service httpd restart (Fedora/RHEL)
root# a2ensite ssl.firma-abc.de (Debian/Ubuntu)
root# service apache2 restart (Debian/Ubuntu)

SSL,
, . SSL- , restart, reload!
SSLCertificateChainFile SSLCACertificateFile.
SSLCertificate, Apache, , (Thawte, VeriSign).
, , ,
. , StartSSL. , ,
, .
, . , ,
.
SSLCertificateChainFile SSLCACerti
ficateFile, Apache .
.
, Apache ,
apache2/httpd reload.
...
SSLCertificateFile /etc/apache2/server.crt
SSLCertificateKeyFile /etc/apache2/server.pem
SSLCertificateChainFile /etc/apache2/sub.class1.server.ca.pem
SSLCACertificateFile /etc/apache2/ca.pem
...

, .
HTTPS-. HTTPS
, HTTPS-
IP-. IP-
VirtualHost. Apache
.

660

23. Apache

<VirtualHost 1.2.3.4:443>
ServerName www.noch-eine-firma.de
DocumentRoot /var/www-secure
SSLEngine on
...
</VirtualHost>

23.5. Awstats Webalizer


, , , , .

Awstats Webalizer. Apache.
.
. , Awstats
. .
, ,
.
Awstats, Webalizer
. , .
Webalizer , , , .


, , .
.
, . ,
, .

. Awstat Webalizer
Piwik Google Analytics (http://www.google.com/intl/
de/analytics/). JavaScript,
.
,
.

Awstats
Awstats , (,
) Apache.
/var/lib/awstats. , , , CGI-Perl,
:
http://vash-website.ru/awstats/awstats.pl;
http://vash-website.ru/awstats/awstats.pl?config=vtoraja-stranica.ru.

23.5. Awstats Webalizer

661

,
Cron-. , .
Awstats awstats! Awstat , Apache Awstat
CGI- Awstat. , ,
.

Awstats
, , , ,
Awstats Debian/Ubuntu Fedora/RHEL , . : Awstats ,

/etc/awstats. awstats. .conf, awstats.firma123.ru.conf.
- awstats.conf (Debian/
Ubuntu) awstats.model.conf (Fedora/RHEL):
root# cd /etc/awstats
root# cp awstats.conf awstats.firma123.ru.conf (Debian/Ubuntu)
root# cp awstats.model.conf awstats.firma123.ru.conf (Fedora/RHEL)

150,
. ,
:
:
# /etc/awstats/awstats.<hostname>.conf
...
LogFile="/home/firma123/www-log/access.log"
SiteDomain="firma123.ru"
HostAliases="localhost 127.0.0.1 firma123.ru"

Awstats .
, :
# /etc/awstats/awstats.<hostname>.conf
...
AllowFullYearView=3

, , , (
). , Awstats
.
Debian Ubuntu , , -,
:
root# mv /etc/awstats/awstats.conf /etc/awstats/awstats.conf.orig (Debian/
Ubuntu)

662

23. Apache

Awstats, /etc/awstats/awstats.conf.local.

Awstats Debian/Ubuntu
Debian/Ubuntu /etc/cron.d/awstats ,
/usr/share/awstats/tools/update.sh. ,
, /etc/awstats/awstats.*conf awstats.pl, Perl, , ,
Awstats. - awstats.conf
, (. ).
Apache - . (root) adm. Awstats, ,
www-data.
ubuntu|debian awstat permission denied
(ubuntu|debian awstat ),
,
.
Apache.
/var/log/apache2 www-data ,
.
root# chgrp -R www-data /var/log/apache2/
root# chmod 2755 /var/log/apache2/

, , logrotate www-data .
logrotate Apache:
# /etc/logrotate.d/apache2
...
create 640 root www-data

, , Awstats
, logrotate :
# /etc/logrotate.d/apache2
...
prerotate
if [ -x /usr/share/awstats/tools/update.sh ]; then
su -l -c /usr/share/awstats/tools/update.sh www-data
fi
endscript

, , , . Cron-
/etc/cron.d/awstats .
/var/cache/awstats/. -

23.5. Awstats Webalizer

663

,
Apache:
# /etc/apache2/hosts-available/firma123.ru
...
Alias
/awstatic
"/var/cache/awstats/kofler.info"
<Directory /var/cache/awstats/kofler.info>
Options +Indexes
</Directory>

Awstats .
.
, :
http://firma123.ru/awstatic/2012/09/awstats.firma123.ru.en.html

+Indexes .
, firma123.ru,
, , .
Awstats CGI-
awstats.pl. Apache ,
Apache :
# /etc/apache2/sites-available/default
...
Alias /awstatsclasses
"/usr/share/awstats/lib/"
Alias /awstats-icon/
"/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias
/awstats/ "/usr/lib/cgi-bin/"

Awstats :
http://hostname/awstats/awstats.pl;
http://hostname/awstats/awstats.pl?config=vtoraja-stranica.de.
,
.
cgi-bin. AuthXxx Directory
/etc/apache2/sites-available/ /usr/lib/cgi-bin!
Awstats Debian Ubuntu
: /usr/share/doc/awstats/README.Debian.gz.

Fedora/RHEL
Fedora Awstats, RHEL
. ,
. EPEL (
Enterprise Linux).
Awstats Fedora/RHEL Cron- /etc/cron.hourly/awstats , /usr/share/awstats/tools/
awstats_updateall.pl. Awstats

664

23. Apache

/etc/awstats/awstats.*conf, awstats.model.conf .
Awstats
.
, .
Apache ,
, Awstats.
Debian/Ubuntu, Awstats Apache. Fedora RHEL , , .
logrotate , Awstats
, . /etc/logrotate.d/httpd prerotate:
# /etc/logrotate.d/httpd
...
prerotate
/usr/bin/awstats_updateall.pl now -configdir=/etc/awstats/ \
--awstatsprog=/var/www/awstats/awstats.pl >/dev/null
endscript

Awstats
/etc/httpd/conf.d/awstats.conf. :
http://hostname/awstats/awstats.pl;
http://hostname/awstats/awstats.pl?config=vtoraja-stranica.de.

localhost. , Allow from 127.0.0.1
Allow from all. , , , Awstats
, , , . Directory
/usr/share/awstats/wwwroot AuthXxx,
.
# /etc/httpd/conf.d/awstats.conf
...
<Directory "/usr/share/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthType Basic
AuthUserFile /etc/httpd/awstat-passwords.pwd
AuthName "awsuser1 awuser2 ..."
Require valid-user
</Directory>

Awstats Fedora/RHEL
. -

23.5. Awstats Webalizer

665

Awstats, Cron- /etc/cron.daily,


/usr/share/awstats/tools/awstats buildstaticpages.pl
Perl. :
http://awstats.sourceforge.net/docs/awstats_tools.html.

Webalizer
Awstats
Webalizer. Awstats: , Webalizer
Cron, Apache
(.23.2). Awstats, . , , , .

.23.2. Webalizer

Webalizer
:
root# apt-get install webalizer (Debian/Ubuntu)
root# yum install webalizer (Fedora/RHEL)

Debian/Ubuntu
. Debian Ubuntu Webalizer *.conf

666

23. Apache

/etc/webalizer. - webalizer.conf.
,
, .
Webalizer /var/log/apache2/access.log.1
/var/www/webalizer.
, , Webalizer access.log.1,
access.log.
, Webalizer logrotate . (Cron
logrotate , Webalizer). logrotate Apache . Webalizer .
: logrotate ,
(daily weekly /etc/logrotate.d/apache2).
webalizer.conf access.log.
Incremental=yes,
Webalizer ,
.
# /etc/webalizer/webalizer.conf
...
LogFile=/var/log/apache2/access.log
Incremental=yes

, logrotate
Webalizer , :
# /etc/logrotate.d/apache2
...
prerotate
/etc/cron.daily/webalizer
endscript

Webalizer : http://hostname/webalizer/.
-, /var/www/webalizer, Webalizer.
,
, , Webalizer.
firma-123.ru,
firma123.
# /etc/webalizer/firma-123.ru.conf
#
LogFile /home/firma123/www-log/access.log
OutputDir /home/firma123/www/webalizer

23.5. Awstats Webalizer

667

#
ReportTitle firma-123.ru
HostName firma-123.ru
# Top-n
TopURLs 50
TopKURLs 30
TopReferrers 50
# Top-n
HideURL *.gif
HideURL *.jpg
HideURL *.png
# localhost, firma-123.ru
IgnoreSite localhost
IgnoreReferrer localhost
IgnoreReferrer firma-123.ru
IgnoreReferrer www.firma-123.ru

. TopXxx Top n ... URLs, Top n ... URLs by kByte


Topn... referrers. . HideURL
, Topn . Ignore ,
.
Webalizer , , , /home/firma123/www/webalizer:
root# mkdir /home/firma123/www/webalizer
root# chown firma123:firma123 /home/kofler/www/webalizer

, ( firma123), .htaccess.

Webalizer Top n ... referrers ,


Apache . Apache
/etc/apache2/ sites-available/* CustomLog combined (
common)!

Fedora/RHEL
Fedora/RHEL Webalizer /etc/
webalizer.conf. /var/www/usage ,, : http://hostname/usage.
,

Webalizer, Cron Webalizer.
, Debian Ubuntu,
Webalizer logrotate. ,

668

23. Apache

webalizer /etc/cron.daily/00webalizer, Webalizer ,


logrotate. (Cron cron.daily .)

23.6. PHP
-. Apache
-. . Apache
, ,
(,
,
, ..).
PHP. - , Perl Java. Linux/UNIX
PHP . PHP http://www.php.net/.
PHP , *.php , HTML, PHP. PHP
<?php ?>.
, PHP, Apache
PHP. PHP-. HTML-. PHP
Apache, , , . , PHP-,
HTML- ( Microsoft ASP
Active Server Pages, ).
Hello World!
PHP. -
PHP. PHP-
HTML, :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//RU">
<html><head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<title> PHP</title>
</head><body>
<p> :
<?php echo date(G:i:s); ?>
</p>
</body></html>

. PHP Apache, ,
,
php5. , :

669

23.6. PHP

Apache, PHP ,
. ,
php5, php5-common, libapache2-mod-php5.
Apache,
, - PHP.
. PHP
php.ini. , , . :
Debian, Ubuntu /etc/php5/apache2/php.ini, /etc/php5/apache2/conf.d/*.ini;
Fedora, Red Hat /etc/php.ini, /etc/php.d/*.ini;
SUSE /etc/php5/apache2/php.ini.
. , PHP, phptest.php, :
<?php phpinfo(); ?>

DocumentRoot , Apache
. PHP, , ,
. ( x) .
http://localhost/phptest.php
(.23.3). ,
Apache PHP (
).

.23.3. PHP

670

23. Apache

. PHP PHP-, , , ,
- (, /srv/www/htdocs/
phpinfo.php).
Apache PHP. -
http://!
Apache. Apache ,
PHP ?
- , ,
, .
Apache (, ), . .

23.7. FTP- (vsftpd)


- FTP-, : -, , ; -, , ,
.
. FTP .
. ,
FTP-
. ,
, !
, FTP .
SSH- SFTP (Secure FTP),
. ,
, :
, SFTP, FTP,
, .
WebDAV, HTTP
. , Apache WebDAV mod_dav.
http://httpd.apache.org/docs/2.2/mod/mod_dav.html.
FTP-, FTP-.
. FTP .
.
Vsftpd. FTP-.
vsftpd. . vsftpd very secure FTP daemon ( -

23.7. FTP- (vsftpd)

671

FTP). very secure ,


FTP- FTP.
. vsftpd :
, Init-V, xinetd.
.
vsftpd.conf listen=YES.
FTP-, ,
.
. vsftpd /etc/vsftpd.conf
/etc/vsftpd/vsftpd.conf. FTP-
. , FTP , . , FTP
, ,
locale_enable YES. FTP
, write_enable YES.
vsftpd.conf tcp_wrappers=Yes, vsftpd /etc/hosts.allow /etc/hosts.deny (.26.2).
vsftpd.conf:
# /etc/vsftpd.conf /etc/vsftpd/vsftpd.conf
...
local_enable=YES / NO
# FTP-
write_enable=YES / NO
#
...
anonymous_enable=YES / NO
# FTP
anon_upload_enable=YES / NO # ,
# FTP
...
listen=YES / NO
# Init-V-Damon (YES)
# xinetd (NO)
tcp_wrapper=YES / NO
# hosts.allow hosts.deny

FTP. FTP .
ftp localhost, , .
, root, , FTP-.

FTP
vsftpd.conf FTP, vsftpd anonymous ftp .
, vsftpd .
FTP- Linux ftp. /etc/
passwd:
Debian, Ubuntu /home/ftp;
Fedora, Red Hat /var/ftp/;
SUSE /srv/ftp/.

672

23. Apache

FTP. FTP, , FTP , , /var/ftp/upload Fedora Red Hat.


FTP
:
root# mkdir /var/ftp/upload
root# chown ftp upload
root# chmod 730 upload

, , , .
, upload.
, FTP
.

FTP

, , (root)
, daemon, lp nobody,
FTP. , , .
Fedora Red Hat .
, vsftpd PAM (
). PAM /etc/pam.d/vsftpd, etc/vsftpd/ftpusers. ,
FTP.
C , FTP
, /etc/vsftpd.user_list, .
vsftpd.conf userlist_enable=YES userlist_
deny=YES ( ).
Debian, SUSE Ubuntu vsftpd PAM.
/etc/pam.d/vsftpd /etc/ftpusers. , FTP.

24

MySQL

MySQL
. , -, MySQL-. ,
phpBB, , TYPO3,
, Bugzilla.
, MySQL-
.
, , SQL
.
.

24.1. MySQL
, Oracle IBM DB/2,
MySQL , . MySQL,
: http://dev.mysql.com.
. MySQL,
GPL. MySQL
( )
. ,
, GPL MySQL, MySQL-. MySQL
http://www.mysql.com/about/legal/.
2010 Oracle Sun MySQL. . ,
, Oracle .
-. MySQL-, -
MySQL, MariaDB (http://askmonty.org/)
, - MySQL, Percona

674

24. MySQL

(http://www.percona.com), Percona, MySQL.


, .
openSUSE MariaDB ,
openSUSE MySQL.


MySQL. , , ,
. ,
:
Debian, Ubuntu mysql-client, mysql-common, mysql-server;
Fedora, RHEL mysql, mysql-server;
SUSE mysql-community-server, mysql-community-server-client.
Fedora , MySQL:
root# yum groupinstall mysql

/. MySQL ,
. , , -.
8.5. Init-V mysql
mysqld.
MySQL /var/lib/
mysql. /var/log/syslog (Debian,
Ubuntu), /var/lib/mysql/- (SUSE) /var/log/mysql*.
. MySQL /etc/
my.cnf /etc/mysql/my.cnf (Debian, Ubuntu).
.
, ,
.
,
[]. [mysqld], . , ,
MySQL. .
old_passwords=1 MySQL
, MySQL4.0 . ,
,
MySQL.
MySQL.
MySQL, old_passwords=0

24.1. MySQL

675

my.cnf , - ! , MySQL.
MySQL http://dev.mysql.com/doc/refman/5.1/en/password-hashing.html.
bind-address=127.0.0.1
MySQL ( -
, ).
MySQL (, PHP), . Debian
Ubuntu ,
, .
skip-networking MySQL, , . ,
, bind-address=127.0.0.1.
, MySQL
-, , , PHP . ,
MySQL- TCP/
IP (, Java), MySQL-!
bind-address=127.0.0.1.


Debian Ubuntu MySQL
. Linux, MySQL .
, Debian Ubuntu debian-sys-main, , /etc/mysql/debian.cnf,
Linux. /etc/mysql/debian-start,
MySQL, , debiansys-main
!
debian.cnf.
Fedora, Red Hat SUSE MySQL
, ,
root, MySQL.
:
user$
mysql>
mysql>
mysql>

mysql -u root
UPDATE mysql.user SET password=PASSWORD('xxx') WHERE user='root';
FLUSH PRIVILEGES;
exit

SQL mysql,
:
user$ mysql -u root -p
Enter password: ******

676

24. MySQL

, Linux MySQL, .
Linux MySQL . MySQL
, ,
Linux.

MySQL
MySQL root . . ,
MySQL .
,
.
, ,
mysql. SELECT user . DELETE
. FLUSH PRIVILEGES .
user$ mysql -u root -p
Enter password: *******
mysql> SELECT user, host, password FROM mysql.user;
+------+----------------+-------------------------------------------+
| user | host
| password
|
+------+----------------+-------------------------------------------+
| root | localhost | *AFCF054603403E6863B8DCFC1BEAC269746E8720
|
| root | <hostname> | *AFCF054603403E6863B8DCFC1BEAC269746E8720
|
| root | 127.0.0.1 | *AFCF054603403E6863B8DCFC1BEAC269746E8720
|
| root | ::1
| *AFCF054603403E6863B8DCFC1BEAC269746E8720
|
|
| localhost |
|
|
| <hostname> |
|
+------+----------------+-------------------------------------------+
mysql> DELETE FROM mysql.user WHERE user='';
mysql> FLUSH PRIVILEGES;
mysql> exit


.
MySQL, SQL,
. , .
, , mydatabase
newuser,
. mysql.
, shell Linux: MySQL, MySQL- , , .
MySQL .
user$ mysql -u root -p
Enter password: ******

24.2. MySQL

677

...
mysql> CREATE DATABASE mydatabase;
mysql> GRANT ALL ON mydatabase.* TO newuser@localhost
IDENTIFIED BY 'xxxxxxxxx';
mysql> exit

newuser
. Linux, MySQL root.
.
newuser (CREATE TABLE), (INSERT) ,, (SELECT).
id: MySQL , ,
.
user$ mysql -u newuser -p
Enter password: ******
mysql> USE mydatabase;
mysql> CREATE TABLE mytable (
id INT NOT NULL AUTO_INCREMENT,
txt VARCHAR(100),
n INT,
PRIMARY KEY(id));
mysql> INSERT INTO mytable (txt, n) VALUES('abc', 123);
mysql> INSERT INTO mytable (txt, n) VALUES('efgsd', -4);
mysql> INSERT INTO mytable (txt, n) VALUES(NULL, 0);
mysql> SELECT * FROM mytable;
+----+-------+------+
| id | txt
| n
|
+----+-------+------+
| 1 | abc
| 123 |
| 2 | efgsd | -4 |
| 3 | NULL
|
0 |
+----+-------+------+
mysql> exit

24.2. MySQL
MySQL.
mysql, mysqldump,
. ,
, , . .
mysqldump mylvmbackup,
.
MySQL 24.3.

678

24. MySQL

Mysql. mysql MySQL ( mysqld ), .


MySQL-, SQL-.
SELECT,
.
mysql , , -u
MySQL. -p . MySQL , -h. ,

SQL-.
user$ mysql -u root -p mojabazadannyh
Enter password: *******

SQL-,
. mysql status,
, ,
MySQL-. Ctrl+D
.
mysql> status
mysql Ver 14.14 Distrib 5.5.22, for debian-linux-gnu (x86_64) using readline 6.2
...
Connection id: 48097
Server version: 5.5.22-0ubuntu1 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 7 days 13 hours 31 min 33 sec
...

UTF-8. , mysql MySQL -1 (latin1).


, UTF-8.
SQL:
mysql> SET NAMES utf8;


. MySQL .
, .
Mysql . , ,
, mysql SQL- *.sql.

24.2. MySQL

679

user$ mysql -u root -p mojabazadannyh < kommandos.sql


Enter password: *******

Mysqladmin
Mysqladmin
. mysqladmin
SQL (, CREATE DATABASE). mysqladmin ,

.
mysql, u , h - ( localhost). -p
, .
, -ppassword ( -p).
, :
. ,
MySQL
debian-sys-maint, Debian Ubuntu.
/etc/mysql/debian.cnf
Linux. mysqladmin :
root# mysqladmin --defaults-file=/etc/mysql/debian.cnf kommando ...

, mysqladmin,
mysqladmin --help. :
, MySQL, MySQL- ().
user$
Enter
user$
...
user$
...

mysqladmin -u root -p create


password: *******
mysqladmin -u root -p extended-status
mysqladmin -u root -p processlist

MySQL Workbench
MySQL Workbench MySQL,
(.24.1). MySQL-, ,
, , ,
..
MySQL Workbench
. RHEL.
MySQL Workbench , Red Hat, MySQL: http://dev.mysql.com/downloads/workbench.

680

24. MySQL

.24.1. MySQL Workbench

PhpMyAdmin
, MySQL
phpMyAdmin. , . phpMyAdmin . ,
MySQL - .
phpMyAdmin.
, phpMyAdmin http://www.
phpmyadmin.net/home_page/ PHP- ,
- Apache.
Debian, Ubuntu. phpMyAdmin Debian
Ubuntu , /etc/
phpmyadmin. - Apache, apache.conf /usr/share/phpmyadmin
-. . ,
apache.conf, , ,
phpMyAdmin, .
Apache.conf Apache /etc/apache2/conf.d. phpMyAdmin
HTTPS,
HTTPS Include apache.conf:

24.2. MySQL

681

<VirtualHost _default_:443>
...
Include /etc/phpmyadmin/apache.conf
</VirtualHost>

. phpMyAdmin config.inc.
php. , phpMyAdmin.
MySQL,
phpMyAdmin . http://www.phpmyadmin.net/documentation/#linked-tables.
phpMyAdmin. phpMyAdmin
. ,
phpMyAdmin. MySQL
, MySQL- ! , :
MySQL,
phpMyAdmin;
phpMyAdmin , .
http://mysite.ru/pMa1 , http://mysite.ru/phpmyadmin;
phpMyAdmin HTTPS, HTTP;
phpMyAdmin Apache , ,
.htaccess (. 23.2).

Chive
phpMyAdmin ,
. ,
( Debian Ubuntu
phpMyAdmin). , phpMyAdmin - .
Chive (http://www.chive-project.com/) phpMyAdmin (.24.2).
Chive phpMyAdmin ,
.
Chive phpMyAdmin. ,
.
. , Chive
. Ubuntu, Personal Package
Archive (PPA, ), Chive. ,
, . .
Chive TAR- , Apache.

682

24. MySQL

.24.2. MySQL Chive

, Apache
. Debian Ubuntu :
root# cd /var/www/
root# wget -O http://www.chive-project.com/Download/Redirect|tar -xzp
root# chown -R www-data chive

Chive :
http://mysite.ru/chive/index.php

. , Chive
. Chive
, phpMyAdmin (. ). Chive
, HTTPS MySQL,
!

24.3.
MySQL, ,
, ,
MySQL. , . mysqldump mylvmbackup.
,
, , ()
. , ,
. .
.
MySQL , , , MySQL

24.3.

683

. ( )
. . MyISAM InnoDB. (,
, ).
.
, MySQL- ,
mysql SQL-. . table_schema ,
engine .
mysql> SELECT table_schema, table_name, engine
FROM information_schema.tables
WHERE table_type='BASE TABLE'
ORDER BY table_schema, table_name;
table_schema table_name engine
----------------------------------mylibrary authors InnoDB
mylibrary categories InnoDB
mylibrary counters MyISAM
mylibrary fulltitles MyISAM
mylibrary languages InnoDB
...

Mysqldump
mysqldump, MySQL,
MySQL SQL-. mysql .
:
user$ mysqldump -u root -p [] > backup.sql


(. mysqldump --help).
, , , MySQL (MyISAM InnoDB).
MyISAM. MyISAM
--lock-all-tables. mysqldump LOCK
.
mysqldump (
, ).
, .
user$ mysqldump -u root -p --lock-all-tables myisam-db > backup.sql

684

24. MySQL

InnoDB. InnoDB.
--skip-opt , MyISAM. --single-transaction
. ,
, , . --disable-keys
. , .
--create-options, mysqldump MySQL CREATE-TABLE.
--quick, mysqldump
, .
. --extended -insert
mysqldump INSERT, .
, -, ,
-, .
--add-drop-table mysqldump CREATETABLE DROP-TABLE. ,
- . ,
.
user$ mysqldump -u root -p --skip-opt --single-transaction \
--disable-keys --create-options --quick \
--extended-insert --add-drop-table inno-db > backup.sql

, ,
MyISAM, InnoDB.
mysqldump . , ,
. ,
, . mysqldump
. (. mylvmbackup ).
( ), --all-databases.
. ,
mysqldump (stored procedure), .
,
--routines --triggers.
.
, ( ). mysql . -default-character-set , , UTF-8,
.

24.3.

685

user$ mysqladmin create dbname


user$ mysql -u root -p --default-character-set=utf8 dbname < backup.sql

. ,
mysqldump, - . ,
, .
:
user$ mysqldump [] dbname | gzip -c > backup.sql.gz
user$ gunzip -c backup.sql.gz | mysql [] dbname

gzip .
,
lzop, :
user$ mysqldump [] dbname | lzip -c > backup.sql.lzo
user$ lzop -c -d backup.sql.lzo | mysql [] dbname

Mylvmbackup
mysqldump .
. MyISAM , InnoDB . , ,
.

,
. InnoDB
, , , MySQL.
,
mylvmbackup . Mylvmbackup
, . ,
(
!). , (Logical Volume, LVM).
mylvmbackup Perl . ,
http://www.lenzg.net/mylvmbackup/.
. , (.14.15). ,
.

.

686

24. MySQL

.
, .
. . C
LVM . , ,
.
Mylvmbackup LVM,
/var/lib/mysql. .
SQL FLUSH TABLES WITH READ LOCK MyISAM , , .
, MySQL- LOCK, .
lvcreate s LVM
. /var/lib/
mysql.
SHOW MASTER STATUS ,
.
backup-pos/*_mysql.pos. ,

.
UNLOCK TABLES MyISAM. MySQL
. ( InnoDB , .)
LVM
/var/lib/mysql TAR-. . ,
.
, TAR- /etc/mysql/my.cnf.
, LVM ,
.
:
InnoDB. , InnoDB .
InnoDB Masterspace-, ,
InnoDB. ,
Masterspace . , ,
. ,
.

24.3.

687

Masterspace InnoDB . LVM.



mysqldump. -,
, , , .. -,
. ,
MySQL ( ), .
. /etc/mylvmbackup.conf.
. , /var/lib/mysql LVM-
/dev/vg1/mysql.
# /etc/mylvmbackup.conf
[mysql]
user = root
password = *******
host = localhost
port = 3306
socket =
mycnf = /etc/mysql/my.cnf
[lvm]
vgname = vg1
lvname = mysql
backuplv =
lvsize = 5G
[fs]
xfs=0
mountdir
backupdir
relpath

= /var/cache/mylvmbackup/mnt/
= /var/cache/mylvmbackup/backup/
=

[tools]
... ( , )
[misc]
backuptype =
prefix =
tararg =
tarsuffixarg =
rsyncarg =
datefmt =
innodb_recover =
pidfile =

tar
backup
cvzf
-avWP
%Y%m%d_%H%M%S
1
/var/tmp/mylvmbackup_recoverserver.pid

. vgname lvname
VG ( ) LV ( ).
LVM /dev/vgname/lvname. backuplv

688

24. MySQL

.
mysql_snapshot. lvsize
. ,
MySQL,
. ,
5. , mylvmbackup , . ,
.
backupdir , mylvmbackup
. , ,
/var/lib/mysql. relpath , /var/lib/mysql
, .
/var/lib/mysql , relpath .
, , /var, relpath=lib/mysql/.
innodb_recover , Masterspace- InnoDB
. , InnoDB, , , Masterspace. , , , ,
.
. :
root# mylvmbackup
20101128 14:50:23
20101128 14:50:23
20101128 14:50:23
20101128 14:50:23
File descriptor 3
Logical volume
20101128 14:50:24
20101128 14:50:24
20101128 14:50:24
20101128 14:50:24
...

Info: Connecting to database...


Info: Flushing tables with read lock...
Info: Taking position record...
Info: Taking snapshot...
left open
"mysql_snapshot" created
Info: Unlocking tables...
Info: Disconnecting from database...
Info: Mounting snapshot...
Info: Recovering innodb...

/var/cache/mylvmbackup/backup *.tar.gz,
.
my.cnf,
( backup-pos/*.pos).
. , . tar- . ,
backup. /var/lib/mysql (
backup). tar-
backup-pos/* /etc/mysql.
root# /etc/init.d/mysql stop
root# rm -rf /var/lib/mysql/* () mv /var/lib/mysql/* /bak/

24.3.

root#
root#
root#
root#
root#

689

mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
tar -x -f backup.tar.gz -C /var/lib/mysql --strip 1 backup
tar -x -f backup.tar.gz -C /etc/mysql --strip 1 backup-pos
mv /etc/mysql/backup-*_my.cnf /etc/mysql/my.cnf
/etc/init.d/mysql start



, mysqldump,
.
, .
/etc/mysql/my.cnf MySQL-.
# /etc/mysql/my.cnf
log_bin = /var/log/mysql/mysql-bin.log

MySQL- ,
. (mysql-bin.000001,
.000002 ..). , (, rsync).
,
.
mysqlbinlog , .
:
root# mysqlbinlog --start-position=<p> mysql-bin.<n> | mysql -u root -p
root# mysqlbinlog mysql-bin.<n+1> | mysql -u root -p
root# mysqlbinlog mysql-bin.<n+2> | mysql -u root -p
..

, ,
(<n>), , (<p>) . , mylvmbackup . , ,
/etc/mysql/*_msql.pos:
root# less /etc/mysql/backup-20101128_145023_mysql.pos
Master:File=mysql-bin.000016
Master:Position=98
...

. , , . MySQL- . ,
,
. MySQL MySQL: http://dev.mysql.com/doc/refman/5.5/en/replication.html.

25

. . ,
.
, (//
), ( , , ) .

25.1.


Time Machine, Apple ,
. Linux
.
,
, ,
. Gnome KDE .
.
Dj Dup https://launchpad.net/deja-dup;
Grsync http://www.opbyte.it/grsync/;
Back in Time http://backintime.le-web.org/.
Dj Dup:
Fedora Ubuntu .
Grsync
,
.

, !
, ,
.

25.1.

691

Dj Dup
Dj Dup ,

, SSH. Ubuntu Dj Dup , . Fedora
Gnome
(Backup).
. Dj Dup : Storage
(), Folders () Schedule (). Save () , . ,
(Local
Folder), .
,
. FTP-, , SSH, WebDAV,
Windows Samba.
Folders () , .
,
Downloads. (, , VirtualBox).
Schedule () ,
(, , ..)
Dj Dup
. , Dj Dup
,
. : , .
.
, ,
.
Always (),
.
At Least Three Months ( ),
, , ,
.
Overview () .
(Backup
Now), Automatic Backups (
).
.
, , ,
( ). ,

692

25.

!
, Dj Dup,
.
, .

Dj Dup AmazonS3. Ubuntu


. , pythonboto. Dj Dup Ubuntu.
Ubuntu-One.
,
, (
).

. Recovery ()
.
,
.
,
Backup (
). Nautilus
. . ,
, ,
.
Dj Dup
, Duplicity.
Python. , ,
Dj Dup , , Duplicity.

Grsync

Grsync.
Grsync (.25.1).
, Grsync
. .
.
.
.
, Grsync . ,
- , . -

25.1.

693

,
( ). ,
, .
, Grsync
, . , .

.25.1. Grsync

Grsync
, 1:1. .

Back In Time
Back In Time .
Gnome, KDE
. Back in Time . Alt+F2 backintime-kde backintime-gnome.
.
General (). , ( ,
). ,
.
.

694

25.

, ,
. , Every hour () Every
day (). None ().
. , , , .
Include (). , -

.
. ,
.
Exclude (). , ()
(, ). ,

Back in Tine ,
. ,
(, ~/.thunderbird ,
Thunderbird ).
Auto-remove ( ).

, , . Smart
remove ( ). . , ,
. , ,
.
Options () Expert Options ( ).

. , , .
Back in Time.
( , ),
.
.
, , , ,
. Recover () , .
Copy () .
.
Back in Time .
, (root).
Gnome, KDE .
. Cron. backintime.

25.2. NAS-

695

~/.config/backintime/config.
Back in Time ! Cron /var/spool/cron/tabs/
.
. ( , ). , ,
(hard link).
. , ( FAT-).

25.2.
NAS-
,
.
,
.
NAS-. NAS Network Attached Device ( ).
, .
NAS-, ,
Linux, Samba -,
-.
NFS-, FTP-, AFP- ( Apple), SSH, (Multimedia Streaming),
..


Windows
NAS- Linux-,
Samba Windows,
. .
, Linux, , , , UNIX Linux. Windows
, UNIX. , Linux, , Windows.
.

Windows, Linux.

696

25.

,
/etc/fstab.
Linux , , TAR.
Dj Dup .
,
Windows. rsync Grsync. , ( , Execute
).
, Windows, Samba,
POSIX CIFS ( ). , , ,
NAS Samba.
, NAS- NFS- Rsync. .

Mount /etc/fstab
,
NAS- mount /etc/
fstab. , NAS- . 20.7.
, NAS- .

Windows
Gnome
mount /etc/fstab,
Gnome.
FileConnect with Server ( ), Windows Share ( Windows), - , ,
, .
, Enable bookmarks ( ),
.
Locations (), Gnome.
Connect (),
Windows. Gnome .

25.3.

697

Gnome GVFS
( Gnome). .gvfs. Nautilus
, ,
, . ,
Dj Dup
, Grsync .gvfs.

25.3.
,
. tar, zip, rsync, rdiff-backup, rsnapshot ..
. .25.1.
25.1.

gzip

gunzip

bzip2

( , gzip, )

bunzip2

xz

( , bzip2,
)

unxz

lzop

/ , gzip

tar

zip

Windows- ZIP-

unzip

zip-

zipinfo

ZIP-

(gzip, bzip2, xz, lzop)


Gzip gunzip. Gzip , name.gz. gunzip . LZ77 ,
( - ). , , ,
, .
:
user$ ls -l filesystem.tex
... 178794 1. Aug 17:43 filesystem.tex
user$ gzip filesystem.tex
user$ ls -l filesystem.tex.gz
... 57937 1. Aug 17:43 filesystem.tex.gz
user$ gunzip filesystem.tex.gz

698

25.

Bzip2 bunzip2. bzip2 bunzip2 gzip/gunzip.


, . , ,
.bz2.
user$ bzip2 filesystem.tex
user$ ls -l filesystem.tex.bz2
... 47105 1. Aug 17:43 filesystem.tex.bz2
user$ bunzip2 filesystem.tex.bz2

Xz unxz. gzip bzip2 xz.


, . ,
.
, 7zr p7zip.
Lzop. lzop.
, . ( 50% ,
gzip). lzop , ,
,
. ,
.
cat lzop. ,
.
root# cat /dev/vg1/lv3 | lzop -c > lv3.img.lzo (55 )
root# cat /dev/vg1/lv3 > lv3.img (50 )

(tar, zip)
Tar. tar Linux . gzip bzip2. tar ,
( ) .
, .
buch
buch.tgz.
user$ tar -czf mojarchiv.tgz buch/

.
c create (), tar .
z zip (). , gzip.
f file (). tar (
). .
.tar.gz .tgz.

699

25.3.

tar -tzf . . less


, less
name.tgz.
user$ tar -tzf mojarchiv.tgz
linuxbuch/
linuxbuch/lanserver.tex
linuxbuch/security.tex~
linuxbuch/buch.tex
linuxbuch/u4.txt~
...

tar -xzf
.
user$ cd drugaja-papka/
user$ tar -xzf mojarchiv.tgz

tar TEX-.
. , !
user$ tar -xzf mojarchiv.tgz '*.tex'

bzip2,
gzip, z j.

Zip. Linux/UNIX TAR


.
Windows, ZIP-.
mojarchiv.zip HTML-, :
user$ zip mojarchiv.zip *.html

, -r:
user$ zip -r mojarchiv.zip mojwebsite/

ZIP-, zipinfo:
user$ zipinfo mojarchiv.zip
Archive: test.zip 143677915 bytes
-rw-r--r-- 2.3 unx 78039 tx defN
-rw-r--r-- 2.3 unx 115618 tx defN
-rw-r--r-- 2.3 unx
3899 tx defN
-rw-r--r-- 2.3 unx
752 tx defN
...

1899 files
10-Jul-06 11:27
7-Apr-05 15:58
28-Jul-06 16:38
11-Feb-04 12:06

unzip:
user$ cd drugaja-papka/
user$ unzip mojarchiv.zip

linuxbuch/lanserver.tex
linuxbuch/security.tex~
linuxbuch/buch.tex
linuxbuch/u4.txt~

700

25.

25.4. (rsync)
rsync . ,
. ( )
. rsync , (, )
.
rsync .
SSH. .
shell-
rsync-.
.25.2 , . .25.3
rsync.
25.2. rsync

file1 file2

directory

host:dir

host

user@host:dir

, SSH user

rsync://user@host/dir

rsync-

rsync://user@host:port/dir

Rsync-
25.3. rsync

-a --archive

--delete

-D

--exclude=pattern

-g --group

-l --links

-o --owner

-p --perms

-r --recursive

-t --times

-u --update

-v --verbose

-W --whole-file

-z

, SSH

. ,
, -a, -

25.4. (rsync)

701

(-rlptgoD). ,
( ,
, ..).
dir2 , . cp, , .
user$ rsync -a dir1/ dir2/

rsync , , , . , ,
dir1, dir2, --delete. , :
,
!
. rsync
hostname: directory, username@hostname:directory. rsync
.
, dir1 username
saturn.sol dir2 mars.sol.
ssh. (, username
mars.sol.)
username@saturn.sol$ rsync -e ssh -az dir1/ mars.sol: dir2/
username@mars.sol's password: ******

rsync .
:
username@saturn.sol$ rsync -e ssh -az mars.sol:dir2/ dir3/
username@mars.sol's password: ******

rsync , , , .
, ,
. -, SSH
.
.
Rsync-. Rsync SSH,
,
rsync rsync- . ,
rsync-.
/etc/rsyncd.conf. rsync-
rsync- 873.
.
rsync- ,
(

702

25.

) (http://unix.stackexchange.com/questions/26182/ http://
serverfault.com/questions/100707/rsync-daemon-is-it-really-useful).

25.5.
(rdiff-backup)
rsync rdiff-backup.
rsync , rdiffbackup .
, ( ). , rdiff-backup
. , , . rdiff-backup , Time Machine AppleOSX
.
. rdiff-backup . , .
root# rdiff-backup /home /home-backup

rdiff-backup rdiff-backupdata.
. , increments ,
.
(.diff), .
.
, filename.2010-04-03T08:37:58+02:00.diff.gz.
.
, /home-backup. /home
, .
( rdiff-backup-data
,
cp -a rsync -a --delete.) . ,
rdiff-backup. -r now. , , .
root# rdiff-backup -r now /home-backhup /tmp/home-actual


, . .diff-
( ), . ,
rdiff-backup.
/home , :

25.5. (rdiff-backup)

703

root# rdiff-backup -r 10D /home-backup/ /tmp/home-historic

(, 2010-12-31), (h), (D),


(W) .. . Time Formats ( )
man rdiff-backup. , , , .
. , :
root# rdiff-backup -r 10D /home-backup/file file-historic
root# rdiff-backup -r 10D /home-backup/dir/ dir-historic

. rdiff-backup,
. , , :
root# rdiff-backup --remove-older-than 4M --force /home-backup/

, ,
.
( ):
root# rdiff-backup --remove-older-than 3B --force /home-backup/

.
, , . rdiff-backup , .
rdiff-backup, rsync,
. SSH.
rdiff-backup .
,
rsync. , -
:
root# rdiff-backup user@firma-abc.de::/home /home-backup

rdiff-backup
http://www.nongnu.org/rdiff-backup/.
Duplicity. rdiff-backup ,

SSH FTP , Duplicity,
Python (http://duplicity.nongnu.org/). rdiff-backup, TAR-. ,
Duplicity -. , Dj Dup,
.
.

704

25.

25.6.
(rsnapshot)
rsync rsnapshot, Perl
.
rdiff-backup, ,
. ,
( ) , rdiff-backup.
.
rsnapshot , . rsnapshot
, , SSH.
, rsnapshot.
: rsnapshot .

, SSH rsync.

rsnapshot ,
/etc/rsnapshot.conf.
. -, (,
/directory/, /directory). -, ( )!
, rsnapshot, . ,
, snapshot_
root, backup interval.
Snapshot_root ,
. /var/cache/rsnapshot,
rsnapshot.
Backup , . backup ( ),
.
backup :
# /etc/rsnapshot.conf
...
backup /home/ localhost/
backup /etc/ localhost/

/home/user/Mail mars.sol, SSH,


cmd_ssh. backup , -,

25.6. (rsnapshot)

705

, . ,
/home/user/.ssh/authorized_keys mars.sol SSH-, . . : , /root/.ssh,
!
# /etc/rsnapshot.conf
...
cmd_ssh /usr/bin/ssh
...
backup user@mars.sol:/home/user/Mail/ mars.sol/

LVM, , ,
.. ,
man rsnapshot.
Interval ,
. :
# /etc/rsnapshot.conf
...
interval hourly 6
interval daily 7
interval weekly 4
#interval monthly 3

, rsnapshot hourly,
. ,
, rsnapshot daily,
rsnapshot weekly. monthly
.
interval hourly6 , rsnapshot
hourly , ( /etc/
cron.d/rsnapshot).
rsnapshot hourly , interval hourly24.
.
rsnapshot ( ). . , .


rsnapshot ( ).
:
root# rsnapshot daily

706

25.


:
/var/cache/rsnapshot/<inverval.n>/<hostname>/<directory>

interval ( hourly, daily, weekly


monthly). n (0 , 1 , , 2 , ..). hostname ,
(localhost ).
/etc ( ) :
/var/cache/rsnapshot/hourly.0/localhost/etc

/home/user/Mail mars.sol (
) :
/var/cache/rsnapshot/monthly.0/mars.sol/home/user/Mail


,
rsnapshot Cron /etc/cron.d/rsnapshot.

Cron:
# /etc/cron.d/rsnapshot
0 */4 * * * root
30 3 * * * root
0 3 * * 1 root
30 2 1 * * root

/usr/bin/rsnapshot
/usr/bin/rsnapshot
/usr/bin/rsnapshot
/usr/bin/rsnapshot

hourly
daily
weekly
monthly

, rsnapshot
(0:00, 4:00, 8:00 ..), 3:30, 3:00,
2:30.
hourly, daily, weekly monthly. ,
. , ,
Cron-, /etc/rsnapshot.conf!
monthly .

25.7.
.

rsync Cron
data
backup.

25.7.

707

, . , .
#!/bin/bash
if [ -d /media/backup/ ]; then
rsync -avW --delete /home/kofler/data /media/backup/
fi

, .
Cron. Cron, /etc/cron.daily/mybackup. ,
(chmod a+x).
, , /etc/myscripts. /etc/cron.d, , :
# /etc/cron.d/mybackup
15 2 * * * root /etc/myscripts/mybackup

2:15.

TAR- data. mydata-day-dd.tar.gz () mydata-month-mm.tar.gz (). dd ( 01 31), mm ( 01 12).


, 43
,
( 28 31 ), 12 .
#!/bin/bash
fname1=/backup/mydata-day-$(date "+%d").tar.gz
fname2=/backup/mydata-month-$(date "+%m").tar.gz
tar czf $fname1 /home/kofler/data
cp $fname1 $fname2
chmod 600 $fname1 $fname2

LVM
, . .
,
LVM
. , ,

708

25.

,
( ).
lvcreate
-s. -L ,
,
. LVM (
) .
. ,
lvdisplay,
.
, /home /dev/vg1/myhome.
/home ,
lvcreate homesnap. 2.
/var/
homesnap.
. , homesnap
. lvremove. -f .
#!/bin/bash
mkdir -p /var/homesnap
lvcreate -s -L 2G -n homesnap /dev/vg1/home
mount -t ext4 /dev/vg1/homesnap /var/homesnap
tar czf /backup/mybackup.tgz /var/homesnap
lvdisplay /dev/vg1/homesnap > /tmp/backup.log
umount /var/homesnap
lvremove -f /dev/vg1/homesnap

lvdisplay , ,
LVM.
root# cat /var/homesnap
...
COW-table size 2.00 GB
Allocated to snapshot 5.23%

, 5% . , , . , /home.


,
,
LVM .
image.lzo oldimage.lzo, . snap
/dev/vg1/lv1, .

25.7.

709

cat lzop.
ionice -c 3 , -, , .
curl.
--limit-rate . , .
#!/bin/bash
mv /backup/image.lzo /backup/old-image.lzo
lvcreate -s -L 2G -n snap /dev/vg1/lv1
ionice -c 3 cat /dev/vg1/snap | lzop -c > /backup/image.lzo
lvremove -f /dev/vg1/snap
# FTP
pw=u12345:2n34jkj546wqdsr
ftp=u12345.backup-server.de
curl --limit-rate 8m -T /backup/image.lzo -u $pw ftp://$ftp/image.lzo

Tartarus
,
. linux backup script,
. .
. , , .
bash- Tartarus.
600, :
TAR;
, FTP-
(, ssh);
;
LVM;
GPG.

26

.
, (,
). , TCP-Wrapper ,
.

26.1.
,
, , , ..
TCP/IP , , .
.26.1, .
26.1.

DNS

HTTP

ICMP

IP

NFS

TCP

UDP

-. IP-. , , -
FTP, FTP-.
.
FTP-, IP- , IP- .

711

26.1.

, IP- ( )
: IP- , ,
. ,
.
IP- . , IP- (.18).
IP- . , - 80. 16-
. 1024
(, HTTP-). , ,
, .
IP- /etc/services . .26.2
, ,
( ), .
26.2. IP-

ftp

20,21

FTP

ssh

22

SSH

telnet

23

Telnet

smtp

25

domain

53

DNS

Bootps bootpc

67, 68

DHCP

http

80

kerberos

88

Kerberos

pop3

110

portmap

111

Portmap ( NFS)

ntp

123

( )

netbios-ns

137

Microsoft/NetBIOS

netbios-dgm

138

Microsoft/NetBIOS

netbios-ssn

139

Microsoft (SMB, Samba)

imap

143

ldap

389

LDAP

427

Apple (AFP)

https

443

()

microsoft-ds

445

CIFS (SMB, Samba)

printer

515

LPD/LPR

548

Apple (AFP)

ipp

631

IPP/CUPS

rmi

1099

(Java)

1433

Microsoft SQL Server

pptp

1723

PPTP/VPN

nfs

2049

NFS

712

26.
26.2 ()

mysql

3128

Squid ( )

3306

MySQL

5353

Zeroconf/Bonjour

5999-6003

X-

9100

HP-JetDirect

IP-. IP-:
- TCP. . ,
. , , ICMP ( ping)
UDP ( DNS NFS).
IP-. IP-
PPP-.
, . ,
, .
. , , IP-. , 2.4, iptables (.26.5).
.
, .
IP-, . ,
, .
, ,
( , , ).
Netstat.
netstat. ,
, .
( mars )
(established) (LISTEN). : a
; tu ,
TCP UDP; pe
, . .
root# netstat -atupe
Active Internet connections (servers and established)
Proto Local Address
Foreign Addr State
User
tcp *:nfs
*:*
LISTEN root
tcp *:54980
*:*
LISTEN root

PID/Prog name
-

713

26.1.

tcp
tcp
tcp
...
tcp6
tcp6
udp
udp
udp
udp
udp
udp
udp
udp
udp
...

*:ldap
*:3142
localhost:mysql

*:*
*:*
*:*

LISTEN
LISTEN
LISTEN

root
root
mysql

5842/slapd
5904/perl
5785/mysqld

[::]:ssh
mars.sol:ssh
*:nfs
mars.local:netbios-ns
mars.sol:netbios-ns
*:netbios-ns
mars.local:netbios-dgm
mars.sol:netbios-dgm
*:netbios-dgm
*:domain
*:55350

[::]:*
merkur.so...
*:*
*:*
*:*
*:*
*:*
*:*
*:*
*:*
*:*

LISTEN
ESTAB

root
root
root
root
root
root
root
root
root
root
avahi

5559/sshd
7729/0
6231/nmbd
6231/nmbd
6231/nmbd
6231/nmbd
6231/nmbd
6231/nmbd
5537/dnsmasq
5604/avahi-...

: Samba,
NFS, Kerberos, LDAP, Dnsmasq, CUPS, MySQL SSH.
( ),
. ,
.
TCP- UDP-
:
root# netstat -tuep
Active Internet connections (w/o servers)
Proto Local Address
Foreign Address State
tcp
localhost:57450 localhost:ldap
ESTABLISHED
tcp
localhost:ldap localhost:57450 ESTABLISHED
tcp6 mars.sol:ssh
merkur.sol:45368 ESTABLISHED

User
root
openldap
root

PID/Program name
6233/smbd
5842/slapd
7729/0

Lsof. , TCP UDP,


lsof. derFormlsof -i []@[-][:]
, .
, UDP
22:
root# lsof -i udp
ntpd
3696 ntp
16u
IPv4
9026 UDP *:ntp
ntpd
3696 ntp
17u
IPv6
9028 UDP *:ntp
ntpd
3696 ntp
18u
IPv6
9031 UDP ip6-localhost:ntp
portmap
4745 daemon 3u
IPv4
12931 UDP *:sunrpc
rpc.statd 4764 statd
5u
IPv4
12962 UDP *:700
rpc.statd 4764 statd
7u
IPv4
12970 UDP *:39146
...
root# lsof -i :22
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
sshd
5559 root 3u IPv6
14097
TCP *:ssh (LISTEN)
sshd
7729 root 3r IPv6
33146
TCP mars.sol:ssh->merkur.sol:45368
(ESTABLISHED)

714

26.

Nmap. netstat lsof , .


.
,
( ) . nmap ,
. .
, nmap
mars. nmap .
.
root# nmap -v -A mars
Starting Nmap 4.62 ( http://nmap.org ) at 2009-03-20 09:43 CET
Initiating ARP Ping Scan at 09:43
Scanning 192.168.0.1 [1 port]
...
Discovered open port 53/tcp on 192.168.0.1
Discovered open port 21/tcp on 192.168.0.1
...
Completed SYN Stealth Scan at 09:43, 0.29s elapsed (1715 total ports)
Initiating Service scan at 09:43
Scanning 9 services on mars.sol (192.168.0.1)
...
Host mars.sol (192.168.0.1) appears to be up ... good.
Interesting ports on mars.sol (192.168.0.1):
Not shown: 1706 closed ports
PORT
STATE
SERVICE
VERSION
21/tcp open
ftp vsftpd
2.0.6
22/tcp open
ssh OpenSSH
4.7p1 Debian 8ubuntu1.2 (protocol 2.0)
53/tcp open
domain dnsmasq 2.41
111/tcp open
rpcbind
139/tcp open
netbios-ssn
Samba smbd 3.X (workgroup: SOL)
389/tcp open
ldap OpenLDAP
2.2.X
445/tcp open
netbios-ssn
Samba smbd 3.X (workgroup: SOL)
749/tcp open
rpcbind
2049/tcp open
rpcbind
MAC Address: 00:14:6C:8E:D9:71 (Netgear)
Device type: general purpose
Running: Linux 2.6.X
...

nmap , zenmap
nmap-frontend.

. , nmap, ! nmap
,
.

26.2.

715

26.2.
,
.
, .
, . ,
, .

(, , ). , ,
.
Apache, Samba, MySQL ,
.
, ,
TCP-Wrapper.
.

. Init-V,
. ,
, ,
chroot, - chroot.
,
,
(.26.3).
.

,
.
,
.
(Mandatory Access Control, MAC). Linux : SELinux AppArmor (.29).
, .
.
.

TCP-Wrapper
.

716

26.

.
TCP-Wrapper. ,
, SSH- NFS-. , , TCP-Wrapper (.26.2).

/etc/hosts.allow hosts.deny
/etc/hosts.allow /etc/hosts.deny , .
, TCP-Wrapper
tcpd. ,
.
TCP-Wrapper hosts.allow:
, , . hosts.deny:
, . : ,
/etc/hosts.allow, /etc/hosts.deny,
!
,
all:all /etc/
hosts.deny. spawn
/var/log/deny.log.
/var/log/deny.log , ( ; , -
IP-).
# /etc/hosts.deny
# ,
#
ALL : ALL : spawn (echo Attempt from %h %a to %d at $(date) \
>> /var/log/deny.log)

/etc/hosts.allow . :
(localhost) ;
ssh ,
( , );
NFS SWAT .
, mars mars.sol,
192.168.0.*
*.sol. ,
, :
# /etc/hosts.allow
#
ALL
: localhost mars mars.sol

: ALLOW

717

26.2.

Sshd
: ALL
portmap : 192.168.0.0/255.255.255.0
mountd : 192.168.0.0/255.255.255.0
swat
: 192.168.0.0/255.255.255.0
# SUSE
cupsd
: 192.168.0.0/255.255.255.0

*.sol
*.sol
*.sol

:
:
:
:

ALLOW
ALLOW
ALLOW
ALLOW

*.sol

: ALLOW

, hosts.allow hosts.deny,
. , . , IP-
, . man 5 hosts_access .

TCP-Wrapper
cupsd SUSE ( 11.2 ),
CUPS TCP-Wrapper ( ).
,
CUPS- /etc/cups/cups.conf.
ldd ,
TCP-Wrapper (libwrap). cupsd
sshd openSUSE Ubuntu :
user$ ldd /usr/sbin/cupsd | grep wrap (openSUSE 11.3 )
user$ ldd /usr/sbin/cupsd | grep wrap (openSUSE 11.2 )
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f1f3fece000)
user$ ldd /usr/sbin/cupsd | grep wrap (Ubuntu)
user$ ldd /usr/sbin/sshd | grep wrap
libwrap.so.0 => /lib/libwrap.so.0 (0x00007f1a5f7f0000)


, Apache MySQL,
, .
, . , Ubuntu
Apache www-data
, . ps axu ( Apache
;
Apache ).
root# ps axu | grep apache2
root ...
/usr/sbin/apache2 -k start
www-data ... /usr/sbin/apache2 -k start
www-data ... /usr/sbin/apache2 -k start
...

Init, ,
,

718

26.

. su
-c .
,
, . , syslog, ,
. Apache, MySQL ,
,
.
( , ).

chroot
chroot , .
, . ,
, , ( root ).
, chroot, , chroot-.
, ..
Init-V.
SUSE DHCP- chroot.
DHCP-
dhcpd, chroot- -chroot. , chroot-
-t.
SELinux AppArmor , chroot, , . Fedora Red Hat chroot -
, SELinux.

26.3. :
, . :
,
. ADSL-
.
,

. , .

26.3. :

719

,
, TCP/IP .
, ,
, . , , .
. .


,
IP-, , , .
, , SSH-,
.
, , . , !
WLAN:
WLAN, WPA2, , .
, , - . , .
, .
, .
cWindows, .


, . .
.
. .26.1.
. ,
,
.
, .
, -, HTTP FTP. (Demilitarized Zone, DMZ). ,
. ,
-, ,
( ).

721

26.3. :








 

 













.26.2. iptables/netfilter

Local Process ( ).

, IP-
IP- ( , FTPD, HTTPD).
Filter Output ( ). -

, IP- .
Filter Forward ( ). , -

, ( ),
.
NAT Postrouting.

, IP- .
.26.2 Filter Input, Filter Output,
Filter Forward , , NAT Postrouting.
,
.

,
, . , .26.2
! , , ,
. , .

. ,
.
.
Deny (-

, ).
Reject c .

, ,
ICMP- , .
Accept .

722

26.

. , : IP-
,
. ,
. .

().
,
.
( ) , .
mangle IP.
.
(chains). :
Input, Forward, Output;
Prerouting, Output Postrouting;
mangle Prerouting Output.
.26.2
.

, Prerouting
Output. ,
Output, , .
- , .

iptables
: -
t
. , .

IP- ,
. ,
(, ,
, ..).
, , .
: , , .
. Input, Forward, Output.
.
iptables. , ,
, -

26.4. ()

723

, .
iptables. .
, , :
http://www.netfilter.org/;
http://www.linuxguruz.org/iptables/;
http://people.netfilter.org/rusty/unreliable-guides/.
nftables. 2001.
,
nftables. ,
. http://lwn.net/Articles/324989/.

26.4.
()
, iptables. . Linux
.
.

. , , . , ,
-.
,
.
, , , . ,
. ,
, . , Linux , , ,
. ,
, , ,
. :
!
Debian. Debian .
.
Fedora Red Hat. Fedora Red Hat , .
system-config-firewall.
(, SSH) (, LAN) .

724

26.

,
. Init:
/etc/sysconfig/iptables;
Init-V /etc/init.d/iptables;
Systemd /lib/systemd/system/iptables.service (Fedora).
Fedora 17 .
Fedora17.
( firewalld).
, . ( .)
FirewallD firewall-config. Fedora17 . 18.
firewallcmd /etc/firewalld. -
. FirewallD
: http://fedoraproject.org/wiki/FirewallD.
SUSE. SUSE ,
. . YaST YaST (,
). ,
LAN ,
. Init-V:
/etc/sysconfig/SuSEfirewall;
Init-V /etc/init.d/SuSEfirewall2*.
Ubuntu. Ubuntu , . Ubuntu ufw (Uncomplicated Firewall,
).
iptables. ,
Ubuntu
ufw, . : ufw .
, ufw
. (
man ufw): ufw enable . . ufw default allow|deny , ( , deny).
ufw allow|deny n ufw allow|deny , -

26.4. ()

725

IP- . ufw
status .
user$ sudo -s
root# ufw enable
root# ufw allow ssh
root# ufw status
Firewall loaded
To Action From
-- ------ ---22:tcp ALLOW Anywhere
22:udp ALLOW Anywhere

/lib/ufw/user.rules user6.rules (
IPv6). , ufw /etc/
ufw/. ufw
https://help.ubuntu.com/12.04/serverguide/firewall.html https://wiki.ubuntu.com/
UncomplicatedFirewall.
Gufw ufw. Ubuntu universe- (
). https://
help.ubuntu.com/community/Gufw.
Firestarter. , .
. , .
, .
DHCP-,
IP- DHCP-.
. Firestarter DHCP- dhcpd,
.
, , ,
.

.
, ,
.
. ,
.
,
, ,

. , . .

726

26.

Firestarter
: http://www.fs-security.com/.
. ,
. .
:
http://www.fwbuilder.org/;
http://www.simonzone.com/software/guarddog/;
http://firehol.sourceforge.net/;
http://www.shorewall.net/.
. iptables -L | wc -l ,

. ,
, ! , -
.

26.5.
iptables
, , . .26.1
. ,
, ,
, ( ). , .
Ubuntu.
, ,
! ,
Init , .
myfirewall-start myfirewallstop.
myfirewall.
/etc/myfirewall/myfirewall-start ( )
/etc/myfirewall/myfirewall-stop ( )
/etc/default/myfirewall ( )

(myfirewall)
MFW_ACTIVE /etc/default/myfirewall ,
. MFW_MASQ , -

26.5. iptables

727

.
:
# /etc/default/myfirewall
# : /
MFW_ACTIVE=yes
# : /
MFW_MASQ=yes
#
MFW_LAN=eth1
MFW_LAN_IP=192.168.0.0/24
#
MFW_INET=eth0

(myfirewall-stop)
myfirewall-stop iptables . .
myfirewall. , which , iptables sysctl.
(, ,
.)
iptables -P
ACCEPT. iptables F , NAT . iptables X . Netfilter
IP.
#!/bin/bash
# /etc/myfirewall/myfirewall-stop
#
. /etc/default/myfirewall
IPT=$(which iptables)
SYS=$(which sysctl)
#
$IPT -P
$IPT -P
$IPT -P
$IPT -P
$IPT -P
$IPT -P
$IPT -F
$IPT -F
$IPT X

iptables
INPUT ACCEPT
OUTPUT ACCEPT
FORWARD ACCEPT
POSTROUTING ACCEPT -t nat
PREROUTING ACCEPT -t nat
OUTPUT ACCEPT -t nat
-t nat

#
$SYS -q -w net.ipv4.ip_forward=0

chmod u+x!

728

26.

(myfirewall-start)
, myfirewall-start .
. , Netfilter. iptables,
.
SSH- .
, (
ADSL- ) . SSH ,
.
wall- . , ,
SSH , iptables.


for , .
.
#!/bin/bash
# /etc/myfirewall/myfirewall-start ( 1)
#
. /etc/default/myfirewall
IPT=$(which iptables)
SYS=$(which sysctl)
if [ $MFW_ACTIVE != "yes" ]; then
echo "Firewall disabled in /etc/default/myfirewall"
exit 0
fi
#
. /etc/myfirewall/myfirewall-stop
# SSH- ( 22)
$IPT -A INPUT -i $MFW_INET -p tcp --dport 22 -j ACCEPT
#
#
#
#
#
#
#
#
#
#
#


23 (telnet)
69 (tftp)
135 (Microsoft DCOM RPC)
139 (NetBIOS/Samba/..)
445 ( CIFS Samba/SMB)
631 (ipp/CUPS)
1433 (Microsoft SQL Server)
2049 (NFS)
3306 (MySQL)
5999-6003 (X-Displays)

26.5. iptables

for PORT in 23 69 135 139 445 631 1433 2049 3306 \


5999 6000 6001 6002 6003; do
$IPT -A INPUT -i $MFW_INET -p tcp --dport $PORT
$IPT -A OUTPUT -o $MFW_INET -p tcp --dport $PORT
$IPT -A INPUT -i $MFW_INET -p udp --dport $PORT
$IPT -A OUTPUT -o $MFW_INET -p udp --dport $PORT
done

-j
-j
-j
-j

729

DROP
DROP
DROP
DROP

wall
wall.
, . wall , , .
, , -. ,
-i. , , ,
HTTP,
.
, ,
, . ,
, , !. , ,
SSH- (,
HTTP, FTP, Telnet ..).
, ,
, wall:
# /etc/myfirewall/myfirewall-start.conf ()
# ,
# ( )
$IPT -N wall
$IPT -A wall -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A wall -m state --state NEW -i ! $MFW_INET -j ACCEPT
$IPT -A wall -j DROP
# INPUT FORWARD
$IPT -A INPUT -j wall
$IPT -A FORWARD -j wall

, :
# /etc/myfirewall/myfirewall-start.conf ()
#
if [ $MFW_MASQ = 'yes' ]; then
$IPT -A POSTROUTING -t nat -o $MFW_INET -s $MFW_LAN_IP -j MASQUERADE
$SYS -q -w net.ipv4.ip_forward=1
fi

730

26.

Upstart

(
), /etc/init:
# /etc/init/myfirewall.conf
description "myfirewall"
start on (starting network-interface

or starting network-manager

or starting networking)
stop on runlevel [!023456]
pre-start exec /etc/myfirewall/myfirewall-start
post-stop exec /etc/myfirewall/myfirewall-stop

service ,
:
root# service myfirewall start
root# service myfirewall stop
root# service myfirewall restart

Init-V
Upstart,
Init-V. , Upstart, Systemd Init-V.
.
#!/bin/sh -e
# Init-V /etc/init.d/myfirewall
### BEGIN INIT INFO
# :
# : networking
# :
# : S
# :
### END INIT INFO
#
. /lib/lsb/init-functions
# ,
case "$1" in
start|restart)
log_begin_msg "Starting firewall and masquerading ..."
. /etc/myfirewall/myfirewall-start
log_end_msg 0
;;
stop)

26.5. iptables

731

log_begin_msg "Stopping firewall and masquerading ..."


. /etc/myfirewall/myfirewall-stop
log_end_msg 0
;;
status)
/sbin/iptables -L -v -n
;;
*)
log_success_msg "Usage: xxx {start|stop|restart|status}"
exit 1
;;
esac
exit 0

, :
root# cd /etc/rcS.d
root# ln -s ../init.d/myfirewall S41myfirewall

27

( WLAN)
, , . WLAN, WPA2, ,
. , , WPA2.
(VPN).
, () .
VPN .
, WLAN. VPN, , LAN- VPN- WLAN-.
VPN PPTP.

27.1. VPN

. ,
VPN ,
, WLAN, ( ,
).
,
. : ,
, .
,
, .. .
,
, , . , ,

27.1. VPN

733


WLAN.
VPN ( ifconfig).
, , () 192.168.0.*.
, .
, , VPN,
. VPN , VPN- ,
.

VPN
VPN.
,
.
IPsec, Openswan. IPsec
,
. - IPv6, IPsec
IPv4. IPsec :
,
.
IPsec 2.6 . IPsec ipsec,
openswan. IPsec ( Windows).
IPsec Openswan :
yy http://www.openswan.org/;
yy http://www.ipsec-howto.org/;
yy http://lartc.org/howto/lartc.ipsec.html.
L2TP. - 2
Microsoft Cisco. PPTP
CiscoL2F ( ). L2TP ,
IPsec (L2TP/IPsec). IPsec
, L2TP .
L2TP :
yy http://www.jacco2.dds.nl/networking/freeswan-l2tp.html;
yy http://sourceforge.net/projects/openl2tp/.
PPTP. (PPP),

734

27.

- ISDN,
(http://www.poptop.org/). PPTP IP-,
(, Novell IPX, AppleTalk ..).
PPTP Microsoft,
(RFC2637),
Windows PPTP-VPN . PPTP .
PPTP ,
. -
PPTP . PPTP , $200 PPTP 24.
OpenVPN. VPN-,
, IPsec (http://openvpn.net/). UDP-. VPN
Linux tun tap. OpenVPN .
OpenVPN Linux, Windows UNIX- (Solaris, *BSD, Mac OSX).
PPPD SSH. SSH. . SSH- IP-.
SSH PPP- SSH-
IP-. VPN
PPTP. SSH PPPD http://
www.oreillynet.com/pub/a/wireless/2001/02/23/wep.html http://www.tldp.org/HOWTO/
VPN-HOWTO/.
VPN-
, . IPsec
IP, .
, , TCP- UDP-.
,
, IP-
(, FTP).
VPN- , - . PPTP, .
PPTP ,
PPTP -
.

VPN
, VPN-,
VPN.
.

27.2. VPN PPTP

735


(WLAN, ).
VPN, SSH.
.
.
(road warrior scenario)
, ,
.
. VPN
, . , .
,
(, , )
- VPN.
, , WLAN.
-, , IP- VPN: WLAN
IP- VPN.
, , VPN
, (, ). -
.
, , . VPN- ,
.

27.2. VPN PPTP


, .27.1, ,
VPN.
VPN- ,
- .
VPN- ,
WLAN ( ). VPN- ( )
.
WLAN . DHCP- , 172.168.0.*.
, WLAN, ,
. ,

736

27.

DHCP- WLAN VPN. WLAN-


PPTP .
 
  

 
 

  

 

 


 

 



 

 
 

.27.1. VPN

: (LAN)
(WLAN):
192.168.0.* ();
172.16.0.* (, WLAN).
,
:
eth0 10.0.0.1 ( ADSL-);
eth1 192.168.0.1 (LAN);
eth2 172.16.0.1 (WLAN).
WLAN DHCP VPN. WLAN VPN-.
WLAN VPN 192.168.0.*. , VPN .
, . PPTPVPN , VPN-
, . : IP-
DHCP-, PPTP-.
. - VPN-
IP-.


, 19,
eth2, -

27.2. VPN PPTP

737

IP- 172.16.0.1. Debian Ubuntu,


/etc/network/interfaces :
# /etc/network/interfaces
...
# WLAN
auto eth2
iface eth2 inet static
address 172.16.0.1
netmask 255.255.255.0

DHCP. DHCP-
WLAN eth2 WLAN 172.16.0.*.
dnsmasq, , 19,
.
interface=eth1 except-interface=eth0. , dnsmasq
eth0. , dnsmasq
pppn.
, dhcp-range IP- . dnsmasq
. ,
dhcp-range eth1 ( 192.168.0.2 192.168.0.239). IP- PPTP-.
# /etc/dnsmasq.conf
except-interface=eth0
dhcp-range=192.168.0.2,192.168.0.239,24h
dhcp-range=172.16.0.2,172.16.0.250,12h
...

:
root# service dnsmasq restart

PPTPD-
PPTP-,
pptpd. .

pptpd.conf
/etc/pptpd.conf pptpd.
IP- VPN-. , VPN. DHCP-, ,
DHCP PPTP .
dnsmasq.conf.
# /etc/pptpd.conf
option /etc/ppp/pptpd-options

738

27.

localip 192.168.0.1
remoteip 192.168.0.240-253
listen 172.16.0.1

pptpd
/etc/ppp/pptpd-options PPP- .
, , ,
option /etc/pptpd.conf.
# /etc/ppp/pptpd-options
name pptpd
#
# chap-secrets
lock
require-mschap-v2
require-mppe-128
refuse-pap
refuse-chap
refuse-mschap
proxyarp
ms-dns 192.168.0.1 # PPTP- DNS

pptpd: name
PPP.
, chap-secrets.
require refuse
mschap 2, Microsoft. require-mppe-128 (128- ), PPTP.
proxyarp IP- VPN ARP
( ) , ,
, VPN-.
ms-dns , VPN-
. ms (Microsoft), ,
Linux.

,
PPP
-
pppd
, /
etc
/
ppp
/
options
( /
etc
/
ppp
/
pptpd
-
options
). PPTP-, /etc/ppp/options.
, /etc/ppp/options .
VPN-, pptpd-options
debug

.
pptpd

pppd
/
var
/
log
/
messages
.

chap-secrets
/etc/ppp/chap-secrets. , PPTP- VPN.

739

27.2. VPN PPTP

. , .
, 12.
(.
name pptpd-options). ,
IP-. PPTP- IP- remoteip, IP-, remoteip, .
# /etc/ppp/chap-secrets
#
pptpd
"vpnclient" "pptpd"

"vpntestpassw"

IP-
*

PPTP-:
root# /etc/init.d/pptpd restart

pptpd
,
:
root# chkconfig --level 35 pptpd on (Red Hat)
root# insserv pptpd (SUSE)
root# systemctl enable pptpd.service (Systemd)

PPTP-
(18.3 , ).
ppp-, ppp0, ppp1 ..
ifconfig. , mars.sol.
lo , eth0
, eth1 LAN, eth2 WLAN, ppp0
VPN- PPTP.
root# ifconfig
lo
Protocol:Local loop
inet Addr:127.0.0.1 Mask:255.0.0.0
...
eth0 Link encap:Ethernet-Hardware-Address 00:16:17:cd:c3:81
inet Adr:10.0.0.1 Bcast:10.0.0.255 Mask:255.255.255.0
...
eth1 Link encap:Ethernet-Hardware-Address 00:14:6c:8e:d9:71
inet Adr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
...
eth2 Link encap:Ethernet-Hardware-Address 00:4f:4e:0f:8e:a0
inet Adr:172.16.0.1 Bcast:172.16.255.255 Mask:255.255.0.0
...
ppp0 Link encap:Point-to-Point-Connection
inet Adr:192.168.0.1 P-z-P:192.168.0.240 Mask:255.255.255.255
...

740

27.

PPTP-
WLAN- . DHCPPPTP-. DHCP UDP 67 68. PPTP UDP 1723, GRE.
, , 26.5. /etc/
default/myfirewall MFW_WLAN WLAN-:
# /etc/default/myfirewall
...
MFW_WLAN=eth2

/etc/myfirewall/myfirewall-start
:
# /etc/myfirewall/myfirewall-start
...
# 67 68 UDP- (DHCP)
$IPT -A INPUT -i $MFW_WLAN -p udp --dport
$IPT -A OUTPUT -o $MFW_WLAN -p udp --dport
$IPT -A INPUT -i $MFW_WLAN -p udp --dport
$IPT -A OUTPUT -o $MFW_WLAN -p udp --dport

67
67
68
68

-j
-j
-j
-j

ACCEPT
ACCEPT
ACCEPT
ACCEPT

# 1723 TCP- (PPTP-)


# GRE- ( 47, PPTP-)
$IPT -A INPUT -i $MFW_WLAN -p tcp --dport 1723 -j ACCEPT
$IPT -A OUTPUT -o $MFW_WLAN -p tcp --sport 1723 -j ACCEPT
$IPT -A INPUT -i $MFW_WLAN -p gre -j ACCEPT
$IPT -A OUTPUT -o $MFW_WLAN -p gre -j ACCEPT
#
$IPT -A INPUT -i
$IPT -A OUTPUT -o
$IPT -A INPUT -i
$IPT -A OUTPUT -o


$MFW_WLAN -p
$MFW_WLAN -p
$MFW_WLAN -p
$MFW_WLAN -p

WLAN-
tcp -j DROP
tcp -j DROP
udp -j DROP
udp -j DROP

27.3. VPN- (PPTP)

VPN-, ,
(. .27.1):
, , PPTP-;
, LAN WLAN. -

27.3. VPN- (PPTP)

741

DHCP.
172.16.0.*;
(VPN) 192.168.0.*;
VPN- 172.16.0.1 (WLAN) 192.168.0.1 (VPN).


.
, VPN, , PPTP.
. Ubuntu network-manager-pptp network-manager-gnome-pptp.

. VPN-.
VPN- -. VPN IP- PPTP- (
172.16.0.1). vpnclient,
/etc/ppp/chap-secrets
PPTP-.
MPPE.
VPN-, WLAN. , WLAN.
VPN-XXX, XXX VPN-.


PPTP- : PPP- pppd PPTP- pptp,
. pptp-linux.
:
/etc/ppp/peers/vpn /etc/ppp/chap-secrets.
Ppp/peers/vpn. /etc/ppp/peers/vpn PPP-
VPN-. , /etc/ppp/peers/. VPN- ,
27.2, :
# /etc/ppp/peers/vpn
pty "/usr/sbin/pptp 172.16.0.1 --nolaunchpppd"
user "vpnclient"
noauth
require-mppe-128
defaultroute
usepeerdns
ipparam "vpn" # Red Hat Fedora

742

27.

pty PPP- pptp. VPN-


IP- 172.16.0.1.
vpnclient.
/etc/ppp/chap-secrets (. ).
chap-secrets VPN-.
noauth , VPN- PPP . - !
require-mppe-128 Microsoft
128- .
defaultroute IP-, VPN-, IP-.
, IP- VPN, - . , pppd !
VPN- route del
default.
usepeerdns , VPN-, /etc/resolv.conf. Red Hat Fedora
, ipparam vpn. , /etc/sysconfig/network-scripts/ifcfg-vpn,
PEERDNS=yes.

, PPP- pppd /etc/


ppp
/
options
, /
etc
/
ppp
/
options
.
pptp
. /etc/ppp/peers/vpn . , options
.
PPTP-, /etc/ppp/
options . SUSE
idle
600.
PPP
- . , , ,
VPN . PPP 18.7.

Ppp-chap-secrets. /etc/ppp/chap-secrets
VPN- ( PPTP
chap-secrets PPTPD- 27.2).
# /etc/ppp/chap-secrets
#login name server password IP adress
"vpnclient" * "vpntestpassw"
*

VPN-. , . route ,
(, route-n
, flags UG).
root# route del default
root# pppd call vpn

27.3. VPN- (PPTP)

743

,
, /etc/ppp/options nodetach.
, pppd .
, ifconfig route
:
root# ifconfig
lo Link encap:Local Loop
inet Address:127.0.0.1 Mask:255.0.0.0
...
eth1 Link encap:Ethernet Hardware Address 00:0C:F1:58:F9:93
inet Address:172.16.0.199 Bcast:172.16.0.255 Mask:255.255.255.0
...
ppp0 Link encap: Point-to-Point connection
inet Address:192.168.0.200 P-z-P:192.168.0.1 Mask:255.255.255.255
...
root# route -n
Kernel IP Routing table
Target Router Genmask Flags
Metric Ref Use Iface
192.168.0.1 0.0.0.0 255.255.255.255
UH 0 0 0 ppp0
172.16.0.0 0.0.0.0 255.255 255.0
U 0 0 0 eth1
0.0.0.0 192.168.0.1
0.0.0.0 UG 0 0 0 ppp0

, , ,
: eth1 WLAN ppp0 VPN. ,
IP-: 127.0.0.1 ( ), 172.16.0.199 (WLAN)
192.168.0.200 ( ).
ppp0, VPN.
,
172.16.0.* eth1.
VPN-, :
root# killall pppd

VPN-, /etc/ppp/peers/vpn
debug. pppd
( , /var/log/messages
/
var
/
log
/
syslog
). http

://
pptpclient
.
sourceforge.net/howto-diagnosis.phtml.

VPN . , VPN-
. Debian Ubuntu , pon pptp poff pptp.

. /etc/sudoers
, sudo.

744

27.

PPTP-
, , (, Samba MySQL), WLAN
, WLAN .
, . ,
.
:
#!/bin/sh
IPT=/sbin/iptables
WLAN=eth1
# 67 68 UDP (DHCP)
$IPT
-A INPUT
-i
$WLAN
-p
udp
$IPT
-A OUTPUT
-o
$WLAN
-p
udp
$IPT
-A INPUT
-i
$WLAN
-p
udp
$IPT
-A OUTPUT
-o
$WLAN
-p
udp
# 1723 TCP (PPTP control)
# GRE
$IPT
-A INPUT
-i
$WLAN
-p
tcp
$IPT
-A OUTPUT
-o
$WLAN
-p
tcp
$IPT
-A INPUT
-i
$WLAN
-p
gre
$IPT
-A OUTPUT
-o
$WLAN
-p
gre
#
$IPT
-A INPUT
-i
$WLAN
-p
tcp
$IPT
-A OUTPUT
-o
$WLAN
-p
tcp
$IPT
-A INPUT
-i
$WLAN
-p
udp
$IPT
-A OUTPUT
-o
$WLAN
-p
udp

--dport
--dport
--dport
--dport

67
67
68
68

--sport
1723
--dport
1723
-j ACCEPT
-j ACCEPT
-j
-j
-j
-j

DROP
DROP
DROP
DROP

-j
-j
-j
-j

ACCEPT
ACCEPT
ACCEPT
ACCEPT
-j ACCEPT
-j ACCEPT

28

Squid DansGuardian
( )

Squid -. ,
, , . Squid .
. Squid ,
.. Squid
DansGuardian. , Squid
DansGuardian (, ) .
. -
-,
. , . ,
Web2.0, ,
.
/. Squid , ,
. , , .

.
, : Squid DansGuar
dian
!
Squid , : http://www.squid-cache.org.

28.1. Squid
. Squid /etc/
squid/squid.conf. , Squid,
, 6000!

746

28. Squid DansGuardian ( )

, , (grep
v ,
#, cat ). 50.
root# cd /etc/squid3
root# mv squid.conf squid.conf.orig
root# grep -v '^#' squid.conf.orig | cat -s > squid.conf

squid.conf ,
localhost, 8
100 , /var/spool/squid .
Squid ,
. ,
Squid. acl localnet localnet,
. (
Squid
.)
http_access ( localnet ).
, ,
Ubuntu, :
# /etc/squid/squid.conf
#
#
# - , squid
visible_hostname mars.sol
#
acl manager
acl localhost
acl to_localhost
acl localnet
acl localnet

proto
src
dst
src
src

cache object
127.0.0.1/32 ::1
127.0.0.0/8 0.0.0.0/32 ::1
192.168.0.0/255.255.255.0
192.168.0.0/255.255.255.0

acl
acl
acl
acl
acl

SSL_ports port 443


Safe_ports port 80
Safe_ports port 21
Safe_ports port 443
Safe_ports port 70

#
#
#
#

http
ftp
https
gopher

acl
acl
acl
acl

Safe_ports
Safe_ports
Safe_ports
Safe_ports

#
#
#
#

wais

http-mgmt
gss-http

port
port
port
port

210
1025-65535
280
488

747

28.1. Squid

acl Safe_ports port 591


acl Safe_ports port 777
acl CONNECT method CONNECT

# filemaker
# multiling http

#
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow localnet
http_access deny all
#
access_log none
#
http_port 3128
#
coredump_dir /var/spool/squid3
#
refresh_pattern ^ftp:
1440
20%
10080
refresh_pattern ^gopher:
1440
0%
1440
refresh_pattern (Release|Packages(.gz)*)$
0
20%
2880
refresh_pattern .
0
20%
4320
#
cache_mem 256 MB
# :
# cache_dir

, Squid:
root# service squid3 restart

-
, IP-
cache_peer ( ). ICP-
, 0 7. , default no-query.
# - (, -)
# cache_peer <-> <> <-> <icp-> <>
cache_peer www-proxy.provider.de parent 8080 7 default

, , no_cache. ,
uranus -:

748

28. Squid DansGuardian ( )

# - uranus.sol
acl
mars dstdomain .uranus .uranus.sol
no_cache deny uranus

, Squid
. , squid.conf
www.squid-cache.org.

. Squid 3128. ,
. Firefox
,
. -
, Squid (, mars.sol), 3128.
Squid , /var/log/
squid/access.log , .
, .

28.2.
-
- . ( )
, Squid . ,
.
: . , Squid
,
.
, Linux ,
HTTP, IP- 80, -. . ,
HTTP. , Squid , - .
squid.conf. squid.conf . http_port
transparent, Squid.
# /etc/squid/squid.conf
...
http_port 3128 transparent

. ,
,
:

28.2. -

749

root# echo 1 > /proc/sys/net/ipv4/ip_forward

. IP: IP-, 80,


IP-, Squid.
, . eth1 , .
root# iptables -A PREROUTING -t nat -i eth1 -p tcp \
--dport 80 -j REDIRECT --to-port 3128

, , ,
Squid -. ,
/var/log/squid/access.log
.
iptables Init-V, . (. 26):
# /etc/myfirewall/myfirewall-start.conf
...
if [ $MFW_MASQ = 'yes' ]; then
#
$IPT -A POSTROUTING -t nat -o $MFW_INET -s $MFW_LAN_IP \
-j MASQUERADE
# -
$IPT -A PREROUTING -t nat -i eth1 -p tcp --dport 80 \
-j REDIRECT --to-port 3128
#
$SYS -q -w net.ipv4.ip_forward=1
fi

, , , ! : , .
, .

VPN. , , , VPN (. ).
: , eth1 (
,
). VPN-, ,
pppn-.
,
pppn-.

750

28. Squid DansGuardian ( )

# /etc/myfirewall/myfirewall
...
if [ $MFW_MASQ = 'yes' ]; then
...
# -
$IPT -A PREROUTING -t nat -i $MFW_LAN -p tcp --dport 80 \
-j REDIRECT --to-port 3128
$IPT -A PREROUTING -t nat -i ppp+ -p tcp --dport 80 \
-j REDIRECT --to-port 3128
fi

28.3. DansGuardian
squid.conf -.
. ,
- . DansGuardian
, .
,
, , .
. DansGuardian
, , .
http://dansguardian.org/.
. DansGuardian
. , DansGuardian
ClamAV ( Windows,
; Linux ).
DansGuardian , . - 8080.
, DansGuardian Squid
(3128) . ,
8080 .
, DansGuardian 80 .
dansguardian.conf.
/etc/dansguardian/dansguardian.conf. ,
, .
UNCONFIGURED; ,
. ,
'access denied' -, language='russian'.
c Linux,
virusscan=off ,

28.3. DansGuardian

751

. Squid
IP- .
# /etc/dansguardian/dansguardian.conf ()
# UNCONFIGURED ( !)
reportinglevel = 3
languagedir = '/etc/dansguardian/languages'
language = 'german'
loglevel = 1
logexceptionhits = 2
logfileformat = 1
filterport = 8080
proxyip = 127.0.0.1
proxyport = 3128
...

, DansGuardian:
root# service dansguardian start

. DansGuardian , 8080.
, 80,
. HTTP- 3128
(Squid) 8080 (DansGuardian):
#
#
# DansGuardian (Port 8080)
# , 80 ( )
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 \
-j REDIRECT --to-port 8080

, Squid
-. , Squid ,
Squid ,
DansGuardian. Squid, DansGuardian
, , http_access allow localnet. ,
Squid 3128
DansGuardian!


DansGuardian /etc/dansguardian/
dansguardianf1.conf. , , ..
naughtynesslimit , . ,
.

752

28. Squid DansGuardian ( )

# /etc/dansguardian/dansguardianf1.conf ()
# ,
bannedphraselist
= '/etc/dansguardian/bannedphraselist'
weightedphraselist = '/etc/dansguardian/weightedphraselist'
exceptionphraselist = '/etc/dansguardian/exceptionphraselist'
bannedsitelist
= '/etc/dansguardian/bannedsitelist'
greysitelist
= '/etc/dansguardian/greysitelist'
exceptionsitelist
= '/etc/dansguardian/exceptionsitelist'
bannedurllist
= '/etc/dansguardian/bannedurllist'
greyurllist
= '/etc/dansguardian/greyurllist'
exceptionurllist
= '/etc/dansguardian/exceptionurllist'
bannedregexpurllist = '/etc/dansguardian/bannedregexpurllist'
bannedextensionlist = '/etc/dansguardian/bannedextensionlist'
bannedmimetypelist = '/etc/dansguardian/bannedmimetypelist'
picsfile
= '/etc/dansguardian/pics'
contentregexplist
= '/etc/dansguardian/contentregexplist'
urlregexplist
= '/etc/dansguardian/lists/urlregexplist'
#
# :
# 50 , 100 ,
# 160 .
naughtynesslimit = 50
...

DansGuardian , (.28.1). ,
, /etc/dansguardian/languages/german/
template.html.
.28.1 , /etc/
dansguardian. ,
, .
28.1. DansGuardian

bannedextensionlist

bannedmimetypelist

bannedphraselist

weightedphraselist

bannedsitelist

bannedurllist

exceptioniplist

, ( )

exceptionsitelist

exceptionurllist

exceptionphraselist

greysitelist

753

28.3. DansGuardian

.28.1. DansGuardian Squid

DansGuardian
(bannedphraselist), , (weightedphraselist exceptionphraselist).
,

. DansGuardian
(. /etc/dansguardian/phraselists).
. , . ,
, /var/log/dansguardian/access.log.
DansGuardian , ! bannedsitelist bannedurllist . ,
.
URLblacklist (http://urlblacklist.com/), Squid-
. . ,
, .
DansGuardian , MP3, (ISO) ..

754

28. Squid DansGuardian ( )

Linux
, . bannedmimetypelist bannedextensionlist ,
. , bannedextensionlist
bannedmimetypelist, dansguardianf1.conf .
DansGuardian xxx, , DansGuardian.
, exceptionip IP- .

DansGuardian! naughtynesslimit=50
( )
. ,
.

.
,
, , . /etc/dansguardian/weightedphraselist.
,
(JavaScript/Flash), (PDF
..).
.
Squid DansGuardian . ( , , ) .
HTTPS-. Squid
HTTPS-.

29

SELinux
AppArmor

SELinux AppArmor ,
, . SELinux Fedora Red Hat AppArmor Ubuntu SUSE.

SELinux AppArmor. , ,
.

29.1. SELinux
Linux :
.
, ( -) .
, . , .. ,

.
UNIX , .
, ,
. , , . ,
.
, ,
. , . ,
. , ,
, .
, ,

756

29. SELinux AppArmor

,
.
. , ,
(
). , ,
. .

setuid, ( Red Hat
Exec Shield) ..
SELinux.
SELinux,
. , SELinux, , .
(Mandatory Access Control, MAC). , SELinux . SELinux , .
, , .
MAC , UNIX. C MAC ,
, .
, ,
- - .
,

. , SELinux
, Linux SELinux , 2.6 .
SELinux. SELinux .
, ,
, SELinux. Red Hat .
Fedora, . ,
Fedora, Red Hat Enterprise.
SELinux Fedora11.
SELinux Red Hat Fedora, . Novell SUSE, Ubuntu
AppArmor . , SUSE
AppArmor SELinux
,

29.1. SELinux

757

. ,
AppArmor.
SELinux. SELinux . ,
- , .
, SELinux. ,
(NFS !).
, .
SELinux .
.
.
.
Linux
SELinux .
SELinux . -
. , .
. SELinux :
http://www.nsa.gov/research/selinux/;
http://sourceforge.net/projects/selinux/;
http://www.crypt.gen.nz/selinux/faq.html;
http://fedoraproject.org/wiki/SELinux.
. SELinux ,
SUSE Ubuntu AppArmor (.29.2). ,
2.6.25 MAC Smack (http://lwn.net/
Articles/252562/). , Smack
SELinux AppArmor.

SELinux
SELinux : -,
, -, , .


SELinux , (, )
(, ) .
.
.
ls -Z. etfattr -n security.
selinux -d _.

758

29. SELinux AppArmor

user$ ls -Z /usr/sbin/httpd
-rwxr-xr-x root root system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd
user$ ls -Z /etc/httpd/conf/httpd.conf
-rw-r--r-- root root system_u:object_r:httpd_config_t:s0 /etc/httpd/conf/httpd.conf
user$ getfattr -n security.selinux -d /etc/httpd/conf/httpd.conf
getfattr: Removing leading '/' from absolute path names
# file: etc/httpd/conf/httpd.conf
security.selinux="system_u:object_r:httpd_config_t:s0\000"

SELinux , . ,
,
SELinux, ,
. ,
chcon:
user$ chcon user_u:object_r:user_home_t _


. () , ps axZ. , ,
.
SELinux.
, (, Firefox) , .
user$ ps axZ | grep httpd
user_u:system_r:httpd_t:s0
user_u:system_r:httpd_t=s0
...

3758 ?
3760 ?

Ss
S

0:00 /usr/sbin/httpd
0:00 /usr/sbin/httpd

, :
:::mls-

, .
SELinux . http://fedoraproject.org/
wiki/SELinux/SecurityContext.

SELinux :
allow 1_t 2_t: { };

: , httpd_t, httpd_log_t.
allow httpd_t httpd_log_t:dir create;

, SELinux
! , SELinux

29.1. SELinux

759

, . ,
. ,
, SELinux
, SELinux: http://
docs.fedoraproject.org/en-US/Fedora/13/html/SELinux_FAQ/.
, .
Strict Fedora 2 strict , , , ,
.
Targeted Fedora3
targeted. .
, ,
, ,
(.).
man :
ftpd_selinux, httpd_selinux, named_selinux, nfs_selinux, samba_selinux ..
:
user$ rpm -qd selinux-policy | grep man8
MLS -

MLS (Multilevel Security, )


( selinux-policy-mls). , RHEL
EAL4.
( ) ,
. :
yy http://fedoraproject.org/wiki/SELinux/FedoraMLSHowto;
yy http://en.wikipedia.org/wiki/Common_Criteria;
yy http://en.wikipedia.org/wiki/Evaluation_Assurance_Level.
SELinux Reference
Policy, Tresys (http://oss.tresys.com/projects/refpolicy).
. SELinux
.

SELinux ()
, , . ,
, targeted , . Fedora/Red Hat
systemconfig-selinux (.29.1). policycoreutils-gui, .
getsebool, ; setsebool .

760

29. SELinux AppArmor

.29.1. SELinux


SELinux , (,
Init-V) . SELinux
.
, /etc/selinux.
/etc/selinux/config. , SELinux (enforcing, permissive disabled)
(strict targeted). , , .
# /etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted

setstatus SELinux.
, SELinux targeted, :
root# sestatus
SELinux status:
SELinuxfs mount:
Current mode:
Mode from config file:
Policy version:
Policy from config file:

enabled
/selinux
enforcing
enforcing
24
targeted

, SELinux
, SELinux :

29.1. SELinux

761

, ,
system-config-security;
, ;
; -

SELinux, , , ;
SELinux .

, SELinux, . , , HTML-, NFS /var/


www/html cp -a, Apache . , cp a
, SELinux. -
, /var/www/html,
SELinux. HTML- system_u:object_r:nfs_t,
user_u:object_r:httpd_sys_content_t.
, cp -a cp -r.
Apache SELinux.
, ,
You dont have permission to access <filename> (
< >). /var/log/messages, ,
- SELinux.
root# less /var/log/messages
...
Aug 31 12:45:45 mars setroubleshoot: SELinux is preventing the
httpd from using potentially mislabeled files (test.html).
For complete SELinux messages run sealert -l 2f35f9a0-bd1b-40ab-9779-3a640b99ef10

sealert, ,
100- ,
.
root# sealert -l dccb472d-6dd8-49d2-b7d7-2658e082c805
SELinux /usr/sbin/httpd index.html.
***** Plugin catchall_boolean (89.3 confidence) suggests *******************
httpd , SELinux
, 'httpd_read_user_content'.
'user_selinux', . setsebool-P
httpd_read_user_content 1
***** Plugin catchall (11.6 confidence) suggests ***************************
, httpd
index.html, .
, .
, :
# grep httpd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
...

762

29. SELinux AppArmor

, .
,
restorecon:
root# restorecon -R -v /var/www/html/*

SELinux
SELinux , systemconfig-security Permissive. SELinux
/var/log/messages.
SELinux , . setenforce 0.
, SELinux system-config-security
( Disabled). ,
. ,
SELinux,
. SELinux,
, , .
restorecon,
.
SELinux
, selinux=0, SELinux .
. enforcing=0. SELinux
, .

29.2. AppArmor
SELinux, Novell
2005 Immunix Subdomain
( ) AppArmor. Novell
AppArmor GPL YaST . , AppArmor Linux
2.6.36. AppArmor SUSE Ubuntu.
2007 Novell AppArmor.
Novell (openSUSE) AppArmor . AppArmor,
, ,
, . AppArmor , , , Canonical.
SELinux, AppArmor MAC ( ). SELinux, AppArmor
.
(EA). , AppArmor

29.2. AppArmor

763

, EA. AppArmor
.
AppArmor , SELinux.
AppArmor SELinux: .
, AppArmor .
Red Hat ,
( AppArmor , ; ,
).
AppArmor , SELinux. .
,
.
. AppArmor.
:
http://www.novell.com/documentation/apparmor/ ( PDF);
https://help.ubuntu.com/community/AppArmor;
https://wiki.ubuntu.com/SecurityTeam/KnowledgeBase/AppArmorProfiles.

AppArmor Ubuntu
AppArmor, Ubuntu12.04.
, SUSE, AppArmor SUSE .
Ubuntu AppArmor .
Init-V /etc/init.d/boot.apparmor,
, /lib/apparmor/rc.apparmor.functions. boot.apparmor /etc/apparmor
/etc/apparmor.d.
Init-V , /etc/apparmor/
rc.apparmor.functions.
aa-status AppArmor.
, , . ,
Ubuntu .
root# aa-status
apparmor module is loaded.
6 profiles are loaded.
6 profiles are in enforce mode.
/sbin/dhclient
/usr/lib/NetworkManager/nm-dhcp-client.action
/usr/lib/connman/scripts/dhclient-script
/usr/sbin/mysqld
/usr/sbin/ntpd
/usr/sbin/tcpdump

764
0
2
2


0
0

29. SELinux AppArmor

profiles are in complain mode.


processes have profiles defined.
processes are in enforce mode.
/usr/sbin/mysqld (851)
/usr/sbin/ntpd (14794)
processes are in complain mode.
processes are unconfined but have a profile defined.

AppArmor securityfs
/sys/kernel/security.
, ..

()
AppArmor . /etc/apparmor.d/.
. Ubuntu /etc/apparmor.d
.
, apparmor-profiles
universe. , ,
, .
complain-. , . aa-enforce aacomplain .
, .
root# aa-enforce /usr/sbin/dnsmasq
Setting /usr/sbin/dnsmasq to enforce mode.
root# aa-complain /usr/sbin/dnsmasq
Setting /usr/sbin/dnsmasq to complain mode.

aa-enforce aa-complain
. ,
:
root# cd /etc/apparmor.d
root# aa-enforce usr.lib.dovecot*

AppArmor
:
root# service <name> restart

AppArmor , , ,
.
, ,
aa-status.
Ubuntu, ,
, /usr/share/doc/apparmorprofiles/
extras/. README,
. , complain,

765

29.2. AppArmor

, ,
. aa-logprof (. man aa-logprof).
, , enforce.


, AppArmor Profile (),
.
AppArmor named:
#include <tunables/global>
/usr/sbin/named {
#include <abstractions/base>
#include <abstractions/nameservice>




capability
capability
capability
capability
capability

net_bind_service,
setgid,
setuid,
sys_chroot,
sys_resource,

# /etc/bind bind.
# /var/lib/bind .
# /var/cache/bind /,
# .
# . /usr/share/doc/bind9/README.Debian.gz
/etc/bind/** r,
/var/lib/bind/** rw,
/var/lib/bind/ rw,
/var/cache/bind/** rw,
/var/cache/bind/ rw,

# gssapi
/etc/krb5.keytab kr,
/etc/bind/krb5.keytab kr,

# ssl
/etc/ssl/openssl.cnf r,

# dnscvsutil
/var/lib/dnscvsutil/compiled/** rw,

/proc/net/if_inet6 r,
/proc/*/net/if_inet6 r,
/usr/sbin/named mr,
/var/run/named/named.pid w,
/var/run/named/session.key w,
# resolvconf
/var/run/named/named.options r,

766




}

29. SELinux AppArmor

# /var/log/named/,
# syslog
/var/log/named/** rw,
/var/log/named/ rw,

(include-)
, (. man
capabilities). ,
.
AppArmor * . ** ,
, , /. ,
. .
.29.1 . ?x
, .
29.1. AppArmor

(read)

(write)

(append)

, (link)

(lock)

mmap ( )

ix

(inherent execute)

px

AppArmor (discrete profile execute)

ux

AppArmor (unconstrained execute)

(tunables)
AppArmor ,
. /etc/apparmor.d/
tunables. ,
/proc. , /home, @{HOMEDIRS}.
# /etc/apparmor.d/tunables/home
@{HOME}=@{HOMEDIRS}/*/ /root/
@{HOMEDIRS}=/home/ /home1/ /myhome/
# /etc/apparmor.d/tunables/proc
@{PROC}=/proc/


,
complain enforce, -

767

29.2. AppArmor

/var/log/kern.log /var/log/syslog .
AppArmor audit.
root#
[...]


[...]

grep audit /var/log/kern.log


audit(1238580174.435:3): type=1503 operation="inode_permission"
requested_mask="a::" denied_mask="a::" name="/dev/tty"
pid=6345 profile="/usr/sbin/cupsd" namespace="default"
audit(1238580174.435:4): type=1503 operation="inode_permission"
requested_mask="w::" denied_mask="w::" name="/etc/krb5.conf"
pid=6345 profile="/usr/sbin/cupsd" namespace="default"

99% audit- , AppArmor


. , , ,
.
. ,
.
, ,
complain- audit- Ubuntu (https://bugs.launchpad.net/). , ,
. ,
. , AppArmor.

AppArmor SUSE

openSUSE 12.1 AppArmor .
AppArmor, . YaST-
Novell AppArmor.
AppArmor Init-V /etc/init.d/boot.
apparmor. , /lib/apparmor/
rc.apparmor.functions. boot.apparmor
/etc/apparmor /etc/apparmor.d.
SELinux, AppArmor . ,
, /etc/apparmor/profiles/extras.
.
, , ,
AppArmor :
root# /etc/init.d/boot.apparmor restart
root# /etc/init.d/boot.apparmor reload

( AppArmor)
( AppArmor)

YaST
AppArmor YaST
SUSE (.29.2).

768

29. SELinux AppArmor

AppArmor () enforce complain. complain , .

.29.2. AppArmor YaST

Edit Profile ( )
. , ,
. YaST
.
Add Profile Wizard ( ):
. ,
. AppArmor,
.
, .
.
/etc/apparmor.d/programmname.
.
: , ,
, .
. ,
.
,
Update Profile Wizard ( ), . AppArmor,
,
.

Вам также может понравиться