Requires Kernel Source

I tried to install the package rkunter from the ports, and it failed on lsof because I did not have the kernel source installed. I installed the kernel source using the svn method (9.0-Stable). When I try to compile rkhunter or lsof again using [cmd=]make install clean[/cmd] I get the error:

Code:
===>  lsof-4.86,7 requires kernel sources
*** Error code 1

I now have the sources in the /usr/src directory, so what am I missing? How can I fix a port when it started and errored out? (specifically, how can I get lsof and rkhunter to compile?)

Basic install info:
amd64
9.0 Release
Using portsnap for port maintenance.
 
*Sometimes* a port may not find the kernel sources even though they are present; in that case I just edit the Makefile (comment out an IGNORE block...) and build it normally. May or may not work in this case...
 
Did you run a make clean on the ports that failed to build earlier?
 
Yep, I did run make clean from within the /usr/ports/systutils/lsof I ran it after downloading the kernel, and just now to make sure I got it right.
 
Moved on.

Rather than mess with it, I just used
# pkg_add -r lsof
then rkhunter installed without issue.
 
Reading this topic alongside a variety of others, and I try to understand relevant parts of the handbook …

At one machine, I followed the example at post 7 under FreeBSD 11 RELEASE do not have ports of sources and collection? and got what was required (for installation of emulators/virtualbox-ose-additions) but the result was much more than required – 2.2G on disk at [FONT=Courier New]/usr/src/[/FONT]

At a second machine, with FreeBSD-CURRENT, I took a hint from Where is the kernel source code? – aiming to get no more than is required – and encountered other difficulties:

Code:
$ cd /usr/ports/emulators/virtualbox-ose-additions/ && sudo make install clean
Password:
===>  virtualbox-ose-additions-5.1.14 requires kernel source files in /usr/src.
*** Error code 1

Stop.
make: stopped in /usr/ports/emulators/virtualbox-ose-additions
$ du -hs /usr/src
7.2M    /usr/src
$ ls -hl /usr/src
total 1
drwxr-xr-x  3 root  wheel     3B  1 Oct 19:11 trueos
$ sudo curl https://download.freebsd.org/ftp/snapshots/i386/12.0-CURRENT/kernel.txz > /usr/src/kernel.txz
sh: cannot create /usr/src/kernel.txz: Permission denied
$ curl https://download.freebsd.org/ftp/snapshots/i386/12.0-CURRENT/kernel.txz > /tmp/kernel.txz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 32.4M  100 32.4M    0     0  2744k      0  0:00:12  0:00:12 --:--:-- 2820k
$ sudo mv /tmp/kernel.txz /usr/src/
Password:
$ cd /usr/src
$ ls -hl
total 66610
-rw-r--r--  1 grahamperrin  wheel    32M 23 Mar 05:01 kernel.txz
drwxr-xr-x  3 root          wheel     3B  1 Oct 19:11 trueos
$ cd /usr/ports/emulators/virtualbox-ose-additions/ && sudo make configure
===>  virtualbox-ose-additions-5.1.14 requires kernel source files in /usr/src.
*** Error code 1

Stop.
make: stopped in /usr/ports/emulators/virtualbox-ose-additions
$ cd /usr/src ; sudo tar -xvf kernel.txz
x ./
x ./boot/
x ./usr/

…

x ./boot/kernel/rtwn-rtl8821aufw.ko
x ./boot/kernel/umass.ko
$ ls
boot            kernel.txz      trueos          usr
$ sudo rm kernel.txz
$ cd /usr/ports/emulators/virtualbox-ose-additions/ && sudo make configure
===>  virtualbox-ose-additions-5.1.14 requires kernel source files in /usr/src.
*** Error code 1

Stop.
make: stopped in /usr/ports/emulators/virtualbox-ose-additions
$

Please, what am I doing wrong?

In Stack Overflow, an answer to Redirect output to a file permission denied? helped me to understand why sudo curl will not work.

I remain confused about how to satisfy the requirement for kernel source files in [FONT=Courier New]/usr/src[/FONT]

TIA
 
