0x90
0x90

Reputation: 41002

Compiling a kernel module for openvz VM?

I have an openvz machine which I am root on, it is a virtual machine I am ssh to:

>uname -a
Linux molo 2.6.32-042stab084.25 #1 SMP Wed Feb 12 16:04:42 MSK 2014 x86_64 x86_64 x86_64 GNU/Linux

I am trying to build an hello world kernel module:

hello.c:

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/init.h>         /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}
module_init(hello_start);
module_exit(hello_end);

Makefile:

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

And when I am trying to compile hello.c:

#make
make -C /lib/modules/2.6.32-042stab084.25/build M=/local/my_modules modules
make: *** /lib/modules/2.6.32-042stab084.25/build: No such file or directory.  Stop.
make: *** [all] Error 2

That is the kernel version uname -r reports

#uname -r
2.6.32-042stab084.25

The following didn't help too:

$sudo apt-get install "linux-headers-$(uname -r)"
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-2.6.32-042stab084.25
E: Couldn't find any package by regex 'linux-headers-2.6.32-042stab084.25'

Here is the /lib/modules directory:

ls /lib/modules/2.6.32-042stab084.25/

modules.alias      modules.ccwmap  modules.dep.bin  modules.ieee1394map  modules.isapnpmap  modules.pcimap    modules.softdep  modules.symbols.bin
modules.alias.bin  modules.dep     modules.devname  modules.inputmap     modules.ofmap      modules.seriomap  modules.symbols  modules.usbmap

Upvotes: 1

Views: 1923

Answers (2)

Alec Istomin
Alec Istomin

Reputation: 311

Download and install linux-headers package from openvz page (more on http://openvz.org/Installation_on_Debian)

1) Add source

cat << EOF > /etc/apt/sources.list.d/openvz-rhel6.list
deb http://download.openvz.org/debian wheezy main
# deb http://download.openvz.org/debian wheezy-test main
EOF

2) Install

wget http://ftp.openvz.org/debian/archive.key
sudo apt-key add archive.key
sudo apt-get update
sudo apt-get install "linux-headers-$(uname -r)"

Remember that you can only do this from the "Host", not from inside of a OpenVZ VPS. Meaning that loading kernel drivers to kernel is only permitted from the Host and would affect all containers on that Host.

Upvotes: 2

user2485710
user2485710

Reputation: 9811

Your kernel doesn't appear to be one of the ones provided by Canonical, usually official kernels end with a version number or with the generic or other suffix.

Usually you find the package with the kernel headers under pool/main/l as you can see here in the case of the security repository for Ubuntu Saucy.

You should ask the question to the person that provided the kernel that you are using, there is not that much you can do without more information unless you are willing to go for an officially supported kernel.

Upvotes: 1

Related Questions