# [MOSTLY SOLVED] Unable to load emerged modules

## pinion

On my system, emerge -av @module-rebuild after a kernel (sys-kernel/gentoo-sources-3.11.8 ) upgrade shows me 3 packages to be reinstalled:

```
 /usr/src/linux $ sudo emerge -pv @module-rebuild

Calculating dependencies... done!

[ebuild   R    ] x11-drivers/nvidia-drivers-331.38  USE="X acpi (multilib) tools -pax_kernel" 0 kB

[ebuild   R   ~] app-emulation/vmware-modules-271.2  USE="-pax_kernel" 0 kB

[ebuild   R   ~] net-wireless/broadcom-sta-6.30.223.141  0 kB

```

However, after successfully emerging the modules, I am unable to load any of them:

```
 /usr/src/linux $ sudo modprobe --verbose wl

insmod /lib/modules/3.11.8-gentoo/net/wireless/wl.ko 

modprobe: ERROR: could not insert 'wl': Exec format error

```

Searching in /var/log/dmesg and /var/log/messages does not show me any errors:

```
Feb 18 14:14:07 localhost sudo:     dave : TTY=pts/0 ; PWD=/usr/src/linux-3.11.8-gentoo ; USER=root ; COMMAND=/sbin/modprobe --verbose wl

Feb 18 14:14:07 localhost sudo: pam_unix(sudo:session): session opened for user root by dave(uid=0)

Feb 18 14:14:07 localhost sudo: pam_unix(sudo:session): session closed for user root

```

```
 /usr/src/linux $ sudo grep wl /var/log/dmesg

 /usr/src/linux $ 

```

I have done a make clean on my kernel and rebuilt it, but after emerging these modules I can still not load them, and get the "Exec format error".  Only emerged modules have this problem.. modules built with the kernel itself load fine:

```
Module                  Size  Used by

ipv6                  219304  52 

x86_pkg_temp_thermal     3388  0 

coretemp                4812  0 

kvm_intel             108676  0 

snd_hda_codec_hdmi     23020  1 

kvm                   176996  1 kvm_intel

crc32c_intel            8312  0 

asus_nb_wmi             7020  0 

asus_wmi               11052  1 asus_nb_wmi

sparse_keymap           1928  1 asus_wmi

rfkill                  7252  1 asus_wmi

snd_hda_codec_realtek    27896  1 

snd_hda_intel          22492  5 

snd_hda_codec          84512  3 snd_hda_codec_realtek,snd_hda_codec_hdmi,snd_hda_intel

snd_hwdep               4240  1 snd_hda_codec

snd_pcm                50288  3 snd_hda_codec_hdmi,snd_hda_codec,snd_hda_intel

hid_logitech_dj         8328  0 

acpi_cpufreq            5388  0 

mperf                    904  1 acpi_cpufreq

freq_table              1720  1 acpi_cpufreq

alx                    18216  0 

snd_page_alloc          5416  2 snd_pcm,snd_hda_intel

i2c_i801                7888  0 

mdio                    2648  1 alx

wmi                     6076  1 asus_wmi

microcode               5408  0 

processor              20336  9 acpi_cpufreq

thermal                 7280  0 

firmware_class          7888  1 microcode

snd_timer              13240  1 snd_pcm

snd                    42152  17 snd_hda_codec_realtek,snd_hwdep,snd_timer,snd_hda_codec_hdmi,snd_pcm,snd_hda_codec,snd_hda_intel

lib80211                2556  0 

pcspkr                  1400  0 

battery                 9780  0 

video                   9884  1 asus_wmi

ac                      3572  0 

thermal_sys            13964  4 video,thermal,processor,x86_pkg_temp_thermal

```

I build my kernel manually with a make && make modules_install.  I have checked my symlink, and it is good:

```
 $ sudo eselect kernel show

Current kernel symlink:

  /usr/src/linux-3.11.8-gentoo                  

```

