Friday, August 13, 2010

Linux Kernel panic reboot

By default after a kernel panic Linux just waits there for a sysadmin to hit the restart or powercycle button.  This is because of the value set on "kernel.panic" parameter.

[root@linux23 ~]# cat /proc/sys/kernel/panic
[root@linux23 ~]# sysctl -a | grep kernel.panic
kernel.panic = 0
[root@linux23 ~]#

To disable this and make the Linux OS reboot after a kernel panic, we have to set an integer N greater than zero to the paramter "kernel.panic", where "N" is the number of seconds to wait before a automatic reboot.  For example , if you set N = 10 , then the system waits for 10 seconds before automatic reboot. To make this permanent, edit /etc/sysctl.conf and set it.

[root@linux23 ~]# echo "10" > /proc/sys/kernel/panic
[root@linux23 ~]# grep kernel.panic /etc/sysctl.conf
kernel.panic = 10
[root@linux23 ~]#

Disable ipv6 on RHEL 4 and 5

Edit /etc/sysconfig/network and change
Edit /etc/modprobe.conf and add these lines (if they're not in it):
alias net-pf-10 off
alias ipv6 off

Stop the ipv6tables service by typing:
service ip6tables stop
Disable the ipv6tables service by typing:
chkconfig ip6tables off
After these changes, IPv6 will be disabled after the next reboot of your system.

Why is there no free RAM in Linux? or Why Memory usage is 100% in Linux?

Traditional Unix tools like 'top' often report a surprisingly small amount of free memory after a system has been running for a while. For instance, after about 3 hours of uptime, the machine I'm writing this on reports under 60 MB of free memory, even though I have 512 MB of RAM on the system. Where does it all go?

The biggest place it's being used is in the disk cache, which is currently over 290 MB. This is reported by top as "cached". Cached memory is essentially free, in that it can be replaced quickly if a running (or newly starting) program needs the memory.

The reason Linux uses so much memory for disk cache is because the RAM is wasted if it isn't used. Keeping the cache means that if something needs the same data again, there's a good chance it will still be in the cache in memory. Fetching the information from there is around 1,000 times quicker than getting it from the hard disk. If it's not found in the cache, the hard disk needs to be read anyway, but in that case nothing has been lost in time.

To see a better estimation of how much memory is really free for applications to use, run the command:
free m

The -m option stands for megabytes, and the output will look something like this:
             total       used       free     shared    buffers     cached
Mem:           503        451         52          0         14        293
-/+ buffers/cache:        143        360
Swap:         1027          0       1027

The -/+ buffers/cache line shows how much memory is used and free from the perspective of the applications. Generally speaking, if little swap is being used, memory usage isn't impacting performance at all.

Notice that I have 512 MB of memory in my machine, but only 503 is listed as available by free. This is mainly because the kernel can't be swapped out, so the memory it occupies could never be freed. There may also be regions of memory reserved for/by the hardware for other purposes as well, depending on the system architecture.

The difference among VIRT, RES, and SHR in top output
VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card's RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.

RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.

SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.

The difference between buffers and cache
Buffers are associated with a specific block device, and cover caching of filesystem metadata as well as tracking in-flight pages. The cache only contains parked file data. That is, the buffers remember what's in directories, what file permissions are, and keep track of what memory is being written from or read to for a particular block device. The cache only contains the contents of the files themselves.

Corrections and additions to this section welcome; I've done a bit of guesswork based on tracing how /proc/meminfo is produced to arrive at these conclusions.

Swappiness (2.6 kernels)
Since 2.6, there has been a way to tune how much Linux favors swapping out to disk compared to shrinking the caches when memory gets full.

When an application needs memory and all the RAM is fully occupied, the kernel has two ways to free some memory at its disposal: it can either reduce the disk cache in the RAM by eliminating the oldest data or it may swap some less used portions (pages) of programs out to the swap partition on disk. It is not easy to predict which method would be more efficient.
The kernel makes a choice by roughly guessing the effectiveness of the two methods at a given instant, based on the recent history of activity.

Before the 2.6 kernels, the user had no possible means to influence the calculations and there could happen situations where the kernel often made the wrong choice, leading to thrashing and slow performance. The addition of swappiness in 2.6 changes this.

Swappiness takes a value between 0 and 100 to change the balance between swapping applications and freeing cache. At 100, the kernel will always prefer to find inactive pages and swap them out; in other cases, whether a swapout occurs depends on how much application memory is in use and how poorly the cache is doing at finding and releasing inactive items.

The default swappiness is 60. A value of 0 gives something close to the old behavior where applications that wanted memory could shrink the cache to a tiny fraction of RAM. For laptops which would prefer to let their disk spin down, a value of 20 or less is recommended.

As a sysctl, the swappiness can be set at runtime with either of the following commands:
# sysctl -w vm.swappiness=30
# echo 30 >/proc/sys/vm/swappiness

The default when Gentoo boots can also be set in /etc/sysctl.conf:
# Control how much the kernel should favor swapping out applications (0-100)
vm.swappiness = 30

Some patchsets allow the kernel to auto-tune the swappiness level as it sees fit; they may not keep a user-set value.

print commands in Linux

To see a list of available printers:

# lpstat -p -d

To print the file to printer "MyPrinter"

# lpr -P MyPrinter filename

To view (query) the print queue, use the lpq or lpstat command. When entered without arguments, it displays the contents of the default print queue.

# lpq
# lpstat

To list the default printer

# lpstat -d

To know the status of default printer

# lpstat -p

If the printer status is disabled, you need to enable the printer using "enable" command as follows.

# /usr/bin/enable <PrinterName>

To disable the printer

# /usr/bin/disable -c <PrinterName>

To reset the print queue, you have to disable and reenable as follows

# /usr/bin/disable -c <PrinterName>
# /usr/bin/enable <PrinterName>

To remove the print job

# lprm <job Number>

How can I unlock a SAN disk in AIX?

I got my LUN mapped to my system, but when I try to create my Volume Group with   mkvg -f vpath100   all I get is an I/O error. What can I do?
Probably there is still a SAN lock on the disk. Try to unlock it with:
 # lquerypv -ch /dev/vpath100
and retry to create your Volume Group.

How can I directly read out the VGDA of a PV (hdisk)?

Information about VGx, LVx, filesystems, etc. are stored in the ODM. But these information are also written to the VGDA of the disks itself. You can read the information directly from the disk's VGDA with a command like this:
 # lqueryvg -Atp hdisk100
You can use
 # redefinevg -d hdisk100 myvg
to synchronize the ODM with the information of the VGDA. You can also synchronize the VGDA with the information stored in the ODM:
 # synclvodm myvg

How to set a static routes in AIX

You can use the route command to set a static route. But this way you don't get it back after reboot.
To make a route persistent you need to change inet0. First check which routes are already set:
 # lsattr -El inet0 -a route
 route net,-hopcount,0,,0, Route True
 route net,-hopcount,,,,,,, Route True

These routes would be set with:
 # chdev -l inet0 -a route=net,-hopcount,0,,0,
 # chdev -l inet0 -a route=net,-hopcount,,,,,,,

To remove these specific static routes:
 # chdev -l inet0 -a delroute=net,-hopcount,0,,0,
 # chdev -l inet0 -a delroute=net,-hopcount,,,,,,,

In this route string is the netmask, the destination net, and the gateway.
For hostroutes the keyword net has to be replaced with host.

Difference between Ethernet Interface(en0) and Ethernet adapter (ent0)

AIX differentiates between hardware adapters, their interfaces and protocols standards associated.

To recognize interface card AIX uses three notations:
ent, en and et.
All are different and are described below and the sake of completeness I am using 0 at the end:
The notation ent0 is used to specify the hardware adapter. It has nothing to do with the TCP/IP address. The parameters associated with ent0 can be seen as below:
# lsattr –El ent0
It will show parameters related to card.
It shows adapter_names, alt_addr, auto_recovery, backup_adapter, hash_mode, mode, netaddr, noloss_failover, num_retries, retry_time, use_alt_addr, use_jumbo_frame.
en0 represents the interface associated with hardware adapter ent0. The notation en0 is used for Standard Ethernet(inet). The TCP/IP address is associated with this interface.
The parameters associated with en0 can be seen as below:
#lsattr –El en0
It'll shows all the parameters related with the interface en0 of the adapter ent0.
It shows alias4, alias6, arp, authority, broadcast=1500, mtu, netaddr, netaddr6, netmask, prefixlen, remmtu, rfc1323, security, state, tcp_mssdflt, tcp_nodelay, tcp_recvspace, tcp_sendspace.
Rest everything is same except mtu(Maximum Transfer Unit) value. Which is 1500 as per the standard ethernet protocol.
et0 represents the interface associated with hardware adapter ent0. The notation et0 is used for IEEE 802.3 Ethernet(inet). If you are using standard ethernet protocol then it will not have TCP/IP address.
The parameters associated with et0 can be seen as below:
#lsattr –El et0
It'll shows all the parameters related with the interface et0 of the adapter ent0.
It shows alias4, alias6, arp, authority, broadcast, mtu=1492, netaddr, netaddr6, netmask, prefixlen, remmtu, rfc1323, security, state, tcp_mssdflt, tcp_nodelay, tcp_recvspace, tcp_sendspace.
Note here as well that the MTU shown will be 1492 as per IEEE 802.3 standard. Rest all parameters will be same. Also, netaddr, netmask fields will be empty fr et0.

Are these terms interchangable or is there a difference between them? I always get confused with these terms. What does en0 and ent0 mean and the difference between these?

AIX differentiates between a network adapter and network interface:

Network adapter Represents the layer-2 device, for example, the Ethernet adapter ent0 has a MAC address, such as 06:56:C0:00:20:03

Network interface Represents the layer-3 device, for example the Ethernet interface en0 has an IP address, such as

Typically, a network interface is attached to a network adapter, for example, an Ethernet interface en0 is attached to an Ethernet adapter ent0.

There are also some network interfaces in AIX that are not attached to a network adapter, for example, the loopback interface lo0 or a Virtual IP Address (VIPA) interface, such as vi0, if defined.

Hhow to disable first time password change in AIX

Clear the ADMCHG flag of the user account with "pwdadm -c <user>".


# pwdadm –c username