Minggu, 05 Desember 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


Jumat, 03 Desember 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.

Rabu, 01 Desember 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'.

Minggu, 21 November 2004

RPM Package Manager

RPM is a recursive acronym for RPM Package Manager (Formerly known as Redhat Package Manager). It is the default package manager in RedHat as well as RedHat based Linux distributions like Mandrake, OpenSuSE, PCLinuxOS and so on [Read about these Linux distributions here ]. It is very powerful and can be used to install, remove, update software, as well as a whole lot of other things in Linux. Basically, RPM can be divided into 3 main areas of functionality.
  1. Packages - Files that are compressed and contain applications, data and other files.
  2. Database - A list of installed packages in a system.
  3. Compilation - Bundling a bunch of files into a package suitable for installation on other systems.
Here are a couple of important RPM commands that are frequently used by Linux users though now a days, they use other tools (such as Yum) which provide automatic dependency checking to achieve the same.

Querying - Know more about a package
You can query the RPM database to know more details about a particular package that is installed in your system. To see if a particular program (say gedit, a text editor) is installed or not, use -q to activate the query mode in RPM.
# rpm -q gedit
RPM usually responds with the name, version and release of the package installed or, more likely reports that it is not present. To see all the files that are installed for gedit and their full path, use the -l sub parameter with the query mode.
# rpm -q -l gedit
Here -q is the mode and -l is the submode. Usually you can bundle the mode and sub-mode parameters together as follows:
# rpm -ql gedit
You can also try...
# rpm -qlv gedit
... for a more verbose output.

To find, in which package the file /bin/sh is located, try :
# rpm -qf /bin/sh
bash-2.05b-38

...which tells that the file /bin/sh is situated in the package bash-2.05b-38.
Now to get more details about the bash package execute the following command:
# rpm -qi bash
...which will give a whole lot of details about the bash package installed in your system.

Installing and removing packages

Suppose you want to install a package (say gedit):
# rpm -ivh gedit-2.6.0-4.rpm

To update gedit to a newer version:
# rpm -Uvh gedit-2.8.0-6.rpm
The -U mode means, if this package is not installed, install it; if an older version of this package is installed, upgrade it.

There is a third installation mode, called freshening, represented by -F. This is similar to -U in that it upgrades a package that is installed, but it adds one restriction - it ignores any packages that are not of the same name as a package that is already installed on your system. So if you have a directory containing a bundle of rpms - say security patches - then you can move into that directory containing the security patches in RPM format and execute the command:

# rpm -Fvh *.rpm

... which will install only those security patches which are related to the packages that are already installed in your system and will ignore the rest.

To remove an already installed package say gedit, just type:
# rpm -e gedit

Drawbacks of RPM

RPM has one difficulty, ie it will not install a package if that package depends on another program that is not already installed on your system. This is known as a dependency issue. RedHat provides two utilities called rpmdb-redhat for RedHat enterprise linux and rpmdb-fedora for Fedora Core. Once you install one of these on your system, RPM will automatically begin suggesting dependency resolutions.

Of course, you can force RPM to install a package even without resolving a dependency problem by using the --force and --nodeps parameters to both the installation related modes and the remove mode. They ignore conflicts and dependencies respectively.

Suppose you do not want to install an RPM package but get one or more files in it. You can use a utility called rpm2cpio to convert your RPM package into a cpio package (which is more or less similar to a tarball) then use the command cpio to extract all the files into a directory as follows:
# rpm2cpio PackageName | cpio -id

This will extract all the files from the RPM package into the current directory. This is only a small subset of the power of RPM. To know more about it try:

# man rpm

Rabu, 17 November 2004

Installing RedHat linux directly from the iso's saved in your hard disk

I came across an article which described how to install RedHat linux directly from the ISO's saved in your hard drive skipping the need to burn them on to a CD. The advantage of this method of installation is that, it is blazingly fast and the installation can be finished in a fraction of what it takes normally to install by booting from a CD or DVD.

But there is a catch though - this method works only if the filesystem on your hard disk is eaither of the following - FAT, ext2, ext3. If you have a file system other than those three, like resierfs, then you are out of luck. Also this method is specific to RedHat linux distribution.

You can also find a different method explained at LinuxQuestions.org.



Minggu, 07 November 2004

Connecting to BSNL dial-up Internet Server using wvdial

Bharat Sanchar Nigam Limited (BSNL) is India's largest telecom company. It is owned by the Govt. of India. BSNL provides Internet dial-up access packages (Sancharnet) which are the best deal when compared to those provided by other ISPs in the country. Here I will explain how to dial in to the BSNL server in linux using wvdial utility. It is assumed that you already have a BSNL dial-up internet account. If not then get one and come back to this page :) .

If this is the first time you are connecting to the internet, then you have to 'su' to root and execute the command :

$ su -

