Monday, February 13, 2012

Module Management in RHEL / CentOS

The Linux kernel allows drivers and features to be compiled as modules rather than as part of the kernel itself. This means that users can often change features in the kernel or add drivers without recompiling, and that the Linux kernel doesn't have to carry a lot of unnecessary baggage. Want to learn how to manage your modules? It's easy to do, just keep reading.

In this tutorial, we'll walk through the steps of seeing what's already loaded in the running kernel, and adding and removing modules from the kernel.

What's Loaded

The first utilities that you'll want to get to know are lsmod and modinfo. Open a terminal and run lsmod. Note that you won't need to use sudo or log in as root just to probe the modules in the system.

You'll see output like this when you use lsmod:

Module                  Size  Used by
parport_pc             18855  0
ppdev                   5030  0
lp                      7462  0
sco                     7209  2
parport                27954  3 parport_pc,ppdev,lp
bridge                 39630  0
stp                     1440  1 bridge
bnep                    9427  2

This shows the modules that are loaded, their size, and whether they're being used by other modules. Take the parport module, for instance. It's being used by several other modules, but what are they? The modinfo utility will tell us — maybe.

Run #modinfo parport, and you'll see something like this:

filename:       /lib/modules/2.6.32-5-amd64/kernel/drivers/parport/parport.ko
license:        GPL
vermagic:       2.6.32-5-amd64 SMP mod_unload modversions

It tells us where the module is found, and its license, and that it has no dependencies. Unfortunately, we really don't know any more than where we started because this module author has chosen not to provide a description of the module. But many modules will have a description and provide some indication what they are used for. Since we got no joy from the parport module, what about trying to find out about one of the modules that depend on it? Let's try modinfo parport_pc. This, at least on my system, produces fairly hefty output, but the relevant part here is the description field which provides:

description: PC-style parallel port driver

So we can surmise that the parport driver has something to do with supporting a Parallel Port. In fact, the parport module is generic support for parallel ports, and parport_pc provides support for parallel ports on x86/x86_64 systems. This isn't something you'll find with modinfo, unfortunately. But when all else fails, check the kernel source under the Documentation directory.

Removing Modules

Modules can be removed using the rmmod utility. The usage is simple, just rmmod modulename. However, if we try to remove the parport module, we get this error:

ERROR: Module parport is in use by parport_pc,ppdev,lp

You can force module removal using rmmod -f, but that's not a good idea, usually. A better way to do it is to use modprobe -r which will automatically look to see what other modules depend on it, and unload those modules as well. If they're in use, then modprobe will refuse to remove them as well, unless you use the -f option with modprobe too.

Installing Modules

What if you have a module you want to load into the kernel? You can do that with insmod or modprobe.

The preferred method is modprobe, because it will also load any modules that the requested module depends on. For instance, if I didn't have the parport module loaded and went to load the lp or parport_pc modules, modprobe would go ahead and load parport as well.

To load a module using modprobe run #modprobe modulename.

Blacklisting Modules

You may on occasion need to "blacklist" a module. Why would you need this feature? Sometimes a module will cause a conflict with another module, is superseded by another module, or is otherwise undesirable.

