aee5339572e0340d43c1d4902d74cd41d3a89010
[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 Tags: grml2hd, installation
12 -- 
13 Install grml on software RAID level 1:
14
15 Create /dev/md0 (and some more /dev/md* devices) first of all:
16 # cd /dev && MAKEDEV dev
17
18 Create RAID:
19 # mdadm --create --verbose /dev/md0 --level=raid1 \
20         --raid-devices=2   /dev/hda1  /dev/hdc1
21
22 Finally install grml on it:
23 # SWRAID='mbr-only' grml2hd /dev/md0 -mbr /dev/md0
24
25 See: man grml2hd + http://grml.org/grml2hd/
26
27 Tags: grml2hd, installation, mdadm, raid
28 -- 
29 Install grml in non interactive mode with grml2hd:
30
31 Adjust configuration as needed:
32 # vim /etc/grml2hd/config
33
34 Then execute:
35
36 # GRML2HD_NONINTERACTIVE=yes grml2hd
37
38 or run:
39
40 # grml2hd -i
41
42 Use with care and only if you really know what you are doing!
43
44 See: man grml2hd + http://grml.org/grml2hd/
45
46 Tags: grml2hd, installation
47 -- 
48 Configure network:
49
50 # grml-network
51
52 Tags: configuration, network
53 -- 
54 Deactivate error correction of zsh:
55
56 % NOCOR=1 zsh
57
58 Run zsh-help for more information regarding zsh.
59
60 Tags: zsh, configuration
61 -- 
62 Disable automatic setting of title in GNU screen:
63
64 % NOPRECMD=1 zsh
65
66 Set it manually e.g. via:
67
68 % screen -X title foobar
69
70 Run zsh-help for more information regarding zsh.
71
72 Tags: zsh, configuration
73 -- 
74 Do not use menu completion in zsh:
75
76 % NOMENU=1 zsh
77
78 Run zsh-help for more information regarding zsh.
79
80 Tags: zsh, configuration
81 -- 
82 Run GNU screen with grml-configuration:
83
84 % grml-screen
85
86 or
87
88 % screen -c /etc/grml/screenrc
89
90 Tags: screen, configuration
91 -- 
92 Print out grml-version:
93
94 % grml-version
95
96 Tags: grml
97 -- 
98 Configure mutt:
99
100 % grml-mutt
101
102 Tags: mutt
103 -- 
104 Configure mutt-ng / muttng:
105
106 % grml-muttng
107
108 Tags: muttng
109 -- 
110 Set up Inode-PPTP connection:
111
112 # grml-pptp-inode
113 or
114 # grml-pptp-xdsl-students
115
116 Tags: pptp, inode, xdsl
117 -- 
118 Set up VPN / WLAN connection at TUG (TU Graz):
119
120 Set ESSID and request for ip-address via DHCP:
121 # iwconfig $DEVICE essid tug
122 # dhclient $DEVICE
123
124 Now run the main script:
125 # grml-vpnc-tugraz
126
127 After running the script an init script is available:
128
129 # /etc/init.d/vpnctug [start|stop]
130
131 Tags: tug
132 -- 
133 Set up PPTP connection at VCG (Virtual Campus Graz):
134
135 # grml-pptp-vcgraz
136
137 Tags: pptp, vcg
138 -- 
139 Set up VPN:
140
141 # grml-vpn <options>
142
143 Usage example:
144
145 # grml-vpn -k 2005 add 1000 192.168.20.1 192.168.20.2
146
147 See: man grml-vpn
148
149 Tags: grml, vpn, network
150 -- 
151 Use encrypted files / partitions:
152
153 # grml-crypt <options>
154
155 Usage example:
156
157 Initialize:
158
159 # grml-crypt format /mnt/external1/encrypted_file /mnt/test
160 # cp big_file /mnt/test
161 # grml-crypt stop /mnt/test
162
163 Use:
164
165 # grml-crypt start /mnt/external1/encrypted_file /mnt/test
166 # grml-crypt stop /mnt/test
167
168 See: man grml-crypt
169
170 Tags: crypto, grml-crypt, dmcrypt, luks
171 -- 
172 Change resolution of X:
173
174 % xrandr -s '1024x768'
175
176 Tags: x11, xorg, resolution
177 -- 
178 Change resolution of framebuffer:
179
180 # fbset 800x600-60
181
182 Tags: resolution
183 -- 
184 Configure newsreader slrn:
185
186 % grml-slrn
187
188 Tags: slrn
189 -- 
190 Configure grml system:
191
192 # grml-config
193
194 Or directly run scripts:
195
196 # grml-config-root
197 % grml-config-user
198
199 Tags: grml, configuration
200 -- 
201 Lock screen (X / console):
202
203 % grml-lock
204
205 Press ctrl-alt-x to lock a GNU screen session.
206
207 Tags: grml, lock, grml-lock, screen
208 -- 
209 Change wallpaper in X:
210
211 % grml-wallpaper <press-tab>
212
213 Tags: grml, wallpaper
214 -- 
215 Start X window system (XFree86 / Xorg / X.org):
216
217 % grml-x $WINDOWMANAGER
218
219 Usage examples:
220
221 % grml-x fluxbox
222 % grml-x -mode '1024x768' wmii
223 % grml-x -nosync wm-ng
224
225 Tags: grml-x, x11, xorg, graphic
226 -- 
227 Collect hardware information:
228
229 % grml-hwinfo
230
231 or run as root to collect some more information:
232
233 # grml-hwinfo
234
235 will generate a file named info.tar.bz2.
236
237 Tags: grml, hardware, hwinfo, collect
238 -- 
239 Configure hardware detection features of harddisk installation:
240
241 # grml-autoconfig
242
243 or manually edit /etc/grml/autoconfig[.small]
244
245 See: man grml-autoconfig
246
247 Tags: grml, installation, configuration
248 -- 
249 Bootoptions / cheatcodes / bootparams for booting grml:
250
251 On the grml-ISO if not running grml:
252 % less /cdrom/GRML/grml-cheatcodes.txt
253
254 When running grml:
255 % most /usr/share/doc/grml-docs/grml-cheatcodes.txt.gz
256
257 Tags: grml, cheatcodes, boot, bootoptions, bootparam
258 -- 
259 Report bugs to Debian's Bug Tracking System (BTS):
260
261 % reportbug --bts debian
262
263 or adjust /etc/reportbug.conf to your needs.
264
265 See:
266
267   http://grml.org/bugs/
268   http://www.debian.org/Bugs/
269
270 Tags: bug, reportbug, bts, debian
271 -- 
272 Offline documentation:
273
274 % grml-info
275
276 Online documentation:
277
278   http://grml.org/faq/
279   http://grml.org/docs/
280   http://wiki.grml.org/doku.php
281
282 Tags: info, grml, grml-info, documentation
283 -- 
284 Mount NTFS partition (read-write):
285
286 # mount.ntfs-3g /dev/sda1 /mnt/sda1
287
288 Tags: ntfs, mount
289 -- 
290 Overwrite specific file on an NTFS partition:
291
292 ntfscp /dev/hda1 /tmp/file_source path/to/file_target
293 -- 
294 Resize an NTFS partition:
295
296 # ntfsresize ..
297
298 Usage example:
299
300 ntfsresize -n -s 10G /dev/hda1 # testcase
301 ntfsresize -s 10G /dev/hda1    # testing was successfull, now really resize partition
302 cfdisk /dev/hda   # delete partition hda1, create new one with 10000MB and fs-type 07 (NTFS)
303
304 Tags: ntfs, resize, ntfsresize
305 -- 
306 Modify resolution for intel graphic chipsets:
307
308 # 915resolution ..
309
310 Usage example:
311
312 # 915resolution 4d 1400 1050
313 -- 
314 Connect bluetooth mouse:
315
316 # bt-hid start
317
318 ... and press 'connect' button on your bluetooth device.
319 -- 
320 Connect bluetooth headset:
321
322 # bt-audio start
323
324 ... and press 'connect' button on your bluetooth device.
325 -- 
326 Secure delete file / directory / partition:
327
328 # wipe -kq /dev/hda1
329
330 See: man wipe
331
332 Also take a look at shred(1), sfill(1) and http://dban.sourceforge.net/
333
334 Tags: delete, secure, wipe, shred
335 -- 
336 Use grml on Samsung X20 laptop:
337
338 # apt-get install grml-samsung-x20
339
340 See: http://www.michael-prokop.at/computer/samsung_x20.html
341 -- 
342 Development information regarding grml:
343
344   http://blog.grml.org/
345
346 Tags: blog, grml, developmnet
347 -- 
348 Contact Grml team:
349
350 #grml on irc.freenode.org - http://grml.org/irc/
351 http://grml.org/contact/
352
353 Tags: contact, irc, freenode, email
354 -- 
355 Join the grml mailinglist:
356
357 http://grml.org/mailinglist/
358
359 Tags: grml, mailinglist
360 -- 
361 Help us - donate!
362
363 http://grml.org/donations/
364
365 Tags: grml, donation
366 -- 
367 Commercial support / system administration / adjusted live-cds:
368
369 grml-solutions: http://grml.org/solutions/
370
371 Tags: grml, commercial, customize
372 -- 
373 Information regarding the kernel provided by grml:
374
375   http://grml.org/kernel/
376
377 Tags: documentation, grml, kernel
378 -- 
379 SMTP command-line test tool:
380
381 % swaks <options>
382
383 Usage example:
384
385 % swaks -s $MAILSERVER -tlsc -a -au $ACCOUNT -ap $PASSWORD -f $MAILADRESSE -t $MAILADRESSE
386
387 See: man swaks
388
389 Tags: swak, smtp, test
390 -- 
391 NTFS related packages:
392
393 scrounge-ntfs
394 salvage-ntfs
395 ntfsprogs
396
397 Tags: utils, ntfs
398 -- 
399 Modify service through init script:
400
401 # Start ssh
402 # Stop samba
403 # Restart apache
404 # Reload postfix
405 # service gpm start
406 # /etc/init.d/lvm start
407
408 Tags: init, script, start, stop
409 -- 
410 Test joystick:
411
412 # jstest /dev/input/js0
413 -- 
414 Play movie:
415
416 % mplayer /path/to/movie
417
418 Tags: movie, mplayer
419 -- 
420 Use webcam with mplayer:
421
422 % mplayer tv:// -tv driver=v4l:width=352:height=288:outfmt=yv12:device=/dev/video0
423
424 Tags: webcam, mplayer
425 -- 
426 Powerful network discovery tool:
427
428 # scapy
429
430 Tags: network, python, tool
431 -- 
432 Grab an entire CD and compress it to Ogg/Vorbis,
433 MP3, FLAC, Ogg/Speex and/or MPP/MP+(Musepack) format:
434
435 % abcde
436
437 Tags: rip, abcde, mp3, transcode, audio
438 -- 
439 Show a console session in several terminals:
440
441 % gems
442 -- 
443 Switch behaviour of caps lock key:
444
445 % caps-ctrl
446 -- 
447 grep with Perl-compatible regular expressions:
448
449 % pcregrep
450 -- 
451 ncp: a fast file copy tool for LANs
452
453 Local (send file):
454 % npush file_to_copy
455
456 Remote (receive file):
457 % npoll
458
459 Tags: copy, file, network
460 -- 
461 utility for sorting records in complex ways:
462
463 % msort
464 -- 
465 a smaller, cheaper, faster SED implementation:
466
467 % minised
468 -- 
469 zsh tips:
470
471 % man zsh-lovers
472
473 See: http://grml.org/zsh/
474 -- 
475 zsh reference card for grml system:
476
477 http://grml.org/zsh/
478 /usr/share/doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz
479 -- 
480 Multiple rename:
481
482 % for i in foo* ; do mv "$i" "bar${i/foo}" ; done
483 % qmv foo*
484 % prename 's/foo/bar/' foo*
485 % mmv "foo*"   "bar#1"
486 % zmv 'foo(*)' 'bar$1'
487 -- 
488 Test TFT / LCD display:
489
490 % lcdtest
491 -- 
492 Test sound:
493
494 % soundtest
495 -- 
496 Improved grep version:
497
498 % glark
499 -- 
500 Grep with highlighting:
501
502 % grep --color=auto ...
503 % hgrep ...
504
505 Tags: grep, color, highlight
506 -- 
507 Extract matches when grepping:
508
509 Usage examples:
510 % ifconfig | grepc 'inet addr:(.*?)\s'
511 % ifconfig | glark --extract-matches 'inet addr:(.*?)\s'
512 -- 
513 Output text as sound:
514
515 % say 'ghroummel'
516 % xsay            # when running X and text selected via mouse
517 -- 
518 Adjust a grml harddisk (grml2hd) installation:
519
520 # grml2hd-utils
521
522 Tags: grml2hd, configuration, installation
523 -- 
524 Get information on movie files:
525
526 % tcprobe -i file.avi
527 -- 
528 Get an overview of your image files:
529
530 % convert 'vid:*.jpg' thumbnails.jpg
531 -- 
532 List all standard defines:
533
534 % gcc -dM -E - < /dev/null
535 -- 
536 Send a mail as reminder:
537
538 echo "mail -s 'check TODO-list' $MAILADDRESS < /dev/null" | at 23:42
539 -- 
540 ncurses-based presentation tool:
541
542 % tpp
543
544 See: man tpp and /usr/share/doc/tpp/examples/
545 -- 
546 Use ICQ / Jabber / Yahoo! / AIM / MSN /... on command line:
547
548 % centericq
549 -- 
550 Use IRC on command line:
551
552 % irssi
553 -- 
554 Diff / merge files:
555
556 % vimdiff file1 file2
557
558 Re-diffing:
559
560 :diffupdate
561
562 Moving between diffs:
563
564 [c
565 ]c
566
567 Synchronizing:
568
569 :diffget
570 :diffput
571 -- 
572 Hardware monitoring without kernel dependencies:
573
574 % mbmon
575 -- 
576 Install grml-iso to usb-stick:
577
578 % grml2usb grml.iso /mount/point
579
580 Tags: usbpen, usbstick, installation, grml2usb
581 -- 
582 Use mplayer on framebuffer console:
583
584 % mplayer -vo fbdev ...
585 -- 
586 Use links2 on framebuffer console:
587
588 % links2 -driver fb ...
589 -- 
590 Switch language / keyboard:
591
592 * use the bootparam lang to set language environment ($LANG, $LC_ALL, $LANGUAGE)
593 * use the bootparams keyboard / xkeyboard to activate specific keyboard layout
594   Usage example: 'grml lang=us keyboard=de xkeyboard=de'
595
596 Or run one of the following commands:
597
598 % grml-lang de
599 or
600 # loadkeys i386/qwertz/de-latin1-nodeadkeys.kmap.gz # console
601 % setxkbmap de                                      # X11
602
603 Tags: language, keyboard, configuration
604 -- 
605 Switch setting of caps-control key (switch between ctrl + shift) on keyboard:
606
607 # caps-ctrl
608 -- 
609 Mount usb device / usb stick:
610
611 % mount /mnt/external1   # corresponds to /dev/sda1
612 or
613 % mount /mnt/external    # corresponds to /dev/sda
614 -- 
615 Install Sun Java packages:
616
617 Download j2re.bin-file from http://java.sun.com/downloads/index.html and run
618
619 # apt-get install java-package
620 # fakeroot make-jpkg j2re-*.bin
621 # dpkg -i sun-j2re*.deb
622 # update-alternatives --config java
623 -- 
624 Improved dd version:
625
626 ddrescue is an improved version of dd which tries to read and
627 if it fails it will go on with the next sectors, where tools
628 like dd will fail.
629
630 % ddrescue ...
631
632 See: man ddrescue
633 -- 
634 How to make an audio file (e.g. Musepack format) out of a DVD track:
635
636 % mkfifo /tmp/fifo.wav
637 % mppenc /tmp/fifo.wav track06.mpc &
638 % mplayer -vo null -vc null -ao pcm:fast:file=/tmp/fifo.wav -dvd-device /dev/dvd dvd://1 -chapter 6-6
639
640 Adjust the mppenc line with the encoder you would like to use,
641 for example 'oggenc -o track06.ogg /tmp/fifo.wav' for ogg files.
642
643 Alternative:
644
645 % mplayer -vo null -dumpaudio -dumpfile track06.raw -aid N -dvd-device /dev/dvd dvd://1 -chapter 6-6
646 to extract audio without processing, where 'N' is the corresponding audio channel (see 'man mplayer')
647
648 Usage example for getting a PCM/wave file from audio channel 128:
649 % mplayer -vo null -vc null -ao pcm:fast:file=track06.wav -aid 128 -dvd-device /dev/dvd dvd://6
650 -- 
651 Create simple chroot:
652
653 # make_chroot_jail $USERNAME
654 -- 
655 Convert DOS formated file to unix format:
656
657 sed 's/.$//'    dosfile > unixfile       # assumes that all lines end with CR/LF
658 sed 's/^M$//'   dosfile > unixfile       # in bash/tcsh, press Ctrl-V then Ctrl-M
659 sed 's/\x0D$//' dosfile > unixfile       # gsed 3.02.80, but top script is easier
660 awk '{sub(/\r$/,"");print}'              # assumes EACH line ends with Ctrl-M
661 gawk -v BINMODE="w" '1' infile >outfile  # in DOS environment; cannot be done with
662                                          # DOS versions of awk, other than gawk
663 tr -d \r < dosfile > unixfile            # GNU tr version 1.22 or higher
664 tr -d '\015' < dosfile > unixfile        # use octal value for "\r" (see man ascii)
665 tr -d '[\015\032]' < dosfile > unixfile  # sometimes ^Z is appended to DOS-files
666 vim -c ":set ff=unix" -c ":wq" file      # convert using vim
667 vim -c "se ff=dos|x" file                # ... and even shorter ;)
668 recode ibmpc..lat1 file                  # convert using recode
669 echo -e "s/\r//g" > dos2unix.sed; sed -f dos2unix.sed < dosfile > unixfile
670
671 Tags: windows, line, convert, recode, tr, line end,
672 -- 
673 Save live audio stream to file:
674
675 % mplayer -ao pcm:file=$FILE $URL
676 -- 
677 Save live stream to file:
678
679 % mplayer -dumpfile $FILE -dumpstream $STREAM
680
681 or
682
683 % mencoder mms://$URL -o $FILE -ovc copy -oac copy
684
685 or
686
687 % mimms mms://file.wmv
688 -- 
689 Merge video files:
690
691 AVI:
692
693 % avimerge -i *.avi -o blub.avi
694
695 MPEG:
696
697 % cat *.mpg > blub.mpg
698
699 WMV:
700
701 % mencoder file1.wmv -ovc lavc -oac lavc -ofps 25 -srate 48000 -mc 0 -noskip -forceidx -o file1.avi
702 % mencoder file2.wmv -ovc lavc -oac lavc -ofps 25 -srate 48000 -mc 0 -noskip -forceidx -o file2.avi
703 % avimerge -i file1.avi file2.avi -o blub.avi
704 -- 
705 Display MS-Word file:
706
707 % strings file.doc | fmt | less
708
709 or
710
711 % antiword file.doc
712 -- 
713 Convert MS-Word file to postscript:
714
715 % antiword -p a4 file.doc > file.ps
716 -- 
717 Convert manual to postscript:
718
719 % zcat /usr/share/man/man1/zsh.1.gz | groff -man > zsh.1.ps
720 or
721 % man -t zsh > zsh.ps
722 -- 
723 Read BIOS:
724
725 % dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8
726 -- 
727 Read HTTP via netcat:
728
729 echo -e "GET / HTTP/1.1\r\nHost: $DOMAIN\r\n\r\n" | netcat $DOMAIN 80
730 -- 
731 Get X ressources for specific program:
732
733 % xrdb -q |grep -i xterm
734 -- 
735 Get windowid of specific X-window:
736
737 % xwininfo -int | grep "Window id:" | cut -d ' ' -f 4
738 -- 
739 Get titel of specific X-window:
740
741 % xprop WM_CLASS
742 -- 
743 check locale - LC_MESSAGES:
744
745 % locale -ck LC_MESSAGES
746 -- 
747 Create random password:
748
749 % pwgen
750 or
751 % dd if=/dev/urandom bs=14 count=1 | hexdump | cut -c 9-
752 -- 
753 Get tarballs of various Linux Kernel trees:
754
755 % ketchup 2.6
756 to get the current stable 2.6 release
757
758 % ketchup -l
759 to get a list of all supported trees
760 -- 
761 Transfer your SSH public key to another host:
762
763 % ssh-keygen   # ssh-keygen / ssh-key-gen: if you don't have a key yet
764 [...]
765 % ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-system
766 or
767 % cat $HOME/.ssh/id_rsa.pub  | ssh user@remote-system 'cat >> .ssh/authorized_keys'
768
769 Tags: ssh, ssh key, public key, ssh-copy-id, ssh-keygen
770 -- 
771 Update /etc/fstab entries:
772
773 # grml-rebuildfstab
774
775 See "man grml-rebuildfstab" for more details about
776 generation of /etc/fstab (including stuff like
777 fs LABELs / UUIDs,...).
778 -- 
779 Fetch and potentially change SCSI device parameters:
780
781 # sdparm /dev/sda
782
783 See: man sdparm
784 -- 
785 reclaim disk space by linking identical files together:
786
787 % dupmerge...
788 -- 
789 Find and remove duplicate files:
790
791 % dupseek ...
792 -- 
793 Perform layer 2 attacks:
794
795 # yersinia ...
796
797 Tags: network, attack, security
798 -- 
799 rootsh
800 -- 
801 Guess PC-type hard disk partitions / partition table:
802
803 # gpart <options>
804
805 Perform a standard scan:
806 # gpart /dev/ice
807
808 Write back the guessed table:
809 # gpart -W /dev/ice /dev/ice
810
811 Tags: partition, recovery, disk
812 -- 
813 Develop, test and use exploit code with the Metasploit Framework:
814
815 cd /tmp
816 wget http://spool.metasploit.com/releases/framework-3.2.tar.gz
817 unp framework-3.2.tar.gz
818 cd framework-3.2
819 ./msfcli
820 -- 
821 Useful documentation:
822
823 % w3m   /usr/share/doc/Debian/reference/reference.en.html
824 or
825 % xpdf =(zcat /usr/share/doc/Debian/reference/reference.en.pdf.gz)
826
827 http://grml.org/docs/           grml Documentation
828 http://wiki.grml.org/           grml Wiki
829 http://www.debian.org/doc/      Debian Documentation
830 http://wiki.debian.org/         Debian Wiki
831 http://www.gentoo.org/doc/en/   Gentoo Documentation
832 http://gentoo-wiki.com/         Gentoo Wiki
833 http://www.tldp.org/            The Linux Documentation Project
834
835 Tips and tricks:
836
837 % fortune debian-hints
838
839 Tags: documentation
840 -- 
841 Fun stuff:
842
843 % fortune debian-hints
844 % dpkg -L funny-manpages
845 -- 
846 Backup master boot record (MBR):
847
848 # dd if=/dev/ice of=/tmp/backup_of_mbr bs=512 count=1
849
850 Tags: backup, mbr
851 -- 
852 Backup partition table:
853
854 # sfdisk -d /dev/hda > hda.out
855
856 Restore partition table:
857
858 # sfdisk /dev/hda < hda.out
859
860 Tags: backup, partition, sfdisk, recovery
861 -- 
862 Clone disk via network using netcat:
863
864 Listener:
865 # nc -vlp 30000 > hda1.img
866 Source:
867 # dd if=/dev/hda1 | nc -vq 0 192.168.1.2 30000
868
869 Adjust blocksize (dd's option bs=...) and include 'gzip -c'
870 to tune speed:
871
872 # dd if=/dev/hda1 bs=32M | gzip -c | nc -vq 0 192.168.1.2 30000
873
874 Tags: network, backup, dd, netcat
875 -- 
876 Backup specific directories via cpio and ssh:
877
878 # for f in directory_list; do find $f >> backup.list done
879 # cpio -v -o --format=newc < backup.list | ssh user@host "cat > backup_device"
880
881 Tags: backup
882 -- 
883 Clone disk via ssh:
884
885 This one uses CPU cycles on the remote server to compare the files:
886 # ssh target_address cat remotefile | diff - localfile
887 # cat localfile | ssh target_address diff - remotefile
888
889 This one uses CPU cycles on the local server to compare the files:
890 # ssh target_address cat <localfile "|" diff - remotefile
891
892 Tags: network, backup, ssh
893 -- 
894 Useful tools for cloning / backups:
895
896 * dd: convert and copy a file
897 * dd_rescue: copies data from one file (or block device) to another
898 * pcopy: a replacement for dd
899 * partimage: back up and restore disk partitions
900 * dirvish: Disk based virtual image network backup system
901 * devclone: in-place filesystem conversion -- device cloning
902 * ntfsclone: efficiently clone, image, restore or rescue an NTFS
903 * dump: ext2/3 filesystem backup
904 * udpcast: multicast file transfer tool
905 * cpio: copy files to and from archives
906 * pax: read and write file archives and copy directory hierarchies
907 * netcat / ssh / tar / gzip / bzip2: additional helper tools
908
909 Tags: network, backup, ssh, udp, rescue, recovery
910 -- 
911 Use grml as a rescue system:
912
913 Different tools:
914
915   * dd: convert and copy a file
916   * ddrescue: copies data from one file or block device to another
917   * partimage: Linux/UNIX utility to save partitions in a compressed image file
918   * cfdisk: Partition a hard drive
919   * nparted: Newt and GNU Parted based disk partition table manipulator
920   * parted-bf: The GNU Parted disk partition resizing program, small version
921   * testdisk: Partition scanner and disk recovery tool
922   * gpart: Guess PC disk partition table, find lost partitions
923
924 ext2/ext3:
925
926   * e2fsprogs: ext2 file system utilities and libraries
927   * e2tools: utilities for manipulating files in an ext2/ext3 filesystem
928   * e2undel: Undelete utility for the ext2 file system
929   * ext2resize: an ext2 filesystem resizer
930   * recover: Undelete files on ext2 partitions
931
932 ReiserFS/Reiser4:
933
934   * reiser4progs: administration utilities for the Reiser4 filesystem
935   * reiserfsprogs: User-level tools for ReiserFS filesystems
936
937 XFS:
938
939   * xfsdump: Administrative utilities for the XFS filesystem
940   * xfsprogs: Utilities for managing the XFS filesystem
941
942 JFS:
943
944   * jfsutils: utilities for managing the JFS filesystem
945
946 NTFS:
947
948   * ntfsprogs: tools for doing neat things in NTFS partitions from Linux
949   * salvage-ntfs: free NTFS data recovery tools
950   * scrounge-ntfs: data recovery program for NTFS file systems
951   * ntfsresize: resize ntfs partitions
952
953 Tags: ntfs, jfs, xfs, ext3, rescue, recovery, backup, filesystem, tools
954 -- 
955 Get ASCII value of a character with zsh:
956
957 % char=N ; print $((#char))
958 -- 
959 Convert a collection of mp3 files to wave or cdr using zsh:
960
961 % for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav}
962 -- 
963 Convert images (foo.gif to foo.png) using zsh:
964
965 % for i in **/*.gif; convert $i $i:r.png
966 -- 
967 Remove all "non txt" files using zsh:
968
969 % rm ./^*.txt
970 -- 
971 Remote Shell Using SSH:
972
973 remote host:
974 % ssh -NR 3333:localhost:22 user@yourhost
975
976 local host:
977 % ssh user@localhost -p 3333
978
979 Tags: port forwarding, ssh, remote port, network
980 -- 
981 Reverse Shell with Netcat:
982
983 local host:
984 % netcat -v -l -p 3333 -e /bin/sh
985
986 remote host:
987 % netcat 192.168.0.1 3333
988
989 TagS: port forwarding, ssh, remote, network
990 -- 
991 Reverse Shell via SSH:
992
993 local host (inside the network):
994 % ssh -NR 1234:localhost:22 remote_host
995
996 remote host (outside the network):
997 % ssh localhost -p 1234
998
999 Tags: port forwarding, ssh, remote port, network
1000 -- 
1001 Remove empty directories with zsh:
1002
1003 % rmdir ./**/*(/od) 2> /dev/null
1004 -- 
1005 Find all the empty directories in a tree with zsh:
1006
1007 % ls -ld *(/^F)
1008 -- 
1009 Find all files without a valid owner and change ownership with zsh:
1010
1011 % chmod user /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
1012 -- 
1013 Display the 5-10 last modified files with zsh:
1014
1015 % print -rl -- /path/to/dir/**/*(D.om[5,10])
1016 -- 
1017 Find and list the ten newest files in directories and subdirs (recursive) with zsh:
1018
1019 % print -rl -- **/*(Dom[1,10])
1020 -- 
1021 Find most recent file in a directory with zsh:
1022
1023 % setopt dotglob ; print directory/**/*(om[1])
1024 -- 
1025 Tunnel all traffic through an external server:
1026
1027 % ssh -ND 3333 username@external.machine
1028
1029 Then set the SOCKS4/5 proxy to localhost:3333.
1030 Check whether it's working by surfing e.g. to checkip.dyndns.org
1031
1032 Tags: ssh, network, proxy, socks, tunnel
1033 -- 
1034 Tunnel everything through SSH via tsocks:
1035
1036 set up the SSH proxy on the client side:
1037
1038 % ssh -ND 3333 user@remote.host.example.com
1039
1040 Adjust /etc/tsocks.conf afterwards (delete all other lines):
1041
1042 server = 127.0.0.1
1043 server_port = 3333
1044
1045 For programs who natively support proxying connections (e.g. Mozilla
1046 Firefox) you can now set the proxy address to localhost port 3333.
1047
1048 All other programs which's connections you want to tunnel through your
1049 external host are prefixed with tsocks, e.g.:
1050
1051 % tsocks netcat example.com 80
1052 % tsocks irssi -c irc.quakenet.eu.org -p 6667
1053
1054 If you call tsocks without parameters it executes a shell witht the
1055 LD_PRELOAD environment variable already set and exported.
1056
1057 Tags: ssh, network, proxy, socks, tunnel, tsocks
1058 -- 
1059 smartctl - control and monitor utility for harddisks using Self-Monitoring,
1060 Analysis and Reporting Technology (SMART):
1061
1062 # smartctl --all /dev/ice
1063
1064 If you want to use smartctl on S-ATA (sata) disks use:
1065
1066 # smartctl -d ata --all /dev/sda
1067
1068 Start offline test:
1069 # smartctl -t offline /dev/ice
1070
1071 Start short test:
1072 # smartctl -t short /dev/ice
1073
1074 Display results of test:
1075 # smartctl -l selftest /dev/ice
1076
1077 Query device information:
1078 # smartctl -i /dev/ice
1079
1080 Tags: smart, s.m.a.r.t, info, test, hardware
1081 -- 
1082 Mount a BSD / Solaris partition:
1083
1084 # mount -t ufs -o ufstype=ufs2 /dev/hda1 /mnt/hda1
1085
1086 Use ufstype 44bsd  for FreeBSD, NetBSD, OpenBSD (read-write).
1087 Use ufstype ufs2   for >= FreeBSD 5.x (read-only).
1088 Use ufstype sun    for SunOS (Solaris) (read-write).
1089 Use ufstype sunx86 for SunOS for Intel (Solarisx86) (read-write).
1090
1091 See /usr/share/doc/linux-doc-$(uname -r)/Documentation/filesystems/ufs.txt.gz
1092 for more details.
1093
1094 Tags: ufs, bsd, mount, solaris
1095 -- 
1096 Read BIOS (and or BIOS) password:
1097
1098 # dd if=/dev/mem bs=512 skip=2 count=1 | hexdump -C | head
1099 -- 
1100 Clone one of the kernel trees via git:
1101
1102  git clone rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
1103                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1104 This path defines the tree. See http://kernel.org/git/ for an overview.
1105 -- 
1106 Mount filesystems over ssh protocol:
1107
1108 % sshfs user@host:/remote_dir /mnt/test
1109
1110 Unmount via:
1111
1112 % fusermount -u /mnt/test
1113
1114 (Notice: requires fuse kernel module)
1115
1116 Tags: ssh, sshfs, network, mount, directory, remote, fuse
1117 -- 
1118 Install Gentoo using grml:
1119
1120 See http://www.gentoo.org/doc/en/altinstall.xml
1121 -- 
1122 Install (plain) Debian (sarge release) via grml:
1123
1124 Assuming you want to install Debian to sda1:
1125
1126 mkfs.ext3 /dev/sda1           # make an ext3 filesystem on /dev/sda1
1127 mount -o rw,suid,dev /dev/sda1 /mnt/test # now mount the new partition
1128 debootstrap sarge /mnt/test ftp://ftp.tugraz.at/mirror/debian # get main packages from a debian-mirror
1129 chroot /mnt/test /bin/bash    # let's chroot into the new system
1130 mount -t devpts none /dev/pts # ...otherwise running base-config might fail ("Terminated" or "openpty failed")
1131 mount -t proc   none /proc    # make sure we also have a mounted /proc
1132 base-config                   # now configure some main settings
1133 vi /etc/mkinitrd/mkinitrd.conf # adjust $ROOT (to /dev/sda1) for your new partition, autodetection will fail in chroot
1134 cd /dev ; ./MAKEDEV generic                                # make sure we have all necessary devices for lilo
1135 apt-get install lilo linux-image-2.6.12-1-386              # install lilo and a kernel which fits your needs
1136 cp /usr/share/doc/lilo/examples/conf.sample /etc/lilo.conf # let's use a template
1137 vi /etc/lilo.conf && lilo                                  # adjust the file for your needs and run lilo afterwards
1138 umount /proc ; umount /dev/pts                             # we do not need them any more
1139 exit                                                       # now leave chroot
1140 cp /etc/hosts /etc/fstab /mnt/test/etc/           # you might want to take the existing files...
1141 cp /etc/network/interfaces /mnt/test/etc/network/ # ...from the running grml system for your new system
1142 umount /mnt/test && reboot    # unmount partition and reboot...
1143
1144 See also: http://www.debian.org/releases/stable/i386/apcs04.html.en
1145 Avoid all of the above steps - use grml-debootstrap(8) instead!
1146
1147 Tags: manual, installation, debian, debootstrap
1148 -- 
1149 Install (plain) Debian (etch release) via grml
1150
1151 Assuming you want to install Debian to sda1:
1152
1153 mkfs.ext3 /dev/sda1           # make an ext3 filesystem on /dev/sda1
1154 mount -o rw,suid,dev /dev/sda1 /mnt/test # now mount the new partition
1155 debootstrap etch /mnt/test ftp://ftp.tugraz.at/mirror/debian # get main packages from a debian-mirror
1156 chroot /mnt/test /bin/bash    # let's chroot into the new system
1157 mount -t proc   none /proc    # make sure we have a mounted /proc
1158 apt-get install locales console-data  # install locales
1159 dpkg-reconfigure locales console-data # adjust locales to your needs
1160 apt-get install vim most zsh screen less initrd-tools file grub     \
1161         usbutils pciutils bzip2 sysfsutils dhcp3-client resolvconf  \
1162         strace lsof w3m # install useful software
1163 apt-get install linux-headers-2.6-686 linux-image-686  # install current kernel
1164
1165 echo "127.0.0.1       localhost" > /etc/hosts   # adjust /etc/hosts and network:
1166 cat >> /etc/network/interfaces << EOF
1167 iface lo inet loopback
1168 iface eth0 inet dhcp
1169 auto lo
1170 auto eth0
1171 EOF
1172
1173 ln -sf /usr/share/zoneinfo/Europe/Vienna /etc/localtime # adjust timezone and /etc/fstab:
1174 cat >> /etc/fstab << EOF
1175 sysfs          /sys         sysfs   auto                       0   0
1176 proc           /proc        proc    defaults                   0   0
1177 /dev/sda1      /            ext3    defaults,errors=remount-ro 0   1
1178 /dev/sda2      none         swap    sw                         0   0
1179 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
1180 EOF
1181 passwd             # set password of user root
1182
1183 mkdir /boot/grub   # setup grub
1184 cp /usr/share/doc/grub/examples/menu.lst /boot/grub
1185 cat >> /boot/grub/menu.lst << EOF
1186 title           Debian Etch, kernel 2.6.18-3-686 (on /dev/sda1)
1187 root            (hd0,0)
1188 kernel          /boot/vmlinuz-2.6.18-3-686 root=/dev/sda1 ro
1189 initrd          /boot/initrd.img-2.6.18-3-686
1190 EOF
1191 vim /boot/grub/menu.lst               # adjust grub configuration to your needs
1192 cd /dev && MAKEDEV generic            # create default devices
1193 cp -i /usr/lib/grub/i386-pc/* /boot/grub/ # copy stage-files to /boot/grub/
1194 grub install  # now install grub, run in grub-cmdline following commands:
1195 > root (hd0,0)
1196 > setup (hd0)
1197 > quit
1198 umount -a # unmount all filesystems in chroot and finally:
1199 exit      # exit the chroot and:
1200 reboot
1201
1202 If you want to use lilo instead of grub take a look at
1203 /usr/share/doc/lilo/examples/conf.sample or use the following template:
1204
1205 cat > /etc/lilo.conf << EOF
1206 # This allows booting from any partition on disks with more than 1024 cylinders.
1207 lba32
1208
1209 # Specifies the boot device
1210 boot=/dev/sda1
1211
1212 # Specifies the device that should be mounted as root.
1213 root=/dev/sda1
1214
1215 # use Debian on software raid:
1216 # raid-extra-boot=mbr-only
1217
1218 install=text
1219 # prompt
1220 timeout=1
1221 map=/boot/map
1222 vga=normal
1223
1224 image=/boot/vmlinuz-2.6.18-grml
1225         label="2.6.18-grml"
1226         #append="...."
1227         read-only
1228         initrd=/boot/initrd.img-2.6.18-grml
1229 EOF
1230
1231 See also: http://www.debian.org/releases/stable/i386/apcs04.html.en
1232 Avoid all of the above steps - use grml-debootstrap(8) instead!
1233
1234 Tags: manual, installation, debian, debootstrap, howto
1235 -- 
1236 Convert files from Unicode / UTF-8 to ISO:
1237
1238 % iconv -c -f utf8 -t iso-8859-15 < utffile > isofile
1239
1240 and vice versa:
1241
1242 % iconv -f iso-8859-15 -t utf8 < isofile > utffile
1243
1244 Tags: utf-8, iso, unicode, utf8
1245 -- 
1246 Assign static setup for network cards (NICs) via udev:
1247
1248 Retrieve information for address (corresponding to MAC address):
1249
1250   # udevadm info -a -p /sys/class/net/eth0/ | grep -i 'ATTR{address}'
1251
1252 Execute /lib/udev/write_net_rules with according values (INTERFACE
1253 is old NIC name, INTERFACE_NAME is new NIC name and MATCHADDR
1254 is the MAC address retrieved with udevadm info command):
1255
1256   # INTERFACE=eth0 INTERFACE_NAME=lan0  MATCHADDR=00:00:00:00:00:01 /lib/udev/write_net_rules
1257
1258 This will generate file /etc/udev/rules.d/70-persistent-net.rules with content:
1259
1260 SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:00:00:00:00:01", KERNEL=="eth*", NAME="lan0"
1261
1262 Finally take down the interface (ifdown/ifconfig) and execute:
1263
1264   # udevadm trigger --action=add --subsystem-match=net
1265
1266 so the interface will be renamed. (Rebooting or
1267 unloading drivers/restart udev/loading drivers again
1268 works as well of course.)
1269
1270 Tags: udev, configuration, name, eth0, howto
1271 -- 
1272 Change the suffix from *.sh to *.pl using zsh:
1273
1274 % autoload zmv
1275 % zmv -W '*.sh' '*.pl'
1276 -- 
1277 Generate SSL certificate:
1278
1279 Create self signed certificate (adjust /etc/ssl/openssl.cnf if necessary):
1280 # openssl req -x509 -newkey rsa:1024 -keyout keyfile -out certfile -days 9999 -nodes
1281
1282 Check certfile:
1283 # openssl x509 -in certfile -text
1284
1285 Verify against CA certificate:
1286 # openssl verify -CAfile cacert.crt -verbose -purpose sslserver
1287
1288 Generate 2048bit RSA-key:
1289 # openssl req -new -x509 -keyout pub-sec-key.pem -out pub-sec-key.pem -days 365 -nodes
1290
1291 As before but add request to existing key pub-sec-key.pem:
1292 # openssl req -new -out request.pem -keyin pub-sec-key.pem
1293
1294 Show request request.pem:
1295 # openssl req -text -noout -in request.pem
1296
1297 Verify signature of request request.pem:
1298 # openssl req -verify -noout -in request.pem
1299
1300 Generate SHA1 fingerprint (modulo key) of request.pem:
1301 # openssl req -noout -modulus -in request.pem | openssl sha1 -c
1302
1303 Generate 2048bit RSA-key and put it to pub-sec-key.pem. Save self signed certificate in self-signed-certificate.pem:
1304 # openssl req -x509 -days 365 -newkey rsa:2048 -out self-signed-certificate.pem -keyout pub-sec-key.pem
1305
1306 As before but create self signed certificate based on existing key pub-sec-key.pem:
1307 # openssl req -x509 -days 365 -new -out self-signed-certificate.pem -key pub-sec-key.pem
1308
1309 Generate new request out of existing self signed certificate:
1310 # openssl x509 -x509toreq -in self-signed-certificate.pem -signkey pub-sec-key.pem -out request.pem
1311
1312 Display certificate self-signed-certificate.pem in plaintext:
1313 # openssl x509 -text -noout -md5 -in self-signed-certificate.pem
1314
1315 Check self signed certificate:
1316 # openssl verify -issuer_checks -CAfile self-signed-certificate.pem self-signed-certificate.pem
1317
1318 Estable OpenSSL-connection using self-signed-certificate.pem and display certificate:
1319 # openssl s_client -showcerts -CAfile self-signed-certificate.pem -connect www.example.com:443
1320
1321 Generate ssl-certificate for use with apache2:
1322
1323 export RANDFILE=/dev/random
1324 mkdir /etc/apache2/ssl/
1325 openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.pem
1326 chmod 600 /etc/apache2/ssl/apache.pem
1327
1328 Also take a look at make-ssl-cert (debconf wrapper for openssl):
1329
1330 # /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/apache.pem
1331
1332 and mod-ssl-makecert (utility to create SSL certificates in /etc/apache/ssl.*/).
1333
1334 Tags: openssl, howto
1335 -- 
1336 Change Windows NT password(s):
1337
1338 # mount -o rw /mnt/hda1
1339 # cd /mnt/hda1/WINDOWS/system32/config/
1340 # chntpw SAM SECURITY system
1341
1342 Notice: if mounting the partition read-write did not work (check syslog!)
1343 try using mount.ntfs-3g instead: mount.ntfs-3g /dev/hda1 /mnt/hda1
1344
1345 (Be careful with deactivating syskey!)
1346
1347 Tags: password, windows, recovery, chntpw, howto
1348 -- 
1349 glark - replacement for grep written in Ruby:
1350
1351 A replacement for (or supplement to) the grep family, glark offers:
1352 Perl compatible regular expressions, highlighting of matches,
1353 context around matches, complex expressions and automatic exclusion
1354 of non-text files.
1355
1356 Usage examples:
1357
1358 % glark -y keyword file      # display only the region that matched, not the entire line
1359 % glark -o format print *.h  # search for either "printf" or "format"
1360
1361 More information: man glark
1362 -- 
1363 Find CD burning device(s):
1364
1365 General information on CD-ROM:
1366 % cat /proc/sys/dev/cdrom/info
1367
1368 Scan using ATA Packet specific SCSI transport:
1369 # cdrecord -dev=ATA -scanbus
1370 # cdrecord-prodvd -s -scanbus dev=ATA
1371
1372 Get specific information for /dev/ice:
1373 # cdrecord dev=/dev/ice -scanbus
1374
1375 Tags: hardware, info, cd burn
1376 -- 
1377 Create devices in /dev on udev:
1378
1379 For example create md devices (/dev/md0, /dev/md1,...):
1380 # cd /dev ; WRITE_ON_UDEV=1 ./MAKEDEV md
1381
1382 Tags: raid, device
1383 -- 
1384 Identify network device (NIC):
1385
1386 # ethtool -i $DEVICE
1387
1388 Show NIC statistics:
1389
1390 # ethtool -S $DEVICE
1391
1392 If your NIC shows some aging signs, you may want to be sure:
1393
1394 # ethtool -t $DEVICE
1395
1396 Disable TCP/UDP checksums:
1397
1398 # ethtool -K $DEVICE tx off
1399
1400 Tags: configuration, network, device
1401 -- 
1402 grml2hd seems to hang? Getting Squashfs errors? Problems while booting?
1403
1404 Switch to tty12 and take a look at the syslog. If you see something like:
1405
1406   SQUASHFS error: zlib_fs returned unexpected result 0x........
1407   SQUASHFS error: Unable to read cache block [.....]
1408   SQUASHFS error: Unable to read inode [.....]
1409
1410 your ISO/CD-ROM very probably is not ok. Verify it via booting with grml testcd.
1411 Check your CD low-level via running:
1412
1413 # readcd -c2scan dev=/dev/cdrom
1414
1415 If the medium really is ok and it still fails try to boot with deactivated DMA
1416 via using grml nodma at the bootprompt.
1417
1418 Tags: grml2hd, installation, verify, squashfs, error
1419 -- 
1420 Write a Microsoft compatible boot record (MBR) using ms-sys
1421
1422 Write a Windows 2000/XP/2003 MBR to a device:
1423
1424 # ms-sys -m /dev/ice
1425
1426 Notice: grab ms-sys from http://ms-sys.sourceforge.net/ - demo:
1427
1428  wget http://surfnet.dl.sourceforge.net/sourceforge/ms-sys/ms-sys-2.1.3.tgz
1429  unp ms-sys-2.1.3.tgz
1430  cd ms-sys-2.1.3
1431  make
1432  ./bin/ms-sys ...
1433
1434 Tags: mbr, windows, ms-sys, recovery
1435 -- 
1436 Use a Vodafone 3G Datacard (UMTS) with Linux:
1437
1438 Plug in your vodafone card and check in syslog whether the appropriate
1439 (probably /dev/ttyUSB0 or /dev/noz0) has been created. If so run:
1440
1441 # comgt -d $DEVICE
1442 # wvdial --config /etc/wvdial.conf.umts $PROFILE
1443
1444 Usage examples:
1445 # comgt -d /dev/ttyUSB0
1446 # wvdial --config /etc/wvdial.conf.umts a1usb
1447
1448 # comgt -d /dev/noz0
1449 # wvdial --config /etc/wvdial.conf.umts tmnozomi
1450
1451 # comgt -d /dev/noz0
1452 # wvdial --config /etc/wvdial.conf.umts dreiusb
1453
1454 # comgt -d /dev/ttyACM0
1455 # wvdial --config /etc/wvdial.conf.umts yesss
1456
1457 If you receive invalid DNS nameservers when connecting, like:
1458
1459 [...]
1460 --> primary   DNS address 10.11.12.13
1461 --> secondary DNS address 10.11.12.14
1462
1463 just provide a working nameserver to resolvconf via:
1464
1465 # echo "nameserver 80.120.17.70" | resolvconf -a ppp0
1466
1467 Notice: some vodafone cards require the nozomi driver (run 'modprobe nozomi' on
1468 your grml system), some other ones require the sierra driver (run
1469 'modprobe sierra').
1470
1471 If your device isn't supported by usbserial yet, manually provide vendor and
1472 product ID when loading the usbserial module. Usage example:
1473
1474 % lsusb
1475 [...]
1476 Bus 004 Device 008: ID 1199:6813 Sierra Wireless, Inc.
1477
1478 # modprobe usbserial vendor=0x1199 product=0x6813
1479
1480 To get a list of available providers execute:
1481
1482 # comgt -s -d /dev/ttyUSB0 /etc/comgt/operator
1483
1484 Tags: umts, 3g, vodafone, sierra, wvdial, ppp, howto
1485 -- 
1486 hdparm - get/set hard disk parameters
1487
1488 Display the identification info that was obtained from the drive at boot time,
1489 if available:
1490 # hpdarm -i /dev/ice
1491
1492 Request identification info directly from the drive:
1493 # hpdarm -I /dev/ice
1494
1495 Perform timings of device + cache reads for benchmark and comparison purposes:
1496 # hdparm -tT /dev/ice
1497
1498 Tags: hardware, performance, configuration, harddisk
1499 -- 
1500 bonnie++ - program to test hard drive performance.
1501
1502 # mkdir /mnt/benchmark
1503 # mount /dev/ice /mnt/benchmark
1504 # chmod go+w /mnt/benchmark
1505 # bonnie -u grml -d /mnt/benchmark -s 2000M
1506
1507 Tags: benchmark, harddisk
1508 -- 
1509 Use gizmo with a bluetooth headset:
1510
1511 % DEVICE="/dev/dsp$(awk '/- BT Headset/ {print $1}' /proc/asound/cards)"
1512 % gizmo --mic $DEVICE --speaker $DEVICE
1513 -- 
1514 Scan a v4l device for TV stations:
1515
1516 % scantv -c /dev/video0 -C /dev/vbi0 -o ~/.xawtv
1517
1518 Then running xawtv should work:
1519
1520 % xawtv
1521 -- 
1522 Run apt-get with timeout of 3 seconds:
1523
1524 # apt-get -o acquire::http::timeout=3  update
1525
1526 Tags: apt-get
1527 -- 
1528 Debian GNU/Linux device driver check page
1529
1530 % $BROWSER http://kmuto.jp/debian/hcl/index.cgi
1531 -- 
1532 Use dd with status line:
1533
1534 # dd if=/dev/ice conv=noerror,notrunc,sync | buffer -S 100k | dd of=/tmp/file
1535 -- 
1536 Generate a 512k file of random data with status bar:
1537
1538 % dd if=/dev/random bs=1024 count=512 | bar -s 512k -of ./random
1539 -- 
1540 Install Grub instead of lilo on grml installation (grml2hd):
1541
1542 install grml:
1543 # grml2hd ....
1544
1545 adjust grub's configuration file menu.lst:
1546 # $EDITOR /boot/grub/menu.lst
1547
1548 now install grub (usage example for /dev/sda1):
1549 # grub install
1550 root (hd0,0)
1551 setup (hd0)
1552
1553 Tags: grml2hd, grub
1554 -- 
1555 Install Ubuntu using grml:
1556
1557 See https://wiki.ubuntu.com/Installation/FromKnoppix
1558
1559 Tags: ubuntu, installation
1560 -- 
1561 Resize ext2 / ext3 partition:
1562
1563 # tune2fs -O '^has_journal' /dev/iceX # disable journaling
1564 # fsck.ext2 -v -y -f /dev/iceX        # check the filesystem
1565 # resize2fs -p /dev/iceX  $SIZE       # resize it (adjust $SIZE)
1566 # fdisk /dev/ice                      # adjust partition in partition table
1567 # fsck.ext2 -v -y -f /dev/iceX        # check filesystem again
1568 # resize2fs -p /dev/iceX              # resize it to maximum
1569 # tune2fs -j /dev/iceX                # re-enable journal
1570
1571 Tags: resize, ext2, ext3, ext4, partition, howto
1572 -- 
1573 Tune ext2 / ext3 filesystem:
1574
1575 Check partition first:
1576
1577 # tune2fs -l /dev/iceX
1578
1579 If you don't see dir_index in the list, then enable it:
1580
1581 # tune2fs -O dir_index /dev/iceX
1582
1583 Now run e2fsck with the -D option to have the directories optimized:
1584
1585 # e2fsck -D /dev/iceX
1586
1587 Notice: since e2fsprogs (1.39-1) filesystems are created with
1588 directory indexing and on-line resizing enabled by default.
1589
1590 Tags: configuration, ext2, ext3, ext4, partition
1591 -- 
1592 Search for printers via network:
1593
1594 # pconf_detect -m NETWORK -i 192.168.0.1/24
1595
1596 Tags: printer, network, scan
1597 -- 
1598 Mount a remote directory via webdav (e.g. Mediacenter of GMX):
1599
1600 # mount -t davfs https://mediacenter.gmx.net/ /mnt/test
1601
1602 Tags: webdav, mount, mediacenter, gmx
1603 -- 
1604 System-Profiling using oprofile:
1605
1606 Prepare setup:
1607
1608 # opcontrol --reset
1609 # opcontrol --setup --no-vmlinux --event=CPU_CLK_UNHALTED:500000:0:1:1 --separate=library
1610
1611 Start logging:
1612 # opcontrol --start
1613
1614 Now $DO_SOME_TASKS...
1615
1616 Stop logging:
1617 # opcontrol --shutdown
1618
1619 Then take a look at the reports using something like e.g.:
1620 # opreport -t 0.5 --exclude-dependent
1621 # opreport -t 0.5 /path/to/executable_to_check
1622 # opannotate -t 0.5 --source --assembly
1623
1624 Tags: profile, profiling, opcontrol, howto
1625 -- 
1626 Install ATI's fglrx driver for Xorg / X.org:
1627
1628 Usually there already exist drivers for the grml-system:
1629 # apt-get update ; apt-get install fglrx-driver fglrx-kernel-`uname -r`
1630
1631 After installing adjust xorg.conf via running:
1632 # aticonfig --initial --input=/etc/X11/xorg.conf
1633
1634 For more information take a look at http://wiki.grml.org/doku.php?id=ati
1635
1636 Tags: xorg, x11, driver, ati
1637 -- 
1638 Install nvidia driver for Xorg / X.org:
1639
1640 Usually there already exist drivers for the grml-system:
1641 # apt-get update ; apt-get install nvidia-glx nvidia-kernel-`uname -r`
1642
1643 Then switch from module nv to nvidia:
1644
1645 # sed -i 's/Driver.*nv.*/Driver      "nvidia"/' /etc/X11/xorg.conf
1646
1647 Tags: xorg, x11, driver, nvidia
1648 -- 
1649 glxgears - a GLX demo that draws three rotating gears
1650
1651 To print frames per second (fps) use:
1652 % glxgears -printfps
1653
1654 Tags: xorg, x11, glx,
1655 -- 
1656 You forgot to boot with 'grml noeject noprompt' to avoid
1657 ejecting and prompting for CD removal when rebooting/halting
1658 the system?
1659
1660 Either run:
1661
1662 # noeject reboot
1663
1664 or:
1665
1666 # noeject halt
1667
1668 If you want to avoid only the prompting part, run:
1669
1670 # noprompt reboot
1671
1672 or:
1673
1674 # noprompt halt
1675
1676 Tags: bootparam, fix, grml
1677 -- 
1678 Mount wikipedia local via fuse:
1679
1680 Adjust configuration:
1681 % cat ~/.wikipediafs/config.xml
1682 <wfs-config>
1683     <general>
1684        <article-cache-time>300</article-cache-time>
1685     </general>
1686     <sites>
1687       <site>
1688         <dirname>wikipedia-de</dirname>
1689         <host>de.wikipedia.org</host>
1690         <basename>/w/index.php</basename>
1691       </site>
1692       <site>
1693         <dirname>wikipedia-en</dirname>
1694         <host>en.wikipedia.org</host>
1695         <basename>/w/index.php</basename>
1696       </site>
1697     </sites>
1698 </wfs-config>
1699
1700 Mount it (/wiki must exist of course):
1701 % mount.wikipediafs /wiki
1702 % cat /wiki/wikipedia-en/Cat
1703
1704 Unmount via:
1705 % fusermount -u /wiki
1706
1707 Tags: fuse, wikipedia, mount
1708 -- 
1709 Remote notification on X via osd (on screen display):
1710
1711 Start osd_server.py at your local host (listens on port 1234 by default):
1712 % osd_server.py
1713
1714 Then login to a $REMOTEHOST
1715 % ssh -R 1234:localhost:1234 $REMOTEHOST
1716
1717 Now send the text to your local display via running something like:
1718 % echo "text to send" | nc localhost 1234
1719
1720 Very useful when you are waiting for a long running job
1721 but want to do something else in the meanwhile:
1722
1723 % ./configure && make && echo "finished compiling" | netcat localhost 1234
1724
1725 You can use this in external programs as well of course. Examples:
1726
1727 Use osd in centericq:
1728
1729 % cat ~/.centericq/external
1730 [...]
1731 %action osd notify
1732 event msg
1733 proto all
1734 status all
1735 options nowait
1736 %exec
1737 #!/bin/bash
1738 if [ -x /usr/bin/socat -a -x /bin/netcat ] ; then
1739   CONTACT_CUSTOM_NICK=$(cat ${CONTACT_INFODIR}/info | head -n 46 | tail -n 1)
1740   osd_msg="*** CenterICQ: new ${EVENT_NETWORK} ${EVENT_TYPE} from ${CONTACT_CUSTOM_NICK} ***"
1741   if echo | socat - TCP4:localhost:1234 &>/dev/null ; then
1742     echo "${osd_msg}" | netcat localhost 1234
1743   fi
1744 fi
1745
1746 Use it in the IRC console client irssi via running:
1747
1748 /script load osd.pl
1749
1750 You can even activate the port forwarding by default globally:
1751
1752 % cat ~/.ssh/config
1753 [...]
1754 Host *
1755 RemoteForward 1234 127.0.0.1:1234
1756 ForwardAgent yes
1757
1758 Notice: if you get 'ABORT: Requested font not found' make sure the
1759 requested font is available, running 'LANG=C LC_ALL=C osd_server.py...'
1760 might help as well.
1761
1762 Tags: osd, notification, ssh, network, port-forwarding
1763 -- 
1764 Avoid automatical startup of init scripts via invoke-rc.d:
1765
1766 First of all make sure the package policyrcd-script-zg2 (which
1767 provides the /usr/sbin/policy-rc.d interface) is installed.
1768
1769 In policyrcd-script-zg2's configuration file named
1770 /etc/zg-policy-rc.d.conf the script /usr/sbin/grml-policy-rc.d is
1771 defined as the interface for handling invoke-rc.d's startup policy.
1772
1773 grml-policy-rc.d can be configure via /etc/policy-rc.d.conf.  By
1774 default you won't notice any differences to Debian's default
1775 behaviour, except that invoke-rc.d won't be executed if a chroot has
1776 been detected (detection: /proc is missing).
1777
1778 If you want to disable automatical startup of newly installed packages
1779 (done via the invoke-rc.d mechanism) just set EXITSTATUS to '101' in
1780 /etc/policy-rc.d.conf.
1781
1782 To restore the default behaviour set EXITSTATUS back to '0' in
1783 /etc/policy-rc.d.conf.
1784
1785 Tags: policy, init, script, invode-rc.d
1786 -- 
1787 Install VMware-Tools for grml:
1788
1789 First of all make sure a CD-ROM device in VMware is available.
1790
1791 Mount the CD-ROM device to /mnt/cdrom, then unpack and install
1792 the tools running:
1793
1794 cd /tmp
1795 unp /mnt/cdrom/vmware-linux-tools.tar.gz
1796 cd vmware-tools-distrib
1797 ./vmware-install.pl
1798
1799 /etc/init.d/networking stop
1800 rmmod pcnet32
1801 rmmod vmxnet
1802 depmod -a
1803 modprobe vmxnet
1804 /etc/init.d/networking start
1805
1806 In an X terminal, launch the VMware Tools running:
1807
1808 vmware-toolbox
1809
1810 Tags: vmware, tool, vmware-toolbox, howto
1811 -- 
1812 Some important Postfix stuff
1813
1814 List mail queue:
1815
1816 # mailq
1817 or
1818 # postqueue -p
1819
1820 Send all messages in the queue:
1821
1822 # postqueue -f
1823
1824 Send all messages in the queue for a specific site:
1825
1826 # postqueue -s site
1827
1828 Delete a specific message
1829 # postsuper -d 12345678942
1830
1831 Deletes all messages held in the queue for later delivery
1832 # postsuper -d ALL deferred
1833
1834 Mail queues in postfix:
1835
1836     incoming -> mail who just entered the system
1837     active   -> mail to be delivered
1838     deferred -> mail to be delivered later because there were problems
1839     hold     -> mail that should not be delivered until released from hold
1840
1841 For configuration of postfix take a look at
1842 /etc/postfix/master.cf  - man 5 master
1843 /etc/postfix/main.cf    - man 5 postconf
1844 and http://www.postfix.org/documentation.html.
1845 -- 
1846 File permissions
1847
1848 mode 4000 - set user ID (suid):
1849
1850 - for executable files: run as the user who owns the file, instead of the
1851   user who runs the file
1852 - for directories: not used
1853
1854 mode 2000 - set group ID (guid):
1855
1856 - for executable files: run as the group who owns the file, instead of the
1857   group of the user who runs the file
1858 - for directories: when a file is created inside the directory, it belongs
1859   to the group of the directory instead of the default group of the user who
1860   created the file
1861
1862 mode 1000 - sticky bit:
1863
1864 - for files: not used
1865 - for directories: only the owner of a file can delete or rename the file
1866
1867 Tags: postix, mailq, postsuper, queue, delete, smtp
1868 -- 
1869 Create MySQL database
1870
1871 # apt-get install mysql-client mysql-server
1872
1873 Run 'mysql' as root - create a database with:
1874
1875 create database grml
1876
1877 Give a user access to the database (without password):
1878
1879 grant all on grml.* to mika;
1880
1881 Give a user access to the database (with password):
1882
1883 grant all on grml.* to enrico identified by "PASSWORD";
1884
1885 Tags: mysql, database
1886 -- 
1887 Setup an HTTPS website:
1888
1889 Create a certificate:
1890
1891 # mkdir /etc/apache2/ssl
1892 # make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
1893
1894 Create a virtual host on port 443:
1895
1896 <VirtualHost www.foo.invalid:443>
1897 [...]
1898 </VirtualHost>
1899
1900 Enable SSL in the VirtualHost:
1901
1902 SSLEngine On
1903 SSLCertificateFile /etc/apache2/ssl/apache.pem
1904
1905 Enable listening on the HTTPS port (/etc/apache2/ports.conf):
1906
1907 Listen 443
1908
1909 and make sure the SSL module is used:
1910
1911 # a2enmod ssl
1912
1913 Tags: ssl, https, configuration, apache
1914 -- 
1915 Useful Apache / Apache2 stuff
1916
1917 Check configuration file via running:
1918
1919 # apache2ctl configtest
1920
1921 Enable a site:
1922
1923 # a2ensite sitename
1924
1925 Enable a module
1926
1927 # a2enmod modulename
1928
1929 Tags: apache, configuration
1930 -- 
1931 Create tar archive and store it on remote machine:
1932
1933 % tar zcf - /sourcedir | ssh user@targethost "cat >file.tgz"
1934
1935 Tags: tar, backup, remote, network, ssh
1936 -- 
1937 Pick out and displays images from network traffic:
1938
1939 # driftnet
1940
1941 Tags: remote, network, sniff, image
1942 -- 
1943 Install Flash plugin:
1944
1945 # dpkg-reconfigure flashplugin-nonfree
1946
1947 Tags: flash, plugin
1948 -- 
1949 To test a proxy, low level way:
1950
1951 % telnet proxy 8080
1952 [...]
1953 GET http://www.google.com HTTP/1.0 [press enter twice]
1954
1955 Tags: proxy
1956 -- 
1957 Adjust system for use of qemu with kqemu:
1958
1959 Make sure you have all you need:
1960 # aptitude update ; aptitude install qemu kqemu-modules-$(uname -r)
1961
1962 Then set up kqemu:
1963
1964 modprobe kqemu
1965 mknod /dev/kqemu c 250 0
1966 chmod 666 /dev/kqemu
1967 chmod 666 /dev/net/tun
1968
1969 Check kqemu support via starting qemu, press
1970 Ctrl-Alt-2 and entering 'info kqemu'.
1971 -- 
1972 (High-Load) Debugging related tools:
1973
1974 mpstat  # report processors related statistics
1975 iostat  # report CPU statistics and input/output statistics for devices and partitions
1976 vmstat  # report virtual memory statistics
1977 slabtop # display kernel slab cache information in real time
1978 atsar   # system activity report
1979 dstat   # versatile tool for generating system resource statistics
1980
1981 Usage examples:
1982
1983 # mpstat -P ALL
1984 # iostat -x 1
1985 # iostat -xtc 5 3
1986 # vmstat 1
1987 # atsar -t 60 10
1988 # dstat -af
1989
1990 Tags: test, debug, information, hardware, statistic
1991 -- 
1992 Using WPA for network setup manually:
1993
1994 # wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
1995
1996 Adjust the options and configuration file to your needs.
1997 Also take a look at 'grml-network'.
1998
1999 Tags: wireless, wpa, network, configuration
2000 -- 
2001 Start X and lock console via exiting:
2002
2003 % startx 2>~/.xsession-errors &| exit
2004
2005 Tags: xorg, x11, startx, graphical
2006 -- 
2007 Which process is writing to disk and/or causes the disk to spin up?
2008
2009 First of all use lsof to check what's going on. Does not help? ->
2010
2011 # echo 1 > /proc/sys/vm/block_dump
2012
2013 The command sets a sysctl to cause the kernel to log all disk
2014 writes. Please notice that there is a lot of data.  So please
2015 disable syslogd/syslog-ng before you do this, or you must make
2016 sure that kernel output is not logged.
2017
2018 When you're done, disable block dump using:
2019 # echo 0 > /proc/sys/vm/block_dump
2020
2021 Alternative:
2022 laptop-mode-tools provides a tool named lm-profiler (laptop mode profiler)
2023 which handles block_dump on its own.
2024
2025 See: $KERNEL-SOURCE/Documentation/laptop-mode.txt
2026
2027 Also take a look at event-viewer(8) which is part of grml-debugtools.
2028
2029 Tags: debug, device, block, partition
2030 -- 
2031 Install initrd via initramfs-tools for currently running kernel:
2032
2033 # update-initramfs -c -t -k $(uname -r)
2034
2035 Tags: initrd
2036 -- 
2037 Install initrd via yaird for currently running kernel:
2038
2039 # yaird -o /boot/initrd.img-$(uname -r)
2040
2041 Install initrd via yaird for specific kernel:
2042
2043 # mount /proc
2044 # mount /sys
2045 # yaird -o /boot/initrd.img-2.6.15-1-686 2.6.15-1-686
2046 -- 
2047 Reinstall package with its original configuration files:
2048
2049 # apt-get install --reinstall -o DPkg::Options::=--force-confmiss -o \
2050   DPkg::Options::=--force-confnew package
2051 -- 
2052 grml 0.8 funkenzutzler - rt2x00 drivers:
2053
2054 To avoid conflicts with the other rt2x00-drivers the package rt2x00 (which
2055 includes beta-version drivers) is not installed by default. If you want to
2056 use the kernel modules rt2400pci, rt2500pci, rt2500usb, rt61pci and/or
2057 rt73usb please install the package manually running:
2058
2059 # dpkg -i /usr/src/rt2x00-modules-*.deb
2060 -- 
2061 Use Java with jikes and jamvm on grml:
2062
2063 Simple demo:
2064
2065 % cp /usr/share/doc/grml-templates/template.java .
2066 % jikes template.java
2067 % jamvm HelloWorld
2068
2069 Notice that grml exports $JIKESPATH (/usr/share/classpath/glibj.zip),
2070 so you do not have to manually run
2071 jikes --bootclasspath /usr/share/classpath/glibj.zip
2072 -- 
2073 Online resizing of (Software-)RAID5:
2074
2075 # Initiate a RAID5 setup for testing purposes:
2076 mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/hda1 /dev/hdb1 /dev/hdd1
2077
2078 # Create filesystem, mount md0, create a testfile and save md5sum for
2079 # later check:
2080 mkfs.ext3 /dev/md0
2081 mount /dev/md0 /mnt/test
2082 dd if=/dev/urandom of=/mnt/test/dd bs=512 count=10000
2083 md5sum /mnt/test/dd > md5sum
2084
2085 # Make sure the RAID is synched via checking:
2086 cat /proc/mdstat
2087
2088 # Now remove one partition:
2089 mdadm /dev/md0 --fail /dev/hdd1 --remove /dev/hdd1
2090
2091 # Delete partition, create a new + bigger one and set partition type to fd
2092 # (Linux raid autodetect):
2093 cfdisk /dev/hdd
2094
2095 # And re-add the partition:
2096 mdadm -a /dev/md0 /dev/hdd1
2097
2098 # Make sure the RAID is synched via checking:
2099 cat /proc/mdstat
2100
2101 # Repeat the steps for all other disks/partitions as well:
2102 mdadm /dev/md0 --fail /dev/hdb1 --remove /dev/hdb1
2103 cfdisk /dev/hdb
2104 mdadm -a /dev/md0 /dev/hdb1
2105 cat /proc/mdstat
2106 mdadm /dev/md0 --fail /dev/hda1 --remove /dev/hda1
2107 cfdisk /dev/hda
2108 mdadm -a /dev/md0 /dev/hda1
2109 cat /proc/mdstat
2110
2111 # Now resize the RAID5 system online [see 'man mdadm' for details]:
2112 mdadm --detail /dev/md0 | grep -e 'Array Size' -e 'Device Size'
2113 mdadm --grow /dev/md0 -z max
2114 mdadm --detail /dev/md0 | grep -e "Array Size" -e 'Device Size'
2115
2116 # Last step - resize the filesystem (online again):
2117 resize2fs /dev/md0
2118
2119 Tags: raid, resize, raid5, mdadm
2120 -- 
2121 ext3 online resizing:
2122
2123 Starting with Linux kernel 2.6.10 you can resize ext3 online.  With
2124 e2fsprogs >=1.39-1 new filesystems are created with directory indexing and
2125 on-line resizing enabled by default (see /etc/mke2fs.conf).
2126
2127 Demo:
2128
2129 cfdisk /dev/hda                           # create a partition with type 8e (lvm)
2130 pvcreate /dev/hda2                        # create a physical volume
2131 vgcreate resize_me /dev/hda2              # create volume group
2132 lvcreate -n resize_me -L100 resize_me     # create a logical volume
2133 mkfs.ext3 /dev/resize_me/resize_me        # now create a new filesystem
2134 mount /dev/resize_me/resize_me /mnt/test  # mount the new fs for demonstrating online resizing
2135 df -h                                     # check the size of the partition
2136 lvextend -L+100M /dev/resize_me/resize_me # let's extend the logical volume
2137 resize2fs /dev/resize_me/resize_me        # and finally resize the filesystem
2138 df -h                                     # recheck the size of the partition
2139
2140 This also works for Software-RAID. Demo:
2141
2142 mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/hda2 /dev/hdb1
2143 mkfs.ext3 /dev/md0
2144 mount /dev/md0 /mnt/test
2145 mdadm /dev/md0 --fail /dev/hda2 --remove /dev/hda2
2146 cfdisk /dev/hda                                  # adjust partition size for hda2
2147 mdadm /dev/md0 --add /dev/hda2
2148 mdadm /dev/md0 --fail /dev/hdb1 --remove /dev/hdb1
2149 cfdisk /dev/hdb                                  # adjust partition size for hdb1
2150 mdadm /dev/md0 --add /dev/hdb1
2151 mdadm --grow /dev/md0 --size=max
2152 resize2fs /dev/md0
2153
2154 Notice: online resizing works as soon as the kernel can re-read the
2155 partition table. So it works for example with LVM and SW-RAID but not with
2156 a plain device (/dev/[sh]d*). The kernel does not re-read the partition
2157 table if the device is already mounted.
2158
2159 Tags: resize, raid, lvm, ext2, ext3, ext4, raid1
2160 -- 
2161 Use vim as an outline editor:
2162
2163 % $PAGER /usr/share/doc/vim-vimoutliner/README.Debian
2164 % vim ~/foo.otl
2165 :he vo
2166 -- 
2167 Monitor directories/files for changes using iwatch
2168
2169 Monitor /tmp for changes:
2170 % iwatch /tmp/
2171
2172 Monitor files/directories specified in /etc/iwatch.xml
2173 and send mail on changes:
2174 % iwatch
2175
2176 Tags: inotify, watch, file, directory
2177 -- 
2178 Some often used mdadm commands:
2179
2180 Set up RAID1:
2181 # mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/hda1 /dev/hdb1
2182
2183 Display details of specific RAID:
2184 # mdadm --detail /dev/md0
2185 # cat /proc/mdstat
2186
2187 Simulating a drive failure by software:
2188 # mdadm --manage --set-faulty /dev/md0 /dev/hda1
2189
2190 Remove disk from RAID:
2191 # mdadm /dev/md0 -r /dev/hda1
2192
2193 Set disk as faulty and remove from RAID:
2194 # mdadm /dev/md0 --fail /dev/hda1 --remove /dev/hda1
2195
2196 Stop a RAID-device:
2197 # mdadm -S /dev/md0
2198
2199 Restart a RAID-device:
2200 # mdadm -R /dev/md0
2201
2202 Add another disk to existing RAID setup (hotadd):
2203 # mdadm /dev/md0 -a /dev/hde1
2204 # mdadm --grow /dev/md0 --raid-devices=4
2205
2206 Assemble and start all arrays:
2207 # mdadm --assemble --scan
2208
2209 Assemble a specific array:
2210 # mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1
2211
2212 Resync:
2213 # mdadm --assemble --run --force --update=resync /dev/md0 /dev/sda1 /dev/sda2
2214
2215 Stop and rebuild:
2216 # mdadm --stop --scan
2217
2218 Scan for and setup arrays automatically:
2219 # mdadm --assemble --scan --auto=yes --verbose
2220
2221 Notice: If the above does not work make sure /etc/mdadm/mdadm.conf contains:
2222 DEVICE partitions
2223 CREATE owner=root group=disk mode=0660 auto=yes
2224 HOMEHOST <system>
2225 MAILADDR root
2226
2227 Running
2228 # /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf
2229 might help as well.
2230
2231 Monitoring the sw raid
2232 # nohup mdadm --monitor --mail=root@localhost --delay=300 /dev/md0
2233
2234 Producing /etc/mdadm/mdadm.conf:
2235 # mdadm --detail --scan > /etc/mdadm/mdadm.conf
2236
2237 See also: man mdadm | less -p "^EXAMPLES"
2238           http://www.tldp.org/HOWTO/Software-RAID-HOWTO.html
2239
2240 Tags: raid, raid1, raid5, configuration, mdadm, howto
2241 -- 
2242 A quick summary of the most commonly used RAID levels:
2243
2244 RAID 0: Striped Set
2245  => 2 disks each 160 GB: 320 GB data
2246 RAID 1: Mirrored Set
2247  => 2 disks each 160 GB: 160 GB data
2248 RAID 5: Striped Set with Parity
2249  => 3 disks each 160 GB: 320 GB data; 160 GB redundancy
2250
2251 Common nested RAID levels:
2252 RAID 01: A mirror of stripes
2253 RAID 10: A stripe of mirrors
2254 RAID 30: A stripe across dedicated parity RAID systems
2255 RAID 100: A stripe of a stripe of mirrors
2256
2257   -- http://en.wikipedia.org/wiki/RAID
2258
2259 Tags: raid, raid1, raid5, raid01, raid10, raid100
2260 -- 
2261 Logical Volume Management (LVM) with Linux
2262
2263 LVM setup layout:
2264 ~~~~~~~~~~~~~~~~~
2265
2266 |    hda1   hdc1      (PV:s on partitions or whole disks)
2267 |       \   /
2268 |        \ /
2269 |       diskvg        (VG)
2270 |       /  |  \
2271 |      /   |   \
2272 |  usrlv rootlv varlv (LV:s)
2273 |    |      |     |
2274 | ext3    ext3  xfs   (filesystems)
2275
2276 Often used commands:
2277 ~~~~~~~~~~~~~~~~~~~~
2278
2279 Create a physical volume:
2280 # pvcreate /dev/hda2
2281
2282 Create a volume group:
2283 # vgcreate testvg /dev/hda2
2284
2285 Create a logical volume:
2286 # lvcreate -n test_lv -L100 testvg
2287
2288 Resize a logical volume:
2289 # lvextend -L+100M /dev/resize_me/resize_me
2290 # resize2fs /dev/resize_me/resize_me               # ext2/3
2291 # xfs_growfs  /dev/resize_me/resize_me             # xfs
2292 # resize_reiserfs -f /dev/resize_me/resize_me      # reiserfs online
2293 # mount -o remount,resize /dev/resize_me/resize_me # jfs
2294
2295 Create a snapshot of a logical volume:
2296 # lvcreate -L 500M --snapshot -n mysnap /dev/testvg/test_lv
2297
2298 Deactivate a volume group:
2299 # vgchange -a n my_volume_group
2300
2301 Actually remove a volume group:
2302 # vgremove my_volume_group
2303
2304 Display information about physical volume:
2305 # pvdisplay /dev/hda1
2306
2307 Remove physical volume:
2308 # vgreduce my_volume_group /dev/hda1
2309
2310 Remove logical volume:
2311 # umount /dev/myvg/homevol
2312 # lvremove /dev/myvg/homevol
2313
2314 See also: man lvm
2315           http://www.tldp.org/HOWTO/LVM-HOWTO/
2316
2317 Tags: lvm, howto, pvcreate, lvcreate
2318 -- 
2319 How to use APT locally
2320
2321 Sometimes you have lots of packages .deb that you would like to use APT to
2322 install so that the dependencies would be automatically solved. Solution:
2323
2324 mkdir debs
2325 dpkg-scanpackages debs /dev/null | gzip > debs/Packages.gz
2326 echo "  deb file:/root debs/" >> /etc/apt/sources.list
2327 dpkg-scansources debs | gzip > debs/Sources.gz
2328 echo "  deb-src file:/root debs/" >> /etc/apt/sources.list
2329
2330 See also: http://www.debian.org/doc/manuals/apt-howto/ch-basico.en.html
2331
2332 Tags: mirror, local
2333 -- 
2334 Check filesystem's LABEL:
2335
2336 generic way:
2337 # blkid /dev/sda1
2338
2339 ext2/3 without blkid:
2340 # dumpe2fs /dev/sda1 | grep "Filesystem volume name"
2341
2342 xfs without blkid:
2343 # xfs_admin -l /dev/sda1
2344
2345 reiserfs without blkid:
2346 # debugreiserfs /dev/sda1 | grep -i label
2347
2348 jfs without blkid:
2349 # jfs_tune -l /dev/sda1 | grep -i label
2350
2351 reiser4 without blkid:
2352 # debugfs.reiser4 /dev/sda1 | grep -i label
2353
2354 Tags: filesystem, ext2, ext3, ext4, blkid, jfs, xfs, label
2355 -- 
2356 Check filesystem's UUID:
2357
2358 generic way:
2359 # blkid /dev/sda1
2360
2361 ext2/3 without blkid:
2362 # dumpe2fs /dev/sda1 | grep -i UUID
2363
2364 xfs without blkid:
2365 # xfs_admin -u /dev/sda1
2366
2367 reiserfs without blkid:
2368 # debugreiserfs /dev/sda1 | grep -i UUID
2369
2370 reiser4 without blkid:
2371 # debugfs.reiser4 /dev/sda1 | grep -i UUID
2372
2373 Tags: filesystem, ext2, ext3, ext4, blkid, jfs, xfs, uuid
2374 -- 
2375 Change a filesystem's LABEL:
2376
2377 swap:
2378 # mkswap -L $LABEL /dev/sda1
2379
2380 ext2/ext3:
2381 # e2label /dev/sda1 $LABEL
2382 # tune2fs -L $LABEL /dev/sda1
2383
2384 reiserfs:
2385 # reiserfstune -l $LABEL /dev/sda1
2386
2387 jfs:
2388 # jfs_tune -L $LABEL /dev/sda1
2389
2390 xfs:
2391 # xfs_admin -L $LABEL /dev/sda1
2392
2393 fat/vfat:
2394 # echo 'drive i: file="/dev/sda1"' >> ~/.mtoolsrc
2395 # mlabel -s i:$LABEL
2396
2397 ntfs:
2398 # ntfslabel $LABEL /dev/sda1
2399
2400 Tags: filesystem, ext2, ext3, ext4, blkid, jfs, xfs
2401 -- 
2402 Disable pdiffs feature of APT:
2403
2404 Permanent:
2405 # echo 'Acquire::PDiffs "false";' >> /etc/apt/apt.conf
2406
2407 Temporary:
2408 # apt-get update -o Acquire::Pdiffs=false
2409 -- 
2410 Backup big devices or files and create compressed splitted
2411 image chunks of it using zsplit
2412
2413 Create backup of /dev/sda named archiveofsda_#.spl.zp in directory
2414 /mnt/sda1/backup, split the files up into chunks of 1GB each and set
2415 read/write buffer to 256kB:
2416 # zsplit -b 256 -N archiveofsda -o /mnt/sda1/backup/ -s 1G /dev/sda
2417
2418 Restore the backup using unzsplit:
2419 # unzsplit -D /dev/sda -d archiveofsda
2420
2421 More usage examples: man zsplit + man unzsplit
2422
2423 Tags: backup, reocvery, spllt, limit, howto
2424 -- 
2425 Measure network performance using iperf:
2426
2427 Server side:
2428 % iperf -s -V
2429
2430 Client side:
2431 % iperf -c <server_address> -V
2432
2433 or
2434
2435 Server with 128k TCP window size:
2436 % iperf -s -w128k
2437
2438 Client with running for 60 seconds and bidirectional test:
2439 % iperf -c <server_address> -r -w128k -t60
2440
2441 Tags: network, benchmark
2442 -- 
2443 Framebuffer resolutions:
2444
2445                               Resolution in pixels
2446 Color depth      |   640x480      800x600      1024x768      1280x1024
2447 256        (8bit)|     769          771           773           775
2448 32000     (15bit)|     784          787           790           793
2449 65000     (16bit)|     785          788           791           794
2450 16.7 Mill.(24bit)|     786          789           792           795
2451
2452 vga=0x... modes:
2453
2454   Mode 0x0300: 640x400 (+640), 8 bits
2455   Mode 0x0301: 640x480 (+640), 8 bits
2456   Mode 0x0303: 800x600 (+800), 8 bits
2457   Mode 0x0303: 800x600 (+832), 8 bits
2458   Mode 0x0305: 1024x768 (+1024), 8 bits
2459   Mode 0x0307: 1280x1024 (+1280), 8 bits
2460   Mode 0x030e: 320x200 (+640), 16 bits
2461   Mode 0x030f: 320x200 (+1280), 24 bits
2462   Mode 0x0311: 640x480 (+1280), 16 bits
2463   Mode 0x0312: 640x480 (+2560), 24 bits
2464   Mode 0x0314: 800x600 (+1600), 16 bits
2465   Mode 0x0315: 800x600 (+3200), 24 bits
2466   Mode 0x0317: 1024x768 (+2048), 16 bits
2467   Mode 0x0318: 1024x768 (+4096), 24 bits
2468   Mode 0x031a: 1280x1024 (+2560), 16 bits
2469   Mode 0x031b: 1280x1024 (+5120), 24 bits
2470   Mode 0x0330: 320x200 (+320), 8 bits
2471   Mode 0x0331: 320x400 (+320), 8 bits
2472   Mode 0x0332: 320x400 (+640), 16 bits
2473   Mode 0x0333: 320x400 (+1280), 24 bits
2474   Mode 0x0334: 320x240 (+320), 8 bits
2475   Mode 0x0335: 320x240 (+640), 16 bits
2476   Mode 0x0336: 320x240 (+1280), 24 bits
2477   Mode 0x033c: 1400x1050 (+1408), 8 bits
2478   Mode 0x033d: 640x400 (+1280), 16 bits
2479   Mode 0x033e: 640x400 (+2560), 24 bits
2480   Mode 0x0345: 1600x1200 (+1600), 8 bits
2481   Mode 0x0346: 1600x1200 (+3200), 16 bits
2482   Mode 0x034d: 1400x1050 (+2816), 16 bits
2483   Mode 0x035c: 1400x1050 (+5632), 24 bits
2484
2485 Tags: framebuffer, resolution
2486 -- 
2487 Portscan using netcat:
2488
2489 # netcat -v -w2 <host|ip-addr.> 1-1024
2490 -- 
2491 Run apt-get but disable apt-listchanges:
2492
2493 APT_LISTCHANGES_FRONTEND=none apt-get ...
2494
2495 Upgrade system but disable apt-listbugs:
2496
2497 APT_LISTBUGS_FRONTEND=none apt-get ...
2498 -- 
2499 Set up a Transparent Debian Proxy
2500
2501 Install of apt-cacher, the default config will do:
2502 # apt-get install apt-cacher
2503
2504 Check out the ip address of debian mirror(s).
2505 Then add this to your firewall script:
2506
2507 DEBIAN_MIRRORS="141.76.2.4 213.129.232.18"
2508 for ip in ${DEBIAN_MIRRORS} ; do
2509   ${IPTABLES} -t nat -A PREROUTING -s $subnet -d $ip -p tcp --dport 80 -j REDIRECT --to-port 3142
2510 done
2511
2512 where ${IPTABLES} is the location of your iptables binary
2513 and $subnet is your internal subnet.
2514
2515 Now everybody in your subnet who does access either
2516 ftp.de.debian.org or ftp.at.debian.org will actually
2517 access your apt-cacher instead.
2518
2519 To use apt-cacher on the router itself, add the following
2520 line to your /etc/apt/apt.conf:
2521
2522 Acquire::http::Proxy "http://localhost:3142/";
2523
2524 Tags: proxy, debian, apt-get, howto
2525 -- 
2526 Version control using Mercurial
2527
2528 Setting up a Mercurial project:
2529
2530 % cd project
2531 % hg init           # creates .hg
2532 % hg add            # add all files
2533 % hg commit         # commit all changes, edit changelog entry
2534
2535 Branching and merging:
2536
2537 % hg clone linux linux-work  # create a new branch
2538 % cd linux-work
2539 <make changes>
2540 % hg commit
2541 % cd ../linux
2542 % hg pull ../linux-work     # pull changesets from linux-work
2543 % hg merge                  # merge the new tip from linux-work into
2544                             # (old versions used "hg update -m" instead)
2545                             # our working directory
2546 % hg commit                 # commit the result of the merge
2547
2548 Importing patches:
2549
2550 % cat ../p/patchlist | xargs hg import -p1 -b ../p
2551
2552 Exporting a patch:
2553
2554 (make changes)
2555 % hg commit
2556 % hg tip
2557 1234:af3b5cd57dd5
2558 % hg export 1234 > foo.patch    # export changeset 1234
2559
2560 Export your current repo via HTTP with browsable interface:
2561
2562 % hg serve -n "My repo" -p 80
2563
2564 Pushing changes to a remote repo with SSH:
2565
2566 % hg push ssh://user@example.com/~/hg/
2567
2568 Merge changes from a remote machine:
2569
2570 host1% hg pull http://foo/
2571 host2% hg merge # merge changes into your working directory
2572
2573 Set up a CGI server on your webserver:
2574 % cp hgwebdir.cgi ~/public_html/hg/index.cgi
2575 % $EDITOR ~/public_html/hg/index.cgi # adjust the defaults
2576 -- 
2577 Download binary codecs for mplayer:
2578
2579 # /usr/share/mplayer/scripts/win32codecs.sh
2580
2581 or
2582
2583 # /usr/share/mplayer/scripts/binary_codecs.sh install
2584
2585 (depending on the mplayer version you have).
2586
2587 To play encrypted DVDs and if you are living in a country where using
2588 libdvdcss code is not illegal can install Debian package libdvdread3
2589 and use the script /usr/share/doc/libdvdread3/install-css.sh.
2590 -- 
2591 Read manpages of uninstalled packages with debman:
2592
2593 % debman -p git-core git
2594 -- 
2595 Test network performance using netperf:
2596
2597 Server:
2598 # netserver
2599
2600 Client:
2601 # netperf -t TCP_STREAM -H 192.168.0.41
2602
2603 Tags: benchmark, network
2604 -- 
2605 Setup Xen within 20 minutes on Debian/grml
2606
2607 Install relevant software und update grub's menu.lst (Xen does not work with
2608 usual lilo so install grub instead if not done already):
2609
2610 apt-get install linux-image-2.6.18-1-xen-686 xen-hypervisor-3.0.3-1-i386 \
2611                  xen-utils-3.0.3-1 xen-tools bridge-utils
2612 update-grub
2613
2614 Example for installation of Debian etch as DomU:
2615
2616 mkdir /mnt/md1/xen
2617 xen-create-image --debootstrap --dir=/mnt/md1/xen --size=2Gb --memory=512Mb --fs=ext3 \
2618    --cache=yes --dist=etch --hostname=xengrml1 --ip 192.168.1.2 --netmask 255.255.255.0 \
2619   --gateway 192.168.1.1 --initrd=/boot/initrd.img-2.6.18-1-xen-686 \
2620   --kernel=/boot/vmlinuz-2.6.18-1-xen-686 --mirror=http://ftp.at.debian.org/debian/
2621
2622 Start services:
2623
2624 /etc/init.d/xend start
2625 /etc/init.d/xendomains start
2626
2627 Setup a bridge for network, either manually:
2628
2629 brctl addbr xenintbr
2630 brctl stp xenintbr off
2631 brctl sethello xenintbr 0
2632 brctl setfd xenintbr 0
2633 ifconfig xenintbr 192.168.1.1 netmask 255.255.255.0 up
2634
2635 or via /etc/network/interfaces (run ifup xenintbr to bring up the device then
2636 without rebooting):
2637
2638 auto xenintbr
2639 iface xenintbr inet static
2640   pre-up brctl addbr xenintbr
2641   post-down brctl delbr xenintbr
2642   address 192.168.1.1
2643   netmask 255.255.255.0
2644   bridge_fd 0
2645   bridge_hello 0
2646   bridge_stp off
2647
2648 Setup forwarding (adjust $PUBLIC_IP; for permanet setup use /etc/sysctl.conf and
2649 add the iptables commands to a startup script like /etc/init.d/rc.local):
2650
2651 echo 1 > /proc/sys/net/ipv4/ip_forward
2652 iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j SNAT --to $PUBLIC_IP
2653 iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to $PUBLIC_IP
2654
2655 Adjust network configuration of Xend:
2656
2657 cat >> /etc/xen/xend-config.sxp << EOF
2658 (network-script    network-route)
2659 (vif-bridge        xenintbr)
2660 (vif-script        vif-bridge)
2661 EOF
2662
2663 List domains, start up a DomU, shutdown later again:
2664
2665 xm create -c /etc/xen/xengrml1.cfg
2666 xm list
2667 xm shutdown 1
2668
2669 This HowTo is also available online at http://grml.org/xen/
2670
2671 Tags: howto, xen, grml
2672 -- 
2673 Play tetris with zsh:
2674
2675 autoload -U tetris
2676 zle -N tetris
2677 bindkey "^Xt" tetris
2678
2679 Now press 'ctrl-x t'.
2680 -- 
2681 Set up a router with grml
2682
2683 Run grml-router script:
2684 # grml-router
2685
2686 Install dnsmasq if not already present:
2687 # apt-get update ; apt-get install dnsmasq
2688
2689 Adjust /etc/dnsmasq.conf according to your needs:
2690 # cat >> /etc/dnsmasq.conf << EOF
2691 domain-needed
2692 bogus-priv
2693 dhcp-range=19.168.0.124,192.168.0.254,1m # dhcp range
2694 dhcp-option=3,192.168.0.1   # dns server
2695 dhcp-option=1,255.255.255.0 # netmask
2696 EOF
2697
2698 Start dnsmasq finally:
2699 # Restart dnsmasq
2700
2701 Tags: network, router, grml
2702 -- 
2703 Display stats about memory allocations performed by a program:
2704
2705 Usage example for 'ls':
2706
2707 % LD_PRELOAD=/lib/libmemusage.so ls > /dev/null
2708 -- 
2709 Use KVM (Kernel-based Virtual Machine for Linux):
2710
2711 Make sure to install the relevant tools:
2712 # apt-get update ; apt-get install kvm
2713 # modprobe kvm
2714
2715 Test it with a minimal system like ttylinux:
2716 # wget http://www.minimalinux.org/ttylinux/packages/bootcd-i386-5.3.iso.gz
2717 # gzip -d bootcd-i386-5.3.iso.gz
2718 # kvm -cdrom bootcd-i386-5.3.iso
2719 -- 
2720 EEPROM data decoding for SDRAM DIMM modules:
2721
2722 # modprobe eeprom
2723 # /usr/share/doc/lm-sensors/examples/eeprom/decode-dimms.pl
2724 -- 
2725 Set up and use DVB:
2726
2727 Make sure your device is supported by Linux and running.
2728 See http://www.linuxtv.org/ for more details.
2729
2730 If the DVB device works on your system (see 'hwinfo --usb'
2731 when using a DVB usb device for example), then make sure you
2732 have the scan util from dvb-utils available:
2733
2734 # aptitude install dvb-utils
2735
2736 Then create a channels.conf configuration file:
2737
2738 % scan /usr/share/doc/dvb-utils/examples/scan/... > ~/.mplayer/channels.conf
2739
2740 You can find some example configuration files on
2741 your grml system in ~/.channels. Usage example:
2742
2743 % ln -s ~/.mplayer/channels.conf-AT-graz ~/.mplayer/channels.conf
2744
2745 Tip: w_scan (see http://free.pages.at/wirbel4vdr/w_scan/index2.html)
2746 might be useful if you do not know the initial configuration
2747 details.
2748 -- 
2749 Get the lastest mercurial snapshot:
2750
2751 Make sure you have the python-dev package available:
2752 # apt-get update ; apt-get install python-dev
2753
2754 Get and build the source:
2755 % hg clone http://selenic.com/repo/hg mercurial
2756 % cd mercurial
2757 % make local
2758 % export PYTHONPATH=$(pwd)
2759 % export PATH=$PATH:$(pwd)
2760
2761 now you should have the newest version of mercurial whenever you execute hg.
2762
2763 To update to the lastest development snapshot, additionally use
2764 the following commands:
2765 % hg pull -u http://hg.intevation.org/mercurial/crew
2766 % make local
2767 -- 
2768 Configure timezone
2769 ==================
2770
2771 Available bootoptions relevant in live-cd mode:
2772 -----------------------------------------------
2773
2774 * utc: set UTC, if your system clock is set to UTC (GMT)
2775 * gmt: set UTC, if your system clock is set to UTC (GMT) [like bootoption utc]
2776 * tz=$option: set timezone to corresponding $option, usage example:
2777   tz=Europe/Vienna
2778
2779 Configuration options relevant on harddisk installation:
2780 --------------------------------------------------------
2781
2782 * Use the tzconfig utility to set the local timezone:
2783
2784   # tzconfig
2785
2786   which adjusts /etc/timezone and /etc/localtime according
2787   to the provided information. Running:
2788
2789   # dpkg-reconfigure tzdata
2790
2791   might be useful as well.
2792
2793 * /etc/default/rcS: set variable UTC according to your needs,
2794   whether your system clock is set to UTC (UTC='yes') or
2795   not (UTC='no')
2796
2797 * /etc/localtime: adjust zoneinfo according to your needs:
2798
2799   # ln -sf /usr/share/zoneinfo/$WHATEVER_YOU_WANT /etc/localtime
2800
2801   The zoneinfo directory contains the time zone files that were
2802   compiled by zic. The files contain information such as rules
2803   about DST. They allow the kernel to convert UTC UNIX time into
2804   appropriate local dates and times. Use the zdump utility to
2805   print current time and date (in the specified time zone).
2806
2807 * /etc/adjtime: This file is used e.g. by the adjtimex function,
2808   which can smoothly adjust system time while the system runs
2809
2810 * If you change the time (using 'date --set ...', ntpdate,...)
2811   it is worth setting also the hardware clock to the correct time:
2812
2813   # hwclock --systohc [--utc]
2814
2815   Remember to add the --utc -option if the hardware clock is set
2816   to UTC!
2817
2818 Still problems?
2819 ---------------
2820
2821 Check your current settings via:
2822
2823   cat /etc/timezone
2824   zdump /etc/localtime
2825   echo $TZ
2826   hwclock --show
2827   grep hwclock /etc/runlevel.conf
2828   grep '^UTC' /etc/default/rc
2829
2830 Further information:
2831 --------------------
2832
2833   hwclock(8) tzselect(1) tzconfig(8)
2834   http://www.debian.org/doc/manuals/system-administrator/ch-sysadmin-time.html
2835   http://wiki.debian.org/TimeZoneChanges
2836
2837 Tags: timezone, rtc, configuration
2838 -- 
2839 Recorder shellscript session using script:
2840
2841 % script -t 2>~/upgrade.time -a ~/upgrade.script
2842 % scriptreplay ~/upgrade.time ~/upgrade.script
2843 -- 
2844 Test UTF-8 capabilities of terminal:
2845
2846 wget http://www.linux-cjk.net/Console/garabik/UTF-8-demo.txt.gz
2847 zcat UTF-8-demo.txt.gz
2848
2849 or:
2850
2851 wget http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
2852 cat UTF-8-test.txt
2853 -- 
2854 UTF-8 at grml / some general information regarding Unicde/UTF-8:
2855
2856   http://wiki.grml.org/doku.php?id=utf8
2857 -- 
2858
2859 This allows one ssh connection attepmt per minute per source ip, with a initial
2860 burst of 10.  The available burst is like a counter which is initialised with
2861 10. Every connection attempt decrements the counter, and every minute where the
2862 connection limit of one per minute is not overstepped the counter is
2863 incremented by one.  If the burst counter is exhausted the real rate limit
2864 comes into play. This gives you 11 connectionattepmts in the first minute
2865 before blocked for 10minutes.  After 10 minutes block the game restarts.
2866
2867 Hint: you could set the burst value to 5 and the block time to only 5 minutes
2868 to achive the same average connection rate but with halve the block time.
2869
2870 iptables -A inet_in -p tcp --syn --dport 22 -m hashlimit --hashlimit-name ssh \
2871          --hashlimit 1/minute \ --hashlimit-burst 10 --hashlimit-mode srcip   \
2872          --hashlimit-htable-expire 600000 -j ACCEPT
2873 iptables -A inet_in -p tcp --dport 22 -m state --state NEW -j REJECT
2874 -- 
2875 Tunnel a specific connection via socat:
2876
2877 On the client:
2878 % socat TCP4-LISTEN:8003 TCP4:gateway:500
2879
2880 On the gateway:
2881 # socat TCP4-LISTEN:500,fork TCP4:target:$PORT
2882
2883 Using localhost:8003 on the client uses the tunnel now.
2884 -- 
2885 Set date:
2886
2887 # date --set=060916102007
2888
2889 where the bits are month(2)/day(2)/hour(2)/minute(2)/year(4)
2890
2891 Set date using a relative date:
2892
2893 # date -s '+3 mins'
2894
2895 or
2896
2897 # date -s '+tomorrow'
2898
2899 Display a specific relative date:
2900
2901 # date -d '+5 days -2 hours'
2902
2903 Don't forget to set hardware clock via:
2904
2905 # hwlock -w
2906 -- 
2907 Booting grml via network / PXE:
2908
2909 Start grml-terminalserver on a system with network access
2910 and where grml is running:
2911
2912 # grml-terminalserver
2913
2914 Then booting your client(s) via PXE should work without
2915 any further work.
2916
2917 See: man grml-terminalserver + http://grml.org/terminalserver/
2918
2919 Tags: howto, pxe, network, boot
2920 -- 
2921 Debugging SSL communications:
2922
2923 % openssl s_client -connect server.adress:993 > output_file
2924 % openssl x509 -noout -text -in output_file
2925
2926 or
2927
2928 # ssldump -a -A -H -i eth0
2929
2930 See http://prefetch.net/articles/debuggingssl.html for more details.
2931
2932 Tags: debug, ssl, openssl
2933 -- 
2934 Remove bootmanager from MBR:
2935
2936 # lilo -M /dev/hda -s /dev/null
2937
2938 Tags: mbr, lilo
2939 -- 
2940 Rewrite grub to MBR:
2941
2942 # mount /mnt/sda1
2943 # grub-install --recheck --no-floppy --root-directory=/mnt/sda1 /dev/sda
2944
2945 Tags: mbr, grub
2946 -- 
2947 Rewrite lilo to MBR:
2948
2949 # mount /mnt/hda1
2950 # lilo -r /mnt/hda1
2951
2952 Tags: mbr, lilo
2953 -- 
2954 Create screenshot of plain/real console - tty1:
2955
2956 # fbgrab -c 1 screeni.png
2957 -- 
2958 Create screenshot when running X:
2959
2960 % scrot
2961
2962 Tip: use the gkrellshoot plugin when using gkrellm
2963
2964 Tags: screenshot, xorg
2965 -- 
2966 Redirect all connections to hostA:portA to hostB:portB, where hostA and hostB are
2967 different networks:
2968
2969 Run the following commands on hostA:
2970
2971 echo 1 > /proc/sys/net/ipv4/ip_forward
2972 iptables -t nat -A PREROUTING -p tcp --dport portA -j DNAT --to hostB:portB
2973 iptables -A FORWARD -i eth0 -o eth0 -d hostB -p tcp --dport portB -j ACCEPT
2974 iptables -A FORWARD -i eth0 -o eth0 -s hostB -p tcp --sport portB -j ACCEPT
2975 iptables -t nat -A POSTROUTING -p tcp -d hostB --dport portB -j SNAT --to-source hostA
2976
2977 Tags: howto, network, redirect, port
2978 -- 
2979 Flash BIOS without DOS/Windows:
2980
2981 Dump flash info and set the flash chip to writable:
2982 # flashrom
2983
2984 Backup the original BIOS:
2985 # flashrom -r backup.bin
2986
2987 Notice: the following step will overwrite your current BIOS!
2988 So make sure you really know what you are doing.
2989
2990 Flash the BIOS image:
2991 # flashrom -wv newbios.bin
2992
2993 Also check out LinuxBIOS: http://linuxbios.org/
2994 -- 
2995 Enable shadow passwords:
2996
2997 # shadowconfig on
2998 -- 
2999 Set up an IPv6 tunnel on grml:
3000
3001 # ipv6-tunnel start
3002 -- 
3003 Set up console newsreader slrn for use with Usenet:
3004
3005 % grml-slrn
3006 -- 
3007 Calculate with IPv6 addresses:
3008
3009 % ipv6calc
3010
3011 For usage examples refer to manpage ipv6calc(8).
3012
3013 Tags: ipv6
3014 -- 
3015 Common network debugging tools for use with IPv6:
3016
3017 % ping6
3018 % tracepath6
3019 % traceroute6
3020 % tracert6
3021 % nc6
3022 % tcpspray6
3023
3024 Tags: ipv6
3025 -- 
3026 Set up NFS (Network File System):
3027
3028 Server-side
3029 ~~~~~~~~~~~
3030 Make sure the relevant services are running on the server side:
3031
3032 # /etc/init.d/portmap start
3033 # /etc/init.d/nfs-common start
3034 # /etc/init.d/nfs-kernel-server start
3035
3036 Export shares via /etc/exports:
3037
3038 /backups 192.168.1.100/24(rw,wdelay,no_root_squash,async,subtree_check)
3039
3040 ... or manually export a directory running:
3041
3042 # exportfs -o rw,wdelay,no_root_squash,async,subtree_check 192.168.1.100:/backups
3043
3044 and unexport a share running:
3045
3046 # exportfs -u 192.168.1.100:/backups
3047
3048 and every time when you modify /etc/exports file run
3049
3050 # exportfs -ra
3051
3052 Display what NFS components are running:
3053
3054 # rpcinfo -p
3055
3056 Display list of exported shares:
3057
3058 # exportfs -v
3059 or
3060 # showmount -e
3061
3062 Client-side
3063 ~~~~~~~~~~~
3064 Make sure the relevant services are running on the client side:
3065
3066 # /etc/init.d/portmap start
3067 # /etc/init.d/nfs-common start
3068
3069 Verify that the server allows you to access its RPC/NFS services:
3070
3071 # rpcinfo -p server_name
3072
3073 Check what directories the server exports:
3074
3075 # showmount -e server_name
3076
3077 On the client side you can use something like the following in /etc/fstab:
3078
3079 192.168.1.101:/backups /mnt/nfs nfs defaults,users,wsize=8192,rsize=8192 0 0
3080
3081 Tags: nfs, howto, network
3082 -- 
3083 Mount a cloop file:
3084
3085 # aptitude install cloop-src
3086 # m-a a-i cloop-src
3087
3088 # modprobe cloop file=/path/to/cloop/file
3089 # mount -r -t iso9660 /dev/cloop /mnt/test
3090 -- 
3091 Create a PS/PDF of a plaintext file:
3092
3093 % a2ps --medium A4dj -E -o output.ps input_file
3094 % ps2pdf output.ps
3095 -- 
3096 Print two pages on one in a PDF file:
3097
3098 % pdfnup --nup 2x1 input.pdf
3099
3100 Concatenate, extract pages/parts, encrypt/decrypt,
3101 compress PDFs using 'pdftk'.
3102 -- 
3103 Read a PS/PDF file on console:
3104
3105 % pstotext file.pdf
3106
3107 or on plain framebuffer console in graphical mode:
3108
3109 % pdf2ps file.pdf ; ps2png file.ps file.png ; fbi file.png
3110
3111 or
3112
3113 % fbgs file.pdf
3114 -- 
3115 Bypass the password of a PDF file:
3116
3117 % gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf -c quit
3118 -- 
3119 Record sound:
3120
3121 % rec test.aiff
3122
3123 This will record a AIFF audio file.
3124 -- 
3125 Change passphrase / password of an existing SSH key:
3126
3127 % ssh-keygen -p
3128 -- 
3129 Enable syntax highlighting in nano:
3130
3131 Just uncomment the include directives for your respective
3132 language at the bottom of the file /etc/nanorc
3133 -- 
3134 Create netboot package for grml-terminalserver:
3135
3136 # bash /usr/share/doc/grml-terminalserver/examples/create-netboot
3137 -- 
3138 To boot grml via network (PXE) check out grml-terminalserver:
3139
3140 # grml-terminalserver
3141
3142 See http://grml.org/terminalserver/ for more details.
3143 -- 
3144 Rotate pictures:
3145
3146 Using the 'Orientation' tag of the Exif header, rotate
3147 the image so that it is upright:
3148 % jhead -autorot *.jpg
3149
3150 Manually rotate a picture:
3151 % convert -rotate 270 input.jpg output.jpg
3152 -- 
3153 Rename files based on the information inside their exif header:
3154
3155 % jhead -n%Y-%m-%d_%Hh%M_%f *.jpg
3156
3157 This will rename a file named img_2071.jpg to something like:
3158
3159 2007-08-17_10h38_img_2071.jpg
3160
3161 if it was shot at 10:38 o'clock on 2007-08-17 (according to
3162 the information inside the exif header).
3163 -- 
3164 Calculate network / netmask:
3165
3166 Usage examples:
3167 % ipcalc 10.0.0.28 255.255.255.0
3168 % ipcalc 10.0.0.0/24
3169 -- 
3170 Blacklist a kernel module:
3171
3172 # blacklist <name_of_kernel_module>
3173
3174 -> running 'blacklist hostap_cs' for example will generate an
3175 entry like this in /etc/modprobe.d/grml:
3176
3177 blacklist hostap_cs
3178 alias hostap_cs off
3179
3180 To remove the module from the blacklist again just invoke:
3181
3182 # unblacklist <name_of_kernel_module>
3183
3184 or manually remove the entry from /etc/modprobe.d/grml.
3185 -- 
3186 Create a Debian package of a perl module:
3187
3188 % dh-make-perl --cpan Acme::Smirch --build
3189 -- 
3190 The Magic SysRq Keys (SysReq or Sys Req, short for System Request):
3191
3192 To reboot your system using the SysRq keys just hold down the Alt and
3193 SysRq (Print Screen) key while pressing the keys REISUB ("Raising
3194 Elephants Is So Utterly Boring").
3195
3196 R = take the keyboard out of raw mode
3197 E = terminates all processes (except init)
3198 I = kills all processes (except init)
3199 S = synchronizes the disk(s)
3200 U = remounts all filesystems read-only
3201 B = reboot the system
3202
3203 Notice: use O instead of B for poweroff.
3204
3205 Or write the sequence to /proc/sysrq-trigger instead:
3206
3207 # for i in r e i s u b ; do echo $i > /proc/sysrq-trigger ; done
3208
3209 To enable or disable SysRq calls:
3210
3211 # echo 0 > /proc/sys/kernel/sysrq
3212 # echo 1 > /proc/sys/kernel/sysrq
3213
3214 See http://en.wikipedia.org/wiki/Magic_SysRq_key for more details.
3215
3216 Tags: reboot, documentation, sysrq, magic
3217 -- 
3218 Memtest / memcheck:
3219
3220 Just boot your grml Live-CD with "memtest" to execute a memcheck/memtest
3221 with Memtest86+.
3222 -- 
3223 Tunnel TCP-Traffic through DNS using dns2tcp:
3224
3225 Server-side:
3226 ~~~~~~~~~~~~
3227 1. Create necessary DNS-Records:
3228 dnstun.example.com.     3600    IN      NS      host.example.com.
3229 dnstun.example.com.     3600    IN      A       192.168.1.1
3230 host.example.com.       3600    IN      A       192.168.1.1
3231
3232 2. Configure dns2tcpd on host.example.com.:
3233 # cat /etc/dns2tcpd.conf 
3234 listen = 192.168.1.1          #the ip dns2tcpd should listen on
3235 port = 53                     #" port " " " "
3236 user = nobody
3237 chroot = /tmp
3238 domain = dnstun.example.com.  # the zone as specified inside dns
3239 ressources = ssh:127.0.0.1:22 # available resources
3240
3241 3. Start the daemon:
3242 # cat > /etc/default/dns2tcp << EOF
3243 # Set ENABLED to 1 if you want the init script to start dns2tcpd.
3244 ENABLED=1
3245 USER=nobody
3246 EOF
3247 # /etc/init.d/dns2tcp start
3248
3249 Client-side:
3250 ~~~~~~~~~~~~
3251 You have two possibilities:
3252 - Use the DNS inside your network (DNS must allow resolving for external domains)
3253 # grep nameserver /etc/resolv.conf 
3254 nameserver 172.16.42.1
3255 # dns2tcpc -z dnstun.example.com 172.16.42.1
3256 Available connection(s) : 
3257         ssh
3258 # dns2tcpc -r ssh -l 2222 -z dnstun.example.com 172.16.42.1 &
3259 Listening on port : 2222
3260 # ssh localhost -p 2222
3261 user@host.example.com:~#
3262
3263 - Directly contact the endpoint (port 53 UDP must be allowed outgoing)
3264 # dns2tcpc -z dnstun.example.com dnstun.example.com
3265 Available connection(s) : 
3266         ssh
3267 # dns2tcpc -r ssh -l 2222 -z dnstun.example.com dnstun.example.com &
3268 Listenning on port : 2222
3269 # ssh localhost -p 2222
3270 user@host.example.com:~#
3271
3272 Notice: using 'ssh -D 8080 ..' you will get a socks5-proxy listening on
3273 localhost:8080 which you can use to tunnel everything through your "dns-uplink".
3274
3275 Tags: howto, network, tunnel
3276 -- 
3277 Configure a MadWifi device for adhoc mode:
3278
3279 Disable the autocreation of athX devices:
3280 # echo "options ath_pci autocreate=none" > /etc/modprobe.d/madwifi
3281
3282 Remove the autocreated device for now:
3283 # wlanconfig ath0 destroy
3284
3285 Configuration in /etc/network/interfaces:
3286
3287 iface ath0 inet static
3288   madwifi-base wifi0
3289   madwifi-mode adhoc
3290   ...
3291
3292 Hints:
3293   - Do not use interface names without ending 0 (otherwise startup fails).
3294   - Only chooss unique names for interfaces.
3295 -- 
3296 Find dangling symlinks using zsh:
3297
3298 % ls **/*(-@)
3299 -- 
3300 Use approx with runit supervision
3301 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3302
3303 Install the packages:
3304 # apt-get install approx runit
3305
3306 Add user approxlog for the logging daemon:
3307 # adduser --system --home /nonexistent --no-create-home approxlog
3308
3309 Create config directory:
3310 # mkdir /etc/sv/approx
3311
3312 Use /var/run/sv.approx as supervise directory:
3313 # ln -s /var/run/sv.approx /etc/sv/approx/supervise
3314
3315 # cat > /etc/sv/approx/run << EOF
3316 #!/bin/sh
3317 echo 'approx starting'
3318 exec approx -f 2>&1
3319 EOF
3320
3321 You normally do not need a logging service for approx because it logs
3322 to syslog too. So just for completion:
3323 # mkdir -p /etc/sv/approx/log
3324 # ln -s /var/run/sv.approx.log /etc/sv/approx/log/supervise
3325 # cat > /etc/sv/approx/log/run << EOF
3326 #!/bin/sh
3327 set -e
3328 LOG="/var/log/approx"
3329 test -d "$LOG" || mkdir -p -m2750 "$LOG" && chown approxlog:adm "$LOG"
3330 exec chpst -uapproxlog svlogd -tt -v "$LOG"
3331 EOF
3332
3333 Now activate the new approx service (will be started within 5s):
3334 # ln -s /etc/sv/approx/ /var/service/
3335
3336 Make approx managed via runit available via init-script interface:
3337 # dpkg-divert --local --rename /etc/init.d/approx
3338 # ln -s /usr/bin/sv /etc/init.d/approx
3339 -- 
3340 Remote-reboot a grml system using SysRQ via /proc (execute as root):
3341
3342 eject &>/dev/null
3343 umount -l /cdrom
3344 eject /dev/cdrom
3345 echo b > /proc/sysrq-trigger
3346
3347 Tags: reboot, howto, grml, network
3348 -- 
3349 Show what happens on /dev/sda0:
3350
3351 # mount the debugfs to relay kernel info to userspace
3352 mount -t debugfs none /sys/kernel/debug
3353
3354 # is a convenient wrapper arround blktrace and blkparse
3355 btrace /dev/sda0
3356
3357 Tags: debug, block, partition, trace
3358 -- 
3359 Convert Flash to Avi:
3360
3361 % ffmpeg -i input.flv output.avi
3362
3363 Extract MP3 from Flash file:
3364
3365 % for i in *.flv; do ffmpeg -i $i -acodec copy ${i%.flv}.mp3 ; done
3366 -- 
3367 Usage example for cryptsetup / -luks encrypted partition on LVM:
3368
3369 volume group name:   x61
3370 logical volume name: home
3371
3372 echo "grml-crypt_home /dev/mapper/x61-home none luks" >> /etc/crypttab
3373 Start cryptdisks
3374 mount /dev/mapper/grml-crypt_home /mnt/test
3375 -- 
3376 fdisk/parted/... complains with something like
3377 'unable to open /dev/sda - unrecognised disk label'?!
3378
3379 See http://grml.org/faq/#fdisk =>
3380
3381 * use /sbin/fdisk.distrib from util-linux
3382 * switch to sfdisk, cfdisk,...
3383 * use parted's mklabel command (but please read the
3384   parted manual before executing this command)
3385 -- 
3386 dmraid - support for SW-RAID / FakeRAID controllers
3387 like Highpoint HPT and Promise FastTrack
3388
3389 Activate all software RAID sets discovered:
3390 # dmraid -ay
3391
3392 Deactivates all active software RAID sets:
3393 # dmraid  -an
3394
3395 Discover all software RAID devices supported on the system:
3396 # dmraid -r
3397 -- 
3398 Extract winmail.dat:
3399
3400 List content:
3401 % ytnef winmail.dat
3402
3403 Extract files to current directory:
3404 % ytnef -f . winmail.dat
3405 -- 
3406 Approx - Debian package proxy/cacher howto
3407
3408 % apt-get install approx
3409 % echo 'debian  http://ftp.de.debian.org/debian' >>/etc/approx/approx.conf
3410 % Restart approx
3411
3412 Add your new approx to sources.list
3413
3414 eg.
3415 deb http://localhost:9999/debian  unstable  main contrib non-free
3416
3417 use approx in grml-debootstrap like:
3418 % grml-debootstrap -r lenny -t /dev/sda1 -m http://127.0.0.1:9999/debian
3419 -- 
3420 Simple webserver with python:
3421
3422 % python -m SimpleHTTPServer
3423 -- 
3424 Upgrade only packages from the grml-stable Debian repository:
3425
3426 echo 'deb http://deb.grml.org/ grml-stable main' > /etc/apt/grml-stable.list
3427 apt-get -o Dir::Etc::sourcelist=/etc/apt/grml-stable.list -o Dir::Etc::sourceparts=/doesnotexist update
3428 apt-get upgrade
3429 -- 
3430 Install Centos into a directory:
3431
3432 % febootstrap centos-5 directory http://mirror.centos.org/centos-5/5.3/os/i386/
3433 -- 
3434 Install Fedora into a directory:
3435
3436 % febootstrap fedora-11 target_directory
3437 -- 
3438 Use Nessus / OpenVAS (remote network security auditor):
3439
3440 Install software packages:
3441 # apt-get update
3442 # apt-get install openvas-client openvas-server openvas-plugins-base openvas-plugins-dfsg
3443
3444 Add a user:
3445 # openvas-adduser
3446
3447 Start openvas server (takes a while):
3448 # Start openvas-server
3449
3450 Invoke client as user:
3451 % OpenVAS-Client
3452 -- 
3453 Find packages not available from any active apt repository:
3454
3455 % apt-show-versions | awk '/No available version in archive/{print $1}'
3456 -- 
3457 Simple mailserver with python:
3458
3459 % python -m smtpd -n -c DebuggingServer localhost:1025
3460 -- 
3461 finger via netcat:
3462
3463 echo $USER | nc $HOST 79
3464 -- 
3465 Install Archlinux using Grml:
3466
3467 https://wiki.archlinux.org/index.php/Install_from_Existing_Linux
3468 or
3469 wget http://tokland.googlecode.com/svn/trunk/archlinux/arch-bootstrap.sh
3470 -- 
3471 Export blockdevices via AoE (ATA over Ethernet):
3472
3473 % vblade -m 11:22:33:44:55:66 160 2 eth0 /dev/sdb1
3474
3475 Allow the host with the mac address 11:22:33:44:55:66 to access /dev/sdb1
3476 via eth0, using the shelf and slot numbers 160 and 2. These numbers are
3477 arbitrary but should be unique within the network.
3478
3479 A word of warning: AoE is prone to all kind of nasty ethernet attacks,
3480 especially arp spoofing. Do not use in hostile networks.
3481
3482 Tags: aoe, blockdevice, export, server
3483 -- 
3484 Access blockdevices via AoE (ATA over Ethernet):
3485
3486 % sudo aoe-discover
3487
3488 and the device should show up under /dev/etherd/. If your shelf and
3489 slot numbers re 160 and 2 the device will be /dev/etherd/e160.2
3490
3491 A word of warning: AoE is prone to all kind of nasty ethernet attacks,
3492 especially arp spoofing. Do not use in hostile networks.
3493
3494 Tags: aoe, blockdevice, export, client
3495 --