Any help is much appreciated.  I am not having any luck getting this resolved.Last edited by pinion on Tue Mar 04, 2014 6:21 pm; edited 1 time in total

----------

## NeddySeagoon

pinion,

Those modules are all emerged against the kernel pointed to by /usr/src/linux.

I guess its not pointing to the kernel you are running, so the moules are installed against the 'wrong' kernel.

Maybe you are not running the kernel you think you are.  Look at the output of 

```
uname -a
```

The Time/Date is the build time of the running kernel.

```
$ uname -a

Linux NeddySeagoon_Static 3.13.3-gentoo #1 SMP PREEMPT Sat Feb 15 19:29:18 GMT 2014 x86_64 AMD Phenom(tm) II X6 1090T Processor AuthenticAMD GNU/Linux
```

----------

## pinion

Here is what uname -a tells me:

```
 ~ $ sudo uname -a

Linux lap8200 3.11.8-gentoo #11 SMP Sat Feb 15 22:45:53 MST 2014 x86_64 Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz GenuineIntel GNU/Linux

```

Thanks for the reply  :Smile: 

----------

## NeddySeagoon

pinion,

That's the 11th build of 3.11.8-gentoo and it happened at Sat Feb 15 22:45:53 MST.

Is that correct or have you built your kernel more recently?

The versions match, which is required but not sufficient.

----------

## pinion

I just did another make clean/rebuild.. and it indicates its the 15th build.. strange.  I've been using gentoo for years now, but maybe I just have been using an incorrect procedure for doing this.

These are the steps I just took:

```
sudo su

mount /boot

cd /usr/src/linux

make clean

rm -rf /lib64/modules/3.11.8-gentoo/ /lib/modules/3.11.8-gentoo/ (to make sure no other modules are out there.. dont usually do that)

cp /boot/config-x86_64-3.11.8-gentoo .config

make && make modules_install

cp arch/x86_64/boot/bzImage /boot/kernel-x86_64-3.11.8-gentoo

cp .config /boot/config-x86_64-3.11.8-gentoo

grub2-mkconfig -o /boot/grub/grub.cfg

reboot...

sudo emerge -av nvidia-drivers

```

modprobe nvidia gives the Exec format error

same thing for broadcom-sta and vmware-modules

Thanks

----------

## NeddySeagoon

pinion,

Well,  Given that the kernel can count its builds, the last build was #14, not #11

Do the build dates check out with your memory?

Danger Will Robinson ... 

```
grub2-mkconfig -o /boot/grub/grub.cfg 
```

I've never used grub2

Exec format error has lots of causes.  dmesg may help further.

As long as /usr/src/linux points to your new kernel, you can build the out of tree modules before tho reboot.

This has the advantage that you should never be without Xorg.

Please post the output of 

```
ls -l /boot 
```

and the content of /boot/grub/grub.cfg

For completeness sake, when /boot is not mounted /boot should be empty, is it?

----------

## pinion

In trying to fix this, I switched to 3.12.7 from gentoo-sources, and removed everything else.. (I left the other sources, but made sure the symlink points to the correct one).  I manually purged the modules, did a make clean, and built the kernel and booted to it a few times.  I have the same problem, however.

I failed to mention earlier that when I emerge these modules, I get permission issues, which I have to step through and add read access to (o+r).  I have had that happening for awhile.. ever since I last upgraded my kernel, and have had no issues loading modules built from the kernel.  I'm not sure what's causing that.. it's just mainly a pain when I build these modules.

ls -l /boot:

```
 ~ $ sudo ls -l /boot/

total 13920

lrwxrwxrwx 1 root root       1 Mar 10  2013 boot -> .

-rw------- 1 root root  100233 Feb 19 10:15 config-x86_64-3.12.7-gentoo

drwx------ 6 root root    1024 Feb 18 20:17 grub

-rw------- 1 root root 5122603 Jan 18 19:37 initramfs.cpio.gz

-rw-r--r-- 1 root root 4835426 Mar 29  2013 initramfs.cpio.gz_bu

-rw------- 1 root root 4119744 Feb 19 10:15 kernel-x86_64-3.12.7-gentoo

drwx------ 2 root root   12288 Mar 12  2013 lost+found

```

