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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
09-04-2014, 06:02 PM
|
#1
|
Member
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333
Rep:
|
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?
|
|
|
09-05-2014, 11:15 AM
|
#2
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200
|
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.
|
|
|
09-06-2014, 03:31 AM
|
#3
|
Member
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333
Original Poster
Rep:
|
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...
|
|
|
09-06-2014, 09:32 AM
|
#4
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200
|
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.
|
|
|
09-09-2014, 04:22 PM
|
#5
|
Member
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333
Original Poster
Rep:
|
Quote:
Originally Posted by business_kid
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.
|
|
|
09-10-2014, 03:48 AM
|
#6
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200
|
I did suggest
Code:
cd /usr/src/linux-<whatever_version>
cp /boot/config-version .
I omitted
Code:
mv config-version .config
Sorry about that.
|
|
|
09-10-2014, 09:15 AM
|
#7
|
Member
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333
Original Poster
Rep:
|
Quote:
Originally Posted by business_kid
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.
|
|
|
09-10-2014, 02:42 PM
|
#8
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200
|
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.
|
|
|
09-10-2014, 05:20 PM
|
#9
|
Member
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333
Original Poster
Rep:
|
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...
|
|
|
09-11-2014, 03:56 AM
|
#10
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200
|
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.
|
|
|
09-12-2014, 03:18 AM
|
#11
|
Member
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333
Original Poster
Rep:
|
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...
|
|
|
09-12-2014, 08:43 AM
|
#12
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200
|
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 page http://www.linuxfromscratch.org/lfs/...08/kernel.html
|
|
|
09-13-2014, 04:20 AM
|
#13
|
Member
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333
Original Poster
Rep:
|
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.
|
|
|
09-13-2014, 10:53 AM
|
#14
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,200
|
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
|
|
|
09-14-2014, 03:47 AM
|
#15
|
Member
Registered: Aug 2013
Distribution: Arch, Debian, Slackware
Posts: 333
Original Poster
Rep:
|
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?
|
|
|
All times are GMT -5. The time now is 08:59 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|