A blog for Linux Lovers.

Archive for the ‘Linux Administration’ Category

Posted by sibu on March 10, 2009

Crontab Entries

Crontab is used to schedule commands to be executed periodically.
Cron is a daemon process, which means it runs continuously in the background, waiting to run a specified operation at predefined times.

Cron Files


/etc/cron.daily, cron.hourly, cron.monthly, cron.weekly.
This files contain scripts that are run daily, hourly, weekly or monthly respectively, place scripts there be executed inregular intervell.

Lines that can be in the crontab file.

minute (0-59),
hour (0-23),
day of the month (1-31),
month of the year (1-12),
day of the week (0-6 with 0=Sunday).

Options Explanation

* Is treated as a wild card. Meaning any possible value.
*/5 Is treated as ever 5 minutes, hours, days, or months. Replacing the 5 with another
numerical value will change this option.
2,4,6 Treated as an OR, so if placed in the hours, this could mean at 2, 4, or 6 o-clock.
9-17 Treats for any value between 9 and 17. So if placed in day of month this would be
days 9 through 17. Or if put in hours it would be between 9 and 5.


crontab : Add a crontab entry for the cron users.
crontab -u john -e : Add a crontab entry for user john
crontab -u carl /var/spool/cron/john : Copy the crontab file of john located in the /var/spool/cron/cron.* for user carl.
crontab -l :List crontab entries.
crontab -r : Remove the current crontab entry.

Posted by sibu on March 10, 2009

Volume Labels

Volume labels make it possible for partitions to retain a consistent name. Each can be a maximum of 16 characters long. There are three tools to make volume labels: mke2fs, tune2fs and e2label.

e2label /dev/hda1 omega

tune2fs -L omega /dev/hda1

The above 2 commands will label the first partition of the drive “omega”. That label stays with that particular partition, even if the drive is moved to another controller or even another computer.

mke2fs omega /dev/hda1

mke2fs -L omega /dev/hda1

The above command also will do the label but only after they make the file system. This means that either of these last two commands will delete any existing data in the partition.

Posted by sibu on March 10, 2009

How to enable and disable ping request.

To Disable Ping

echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

To Enable Ping

echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all

Posted by sibu on March 8, 2009

Linux filesystem blocks

Linux filesystem blocks

The blocks used for two different purpose:

1. Most blocks stores user data as files (user data).
2. Some blocks in every file system store the file system’s metadata.In simple words Metadata describes the structure of the file system. Most common metadata structure are superblock, inode and directories.


Each file system is different and they have type like ext2, ext3 etc. Further each file system has size like 5 GB, 10 GB and status such as mount status. In short each file system has a superblock, which contains information about file system such as:

* File system type
* Size
* Status
* Information about other metadata structures

If this information lost, you are in trouble (data loss) so Linux maintains multiple redundant copies of the superblock in every file system. This is very important in many emergency situation, for example you can use backup copies to restore damaged primary super block. Following command displays primary and backup superblock location on /dev/hda3

# dumpe2fs /dev/hda3 | grep -i superblock

dumpe2fs 1.35 (28-Feb-2004)
Primary superblock at 0, Group descriptors at 1-5
Backup superblock at 32768, Group descriptors at 32769-32773
Backup superblock at 98304, Group descriptors at 98305-98309
Backup superblock at 163840, Group descriptors at 163841-163845
Backup superblock at 229376, Group descriptors at 229377-229381
Backup superblock at 294912, Group descriptors at 294913-294917
Backup superblock at 819200, Group descriptors at 819201-819205
Backup superblock at 884736, Group descriptors at 884737-884741
Backup superblock at 1605632, Group descriptors at 1605633-1605637
Backup superblock at 2654208, Group descriptors at 2654209-2654213
Backup superblock at 4096000, Group descriptors at 4096001-4096005
Backup superblock at 7962624, Group descriptors at 7962625-7962629
Backup superblock at 11239424, Group descriptors at 11239425-11239429

When a file system fails then

* File system will refuse to mount
* Entire system get hangs
* Even if filesystem mount operation result into success, users may notice strange behavior when mounted such as system reboot, gibberish characters in directory listings etc

