martes, 20 de enero de 2015

Building a kernel module on SLES 11 SP3



Building a kernel module on SLES 11 SP3

In this example I am using zncryptfs kernel module from Cloudera/Gazzang repo.

[root@hive-1 ~]# zypper install zncrypt-kernel-module

This will ask you to install a kernel module that doesn’t have the ‘dkms’ dependency, we will install the kernel module breaking that dependency:

Problem: nothing provides dkms needed by zncrypt-kernel-module-3.4.2_SLES11-1024.x86_64
Solution 1: do not install zncrypt-kernel-module-3.4.2_SLES11-1024.x86_64
Solution 2: break zncrypt-kernel-module-3.4.2_SLES11-1024.x86_64 by ignoring some of its dependencies

Choose from above solutions by number or cancel [1/2/c] (c): 2

Select option 2.

3.1.2 Update to the latest kernel module

Update the kernel:
hive-ne-SLES-1:~ # zypper install -y kernel-default
Several operations

Then reboot; the kernel version should be updated after reboot.

hive-ne-SLES-1:~ # uname -r
3.0.101-0.40-default



kernel module needs to be build manually 
then:
First requirement to build the kernel module is to have the kernel headers installed, to install them check the kernel version and install its kernel headers accordingly:


hive-ne-SLES-1:~ #zypper install -y kernel-default-devel
…..
Several operations
….

Once the kernel headers are installed you will see the include files at /usr/src/linux-3.0.101-0.40/include; then go to the zncrypt kernel module source code directory to build it.

hive-ne-SLES-1:~ # cd /usr/src/zncryptfs-3.4.2/

You may have the following error message:
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # make
Searching known bugs on kernel...
make -C /lib/modules/3.0.101-0.40-default/build M=/usr/src/zncryptfs-3.4.2 modules
make: *** /lib/modules/3.0.101-0.40-default/build: No such file or directory.  Stop.
make: *** [all] Error 2
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 #

To fix previous error create a symlink from /lib/modules/$(uname -r)/build to the x86_64 obj headers directory, then execute again make

hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # ln -s /usr/src/linux-3.0.101-0.40-obj/x86_64/default/ /lib/modules/$(uname -r)/build
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # make
Searching known bugs on kernel...
make -C /lib/modules/3.0.101-0.40-default/build M=/usr/src/zncryptfs-3.4.2 modules
make[1]: Entering directory `/usr/src/linux-3.0.101-0.40-obj/x86_64/default'
make -C ../../../linux-3.0.101-0.40 O=/usr/src/linux-3.0.101-0.40-obj/x86_64/default/. modules
 CC [M]  /usr/src/zncryptfs-3.4.2/main.o
 CC [M]  /usr/src/zncryptfs-3.4.2/hooks.o
 CC [M]  /usr/src/zncryptfs-3.4.2/messaging.o
 CC [M]  /usr/src/zncryptfs-3.4.2/auth.o
 CC [M]  /usr/src/zncryptfs-3.4.2/acl.o
 CC [M]  /usr/src/zncryptfs-3.4.2/profile.o
 CC [M]  /usr/src/zncryptfs-3.4.2/stats.o
 CC [M]  /usr/src/zncryptfs-3.4.2/procfs.o
 CC [M]  /usr/src/zncryptfs-3.4.2/timeconv.o
 CC [M]  /usr/src/zncryptfs-3.4.2/debug.o
 LD [M]  /usr/src/zncryptfs-3.4.2/zncryptfs.o
 Building modules, stage 2.
 MODPOST 1 modules
 CC      /usr/src/zncryptfs-3.4.2/zncryptfs.mod.o
 LD [M]  /usr/src/zncryptfs-3.4.2/zncryptfs.ko
make[1]: Leaving directory `/usr/src/linux-3.0.101-0.40-obj/x86_64/default'
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 #

At this point the kernel module is build you can see it at /usr/src/zncryptfs-3.4.2/zncryptfs.ko

3.1.3 Load the module

hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # depmod -a
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # modprobe zncryptfs
FATAL: Module zncryptfs not found.
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 #

That error means that the kernel module is not part of the modules of the current kernel $(uname -r).

To fix that a symlink needs to be created to point to this kernel module or it can be copied.

hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # ln -s /usr/src/zncryptfs-3.4.2/zncryptfs.ko /lib/modules/$(uname -r)/
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # depmod -a
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # modprobe zncryptfs
FATAL: module '/lib/modules/3.0.101-0.8-default/zncryptfs.ko' is unsupported
Use --allow-unsupported or set allow_unsupported_modules to 1 in
/etc/modprobe.d/unsupported-modules
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 #

This is the last error we might see, it refers that the policy to allow unsupported modules, just change the variable of the config file as indicated (set allow_unsupported_modules to 1) :

hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # vi /etc/modprobe.d/unsupported-modules

Then run:

hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # depmod -a
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # modprobe zncryptfs
hive-ne-SLES-1:/usr/src/zncryptfs-3.4.2 # lsmod | grep zncrypt
zncryptfs              82143  0


The module is loaded and ready to be used

Enjoy!
P.S. There is a Queen that has her own flag

No hay comentarios:

Publicar un comentario en la entrada