/boot/grub/grub.cfg

```

 ~ $ sudo cat /boot/grub/grub.cfg

#

# DO NOT EDIT THIS FILE

#

# It is automatically generated by grub2-mkconfig using templates

# from /etc/grub.d and settings from /etc/default/grub

#

### BEGIN /etc/grub.d/00_header ###

if [ -s $prefix/grubenv ]; then

  load_env

fi

if [ "${next_entry}" ] ; then

   set default="${next_entry}"

   set next_entry=

   save_env next_entry

   set boot_once=true

else

   set default="0"

fi

if [ x"${feature_menuentry_id}" = xy ]; then

  menuentry_id_option="--id"

else

  menuentry_id_option=""

fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then

  set saved_entry="${prev_saved_entry}"

  save_env saved_entry

  set prev_saved_entry=

  save_env prev_saved_entry

  set boot_once=true

fi

function savedefault {

  if [ -z "${boot_once}" ]; then

    saved_entry="${chosen}"

    save_env saved_entry

  fi

}

function load_video {

  if [ x$feature_all_video_module = xy ]; then

    insmod all_video

  else

    insmod efi_gop

    insmod efi_uga

    insmod ieee1275_fb

    insmod vbe

    insmod vga

    insmod video_bochs

    insmod video_cirrus

  fi

}

if loadfont unicode ; then

  set gfxmode=1920x1080

  load_video

  insmod gfxterm

  set locale_dir=$prefix/locale

  set lang=

  insmod gettext

fi

terminal_output gfxterm

insmod part_msdos

insmod ext2

set root='hd0,msdos1'

if [ x$feature_platform_search_hint = xy ]; then

  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  904636c1-f00b-42fb-8f3f-543a76b82269

else

  search --no-floppy --fs-uuid --set=root 904636c1-f00b-42fb-8f3f-543a76b82269

fi

insmod jpeg

background_image -m stretch /grub/Ghosts-nine-inch-nails-23374236-1920-1440.jpg

if sleep --interruptible 0 ; then

  set timeout=2

fi

### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###

menuentry 'Gentoo GNU/Linux' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-/dev/mapper/root' {

   load_video

   set gfxpayload=1920x1080

   insmod gzio

   insmod part_msdos

   insmod ext2

   set root='hd0,msdos1'

   if [ x$feature_platform_search_hint = xy ]; then

     search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  904636c1-f00b-42fb-8f3f-543a76b82269

   else

     search --no-floppy --fs-uuid --set=root 904636c1-f00b-42fb-8f3f-543a76b82269

   fi

   echo   'Loading Linux x86_64-3.12.7-gentoo ...'

   linux   /kernel-x86_64-3.12.7-gentoo root=/dev/mapper/root ro crypt_root=/dev/sda3 scandelay=3 timeout=0 video=vesafb:mtrr:3,ywrap splash=theme:atl_default console=tty1 

   echo   'Loading initial ramdisk ...'

   initrd   /initramfs.cpio.gz

}

submenu 'Advanced options for Gentoo GNU/Linux' $menuentry_id_option 'gnulinux-advanced-/dev/mapper/root' {

   menuentry 'Gentoo GNU/Linux, with Linux x86_64-3.12.7-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-x86_64-3.12.7-gentoo-advanced-/dev/mapper/root' {

      load_video

      set gfxpayload=1920x1080

      insmod gzio

      insmod part_msdos

      insmod ext2

      set root='hd0,msdos1'

      if [ x$feature_platform_search_hint = xy ]; then

        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  904636c1-f00b-42fb-8f3f-543a76b82269

      else

        search --no-floppy --fs-uuid --set=root 904636c1-f00b-42fb-8f3f-543a76b82269

      fi

      echo   'Loading Linux x86_64-3.12.7-gentoo ...'

      linux   /kernel-x86_64-3.12.7-gentoo root=/dev/mapper/root ro crypt_root=/dev/sda3 scandelay=3 timeout=0 video=vesafb:mtrr:3,ywrap splash=theme:atl_default console=tty1 

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs.cpio.gz

   }

   menuentry 'Gentoo GNU/Linux, with Linux x86_64-3.12.7-gentoo (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-x86_64-3.12.7-gentoo-recovery-/dev/mapper/root' {

      load_video

      set gfxpayload=1920x1080

      insmod gzio

      insmod part_msdos

      insmod ext2

      set root='hd0,msdos1'

      if [ x$feature_platform_search_hint = xy ]; then

        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  904636c1-f00b-42fb-8f3f-543a76b82269

      else

        search --no-floppy --fs-uuid --set=root 904636c1-f00b-42fb-8f3f-543a76b82269

      fi

      echo   'Loading Linux x86_64-3.12.7-gentoo ...'

      linux   /kernel-x86_64-3.12.7-gentoo root=/dev/mapper/root ro single crypt_root=/dev/sda3 scandelay=3 timeout=0 video=vesafb:mtrr:3,ywrap splash=theme:atl_default console=tty1

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs.cpio.gz

   }

}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###

### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###

# This file provides an easy way to add custom menu entries.  Simply type the

# menu entries you want to add after this comment.  Be careful not to change

# the 'exec tail' line above.

### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###

if [ -f  ${config_directory}/custom.cfg ]; then

  source ${config_directory}/custom.cfg

elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then

  source $prefix/custom.cfg;

fi

### END /etc/grub.d/41_custom ###

```

