Pages

Monday, March 15, 2010

Error:: "Esc is Already Running"

If you got the error after rebooting the Linux Machine, just follow the follow the given steps....

1) On command prompt...
     # rpm -qi esc
O/P:::

Name        : esc                          Relocations: (not relocatable)
Version     : 1.1.0                             Vendor: CentOS
Release     : 9.el5                         Build Date: Thu 03 Sep 2009 11:59:48 PM IST
Install Date: Tue 24 Nov 2009 05:37:13 AM IST      Build Host: builder10.centos.org
Group       : Applications/Internet         Source RPM: esc-1.1.0-9.el5.src.rpm
Size        : 1211315                          License: GPL
Signature   : DSA/SHA1, Sun 20 Sep 2009 09:23:30 AM IST, Key ID a8a447dce8562897
URL         : http://directory.fedora.redhat.com/wiki/CoolKey
Summary     : Enterprise Security Client Smart Card Client
Description :
Enterprise Security Client allows the user to enroll and manage their
cryptographic smartcards.

2.) Now remove package from yum..

# yum remove esc


regards
Kuldeep Sharma

Kernel panic - not syncing: Attempted to kill init! " Error

Kernel panic - not syncing: Attempted to kill init! " Error

Follow the following steps.
1. Once you are at the grub screen, press c for command line.
2. On command line execute the following commands.
find /grub/stage2
find /etc/hosts
This will provide you the boot partition & the root partition nos. in the format (hd0,2) etc
If the root partition & boot partitions are same then execute the following commands.
root (hd0,2)
kernel /boot/vmlinuz-kernel version ro root=/dev/hda3
initrd /boot/initrd-version
boot
if the boot & root partitions are different then replace the root=/dev/hda3 with the value you get for root partition i.e. if you get (hd0,5) then replace the value with /dev/hda6.
If you still get the kernel panic message, recreate the initrd image using the mkinitrd command.

Hope this will work. 

Regards 

Kuldeep Sharma

Sunday, March 14, 2010

Resetting root Password in Linux

How to reset forgotten root password in Linux?


Quantcast

The root password for the Linux system can be reset by booting it into the Single User mode which is also termed as Emergency mode or more popularly known as Rescue mode.
If the boot loader installed on your Linux system is GRUB, then please follow the below listed steps to reset the root password.
  • Select the line which specifies the kernel to be loaded.
  • Press the ‘e’ key to edit the entry.
  • Choose second line (the line starting with the word kernel).
  • Press the ‘e’ key again to edit kernel entry
  • Append the letter ‘S’ or word ’single’ to the end of the line.
  • Press the [ENTER] key
  • Press the ‘b’ key to boot the Linux kernel into single user mode
After the booting process completes, mount the ‘/’ and ‘proc’ partitions using the below listed commands.
# mount -t proc proc /proc
# mount -o remount,rw /
Issue the 'passwd' command to change the root password.
Finally, reboot the system employing the below commands.
# sync
# reboot
If the boot loader installed on your Linux system is not GRUB but LILO, then please follow the below mentioned steps to reset the root password.
  • At the Boot: prompt displayed by the LILO boot loader, type linux single and press the [ENTER] key:
  • Allow the system boot and when it displays the # prompt, type passwd to reset the root password.
  • Finally, reboot the system by issuing sync followed by the reboot command.

Intro About Run Levels in Linux

Run Levels and inittab – RHEL

Now that we have already seen the boot sequence and GRUB file for linux, lets now check what is run level and one of the important file /etc/inittab which is used during booting linux.
Run Level
Operating system like linux has several services that are running. Each service will provide some functionality to OS. Example ftp service will allow other machine to FTP from your machine. Similarly network service will allow networking functionality.
But keeping all the services running while working on only few serivce will impact performance. Some times administrator does not need all the services and just need few services for working.
For this kind of situation, linux provides different runlevel. Each run level has some specific set of services running. Example if you start your linux in run level 1, some specific set of services will get started but not all. If you boot linux in run level 2 some more services will get started over and above services from run level 1. So run level is just a way to tell OS what are all services it should start during boot time.
Linux has 7 run levels, they are given as below. These run levels are defined in a file /etc/inittab which is the file read during boot time to get the default run level set and linux will boot in that run level.
0 -> Used for shutdown. Setting this in /etc/inittab, linux wont be able to boot.
1 -> Single user mode. Linux will start in single user mode. Usually used for maintenance task.
2 -> Multiuser, without NFS.
3 -> Full multiuser mode, no X Server started so no graphical display.
4 -> unused
5 -> Starts XDisplay as well. X Server is started with all graphical display.
6 -> reboot. Do not set this value in /etc/inittab, else linux will reboot continuously.

