Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Beginning Ubuntu Linux - From Novice To Professional (2006)

.pdf
Скачиваний:
71
Добавлен:
17.08.2013
Размер:
25.54 Mб
Скачать

448

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

Figure 31-3. Remove the X from the check box alongside any service you would like to disable.

Table 31-1 lists the various run-level services, along with a short description of what they do and whether it’s safe for you to disable them. Only remove the check from the boxes of services you wish to deactivate! Don’t disable any services that you think should be running or otherwise interfere with the run-level settings. There’s a very real risk you will damage your setup by doing so. Limit your changes to the services you specifically want to remove.

Note SysV Runlevel Config truncates the names of some services in the left hand column. In Table 31-1, I’ve listed the services as stated by the program, and then continued the full name within square brackets for clarity.

Table 31-1. Ubuntu Run Level Services

Service

Description

acpi-supp[ort]

Required for proper running of the Advanced Configuration and

 

Power Interface (ACPI). It’s vital to the correction functioning of

 

Ubuntu, so don’t disable it unless your computer uses the alternative

 

Advanced Power Management (APM) system (see the apmd service).

 

All modern computers use ACPI.

acpid

Also required for ACPI. Don’t disable it.

alsa

At one time, this started the sound hardware, but it is no longer

 

used. It’s disabled by default in all run levels.

alsa-utils

Controls the volume of the system on startup. Don’t disable it.

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

449

Table 31-1. Ubuntu Run Level Services (Continued)

Service

Description

anacron

Runs scheduled tasks, as described in Chapter 33. It allows the running

 

of housekeeping tasks, so you shouldn’t disable it (although it’s not

 

essential to the running of Ubuntu).

apmd

Activates the Advanced Power Management (APM) function.

 

Nowadays, APM has been superseded by ACPI, so if you’re sure

 

your computer uses ACPI, you can disable this service.

atd

Scheduling service, as discussed in Chapter 33. If you don’t use the

 

at command, you can disable this.

bluez-uti[ls]

Required for the correct functioning of Bluetooth hardware (mobile

 

phones, wireless headphones, and so on). If you don’t use Bluetooth,

 

you can disable this.

bootlogd

Logs boot messages. If you’re sure you’ll never, ever examine the

 

boot log, as is sometimes necessary when problem solving, you can

 

disable this service.

cron

Another scheduling service, as discussed in Chapter 33. Many

 

housekeeping tasks are run via cron, so this should not be disabled

 

(although it’s not essential to the running of Ubuntu).

cupsys

Part of the printing subsystem. If you don’t use a printer, either

 

attached directly or across a network, this can be disabled.

dbus

Allows software to communicate with other software. It’s vital, so

 

don’t disable it.

dns-clean

Part of the ppp subsystem that’s designed to facilitate modem network

 

connections. If you use a modem of any type, don’t disable this. If

 

you use an Ethernet or wireless connection, it can be disabled.

evms

Controls the Enterprise Volume Management Subsystem, which is

 

used to manage multiple disk setups. If your computer doesn’t use

 

RAID or any other kind of logical partitioning scheme, you can

 

disable this. If your computer has only one hard disk, you can defi-

 

nitely disable this service.

fetchmail

System service that can collect mail from remote mail servers for

 

local delivery. It can be disabled on most systems, unless your mail

 

client specifically uses it. The default e-mail client under Ubuntu,

 

Evolution, doesn’t use fetchmail.

gdm

Starts the GNOME desktop subsystem and therefore the X server.

 

Don’t disable this, unless you want a command-prompt-only run level.

halt

Used to shut down the system. Don’t disable this service.

hdparm

Runs the hdparm.conf script, which allows you to optimize your hard

 

disk settings. Don’t disable this.

hotkey-se[tup]

Configures various additional keys on some notebook computers,

 

such as those that allow the dimming of the screen. You can disable

 

this, unless you’re using a notebook computer.

hotplug

Controls systems such as USB and PCMCIA that allow hardware to

 

be inserted when the computer is switched on. Also controls some

 

sound devices. Don’t disable this.

450 C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

Table 31-1. Ubuntu Run Level Services (Continued)

Service

Description

hotplug-n[et]

Works like hotplug. Don’t disable it.

hplip

Subsystem for Hewlett Packard (HP) scanners and/or printers. If you

 

don’t use an HP scanner or printer, you can disable this.

ifrename

Part of the networking subsystem that allows the renaming of network

 

devices. Unless you’re running a complicated server system, this can

 

be safely disabled. If you find your network connection doesn’t work

 

afterwards, enable it.

ifupdown

Part of the network subsystem. Don’t disable it.