To blacklist a module, the easiest way to do it (there's usually more than one way to do things...) is to add the module to /etc/modprobe.d/blacklist.conf. For instance, on Debian systems the evbug module is automatically blacklisted because it's not something most users will need. To add a module to the blacklist, just add one line to the blacklist.conf file:

blacklist modulename

Adding multiple IP addresses on one Ethernet

If we have one network interface, eth0. And when you add IP addresses, you actually create virtual network interfaces named eth0:1, eth0:2, ...... eth0:n.

How to set it on temporary basis on all OS's:

#ifconfig eth0:1 up [IP address] netmask [chosen netmask, if unsure use].

You can add commands like this to your startup scripts to have them come up on reboot, but there is cleaner way which is maintioned below;

How to set it Permanently basis on RHEL / CentOS :

All interface configuration files are located in "/etc/sysconfig/network-scripts/". Each interface is represented by a file corresponding to ifcfg-eth<x> where <x> represents the unique interface number for that card (e.g. the first interface card is represented by ifcfg-eth0). To create an alias for that interface, you need to create a file in the format of ifcfg-eth0:<y> where <y> represents the alias number (e.g. the 2nd ip for the first card would be ifcfg-eth0:1). To set up two ip addresses on a ethernet edit/create the following files as noted (substituting your ip addresses where denoted by x's):





This assumes all ip addresses are in the same range. See the RedHat Enterprise Linux Reference Guide for details on the configurable parameters. Finally, running "service network restart" will restart the network interfaces (probably best to do this from lish). Hope it helps.

NIC Bonding : Bind multiple Network Interfaces (NIC) Into a Single Interface

The first step is to rename the server-change /etc/sysconfig/network to match your new server name.That’s easy :)

Now to the bonding driver. RHEL6 and OL 6 have deprecated /etc/modprobe.conf in favour of /etc/modprobe.d and its configuration files. It’s still necessary to tell the kernel that it should use the bonding driver for my new device, bond0 so I created a new file /etc/modprobe.d/bonding.conf with just one line in it:

alias bond0 bonding

That’s it, don’t put any further information about module parameters in the file, this is deprecated. The documentation clearly states “Important: put all bonding module parameters in ifcfg-bondN files”.

Now I had to create the configuration files for eth0, eth1 and bond0. They are created as follows:

File: ifcfg-eth0

File: ifcfg-eth1

File: ifcfg-bond0

 BONDING_OPTS="<bonding parameters separated by spaces>"

Now for the bonding paramters-there are a few of interest. First, I wanted to set the mode to active-passive, which is Oracle recommended (with the rationale: it is simple). Additionally, you have to set either the arp_interval/arp_target parameters or a value to miimon to allow for speedy link failure detection. My BONDING_OPTS for bond0 is therefore as follows:

BONDING_OPTS=”miimon=1000 mode=active-backup”

Have a look at the documentation for more detail about the options.

The test is going to be simple: first I’ll bring up the interface bond0 by issuing a “system network restart” command on the xen console, followed by a “xm network-detach” command.The output of the network restart command is here:

[root@rhel6ref network-scripts]# service network restart
Shutting down loopback interface:  [  OK  ]
Bringing up loopback interface:  [  OK  ]
Bringing up interface bond0:  [  OK  ]

[root@rhel6ref network-scripts]# ifconfig
bond0     Link encap:Ethernet  HWaddr 00:16:1E:1B:1D:1F
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::216:1eff:fe1b:1d1f/64 Scope:Link
          RX packets:297 errors:0 dropped:0 overruns:0 frame:0
          TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:9002 (8.7 KiB)  TX bytes:1824 (1.7 KiB)

eth0      Link encap:Ethernet  HWaddr 00:16:1E:1B:1D:1F
          RX packets:214 errors:0 dropped:0 overruns:0 frame:0
          TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6335 (6.1 KiB)  TX bytes:1272 (1.2 KiB)

eth1      Link encap:Ethernet  HWaddr 00:16:1E:1B:1D:1F
          RX packets:83 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2667 (2.6 KiB)  TX bytes:552 (552.0 b)

lo        Link encap:Local Loopback
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

The kernel traces these operations in /var/log/messages:

 May  1 07:55:49 rhel6ref kernel: bonding: bond0: Setting MII monitoring interval to 1000.
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: setting mode to active-backup (1).
 May  1 07:55:49 rhel6ref kernel: ADDRCONF(NETDEV_UP): bond0: link is not ready
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: Adding slave eth0.
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: Warning: failed to get speed and duplex from eth0, assumed to be 100Mb/sec and Full.
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: making interface eth0 the new active one.
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: first active interface up!
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: enslaving eth0 as an active interface with an up link.
 May  1 07:55:49 rhel6ref kernel: ADDRCONF(NETDEV_CHANGE): bond0: link becomes ready
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: Adding slave eth1.
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: Warning: failed to get speed and duplex from eth1, assumed to be 100Mb/sec and Full.
 May  1 07:55:49 rhel6ref kernel: bonding: bond0: enslaving eth1 as a backup interface with an up link.

This shows an active device of eth0, with eth1 as the passive device. Note that the MAC addresses of all devices are identical (which is expected behaviour). Now let’s see what happens to the channel failover when I take a NIC offline. First of all I have to check xenstore which NICs are present:

Official Document on NIC Bonding

Enabling & Disabling Promiscuous mode on Ethernet

                     You can try below things to get it done;

In RHEL / CentOS :

#/sbin/ifconfig ethX promisc   (Temporary solution, You will loose setting if you reboot VM )

To set it permanently Edit file –

#cat /etc/sysconfig/network-scripts/ifcfg-eth1



Temporary solution is same as above.

But for permanent change edit file “ /etc/sysconfig/network/ifcfg-rth-id-xx:xx:xx:xx:xx:xx”

Here you can add line “ifconfig eth0 promisc” OR if this doesn’t work add “PROMISC=yes

And to disable this mode either simply remove added line from the respective files or use command ;

#/sbin/ifconfig ethX -promisc   (Temporary solution)