You can check the current run level of your Linux using following command.

[chramana@ap6023fems chramana]$ /sbin/runlevel
N 3

Here it gives 2 characters which are . So the current run level is 3 and previous run level is null, meaning that system started with run level 3 from the very beginning.
After having this brief idea about run level we will see the content of /etc/inittab file
/etc/inittab
This file is one of the most important file for booting. Every the entry in this file has following format each seperated by “:”"
Identification tag of that line : Run level numbers : Keyword : Path of script to be executed
Example:
si::sysinit:/etc/rc.d/rc.sysinit
In the above line there is no “Run level number” after 1st “:”, that means that this command will run for all the run levels.
Following are the different entries in the file
The first entry in file is
id:3:initdefault:
This line decide what should be runlevel at the time of booting. Here the run level is 3, that means that system will start in run level 3 by default. If we change this run level from 3 to 5 and reboot then system will start in run level 5.
si::sysinit:/etc/rc.d/rc.sysinit
This line is for system initialization and is executed at all run level. It calls the script /etc/rc.d/rc.sysinit to initialize the system during startup.
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

These lines will carry out the task based on the run level in which we are starting the system. Depending on the run level proccessing will change.
Each of this entry will call same script /etc/rc.d/rc but will pass the arguement as run level #, depending on which run level system is booting.
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
This command is used to trap the key pressed and will be executed for all run level. If a combination of ctrl+Alt+Del key is pressed then it will shutdown the system by running /sbin/shutdown command. -t3 -r now are the arguements to this script.
pf::powerfail:/sbin/shutdown -f -h +2 “Power Failure; System Shutting Down”

The above line tells what needs to be done is a power falure is detected by the system. There are device drivers which will detect change in the UPS status when power goes off. When such condition occurs then this command will guide system for required action.
In this case its doing to display message “Power Failure; System Shutting Down” and system will do a clean shutdown using /sbin/shutdown script in 2 mins (hence +2 in script). This command will run for all run sequence.
ppr:12345:powerokwait:/sbin/shutdown -c “Power Restored; Shutdown Cancelled”
This is a power restore action. Suppose when power goes off and we have configured to run shutdown command after 10 mins (+10 option) and lets say power comes back in 9 mins, then we dont want to shutdown the system as power came back, in this case we can specify the action to be taken in this command.
x:5:respawn:/etc/X11/prefdm -nodaemon
The above command starts a X11 server in run level 5.
/etc/inittab calls several other script which initializes and configures the system at the time of starting.
We can also check which all services starts at what level using chkconfig command as shown below.
[root@ap6023fems chramana]# /sbin/chkconfig –list
xinetd          0:off   1:off   2:off   3:off   4:on    5:on    6:off
gpm             0:off   1:off   2:on    3:off   4:on    5:on    6:off
ypxfrd          0:off   1:off   2:off   3:off   4:off   5:off   6:off
dc_client       0:off   1:off   2:off   3:off   4:off   5:off   6:off
lm_sensors      0:off   1:off   2:on    3:off   4:on    5:on    6:off
ldap            0:off   1:off   2:off   3:off   4:off   5:off   6:off
winbind         0:off   1:off   2:off   3:off   4:off   5:off   6:off
rpcidmapd       0:off   1:off   2:off   3:off   4:on    5:on    6:off
snmptrapd       0:off   1:off   2:off   3:off   4:off   5:off   6:off
ripd            0:off   1:off   2:off   3:off   4:off   5:off   6:off
ocfs2           0:off   1:off   2:on    3:off   4:on    5:on    6:off
sysstat         0:off   1:on    2:on    3:off   4:on    5:on    6:off
squid           0:off   1:off   2:off   3:off   4:off   5:off   6:off
messagebus      0:off   1:off   2:off   3:off   4:on    5:on    6:off
rawdevices      0:off   1:off   2:off   3:off   4:on    5:on    6:off
FreeWnn         0:off   1:off   2:off   3:off   4:off   5:off   6:off
lisa            0:off   1:off   2:off   3:off   4:off   5:off   6:off
crond           0:off   1:off   2:on    3:off   4:on    5:on    6:off
openibd         0:off   1:off   2:on    3:off   4:on    5:on    6:off
cups            0:off   1:off   2:on    3:off   4:on    5:on    6:off
ripngd          0:off   1:off   2:off   3:off   4:off   5:off   6:off
iiim            0:off   1:off   2:on    3:off   4:on    5:on    6:off
cpuspeed        0:off   1:on    2:on    3:off   4:on    5:on    6:off
multipathd      0:off   1:off   2:off   3:off   4:off   5:off   6:off
apmd            0:off   1:off   2:on    3:off   4:on    5:on    6:off
rdisc           0:off   1:off   2:off   3:off   4:off   5:off   6:off
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
yppasswdd       0:off   1:off   2:off   3:off   4:off   5:off   6:off
rpcgssd         0:off   1:off   2:off   3:off   4:on    5:on    6:off
irda            0:off   1:off   2:off   3:off   4:off   5:off   6:off

