LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-04-2014, 06:02 PM   #1
slacker_
Member
 
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333

Rep: Reputation: 3
How can I build a kernel module on one system for a diff. kernel on a diff. system?


I meant to post this here earlier but it somehow wound up in the non-*nix general forum...

I have been searching for hours trying to find any guides or information in general for how to build a kernel module for a kernel I am not currently running, but I can't find any guides or anything helpful.

The situation I'm in is as follows:

I am running debian stable (kernel 3.2 x64) on my laptop, and I am trying to build a kernel module for a desktop running an ubuntu variant called Zorin (kernel 3.13 x32). The reason I am building it on my laptop is because the desktop in question has no internet access, and so cannot download the build-essential files, and this module will solve that problem.

I know I could load the files on a usb drive and copy it over, but I figured this was a perfect time to learn how to do this particular task with kernel modules.

So, how can I build this module for the 3.13.0-32 kernel if I'm running 3.2.04-amd64 kernel?
 
Old 09-05-2014, 11:15 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200

Rep: Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536
I would get the correct source - the Zorin source if they do one (They may have patched it). Get the .config, which is usually available as /boot/config-version. Add the module to the .config. They are your ingredients.

Your optimal toolchain is the Zorin kernel headers, gcc, and glibc. Things compiled elsewhere may work, but no guarantees. Best to build on the original box or install Zorin on the box you are building on (even in a vm). You will have to install kernel, & module tree, as otherwise you will probably hit a 'version magic' problem. Your usb drive sounds like a good idea. Even low powered cpus do a reasonable job building kernels. You need close to 750MB of Storage for a full compiled kernel tree, however.
 
Old 09-06-2014, 03:31 AM   #3
slacker_
Member
 
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333

Original Poster
Rep: Reputation: 3
The module is for a realtek usb wifi dongle (7601 model) so no one really has a specific patched source that I've seen. So building from source provided by manufacturer is my only option.

When you say "Things compiled elsewhere may work, but no guarantees," is this to say that building this module on my laptop is very unlikely to work, or it is incredibly difficult?

Being that I am very new to this whole process, could you give like a step by step kind of walkthrough for this process? I don't know what is involved with installing a kernel tree, or wat version magic is...
 
Old 09-06-2014, 09:32 AM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200

Rep: Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536
The Realtek code should provide details. If you can't follow them, try this.

You installed Zorin. Install the kernel source, which root will find in /usr/src.
Then, as you have a manufacturer module to build

