14

In a newly installed virtual machine I get this error when compiling the kernel for the x86 architecture:

$ Could not mmap file: vmlinux

$ make: *** [vmlinux] Error 1

It is the first time I see it. I have increased the size of /proc/sys/kernel/shmmax to 128MB, but it does not solve the issue. Any ideas?

Thanks! :)

JesseTG
  • 2,025
  • 1
  • 24
  • 48
user3018391
  • 141
  • 1
  • 4

2 Answers2

22

I had the same issue when compiling kernel in virtual box shared folder. Error comes from mmap_file() function in source file scripts/sortextable.c. Moreover, all mmap functions failed with errno EINVAL within shared folder.

I fixed it with copying linux sources into non shared folder like /home/Name/linux and compiled there.

Jurasic
  • 1,845
  • 1
  • 23
  • 29
18

I had the same problem compiling linux kernel on the VirtualBox shared folder here and I make a little fix in the function sortextable at line 104 (+/-) of script link-vmlinux.sh localized in scripts/ directory

I change this:

sortextable()
{
        ${objtree}/scripts/sortextable ${1}        
}

for this:

sortextable()
{
    cp ${1} /tmp/.${1}
    scripts/sortextable /tmp/.${1}
    cp /tmp/.${1} ${1}
}

And works for me!

Alan Silva
  • 191
  • 1
  • 4
  • What does this actually do? – JesseTG Sep 13 '16 at 00:57
  • Just only a patch in shell script to solve the problem of function execution in a specific file. Only uses a trick to execute this execution on /tmp directory. As I said, this works for me! – Alan Silva Oct 21 '16 at 19:42
  • This also worked for me. Much simpler solution that moving the entire source to a native VM folder. – Declan Shanaghy Nov 11 '16 at 04:21
  • Nice idea, but I got `sortextable not found`. Maybe the script path needs to be adjusted. – user1593842 Jul 11 '20 at 22:35
  • 1
    why not `${objtree}scripts/sortextable /tmp/.${1}`? That should work – user1593842 Jul 14 '20 at 13:03
  • I just faced this problem building px4 project under libvirt ubuntu vm. The expanded solution (posted by Alan) seemed to work for me, while the condensed solution (by user1593842) did not. Not sure why, but that's my empirical result. – Wayne Oct 08 '20 at 19:12
  • stackoverflow is awesome. And so is this workaround. – gbarry Oct 29 '20 at 23:20
  • Encounter this issue while compiling 5.11.16 on Debian 10 VM in a shared folder. This solution worked for me too. Though I didn't find `sortextable()` in the script. I think its renamed to `sorttable()`. – Ashfaqur Rahaman Apr 24 '21 at 14:38