– output truncated –
The first column gives the service name and further column gives the status of services at different run level starting from 1 to 6. Last script that will be executed is /etc/rd.d/rc.local. So any customization can be done in this script.
You can switch off or switch on any service for that run level using following command.
chkconfig off | on
Example:
chkconfig acpid off

This will turn off acpid service, so next time when you reboot, it wont start acpid serivce which its supposed to start at run level 4 and 5.
system-config-services is the graphical interface to chkconfig.
Same things can be done using system-config-services tool.
Hope this helps !!

Saturday, March 13, 2010

Linux Partitions

Creating Partition and Filesystem in Linux

Introduction
This post describes how to create a partitons in linux and use it. Creating a new partition for use is a 4 step process.
  1. You identify a disk and create a partition using fdisk
  2. You create a file system on that disk and assign a label
  3. You create an entry in /etc/fstab to make partition persistant accrose reboot
  4. You mount the partition for access to the user.
Lets start with creating a partition from a disk.
Creating Partition and filesystem
In my system I have /dev/sda as primary device and following are the different partitions
[root@10.176.87.179]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             2.9G  350M  2.4G  13% /
/dev/sda7             487M   18M  444M   4% /home
/dev/sda6             965M   18M  898M   2% /data
/dev/sda3             2.9G  1.7G  1.1G  62% /usr
/dev/sda1              99M   11M   83M  12% /boot
tmpfs                 252M     0  252M   0% /dev/shm
/dev/hdc              2.8G  2.8G     0 100% /cdrom

The total size for all these partitions (except cdrom) comes to 7.5G. Addition to that I have 1G swap partition created on /dev/sda5
[root@10.176.87.179]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       1020088 0       -1

So that makes it 8.5G. Total size of /dev/sda is 10G. This leaves 1.5G free for creating another partition.
1) create a partition using fdisk
fdisk -l will give the list of existing partition
[root@10.176.87.179]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         395     3068415   83  Linux
/dev/sda3             396         777     3068415   83  Linux
/dev/sda4             778        1305     4241160    5  Extended
/dev/sda5             778         904     1020096   82  Linux swap / Solaris
/dev/sda6             905        1031     1020096   83  Linux
/dev/sda7            1032        1095      514048+  83  Linux

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn’t contain a valid partition table
For creating a partition, we can use fdisk followed by device name.
[root@10.176.87.179]# fdisk /dev/sda
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (1096-1305, default 1096):
Using default value 1096
Last cylinder or +size or +sizeM or +sizeK (1096-1305, default 1305): +1G

Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         395     3068415   83  Linux
/dev/sda3             396         777     3068415   83  Linux
/dev/sda4             778        1305     4241160    5  Extended
/dev/sda5             778         904     1020096   82  Linux swap / Solaris
/dev/sda6             905        1031     1020096   83  Linux
/dev/sda7            1032        1095      514048+  83  Linux
/dev/sda8            1096        1218      987966   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

