Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > by-pkgid > 965e33040dd61030a94f0eb89877aee8 > files > 5829

howto-html-en-20080722-2mdv2010.1.noarch.rpm

<HTML>
<HEAD>
<TITLE>Small Memory mini-HOWTO</TITLE>
</HEAD>
<BODY>
<CENTER>
<H1>Small Memory Mini-HOWTO v0.1</H1>
<H1>by: Todd Burgess</H1>
<H1>tburgess@uoguelph.ca</H1>
</CENTER>

<H2>Introduction</H2>

The purpose of this mini HOWTO is to describe how to run Linux on a
system with a small amount of memory. Assuming buying more memory is out
of the question there are many things you can do to tighten up memory 
usage in Linux.
<P>
Many Linux distributions out of the box are quite bloated from a memory
perspective. They run more services and offer more features then most of
us will ever need. By removing many of these services you can free up
several megabytes of real memory.
<P>
My own system is a 486DX2-66 with 12MB of physical memory and 12MB of
swap space. It has run Linux for the last 3 years quite happily and
hopefully it will run Linux for several more years. :)

<H2>Linux Kernel</H2>

All the Linux kernels which come with distributions are quite bloated
and contain more features then any of us will ever need or use. If you
have not re-compiled your own kernel it is highly recommended that you
do so. How to re-compile a kernel is beyond the scope of this document
but many excellent Linux books and guides cover this subject in intimate
detail.
<P>
If you do re-compile your kernel remember to put in no more features
then you need. For instance: how many of you include PLIP support in
your kernel? How many of you who include it actually use it? Smaller
kernels require less time to load, use less memory and use less CPU
cycles.
<P>
Another thing is modules. I personally do not use them because I found
them to be a cumbersome. If you use them and like them then they can
help to relieve "kernel bloat."

<H2>Virtual Consoles</H2>

VCs are a great way to free up memory. Most Linux distributions run
about 6 of them out of the box. On average running 6 VCs requires about
4MB of memory. Removing a couple of them can free up a couple MBs of
memory.
<P>
Most of users can get away running only 3 or 4 VCs. How many you choose
to remove is a matter personal preference. Just remember that the fewer
you run the more memory your applications will have to run.
<P>
The file which outlines how many VCs get loaded is in the file
/etc/inittab . In order to remove VCs:
<P>
<OL>
<LI>Load /etc/inittab in a text editor
<LI>Look for a line which looks like (the key feature being a line which
   starts with c1):
   <BR>
   c1:12345:respawn:/sbin/getty tty1 38400 linux
   <BR>
   Start at the highest number (ie c6) and comment it out by inserting a '#'
   in the first row. Repeat this step as many times as needed. 
   Remember every line you comment out is one less VC running.
<LI>Re-boot the system for your changes to take effect.
</OL>

<H2>Daemons</H2>

Many Linux distributions run many daemons most of us will never use. Most
of these daemons are loaded by scripts. Where these scripts are and
what they are called depends on your Linux distribution. Slackware 
set-up scripts are buried in /etc/rc.d/rc.* . 
<P>
Before you proceed a knowledge of Unix shell script programming would be
a definite asset. If however you have no experience writing Unix shell
scripts what follows is probably the quickest introduction to shell 
script programming ever written. 
<P>
Take the following shell script 
<XMP>
#!/bin/sh
echo "hello world"
#echo "good bye cruel world"
</XMP>
<P>
The following will echo the string "hello world". Shell scripts must 
contain the the line "#!/bin/sh" at the very top line. After that 
every line is executed as if you had typed it at the keyboard (think
of shell scripts as nothing more then glorified keyboard macros). 
<P>
Lines which begin with a '#' are said to be commented out because they 
do not get executed by the shell. Most start up scripts when they 
load daemons look like:
<P>
<XMP>
if somecondition
  do something 
fi
</XMP>

What you want to do is comment out every line starting with the if
statement and ending with the fi statement. 
<P>
If you want to find where a daemon is loaded what you want to do is
search the start up scripts for the name of the daemon. If I 
wanted to find where inetd is loaded in Slackware I would do the
following:
<XMP>
     1	cd /etc/rc.d
     2	grep -n inetd rc.*
</XMP>

<H3>inetd</H3>

inetd allows people to do things like telnet, ftp and send talk requests
to your machine. If you never use your system as a server or need to
access any of its services remotely you can remove inetd.

<H3>lpd</H3>

lpd is used to print files on your printer using the lpr command. If you 
never print on your Linux box you can remove lpd. If however you own
a HP Deskjet printer and would like to print I highly recommend the
package I put together called dj-printcap which is available at:
<A HREF="ftp://sunsite.unc.edu/pub/Linux/system/Printing/dj-printcap.tar.gz">
ftp://sunsite.unc.edu/pub/Linux/system/Printing/dj-printcap.tar.gz</A>

<H3>nfsd and mountd</H3>

These two daemons are used to run a NFS server. If you never use 
your Linux system as a NFS server you can safely remove these two
daemons.

<H3>portmap</H3>

The portmap daemon is used to handle RPC services. If you do not run
a NFS server or any other RPC programs you can remove portmap.

<H3>sendmail</H3>

sendmail is another daemon which requires a fair bit of memory. If
you never use your Linux box as a relay for sending e-mail or 
you never receive mail on your Linux box you can probably 
remove sendmail. If you do send e-mail from your Linux box most
e-mail clients can be set-up to send e-mail from another mail 
server.

<H3>others</H3>

There may be other daemons your system starts up which you do 
not need. Remove what you feel you have to. Two daemons which
you must run are syslogd and klogd.

<H2>Conclusions</H2>

The following illustrates the steps I took to tighten up my 
memory usage on my Linux box. Hopefully I have provided 
you with some insight into what you can do with your Linux
box to conserve memory.
<P>
Good luck and happy hacking!<BR>
Todd Burgess<BR>
<A HREF="mailto:tburgess@uoguelph.ca">tburgess@uoguelph.ca</A><BR>
<A HREF="http://eddie.cis.uoguelph.ca/~tburgess">
http://eddie.cis.uoguelph.ca/~tburgess</A>

</BODY>
</HTML>