lunes, 4 de marzo de 2013

Getting EC2 XEN Kernel Headers for Centos to build kernel modules

Hey..

So this 'my First time'. I am showing how to get the headers for a xen kernel and for centos, if you are looking the same for ubuntu, at the bottom I show a link that could help; I will  do it by an example. 

Let's say that we have the EC2 ami: ami-01996f68  (For this particular ami see appendix A)




Distro: centos 5.5 x64
Kernel: 2.6.18-194.26.1.el5xen
Instance user: root

First review your installed  rpms, just to see what you have:

-bash-3.2#  uname -a ; rpm -qa kernel\* | sort
Linux ip-10-142-132-23 2.6.18-194.26.1.el5xen #1 SMP Tue Nov 9 13:35:30 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
kernel-xen-2.6.18-194.26.1.el5
-bash-3.2# 

Just to verify that there are not headers:

-bash-3.2# ls /usr/src/kernels/-bash-3.2# 

Ok, there is nothing. 

1. Getting headers from kernel-xen-devel installation

Now install kernel-xen-devel, If you are this contains the headers that you are looking for, if you are not then go to section 2.

-bash-3.2# yum install  kernel-xen-devel

See: 

# ls /usr/src/kernels/
2.6.18-348.1.1.el5-xen-x86_64  2.6.18-348.1.1.el5xen-x86_64
-bash-3.2# 

Don't use '.el5-xen' use the one with "el5xen" because your kernel is:  2.6.18-194.26.1.el5xen

Wait!.. what? my kernel is:  2.6.18-194.26.1.el5xen and will use 2.6.18-348.1.1.el5xen-x86_64? Yes, let's give it a try.. if doesn't work move to section 2.

There you go, you have some headers:

-bash-3.2# ls /usr/src/kernels/2.6.18-348.1.1.el5xen-x86_64/
arch   crypto   fs       init  kabi_whitelist  lib       mm           Module.markers  net      scripts   sound                                 usr
block  drivers  include  ipc   kernel          Makefile  Module.kabi  Module.symvers  samples  security  symsets-2.6.18-348.1.1.el5xen.tar.gz
-bash-3.2# 

Ok, now let's create the symlink. First do a backup of current /build symlink:

-bash-3.2# mv /lib/modules/2.6.18-194.26.1.el5xen/build /lib/modules/2.6.18-194.26.1.el5xen/build.back 
-bash-3.2#

Then create the symlink:

-bash-3.2# ln -s /usr/src/kernels/2.6.18-348.1.1.el5xen-x86_64/ /lib/modules/2.6.18-194.26.1.el5xen/build
-bash-3.2#

There you go, try to build your kernel kernel module at your XEN kernel. If you were not lucky building it move to section 2.

i.e. I just build gazzang zNcrypt kernel module:

  Installing     : ezncryptfs                                                                                                                   Removing existing ezncryptfs DKMS kernel modules...
Building ezncryptfs 1.1.3_rhel5 DKMS kernel module...
Successfully installed ezncryptfs module !


2. Getting headers from a repo:

This is the long way, and useful. Trick is to find the rpms of your installed kernel.

First, you need to get from a repo kernel-xen-devel-'uname -r', in our example just google: kernel-xen-devel-2.6.18-194.26.1.el5xen

Now, use your search skills over the web, I found: kernel-xen-devel-2.6.18-194.el5.x86_64.rpm from: http://vault.centos.org/5.5/os/x86_64/CentOS/

execute:

[user@ip-10-142-132-23 ~]$ pwd/home/user[user@ip-10-142-132-23 ~]$ wget http://vault.centos.org/5.5/os/x86_64/CentOS/kernel-xen-devel-2.6.18-194.el5.x86_64.rpm
--2013-03-04 14:08:10--  http://vault.centos.org/5.5/os/x86_64/CentOS/kernel-xen-devel-2.6.18-194.el5.x86_64.rpmResolving vault.centos.org... 216.151.172.58Connecting to vault.centos.org|216.151.172.58|:80... connected.HTTP request sent, awaiting response... 200 OK
Length: 5641264 (5.4M) [application/x-rpm]Saving to: `kernel-xen-devel-2.6.18-194.el5.x86_64.rpm'
100%[============================================================================================================>] 5,641,264   8.02M/s   in 0.7s  
 

2013-03-04 14:08:11 (8.02 MB/s) - `kernel-xen-devel-2.6.18-194.el5.x86_64.rpm' saved [5641264/5641264]
[user@ip-10-142-132-23 ~]$ lskernel-xen-devel-2.6.18-194.el5.x86_64.rpm
[user@ip-10-142-132-23 ~]$


Or download it to your local then use scp.

Install it by rpm, remember it is recommended to install any rpm package as non-root.

[user@ip-10-142-132-23 ~]$ sudo rpm -i kernel-xen-devel-2.6.18-194.el5.x86_64.rpm
package kernel-xen-devel-2.6.18-348.1.1.el5.x86_64 (which is newer than kernel-xen-devel-2.6.18-194.el5.x86_64) is already installed
[user@ip-10-142-132-23 ~]$ 

ups! .. ok, uninstall 348 from there. ( it is the one that was installed in section 1)


bash-3.2$ uname -a ; rpm -qa kernel\* | sort
Linux ip-10-142-132-23 2.6.18-194.26.1.el5xen
#1 SMP Tue Nov 9 13:35:30 EST 2010 x86_64 x86_64 x86_64 GNU/Linuxkernel-headers-2.6.18-348.1.1.el5kernel-xen-2.6.18-194.26.1.el5kernel-xen-devel-2.6.18-348.1.1.el5
bash-3.2$ rpm -e kernel-xen-devel-2.6.18-348.1.1.el5
error: Failed dependencies: kernel-devel is needed by (installed) dkms-2.1.1.2-1.el5.rf.noarchbash-3.2$ sudo rpm -e kernel-xen-devel-2.6.18-348.1.1.el5
error: Failed dependencies: kernel-devel is needed by (installed) dkms-2.1.1.2-1.el5.rf.noarch
bash-3.2$ 

Ohh I already installed dkms as a zncrypt dependency, because I was lucky on section 1, you might not be lucky on section 1 but it was installed anyway.

Fix this by:

-bash-3.2#  rpm -e dkms-2.1.1.2-1.el5.rf.noarch
-bash-3.2#  rpm -e kernel-xen-devel-2.6.18-348.1.1.el5

Let's try to install again our rpm as non-root user:

 bash-3.2$ uname -a ; rpm -qa kernel\* | sort
Linux ip-10-142-132-23 2.6.18-194.26.1.el5xen #1 SMP Tue Nov 9 13:35:30 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
kernel-headers-2.6.18-348.1.1.el5
kernel-xen-2.6.18-194.26.1.el5
kernel-xen-devel-2.6.18-194.el5
bash-3.2$ uname -r
2.6.18-194.26.1.el5xen
bash-3.2$

You can see that our kernel matches with kernel-xen-devel. 

Ok, now let's create the symlink. First do a backup of current /build symlink if you wish:

-bash-3.2# mv /lib/modules/2.6.18-194.26.1.el5xen/build /lib/modules/2.6.18-194.26.1.el5xen/build.back.old

Then create the symlink:

-bash-3.2#  ln -s /usr/src/kernels/2.6.18-194.el5xen-x86_64/ /lib/modules/2.6.18-194.26.1.el5xen/build


Time to build! Enjoy!



I don't need to say that you need to change the commands to your named kernel. Ups, Just did it! Ok, geek comment.


Option 3???  Please comment!




If you need to do this at ubuntu, perhaps follow link might help you: http://daemonscorner.blogspot.mx/2009/10/installing-linux-kernel-headers-for.html  
(I have not tried it)


---------------------------------------------------------------------------------------------------------

Appendix A. 


Some errors might appear when changing to root user in this ami.

bash: /root/.bash_profile: No such file or directory
bash: --: command not found
bash: /root/.bash_profile: No such file or directory
[root@ip-10-142-132-23 user]# ls

To fix this comment some lines as root to .bashrc

Follow is the complete file with the lines already commented (bolded)... just compare with yours:
#cat .bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
--
#/root/.bash_profile
# .bash_profile
# Get the aliases and functions
#if [ -f ~/.bashrc ]; then
#        . ~/.bashrc
#fi

# User specific environment and startup programs
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/root/bin
export PATH
unset USERNAME


-Kozlex

P.D. As the only nation to use six colors in their flag's primary design, South Africa gets first place on our list of the world's most colorful flags

No hay comentarios:

Publicar un comentario