Added some further tips (SSL debugging, lilo/grub, screenshot..)
[grml-tips.git] / grml_tips
1 Install grml to harddisk:
2
3 # grml2hd
4
5 Notice: You can pre-select the partition for the partition selector
6 and mbr dialogs inside grml2hd using:
7 # grml2hd /dev/hda1 -mbr /dev/hda
8
9 See: man grml2hd + http://grml.org/grml2hd/
10 -- 
11 Install grml on software RAID level 1:
12
13 Create /dev/md0 (and some more /dev/md* devices) first of all:
14 # cd /dev && MAKEDEV dev
15
16 Create RAID:
17 # mdadm --create --verbose /dev/md0 --level=raid1 \
18         --raid-devices=2   /dev/hda1  /dev/hdc1
19
20 Finally install grml on it:
21 # SWRAID='mbr-only' grml2hd /dev/md0 -mbr /dev/md0
22
23 See: man grml2hd + http://grml.org/grml2hd/
24 -- 
25 Install grml in non interactive mode with grml2hd:
26
27 Adjust configuration as needed:
28 # vim /etc/grml2hd/config
29
30 Then execute:
31
32 # GRML2HD_NONINTERACTIVE=yes grml2hd
33
34 or run:
35
36 # grml2hd -i
37
38 Use with care and only if you really know what you are doing!
39
40 See: man grml2hd + http://grml.org/grml2hd/
41 -- 
42 Configure network:
43
44 # grml-network
45 -- 
46 Boot grml via network:
47
48 # grml-terminalserver
49
50 See: man grml-terminalserver + http://grml.org/terminalserver/
51 -- 
52 Deactivate error correction of zsh:
53
54 % NOCOR=1 zsh
55
56 Run zsh-help for more information regarding zsh.
57 -- 
58 Disable automatic setting of title in GNU screen:
59
60 % NOPRECMD=1 zsh
61
62 Set it manually e.g. via:
63
64 % screen -X title foobar
65
66 Run zsh-help for more information regarding zsh.
67 -- 
68 Do not use menu completion in zsh:
69
70 % NOMENU=1 zsh
71
72 Run zsh-help for more information regarding zsh.
73 -- 
74 Run GNU screen with grml-configuration:
75
76 % grml-screen
77
78 or
79
80 % screen -c /etc/grml/screenrc
81 -- 
82 Print out grml-version:
83
84 % grml-version
85 -- 
86 Configure mutt:
87
88 % grml-mutt
89 -- 
90 Configure mutt-ng / muttng:
91
92 % grml-muttng
93 -- 
94 Set up Inode-PPTP connection:
95
96 # grml-pptp-inode
97 or
98 # grml-pptp-xdsl-students
99 -- 
100 Set up VPN / WLAN connection at TUG (TU Graz):
101
102 Set ESSID and request for ip-address via DHCP:
103 # iwconfig $DEVICE essid tug
104 # dhclient $DEVICE
105
106 Now run the main script:
107 # grml-vpnc-tugraz
108
109 After running the script an init script is available:
110
111 # /etc/init.d/vpnctug [start|stop]
112 -- 
113 Set up PPTP connection at VCG (Virtual Campus Graz):
114
115 # grml-pptp-vcgraz
116 -- 
117 Set up VPN:
118
119 # grml-vpn <options>
120
121 Usage example:
122
123 # grml-vpn -k 2005 add 1000 192.168.20.1 192.168.20.2
124
125 See: man grml-vpn
126 -- 
127 Use encrypted files / partitions:
128
129 # grml-crypt <options>
130
131 Usage example:
132
133 Initialize:
134
135 # grml-crypt format /mnt/external1/encrypted_file /mnt/test
136 # cp big_file /mnt/test
137 # grml-crypt stop /mnt/test
138
139 Use:
140
141 # grml-crypt start /mnt/external1/encrypted_file /mnt/test
142 # grml-crypt stop /mnt/test
143
144 See: man grml-crypt
145 -- 
146 Change resolution of X:
147
148 % xrandr -s '1024x768'
149 -- 
150 Change resolution of framebuffer:
151
152 # fbset 800x600-60
153 -- 
154 Configure newsreader slrn:
155
156 % grml-slrn
157 -- 
158 Configure grml system:
159
160 # grml-config
161
162 Or directly run scripts:
163
164 # grml-config-root
165 % grml-config-user
166 -- 
167 Lock screen (X / console):
168
169 % grml-lock
170
171 Press ctrl-alt-x to lock a GNU screen session.
172 -- 
173 Change wallpaper in X:
174
175 % grml-wallpaper <press-tab>
176 -- 
177 Start X window system (XFree86 / Xorg / X.org):
178
179 % grml-x $WINDOWMANAGER
180
181 Usage examples:
182
183 % grml-x fluxbox
184 % grml-x -mode '1024x768' wmii
185 % grml-x -nosync wm-ng
186 -- 
187 Collect hardware information:
188
189 % grml-hwinfo
190
191 or run as root to collect some more information:
192
193 # grml-hwinfo
194
195 will generate a file named info.tar.bz2.
196 -- 
197 Configure hardware detection features of harddisk installation:
198
199 # grml-autoconfig
200
201 or manually edit /etc/grml/autoconfig[.small]
202
203 See: man grml-autoconfig
204 -- 
205 Bootoptions / cheatcodes / bootparams for booting grml:
206
207 On the grml-ISO if not running grml:
208 % less /cdrom/GRML/grml-cheatcodes.txt
209
210 When running grml:
211 % most /usr/share/doc/grml-docs/grml-cheatcodes.txt.gz
212 -- 
213 Report bugs to Debian's Bug Tracking System (BTS):
214
215 % reportbug --bts debian
216
217 or adjust /etc/reportbug.conf to your needs.
218
219 See:
220
221   http://grml.org/bugs/
222   http://www.debian.org/Bugs/
223 -- 
224 Offline documentation:
225
226 % grml-info
227
228 Online documentation:
229
230   http://grml.org/faq/
231   http://grml.org/docs/
232   http://wiki.grml.org/doku.php
233 -- 
234 Mount ntfs partition (read-write):
235
236 # modprobe fuse
237 # ntfsmount /dev/hda1 /mnt/hda1
238 -- 
239 Overwrite specific file on an NTFS partition:
240
241 ntfscp /dev/hda1 /tmp/file_source path/to/file_target
242 -- 
243 Resize an NTFS partition:
244
245 # ntfsresize ..
246
247 Usage example:
248
249 ntfsresize -n -s 10G /dev/hda1 # testcase
250 ntfsresize -s 10G /dev/hda1    # testing was successfull, now really resize partition
251 cfdisk /dev/hda   # delete partition hda1, create new one with 10000MB and fs-type 07 (NTFS)
252 -- 
253 Modify resolution for intel graphic chipsets:
254
255 # 915resolution ..
256
257 Usage example:
258
259 # 915resolution 4d 1400 1050
260 -- 
261 Connect bluetooth mouse:
262
263 # bt-hid start
264
265 ... and press 'connect' button on your bluetooth device.
266 -- 
267 Connect bluetooth headset:
268
269 # bt-audio start
270
271 ... and press 'connect' button on your bluetooth device.
272 -- 
273 Secure delete file / directory / partition:
274
275 # wipe -kq /dev/hda1
276
277 See: man wipe
278
279 Also take a look at shred(1), sfill(1) and http://dban.sourceforge.net/
280 -- 
281 Use grml on Samsung X20 laptop:
282
283 # apt-get install grml-samsung-x20
284
285 See: http://www.michael-prokop.at/computer/samsung_x20.html
286 -- 
287 Development information regarding grml:
288
289   http://grml.supersized.org/
290 -- 
291 Contact grml team:
292
293 #grml on irc.freenode.org - http://grml.org/irc/
294 http://grml.org/contact/
295 -- 
296 Join the grml mailinglist:
297
298 http://grml.org/mailinglist/
299 -- 
300 Help us - donate!
301
302 http://grml.org/donations/
303 -- 
304 Commercial support / system administration / adjusted live-cds:
305
306 grml-solutions: http://grml.org/solutions/
307 -- 
308 Information regarding the kernel provided by grml:
309
310   http://grml.org/kernel/
311 -- 
312 SMTP command-line test tool:
313
314 % swaks <options>
315
316 Usage example:
317
318 % swaks -s $MAILSERVER -tlsc -a -au $ACCOUNT -ap $PASSWORD -f $MAILADRESSE -t $MAILADRESSE
319
320 See: man swaks
321 -- 
322 NTFS related packages:
323
324 scrounge-ntfs
325 salvage-ntfs
326 ntfsprogs
327 -- 
328 Modify service through init script:
329
330 # Start ssh
331 # Stop samba
332 # Restart apache
333 # Reload postfix
334 # service gpm start
335 # /etc/init.d/lvm start
336 -- 
337 Test joystick:
338
339 # jstest /dev/input/js0
340 -- 
341 Play movie:
342
343 % mplayer /path/to/movie
344 -- 
345 Use webcam with mplayer:
346
347 % mplayer tv:// -tv driver=v4l:width=352:height=288:outfmt=yv12:device=/dev/video0
348 -- 
349 Powerful network discovery tool:
350
351 # scapy
352 -- 
353 Grab an entire CD and compress it to Ogg/Vorbis,
354 MP3, FLAC, Ogg/Speex and/or MPP/MP+(Musepack) format:
355
356 % abcde
357 -- 
358 Show a console session in several terminals:
359
360 % gems
361 -- 
362 Switch behaviour of caps lock key:
363
364 % caps-ctrl
365 -- 
366 grep with Perl-compatible regular expressions:
367
368 % pcregrep
369 -- 
370 ncp: a fast file copy tool for LANs
371
372 Local (send file):
373 % npush file_to_copy
374
375 Remote (receive file):
376 % npoll
377 -- 
378 utility for sorting records in complex ways:
379
380 % msort
381 -- 
382 a smaller, cheaper, faster SED implementation:
383
384 % minised
385 -- 
386 zsh tips:
387
388 % man zsh-lovers
389
390 See: http://grml.org/zsh/
391 -- 
392 zsh reference card for grml system:
393
394 http://grml.org/zsh/
395 /usr/share/doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz
396 -- 
397 Multiple rename:
398
399 % for i in foo* ; do mv "$i" "bar${i/foo}" ; done
400 % qmv foo*
401 % prename 's/foo/bar/' foo*
402 % mmv "foo*"   "bar#1"
403 % zmv 'foo(*)' 'bar$1'
404 -- 
405 Test TFT / LCD display:
406
407 % lcdtest
408 -- 
409 Test sound:
410
411 % soundtest
412 -- 
413 Improved grep version:
414
415 % glark
416 -- 
417 Grep with highlighting:
418
419 % grep --color=auto ...
420 % hgrep ...
421 -- 
422 Extract matches when grepping:
423
424 Usage examples:
425 % ifconfig | grepc 'inet addr:(.*?)\s'
426 % ifconfig | glark --extract-matches 'inet addr:(.*?)\s'
427 -- 
428 Output text as sound:
429
430 % say 'ghroummel'
431 % xsay            # when running X and text selected via mouse
432 -- 
433 Adjust a grml harddisk (grml2hd) installation:
434
435 # grml2hd-utils
436 -- 
437 Get information on movie files:
438
439 % tcprobe -i file.avi
440 -- 
441 Get an overview of your image files:
442
443 % convert 'vid:*.jpg' thumbnails.jpg
444 -- 
445 List all standard defines:
446
447 % gcc -dM -E - < /dev/null
448 -- 
449 Send a mail as reminder:
450
451 echo "mail -s 'check TODO-list' $MAILADDRESS < /dev/null" | at 23:42
452 -- 
453 ncurses-based presentation tool:
454
455 % tpp
456
457 See: man tpp and /usr/share/doc/tpp/examples/
458 -- 
459 Use ICQ / Jabber / Yahoo! / AIM / MSN /... on command line:
460
461 % centericq
462 -- 
463 Use IRC on command line:
464
465 % irssi
466 -- 
467 Diff / merge files:
468
469 % vimdiff file1 file2
470
471 Re-diffing:
472
473 :diffupdate
474
475 Moving between diffs:
476
477 [c
478 ]c
479
480 Synchronizing:
481
482 :diffget
483 :diffput
484 -- 
485 Hardware monitoring without kernel dependencies:
486
487 % mbmon
488 -- 
489 Install grml-iso to usb-stick:
490
491 % grml2usb grml.iso /mount/point
492 -- 
493 Use mplayer on framebuffer console:
494
495 % mplayer -vo fbdev ...
496 -- 
497 Use links2 on framebuffer console:
498
499 % links2 -driver fb ...
500 -- 
501 Switch language / keyboard:
502
503 * use the bootparam lang to set language environment ($LANG, $LC_ALL, $LANGUAGE)
504 * use the bootparams keyboard / xkeyboard to activate specific keyboard layout
505   Usage example: 'grml lang=us keyboard=de xkeyboard=de'
506
507 Or run one of the following commands:
508
509 % grml-lang de
510 or
511 # loadkeys i386/qwertz/de-latin1-nodeadkeys.kmap.gz # console
512 % setxkbmap de                                      # X11
513 -- 
514 Switch setting of caps-control key (switch between ctrl + shift) on keyboard:
515
516 # caps-ctrl
517 -- 
518 Mount usb device / usb stick:
519
520 % mount /mnt/external1   # corresponds to /dev/sda1
521 or
522 % mount /mnt/external    # corresponds to /dev/sda
523 -- 
524 Install Sun Java packages:
525
526 Download j2re.bin-file from http://java.sun.com/downloads/index.html and run
527
528 # apt-get install java-package
529 # fakeroot make-jpkg j2re-*.bin
530 # dpkg -i sun-j2re*.deb
531 # update-alternatives --config java
532 -- 
533 Improved dd version:
534
535 ddrescue is an improved version of dd which tries to read and
536 if it fails it will go on with the next sectors, where tools
537 like dd will fail.
538
539 % ddrescue ...
540
541 See: man ddrescue
542 -- 
543 How to make an audio file (e.g. Musepack format) out of a DVD track:
544
545 % mkfifo /tmp/fifo.wav
546 % mppenc /tmp/fifo.wav track06.mpc &
547 % mplayer -vo null -vc null -ao pcm:fast:file=/tmp/fifo.wav -dvd-device /dev/dvd dvd://1 -chapter 6-6
548
549 Adjust the mppenc line with the encoder you would like to use,
550 for example 'oggenc -o track06.ogg /tmp/fifo.wav' for ogg files.
551
552 Alternative:
553
554 % mplayer -vo null -dumpaudio -dumpfile track06.raw -aid N -dvd-device /dev/dvd dvd://1 -chapter 6-6
555 to extract audio without processing, where 'N' is the corresponding audio channel (see 'man mplayer')
556
557 Usage example for getting a PCM/wave file from audio channel 128:
558 % mplayer -vo null -vc null -ao pcm:fast:file=track06.wav -aid 128 -dvd-device /dev/dvd dvd://6
559 -- 
560 Create simple chroot:
561
562 # make_chroot_jail $USERNAME
563 -- 
564 Convert DOS formated file to unix format:
565
566 sed 's/.$//'    dosfile > unixfile       # assumes that all lines end with CR/LF
567 sed 's/^M$//'   dosfile > unixfile       # in bash/tcsh, press Ctrl-V then Ctrl-M
568 sed 's/\x0D$//' dosfile > unixfile       # gsed 3.02.80, but top script is easier
569 awk '{sub(/\r$/,"");print}'              # assumes EACH line ends with Ctrl-M
570 gawk -v BINMODE="w" '1' infile >outfile  # in DOS environment; cannot be done with
571                                          # DOS versions of awk, other than gawk
572 tr -d \r < dosfile > unixfile            # GNU tr version 1.22 or higher
573 tr -d '\015' < dosfile > unixfile        # use octal value for "\r" (see man ascii)
574 tr -d '[\015\032]' < dosfile > unixfile  # sometimes ^Z is appended to DOS-files
575 vim -c ":set ff=unix" -c ":wq" file      # convert using vim
576 vim -c "se ff=dos|x" file                # ... and even shorter ;)
577 recode ibmpc..lat1 file                  # convert using recode
578 echo -e "s/\r//g" > dos2unix.sed; sed -f dos2unix.sed < dosfile > unixfile
579 -- 
580 Save live audio stream to file:
581
582 % mplayer -ao pcm:file=$FILE
583
584 or
585
586 % mencoder mms://file.wmv -o $FILE -ovc copy -oac copy
587 -- 
588 Merge video files:
589
590 AVI:
591
592 % avimerge -i *.avi -o blub.avi
593
594 MPEG:
595
596 % cat *.mpg > blub.mpg
597
598 WMV:
599
600 % mencoder file1.wmv -ovc lavc -oac lavc -ofps 25 -srate 48000 -mc 0 -noskip -forceidx -o file1.avi
601 % mencoder file2.wmv -ovc lavc -oac lavc -ofps 25 -srate 48000 -mc 0 -noskip -forceidx -o file2.avi
602 % avimerge -i file1.avi file2.avi -o blub.avi
603 -- 
604 Display MS-Word file:
605
606 % strings file.doc | fmt | less
607
608 or
609
610 % antiword file.doc
611 -- 
612 Convert MS-Word file to postscript:
613
614 % antiword -p a4 file.doc > file.ps
615 -- 
616 Convert manual to postscript:
617
618 % zcat /usr/share/man/man1/zsh.1.gz | groff -man > zsh.1.ps
619 or
620 % man -t zsh > zsh.ps
621 -- 
622 Read BIOS:
623
624 % dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8
625 -- 
626 Read HTTP via netcat:
627
628 echo "GET / HTTP/1.0\r\n\r\n" | netcat $DOMAIN 80
629 -- 
630 Get X ressources for specific program:
631
632 % xrdb -q |grep -i xterm
633 -- 
634 Get windowid of specific X-window:
635
636 % xwininfo -int | grep "Window id:" | cut -d ' ' -f 4
637 -- 
638 Get titel of specific X-window:
639
640 % xprop WM_CLASS
641 -- 
642 check locale - LC_MESSAGES:
643
644 % locale -ck LC_MESSAGES
645 -- 
646 Create random password:
647
648 % pwgen
649 or
650 % dd if=/dev/urandom bs=14 count=1 | hexdump | cut -c 9-
651 -- 
652 Get tarballs of various Linux Kernel trees:
653
654 % ketchup 2.6
655 to get the current stable 2.6 release
656
657 % ketchup -l
658 to get a list of all supported trees
659 -- 
660 Transfer your SSH public key to another host:
661
662 % ssh-copy-id -i ~/.ssh/id_dsa.pub user@remote-system
663 or
664 % cat $HOME/.ssh/id_rsa.pub  | ssh user@remote-system 'cat >> .ssh/authorized_keys'
665 -- 
666 Update /etc/fstab entries:
667
668 # grml-rebuildfstab
669
670 See "man grml-rebuildfstab" for more details about
671 generation of /etc/fstab (including stuff like
672 fs LABELs / UUIDs,...).
673 -- 
674 Fetch and potentially change SCSI device parameters:
675
676 # sdparm /dev/sda
677
678 See: man sdparm
679 -- 
680 reclaim disk space by linking identical files together:
681
682 % dupmerge...
683 -- 
684 Find and remove duplicate files:
685
686 % dupseek ...
687 -- 
688 Perform layer 2 attacks:
689
690 # yersinia ...
691 -- 
692 rootsh
693 -- 
694 Guess PC-type hard disk partitions / partition table:
695
696 # gpart <options>
697
698 Perform a standard scan:
699 # gpart /dev/ice
700
701 Write back the guessed table:
702 # gpart -W /dev/ice /dev/ice
703 -- 
704 Develop, test and use exploit code with the Metasploit Framework:
705
706 cd /tmp
707 wget http://framework-mirrors.metasploit.com/msf/downloader/framework-3.0.tar.gz
708 unp framework-3.0.tar.gz
709 cd framework-3.0
710 ./msfcli
711 -- 
712 Useful documentation:
713
714 % w3m   /usr/share/doc/Debian/reference/reference.en.html
715 or
716 % xpdf =(zcat /usr/share/doc/Debian/reference/reference.en.pdf.gz)
717
718 http://grml.org/docs/           grml Documentation
719 http://wiki.grml.org/           grml Wiki
720 http://www.debian.org/doc/      Debian Documentation
721 http://wiki.debian.org/         Debian Wiki
722 http://www.gentoo.org/doc/en/   Gentoo Documentation
723 http://gentoo-wiki.com/         Gentoo Wiki
724 http://www.tldp.org/            The Linux Documentation Project
725
726 Tips and tricks:
727
728 % fortune debian-hints
729 -- 
730 Fun stuff:
731
732 % fortune debian-hints
733 % dpkg -L funny-manpages
734 -- 
735 Backup master boot record (MBR):
736
737 # dd if=/dev/ice of=/tmp/backup_of_mbr bs=512 count=1
738 -- 
739 Backup partition table:
740
741 # sfdisk -d /dev/hda > hda.out
742
743 Restore partition table:
744
745 # sfdisk /dev/hda < hda.out
746 -- 
747 Clone disk via network using netcat:
748
749 Listener:
750 # nc -vlp 30000 > hda1.img
751 Source:
752 # dd if=/dev/hda1 | nc -vq 0 192.168.1.2 30000
753
754 Adjust blocksize (dd's option bs=...) and include 'gzip -c'
755 to tune speed:
756
757 # dd if=/dev/hda1 bs=32M | gzip -c | nc -vq 0 192.168.1.2 30000
758 -- 
759 Backup specific directories via cpio and ssh:
760
761 # for f in directory_list; do find $f >> backup.list done
762 # cpio -v -o --format=newc < backup.list | ssh user@host "cat > backup_device"
763 -- 
764 Clone disk via ssh:
765
766 This one uses CPU cycles on the remote server to compare the files:
767 # ssh target_address cat remotefile | diff - localfile
768 # cat localfile | ssh target_address diff - remotefile
769
770 This one uses CPU cycles on the local server to compare the files:
771 # ssh target_address cat <localfile "|" diff - remotefile
772 -- 
773 Useful tools for cloning / backups:
774
775 * dd: convert and copy a file
776 * dd_rescue: copies data from one file (or block device) to another
777 * pcopy: a replacement for dd
778 * partimage: back up and restore disk partitions
779 * dirvish: Disk based virtual image network backup system
780 * devclone: in-place filesystem conversion -- device cloning
781 * ntfsclone: efficiently clone, image, restore or rescue an NTFS
782 * dump: ext2/3 filesystem backup
783 * udpcast: multicast file transfer tool
784 * cpio: copy files to and from archives
785 * pax: read and write file archives and copy directory hierarchies
786 * netcat / ssh / tar / gzip / bzip2: additional helper tools
787 -- 
788 Use grml as a rescue system:
789
790 Different tools:
791
792   * dd: convert and copy a file
793   * ddrescue: copies data from one file or block device to another
794   * partimage: Linux/UNIX utility to save partitions in a compressed image file
795   * cfdisk: Partition a hard drive
796   * nparted: Newt and GNU Parted based disk partition table manipulator
797   * parted-bf: The GNU Parted disk partition resizing program, small version
798   * testdisk: Partition scanner and disk recovery tool
799   * gpart: Guess PC disk partition table, find lost partitions
800
801 ext2/ext3:
802
803   * e2fsprogs: ext2 file system utilities and libraries
804   * e2tools: utilities for manipulating files in an ext2/ext3 filesystem
805   * e2undel: Undelete utility for the ext2 file system
806   * ext2resize: an ext2 filesystem resizer
807   * recover: Undelete files on ext2 partitions
808
809 ReiserFS/Reiser4:
810
811   * reiser4progs: administration utilities for the Reiser4 filesystem
812   * reiserfsprogs: User-level tools for ReiserFS filesystems
813
814 XFS:
815
816   * xfsdump: Administrative utilities for the XFS filesystem
817   * xfsprogs: Utilities for managing the XFS filesystem
818
819 JFS:
820
821   * jfsutils: utilities for managing the JFS filesystem
822
823 NTFS:
824
825   * ntfsprogs: tools for doing neat things in NTFS partitions from Linux
826   * salvage-ntfs: free NTFS data recovery tools
827   * scrounge-ntfs: data recovery program for NTFS file systems
828   * ntfsresize: resize ntfs partitions
829 -- 
830 Get ASCII value of a character with zsh:
831
832 % char=N ; print $((#char))
833 -- 
834 Convert a collection of mp3 files to wave or cdr using zsh:
835
836 % for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav}
837 -- 
838 Convert images (foo.gif to foo.png) using zsh:
839
840 % for i in **/*.gif; convert $i $i:r.png
841 -- 
842 Remove all "non txt" files using zsh:
843
844 % rm ./^*.txt
845 -- 
846 Remote Shell Using SSH:
847
848 remote host:
849 % ssh -NR 3333:localhost:22 user@yourhost
850
851 local host:
852 % ssh user@localhost -p 3333
853 -- 
854 Reverse Shell with Netcat:
855
856 local host:
857 % netcat -v -l -p 3333 -e /bin/sh
858
859 remote host:
860 % netcat 192.168.0.1 3333
861 -- 
862 Reverse Shell via SSH:
863
864 local host (inside the network):
865 % ssh -NR 1234:localhost:22 remote_host
866
867 remote host (outside the network):
868 % ssh localhost -p 1234
869 -- 
870 Remove empty directories with zsh:
871
872 % rmdir ./**/*(/od) 2> /dev/null
873 -- 
874 Find all the empty directories in a tree with zsh:
875
876 % ls -ld *(/^F)
877 -- 
878 Find all files without a valid owner and change ownership with zsh:
879
880 % chmod user /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
881 -- 
882 Display the 5-10 last modified files with zsh:
883
884 % print -rl -- /path/to/dir/**/*(D.om[5,10])
885 -- 
886 Find and list the ten newest files in directories and subdirs (recursive) with zsh:
887
888 % print -rl -- **/*(Dom[1,10])
889 -- 
890 Find most recent file in a directory with zsh:
891
892 % setopt dotglob ; print directory/**/*(om[1])
893 -- 
894 Tunnel all traffic through an external server:
895
896 % ssh -ND 3333 username@external.machine
897
898 Then set the SOCKS4/5 proxy to localhost:3333.
899 Check whether it's working by surfing e.g. to checkip.dyndns.org
900 -- 
901 Tunnel everything through SSH via tsocks:
902
903 set up the SSH proxy on the client side:
904
905 % ssh -ND 3333 user@remote.host.example.com
906
907 Adjust /etc/tsocks.conf afterwards (delete all other lines):
908
909 server = 127.0.0.1
910 server_port = 3333
911
912 For programs who natively support proxying connections (e.g. Mozilla
913 Firefox) you can now set the proxy address to localhost port 3333.
914
915 All other programs which's connections you want to tunnel through your
916 external host are prefixed with tsocks, e.g.:
917
918 % tsocks netcat example.com 80
919 % tsocks irssi -c irc.quakenet.eu.org -p 6667
920
921 If you call tsocks without parameters it executes a shell witht the
922 LD_PRELOAD environment variable already set and exported.
923 -- 
924 smartctl - control and monitor utility for harddisks using Self-Monitoring,
925 Analysis and Reporting Technology (SMART):
926
927 # smartctl --all /dev/ice
928
929 If you want to use smartctl on S-ATA (sata) disks use:
930
931 # smartctl -d ata --all /dev/sda
932
933 Start offline test:
934 # smartctl -t offline /dev/ice
935
936 Start short test:
937 # smartctl -t short /dev/ice
938
939 Display results of test:
940 # smartctl -l selftest /dev/ice
941
942 Query device information:
943 # smartctl -i /dev/ice
944 -- 
945 Mount a BSD / Solaris partition:
946
947 # mount -t ufs -o ufstype=ufs2 /dev/hda1 /mnt/hda1
948
949 Use ufstype 44bsd  for FreeBSD, NetBSD, OpenBSD (read-write).
950 Use ufstype ufs2   for >= FreeBSD 5.x (read-only).
951 Use ufstype sun    for SunOS (Solaris) (read-write).
952 Use ufstype sunx86 for SunOS for Intel (Solarisx86) (read-write).
953
954 See /usr/share/doc/linux-doc-$(uname -r)/Documentation/filesystems/ufs.txt.gz
955 for more details.
956 -- 
957 Read BIOS (and or BIOS) password:
958
959 # dd if=/dev/mem bs=512 skip=2 count=1 | hexdump -C | head
960 -- 
961 Clone one of the kernel trees via git:
962
963  git clone rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
964                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
965 This path defines the tree. See http://kernel.org/git/ for an overview.
966 -- 
967 Mount filesystems over ssh protocol:
968
969 % sshfs user@host:/remote_dir /mnt/test
970
971 Unmount via:
972
973 % fusermount -u /mnt/test
974
975 (Notice: requires fuse kernel module)
976 -- 
977 Install Gentoo using grml:
978
979 See http://www.gentoo.org/doc/en/altinstall.xml
980 -- 
981 Install (plain) Debian (sarge release) via grml:
982
983 Assuming you want to install Debian to sda1:
984
985 mkfs.ext3 /dev/sda1           # make an ext3 filesystem on /dev/sda1
986 mount -o rw,suid,dev /dev/sda1 /mnt/test # now mount the new partition
987 debootstrap sarge /mnt/test ftp://ftp.tugraz.at/mirror/debian # get main packages from a debian-mirror
988 chroot /mnt/test /bin/bash    # let's chroot into the new system
989 mount -t devpts none /dev/pts # ...otherwise running base-config might fail ("Terminated" or "openpty failed")
990 mount -t proc   none /proc    # make sure we also have a mounted /proc
991 base-config                   # now configure some main settings
992 vi /etc/mkinitrd/mkinitrd.conf # adjust $ROOT (to /dev/sda1) for your new partition, autodetection will fail in chroot
993 cd /dev ; ./MAKEDEV generic                                # make sure we have all necessary devices for lilo
994 apt-get install lilo linux-image-2.6.12-1-386              # install lilo and a kernel which fits your needs
995 cp /usr/share/doc/lilo/examples/conf.sample /etc/lilo.conf # let's use a template
996 vi /etc/lilo.conf && lilo                                  # adjust the file for your needs and run lilo afterwards
997 umount /proc ; umount /dev/pts                             # we do not need them any more
998 exit                                                       # now leave chroot
999 cp /etc/hosts /etc/fstab /mnt/test/etc/           # you might want to take the existing files...
1000 cp /etc/network/interfaces /mnt/test/etc/network/ # ...from the running grml system for your new system
1001 umount /mnt/test && reboot    # unmount partition and reboot...
1002
1003 See also: http://www.debian.org/releases/stable/i386/apcs04.html.en
1004 Avoid all of the above steps - use grml-debootstrap(8) instead!
1005 -- 
1006 Install (plain) Debian (etch release) via grml
1007
1008 Assuming you want to install Debian to sda1:
1009
1010 mkfs.ext3 /dev/sda1           # make an ext3 filesystem on /dev/sda1
1011 mount -o rw,suid,dev /dev/sda1 /mnt/test # now mount the new partition
1012 debootstrap etch /mnt/test ftp://ftp.tugraz.at/mirror/debian # get main packages from a debian-mirror
1013 chroot /mnt/test /bin/bash    # let's chroot into the new system
1014 mount -t proc   none /proc    # make sure we have a mounted /proc
1015 apt-get install locales console-data  # install locales
1016 dpkg-reconfigure locales console-data # adjust locales to your needs
1017 apt-get install vim most zsh screen less initrd-tools file grub     \
1018         usbutils pciutils bzip2 sysfsutils dhcp3-client resolvconf  \
1019         strace lsof w3m # install useful software
1020 apt-get install linux-headers-2.6-686 linux-image-686  # install current kernel
1021
1022 echo "127.0.0.1       localhost" > /etc/hosts   # adjust /etc/hosts and network:
1023 cat >> /etc/network/interfaces << EOF
1024 iface lo inet loopback
1025 iface eth0 inet dhcp
1026 auto lo
1027 auto eth0
1028 EOF
1029
1030 ln -sf /usr/share/zoneinfo/Europe/Vienna /etc/localtime # adjust timezone and /etc/fstab:
1031 cat >> /etc/fstab << EOF
1032 sysfs          /sys         sysfs   auto                       0   0
1033 proc           /proc        proc    defaults                   0   0
1034 /dev/sda1      /            ext3    defaults,errors=remount-ro 0   1
1035 /dev/sda2      none         swap    sw                         0   0
1036 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
1037 EOF
1038 passwd             # set password of user root
1039
1040 mkdir /boot/grub   # setup grub
1041 cp /usr/share/doc/grub/examples/menu.lst /boot/grub
1042 cat >> /boot/grub/menu.lst << EOF
1043 title           Debian Etch, kernel 2.6.18-3-686 (on /dev/sda1)
1044 root            (hd0,0)
1045 kernel          /boot/vmlinuz-2.6.18-3-686 root=/dev/sda1 ro
1046 initrd          /boot/initrd.img-2.6.18-3-686
1047 EOF
1048 vim /boot/grub/menu.lst               # adjust grub configuration to your needs
1049 cd /dev && MAKEDEV generic            # create default devices
1050 cp -i /usr/lib/grub/i386-pc/* /boot/grub/ # copy stage-files to /boot/grub/
1051 grub install  # now install grub, run in grub-cmdline following commands:
1052 > root (hd0,0)
1053 > setup (hd0)
1054 > quit
1055 umount -a # unmount all filesystems in chroot and finally:
1056 exit      # exit the chroot and:
1057 reboot
1058
1059 If you want to use lilo instead of grub take a look at
1060 /usr/share/doc/lilo/examples/conf.sample or use the following template:
1061
1062 cat > /etc/lilo.conf << EOF
1063 # This allows booting from any partition on disks with more than 1024 cylinders.
1064 lba32
1065
1066 # Specifies the boot device
1067 boot=/dev/sda1
1068
1069 # Specifies the device that should be mounted as root.
1070 root=/dev/sda1
1071
1072 # use Debian on software raid:
1073 # raid-extra-boot=mbr-only
1074
1075 install=text
1076 # prompt
1077 timeout=1
1078 map=/boot/map
1079 vga=normal
1080
1081 image=/boot/vmlinuz-2.6.18-grml
1082         label="2.6.18-grml"
1083         #append="...."
1084         read-only
1085         initrd=/boot/initrd.img-2.6.18-grml
1086 EOF
1087
1088 See also: http://www.debian.org/releases/stable/i386/apcs04.html.en
1089 Avoid all of the above steps - use grml-debootstrap(8) instead!
1090 -- 
1091 Convert files from Unicode / UTF-8 to ISO:
1092
1093 % iconv -f utf8 -t iso-8859-15 < utffile > isofile
1094
1095 and vice versa:
1096
1097 % iconv -f iso-8859-15 -t utf8 < isofile > utffile
1098 -- 
1099 Assign static setup for network cards (eth0 and eth1) via udev:
1100
1101 First method - manual:
1102 ~~~~~~~~~~~~~~~~~~~~~~
1103 Get information for SYSFS address:
1104 # udevinfo -a -p /sys/class/net/eth0/ | grep address
1105
1106 Then create udev rules:
1107 # cat /etc/udev/network.rules
1108 # match eth* stuff:
1109 KERNEL=="eth*", SYSFS{address}=="00:00:00:00:00:01", NAME="wlan0"
1110 KERNEL=="eth*", SYSFS{address}=="00:00:00:00:00:02", NAME="lan0"
1111 # do not match eth* drivers but also e.g. firewire stuff:
1112 ACTION=="add", SUBSYSTEM=="net", SYSFS{address}=="00:00:00:00:00:03", NAME="1394"
1113
1114 Now activate the rules:
1115 # cd /etc/udev/rules.d/ && ln -s ../network.rules z35_network.rules
1116
1117 Unload the drivers, restart udev and load the drivers again to activate
1118 the settings.
1119
1120 Second method - automatic:
1121 ~~~~~~~~~~~~~~~~~~~~~~~~~~
1122 Run /lib/udev/write_net_rules shipped with recent udev versions:
1123
1124 # INTERFACE=wlan1 /lib/udev/write_net_rules 00:00:00:00:00:04
1125
1126 This command will create /etc/udev/rules.d/z25_persistent-net.rules containing:
1127
1128 SUBSYSTEM=="net", DRIVER=="?*", SYSFS{address}=="00:00:00:00:00:04", NAME=wlan1
1129
1130 See /usr/share/doc/udev/writing_udev_rules/index.html for more information.
1131 -- 
1132 Change the suffix from *.sh to *.pl using zsh:
1133
1134 % autoload zmv
1135 % zmv -W '*.sh' '*.pl'
1136 -- 
1137 Generate SSL certificate:
1138
1139 Create self signed certificate (adjust /etc/ssl/openssl.cnf if necessary):
1140 # openssl req -x509 -newkey rsa:1024 -keyout keyfile -out certfile -days 9999 -nodes
1141
1142 Check certfile:
1143 # openssl x509 -in certfile -text
1144
1145 Verify against CA certificate:
1146 # openssl verify -CAfile cacert.crt -verbose -purpose sslserver
1147
1148 Generate 2048bit RSA-key:
1149 # openssl req -new -x509 -keyout pub-sec-key.pem -out pub-sec-key.pem -days 365 -nodes
1150
1151 As before but add request to existing key pub-sec-key.pem:
1152 # openssl req -new -out request.pem -keyin pub-sec-key.pem
1153
1154 Show request request.pem:
1155 # openssl req -text -noout -in request.pem
1156
1157 Verify signature of request request.pem:
1158 # openssl req -verify -noout -in request.pem
1159
1160 Generate SHA1 fingerprint (modulo key) of request.pem:
1161 # openssl req -noout -modulus -in request.pem | openssl sha1 -c
1162
1163 Generate 2048bit RSA-key and put it to pub-sec-key.pem. Save self signed certificate in self-signed-certificate.pem:
1164 # openssl req -x509 -days 365 -newkey rsa:2048 -out self-signed-certificate.pem -keyout pub-sec-key.pem
1165
1166 As before but create self signed certificate based on existing key pub-sec-key.pem:
1167 # openssl req -x509 -days 365 -new -out self-signed-certificate.pem -key pub-sec-key.pem
1168
1169 Generate new request out of existing self signed certificate:
1170 # openssl x509 -x509toreq -in self-signed-certificate.pem -signkey pub-sec-key.pem -out request.pem
1171
1172 Display certificate self-signed-certificate.pem in plaintext:
1173 # openssl x509 -text -noout -md5 -in self-signed-certificate.pem
1174
1175 Check self signed certificate:
1176 # openssl verify -issuer_checks -CAfile self-signed-certificate.pem self-signed-certificate.pem
1177
1178 Estable OpenSSL-connection using self-signed-certificate.pem and display certificate:
1179 # openssl s_client -showcerts -CAfile self-signed-certificate.pem -connect www.example.com:443
1180
1181 Generate ssl-certificate for use with apache2:
1182
1183 export RANDFILE=/dev/random
1184 mkdir /etc/apache2/ssl/
1185 openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.pem
1186 chmod 600 /etc/apache2/ssl/apache.pem
1187
1188 Also take a look at make-ssl-cert (debconf wrapper for openssl):
1189
1190 # /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/apache.pem
1191
1192 and mod-ssl-makecert (utility to create SSL certificates in /etc/apache/ssl.*/).
1193 -- 
1194 Change Windows NT password(s):
1195
1196 # mount -o rw /mnt/hda1
1197 # cd /mnt/hda1/WINDOWS/system32/config/
1198 # chntpw SAM SECURITY system
1199
1200 Notice: if mounting the partition read-write did not work (check syslog!)
1201 try using mount.ntfs-3g instead: mount.ntfs-3g /dev/hda1 /mnt/hda1
1202
1203 (Be careful with deactivating syskey!)
1204 -- 
1205 glark - replacement for grep written in Ruby:
1206
1207 A replacement for (or supplement to) the grep family, glark offers:
1208 Perl compatible regular expressions, highlighting of matches,
1209 context around matches, complex expressions and automatic exclusion
1210 of non-text files.
1211
1212 Usage examples:
1213
1214 % glark -y keyword file      # display only the region that matched, not the entire line
1215 % glark -o format print *.h  # search for either "printf" or "format"
1216
1217 More information: man glark
1218 -- 
1219 Find CD burning device(s):
1220
1221 General information on CD-ROM:
1222 % cat /proc/sys/dev/cdrom/info
1223
1224 Scan using ATA Packet specific SCSI transport:
1225 # cdrecord -dev=ATA -scanbus
1226 # cdrecord-prodvd -s -scanbus dev=ATA
1227
1228 Get specific information for /dev/ice:
1229 # cdrecord dev=/dev/ice -scanbus
1230 -- 
1231 Create devices in /dev on udev:
1232
1233 For example create md devices (/dev/md0, /dev/md1,...):
1234 # cd /dev ; WRITE_ON_UDEV=1 ./MAKEDEV md
1235 -- 
1236 Identify network device (NIC):
1237
1238 # ethtool -i $DEVICE
1239
1240 Show NIC statistics:
1241
1242 # ethtool -S $DEVICE
1243
1244 If your NIC shows some aging signs, you may want to be sure:
1245
1246 # ethtool -t $DEVICE
1247
1248 Disable TCP/UDP checksums:
1249
1250 # ethtool -K $DEVICE tx off
1251 -- 
1252 grml2hd seems to hang? Getting Squashfs errors? Problems while booting?
1253
1254 Switch to tty12 and take a look at the syslog. If you see something like:
1255
1256   SQUASHFS error: zlib_fs returned unexpected result 0x........
1257   SQUASHFS error: Unable to read cache block [.....]
1258   SQUASHFS error: Unable to read inode [.....]
1259
1260 your ISO/CD-ROM very probably is not ok. Verify it via booting with grml testcd.
1261 Check your CD low-level via running:
1262
1263 # readcd -c2scan dev=/dev/cdrom
1264
1265 If the medium really is ok and it still fails try to boot with deactivated DMA
1266 via using grml nodma at the bootprompt.
1267 -- 
1268 Write a Microsoft compatible boot record (MBR) using ms-sys
1269
1270 Write a Windows 2000/XP/2003 MBR to device:
1271
1272 # ms-sys -m /dev/ice
1273 -- 
1274 Use a Vodafone 3G Datacard (UMTS) with Linux:
1275
1276 Plug in your vodafone card and check in syslog whether the appropriate
1277 (probably /dev/ttyUSB0 or /dev/noz0 when using newer vodafone cards) has
1278 been created. If so run:
1279
1280 # gcom -d $DEVICE
1281 # wvdial --config /etc/wvdial.conf.umts $PROFILE
1282
1283 Usage examples:
1284 # gcom -d /dev/ttyUSB0
1285 # wvdial --config /etc/wvdial.conf.umts a1usb
1286
1287 # gcom -d /dev/noz0
1288 # wvdial --config /etc/wvdial.conf.umts tmnozomi
1289
1290 # gcom -d /dev/noz0
1291 # wvdial --config /etc/wvdial.conf.umts dreiusb
1292
1293 Notice: newer vodafone cards require the nozomi driver. Run 'modprobe nozomi' on
1294 your grml system.
1295 -- 
1296 hdparm - get/set hard disk parameters
1297
1298 Display the identification info that was obtained from the drive at boot time,
1299 if available:
1300 # hpdarm -i /dev/ice
1301
1302 Request identification info directly from the drive:
1303 # hpdarm -I /dev/ice
1304
1305 Perform timings of device + cache reads for benchmark and comparison purposes:
1306 # hdparm -tT /dev/ice
1307 -- 
1308 bonnie++ - program to test hard drive performance.
1309
1310 # mkdir /mnt/benchmark
1311 # mount /dev/ice /mnt/benchmark
1312 # chmod go+w /mnt/benchmark
1313 # bonnie -u grml -d /mnt/benchmark -s 2000M
1314 -- 
1315 Use gizmo with a bluetooth headset:
1316
1317 % DEVICE="/dev/dsp$(awk '/- BT Headset/ {print $1}' /proc/asound/cards)"
1318 % gizmo --mic $DEVICE --speaker $DEVICE
1319 -- 
1320 Scan a v4l device for TV stations:
1321
1322 % scantv -c /dev/video0 -C /dev/vbi0 -o ~/.xawtv
1323
1324 Then running xawtv should work:
1325
1326 % xawtv
1327 -- 
1328 Run apt-get with timeout of 3 seconds:
1329
1330 # apt-get -o acquire::http::timeout=3  update
1331 -- 
1332 Debian GNU/Linux device driver check page
1333
1334 % $BROWSER http://kmuto.jp/debian/hcl/index.cgi
1335 -- 
1336 Use dd with status line:
1337
1338 # dd if=/dev/ice conv=noerror,notrunc,sync | buffer -S 100k | dd of=/tmp/file
1339 -- 
1340 Generate a 512k file of random data with status bar:
1341
1342 % dd if=/dev/random bs=1024 count=512 | bar -s 512k -of ./random
1343 -- 
1344 Install Grub instead of lilo on grml installation (grml2hd):
1345
1346 install grml:
1347 # grml2hd ....
1348
1349 adjust grub's configuration file menu.lst:
1350 # $EDITOR /boot/grub/menu.lst
1351
1352 now install grub (usage example for /dev/sda1):
1353 # grub install
1354 root (hd0,0)
1355 setup (hd0)
1356 -- 
1357 Install Ubuntu using grml:
1358
1359 See https://wiki.ubuntu.com/Installation/FromKnoppix
1360 -- 
1361 Resize ext2 / ext3 partition:
1362
1363 # tune2fs -O '^has_journal' /dev/iceX # disable journaling
1364 # fsck.ext2 -v -y -f /dev/iceX        # check the filesystem
1365 # resize2fs -p /dev/iceX  $SIZE       # resize it (adjust $SIZE)
1366 # fdisk /dev/ice                      # adjust partition in partition table
1367 # fsck.ext2 -v -y -f /dev/iceX        # check filesystem again
1368 # resize2fs -p /dev/iceX              # resize it to maximum
1369 # tune2fs -j /dev/iceX                # re-enable journal
1370 -- 
1371 Tune ext2 / ext3 filesystem:
1372
1373 Check partition first:
1374
1375 # tune2fs -l /dev/iceX
1376
1377 If you don't see dir_index in the list, then enable it:
1378
1379 # tune2fs -O dir_index /dev/iceX
1380
1381 Now run e2fsck with the -D option to have the directories optimized:
1382
1383 # e2fsck -D /dev/iceX
1384
1385 Notice: since e2fsprogs (1.39-1) filesystems are created with
1386 directory indexing and on-line resizing enabled by default.
1387 -- 
1388 Search for printers via network:
1389
1390 # pconf_detect -m NETWORK -i 192.168.0.1/24
1391 -- 
1392 Mount a remote directory via webdav (e.g. Mediacenter of GMX):
1393
1394 # mount -t davfs https://mediacenter.gmx.net/ /mnt/test
1395 -- 
1396 System-Profiling using oprofile:
1397
1398 Prepare setup:
1399
1400 # opcontrol --reset
1401 # opcontrol --setup --no-vmlinux --event=CPU_CLK_UNHALTED:500000:0:1:1 --separate=library
1402
1403 Start logging:
1404 # opcontrol --start
1405
1406 Now $DO_SOME_TASKS...
1407
1408 Stop logging:
1409 # opcontrol --shutdown
1410
1411 Then take a look at the reports using something like e.g.:
1412 # opreport -t 0.5 --exclude-dependent
1413 # opreport -t 0.5 /path/to/executable_to_check
1414 # opannotate -t 0.5 --source --assembly
1415 -- 
1416 Install ATI's fglrx driver for Xorg / X.org:
1417
1418 Usually there already exist drivers for the grml-system:
1419 # apt-get update ; apt-get install fglrx-driver fglrx-kernel-`uname -r`
1420
1421 After installing adjust xorg.conf via running:
1422 # aticonfig --initial --input=/etc/X11/xorg.conf
1423
1424 For more information take a look at http://wiki.grml.org/doku.php?id=ati
1425 -- 
1426 Install nvidia driver for Xorg / X.org:
1427
1428 Usually there already exist drivers for the grml-system:
1429 # apt-get update ; apt-get install nvidia-glx nvidia-kernel-`uname -r`
1430
1431 Then switch from module nv to nvidia:
1432
1433 # sed -i 's/Driver.*nv.*/Driver      "nvidia"/' /etc/X11/xorg.conf
1434 -- 
1435 glxgears - a GLX demo that draws three rotating gears
1436
1437 To print frames per second (fps) use:
1438 % glxgears -printfps
1439 -- 
1440 You forgot to boot with 'grml noeject noprompt' to avoid
1441 ejecting and prompting for CD removal when rebooting/halting
1442 the system?
1443
1444 Either run:
1445
1446 # noeject reboot
1447
1448 or:
1449
1450 # noeject halt
1451
1452 If you want to avoid only the prompting part, run:
1453
1454 # noprompt reboot
1455
1456 or:
1457
1458 # noprompt halt
1459 -- 
1460 Mount wikipedia local via fuse:
1461
1462 Adjust configuration:
1463 % cat ~/.wikipediafs/config.xml
1464 <wfs-config>
1465     <general>
1466        <article-cache-time>300</article-cache-time>
1467     </general>
1468     <sites>
1469       <site>
1470         <dirname>wikipedia-de</dirname>
1471         <host>de.wikipedia.org</host>
1472         <basename>/w/index.php</basename>
1473       </site>
1474       <site>
1475         <dirname>wikipedia-en</dirname>
1476         <host>en.wikipedia.org</host>
1477         <basename>/w/index.php</basename>
1478       </site>
1479     </sites>
1480 </wfs-config>
1481
1482 Mount it (/wiki must exist of course):
1483 % mount.wikipediafs /wiki
1484 % cat /wiki/wikipedia-en/Cat
1485
1486 Unmount via:
1487 % fusermount -u /wiki
1488 -- 
1489 Remote notification on X via osd (on screen display):
1490
1491 Start osd_server.py at your local host (listens on port 1234 by default):
1492 % osd_server.py
1493
1494 Then login to a $REMOTEHOST
1495 % ssh -R 1234:localhost:1234 $REMOTEHOST
1496
1497 Now send the text to your local display via running something like:
1498 % echo "text to send" | nc localhost 1234
1499
1500 Very useful when you are waiting for a long running job
1501 but want to do something else in the meanwhile:
1502
1503 % ./configure && make && echo "finished compiling" | netcat localhost 1234
1504
1505 You can use this in external programs as well of course. Examples:
1506
1507 Use osd in centericq:
1508
1509 % cat ~/.centericq/external
1510 [...]
1511 %action osd notify
1512 event msg
1513 proto all
1514 status all
1515 options nowait
1516 %exec
1517 #!/bin/bash
1518 if [ -x /usr/bin/socat -a -x /bin/netcat ] ; then
1519   CONTACT_CUSTOM_NICK=$(cat ${CONTACT_INFODIR}/info | head -n 46 | tail -n 1)
1520   osd_msg="*** CenterICQ: new ${EVENT_NETWORK} ${EVENT_TYPE} from ${CONTACT_CUSTOM_NICK} ***"
1521   if echo | socat - TCP4:localhost:1234 &>/dev/null ; then
1522     echo "${osd_msg}" | netcat localhost 1234
1523   fi
1524 fi
1525
1526 Use it in the IRC console client irssi via running:
1527
1528 /script load osd.pl
1529
1530 You can even activate the port forwarding by default globally:
1531
1532 % cat ~/.ssh/config
1533 [...]
1534 Host *
1535 RemoteForward 1234 127.0.0.1:1234
1536 ForwardAgent yes
1537
1538 Notice: if you get 'ABORT: Requested font not found' make sure the
1539 requested font is available, running 'LANG=C LC_ALL=C osd_server.py...'
1540 might help as well.
1541 -- 
1542 Avoid automatical startup of init scripts via invoke-rc.d:
1543
1544 First of all make sure the package policyrcd-script-zg2 (which
1545 provides the /usr/sbin/policy-rc.d interface) is installed.
1546
1547 In policyrcd-script-zg2's configuration file named
1548 /etc/zg-policy-rc.d.conf the script /usr/sbin/grml-policy-rc.d is
1549 defined as the interface for handling invoke-rc.d's startup policy.
1550
1551 grml-policy-rc.d can be configure via /etc/policy-rc.d.conf.  By
1552 default you won't notice any differences to Debian's default
1553 behaviour, except that invoke-rc.d won't be executed if a chroot has
1554 been detected (detection: /proc is missing).
1555
1556 If you want to disable automatical startup of newly installed packages
1557 (done via the invoke-rc.d mechanism) just set EXITSTATUS to '101' in
1558 /etc/policy-rc.d.conf.
1559
1560 To restore the default behaviour set EXITSTATUS back to '0' in
1561 /etc/policy-rc.d.conf.
1562 -- 
1563 Install VMware-Tools for grml:
1564
1565 First of all make sure a CD-ROM device in VMware is available.
1566
1567 Mount the CD-ROM device to /mnt/cdrom, then unpack and install
1568 the tools running:
1569
1570 cd /tmp
1571 unp /mnt/cdrom/vmware-linux-tools.tar.gz
1572 cd vmware-tools-distrib
1573 ./vmware-install.pl
1574
1575 /etc/init.d/networking stop
1576 rmmod pcnet32
1577 rmmod vmxnet
1578 depmod -a
1579 modprobe vmxnet
1580 /etc/init.d/networking start
1581
1582 In an X terminal, launch the VMware Tools running:
1583
1584 vmware-toolbox
1585 -- 
1586 Some important Postfix stuff
1587
1588 List mail queue:
1589
1590 # mailq
1591 or
1592 # postqueue -p
1593
1594 Send all messages in the queue:
1595
1596 # postqueue -f
1597
1598 Send all messages in the queue for a specific site:
1599
1600 # postqueue -s site
1601
1602 Delete a specific message
1603 # postsuper -d 12345678942
1604
1605 Deletes all messages held in the queue for later delivery
1606 # postsuper -d ALL deferred
1607
1608 Mail queues in postfix:
1609
1610     incoming -> mail who just entered the system
1611     active   -> mail to be delivered
1612     deferred -> mail to be delivered later because there were problems
1613     hold     -> mail that should not be delivered until released from hold
1614
1615 For configuration of postfix take a look at
1616 /etc/postfix/master.cf  - man 5 master
1617 /etc/postfix/main.cf    - man 5 postconf
1618 and http://www.postfix.org/documentation.html.
1619 -- 
1620 File permissions
1621
1622 mode 4000 - set user ID (suid):
1623
1624 - for executable files: run as the user who owns the file, instead of the
1625   user who runs the file
1626 - for directories: not used
1627
1628 mode 2000 - set group ID (guid):
1629
1630 - for executable files: run as the group who owns the file, instead of the
1631   group of the user who runs the file
1632 - for directories: when a file is created inside the directory, it belongs
1633   to the group of the directory instead of the default group of the user who
1634   created the file
1635
1636 mode 1000 - sticky bit:
1637
1638 - for files: not used
1639 - for directories: only the owner of a file can delete or rename the file
1640 -- 
1641 Create MySQL database
1642
1643 # apt-get install mysql-client mysql-server
1644
1645 Run 'mysql' as root - create a database with:
1646
1647 create database grml
1648
1649 Give a user access to the database (without password):
1650
1651 grant all on grml.* to mika;
1652
1653 Give a user access to the database (with password):
1654
1655 grant all on grml.* to enrico identified by "PASSWORD";
1656 -- 
1657 Setup an HTTPS website:
1658
1659 Create a certificate:
1660
1661 # mkdir /etc/apache2/ssl
1662 # make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
1663
1664 Create a virtual host on port 443:
1665
1666 <VirtualHost www.foo.invalid:443>
1667 [...]
1668 </VirtualHost>
1669
1670 Enable SSL in the VirtualHost:
1671
1672 SSLEngine On
1673 SSLCertificateFile /etc/apache2/ssl/apache.pem
1674
1675 Enable listening on the HTTPS port (/etc/apache2/ports.conf):
1676
1677 Listen 443
1678
1679 and make sure the SSL module is used:
1680
1681 # a2enmod ssl
1682 -- 
1683 Useful Apache / Apache2 stuff
1684
1685 Check configuration file via running:
1686
1687 # apache2ctl configtest
1688
1689 Enable a site:
1690
1691 # a2ensite sitename
1692
1693 Enable a module
1694
1695 # a2enmod modulename
1696 -- 
1697 Create tar archive and store it on remote machine:
1698
1699 % tar zcf - /sourcedir | ssh user@targethost "cat >file.tgz"
1700 -- 
1701 Pick out and displays images from network traffic:
1702
1703 # driftnet
1704 -- 
1705 Install Flash plugin:
1706
1707 # dpkg-reconfigure flashplugin-nonfree
1708 -- 
1709 To test a proxy, low level way:
1710
1711 % telnet proxy 8080
1712 [...]
1713 GET http://www.google.com HTTP/1.0 [press enter twice]
1714 -- 
1715 Adjust system for use of qemu with kqemu:
1716
1717 Make sure you have all you need:
1718 # apt-get update ; apt-get install qemu grml-kerneladdons-$KERNELVERSION
1719
1720 Then set up kqemu:
1721
1722 modprobe kqemu
1723 mknod /dev/kqemu c 250 0
1724 chmod 666 /dev/kqemu
1725 chmod 666 /dev/net/tun
1726
1727 Check kqemu support via starting qemu, press
1728 Ctrl-Alt-2 and entering 'info kqemu'.
1729 -- 
1730 (High-Load) Debugging related tools:
1731
1732 mpstat  # report processors related statistics
1733 iostat  # report CPU statistics and input/output statistics for devices and partitions
1734 vmstat  # report virtual memory statistics
1735 slabtop # display kernel slab cache information in real time
1736 atsar   # system activity report
1737 dstat   # versatile tool for generating system resource statistics
1738
1739 Usage examples:
1740
1741 # mpstat -P ALL
1742 # iostat -x 1
1743 # iostat -xtc 5 3
1744 # vmstat 1
1745 # atsar -t 60 10
1746 # dstat -af
1747 -- 
1748 Using WPA for network setup manually:
1749
1750 # wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
1751
1752 Adjust the options and configuration file to your needs.
1753 Also take a look at 'grml-network'.
1754 -- 
1755 Start X and lock console via exiting:
1756
1757 % startx 2>~/.xsession-errors &| exit
1758 -- 
1759 Which process is writing to disk and/or causes the disk to spin up?
1760
1761 First of all use lsof to check what's going on. Does not help? ->
1762
1763 # echo 1 > /proc/sys/vm/block_dump
1764
1765 The command sets a sysctl to cause the kernel to log all disk
1766 writes. Please notice that there is a lot of data.  So please
1767 disable syslogd/syslog-ng before you do this, or you must make
1768 sure that kernel output is not logged.
1769
1770 When you're done, disable block dump using:
1771 # echo 0 > /proc/sys/vm/block_dump
1772
1773 Alternative:
1774 laptop-mode-tools provides a tool named lm-profiler (laptop mode profiler)
1775 which handles block_dump on its own.
1776
1777 See: $KERNEL-SOURCE/Documentation/laptop-mode.txt
1778
1779 Also take a look at event-viewer(8) which is part of grml-debugtools.
1780 -- 
1781 Install initrd via initramfs-tools for currently running kernel:
1782
1783 # update-initramfs -c -t -k $(uname -r)
1784 -- 
1785 Install initrd via yaird for currently running kernel:
1786
1787 # yaird -o /boot/initrd.img-$(uname -r)
1788
1789 Install initrd via yaird for specific kernel:
1790
1791 # mount /proc
1792 # mount /sys
1793 # yaird -o /boot/initrd.img-2.6.15-1-686 2.6.15-1-686
1794 -- 
1795 Reinstall package with its original configuration files:
1796
1797 # apt-get install --reinstall -o DPkg::Options::=--force-confmiss -o \
1798   DPkg::Options::=--force-confnew package
1799 -- 
1800 grml 0.8 funkenzutzler - rt2x00 drivers:
1801
1802 To avoid conflicts with the other rt2x00-drivers the package rt2x00 (which
1803 includes beta-version drivers) is not installed by default. If you want to
1804 use the kernel modules rt2400pci, rt2500pci, rt2500usb, rt61pci and/or
1805 rt73usb please install the package manually running:
1806
1807 # dpkg -i /usr/src/rt2x00-modules-*.deb
1808 -- 
1809 Use Java with jikes and jamvm on grml:
1810
1811 Simple demo:
1812
1813 % cp /usr/share/doc/grml-templates/template.java .
1814 % jikes template.java
1815 % jamvm HelloWorld
1816
1817 Notice that grml exports $JIKESPATH (/usr/share/classpath/glibj.zip),
1818 so you do not have to manually run
1819 jikes --bootclasspath /usr/share/classpath/glibj.zip
1820 -- 
1821 Online resizing of (Software-)RAID5:
1822
1823 # Initiate a RAID5 setup for testing purposes:
1824 mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/hda1 /dev/hdb1 /dev/hdd1
1825
1826 # Create filesystem, mount md0, create a testfile and save md5sum for
1827 # later check:
1828 mkfs.ext3 /dev/md0
1829 mount /dev/md0 /mnt/test
1830 dd if=/dev/urandom of=/mnt/test/dd bs=512 count=10000
1831 md5sum /mnt/test/dd > md5sum
1832
1833 # Make sure the RAID is synched via checking:
1834 cat /proc/mdstat
1835
1836 # Now remove one partition:
1837 mdadm /dev/md0 --fail /dev/hdd1 --remove /dev/hdd1
1838
1839 # Delete partition, create a new + bigger one and set partition type to fd
1840 # (Linux raid autodetect):
1841 cfdisk /dev/hdd
1842
1843 # And re-add the partition:
1844 mdadm -a /dev/md0 /dev/hdd1
1845
1846 # Make sure the RAID is synched via checking:
1847 cat /proc/mdstat
1848
1849 # Repeat the steps for all other disks/partitions as well:
1850 mdadm /dev/md0 --fail /dev/hdb1 --remove /dev/hdb1
1851 cfdisk /dev/hdb
1852 mdadm -a /dev/md0 /dev/hdb1
1853 cat /proc/mdstat
1854 mdadm /dev/md0 --fail /dev/hda1 --remove /dev/hda1
1855 cfdisk /dev/hda
1856 mdadm -a /dev/md0 /dev/hda1
1857 cat /proc/mdstat
1858
1859 # Now resize the RAID5 system online [see 'man mdadm' for details]:
1860 mdadm --detail /dev/md0 | grep -e 'Array Size' -e 'Device Size'
1861 mdadm --grow /dev/md0 -z max
1862 mdadm --detail /dev/md0 | grep -e "Array Size" -e 'Device Size'
1863
1864 # Last step - resize the filesystem (online again):
1865 resize2fs /dev/md0
1866 -- 
1867 ext3 online resizing:
1868
1869 Starting with Linux kernel 2.6.10 you can resize ext3 online.  With
1870 e2fsprogs >=1.39-1 new filesystems are created with directory indexing and
1871 on-line resizing enabled by default (see /etc/mke2fs.conf).
1872
1873 Demo:
1874
1875 cfdisk /dev/hda                           # create a partition with type 8e (lvm)
1876 pvcreate /dev/hda2                        # create a physical volume
1877 vgcreate resize_me /dev/hda2              # create volume group
1878 lvcreate -n resize_me -L100 resize_me     # create a logical volume
1879 mkfs.ext3 /dev/resize_me/resize_me        # now create a new filesystem
1880 mount /dev/resize_me/resize_me /mnt/test  # mount the new fs for demonstrating online resizing
1881 df -h                                     # check the size of the partition
1882 lvextend -L+100M /dev/resize_me/resize_me # let's extend the logical volume
1883 resize2fs /dev/resize_me/resize_me        # and finally resize the filesystem
1884 df -h                                     # recheck the size of the partition
1885
1886 This also works for Software-RAID. Demo:
1887
1888 mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/hda2 /dev/hdb1
1889 mkfs.ext3 /dev/md0
1890 mount /dev/md0 /mnt/test
1891 mdadm /dev/md0 --fail /dev/hda2 --remove /dev/hda2
1892 cfdisk /dev/hda                                  # adjust partition size for hda2
1893 mdadm /dev/md0 --add /dev/hda2
1894 mdadm /dev/md0 --fail /dev/hdb1 --remove /dev/hdb1
1895 cfdisk /dev/hdb                                  # adjust partition size for hdb1
1896 mdadm /dev/md0 --add /dev/hdb1
1897 mdadm --grow /dev/md0 --size=max
1898 resize2fs /dev/md0
1899
1900 Notice: online resizing works as soon as the kernel can re-read the
1901 partition table. So it works for example with LVM and SW-RAID but not with
1902 a plain device (/dev/[sh]d*). The kernel does not re-read the partition
1903 table if the device is already mounted.
1904 -- 
1905 Use vim as an outline editor:
1906
1907 % $PAGER /usr/share/doc/vim-vimoutliner/README.Debian
1908 % vim ~/foo.otl
1909 :he vo
1910 -- 
1911 Monitor directories/files for changes using iwatch
1912
1913 Monitor /tmp for changes:
1914 % iwatch /tmp/
1915
1916 Monitor files/directories specified in /etc/iwatch.xml
1917 and send mail on changes:
1918 % iwatch
1919 -- 
1920 Some often used mdadm commands:
1921
1922 Set up RAID1:
1923 # mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/hda1 /dev/hdb1
1924
1925 Display details of specific RAID:
1926 # mdadm --detail /dev/md0
1927 # cat /proc/mdstat
1928
1929 Simulating a drive failure by software:
1930 # mdadm --manage --set-faulty /dev/md0 /dev/hda1
1931
1932 Remove disk from RAID:
1933 # mdadm /dev/md0 -r /dev/hda1
1934
1935 Set disk as faulty and remove from RAID:
1936 # mdadm /dev/md0 --fail /dev/hda1 --remove /dev/hda1
1937
1938 Stop a RAID-device:
1939 # mdadm -S /dev/md0
1940
1941 Restart a RAID-device:
1942 # mdadm -R /dev/md0
1943
1944 Add another disk to existing RAID setup (hotadd):
1945 # mdadm /dev/md0 -a /dev/hde1
1946 # mdadm --grow /dev/md0 --raid-devices=4
1947
1948 Assemble and start all arrays:
1949 # mdadm --assemble --scan
1950
1951 Assemble a specific array:
1952 # mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1
1953
1954 Resync:
1955 # mdadm --assemble --run --force --update=resync /dev/md0 /dev/sda1 /dev/sda2
1956
1957 Stop and rebuild:
1958 # mdadm --stop --scan
1959
1960 Scan for and setup arrays automatically:
1961 # mdadm --assemble --scan --auto=yes --verbose
1962
1963 Notice: If the above does not work make sure /etc/mdadm/mdadm.conf contains:
1964 DEVICE partitions
1965 CREATE owner=root group=disk mode=0660 auto=yes
1966 HOMEHOST <system>
1967 MAILADDR root
1968
1969 Running
1970 # /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf
1971 might help as well.
1972
1973 Monitoring the sw raid
1974 # nohup mdadm --monitor --mail=root@localhost --delay=300 /dev/md0
1975
1976 Producing /etc/mdadm/mdadm.conf:
1977 # mdadm --detail --scan > /etc/mdadm/mdadm.conf
1978
1979 See also: man mdadm | less -p "^EXAMPLES"
1980           http://www.tldp.org/HOWTO/Software-RAID-HOWTO.html
1981 -- 
1982 A quick summary of the most commonly used RAID levels:
1983
1984 RAID 0: Striped Set
1985  => 2 disks each 160 GB: 320 GB data
1986 RAID 1: Mirrored Set
1987  => 2 disks each 160 GB: 160 GB data
1988 RAID 5: Striped Set with Parity
1989  => 3 disks each 160 GB: 320 GB data; 160 GB redundancy
1990
1991 Common nested RAID levels:
1992 RAID 01: A mirror of stripes
1993 RAID 10: A stripe of mirrors
1994 RAID 30: A stripe across dedicated parity RAID systems
1995 RAID 100: A stripe of a stripe of mirrors
1996
1997   -- http://en.wikipedia.org/wiki/RAID
1998 -- 
1999 Logical Volume Management (LVM) with Linux
2000
2001 LVM setup layout:
2002 ~~~~~~~~~~~~~~~~~
2003
2004 |    hda1   hdc1      (PV:s on partitions or whole disks)
2005 |       \   /
2006 |        \ /
2007 |       diskvg        (VG)
2008 |       /  |  \
2009 |      /   |   \
2010 |  usrlv rootlv varlv (LV:s)
2011 |    |      |     |
2012 | ext3    ext3  xfs   (filesystems)
2013
2014 Often used commands:
2015 ~~~~~~~~~~~~~~~~~~~~
2016
2017 Create a physical volume:
2018 # pvcreate /dev/hda2
2019
2020 Create a volume group:
2021 # vgcreate testvg /dev/hda2
2022
2023 Create a logical volume:
2024 # lvcreate -n test_lv -L100 testvg
2025
2026 Resize a logical volume:
2027 # lvextend -L+100M /dev/resize_me/resize_me
2028 # resize2fs /dev/resize_me/resize_me               # ext2/3
2029 # xfs_growfs  /dev/resize_me/resize_me             # xfs
2030 # resize_reiserfs -f /dev/resize_me/resize_me      # reiserfs online
2031 # mount -o remount,resize /dev/resize_me/resize_me # jfs
2032
2033 Create a snapshot of a logical volume:
2034 # lvcreate -L 500M --snapshot -n mysnap /dev/testvg/test_lv
2035
2036 Deactivate a volume group:
2037 # vgchange -a n my_volume_group
2038
2039 Actually remove a volume group:
2040 # vgremove my_volume_group
2041
2042 Display information about physical volume:
2043 # pvdisplay /dev/hda1
2044
2045 Remove physical volume:
2046 # vgreduce my_volume_group /dev/hda1
2047
2048 Remove logical volume:
2049 # umount /dev/myvg/homevol
2050 # lvremove /dev/myvg/homevol
2051
2052 See also: man lvm
2053           http://www.tldp.org/HOWTO/LVM-HOWTO/
2054 -- 
2055 How to use APT locally
2056
2057 Sometimes you have lots of packages .deb that you would like to use APT to
2058 install so that the dependencies would be automatically solved. Solution:
2059
2060 mkdir debs
2061 dpkg-scanpackages debs /dev/null | gzip > debs/Packages.gz
2062 echo "  deb file:/root debs/" >> /etc/apt/sources.list
2063 dpkg-scansources debs | gzip > debs/Sources.gz
2064 echo "  deb-src file:/root debs/" >> /etc/apt/sources.list
2065
2066 See also: http://www.debian.org/doc/manuals/apt-howto/ch-basico.en.html
2067 -- 
2068 Check filesystem's LABEL:
2069
2070 generic way:
2071 # vol_id -l /dev/sda1
2072
2073 ext2/3 without vol_id:
2074 # dumpe2fs /dev/sda1 | grep "Filesystem volume name"
2075
2076 xfs without vol_id:
2077 # xfs_admin -l /dev/sda1
2078
2079 reiserfs without vol_id:
2080 # debugreiserfs /dev/sda1 | grep -i label
2081
2082 jfs without vol_id:
2083 # jfs_tune -l /dev/sda1 | grep -i label
2084
2085 reiser4 without vol_id:
2086 # debugfs.reiser4 /dev/sda1 | grep -i label
2087 -- 
2088 Check filesystem's UUID:
2089
2090 generic way:
2091 # vol_id -u /dev/sda1
2092
2093 ext2/3 without vol_id:
2094 # dumpe2fs /dev/sda1 | grep -i UUID
2095
2096 xfs without vol_id:
2097 # xfs_admin -u /dev/sda1
2098
2099 reiserfs without vol_id:
2100 # debugreiserfs /dev/sda1 | grep -i UUID
2101
2102 reiser4 without vol_id:
2103 # debugfs.reiser4 /dev/sda1 | grep -i UUID
2104 -- 
2105 Change a filesystem's LABEL:
2106
2107 swap:
2108 # mkswap -L $LABEL /dev/sda1
2109
2110 ext2/ext3:
2111 # e2label /dev/sda1 $LABEL
2112 # tune2fs -L $LABEL /dev/sda1
2113
2114 reiserfs:
2115 # reiserfstune -l $LABEL /dev/sda1
2116
2117 jfs:
2118 # jfs_tune -L $LABEL /dev/sda1
2119
2120 xfs:
2121 # xfs_admin -L $LABEL /dev/sda1
2122
2123 fat/vfat:
2124 # echo 'drive i: file="/dev/sda1"' >> ~/.mtoolsrc
2125 # mlabel -s i:$LABEL
2126
2127 ntfs:
2128 # ntfslabel $LABEL /dev/sda1
2129 -- 
2130 Disable pdiffs feature of APT:
2131
2132 Permanent:
2133 # echo 'Acquire::PDiffs "false";' >> /etc/apt/apt.conf
2134
2135 Temporary:
2136 # apt-get update -o Acquire::Pdiffs=false
2137 -- 
2138 Backup big devices or files and create compressed splitted
2139 image chunks of it using zsplit
2140
2141 Create backup of /dev/sda named archiveofsda_#.spl.zp in directory
2142 /mnt/sda1/backup, split the files up into chunks of 1GB each and set
2143 read/write buffer to 256kB:
2144 # zsplit -b 256 -N archiveofsda -o /mnt/sda1/backup/ -s 1G /dev/sda
2145
2146 Restore the backup using unzsplit:
2147 # unzsplit -D /dev/sda -d archiveofsda
2148
2149 More usage examples: man zsplit + man unzsplit
2150 -- 
2151 Measure network performance using iperf:
2152
2153 Server side:
2154 % iperf -s -V
2155
2156 Client side:
2157 % iperf -c <server_address> -V
2158
2159 or
2160
2161 Server with 128k TCP window size:
2162 % iperf -s -w128k
2163
2164 Client with running for 60 seconds and bidirectional test:
2165 % iperf -c <server_address> -r -w128k -t60
2166 -- 
2167 Framebuffer resolutions:
2168
2169                               Resolution in pixels
2170 Color depth      |   640x480      800x600      1024x768      1280x1024
2171 256        (8bit)|     769          771           773           775
2172 32000     (15bit)|     784          787           790           793
2173 65000     (16bit)|     785          788           791           794
2174 16.7 Mill.(24bit)|     786          789           792           795
2175
2176 vga=0x... modes:
2177
2178   Mode 0x0300: 640x400 (+640), 8 bits
2179   Mode 0x0301: 640x480 (+640), 8 bits
2180   Mode 0x0303: 800x600 (+800), 8 bits
2181   Mode 0x0303: 800x600 (+832), 8 bits
2182   Mode 0x0305: 1024x768 (+1024), 8 bits
2183   Mode 0x0307: 1280x1024 (+1280), 8 bits
2184   Mode 0x030e: 320x200 (+640), 16 bits
2185   Mode 0x030f: 320x200 (+1280), 24 bits
2186   Mode 0x0311: 640x480 (+1280), 16 bits
2187   Mode 0x0312: 640x480 (+2560), 24 bits
2188   Mode 0x0314: 800x600 (+1600), 16 bits
2189   Mode 0x0315: 800x600 (+3200), 24 bits
2190   Mode 0x0317: 1024x768 (+2048), 16 bits
2191   Mode 0x0318: 1024x768 (+4096), 24 bits
2192   Mode 0x031a: 1280x1024 (+2560), 16 bits
2193   Mode 0x031b: 1280x1024 (+5120), 24 bits
2194   Mode 0x0330: 320x200 (+320), 8 bits
2195   Mode 0x0331: 320x400 (+320), 8 bits
2196   Mode 0x0332: 320x400 (+640), 16 bits
2197   Mode 0x0333: 320x400 (+1280), 24 bits
2198   Mode 0x0334: 320x240 (+320), 8 bits
2199   Mode 0x0335: 320x240 (+640), 16 bits
2200   Mode 0x0336: 320x240 (+1280), 24 bits
2201   Mode 0x033c: 1400x1050 (+1408), 8 bits
2202   Mode 0x033d: 640x400 (+1280), 16 bits
2203   Mode 0x033e: 640x400 (+2560), 24 bits
2204   Mode 0x0345: 1600x1200 (+1600), 8 bits
2205   Mode 0x0346: 1600x1200 (+3200), 16 bits
2206   Mode 0x034d: 1400x1050 (+2816), 16 bits
2207   Mode 0x035c: 1400x1050 (+5632), 24 bits
2208 -- 
2209 Portscan using netcat:
2210
2211 # netcat -v -w2 <host|ip-addr.> 1-1024
2212 -- 
2213 Run apt-get but disable apt-listchanges:
2214
2215 APT_LISTCHANGES_FRONTEND=none apt-get ...
2216
2217 Upgrade system but disable apt-listbugs:
2218
2219 APT_LISTBUGS_FRONTEND=none apt-get ...
2220 -- 
2221 Set up a Transparent Debian Proxy
2222
2223 Install of apt-cacher, the default config will do:
2224 # apt-get install apt-cacher
2225
2226 Check out the ip address of debian mirror(s).
2227 Then add this to your firewall script:
2228
2229 DEBIAN_MIRRORS="141.76.2.4 213.129.232.18"
2230 for ip in ${DEBIAN_MIRRORS} ; do
2231   ${IPTABLES} -t nat -A PREROUTING -s $subnet -d $ip -p tcp --dport 80 -j REDIRECT --to-port 3142
2232 done
2233
2234 where ${IPTABLES} is the location of your iptables binary
2235 and $subnet is your internal subnet.
2236
2237 Now everybody in your subnet who does access either
2238 ftp.de.debian.org or ftp.at.debian.org will actually
2239 access your apt-cacher instead.
2240
2241 To use apt-cacher on the router itself, add the following
2242 line to your /etc/apt/apt.conf:
2243
2244 Acquire::http::Proxy "http://localhost:3142/";
2245 -- 
2246 Version control using Mercurial
2247
2248 Setting up a Mercurial project:
2249
2250 % cd project
2251 % hg init           # creates .hg
2252 % hg add            # add all files
2253 % hg commit         # commit all changes, edit changelog entry
2254
2255 Branching and merging:
2256
2257 % hg clone linux linux-work  # create a new branch
2258 % cd linux-work
2259 <make changes>
2260 % hg commit
2261 % cd ../linux
2262 % hg pull ../linux-work     # pull changesets from linux-work
2263 % hg merge                  # merge the new tip from linux-work into
2264                             # (old versions used "hg update -m" instead)
2265                             # our working directory
2266 % hg commit                 # commit the result of the merge
2267
2268 Importing patches:
2269
2270 % cat ../p/patchlist | xargs hg import -p1 -b ../p
2271
2272 Exporting a patch:
2273
2274 (make changes)
2275 % hg commit
2276 % hg tip
2277 1234:af3b5cd57dd5
2278 % hg export 1234 > foo.patch    # export changeset 1234
2279
2280 Export your current repo via HTTP with browsable interface:
2281
2282 % hg serve -n "My repo" -p 80
2283
2284 Pushing changes to a remote repo with SSH:
2285
2286 % hg push ssh://user@example.com/~/hg/
2287
2288 Merge changes from a remote machine:
2289
2290 host1% hg pull http://foo/
2291 host2% hg merge # merge changes into your working directory
2292
2293 Set up a CGI server on your webserver:
2294 % cp hgwebdir.cgi ~/public_html/hg/index.cgi
2295 % $EDITOR ~/public_html/hg/index.cgi # adjust the defaults
2296
2297 Mercurial repositories of grml can be found at http://hg.grml.org/
2298 -- 
2299 Download binary codecs for mplayer:
2300
2301 # /usr/share/mplayer/scripts/win32codecs.sh
2302
2303 or
2304
2305 # /usr/share/mplayer/scripts/binary_codecs.sh install
2306
2307 (depending on the mplayer version you have).
2308
2309 To play encrypted DVDs and if you are living in a country where using
2310 libdvdcss code is not illegal can install Debian package libdvdread3
2311 and use the script /usr/share/doc/libdvdread3/install-css.sh.
2312 -- 
2313 Read manpages of uninstalled packages with debman:
2314
2315 % debman -p git-core git
2316 -- 
2317 Test network performance using netperf:
2318
2319 Server:
2320 # netserver
2321
2322 Client:
2323 # netperf -t TCP_STREAM -H 192.168.0.41
2324 -- 
2325 Setup Xen within 20 minutes on Debian/grml
2326
2327 Install relevant software und update grub's menu.lst (Xen does not work with
2328 usual lilo so install grub instead if not done already):
2329
2330 apt-get install linux-image-2.6.18-1-xen-686 xen-hypervisor-3.0.3-1-i386 \
2331                  xen-utils-3.0.3-1 xen-tools bridge-utils
2332 update-grub
2333
2334 Example for installation of Debian etch as DomU:
2335
2336 mkdir /mnt/md1/xen
2337 xen-create-image --debootstrap --dir=/mnt/md1/xen --size=2Gb --memory=512Mb --fs=ext3 \
2338    --cache=yes --dist=etch --hostname=xengrml1 --ip 192.168.1.2 --netmask 255.255.255.0 \
2339   --gateway 192.168.1.1 --initrd=/boot/initrd.img-2.6.18-1-xen-686 \
2340   --kernel=/boot/vmlinuz-2.6.18-1-xen-686 --mirror=http://ftp.at.debian.org/debian/
2341
2342 Start services:
2343
2344 /etc/init.d/xend start
2345 /etc/init.d/xendomains start
2346
2347 Setup a bridge for network, either manually:
2348
2349 brctl addbr xenintbr
2350 brctl stp xenintbr off
2351 brctl sethello xenintbr 0
2352 brctl setfd xenintbr 0
2353 ifconfig xenintbr 192.168.1.1 netmask 255.255.255.0 up
2354
2355 or via /etc/network/interfaces (run ifup xenintbr to bring up the device then
2356 without rebooting):
2357
2358 auto xenintbr
2359 iface xenintbr inet static
2360   pre-up brctl addbr xenintbr
2361   post-down brctl delbr xenintbr
2362   address 192.168.1.1
2363   netmask 255.255.255.0
2364   bridge_fd 0
2365   bridge_hello 0
2366   bridge_stp off
2367
2368 Setup forwarding (adjust $PUBLIC_IP; for permanet setup use /etc/sysctl.conf and
2369 add the iptables commands to a startup script like /etc/init.d/rc.local):
2370
2371 echo 1 > /proc/sys/net/ipv4/ip_forward
2372 iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j SNAT --to $PUBLIC_IP
2373 iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to $PUBLIC_IP
2374
2375 Adjust network configuration of Xend:
2376
2377 cat >> /etc/xen/xend-config.sxp << EOF
2378 (network-script    network-route)
2379 (vif-bridge        xenintbr)
2380 (vif-script        vif-bridge)
2381 EOF
2382
2383 List domains, start up a DomU, shutdown later again:
2384
2385 xm create -c /etc/xen/xengrml1.cfg
2386 xm list
2387 xm shutdown 1
2388
2389 This HowTo is also available online at http://grml.org/xen/
2390 -- 
2391 Play tetris with zsh:
2392
2393 autoload -U tetris
2394 zle -N tetris
2395 bindkey "^Xt" tetris
2396
2397 Now press 'ctrl-x t'.
2398 -- 
2399 Set up a router with grml
2400
2401 Run grml-router script:
2402 # grml-router
2403
2404 Install dnsmasq if not already present:
2405 # apt-get update ; apt-get install dnsmasq
2406
2407 Adjust /etc/dnsmasq.conf according to your needs:
2408 # cat >> /etc/dnsmasq.conf << EOF
2409 domain-needed
2410 bogus-priv
2411 dhcp-range=19.168.0.124,192.168.0.254,1m # dhcp range
2412 dhcp-option=3,192.168.0.1   # dns server
2413 dhcp-option=1,255.255.255.0 # netmask
2414 EOF
2415
2416 Start dnsmasq finally:
2417 # Restart dnsmasq
2418 -- 
2419 Display stats about memory allocations performed by a program:
2420
2421 Usage example for 'ls':
2422
2423 % LD_PRELOAD=/lib/libmemusage.so ls > /dev/null
2424 -- 
2425 Use KVM (Kernel-based Virtual Machine for Linux):
2426
2427 Make sure to install the relevant tools:
2428 # apt-get update ; apt-get install kvm
2429 # modprobe kvm
2430
2431 Test it with a minimal system like ttylinux:
2432 # wget http://www.minimalinux.org/ttylinux/packages/bootcd-i386-5.3.iso.gz
2433 # gzip -d bootcd-i386-5.3.iso.gz
2434 # kvm -cdrom bootcd-i386-5.3.iso
2435 -- 
2436 EEPROM data decoding for SDRAM DIMM modules:
2437
2438 # modprobe eeprom
2439 # /usr/share/doc/lm-sensors/examples/eeprom/decode-dimms.pl
2440 -- 
2441 Set up and use DVB:
2442
2443 Make sure your device is supported by Linux and running.
2444 See http://www.linuxtv.org/ for more details.
2445
2446 If the DVB device works on your system (see 'hwinfo --usb'
2447 when using a DVB usb device for example), then make sure you
2448 have the scan util from dvb-utils available:
2449
2450 # aptitude install dvb-utils
2451
2452 Then create a channels.conf configuration file:
2453
2454 % scan /usr/share/doc/dvb-utils/examples/scan/... > ~/.mplayer/channels.conf
2455
2456 You can find some example configuration files on
2457 your grml system in ~/.channels. Usage example:
2458
2459 % ln -s ~/.mplayer/channels.conf-AT-graz ~/.mplayer/channels.conf
2460
2461 Tip: w_scan (see http://free.pages.at/wirbel4vdr/w_scan/index2.html)
2462 might be useful if you do not know the initial configuration
2463 details.
2464 -- 
2465 Get the lastest mercurial snapshot:
2466
2467 Make sure you have the python-dev package available:
2468 # apt-get update ; apt-get install python-dev
2469
2470 Get and build the source:
2471 % hg clone http://selenic.com/repo/hg mercurial
2472 % cd mercurial
2473 % make local
2474 % export PYTHONPATH=$(pwd)
2475 % export PATH=$PATH:$(pwd)
2476
2477 now you should have the newest version of mercurial whenever you execute hg.
2478
2479 To update to the lastest development snapshot, additionally use
2480 the following commands:
2481 % hg pull -u http://hg.intevation.org/mercurial/crew
2482 % make local
2483 -- 
2484 Configure timezone
2485 ==================
2486
2487 Available bootoptions relevant in live-cd mode:
2488 -----------------------------------------------
2489
2490 * utc: set UTC, if your system clock is set to UTC (GMT)
2491 * gmt: set UTC, if your system clock is set to UTC (GMT) [like bootoption utc]
2492 * tz=$option: set timezone to corresponding $option, usage example:
2493   tz=Europe/Vienna
2494
2495 Configuration options relevant on harddisk installation:
2496 --------------------------------------------------------
2497
2498 * Use the tzconfig utility to set the local timezone:
2499
2500   # tzconfig
2501
2502   which adjusts /etc/timezone and /etc/localtime according
2503   to the provided information. Running:
2504
2505   # dpkg-reconfigure tzdata
2506
2507   might be useful as well.
2508
2509 * /etc/default/rcS: set variable UTC according to your needs,
2510   whether your system clock is set to UTC (UTC='yes') or
2511   not (UTC='no')
2512
2513 * /etc/localtime: adjust zoneinfo according to your needs:
2514
2515   # ln -sf /usr/share/zoneinfo/$WHATEVER_YOU_WANT /etc/localtime
2516
2517   The zoneinfo directory contains the time zone files that were
2518   compiled by zic. The files contain information such as rules
2519   about DST. They allow the kernel to convert UTC UNIX time into
2520   appropriate local dates and times. Use the zdump utility to
2521   print current time and date (in the specified time zone).
2522
2523 * /etc/adjtime: This file is used e.g. by the adjtimex function,
2524   which can smoothly adjust system time while the system runs
2525
2526 * If you change the time (using 'date --set ...', ntpdate,...)
2527   it is worth setting also the hardware clock to the correct time:
2528
2529   # hwclock --systohc [--utc]
2530
2531   Remember to add the --utc -option if the hardware clock is set
2532   to UTC!
2533
2534 Still problems?
2535 ---------------
2536
2537 Check your current settings via:
2538
2539   cat /etc/timezone
2540   zdump /etc/localtime
2541   echo $TZ
2542   hwclock --show
2543   grep hwclock /etc/runlevel.conf
2544   grep '^UTC' /etc/default/rc
2545
2546 Further information:
2547 --------------------
2548
2549   hwclock(8) tzselect(1) tzconfig(8)
2550   http://www.debian.org/doc/manuals/system-administrator/ch-sysadmin-time.html
2551   http://wiki.debian.org/TimeZoneChanges
2552 -- 
2553 Recorder shellscript session using script:
2554
2555 % script -t 2>~/upgrade.time -a ~/upgrade.script
2556 % scriptreplay ~/upgrade.time ~/upgrade.script
2557 -- 
2558 Test UTF-8 capabilities of terminal:
2559
2560 wget http://melkor.dnp.fmph.uniba.sk/~garabik/debian-utf8/download/UTF-8-demo.txt.gz
2561 zcat UTF-8-demo.txt.gz
2562
2563 or:
2564
2565 wget http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
2566 cat UTF-8-test.txt
2567 -- 
2568 UTF-8 at grml / some general information regarding Unicde/UTF-8:
2569
2570   http://wiki.grml.org/doku.php?id=utf8
2571 -- 
2572
2573 This allows one ssh connection attepmt per minute per source ip, with a initial
2574 burst of 10.  The available burst is like a counter which is initialised with
2575 10. Every connection attempt decrements the counter, and every minute where the
2576 connection limit of one per minute is not overstepped the counter is
2577 incremented by one.  If the burst counter is exhausted the real rate limit
2578 comes into play. This gives you 11 connectionattepmts in the first minute
2579 before blocked for 10minutes.  After 10 minutes block the game restarts.
2580
2581 Hint: you could set the burst value to 5 and the block time to only 5 minutes
2582 to achive the same average connection rate but with halve the block time.
2583
2584 iptables -A inet_in -p tcp --syn --dport 22 -m hashlimit --hashlimit-name ssh \
2585          --hashlimit 1/minute \ --hashlimit-burst 10 --hashlimit-mode srcip   \
2586          --hashlimit-htable-expire 600000 -j ACCEPT
2587 iptables -A inet_in -p tcp --dport 22 -m state --state NEW -j REJECT
2588 -- 
2589 Tunnel a specific connection via socat:
2590
2591 On the client:
2592 % socat TCP4-LISTEN:8003 TCP4:gateway:500
2593
2594 On the gateway:
2595 # socat TCP4-LISTEN:500,fork TCP4:target:$PORT
2596
2597 Using localhost:8003 on the client uses the tunnel now.
2598 -- 
2599 Set date:
2600
2601 # date --set=060916102007
2602
2603 where the bits are month(2)/day(2)/hour(2)/minute(2)/year(4)
2604
2605 Set date using a relative date:
2606
2607 # date -s '+3 mins'
2608
2609 or
2610
2611 # date -s '+tomorrow'
2612
2613 Display a specific relative date:
2614
2615 # date -d '+5 days -2 hours'
2616
2617 Don't forget to set hardware clock via:
2618
2619 # hwlock -w
2620 -- 
2621 Booting grml via network / PXE:
2622
2623 Start grml-terminalserver on a system with network access
2624 and where grml is running:
2625
2626 # grml-terminalserver
2627
2628 Then booting your client(s) via PXE should work without
2629 any further work.
2630 -- 
2631 Debugging SSL communications:
2632
2633 % openssl s_client -connect server.adress:993
2634
2635 or
2636
2637 # ssldump -a -A -H -i eth0
2638
2639 See http://prefetch.net/articles/debuggingssl.html for more details.
2640 -- 
2641 Remove bootmanager from MBR:
2642
2643 # lilo -M /dev/hda -s /dev/null
2644 -- 
2645 Rewrite grub to MBR:
2646
2647 # mount /mnt/sda1
2648 # grub-install --recheck --no-floppy --root-directory=/mnt/sda1 /dev/sda
2649 -- 
2650 Rewrite lilo to MBR:
2651
2652 # mount /mnt/hda1
2653 # lilo -r /mnt/hda1
2654 -- 
2655 Create screenshot of plain/real console - tty1:
2656 # fbgrab -c 1 screeni.png
2657 -- 
2658 Create screenshot when running X:
2659
2660 % scrot
2661
2662 Tip: use the gkrellshoot plugin when using gkrellm
2663 -- 
2664 Redirect all connections to hostA:portA to hostB:portB, where hostA and hostB are
2665 different networks:
2666
2667 Run the following commands on hostA:
2668
2669 echo 1 > /proc/sys/net/ipv4/ip_forward
2670 iptables -t nat -A PREROUTING -p tcp --dport portA -j DNAT --to hostB:portB
2671 iptables -A FORWARD -i eth0 -o eth0 -d hostB -p tcp --dport portB -j ACCEPT
2672 iptables -A FORWARD -i eth0 -o eth0 -s hostB -p tcp --sport portB -j ACCEPT
2673 iptables -t nat -A POSTROUTING -p tcp -d hostB --dport portB -j SNAT --to-source hostA
2674 -- 
2675