How to install Kernel Modules to lib/modules/ from Kernel-Source - linux

Got a Kernel-Source and I want to install the Modules to my ARM-System to the path lib/modules. How can I do that?

You can place them in a directory in /lib/modules. Then you will need to edit /etc/depmod.conf to make the kernel use them on boot. Then run the depmod command to make these changes take effect. If you want to load them immediately, you will have to use the modprobe command.

Related

Cannot get custom kernel to boot - mkinitpcio does not add any modules

1. What I am trying to achieve:
Build a custom kernel so I can install and run Anbox-git from AUR on my Arch laptop. Custom kernel is needed for the package to work.
2. What I did to achieve it:
Download Arch Linux kernel v5.8.5-arch1 from here
I followed the guidelines on tradional compilation Arch wiki to create the custom kernel
Via make nconfig I applied the changes mentioned in the Anbox Arch wiki page.
Via make nconfig I changed EFIVAR_FS option from "M" to "*" to resolve an error from earlier attemps.
Via make nconfig under Location: -> Device Drivers-> Multiple devices driver support (RAID and LVM) (MD [=y])-> Device mapper support (BLK_DEV_DM [=y]) I added a few more options (*) because on earlier builds mkinitpcio gave errors for missing modules for DM_CRYPT, and some more DM_ modules which I cannot easily reproduce (will do if necessary for the answer, but I hope it'll be irrelevant).
After creating the config this way I did:
sudo make modules_install
sudo cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-linux58ac
sudo cp /etc/mkinitcpio.d/linux.preset /etc/mkinitcpio.d/linux58ac.preset
Adapted the preset file per Arch wiki instructions
sudo mkinitcpio -p linux58ac
Important: The mkinitpcio runs fine, but keeps giving me a warning:
WARNING: No modules were added to the image. This is probably not what
you want.
sudo grub-mkconfig -o /boot/grub/grub.cfg
3. Expected result:
I am able to reboot, select the new kernel from grub menu, get the usual LVM password prompt, and launch into it without problems.
4. Result I get:
I can reboot and select new kernel from grub but when I select it I get a
Warning: /lib/modules/5.8.5-arch1/modules.devname not found, ignoring.
Starting version 246.4-1-arch
ERROR device 'dev/mapper/vg0-root' not found. Skipping fsck.
mount /new_root: special device /dev/mapper/vg0-root does not exist.
You are being dropped into an emergy shell.
I checked and the /lib/modules/5.8.5-arch1/modules.devnamedoes indeed exist. But I think the actual problem is that mkinitcpio doesn't load the correct modules into the custom kernel, causing it to become unbootable.
Any help appreciated!

How can I solve stdarg.h No such file or directory while compiling out-of-tree Linux kernel module?

I have an out-of-tree Linux kernel module that I need to compile. When I execute "make" in the kernel module directory I am getting:
"fatal error: stdarg.h: No such file or directory"
Before starting the build I installed the header file based on my Linux distribution.
$sudo apt-get install kernel-headers-$(uname -r)
How can I solve this compilation error? (my distribution is Ubuntu 16.04 with linux-headers-4.15.0-42-generic)
I ran a search of stdarg.h with the "locate" command to see if I can sport the file on the system.
I got:
/usr/include/c++/5/tr1/stdarg.h
/usr/lib/gcc/i686-linux-gnu/5/include/cross-stdarg.h
/usr/lib/gcc/i686-linux-gnu/5/include/stdarg.h
...
It tells me there is at least one stdarg.h provided by the compiler.
I tried to include the path "/usr/lib/gcc/i686-linux-gnu/5/include" in the kernel module Makefile so stdarg.h can be picked up. It did not work (while building, another reference to stdarg.h in the official kernel header was not being resolved).
I finally created a symlink directly under:
/usr/src/linux-headers-4.15.0-42-generic/include
$sudo ln -s /usr/lib/gcc/i686-linux-gnu/5/include/stdarg.h stdarg.h
This was just enough to solve the compilation issue.
I am wondering if the kernel headers should come with an implementation of stdarg.h by default (that is the first time I encounter this issue). I have also read that the compiler provide one implementation and most of the time it is better to use the compiler version.
Updated note: if the above solution still does not solve the problem:
Before running make again, do a make clean. Do a ls -la in the folder and look for a ".cache.mk" file. If this is still there, remove it and run "make" again. It should solve the problem.
I had the same issue with CentOS 9, and the other answers didn't work for me. Apparently the problem is that in more recent kernels, it shouldn't be <stdarg.h> but <linux/stdarg.h>. With virtualbox guest additions 6.1.34, it correctly checks for kernel with a version of 5.15.0 or more. But my kernel is the 5.14.xx, meaning the include for stdarg.h is wrong.
Solving the issue
Dependencies
Install all the dependencies for the guest edition
gcc make perl kernel-devel kernel-headers bzip2 dkms
Installation
Run the Guest Addition installation like you would normally. It will fail by saying it is unable to compile the kernel modules. That's expected. It will copy all the file we need to the VM disk.
Editing
We now need to edit the erroneous files.
/opt/VBoxGuestAdditions-6.1.34/src/vboxguest-6.1.34/vboxguest/include/iprt/stdarg.h
/opt/VBoxGuestAdditions-6.1.34/src/vboxguest-6.1.34/vboxsf/include/iprt/stdarg.h
On line 48 (may change for different versions), it check for a version of Linux and select the correct header depending on the version. We need to replace if RTLNX_VER_MIN(5,15,0) with if RTLNX_VER_MIN(5,14,0) in both files.
Compile the kernel modules
We can now compile the kernel modules, and the error should be gone.
sudo rcvboxadd quicksetup all
I personally got an error the first time, but then I recompiled without changing anything and it worked.
Remember that it's just a workaround, it may not work with different versions.
If you using Arch Linux with zen-kernel:
sudo CPATH=/usr/src/linux-zen/include/linux vmware-modconfig --console --install-all
I had the same problem with VirtualBox 6.1.0 running archlinux with kernel 6.1.9.
I downloaded VirtualBoxGuestAdditions_7.2.0.iso file from https://download.virtualbox.org/virtualbox/7.0.2/ link(you may select more appropriate to your VirtualBox version) and assigned as an optical drive to virtualbox machine. After start of the system running blkid command on terminal showed the name of CD rom device which was /dev/sr0. then I created iso folder on
/mnt folder
mkdir /mnt/iso
and mounted cd drive to that folder
mount -o loop /dev/sr0 /mnt/iso
after I cd'ed to /mnt/iso
cd /mnt/iso
and manually run VirtualBoxGuestAdditions.run script
sh ./VirtualBoxGuestAdditions.run
which successfully compiled and istalled required virtualbox guest modules.
Now everytime I update kernel version I redo the same procedure. And it work fine.
It also remove old 6.1.0 guest additons folder.

Should I make modules_install install everytime I make a little change to linux kernel

Should I make modules_install install everytime I make a little change to linux kernel ?
For example, If I want to print out the variable in fs/namei.c, the only thing I did was printk(...) should I make modules_install install after I make ?
If the change is in the kernel and not in a kernel module, indeed there is no need to run "make modules_install". If for example the platform is x86_64, it is enough in the example you posted to run "make bzImage" and then "make install". And running "make bzImage" is faster than runnung "make", because when you run "make" you are also building the modules. However, if you changed something that can affect kernel modules, like a header file which they use, than you must run make, and then make modules_install and then make install, so that the change will take effect.
Rami Rosen

Want to permanently mount Kernel-Driver into System

I wrote my own kernel driver for a usb-device. After I compile it with make, I have the kernelobejct file usbdriver.ko and with sudo insmod usbdriver.ko I can install and then use it.
But if I restart my Debian, I need to do do insmod again to use it ...
How can i mount/install that driver permanently into the system, so that it loads when the os is starting? And how can I also grant other users than only root to access the asscoiated device-files under /dev/usbdriver0?
Copy your driver to /lib/modules/$(uname -r)/kernel/drivers/ and add it to /etc/modules: http://www.cyberciti.biz/tips/compiling-linux-kernel-module.html.
I don't know but I think it's in the source code somewhere.

Command 'make modules' doesn't build all modules

I'm running Fedora 14 64 bits.
I cloned the kernel source tree from git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
About a week ago I compiled and upgraded the kernel from 2.6.35 to 2.6.39, it went pretty smoothly, all I did was very straight-forward:
make menuconfig
make oldconfig
make -j8
make modules_install && install
Then I added a dummy system call (I was following this with the Linux Kernel Development book by Robert Love) and tried to compile again, it compiled the kernel fine, but when I issued:
[root#xps420 Kernel]# make modules
CHK include/linux/version.h
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
Building modules, stage 2.
MODPOST 4 modules
it only made 4 modules, previously there were over 2000 modules.
I thought it was my dummy system call that was causing the problem, I undid all the changes and tried again, with the same result.
Again, the steps I took were:
make menuconfig
make oldconfig
make -j8
make modules ----> suspicious
I'm not sure what is causing this.
EDIT:
A little more info, I run make clean before recompiling, but it still only made 4 modules.
At one point I did make modules_install, and checked /lib/modules/[ver], only those 4 modules were copied there. I should have stopped there but I went ahead and run make install anyway, it installed the kernel, but was unable to boot with it.
EDIT:
I just downloaded the stable release (2.6.39.1) from kernel.org, after going thru the steps above, the same thing happened. This is strange. Maybe something in my system is screwing this up :( Hopefully someone has run into this and shed some light.
Ok, after several cups of coffee and lots of googling, I don't know how this all works yet, but looks like when I first upgraded the kernel, the .config was based on the running kernel's config and it includes all the needed modules, therefore it ran fine? Then somehow on the subsequent compilations almost all of the modules were not configured in the .config (except the 4 mentioned above). Long story short, I used the old .config and ran menuconfig to make additional changes, it seems to solve my problem. Thanks!
If you don't do a "make clean", the previous compilation results are still there. Only modules affected by the code you changed will be rebuilt.
Perhaps only those four modules have a dependency on the files you touched. If you'd like to confirm this, do a make clean and then try building again, and see if you don't get all the modules compiling again. Of course, it'll take a lot longer!
Try make V=1 ... for verbose output.
Or even V=2.
I encountered the same problem, and solved it by following wliao's advice.
Problem description:
I upgraded kernel to 5.0.0 from 3.x.x(CentOS7 built-in) days ago;
Today, I am going to upgrade it to 5.3.0-rc6+;
Before upgrade, I did a full clean by make distclean;
After make, make modules_install and make install, I tried to reboot with new kernel;
But boot failed with: error: /vmlinuz-5.3.0-rc6+ has invalid signature.
After a long while googling, I came here, thank goodness!
Solving steps:
Copy the existing config file from /boot
cp -p /boot/config-3.10.0-957.27.2.el7.x86_64 .config
Config additional settings by menuconfig
make menuconfig
Build
make -j $(nproc)
sudo make modules_install
sudo make install
Show your new kernel version
sudo grep ^menuentry /boot/efi/EFI/centos/grub.cfg | cut -d "'" -f2
Set your default boot kernel
sudo grub2-set-default 'CentOS Linux (5.3.0-rc6+) 7 (Core)'
Boot successfully!

Resources