ifupdown-[clean]

Part of the network subsystem. Don’t disable it.

klogd

Logs kernel messages. This is handy for problem solving, but this

 

service can be disabled if you’re absolutely sure you’ll never need it.

linux-res[tricted-

Handles the loading of closed-source kernel modules, such as some

modules-common]

wireless card and graphics card drivers. Unless you’re sure you don’t

 

use such drivers, don’t disable this service.

lvm

Controls the Logical Volume Management (LVM) subsystem. If your

 

system doesn’t use RAID or any other kind of LVM system, this service

 

can be disabled.

makedev

Controls the /dev hardware subsystem. Don’t disable it.

mdadm

Controls the software RAID setup. Disable it if you don’t use

 

software RAID.

mdadm-raid

Controls the software RAID setup. Disable it if you don’t use

 

software RAID.

module-in[it-tools]

Loads additional kernel module(s). Don’t disable it.

mountvirt[fs]

Mounts virtual file systems that are essential to Ubuntu. Don’t

 

disable it.

networking

Manages network interfaces. Don’t disable it.

ntpdate

Synchronizes time with the Ubuntu time servers. You can disable

 

this, unless your PC’s system clock is faulty and loses/gains time.

pcmcia

Starts PCMCIA devices on notebooks. You can disable this if you use

 

a desktop computer, unless you have a PCI-based wireless card (or

 

similar) that uses a PCMCIA card.

powernowd

Controls the CPU frequency scaling service that’s common on many

 

notebook and desktop computers. This can be disabled if absolutely

 

necessary, but it’s a good thing to have around.

ppp

Controls PPP connections, such as those established by modems

 

(both dial-up and DSL/cable). If you don’t use a modem, you can

 

disable this.

pppd-dns

Controls PPP connections. You can disable it if you don’t use a modem.

readahead

Optimization software designed to store commonly used libraries in

 

memory. It’s designed to speed up your system, but many people

 

report it makes little difference, so it can be disabled.

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

451

Table 31-1. Ubuntu Run Level Services (Continued)

Service

Description

reboot

Responsible for rebooting the system. Don’t adjust this setting.

rmnologin

Script that removes a system script that prevents nonroot users from

 

logging in during startup. Don’t disable it.

rsync

Controls the rsync service that allows the efficient transfer of files

 

between computers. This can be disabled.

screen-cl[eanup]

Takes care of some bootup housework. Don’t disable it.

sendsigs

Kills processes during shutdown and rebooting. Don’t disable it.

single

Runs scripts specific to the correct function of run level 1 (single-

 

user mode). Don’t alter this setting.

stop-boot[logd]

Related to bootlogd and can be disabled if bootlogd is.

sudo

Security feature to ensure the grace period that sudo allows before it

 

once again asks for your password. This can be disabled, although

 

the security conscious may like to leave it active.

sysklogd

Starts the system logging service. As with klogd, it can be disabled if

 

you do not wish to enable system logging.

udev

Part of the hardware subsystem. Don’t disable it.

udev-mtab

Part of the hardware subsystem. Don’t disable it

umountfs

Unmounts file systems at reboot or shutdown. Don’t disable it.

urandom

Controls the random number generator. Don’t disable it.

usplash

Part of the system that causes the pretty graphics to appear during

 

boot. You can disable this.

vbesave

Part of the graphical subsystem. Don’t disable this.

xorg-comm[on]

Starts the graphical subsystem. Don’t disable this. If you wish to

 

deactivate the GUI, disable the gdm service.

 

 

When you’ve finished using SysV Runlevel Config, type Q to quit the program. Then reboot to test your new settings.

Repairing Problems

If you find you’ve introduced a terrible problem, the solution is simply to switch to another run level. Run levels 3 through 5 are clones of 2 (or they were before you edited run level 2), so you can simply make one of those the default. Then, after rebooting into it, run SysV Runlevel Control again to experiment and reintroduce some excluded services into run level 2. Then you can switch back to run level 2 afterwards.

The default run level is set in the /etc/inittab file. You can load this into the nano command-line text editor, like so:

sudo nano /etc/inittab

452

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

Then look for the line that reads id:2:initdefault: and replace it with id:3:initdefault: (to switch to run level 3; to revert to run level 2, replace 3 with 2). Press Ctrl+X to exit nano and answer Y to the option of saving the buffer, which will save the file.

Optimizing Hard Disk Settings

The hard disk is one of the key elements in the modern PC. Because most of your PC’s data must travel to and from it, speeding up your hard disk means that your entire PC will be faster.

Ubuntu provides a powerful command-line tool that you can use to control every aspect of your hard disk: hdparm. This is a power-user’s tool. Not only must it be run with superuser powers (preceded by sudo at the command line), but you also must be careful not to mistype the commands. All changes are made instantly, so if you make a mistake, your system may crash, or at least suffer from serious problems. There’s even the risk of data loss, although this is minimized by making sure that you have no other programs running at the same time you run hdparm.

The good news is that changes made via hdparm will last for only the current session, so there’s no risk of permanent damage. Any changes that are beneficial can be made permanent later.

In the context of optimization, hdparm lets you both benchmark the disk and change various technical settings, such as the sector multcount value. These adjustments can bring speed boosts.

Benchmarking Your Hard Disk

Because experimenting with hdparm can cause crashes, and because its benchmarking feature needs almost exclusive access to the hard disk, hdparm is best run with as few as possible additional programs up and running. Therefore, killing the GUI is a good idea. To stop the GUI, open a GNOME Terminal window (Applications Accessories Terminal), and type the following:

sudo /etc/init.d/gdm stop

You’ll then need to log in again, so do so.

Note Technically speaking, switching to run level 1 is an even better idea, because this will deactivate all unnecessary services. Run level 1 is akin to the Windows Safe Mode, except without the GUI. However, you want realistic benchmark results to test the changes you make via hdparm, and it’s debatable whether the restricted confines of run level 1 will provide such results.

Let’s start by benchmarking your hard disk to see its performance based on the current settings. Type the following (assuming Ubuntu is installed on the first hard disk in your system; if it’s on the second hard disk, change /dev/hda to /dev/hdb):

sudo hdparm –tT /dev/hda

This will benchmark your disk in two ways. The first tests the PC’s memory throughput, measuring the data rate of the memory, CPU, and cache. The second actually tests the disk’s

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

453

data rate. The second test affects the outcome of the first, which is why the two are used together. Between them, these two methods of benchmarking present the standard way your disk is used on a day-to-day basis. Figure 31-4 shows the results on my system.

Figure 31-4. The hdparm program can be used to both benchmark and optimize your hard disk.

Make a note of the figures so that you can compare them to the results of these tests after you change hard disk settings.

Changing Hard Disk Settings

You can use hdparm to view your current hard disk settings by entering the following at the command prompt:

sudo hdparm /dev/hda

On my test PC, these are the results I got:

/dev/hda:

 

 

 

multcount

= 0 (off)

IO_support

=

1

(32-bit)

unmaskirq

=

1

(on)

using_dma

=

1

(on)

keepsettings

=

0

(off)

readonly

=

0

(off)

readahead

= 256 (on)

geometry

= 65535/16/63, sectors = 160086528, start = 0

 

 

 

 

454

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

Let’s take a look at what these settings mean.

The Multcount Setting

The first, multcount, refers to how many sectors can be read from the hard disk at any one time. The theory is that the highest possible value here is best. Most modern hard drives support a value of up to 32. You can find out by issuing the following command:

sudo hdparm -i /dev/hda

Look for MaxMultSect in the results. On my test PC, this read MaxMultSect=16.

Ironically, although higher values are thought best, sometimes a lower value can speed up hard disk access. You can experiment with the multcount setting on your hard disk by using the -m hdparm command option:

sudo hdparm -m16 /dev/hda

You can then follow this by another benchmark to see if there is an improvement:

sudo hdparm -tT /dev/hda

If there isn’t any improvement, you could try a lower value by simply swapping the -m16 for -m8.

The IO_Support Setting

The IO_support line refers to the input/output (I/O) mode used by the hard disk controller. There are three possible settings: 0, to disable 32-bit support; 1 to enable 32-bit support; and 3 to enable 32-bit support with a special sync signal.

You can change the IO_support setting with the -c hdparm command option, and the 32-bit support with sync option (3) is generally considered the best choice:

sudo hdparm -c3 /dev/hda

The Unmaskirq Setting

The third setting, umaskirq, allows Ubuntu to attend to other tasks while waiting for your hard disk to return data. This won’t affect hard disk performance very much, and generally it’s a good idea for the health of your system to activate it if isn’t already switched on. This command activates umaskirq:

sudo hdparm -u1 /dev/hda

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

455

The Using_Dma Setting

The fourth setting refers to whether Direct Memory Access (DMA) is in use. Hard disks are sold on the basis of their DMA modes, such as UltraDMA Burst 2 and the like. DMA is considered an indicator as to the speed of a hard disk, but the truth is that, like any specification, it is only a guide.