Most of time fsck (front end to ext2/ext3 utility) can fix the problem, first simply run e2fsck - to check a Linux ext2/ext3 file system, first unmount /dev/sda3 then type following command :

# e2fsck -f /dev/sda3


* -f : Force checking even if the file system seems clean.

Please note that If the superblock is not found, e2fsck will terminate with a fatal error. However Linux maintains multiple redundant copies of the superblock in every file system, so you can use -b {alternative-superblock} option to get rid of this problem.

The location of the backup superblock is dependent on the filesystem’s blocksize:

* For filesystems with 1k blocksizes, a backup superblock can be found at block 8193
* For filesystems with 2k blocksizes, at block 16384
* For 4k blocksizes, at block 32768.

Tip you can also try any one of the following command(s) to determine alternative-superblock locations:
# mke2fs -n /dev/sda3
# dumpe2fs /dev/sda3|grep -i superblock

To repair file system by alternative-superblock use command as follows:
# e2fsck -f -b 8193 /dev/sda3

However it is highly recommended that you make backup before you run fsck command on system, use dd command to create a backup (provided that you have spare space under /disk2)
# dd if=/dev/sda3 of=/disk2/backup-sda3.img

Posted by sibu on March 3, 2009

DNS Server Setup..

DNS Server Setup

A name server translates domain names into IP addresses. This makes it possible for a user to access a website by typing in the domain name instead of the website’s actual IP address.
In order to run a `name server’, named daemon is needed. The files needed for configuring and running DNS (master and slave server) are:
1) /etc/named.conf
2) /var/named it’s a directory where the main database stays)
3) dnsconf utility

named configuration file (/etc/named.conf): It basically defines the parameters that point to the sources of domain database information, which can be local files or on remote servers.

Hint file (cache file)(/var/named/ It actually provides the name of root server which gets activated in case the machine name is not there in user defined zone.

localhost file (/var/named.local): All configuration have a local domain Database for resolving address to the host name localhost.

Now lets open /etc/named.conf
# This is the macro which defines where will the DNS related file stay.
Options {
directory “/var/named”;
# the line below says about the root servers or cache servers
zone “.” {
type hint;
file “”;

# This particular option tells about the file, which will keep hostname to Ipaddress mapping
zone “”{
type master;
file “/var/named/”;

/var/named/ contains

@ IN SOA (
2000011301 ; serial
3600 ; refresh
900 ; retry
1209600 ; expire
43200 ; default_ttl
)               IN     NS               IN     NS              IN      A

@: It means current domain name.

In: This stands for Internet servers

SOA: This stands for `Start Of Authority’. This is the record that states that this server is authorative for the specified domain.

20000011301;serial: This is the serial number–a numeric value that tells or notifies the slave server, that the database has been updated. So slave server should also update it.

3600;refresh: This is the refresh cycle in seconds. In every refresh cycle the slave server comes to master server and checks for the updated database.

1800;retry: This particular line refers to the retry cycle which in turn means that the slave server should wait before asking the master server again in case master server doesn’t respond.

1209600;expire: In the event of a failure of the master DNS server, a slave server will continue to use its existing data for this period of time. After the expire time has passed, the data are considered stale and will not be used at which time the domain will no loger resolve. This value should be long enough to allow master server outages to be corrected, on the order of weeks.

432100;default_ttl: This refers to the default time to leave, for this domain to work for, when named is once started. Remember the user doesn’t have to play with this unless he wants that the query time from the slave server should be somewhat less or more. In case we want to change, we should change only the refresh time in both master and slave. The best way is to make it 2, which means after each 2 seconds slave server will query to master server.

Posted by sibu on March 3, 2009

Fix a corrupt rpm database.

Symptoms : All rpm commands ‘hang up’

Find and kill all process running rpm or up2date:

ps -aux |grep rpm

ps -aux |grep up2date

Remove all rpm database lock files.

rm -f /var/lib/rpm/__db*

This usually get things doing..

If its not working  then first make a backup of the database:

cp -r /var/lib/rpm /var/lib/rpm.copy

then rebuild the database

rpm –rebuilddb