Sunday, 5 December 2004

Package Management using YUM

RedHat and other RPM based Linux distributions contain one drawback over distributions like Debian in that it is very hard to upgrade or install softwares because of dependency issues. And where Debian Linux has a very efficient and clean package management tool in the apt-get package which automatically resolves the dependency issues, redhat/ rpm based distributions lacked this. That was until yum came along. Yum stands for Yellowdog Updater, Modified for Redhat based distributions which is the counterpart of apt-get for Debian. Yum automatically computes dependencies and figures out what steps need to occur in order to install packages. It makes it much easier to maintain groups of machines without having to manually update each one using rpm.



Here I will explain how to install, uninstall and update individual packages in your Redhat Linux system. Before you start using yum, you have to modify the configuration file /etc/yum.conf. This is because the redhat repository server is severely overloaded and might be very slow. So it is in our interests to look at third party repositories. Here I will use mirrors.kernel.org as the alternate repository. So my edited /etc/yum.conf file reflecting the change is as shown below:



#File /etc/yum.conf



[main]

cachedir=/var/cache/yum

debuglevel=2

logfile=/var/log/yum.log

pkgpolicy=newest

distroverpkg=redhat-release

tolerant=1

exactarch=1

retries=20



[base]

name=Fedora Core $releasever - $basearch - Base

#baseurl=http://download.fedora.redhat.com/pub/fedora/ Linux/core/$releasever/$basearch/os/

baseurl=http://mirrors.kernel.org/fedora/core/$releasever/ $basearch/os/



[updates-released]

name=Fedora Core $releasever - $basearch - Released Updates

#baseurl=http://download.fedora.redhat.com/pub/fedora/ Linux/core/updates/$releasever/$basearch/

baseurl=http://mirrors.kernel.org/fedora/core/updates/ $releasever/$basearch/

As you can see, I have commented out the redhat fedora repository server and added the mirrors.kernel.org repository.

Also add the following two lines to the /etc/sysconfig/rhn/sources file.

yum fedora-core-1 http://mirrors.kernel.org/fedora/core/1/i386/os

yum updates-released http://mirrors.kernel.org/fedora/core/updates/1/i386
This is only for using our choosen repository with other redhat updation tools like up2date and rpm tools which also come with Fedora core 1 and above. Now you are ready to use yum.



Updating the RPM headers
(This has to be done at least once the first time before you start using yum).

This downloads the header files of the RPM packages from the repositories to your machine and will take only a couple of minutes to complete.

# yum check-update
Update all the packages installed on your system

# yum update
Update just an individual package (say gedit):

# yum update gedit
In the above case, if the gedit package installed on your system is the current version, yum will not do anything.

Install a package (say rdesktop) for the first time:

# yum install rdesktop
Suppose you have a package (say mplayer) installed and you would like a GUI interface to it. But you do not have any idea what the package might be called. You can find it out using the following command :

# yum search mplayer gui
And this is what you might see:

Gathering header information file(s) from server(s)

Server: Fedora Core 1 - i386 - Base

Server: Fedora Core 1 - i386 - Released Updates

Finding updated packages

Downloading needed headers

Looking in available packages for a providing package

Available package: mplayer-frontend.i386 2:3.48-1 from base matches with Gtk+ frontend for mplayer.

Available package: mplayer-frontend.i386 2:3.48-1 from base matches with mplayer-frontend
From the above output, you come to know that 'mplayer gui' package is known by the name mplayer-frontend. Now you can install the package as explained earlier. The search option also accepts wild card characters in the event you need to utilize them.

If you need a certain library which is not a standalone package like say libc6.1-1.so.2 . Just use the following command to search in which package, the particular library is in:

# yum provides libc6.1-1.so.2
You might get the following output:

Gathering header information file(s) from server(s)

Server: Fedora Core 1 - i386 - Base

Server: Fedora Core 1 - i386 - Released Updates

Finding updated packages

Downloading needed headers

Looking in available packages for a providing package

Available package: compat-libstdc++.i386 0:7.3-2.96.118 from base matches with

libstdc++-libc6.1-1.so.2

Available package: compat-libstdc++.i386 0:7.3-2.96.118 from base matches with

libstdc++-libc6.1-1.so.2(GCC.INTERNAL)

2 results returned

Looking in installed packages for a providing package

No packages found

... which tells that the library is in the compat-libstdc++ package which can be installed using

# yum install compat-libstdc++
To remove a package (say gedit):

# yum remove gedit
This removes the selected package as well as any other package that depends on it.

One thing worth noting is that when Yum downloads packages or updates for installation it does not remove them automatically from its disk cache, so some periodic maintenance is required.This is achieved as follows:

# yum clean all
The above command deletes any old cached packages from your system as well as removing any old rpm headers that are no longer needed.

Lastly if you want to get any additional information about a package (say xchat) without actually installing it, do the following :

# yum info xchat
As you can see, it is a piece of cake in managing packages using yum. To know more about this wonderful package management software, you may visit official yum project page or do

$ man yum


Friday, 3 December 2004

Boost your hard drive performance in Linux using hdparm

Hdparm is a command-line utility that provides powerful control over your hard drive parameters (HD PARaMeters). It can also tell you a lot about your disk drive. Everything you do with hdparm, until you make a script for it, will be done at the command line. It can be adjusted manually and then put into a startup script to make your chosen settings effective every time the system starts up.

Suppose I want to improve the performance of my first hard disk drive - /dev/hda . The first thing I do is find out the characteristics of my hard disk. This can be done as follows:
# hdparm -i /dev/hda
And the output on my machine is this :
/dev/hda:
Model=QUANTUM FIREBALLlct10 10, FwRev=A03.0900, SerialNo=872007625887
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
RawCHS=16383/16/63, TrkSize=32256, SectSize=21298, ECCbytes=4
BuffType=DualPortCache, BuffSize=418kB, MaxMultSect=16, MultSect=16
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=20044080
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 *udma2
AdvancedPM=no WriteCache=enabled
Drive conforms to: ATA/ATAPI-4 T13 1153D revision 15: 1 2 3 4

* signifies the current active mode
In the output shown above, a few important values to be noted with interest are as follows:
  • MaxMultSect - The maximum number of sectors your hard disk can read at a time.
  • MultSect - The current number of sectors being read at a time.
  • PIO modes, DMA and UDMA modes - The modes supported by your hard drive. The one marked with an asterisk (*) is the one currently set.
  • AdvancedPM - Indicates whether or not your hard drive supports Advanced Power Management.
Another command :
# hdparm /dev/hda
will reveal the following information ...
/dev/hda:
multcount = 16 (on)
IO_support = 0 (default 16-bit)
unmaskirq = 0 (off)
using_dma = 1 (on)
keepsettings = 0 (off)
readonly = 0 (off)
readahead = 256 (on)
geometry = 19885/16/63, sectors = 20044080, start = 0
The items of interest in the above output are as follows:
  • multcount - The number of sectors being read at a time.
  • I/O support - The operating mode of your hard disk (16/32/32sync).
  • using_dma - Whether or not the drive is using the DMA feature. This may be on by default if your version of Linux properly detects and supports your chipset and drive's DMA capabilities.
  • keepsettings - Whether the settings are kept after the drive resets (usually caused by errors).
  • readonly - Whether the drive is read-only. Normally set to 1 only for CD-ROMs.
  • readahead - How many sectors ahead will be read when you access the hard drive.
The hdparm program provides two performance testing features that are crucial in letting you know whether or not you are improving performance or not as you tweak along.
# hdparm -Tt /dev/hda1
will show results such as the following before enhancing the performance.
/dev/hda1:
Timing buffer-cache reads: 340 MB in 2.01 seconds = 169.43 MB/sec
Timing buffered disk reads: 30 MB in 3.08 seconds = 9.73 MB/sec
and the results like these after enhancing the performance.
/dev/hda1:
Timing buffer-cache reads: 340 MB in 0.91 seconds = 200.00 MB/sec
Timing buffered disk reads: 30 MB in 1.05 seconds = 19.73 MB/sec
The goal is to see the time in seconds decrease and the MB/sec to increase in the above output.You can do that by using a variety of parameters, invoked one at a time, then rerunning the performance tests to see if things are improving or not.

For example: Begin by setting the operating mode of the interface between the system and the disk drive using one of the following parameters:
  • -c0 - Sets operating mode to 16-bits
  • -c1 - Sets operating mode to 32-bits
  • -c3 - Sets operating mode to 32-bits synchronized
Mode -c1 is usually used for best performance. Mode -c3 is required only for certain chipsets.
# hdparm -c1 /dev/hda
Next set the data transfer parameters, which you can determine from the -i command shown earlier. In the above case, the value of MaxMultSect is 16 which is the maximum supported.
# hdparm -m16 /dev/hda
Next try activating DMA mode for your system interface:
# hdparm -d1
Then set the drive mode (a value of X32 is most common; UDMA-5 is X69):
# hdparm -X32 /dev/hda
Finally, try setting the read-ahead value, which is typically set to the same value as multcount from earlier (See the hdparm /dev/hda output above), or 16:
# hdparm -a16 /dev/hda
If any or all of these settings make incremental improvements in performance, remember them and create a script that sets them all sequentially or includes them all in one line.