DMA is activated by default under Ubuntu, but you can alter the DMA mode using the -X command option. However, on most modern PCs, this isn’t necessary because the computer’s BIOS defaults to the fastest DMA mode.

Other Settings

The last three settings, above the summary of the geometry and sector information of the disk, are those you shouldn’t change. The readahead setting controls how many hard disk blocks are loaded in advance. It doesn’t affect the performance of modern IDE-based hard disks, because the drive electronics contain buffers that perform this task themselves.

The keepsettings setting refers to the ability of the drive to remember hdparm settings over a reboot, which isn’t necessary because you intend to use the hdparm.conf file to change the disk settings at each boot. The readonly setting sets whether or not the hard disk is read-only (so that no data can be written to it). Changing this setting is not advisable!

Making Disk Optimizations Permanent

The /etc/hdparm.conf file is read at each bootup, and any settings it contains are applied to the hard disk. You can edit this file in the Gedit text editor by typing the following:

sudo gedit /etc/hdparm.conf

The simplest way of using this file is to edit the hdparm command string at the end of the file. To do so, start by finding the line that reads as follows:

#command_line {

Delete the hash mark from the beginning of the line. Then delete the next line (the one that starts with a hash mark, followed by hdparm –q –m16 . . .), and type your own version of the hdparm command, complete with the command options you discovered previously. For example, if your benchmarking has shown that the multcount and IO_support command options bring dividends, you might type something like the following:

hdparm -m16 -c3 /dev/hda

There’s no need to type a hash mark at the beginning, as with the line you deleted. Then delete the hash mark from in front of the line beneath this, so that it’s simply a bracket (}) on its own, as shown in Figure 31-5.

456

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

Figure 31-5. You can make your disk tweaking permanent by editing the hdparm.conf file.

When you’ve finished, save the file and reboot to test your settings.

Prelinking

As discussed in Chapter 29, a lot of Ubuntu software relies on other pieces of code to work. These are sometimes referred to as libraries, which is a good indicator of their purpose: to provide functions that programs can check in and out whenever they need them, as if they were borrowing books from a library.

Whenever a program starts, it must look for these other libraries and load them into memory so they’re ready for use. This can take some time, particularly on larger and more complicated programs. Because of this, the concept of prelinking was invented. By a series of complicated tricks, the prelink program makes each bit of software you might run aware of the libraries it needs, so that memory can be better allocated.

Prelinking claims to boost program startup times by up to 50% or more, but the problem is that it’s a hack—a programming trick designed to make your system work in a nonstandard way. Because of this, some programs are incompatible with prelinking. In fact, some might simply refuse to work unless prelinking is deactivated. At the time of writing, such programs are in the minority. However, keep in mind that prelinking can be easily reversed if necessary. Alternatively, you might want to weigh whether it’s actually worth setting up prelinking in the first place.

C H A P T E R 3 1 O P T I M I Z I N G Y O U R S Y S T E M

457

Note Many of the GNOME programs under Ubuntu aren’t compiled in a way that’s compatible with prelinking. Therefore, you might not see much of a speed boost using the GNOME desktop.

Configuring Prelinking

If you decide to go ahead with prelinking, you’ll need to download the relevant software from the Ubuntu software repositories. (If you haven’t already set up the Synaptic Package Manager to use online repositories, see Chapter 8). Open Synaptic Package Manager (System Administration), click the Search button, and type prelink into the search box. Mark prelink for installation, and then click Apply.

Before you can run a prelinking sweep of your system, you need to enable it in one of its configuration files. To do this, type the following in a GNOME Terminal window:

sudo gedit /etc/default/prelink

Change the line that reads PRELINKING=unknown to PRELINKING=yes. Then save the file and quit Gedit.

To run a prelinking scan of your system, simply issue this command:

sudo prelink -a

This will prelink practically all the binary files on your system and may take some time to complete. You may also see some error output, but you don’t need to pay attention to it.

Prelinking was automatically added as a daily cron job when you installed it (see Chapter 33 for a description of cron), so any new programs you add will be automatically prelinked.

Deactivating Prelinking

Should you find prelinking makes a particular application malfunction or simply stop working, you can try undoing prelinking. To do this, find out where the main binary for the program resides, and then issue the prelink command with the --undo command option. For example, to remove prelinking from the Gedit text editor program, you could type the following:

whereis gedit

sudo prelink --undo /usr/bin/gedit

However, this may not work because some programs might rely on additional binaries on the system. Therefore, the solution might be to undo prelinking for the entire system, which you can do by typing the following:

sudo prelink -ua

After this, you should remove the prelink package to stop it running again in future (or manually remove its cron entry, as explained in Chapter 33).