The above step creates a raw partition. Here it prompted for
Command (m for help):
and we entered “n”. “n” here means new partition. Then it asked for starting cylinder. By default it takes the cylinder in continuation. Else if we leave some cylinders in between that slot will be empty and we wont be able to use those unless if we want to create the partition of exact that size. So better to accept the default and create a partition in continuous cylinders.
Next input it ask is the end cylinder number. Usually its hard to calculate the number of cylinders depending on the size of slot we need. So we can directly enter the size of slot as +1G or +500M. Here G, M and K can be used representing GB, MB and KB. Remember to use + at the start.
Once these inputs are given, we can use “p” to print the partition list and see if its going to create correct partition. Please note that till now nothing has happened. We are just checking our setting by typing “p”. After checking when we type “w” that time its going to start creating a partition. So we can backoff any time using “quit” until we type “w”.
2) create a file system on that partition and assign a label
For creating a partition, following command is used.
mkfs.ext3
Following are the main and important options
-b -> This represent the block size to be used.
-i -> This represent the block/inode ratio.

inode is a pointer to each and every file in linux. For every file there is an inode. usually its not a good idea to give same number of inodes as number of blocks.
Example:
Partition size = 1000M
block size = 2K
Number of blocks = 500K (1000M/2K)
For each file created, however small it is, its going to use atleast 1 block. And for each file we need 1 inode value.
Now if there are 500K blocks, its not a good idea to give 500K as inode value. Because we are not going to have 500K files. If you thing about it usually in a normal file system some of the file will be larger then 2K (block size). In that case single file will occupy more number of blocks and but still number of inode used for that file will be only 1.
Another disadvantage of giving more number of inode values is that, it will take more space for storing those many values in inode table.
For more options on mkfs.ext3 command, see the man pages.
Lets try creating a file system.
[root@10.176.87.179]# mkfs.ext3 -b 2048 -i 4096 /dev/sda8
mke2fs 1.39 (29-May-2006)
Could not stat /dev/sda8 — No such file or directory

The device apparently does not exist; did you specify it correctly?
OK. Now we got this error. The reason we got this error is because, even though we created a partition, our kernel does not know about it.
When we create a partition, an entry goes in the partition table of that device. This partition table is maintained in the 1st sector of that device. During booting kernel reads the partition table and loads it in memory.
So does that mean that we need to reboot out system? Apperantly reboot can solve our problem, but we can solve the same without reboot as well. We have a command called partprob which will ask kernel to read the partition table on the device and load into memory. Doing that, kernel will know about new partition.
You can list the current partition which kernel is aware of using /proc/partitions file. /proc is a virtual file system in memory. This contains all the information which kernel is aware of and which is used by kernel.
[root@10.176.87.179]# cat /proc/partitions
major minor  #blocks  name

8     0   10485760 sda
8     1     104391 sda1
8     2    3068415 sda2
8     3    3068415 sda3
8     4          1 sda4
8     5    1020096 sda5
8     6    1020096 sda6
8     7     514048 sda7
8    16    5242880 sdb

So we can see here that partition sda8 is not loaded in memory. Now lets run partprobe command.
[root@10.176.87.179]# partprobe
Now if we see /proc/partitions we see sda8
[root@10.176.87.179]# cat /proc/partitions
major minor  #blocks  name

8     0   10485760 sda
8     1     104391 sda1
8     2    3068415 sda2
8     3    3068415 sda3
8     4          1 sda4
8     5    1020096 sda5
8     6    1020096 sda6
8     7     514048 sda7
8     8     987966 sda8
8    16    5242880 sdb

Now try the mkfs.ext3 command.
[root@10.176.87.179]# mkfs.ext3 -b 2048 -i 4096 -L /oracle /dev/sda8
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
247008 inodes, 493982 blocks
24699 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=506462208
31 block groups
16384 blocks per group, 16384 fragments per group
7968 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

So it has created the required file system.
-L is used to give label to that partition. This is not a mandatory option.
3) Create an entry in /etc/fstab to make partition persistant accrose reboot
Now to make this partition get mounted automatically when the system reboots, we should make entry in /etc/fstab file. /etc/fstab is the file which kernel reads during booting and mount the file system mentioned in this file.
This file has entry in following format
                   
