home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / HOWTO / TIPS_HOW.GZ / TIPS_HOW
Encoding:
Text File  |  1996-08-18  |  16.1 KB  |  406 lines

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