Merge remote-tracking branch 'origin/github/pr/45'
[grml.org.git] / docs / grml-doc-4.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4  <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.21">
5  <TITLE>grml - Linux for system administrators and texttool users: sysadmin tasks</TITLE>
6  <LINK HREF="grml-doc-5.html" REL=next>
7  <LINK HREF="grml-doc-3.html" REL=previous>
8  <LINK HREF="grml-doc.html#toc4" REL=contents>
9 </HEAD>
10 <BODY>
11 <A HREF="grml-doc-5.html">Next</A>
12 <A HREF="grml-doc-3.html">Previous</A>
13 <A HREF="grml-doc.html#toc4">Contents</A>
14 <HR>
15 <H2><A NAME="s4">4.</A> <A HREF="grml-doc.html#toc4">sysadmin tasks</A></H2>
16
17 <H2><A NAME="ss4.1">4.1</A> <A HREF="grml-doc.html#toc4.1">resize NTFS partition</A>
18 </H2>
19
20
21 <P>Let's assume you have a harddisk with a single partition using NTFS as the
22 filesystem. Now you would like to resize the partition so you can install
23 Linux to it. Run:</P>
24 <P>
25 <BLOCKQUOTE><CODE>
26 <HR>
27 <PRE>
28 ntfsresize --no-action --size 20000M /dev/hda1
29 </PRE>
30 <HR>
31 </CODE></BLOCKQUOTE>
32 </P>
33 <P>to check wheter it works. If you do not notice any errors you can drop the
34 '--no-action'-option and resize the partition. For more details take a look
35 at 
36 <A HREF="http://linux-ntfs.sourceforge.net/info/ntfsresize.html">the ntfsresize-homepage</A>.</P>
37
38 <H2><A NAME="ss4.2">4.2</A> <A HREF="grml-doc.html#toc4.2">backup and restore Master Boot Record (MBR)</A>
39 </H2>
40
41 <P>Backup the MBR via:</P>
42 <P>
43 <BLOCKQUOTE><CODE>
44 <HR>
45 <PRE>
46 dd if=/dev/hda of=hda.mbr bs=512 count=1
47 </PRE>
48 <HR>
49 </CODE></BLOCKQUOTE>
50 </P>
51 <P>and restore it via:</P>
52 <P>
53 <BLOCKQUOTE><CODE>
54 <HR>
55 <PRE>
56 dd if=hda.mbr of=/dev/hda bs=512 count=1
57 </PRE>
58 <HR>
59 </CODE></BLOCKQUOTE>
60 </P>
61 <P>Caution: the MBR contains the partition table (the first four primary
62 entries). If you changed the partition since creating the backup-file
63 you will probably lose your partitions.</P>
64 <P>If you do not want to restore the partition table you should use with
65 'bs=448' instead. This will write only the first 448 bytes of the
66 MBR leaving the last 64 bytes intact (4 partition table entries * 16
67 bytes/entry).</P>
68
69 <H2><A NAME="ss4.3">4.3</A> <A HREF="grml-doc.html#toc4.3">backup and restore harddisc</A>
70 </H2>
71
72 <P>
73 <BLOCKQUOTE><CODE>
74 <HR>
75 <PRE>
76 zcat /mnt/Backup/hda1.dd.gz | dd of=/dev/hdb1
77 </PRE>
78 <HR>
79 </CODE></BLOCKQUOTE>
80 </P>
81 <P>You might want to use a specific blocksize to improve performance.
82 Specify it via 'bs=...k', values from 4k up to 1024k might fit your
83 needs.</P>
84
85 <H2><A NAME="ss4.4">4.4</A> <A HREF="grml-doc.html#toc4.4">clone harddisc</A>
86 </H2>
87
88 <P>
89 <BLOCKQUOTE><CODE>
90 <HR>
91 <PRE>
92 dd if=/dev/hda of=/dev/hdb
93 </PRE>
94 <HR>
95 </CODE></BLOCKQUOTE>
96 </P>
97 <P>Notice: this includes of course the bootsector too!
98 More detailed information is available in the
99 <A HREF="http://www.tldp.org/HOWTO/Hard-Disk-Upgrade/">Hard-Disk-Upgrade HowTo</A>.</P>
100
101 <P>TODO: backup via network (netcat/scp/...)</P>
102 <P>tar -cf - directory | ssh user@remote tar -xf - -C /dest/dir
103 dd if=image | ssh fileserver "cd /tmp; dd of=image"</P>
104 <P>vom client zum server:
105 dd if=/dev/hda1 | ssh fileserver 'cat > image'</P>
106 <P>vom server zum client:
107 ssh client 'dd if=/dev/hda' > image</P>
108 <P>-> unbedingt Blocksize anpassen wegen Performance!</P>
109 <P>http://lists.suse.com/archive/suse-linux/2004-May/2786.html</P>
110 <P>Komplettes Partitions Backup (Image):</P>
111 <P>mount /dev/hda1 / -o remount,rw;
112 dd if=/dev/zero of=/delme1 bs=4048; rm /delme1;
113 mount /dev/hda1 / -o remount,ro;</P>
114 <P>Lokal:</P>
115 <P>dd if=/dev/hda1 bs=4048 | bzip2 > /mountpoint/image_hda1.bz;</P>
116 <P>Netzwerk:</P>
117 <P>ssh host -c blowfish 'dd if=/dev/hda1 bs=4048 | bzip2' | dd of=/image_hda1.bz</P>
118 <P>Entfernten Rechner mit tar sichern:</P>
119 <P>ssh root@otherhost -c blowfish 'tar -f - -p -P -c --exclude=/tmp --exclude=/var/cache /' | dd of=/daten/backup.tar</P>
120 <P>Remote backup via rsync:
121 rsync --delete -avze ssh /home/mika/ mika@mari:/Backup/</P>
122 <P>grml-system klonen:
123 rsync -avzp --rsh="ssh -l root -p 66" /Grml/grml_uncompressed remote:/Grml/</P>
124
125 <H2><A NAME="ss4.5">4.5</A> <A HREF="grml-doc.html#toc4.5">install lilo</A>
126 </H2>
127
128 <P>Mount your root partition with the dev-flag:
129 <BLOCKQUOTE><CODE>
130 <HR>
131 <PRE>
132 mount -o dev /mnt/hda1
133 </PRE>
134 <HR>
135 </CODE></BLOCKQUOTE>
136 </P>
137 <P>Then adjust /mnt/hda1/etc/lilo.conf. Now execute lilo in the chroot:</P>
138 <P>
139 <BLOCKQUOTE><CODE>
140 <HR>
141 <PRE>
142 chroot /mnt/hda1 lilo
143 </PRE>
144 <HR>
145 </CODE></BLOCKQUOTE>
146 </P>
147
148 <H2><A NAME="ss4.6">4.6</A> <A HREF="grml-doc.html#toc4.6">install grub</A>
149 </H2>
150
151 <P>TODO: grub-install</P>
152
153 <H2><A NAME="ss4.7">4.7</A> <A HREF="grml-doc.html#toc4.7">rescue partition(s)/-tables</A>
154 </H2>
155
156 <P>TODO: ntfsresize, parted, ntfsclone</P>
157
158 <H2><A NAME="ss4.8">4.8</A> <A HREF="grml-doc.html#toc4.8">restore password</A>
159 </H2>
160
161 <P>You can change the password of a Linux system via chrooting into:
162 <BLOCKQUOTE><CODE>
163 <HR>
164 <PRE>
165 mount /dev/hda1    # mount rootpartition, make sure it is mounted read-writeable!
166 chroot /mnt/hda1
167 passwd root
168 </PRE>
169 <HR>
170 </CODE></BLOCKQUOTE>
171 </P>
172 <P>or via using /bin/sh instead of the init-system:</P>
173 <P>
174 <BLOCKQUOTE><CODE>
175 <HR>
176 <PRE>
177 linux init=/bin/sh       # boot with bootparam init
178 mount -o remount,rw /    # mount root partition read-writeable
179 /usr/bin/passwd          # now set the password
180 mount -n -o remount,ro / # remount / read-only
181 /sbin/init 6             # reboot
182 </PRE>
183 <HR>
184 </CODE></BLOCKQUOTE>
185 </P>
186 <P>If you don't have /usr/bin/passwd available you could change
187 /etc/passwd. Just remove the 'x' in the line containing information
188 about user root, just change:</P>
189 <P>
190 <BLOCKQUOTE><CODE>
191 <HR>
192 <PRE>
193 root:x:0:0:root:/root:/bin/zsh
194 </PRE>
195 <HR>
196 </CODE></BLOCKQUOTE>
197 </P>
198 <P>to something like:</P>
199 <P>
200 <BLOCKQUOTE><CODE>
201 <HR>
202 <PRE>
203 root::0:0:root:/root:/bin/zsh
204 </PRE>
205 <HR>
206 </CODE></BLOCKQUOTE>
207 </P>
208 <P>or you could even remove the hash in /etc/shadow, change:</P>
209 <P>
210 <BLOCKQUOTE><CODE>
211 <HR>
212 <PRE>
213 root:foooobaaaarrrr.:11808:0:10000::::
214 </PRE>
215 <HR>
216 </CODE></BLOCKQUOTE>
217 </P>
218 <P>into something like this:</P>
219 <P>
220 <BLOCKQUOTE><CODE>
221 <HR>
222 <PRE>
223 root::11808:0:10000:::
224 </PRE>
225 <HR>
226 </CODE></BLOCKQUOTE>
227 </P>
228
229 <H2><A NAME="ss4.9">4.9</A> <A HREF="grml-doc.html#toc4.9">rescue a Linux system (Debian)</A>
230 </H2>
231
232 <P>You have a system which does not boot anymore because there have been
233 problems at the last upgrade? Just mount the root-partition and chroot
234 into it:
235 <BLOCKQUOTE><CODE>
236 <HR>
237 <PRE>
238 mount /mnt/hda1
239 chroot /mnt/hda1
240 </PRE>
241 <HR>
242 </CODE></BLOCKQUOTE>
243 </P>
244 <P>Now you can run commands within your 'damaged system'.
245 Notice: 'chroot /mnt/hda1 /bin/bash' might be required
246 if /mnt/hda1 does not contain a zsh because chroot invokes
247 $SHELL.</P>
248
249 <H2><A NAME="ss4.10">4.10</A> <A HREF="grml-doc.html#toc4.10">setting up a firewall</A>
250 </H2>
251
252 <H2><A NAME="ss4.11">4.11</A> <A HREF="grml-doc.html#toc4.11">setting up a gateway</A>
253 </H2>
254
255 <H2><A NAME="ss4.12">4.12</A> <A HREF="grml-doc.html#toc4.12">setting up a transparent bridge</A>
256 </H2>
257
258 <H2><A NAME="ss4.13">4.13</A> <A HREF="grml-doc.html#toc4.13">scan for virus</A>
259 </H2>
260
261 <P>Let's assume you want to check for virus on your hard disc.
262 Mount the partition and run clamscan:</P>
263 <P>
264 <BLOCKQUOTE><CODE>
265 <HR>
266 <PRE>
267 mount /mnt/hda1        # mount the partition you want to scan
268 clamscan -r /mnt/hda1
269 </PRE>
270 <HR>
271 </CODE></BLOCKQUOTE>
272 </P>
273 <P>TODO: freshclam</P>
274
275 <H2><A NAME="ss4.14">4.14</A> <A HREF="grml-doc.html#toc4.14">rootkits, intruders &amp; co</A>
276 </H2>
277
278 <P>Use chkrootkit to scan for rootkits.
279 <BLOCKQUOTE><CODE>
280 <HR>
281 <PRE>
282 mount /mnt/hda1  # assuming that hda1 contains your root-partition, adjust it!
283 chkrootkit -r /mnt/hda1
284 </PRE>
285 <HR>
286 </CODE></BLOCKQUOTE>
287 </P>
288 <P>If you don't want to run integrity checkers like tripwire/aide on your systems
289 you could create md5sums of the binaries:</P>
290 <P>
291 <BLOCKQUOTE><CODE>
292 <HR>
293 <PRE>
294 mount /mnt/hdaX  # assuming that hda1 contains your root-partition, adjust it!
295 find /mnt/hda1/bin /mnt/hda1/usr/bin /mnt/hda1/sbin /mnt/hda1/usr/sbin -type f -print0 | xargs -0 md5sum > /tmp/md5sum.clean
296 sort /tmp/md5sum.clean > /tmp/md5sum.clean.sorted
297 </PRE>
298 <HR>
299 </CODE></BLOCKQUOTE>
300 </P>
301 <P>In case of a possible infection you could run the command again
302 (adjusting 'clean' to e.g. 'check') and compare the two md5sum-files
303 (preferably the sorted ones) via the diff-command.</P>
304
305
306
307 <H2><A NAME="ss4.15">4.15</A> <A HREF="grml-doc.html#toc4.15">System information</A>
308 </H2>
309
310 <P>Interactive tools:
311 <BLOCKQUOTE><CODE>
312 <HR>
313 <PRE>
314 Performance Tools: System CPU.
315       vmstat (Virtual Memory Statistics)
316       top
317       procinfo (Display Info from the /proc File System)
318       gnome-system-monitor
319       mpstat (Multiprocessor Stat)
320       sar (System Activity Reporter)
321       oprofile
322
323 Performance Tools: System Memory.
324       vmstat  (Virtual Memory Statistics)
325       top
326       procinfo
327       gnome-system-monitor
328       free
329       slabtop
330       sar
331       /proc/meminfo
332
333 Performance Tools: Process-Specific CPU.
334       time
335       strace
336       ltrace
337       ps (Process Status)
338       ld.so (Dynamic Loader)
339       gprof
340       oprofile
341
342 Performance Tools: Process-Specific Memory.
343       ps
344       /proc/\&lt;PID\>
345       memprof
346       valgrind (cachegrind)
347       kcachegrind
348       oprofile
349       ipcs
350
351 Performance Tools: Disk I/O.
352       vmstat
353       dstat
354       iostat
355       sar
356       lsof  (List Open Files)
357
358 Performance Tools: Network.
359       mii-tool (Media-Independent Interface Tool)
360       ethtool
361       ifconfig (Interface Configure)
362       ip
363       sar
364       gkrellm
365       iptraf
366       netstat
367       etherape
368
369 Utility Tools: Performance Tool Helpers.
370       bash/zsh
371       tee
372       script
373       watch
374       ldd
375       objdump
376       GNU Debugger (gdb)
377       gcc (GNU Compiler Collection)
378
379 Schedutils: CPU related stuff
380       schedtool
381       chrt
382       taskset
383 </PRE>
384 <HR>
385 </CODE></BLOCKQUOTE>
386 </P>
387
388 <HR>
389 <A HREF="grml-doc-5.html">Next</A>
390 <A HREF="grml-doc-3.html">Previous</A>
391 <A HREF="grml-doc.html#toc4">Contents</A>
392 </BODY>
393 </HTML>