From all these settings, you might be using the following optimal single command :
# hdparm -X34 -m16 -c1 -a16 -d1 /dev/hda
Now save this command into a file and make the file into a script and place in the directory for the runlevel at which you normally use linux. I use runlevel 2 by default on my home machine. So I create a file named /etc/init.d/hdparm.local with the above hdparm command. Then configure it to start at runlevel 2 as follows:
# ln -s /etc/init.d/hdparm.local /etc/rc2.d/S20hdparm.local
Update (Oct 26 2007): If you are using Ubuntu or any Debian based Linux distribution, you can set the hdparm command and its options in the /etc/hdparm.conf configuration file instead of creating the above mentioned script and saving it in init.d directory. Also note that in Ubuntu Gutsy Gibbon, even the IDE drives are provided device nodes with name /dev/sda instead of /dev/hda. So make the necessary changes while executing the commands.

The next step is to keep an eye on dmesg and/or /var/log/syslog. In some cases, an error will cause the settings to be reset. So that's where the -k (keep) flag comes in. If you are 100% positive that these settings won't corrupt your data, you can add -k to the script.

WARNING : Setting hdparm parameters too aggressively - that is, in excess of the disk controller or drive capabilities - can lead to data loss. It is best to test hdparm settings on a fresh installation of the operating system before committing any applications or programs to the drive and prepare to back down on the settings and reinstall the OS if the drive is unstable or the hdparm tests show erratic results or fail.

Wednesday, 1 December 2004

Popular Linux Links

I come across loads of linux links while searching for stuff related to linux. I share some of the websites which I found to be interesting below.

LinuxHomeNetworking - This site contains a whole lot of tutorials on configuring various aspects of linux like setting up Quotas for users, DNS configuration, sendmail configuration and most things related to networking. A very good site to pick up the skills in configuring various networking related linux softwares.

TLDP.Org - This site is maintained by a loosely knit team of volunteers who provide documentation for many aspects of Linux. There are several forms of documentation: Guides, HOWTOs, man pages, and FAQs.This is one of the first places to look when you encounter a problem related to linux.

LinuxSecurity.com - This site deals with issues related to security in linux. It has the latest news, advisories, resources like white papers, HowTo's, security dictionary and newsletters.

LinuxQuestions.org - This is a linux forum where you can post your questions based on linux and get them answered by visitors to this site. Even if you are not interested in posting your question, it would be worth your time, if you browse through posts on this high traffic site. A number of times when I googled for linux related topics, I got this site consistently in the first page of the search - which speaks volumes about the popularity of this site.

L.O.S.T - A site which hosts user contributed tips on getting various jobs done in linux. The tips can be eaither downloaded as a fortune database or can be viewed online.

Linux Devcenter - This is an O'Reilly site which has lots of articles on linux. This site is specifically targeted at developers. But anybody interested in linux can gain something by visiting this site.

Kernel.org - This is the primary site for the Linux kernel source. If you are interested in downloading patches for your kernel or getting the latest kernel source, then this is the site to visit.

www-130.ibm.com - This is IBM's linux resource site for developers. Here you can obtain a wealth of tutorials and articles on configuring, administering and using linux and linux based softwares.

Linux Magazines

Redhat Magazine - An online magazine brought out by redhat. This magazine publishes articles related to redhat enterprise linux and fedora.

LinuxGazette.net - A monthly magazine dedicated to linux which can be downloaded in a variety of formats for offline viewing. I really like their 'Ask the Answer Gang' and 'MailBag' sections.

LinuxGazette.com - This is the counterpart of the linuxgazette.net magazine whose team split into two because of the difference in opinion between them. You can post your articles and questions in its forum after you have registered with their site.

LinuxFocus.org - The goal of LinuxFocus is to produce and publish a free online magazine about Linux and related issues in a number of languages. LinuxFocus is an open magazine, it is the joint effort of many people. Anyone can contribute interesting articles.

Linux-Mag - This is another online magazine which has loads of articles and tips on linux for both the newbies and the linux guru's alike.

LinuxHotBox - This is a linux eMagazine which you can download and read offline. Has quite good subject matter though the magazine itself is over a few MB's download which could be tough on dialup users. Ironically, they only have a windows exe version of their ebook for download.

Online Books

Rute - A great, must read, online book on linux. You can also get the printed version of this book.

Safari.OReilly.com - This is the online library of O'Reilly - the biggest computer book publishers in the world. You get to read most linux books published by O'Reilly here. It is basically a paid service but you can try safari free for 14 days.

These are only a few of the interesting sites I came across. You can get more linux related links on the right side bar of this site under the section 'My Linux Bookmarks'.