cd /usr/src/linux-<whatever_version>
cp /boot/config-version . (the full stop is important)
make -j3
Leave it chewing while you grab a coffee, pint5, or whatever
You now have a ready built kernel. Now look at building the module (follow Realtek's instructions to the letter).

EDIT: If you still have issues, post a link to the Reakltek code.
 
Old 09-09-2014, 04:22 PM   #5
slacker_
Member
 
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by business_kid View Post
The Realtek code should provide details. If you can't follow them, try this.

You installed Zorin. Install the kernel source, which root will find in /usr/src.
Then, as you have a manufacturer module to build

cd /usr/src/linux-<whatever_version>
cp /boot/config-version . (the full stop is important)
make -j3
Leave it chewing while you grab a coffee, pint5, or whatever
You now have a ready built kernel. Now look at building the module (follow Realtek's instructions to the letter).

EDIT: If you still have issues, post a link to the Reakltek code.
I was having too many other issues with zorin so I abandoned it for mint. However, I still need to get this module working so I followed along with what you detailed, and here's what happened:

Code:
mint linux-headers-3.13.0-24 # cp /boot/config-3.13.0-24-generic .
mint linux-headers-3.13.0-24 # make -j3
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
***
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
make[2]: *** [silentoldconfig] Error 1
make[1]: *** [silentoldconfig] Error 2
make[1]: *** No rule to make target `/usr/src/linux-headers-3.13.0-24/arch/x86/syscalls/syscall_32.tbl', needed by `arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h'.  Stop.
make: *** [archheaders] Error 2
make: INTERNAL: Exiting with 4 jobserver tokens available; should be 3!
mint linux-headers-3.13.0-24 #
It tells me to run make oldconfig, which it seems to try to do on it's own as well, but I do, and it completes. But make -j3 still errors with the message "4 jobserver tokens available, should be 3!" which I have no idea what that means. I see further up a couple lines it says "No rule to make target [...]" Any ideas?

Last edited by slacker_; 09-09-2014 at 04:23 PM.
 
Old 09-10-2014, 03:48 AM   #6
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200

Rep: Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536
I did suggest
Code:
cd /usr/src/linux-<whatever_version>
cp /boot/config-version .
I omitted
Code:
mv config-version  .config
Sorry about that.
 
Old 09-10-2014, 09:15 AM   #7
slacker_
Member
 
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by business_kid View Post
I did suggest
Code:
cd /usr/src/linux-<whatever_version>
cp /boot/config-version .
I omitted
Code:
mv config-version  .config
Sorry about that.
So I loaded up a VM to build this in, as the machine it's for is elsewhere. For all intents and purposes it is exactly the same as the other machine.

I did what you said, mv config-<version> .config, and then make -j3 and it did the same thing:

Code:
test-VB ~ # cd /usr/src/linux-headers-3.13.0-24
test-VB linux-headers-3.13.0-24 # cp /boot/config-3.13.0-24-generic .
test-VB linux-headers-3.13.0-24 # mv config-3.13.0-24-generic .config
test-VB linux-headers-3.13.0-24 # make -j3
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
make[1]: *** No rule to make target `/usr/src/linux-headers-3.13.0-24/arch/x86/syscalls/syscall_32.tbl', needed by `arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h'.  Stop.
make: *** [archheaders] Error 2
make: INTERNAL: Exiting with 4 jobserver tokens available; should be 3!
Now what...? It seems it's expecting something with the "No rule to make target [...]" bit, but that's just a blind guess.
 
Old 09-10-2014, 02:42 PM   #8
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200

Rep: Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536
You need to install the linux kernel source and the kernel headers. I take it you have the source, but not the headers. You can run make headers_install and it should do that, or use the headers package from your distro.
 
Old 09-10-2014, 05:20 PM   #9
slacker_
Member
 
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333

Original Poster
Rep: Reputation: 3
I ran 'apt-get install linux-headers$(uname -r) build-essential' so I have the kernel headers. I didn't install the specific source, as I thought the headers took care of that for me. Should I be working directly with the source itself and not the headers..? I'm confused now...
 
Old 09-11-2014, 03:56 AM   #10
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200

Rep: Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536
The kernel headers are the include files for the kernel.

To build a kernel, or a kernel module. you do need the source. /usr/src/linux-version should be close to 500Megs, and another 200 Megs or so when built. I am just amazed that you apparently have ~/scripts/kconfig but no kernel source.
 
Old 09-12-2014, 03:18 AM   #11
slacker_
Member
 
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333

Original Poster
Rep: Reputation: 3
Ok. So, since I'm in a VM, I can roll back to scratch. Walk me through this from step one (obtaining the kernel source) and maybe I won't screw it up this time...
 
Old 09-12-2014, 08:43 AM   #12
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200

Rep: Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536
Get a kernel source, from your distro, or else
ftp://ftp.<your-country>.kernel.org/pub/linux/<version>/linux-<version>.tar.bz2

e.g. ftp://ftp.ie.kernel.org for Ireland. Insert sensible stuff everywhere I have <>brackets, and beware that these guys love loads of directories, and have probably added some since I was there last:-P.

There's a README in the kernel. Read that. It gives a compile procedure. You might start with
make headers_install to get past the headers issue.
Use the slackware config

Also a good read particularly on installing the kernel is the Linuxfromscratch pagehttp://www.linuxfromscratch.org/lfs/...08/kernel.html
 
Old 09-13-2014, 04:20 AM   #13
slacker_
Member
 
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333

Original Poster
Rep: Reputation: 3
Ok, kernel config built up just fine. I feel stupid for having to ask, but I'm in the realtek module readme and I'm not sure what the following means:

Code:
2> In Makefile
         set the "MODE = STA" in Makefile and chose the TARGET to Linux by set "TARGET = LINUX"
         define the linux kernel source include file path LINUX_SRC
         modify to meet your need.

3> In os/linux/config.mk 
        define the GCC and LD of the target machine
        define the compiler flags CFLAGS
        modify to meet your need.
For 2> I'm not sure if it means set "TARGET" explicitly to "LINUX" or to whatever OS/Version I'm running...
For 3> what does it mean by define GCC and LD of the target machine? Am I putting versions there? And compiler flags has me lost as well... As I said before, this is all new to me, so I'm rather lost with it at the moment.
 
Old 09-13-2014, 10:53 AM   #14
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200

Rep: Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536Reputation: 2536
The Realtek code will have a Makefile in the top source directory. Open it in an editor. Look in the early part for the lines in blue, and enter the green instead of whatever is there

MODE =
STA
TARGET = LINUX

Likewise in (top source dir)/os/linux/config.mk
GCC= /usr/bin/gcc
LD= /usr/bin/ld
 
Old 09-14-2014, 03:47 AM   #15
slacker_
Member
 
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333

Original Poster
Rep: Reputation: 3
These values are already set correctly. Now onto building the module... however the readme doesn't say anything about how to build it against a kernel source other than the one you're running. Ie, I have the kernel source built and sitting at ~/Desktop but don't know how to tell this module to look there. I tried 'make -C /home/test/Desktop/linux-kernel-<version> M=$PWD' as suggested (sort of) from an old blog post about building modules, and this was the output:

Code:
test@test-VB ~/Downloads/realtek $ make -C ~/Desktop/linux-source-3.13.0/ M=$PWDmake: Entering directory `/home/test/Desktop/linux-source-3.13.0'
/home/test/Downloads/realtek/Makefile:25: /home/test/Desktop/linux-source-3.13.0/os/linux/config.mk: No such file or directory
make[1]: *** No rule to make target `/home/test/Desktop/linux-source-3.13.0/os/linux/config.mk'.  Stop.
make: *** [_module_/home/test/Downloads/realtek] Error 2
make: Leaving directory `/home/test/Desktop/linux-source-3.13.0'
Did I screw something up?
 
  


Reply

Tags
debian, kernel, module, zorin


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can you build a kernel module for a kernel that isn't running on your system? slacker_ General 13 09-08-2014 10:02 AM
i being trying to install immunity debugger on my linux system and found it very diff muiadedeji Linux - Newbie 2 07-20-2010 06:06 PM
diff between "system calls" and "kernel threads" shariefbe Linux - Software 5 12-13-2009 11:23 AM
[SOLVED] Diff between Kernel Compilation and Kernel Configuration ?? vikas027 Linux - Enterprise 8 09-20-2008 02:01 AM
dual boot system(solaris and linux) on diff HD ddaas Solaris / OpenSolaris 8 07-22-2005 05:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration