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