I just verified that /boot is empty when not mounted.

Thanks for the help.

----------

## NeddySeagoon

pinion,

Well you only have one kernel in that /boot.

Do you have /boot on any other HDD too?

That way lies madness but I have seen users install perfectly good kernels in /boot on the wrong drive, so I need to ask.

If you only have one drive, it can only be booting that kernel.

Where do you get permissions issues?

Setting things world readable in relation to kernel modules sounds like a very bad thing. Only root should be able to load modules. 

Compare the permissions on your modules tree with mine

```
$ ls -l /lib/modules/`uname -r`

total 528

lrwxrwxrwx 1 root root     28 Feb 16 11:05 build -> /usr/src/linux-3.13.3-gentoo

drwxr-xr-x 9 root root   4096 Feb 16 11:05 kernel

drwxr-xr-x 2 root root   4096 Feb 17 21:31 misc

-rw-r--r-- 1 root root 124377 Feb 17 21:31 modules.alias

-rw-r--r-- 1 root root 127105 Feb 17 21:31 modules.alias.bin

-rw-r--r-- 1 root root   5591 Feb 16 11:05 modules.builtin

-rw-r--r-- 1 root root   8196 Feb 17 21:31 modules.builtin.bin

-rw-r--r-- 1 root root  18992 Feb 17 21:31 modules.dep

-rw-r--r-- 1 root root  28234 Feb 17 21:31 modules.dep.bin

-rw-r--r-- 1 root root    250 Feb 17 21:31 modules.devname

-rw-r--r-- 1 root root   8475 Feb 16 11:05 modules.order

-rw-r--r-- 1 root root    131 Feb 17 21:31 modules.softdep

-rw-r--r-- 1 root root  84145 Feb 17 21:31 modules.symbols

-rw-r--r-- 1 root root  97194 Feb 17 21:31 modules.symbols.bin

lrwxrwxrwx 1 root root     28 Feb 16 11:05 source -> /usr/src/linux-3.13.3-gentoo
```

since only root can run modprobe, permissions of 640 woks just as well.

In a random subdir, I get 

```
$ ls -l /lib/modules/`uname -r`/misc

total 484

-rw-r--r-- 1 root root 416352 Feb 17 21:31 vboxdrv.ko

-rw-r--r-- 1 root root  12152 Feb 17 21:31 vboxnetadp.ko

-rw-r--r-- 1 root root  32344 Feb 17 21:31 vboxnetflt.ko

-rw-r--r-- 1 root root  30664 Feb 17 21:31 vboxpci.ko
```

but they are all the same.

The `uname -r` runs uname -r and puts the result in the command, so it returns things related to the running kernel.

----------

## pinion

Yeah, I removed the older kernels to clean things up a bit.  I only have the one drive (I encrypted it though.. so I have a custom init script in the initramfs.cpio.gz file).

My permissions are similar for modules.

```
 ~ $ ls -l /lib/modules/`uname -r`

total 1172

lrwxrwxrwx 1 root root     28 Feb 18 19:39 build -> /usr/src/linux-3.12.7-gentoo

drwx------ 9 root root   4096 Feb 19 10:14 kernel

-rw-r--r-- 1 root root 303373 Feb 19 10:25 modules.alias

-rw-r--r-- 1 root root 289646 Feb 19 10:25 modules.alias.bin

-rw------- 1 root root   4207 Feb 19 10:14 modules.builtin

-rw-r--r-- 1 root root   6027 Feb 19 10:25 modules.builtin.bin

-rw-r--r-- 1 root root  82512 Feb 19 10:25 modules.dep

-rw-r--r-- 1 root root 127513 Feb 19 10:25 modules.dep.bin

-rw-r--r-- 1 root root    224 Feb 19 10:25 modules.devname

-rw------- 1 root root  34677 Feb 19 10:14 modules.order

-rw-r--r-- 1 root root    165 Feb 19 10:25 modules.softdep

-rw-r--r-- 1 root root 137764 Feb 19 10:25 modules.symbols

-rw-r--r-- 1 root root 168367 Feb 19 10:25 modules.symbols.bin

drwxr-xr-x 3 root root   4096 Feb 18 22:29 net

lrwxrwxrwx 1 root root     28 Feb 19 10:14 source -> /usr/src/linux-3.12.7-gentoo

drwxr-xr-x 2 root root   4096 Feb 19 10:25 video

```

When I emerge a module, I need to give read access to a few files inside the kernel source (/usr/src/linux/include/generated/autoconf.h for instance).. and executable permissions to a few scripts also inside the kernel source files.  I have found that once you compile the kernel, it resets permissions as well.  I don't understand why I run into the permission issues, as the files are all rw by root, and I always do a 'sudo emerge' to install something.

----------

## pinion

I re-emerged portage, did a 'chmod a+rXw -R' on /usr/src/linux, and re-emerged the modules... and now I can load the modules (nvidia & wl.. emerging vmware-modules-279.0 or 271.2 failed).  I can use my wifi adapter, however it crashes every few minutes and restarts.. which it was doing before I ran into this problem and is what spawned me upgrading my kernel and modules to begin with.  I am unable to start X, but I am chasing down X errors to figure out why.

I am really curious why I get these permission issues against /usr/src/linux.  It has only been going on for a few months, after upgrading a bunch of stuff on my system.  I install modules using 'sudo emerge', and root has rwx access to all of /usr/src/linux as it should.

Anyway, Once I get my X issues straightened out with the nvidia driver, I will be somewhat set.

Thanks for the help.

----------

## pinion

So, I was wrong... it seemed the ability to load modules was a fluke, as apon rebooting I could no longer load emerged modules.  I discovered that the emerged modules were all ELF files, where the modules built with the kernel were not.  I finally took a year old config of my kernel I had saved, loaded that into menuconfig and built a clean kernel off of it, and that worked!  Except, I still get the strange /usr/src/linux permission problems when emerging modules.  I am unable to get vmware-modules to emerge, but that appears to be a 3.12 kernel issue with vmware, and for the time being I am just using VirtualBox, which seems to work just fine.