# wvdialconf
wvdialconf script, builds a configuration file for wvdial. It detects your modem, its maximum baud rate, and a good initialization string and generates or updates the wvdial configuration file based on this information.Now if you check the /etc/wvdial.conf file, you will see that wvdialconf has written the necessary data regarding your modem there. Now you have to open the /etc/wvdial.conf file and enter the BSNL dial-up access phone number, your username and password as follows:

; /etc/wvdial.conf file

Phone = 172222

Username = "your login name"

Password = "your password"
Also make sure that the line -

New PPPD = yes
exists in the /etc/wvdial.conf file in the [Dialer Defaults] section. If it is not there, then include that too.

Next you have to modify your /etc/resolv.conf file and enter the primary and secondary DNS servers of BSNL for name resolution. If you do not do this then, you will be able to login to the BSNL server, but will not be able to browse the web. My /etc/resolv.conf file is as follows:

nameserver 61.1.96.65 #Primary BSNL DNS Server

nameserver 61.1.128.5 #Secondary BSNL DNS server

nameserver 61.0.0.5 # Tertiary BSNL DNS server
Now to connect to the internet, just run wvdial command in the console as follows:

# wvdial
By default only root can run wvdial. To let other users execute wvdial utility, I did the following:

First I created a group called 'modem'.

# groupadd -g 503 modem
I Made sure that the group id 503 is not used by any other group; If not then you could use any other unique number greater than 500.Then I included all users who are allowed to connect to the internet to this newly created group.

# usermod -G modem ravi

# usermod -G modem sada
Then I permitted the modem group to connect to the internet by editing the sudo configuration file /etc/sudoers as follows:

# visudo
//Now you are in /etc/sudoers file

%modem localhost=/usr/bin/wvdial
From here onwards, those who are in the modem group can execute the following command to connect to the internet.

$ sudo wvdial

password: ******
My complete /etc/wvdial.conf file is as follows:

[Dialer Defaults]

New PPPD = yes ;Don't forget to include this line

Modem = /dev/modem

Baud = 14000 ;I use the linuxant driver so speed is less

Init1 = ATZ

Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0

ISDN = 0

Modem Type = Analog Modem



;BSNL phone no:,username and password settings

Phone = 172222

Username = "My login name"

Password = "My Password"


Sabtu, 30 Oktober 2004

Dual Booting Windows XP/2000 and Red Hat Fedora Core 2

There are two ways in which you can dual boot between windowsXP/2000 and Linux.
  1. Install the boot loader in the Master Boot Record (MBR)
  2. Install the bootloader on the linux partition.
The first method is the easier of the two. But if by any chance, you descide to Hibernate your computer while in WindowsXP for example, then your MBR is overwritten by windowsXP and you will be unable to boot into linux using your bootloader.
Here I will explain how to overcome this setback by using the second method. That is installing the bootloader (LILO or Grub) on the linux partition . Here I am explaining the steps with respect to RedHat Fedora Core 2 distribution. But the steps are equally valid for any linux distribution.
The procedure is as follows:
  • Install WindowsXP/2000 first.
  • Now install Fedora core 2. I installed it in /dev/hda3 ; which was my linux ext3 partition.
  • While installing, enforce LBA32. This is necessary only if you intend to install the bootloader in a partition above 32GB. In my case (I have only 12 GB total) it was not necessary.
  • At the section where the installer asks whether you want to install a boot loader; select yes (Fedora comes with Grub as default boot loader) and in the advanced settings, select your linux partition as the place to install the bootloader. In my case it was /dev/hda3. Nowcomplete the Fedora core 2 install.
  • Reboot the computer and load again from the first CD in your Fedora Core 2 distribution.
  • At the boot prompt, type:
    boot: linux rescue
    ... And boot into rescue mode. Fedora will automatically try to detect your linux partition ;boot you into single user mode and mount your linux partition in the /mnt/sysimage directory.
  • Here when you get the root prompt, issue the following commands:
    # chroot  /mnt/sysimage
    # dd if=/dev/hda3 of=linux.bin bs=512 count=1
  • Now insert a floppy and copy the linux.bin file into it as follows:
    # mcopy linux.bin a:
  • Type exit 2 times - which will reboot your machine. Now remove the FC2 CD and boot into windows XP/2000.
  • Get to the command prompt and copy the linux.bin file into the C:\ drive.
    A:\> copy linux.bin  C:\
  • Finally add the following line to the boot.ini file residing in the C:\ drive.
    C:\linux.bin=" Red Hat Fedora Core 2"
  • Reboot machine and choose "Red Hat Fedora Core 2" from boot.ini menu, which will cause NTLDR to load first 512 kb from Fedora Core 2 boot partition.
  • Select from grub menu the desired kernel and press Enter.
Now even if you hibernate while in Windows XP, your bootloader will not be overwritten and you will be able to boot successfully into Linux.