home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / HOWTO / OTHER_FO / SGML / TIPS_HOW.GZ / Tips-HOWTO.sgml
Encoding:
SGML Document  |  1996-08-18  |  17.1 KB  |  439 lines

  1. <!doctype linuxdoc system> 
  2.  
  3. <article>
  4.  
  5. <title>The Linux Tips HOWTO
  6. <author>Paul Anderson, <tt/panderso@ebtech.net/
  7. <date>v2.0, August 1996
  8. <abstract>
  9. This HOWTO contains those hard to find hints and tweekings that make Linux 
  10. a bit nicer.
  11. </abstract>
  12.  
  13. <toc>
  14.  
  15. <sect>Introduction
  16. <p>
  17. Welcome to the <bf/Linux Tips HOWTO/, a list of neato tricks and optimizations that make Linux more fun.  All I have in here right now are tips off of the top of my head, and tips from the old Tips-HOWTO(Why take out decent tips, right?).  So send all your favorite hints and tips to me so I can put them in the next Tips-HOWTO.
  18.  
  19. Paul Anderson <em/Maintainer--Linux TIPS HOWTO/
  20.  
  21. <tt/panderso@ebtech.net/
  22. <sect> Short Tips
  23.  
  24. <sect1> Handy Syslog Trick <it/Paul Anderson, Tips-HOWTO maintainer/
  25.  
  26. <p>
  27. Edit your /etc/syslog.conf, and put in the following line:
  28. <tscreen><verb>
  29. # Dump everything on tty8
  30. *.*                    /dev/tty8
  31. </verb></tscreen>
  32. One caveat: <it/REMEMBER TO USE TABS!/  syslog doesn't like spaces...
  33.   
  34. <sect1> Moving directories between filesystems. <it/Alan Cox,/ 
  35. <tt/A.Cox@swansea.ac.uk/
  36.  
  37. <p>
  38. Quick way to move an entire tree of files from one disk to another
  39. <tscreen><verb>
  40. (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xvfp -)
  41. </verb></tscreen>
  42. <it>[ Change from cd /source/directory; tar....etc.  to prevent possibility of trashing directory in case of disaster.  Thanks to Jim Dennis, jadestar@rahul.net, for letting me know. -Maint. ]</it>
  43.  
  44. <sect1> Finding out which directories are the largest. <it/Mick Ghazey,/
  45. <tt/mghazey@miso.lowdown.com/
  46.  
  47. <p>
  48. Ever wondered which directories are the biggest on your computer?  Here's how to find out.
  49. <tscreen><verb>
  50. du -S | sort -n
  51. </verb></tscreen>
  52.  
  53. <sect1> The Linux Gazette
  54.  
  55. <p>
  56. Kudos go to John Fisk, creator of the Linux Gazette.  This is an excellent 
  57. e-zine plus, it's <bf/FREE!!!/  Now what more could you ask?  Check it out at:
  58. <tscreen><verb>
  59. http://www.redhat.com/lg
  60. </verb></tscreen>
  61. While you're there, drop John Fisk a note telling him how wonderful an e-zine LG is.
  62.  
  63. <sect1> Pointer to patch for GNU Make 3.70 to change VPATH behavior.
  64. <it/Ted Stern,/ <tt/stern@amath.washington.edu/
  65.  
  66. <p>
  67. I don't know if many people have this problem, but there is a "feature" of GNU
  68. make version 3.70 that I don't like. It is that VPATH acts funny if you give it
  69. an absolute pathname.  There is an extremely solid patch that fixes this, which
  70. you can get from Paul D. Smith <tt><psmith@wellfleet.com></tt>.  He also posts the
  71. documentation and patch after every revision of GNU make on the newsgroup
  72. `gnu.utils.bug` Generally, I apply this patch and recompile gmake on every
  73. system I have access to.
  74.  
  75. <sect1> How do I stop my system from fscking on each reboot? <it/Dale Lutz,/ 
  76. <tt/dal@wimsey.com/
  77.  
  78. <p>
  79. Q:  How do I stop e2fsck from checking my disk every time I boot up.
  80.  
  81. A:  When you rebuild the kernel, the filesystem is marked as 'dirty' and
  82.     so your disk will be checked with each boot.  The fix is to run:
  83.  
  84.         rdev -R /zImage 1
  85.  
  86.     This fixes the kernel so that it is no longer convinced that the 
  87.     filesystem is dirty.
  88.  
  89. <em/Note: If using lilo, then add /<tt/read-only/ <em>to your linux setup in your lilo config file (Usually /etc/lilo.conf) </em>
  90.  
  91. <sect1>How to avoid fscks caused by "device busy" at reboot time. 
  92. <it/Jon Tombs,/ <tt/jon@gtex02.us.es/
  93.  
  94. <p>
  95. If you often get device busy errors on shutdown that leave the filesystem in
  96. need of an fsck upon reboot, here is a simple fix:
  97.  
  98. To <tt>/etc/brc</tt> or <tt>/sbin/brc</tt>, add the line
  99. <tscreen><verb>
  100. mount -o remount,ro /mount.dir
  101. </verb></tscreen>
  102. for all your mounted filesystems except /, before the call to umount -a. This
  103. means if, for some reason, shutdown fails to kill all processes and umount the
  104. disks they will still be clean on reboot. Saves a lot of time at reboot for
  105. me
  106.  
  107.  
  108.  
  109. <sect1>How to find the biggest files on your hard-drive.
  110. <p><it/Simon Amor,/ <tt/simon@foobar.co.uk/
  111. <p>
  112. <tscreen><verb>
  113. ls -l | sort +4n
  114. </verb></tscreen>
  115. <p>
  116. Or, for those of you really scrunched for space this takes awhile but works 
  117. great:
  118. <p>
  119. <tscreen><verb>
  120. cd /
  121. ls -lR | sort +4n
  122. </verb></tscreen>
  123.  
  124. <sect1>How to print pages with a margin for hole punching. <it/Mike Dickey,/ 
  125. <tt/mdickey@thorplus.lib.purdue.edu/
  126.  
  127. <p>
  128. <tscreen><code>
  129.         #!/bin/sh
  130.         # /usr/local/bin/print
  131.         # a simple formatted printout, to enable someone to
  132.         # 3-hole punch the output and put it in a binder
  133.  
  134.         cat $1 | pr -t -o 5 -w 85 | lpr
  135. </code></tscreen>
  136.  
  137. <sect1>A way to search through trees of files for a particular regular expression.
  138. <it/Raul Deluth Miller,/ <tt/rockwell@nova.umd.edu/
  139.  
  140. <p>
  141. I call this script 'forall'.  Use it like this:
  142. <tscreen><verb>
  143. forall /usr/include grep -i ioctl
  144. forall /usr/man grep ioctl
  145. </verb></tscreen>
  146. Here's forall:
  147. <tscreen><code>
  148. #!/bin/sh
  149. if [ 1 = `expr 2 \> $#` ]
  150. then
  151.         echo Usage: $0 dir cmd [optargs]
  152.         exit 1
  153. fi
  154. dir=$1
  155. shift
  156. find $dir -type f -print | xargs "$@"
  157. </code></tscreen>
  158.  
  159. <sect1>A script for cleaning up after programs that creat autosave and backup files.
  160. <it/Barry Tolnas,/ <tt/tolnas@nestor.engr.utk.edu/
  161. <p>
  162. Here is a simple two-liner which recursively descends a
  163. directory hierarchy removing emacs auto-save (~) and backup (#) files, .o 
  164. files, and  TeX .log files. It also compresses .tex files and
  165. README files. I call it 'squeeze' on my system.
  166. <tscreen><code>
  167. #!/bin/sh
  168. #SQUEEZE removes unnecessary files and compresses .tex and README files
  169. #By Barry tolnas, tolnas@sun1.engr.utk.edu
  170. #
  171. echo squeezing $PWD
  172. find  $PWD \( -name \*~ -or -name \*.o -or -name \*.log -or -name \*\#\) -exec
  173. rm -f {} \;
  174. find $PWD \( -name \*.tex -or -name \*README\* -or -name \*readme\* \) -exec gzip -9 {} \;
  175. </code></tscreen>
  176.  
  177. <sect1>How to find out what process is eating the most memory. <it/Simon Amor,/
  178. <tt/simon@foobar.co.uk/
  179. <p>
  180. <tscreen><verb>
  181. ps -aux | sort +4n
  182. </verb></tscreen>
  183. -OR-
  184. <tscreen><verb>
  185. ps -aux | sort +5n
  186. </verb></tscreen>
  187.  
  188. <sect> Detailed Tips
  189.  
  190. <sect1>Sharing swap partitions between Linux and Windows. <it/Tony Acero,/ 
  191. <tt/ace3@midway.uchicago.edu/
  192.  
  193. <p><enum>
  194. <item> Format the partition as a dos partition, and create the Windows
  195. swap file on it, but don't run windows yet. (You want to keep the swap
  196. file completely empty for now, so that it compresses well).
  197.  
  198. <item> Boot linux and save the partition into a file.  For example if the partition was /dev/hda8:
  199. <tscreen><verb>
  200. dd if=/dev/hda8 of=/etc/dosswap
  201. </verb></tscreen>
  202. <item> Compress the dosswap file; since it is virtually all 0's it will compress very well
  203. <tscreen><verb>
  204. gzip -9 /etc/dosswap
  205. </verb></tscreen>
  206. <item> Add the following to the /etc/rc file to prepare and install the swap space under Linux:
  207.  
  208. <em/XXXXX is the number of blocks in the swap partition/
  209. <tscreen><verb>
  210. mkswap /dev/hda8 XXXXX
  211. swapon -av   
  212. </verb></tscreen>
  213. Make sure you add an entry for the swap partition in your /etc/fstab file
  214.  
  215. <item> If your init/reboot package supports /etc/brc or /sbin/brc add the
  216. following to /etc/brc, else do this by hand when you want to boot to
  217. dos|os/2 and you want to convert the swap partition back to the
  218. dos/windows version:
  219. </enum>
  220. <tscreen><verb>
  221. swapoff -av
  222. zcat /etc/dosswap.gz | dd of=/dev/hda8 bs=1k count=100
  223. </verb></tscreen>
  224. # Note that this only writes the first 100 blocks back to the partition. I've found empirically that this is sufficient 
  225.  
  226. >
  227. >  What are the pros and cons of doing this?
  228.  
  229. Pros: you save a substantial amount of disk space.
  230.  
  231. Cons: if step 5 is not automatic, you have to remember to do it by hand,
  232. and it slows the reboot process by a nanosecond :-)
  233.  
  234. <sect1>How to use the immutable flag. 
  235. <it/Jim Dennis,/ <tt/jadestar@rahul.net/
  236.  
  237. <p>
  238.                 Use the Immutable Flag
  239.  
  240.         Right after you install and configure your system
  241.         go through the /bin, /sbin/, /usr/bin, /usr/sbin and
  242.         /usr/lib (and a few of the other usual suspects and
  243.         make liberal use of the 'chattr +i command'.  Also add that
  244.         to the the kernel files in root.  Now 'mkdir /etc/.dist/'
  245.         copy everything from /etc/ on down (I do this in two steps
  246.         using /tmp/etcdist.tar to avoid recursion) into that directory.
  247.         (Optionally you can just create /etc/.dist.tar.gz) -- and
  248.         mark that as immutable.
  249.  
  250.         The reason for all of this is to limit the damage that you can
  251.         do when logged in as root.  You won't overwrite files with a
  252.         stray redirection operator, and you won't make the system
  253.         unusable with a stray space in an 'rm -fr' command (you might
  254.         still do alot of damage to your data -- but your libs and
  255.         bins will be safer.
  256.  
  257.         This also makes a variety of security and denial of service
  258.         exploits either impossible or more difficult (since many of
  259.         them rely on overwriting a file through the actions of some
  260.         SUID program that *isn't providing an arbitrary shell command*).
  261.  
  262.         The only inconvenience of this is when building and
  263.         doing your 'make install' on various sorts of system binaries.
  264.         On the other hand it also prevents the 'make install' from
  265.         over-writing the files.  When you forget to read the Makefile
  266.         and chattr -i the files that are to be overwritten (and the
  267.         directories to which you want to add files) -- the make fails,
  268.         you just use the chattr command and rerun it.  You can also
  269.         take that opportunity to move your old bin's, libs, or whatever
  270.         into a .old/ directory or rename or tar them or whatever.
  271.  
  272. <sect1>A suggestion for where to put new stuff.
  273. <it/Jim Dennis,/ <tt/jadestar@rahul.net/
  274.  
  275. <p>
  276.         All new stuff starts under /usr/local! or /usr/local/`hostname`
  277.  
  278.         If your distribution is one that leaves /usr/local empty
  279.         then just create your /usr/local/src, /usr/local/bin etc
  280.         and use that.  If your distribution puts things in the /usr/local
  281.         tree than you may want to 'mkdir /usr/local/`hostname`' and
  282.         give the 'wheel' group +w to it (I also make it SUID and SGID
  283.         to insure that each member of the wheel group can only mess with
  284.         their own files thereunder, and that all files created will
  285.         belong to the 'wheel' group.
  286.  
  287.         Now discipline yourself to *ALWAYS! ALWAYS! ALWAYS!* put new
  288.         packages under /usr/local/src/.from/$WHEREVER_I_GOT_IT/
  289.         (for the .tar or whatever files) and build them  under
  290.         /usr/local/src (or .../$HOSTNAME/src).  Make sure that it
  291.         installs under the local hierarchy.  If it *absolutely must*
  292.         be installed back in /bin or /usr/bin or somewhere else --
  293.         put a symlink from the local heirarchy to each element that
  294.         when anywhere else.
  295.  
  296.         The reason for this -- even though it's more work -- is that
  297.         it helps isolate what has to be backed up and restored or
  298.         reinstalled in the event of a full re-install from the
  299.         distribution medio (usually CD these days).  By using a
  300.         /usr/local/.from directory you also keep an informal log
  301.         of where your sources are coming from -- which helps when
  302.         you're looking for new updates -- and may be critical when
  303.         monitoring the security announcement lists.
  304.  
  305.         One of my systems at home (the one I'm calling from)
  306.         was put together before I adopted these policies for myself.
  307.         I still don't "know" all the ways that it differs from the
  308.         stock "as installed" system.  This is despite the fact that
  309.         I've done very little with my home system's configuration
  310.         and I'm the *only* person who ever uses it.
  311.  
  312.         By contrast the systems I've set up at work (when I was thrust
  313.         into the role of system administrator there) have all been
  314.         configured this way -- have been administered by many
  315.         contractors and other MIS people, and have had a large number
  316.         of upgrades and package installations.  Nonetheless I have a
  317.         very good idea which precise elements were put in *after*
  318.         the initial installation and configuration.
  319.         distribution medio (usually CD these days).  By using a
  320.         /usr/local/.from directory you also keep an informal log
  321.         of where your sources are coming from -- which helps when
  322.         you're looking for new updates -- and may be critical when
  323.         monitoring the security announcement lists.
  324.  
  325.         One of my systems at home (the one I'm calling from)
  326.         was put together before I adopted these policies for myself.
  327.         I still don't "know" all the ways that it differs from the
  328.         stock "as installed" system.  This is despite the fact that
  329.         I've done very little with my home system's configuration
  330.         and I'm the *only* person who ever uses it.
  331.  
  332.         By contrast the systems I've set up at work (when I was thrust
  333.         into the role of system administrator there) have all been
  334.         configured this way -- have been administered by many
  335.         contractors and other MIS people, and have had a large number
  336.         of upgrades and package installations.  Nonetheless I have a
  337.         very good idea which precise elements were put in *after*
  338.         the initial installation and configuration.
  339.  
  340. <sect1>Some tips for new sysadmins.
  341. <it/Jim Dennis,/ <tt/jadestar@rahul.net/
  342.  
  343. <p>
  344.         Create and maintain a /README.`hostname` and/or a
  345.         /etc/README.`hostname`
  346. <em>[Or possibly /usr/local/etc/README.`hostname` -Maint. ]</em>
  347.  
  348.         Absolutely, from *day one* of administering a system
  349.         take notes in an online log file.  You might make
  350.         `vi /README.$(hostname)` a line in root's ~/bash_logout.
  351.         Another way to do this is to write an su or a sudo script
  352.         that does something like:
  353. <tscreen><verb>
  354.                 function exit \
  355.                         { unset exit; exit; \
  356.                           cat ~/tmp/session.$(date +%y%m%d) \
  357.                           >> /README.$(hostname) && \
  358.                           vi /README.$(hostname)
  359.                           }
  360.                 script -a ~/tmp/session.$(date +%y%m%d)
  361.                 /bin/su.org -
  362. </verb></tscreen>
  363.  
  364.         (use the typescript command to create a session log
  365.         and create a function to automate appending and updating
  366.         the log).
  367.  
  368.         I'll admit that I haven't implemented this automation of
  369.         policy -- I've just relied on self-discipline so far.
  370.         However I have been toying with the idea (even to the
  371.         point of prototyping the scripts and shell functions as you
  372.         see them).  One thing that holds me back on this is
  373.         the 'script' command itself.  I think I'll have to grab the
  374.         sources and add a couple of command line parameters (to
  375.         pause/stop the script recording from the command line) before
  376.         I commit to using this).
  377.  
  378.         My last suggestion (for this round):
  379.  
  380.         Root's path should consist of 'PATH=~/bin'
  381.  
  382.         That's it.  Nothing else on root's path.  Everything root
  383.         does is provided by a symlink from ~/bin or by an alias or
  384.         shell function, or is a script or binary in ~/bin, or is
  385.         typed out with an explicit path.
  386.  
  387.         This makes anyone running as root aware (sometimes painfully
  388.         so) of how he or she is trusting binaries.  The wise admin
  389.         of a multi-user host will periodically look through his or
  390.         here ~/bin and ~/.*history files to look for patterns and
  391.         loopholes.
  392.  
  393.         The really motivated admin will spot sequences
  394.         that can be automated, places where sanity checks can be
  395.         inserted, and tasks for which 'root' privileges should be
  396.         temporarily eschewed (launching editors, MTA's and other
  397.         large interactive programs with elaborate scripting features
  398.         that *might* be embedded in transparent or data files --
  399.         like the infamous vi ./.exrc and emacs ./.emacs and the
  400.         even more insidous $EXINIT and the embedded header/footer
  401.         macros).  Naturally those sorts of commands can be run
  402.         with something like:
  403. <tscreen><verb>
  404.                 cp $data $some_users_home/tmp
  405.                 su -c $origcommand $whatever_switches
  406.                 cp $some_users_home/tmp $data
  407. </verb></tscreen>
  408.         (...where the specifics depend on the command).
  409.  
  410.         Mostly these last sorts of precautions are overboard for the
  411.         home or "single" user workstation -- but they are very good
  412.         policy the admin of a multi-user -- particular a publicly
  413.         exposed system (like the one's at netcom).
  414.  
  415.  
  416. <sect1>How to configure xdm's chooser for host selection. 
  417. <it/Arrigo Triulzi,/ <tt/a.triulzi@ic.ac.uk/
  418.  
  419. <p><enum>
  420. <item> Edit the file that launches xdm 
  421. most likely /etc/rc/rc.6 or /etc/rc.local) so that it contains the
  422. following lines in the xdm startup section.<tscreen><verb>        
  423. /usr/bin/X11/xdm
  424. exec /usr/bin/X11/X -indirect hostname
  425. </verb></tscreen>
  426. <item> Edit /usr/lib/X11/xdm/Xservers and comment out the line which
  427. starts the server on the local machine [i.e. starting 0:]
  428.  
  429. <item> Reboot the machine and you're home and away.
  430. </enum>
  431. <p>
  432. I add this because when I was, desperately, trying to set it up for
  433. my own subnet over here it took me about a week to suss out all the
  434. problems.
  435.  
  436. Caveat: with old SLS (1.1.1) for some reason you can leave a -nodaemon
  437. after the xdm line -- this does <bf/NOT/ work for later releases.
  438. </article>
  439.