OK, the first machine where I went wrong is a supported version of FreeBSD – 11.0-RELEASE-p1 #0 r306420 (I'm testing area51 stuff). For reasons that are off-topic, it was easier for me to copy some of what's above from a different machine.

I'd like to get it right. Can someone, please, give me an example of how to get kernel source files for 11.0 in [FONT=Courier New]/usr/src[/FONT] …? I'm struggling.
 
So this would be for FreeBSD 11-RELEASE
svnlite checkout https://svn.freebsd.org/base/release/11.0.0 /usr/src

Note that -RELEASE installations should use ../base/releng/11.0 to get security and bug-fix updates. ../base/release holds snapshots of the source tree that are used to build installation media, and are not updated.

The alternative to checking out the source from the SVN repo is to download the base.txz and kernel.txz src.txz distribution tarball for your architecture, extract it to /usr/src, and then run freebsd-update fetch install. This will save some space, and by default freebsd-update(8) will keep the source tree updated if it is present on the system.

EDIT: I appreciate the thanks, but I had to correct a very stupid error on my part. You need src.txz, obviously.o_O
 
more than required – 2.2G on disk at [FONT=Courier New]/usr/src/[/FONT]

– so I refrained from following the … https://svn.freebsd.org/kernel/releng/11.0 [I]…[/I] example.

Taking a hint from the Source Roadmap section of https://svn.freebsd.org/base/releng/11.0/README

Code:
sys        Kernel sources.

– and aiming for only what is required, I chose to get kernel source files for the platform of the virtual machine:

$ uname -mv
Code:
FreeBSD 11.0-RELEASE-p1 #0 r306420: Thu Sep 29 01:43:23 UTC 2016     root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

$ sudo svnlite checkout https://svn.freebsd.org/base/releng/11.0/sys/amd64 /usr/src

The result was wrong – not recognised for the purpose of installation of emulators/virtualbox-ose-additions – so I removed the copies of the source files and the /usr/src/.svn directory, then experimented with an alternative local path:

$ sudo svnlite checkout https://svn.freebsd.org/base/releng/11.0/sys/amd64 /usr/src/sys/amd64

Still wrong – less than is required – so I removed everything from /usr/src/ then experimented with a broader remote path, to include kernel source files for other platforms:

$ sudo svnlite checkout https://svn.freebsd.org/base/releng/11.0/sys /usr/src/sys

The end results were good. Not too much on disk – 674M at /usr/src/ – and a successful installation of guest additions for VirtualBox:

Code:
…
A    /usr/src/sys/nfsclient/nlminfo.h
A    /usr/src/sys/nfsserver/nfs.h
 U   /usr/src/sys
Checked out revision 315885.
$ date ; pwd
Thu 23 Mar 2017 20:58:35 UTC
/usr/ports/emulators/virtualbox-ose-additions
$ sudo make install clean
Password:
===>  Installing for virtualbox-ose-additions-5.1.18
===>   virtualbox-ose-additions-5.1.18 depends on package: libGL>0 - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xcomposite.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xdamage.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xfixes.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/x11.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xcursor.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xext.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xmu.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xorg-server.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xrandr.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on file: /usr/local/libdata/pkgconfig/xt.pc - found
===>   virtualbox-ose-additions-5.1.18 depends on shared library: libdbus-1.so - found (/usr/local/lib/libdbus-1.so)
===>  Checking if virtualbox-ose-additions already installed
===>   Registering installation for virtualbox-ose-additions-5.1.18
Installing virtualbox-ose-additions-5.1.18...
=============================================================================

VirtualBox Guest Additions were installed.

…
 
grahamperrin, I would recommend two things. The first is growing your virtual disk. VirtualBox gets updated often enough that you may as well just have an up-to-date source tree on your disk at all times. The second recommendation is that, if you're not updating your system from source, you go the freebsd-update(8) route that I outlined above. You've said repeatedly that your system is at -RELEASE-p1, while the up-to-date level is -RELEASE-p8. This means the kernel you built the VBox Guest Additions modules against may be different than the one on the running system. I don't recall if the kernel was modified in any of the updates leading to -p8, but keeping the source tree and installed system in sync is always a good idea.

You should update the installed system now. Note that doing so means you should also probably reinstall the Guest Additions.
 
Back
Top