China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-25 17:21
中国DOS联盟论坛 » 其它操作系统综合讨论区 » Linux System Optimization and Fine-Tuning [repost] View 1,277 Replies 0
Original Poster Posted 2003-04-16 00:00 ·  中国 广东 河源 电信
高级用户
★★
PCDOS
Credits 912
Posts 217
Joined 2002-10-17 00:00
23-year member
UID 11
Gender Male
From 广东
Status Offline
Linux system optimization and fine-tuning
Optimization work for a system needs to use different methods according to different systems. This article aims to describe some general ways to optimize Linux.

1. Compilation options


When we use -O9 to compile a program, perhaps the file size in bytes is the largest, but often its running speed is also the fastest.

According to different machine architectures, you can add the following statements to /etc/profile .


i686:


export CFLAGS=-O9 -funroll-loops -ffast-math -malign-double -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions


i586:

export CFLAGS=-O3 -march=pentium -mcpu=pentium -ffast-math -funroll-loops -fomit-frame-pointer -fforce-mem -fforce-addr -malign-double -fno-exceptions


i486:

FLAGS=-O3 -funroll-all-loops -malign-double -mcpu=i486 -march=i486 -fomit-frame-pointer -fno-exceptions


Also, when installing programs, using tarball format is always better than RPM format, because tarball needs to be recompiled, and can be optimized for your machine architecture to get the best performance. This is probably also why the download center on this site provides everything in .tar.gz format!


2. Recompile the kernel

The Linux versions released by general Linux distributors always have some things in the kernel that are not very practical for you, such as support for HAM Radio, support for Token Ring, and so on.


If you feel a bit timid about compiling it yourself, you can check the materials on the following two websites:


Linux Kernel Howto: www.linuxdoc.org/HOWTO/Kernel-HOWTO.html


Linux Kernel : www.kernel.org


After three failed compilations, you should be able to successfully compile the kernel you need. "Failure is the mother of success"!
3. Stop services you do not use

Sendmail, httpd, crond, kudzu, mysql, portmap, postgresql, smb, snortd, webmin, inetd (or xinetd), etc. are all great programs, but if you do not use them, why let them occupy your precious resources? Also, these programs all bring security risks. Generally speaking, a "clean" Linux system only needs gpm, network, syslog, ssh, and xfs. If there is a temporary need, just start them manually. These startup scripts are generally all in the /etc/rc.d/init.d directory.


To check the services in use on your machine, you can use the nmap tool to scan.


$ nmap -p1-65535 211.94.129.28

Starting nmap V. 2.54BETA30 ( www.insecure.org/nmap/ )

Interesting ports on freelamp.com (211.94.129.28):

(The 65492 ports scanned but not shown below are in state: closed)

---Edited version of the output due to space considerations--

Port State Service

...

514/tcp open shell

1025/tcp open listen

1099/tcp open unknown

1214/tcp open unknown

...


To check the program name running on a specific port, you can use:


# netstat -anp|more


Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

....

tcp 0 0 203.199.66.200:8007 203.199.66.197:1060 CLOSE 1005/java

tcp 0 0 203.199.66.200:22 203.199.66.197:3768 ESTABLISHED 1381/sshd

tcp 0 0 203.199.66.200:23 192.168.57.46:1546 ESTABLISHED 1229/in.telnetd: 19

....


The last column shows the running program and its PID.


We can also use the ps command to check the daemon programs currently running on the machine:


# ps xc -u 0

PID TTY STAT TIME COMMAND

...

1475 ? S 0:02 sendmail

1498 ? S 0:04 gpm

16539 ? S 0:01 httpd

...


4. Plan your file system well

Before installing the system, you need to make a proper plan for the hard disk. Dividing out certain file systems is not only required by the system itself, but is also very meaningful from the security standpoint. Generally we need /, /usr, /var, /tmp , /home and swap. Also, making / and /usr a bit larger is very necessary. If your machine provides mail service for others, or offers personal homepages and similar services, then a very large /home is extremely important. If your business is good enough, you can even buy a second hard disk and create /home2 .

Also, putting the swap partition on the outermost part of the hard disk can improve read/write speed. If there are multiple hard disks, you can create a swap partition on each hard disk. In addition, it is recommended that the size of the swap partition be twice the physical memory.

If you use an IDE hard disk, you can use

/sbin/hdparm -c1 -d1 -m16 /dev/hda

to improve hard disk performance.

New versions of Linux all support journaling file systems. This kind of file system not only provides quick recovery of file integrity, but also has much better read/write speed than the ordinary ext2 file system.


For many people, the last access time of a file is of no use at all, so we can turn off the operating system's function of recording the last access time of files by modifying: /etc/fstab :


Change dev/hda6 /home ext2 defaults 1 2


to:


/dev/hda6 /home ext2 defaults,noatime 1 2

5. Turn off software related to X

If you are like me and do not like working in a window environment, then what do you need X for? Let us make the default interface after booting into Console:

Modify: /etc/inittab and change


id:5:initdefault:

to:

id:3:initdefault:


No browser anymore? No problem, you can use lynx under Console to browse websites.

links is also a pretty good browser, you can get it from


artax.karlin.mff.cuni.cz/ mikulas/links/


download it.


6. Turn off extra virtual consoles

We know that to switch from the console to the X window, we generally use Alt-F7 . Why? Because the system defines 6 virtual consoles by default, so X becomes the seventh. In fact, many people generally will not need so many virtual consoles. Modify

/etc/inittab and comment out those you do not need.


# Run gettys in standard runlevels

1:2345:respawn:/sbin/mingetty tty1

2:2345:respawn:/sbin/mingetty tty2

3:2345:respawn:/sbin/mingetty tty3

4:2345:respawn:/sbin/mingetty tty4

#5:2345:respawn:/sbin/mingetty tty5

#6:2345:respawn:/sbin/mingetty tty6




Conclusion:

The philosophy of system optimization can simply be summed up in four words: "less is more"; run only the services you need, use the right applications to complete tasks, use the command line, and only after you have fully streamlined your system can your system performance be fully brought out. My wish is to completely recompile all the programs in my system. :- ) In fact, most of the programs in FreeLAMP.com are "masterpieces" after I recompiled them.
我完全同意设想建立DOS组织“DOS联盟” ,也就是说和Wengier、以及“起步”站长莫老师等DOS战友一起来建立这个“DOS联盟”,以发展我国自主OS(操作系统)的高度去完成我们共同的愿望。
------党委书记
Forum Jump: