For my thesis I am creating a Manet using the protocol ARAN. To install the protocol I'm using this manual, but the first step, the creation of trace_route, I received errors such as:
-linux/module.h: No such file or directory
-linux/procs_Fs: No such file or directory
-linux/skbuff: No such file or directory
I searched the web and found out that the problem is in the headers, but I do not find the solution ...
P.S. I am using Ubuntu 10.04 LTS Kernel 2.6.33 recompiled
You're missing the Linux kernel headers which allow you to compile code against the Linux kernel.
To install just the headers in Ubuntu:
$ sudo apt-get install linux-headers-$(uname -r)
To install the entire Linux kernel source in Ubuntu:
$ sudo apt-get install linux-source
Note that you should use the kernel headers that match the kernel you are running.
**/*source file name is basic.c */**
#include <linux/init.h>
#include <linux/module.h>
/*MODULE_LICENSE("Dual BSD/GPL");*/
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
=====================================
now make file for ubuntu
/*at first type on ur terminal that $(uname -r) then u will get the version..
that is using on ur system */
obj-m +=basic.o
KDIR =//usr/src/linux-headers-3.13.0-44-generic
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
================================================
To run the code
$sudo insmode basic.ko
$dmesg
u will get the output
$sudo rmmod basic.ko
$dmesg
Related
I'm trying to learn how to build a minimal initramfs for Linux. I set CONFIG_INITRAMFS_SOURCE="asd", created asd directory, inside there's an init file compiled using gcc -fpic -static main.c -o init. In the kernel log I'm getting the following error:
Run /init as init process
Failed to execute /init (error -8)
Here's the input source code:
int main() {
printf("Hello, world!\n");
for(;;);
}
What am I doing wrong?
It works with a defconfig kernel and CONFIG_INITRAMFS_SOURCE set. In the directory I had to make the node dev/console.
mkdir dev
sudo mknod --mode=0600 dev/console c 5 1
After running -kernel linux*/arch/x86_64/boot/bzImage in qemu Hello, world! is shown after calling init.
I'm working on a linux kernel driver and need access to the kmalloc and kfree functions. From my research these should be available in the slab.h header, but that file doesn't exist in my filesystem.
I tried updating my includes using this solution: https://askubuntu.com/questions/75709/how-do-i-install-kernel-header-files but it shows that I already have all relevant files.
My system is a VMWare Ubuntu 16.04 installation running kernel 4.15.0.
Any ideas?
Here is a very simple demo module that calls kmalloc and kfree:
demo.c:
#define pr_fmt(fmt) "demo: " fmt
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
MODULE_LICENSE("GPL");
static int __init demo_init(void) {
void *buf;
buf = kmalloc(1000, GFP_KERNEL);
pr_info("kmalloc returned %p\n", buf);
kfree(buf);
return 0;
}
static void __exit demo_exit(void) {
}
module_init(demo_init);
module_exit(demo_exit);
Makefile:
ifneq ($(KERNELRELEASE),)
# KBuild part of Makefile
obj-m += demo.o
else
# Normal part of Makefile
#
# Kernel build directory specified by KDIR variable
# Default to running kernel's build directory if KDIR not set externally
KDIR ?= "/lib/modules/`uname -r`/build"
all:
$(MAKE) -C "$(KDIR)" M=`pwd` modules
clean:
$(MAKE) -C "$(KDIR)" M=`pwd` clean
endif
You can just run make to build the module for the currently running kernel version:
$ make
Or you can set KDIR to build the module for an arbitrary kernel version (defined by ${KERNELVER} in the following example):
$ make KDIR="/lib/modules/${KERNELVER}/build"
(If KDIR is unspecified, the Makefile sets it to the build path for the currently running kernel: "/lib/modules/`uname -r`/build".)
If it builds successfully, then you definitely have the kernel headers installed!
To test the module, run:
$ sudo /sbin/insmod demo.ko
$ sudo /sbin/rmmod demo
$ sudo dmesg
There should be a message on the kernel log similar to this showing the return value from the kmalloc() call:
[TIMESTAMP] demo: kmalloc returned xxxxxxxxxxxxxxx
The module also calls kfree() to free the allocated block.
I'm trying to do cross-compilation for an ARM a8 processor. I'm moving the code base to a new system, and therefore it should be installed using the same compiler and makefiles as the original system.
I know that I'm using a arm-linux-gnueabihf-gcc compiler.
I've installed the following packages:
> sudo apt install gcc-arm-linux-gnueabihf
> sudo apt install binutils-arm-linux-gnueabi
When I compile the following code block:
#include <stdio.h>
// filename: simple.c
int main(void)
{
printf("I'm printing!\n");
return;
}
with this command:
> arm-linux-gnueabihf-gcc simple.c
I expect it to compile at this step. I instead get:
In file included from simple.c:1:0:
/usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory
#include <bits/libc-header-start.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Any help would be appreciated! Thank you!
I think what you are missing is the multilib packets, if I'm right, this should do the trick for you.
sudo apt install gcc-multilib g++-multilib
My teacher gives me a linux kernel vmlinuz-3.17.2 and a rootfs.ext2 which can be loaded to qemu. And he asks me to build a simplest kernel module which prints a hello world as homework.
Firstly, I download the kernel source and run make oldconfig
Secondly, I make the config to be PREEMPT and without modversions
(according to uname -a of vmlinuz running in qemu) , then make prepare
Thirdly, I compile the kernel mod and copy hello.ko in rootfs.ext2
Finally, In qemu, I run insmod hello.ko which exit without any prompt
and echo $? returns 0.
However, I can't see anything in dmesg or /var/log/messages
Is there anything wrong? How can I do with this?
There is also nothing to be printed when I run rmmod hello.ko successfully.
My log level is 7 4 1 7
I have make my hello.c as follows:
#include <linux/init.h>
#include <linux/module.h>
static int __init hello_init(void)
{
pr_info("Hello World");
return -1;
// I changed this to -1 deliberately, Because It seems that the code is not executed.
}
static void __exit hello_exit(void)
{
printk(KERN_ERR "Goodbye, cruel world\n");
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
Buildroot
Buildroot is the easiest way to do it:
minimal out-of-tree example: How to add a Linux kernel driver module as a Buildroot package?
minimal in-tree example: https://github.com/cirosantilli/buildroot/tree/kernel-module-2016.05
how to debug the module with GDB: How to debug Linux kernel modules with QEMU?
Tested on Ubuntu 16.04.
i dont have internet connection, so i installed gcc on my linux system manually through its debian package. but i am not able to compile any c code.
here is my sample c code.
#include <stdio.h>
main()
{
printf("Hellp world");
return 0;
}
the error that it shows:
ocpe#blrkec241972d:~$ gcc -o hello hello.c
hello.c:1:19: error: stdio.h: No such file or directory
hello.c: In function âmainâ:
hello.c:4: warning: incompatible implicit declaration of built-in function âprintfâ
I think i have not installed all the dependencies of compiler. Plz suggest me descriptive way to install it correctly..
Assuming by "installed manually", you mean "using dpkg -i", then you need to also install libc6-dev. I suggest further installing, at very minimum, build-essential and everything it depends on.
Debian actually has a few programs to help with offline package installation. One option is of course to use CD/DVD images. Another is to use something like apt-offline.
On my Debian system, the header files are in another package libc6-dev. You're probably missing that (and some others as well, I would guess).
What about this gcc -Wall hello.c -o hello -I/usr/include/stdio.h?
You can see your include search path by using:
echo | gcc -v -x c -E -
On my Ubuntu Linux machine i can see this output for the previous command:
#include \"...\" search starts here:
/usr/lib/gcc/i686-linux-gnu/4.6.1/include
/usr/local/include
/usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed
/usr/include/i386-linux-gnu
/usr/include
EDIT :
Install build-essential
Download from here : http://packages.debian.org/squeeze/i386/build-essential/download (assume you are 32 bits), and install dowloaded package like this:
dpkg -i build-essential.deb