Device Name -> Name of the partition which needs to be mounted
Mount Point -> Directory which is to be used as moint point
File system Type -> Type used for creating file system. ext3 in our case.
Mount Option -> Various options used during mount. Check man page for mkfs command to check various mount options.
Dump Frequency -> 0 – never dump, 1 – daily, 2 – every other day etc. This is a sort of taking  backup.
File System Check order -> Order in which file system is checked while the system boots. 0 – ignore, 1 – always for root etc.
So here is our entry will look like
[root@10.176.87.179]# cat /etc/fstab | grep oracle
LABEL=/oracle           /oracle                 ext3    defaults        0 0

4) mount the partition for access to the user.
[root@10.176.87.179]# mkdir /oracle
[root@10.176.87.179]# mount -a
[root@10.176.87.179]# cd /oracle
[root@10.176.87.179]# df -h .

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda8             935M   24M  863M   3% /oracle

mount -a is going to mount all the devices present in /etc/fstab file. You can also mount /dev/sda8 using following command
[root@10.176.87.179]# mount /dev/sda8 /oracle

hope this helps !!

Tuesday, March 2, 2010

Configuring poptop VPN Server

Hi Friends,

                  Let us discuss How to Configure poptop VPN Server on Linux(CentOS5.3) System.
1.) First of all Install all the required Libraries and pptd Server on Linux System.
2.) You can also make the use of yum to install the pptp server as...
         # yum -y install ppp
3.) After you make sure that you have ppp installed, download and install Poptop. You can get the RHEL/CentOS 5 RPMs from net easily.
4.) After installing Poptop, open the file /etc/pptpd.conf.
     # vi /etc/pptpd.conf
                   Go to the end of the file where you can see examples of localip and remoteip. Below them add your own values for localip and remoteip.
localip      10.0.0.1
remoteip     10.0.0.10-100



In the above, 10.0.0.1 will be used for the ppp interface and 10.0.0.10 - 10.0.0.100 will be assigned to the clients. You can also use different private IPs in ‘localip’ and ‘remoteip’, like 10.20.26.1 and 10.20.26.10-100.

5.) Next, open the file /etc/ppp/options.pptpd.
           #vi /etc/ppp/option.pptpd

6.) Uncomment the ms-dns lines (by removing the ‘#’ in front of them) and change them to the dns servers provided by your ISP or to public DNS servers like ones provided by OpenDNS.
               ms-dns 208.67.222.222
               ms-dns 208.67.220.220

     Thats all you need to change in the options.pptpd file.

7.) Next you will need to edit the file /etc/ppp/chap-secrets to add usernames and passwords for your clients. You need to enter the usernames and passwords in the following format.
          
# Secrets for authentication using CHAP
# client server secret IP addresses
username pptpd password *
username2 pptpd password2 *


You can also put a * in place of ‘pptpd’ just like there is a * below ‘IP addresses’. Also instead of a * below ‘IP addresses’ you can put the IP address from which the client will be connecting.


IP Forwarding and Firewall Rules:
 1.) Now we need to enable IP forwarding. So open the file /etc/sysctl.conf
        and set ‘net.ipv4.ip_forward’ to 1.       net.ipv4.ip_forward = 1

   To make the changes to sysctl.conf take effect, use the following command.
       # sysctl -p
   Or you can also use the following command to enable IP forwarding temporarily.
    # echo 1 > /proc/sys/net/ipv4/ip_forward

   2.) Next, configure iptables to do NAT.
    # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

  3.) Next, we need to allow TCP port 1723 and the GRE protocol through iptables.
    #iptables -A INPUT -i eth0 -p tcp --dport 1723 -j ACCEPT
    #iptables -A INPUT -i eth0 -p gre -j ACCEPT

  4.) Next, we need to allow TCP port 1723 and the GRE protocol through iptables.     #iptables -A INPUT -i eth0 -p tcp --dport 1723 -j ACCEPT
    #iptables -A INPUT -i eth0 -p gre -j ACCEPT


   5.) Now start the PPTP server if you haven’t already.
    #service pptpd start
 
        If you followed the above steps correctly, the PPTP server should now be ready for use.