Here is a diff of the kernel .config that worked ( < ) and the one I was using previously ( > ):

```
181c181

< CONFIG_CC_OPTIMIZE_FOR_SIZE=y

---

> # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set

221c221

< # CONFIG_JUMP_LABEL is not set

---

> CONFIG_JUMP_LABEL=y

625,626c625,626

< # CONFIG_IA32_AOUT is not set

< # CONFIG_X86_X32 is not set

---

> CONFIG_IA32_AOUT=y

> CONFIG_X86_X32=y

1114d1113

< # CONFIG_NET_9P_RDMA is not set

1148c1147

< # CONFIG_CONNECTOR is not set

---

> CONFIG_CONNECTOR=m

1701,1702c1700

< CONFIG_MLX4_CORE=m

< # CONFIG_MLX4_DEBUG is not set

---

> # CONFIG_MLX4_CORE is not set

2529d2526

< CONFIG_DRM_TTM=m

2539,2540c2536

< CONFIG_DRM_RADEON=m

< # CONFIG_DRM_RADEON_UMS is not set

---

> # CONFIG_DRM_RADEON is not set

2543c2539,2541

< # CONFIG_DRM_I915 is not set

---

> CONFIG_DRM_I915=m

> # CONFIG_DRM_I915_KMS is not set

> # CONFIG_DRM_I915_PRELIMINARY_HW_SUPPORT is not set

2586a2585

> # CONFIG_FB_UVESA is not set

2757a2757

> CONFIG_SND_HDA_I915=y

3336c3316

< # CONFIG_MXM_WMI is not set

---

> CONFIG_MXM_WMI=m

3542d3521

< CONFIG_SUNRPC_XPRT_RDMA=m

3622c3601

< CONFIG_PRINTK_TIME=y

---

> # CONFIG_PRINTK_TIME is not set

3660a3640

> # CONFIG_KMEMCHECK is not set

3676,3677c3656,3657

< CONFIG_PANIC_ON_OOPS=y

< CONFIG_PANIC_ON_OOPS_VALUE=1

---

> # CONFIG_PANIC_ON_OOPS is not set

> CONFIG_PANIC_ON_OOPS_VALUE=0

3696c3676

< CONFIG_DEBUG_BUGVERBOSE=y

---

> # CONFIG_DEBUG_BUGVERBOSE is not set

3957c3937

< # CONFIG_KVM_AMD is not set

---

> CONFIG_KVM_AMD=m

4001d3980

< CONFIG_GENERIC_ALLOCATOR=y

```

Do you see what may have caused the modules to not load?

Thanks

----------

## Logicien

To have a clean of /usr/src/linux source code, I would do

```
make mrproper

make clean
```

The kernel and the initramfs versions loaded by Grub must be the same. That's imply (re)create an initramfs for the kernel version who have been (re)installed, every time you (re)install one.

----------

## NeddySeagoon

Logicien,

That is true if the initrd contains kernel modules.

My user space only initrd from April 2009 is still working properly.

----------

## Logicien

NeddySeagoon,

I was precisely thinking to an initramfs who contain kernel modules. Your initrd from 2009 should contain some binaries and librairies of that time that have been upgraded on your Gentoo box since then. Would you not like to upgrade your initrd too?

----------

## pinion

I guess it really comes down to where your initrd is coming from, and what modules/built-ins it is using.  Personally, since I encrypt my hard drive, I made the initrd I am using, and use minimal built-in drivers (no modules).  So, I don't update it unless there is a specific need to.  However, if using something like genkernel, I can see it would make sense to update the initrd with every kernel build.

----------

## NeddySeagoon

Logicien,

My initrd is like firmware it runs one at every boot, does its job then exits.

I don't care about security updates as it does not interact with the outside world - even the keyboard, so it cannot be used to attack my system.

Why would I want to change it?

I'll make a new initrd next year, when I get a new PC  :)

----------

