Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 434710 - linux-mod.eclass should set KERNEL_DIR and KBUILD_OUTPUT if not present
Summary: linux-mod.eclass should set KERNEL_DIR and KBUILD_OUTPUT if not present
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Gentoo Kernel Bug Wranglers and Kernel Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-11 09:36 UTC by Dennis Schridde
Modified: 2021-09-08 12:46 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dennis Schridde 2012-09-11 09:36:51 UTC
For example, app-emulation/virtualbox-modules does not compile when KERNEL_DIR and KBUILD_OUTPUT are not set and the sources and binaries are not both in /usr/src/linux.

Hence it would be nice if linux-info.eclass (or linux-mod - might be more appropriate) would set these variables depending on the detected running kernel version. It is difficult to automatically set these variables as make.conf, for example does not support $() substitutions (e.g. $(uname -r)).

Reproducible: Always
Comment 1 David Zaslavsky 2021-01-04 03:30:03 UTC
I'm not sure if there's any interest in dealing with this, but I am having the same problem: emerging virtualbox fails because the build products of the kernel are not placed in /usr/src/linux.

>>> Emerging (1 of 1) app-emulation/virtualbox-modules-6.1.16-r1::gentoo
>>> Failed to emerge app-emulation/virtualbox-modules-6.1.16-r1, Log file:
>>>  '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.16-r1/temp/build.log'
 * Package:    app-emulation/virtualbox-modules-6.1.16-r1
 * Repository: gentoo
 * Maintainer: polynomial-c@gentoo.org
 * USE:        abi_x86_64 amd64 elibc_glibc kernel_linux userland_GNU
 * FEATURES:   network-sandbox preserve-libs sandbox userpriv usersandbox
 * Determining the location of the kernel source code
 * Found kernel source directory:
 *     /usr/src/linux
 * Found sources for kernel version:
 *     5.10.4-gentoo
 * Could not find a usable .config in the kernel source directory.
 * Please ensure that /usr/src/linux points to a configured set of Linux sources.
 * If you are using KBUILD_OUTPUT, please set the environment var so that
 * it points to the necessary object directory so that it might find .config.
 * ERROR: app-emulation/virtualbox-modules-6.1.16-r1::gentoo failed (setup phase):
 *   Kernel not configured; no .config found in /usr/src/linux
 * 
 * Call stack:
 *                             ebuild.sh, line 125:  Called pkg_setup
 *   virtualbox-modules-6.1.16-r1.ebuild, line  37:  Called linux-mod_pkg_setup
 *                      linux-mod.eclass, line 586:  Called linux-info_pkg_setup
 *                     linux-info.eclass, line 962:  Called check_extra_config
 *                     linux-info.eclass, line 770:  Called require_configured_kernel
 *                     linux-info.eclass, line 304:  Called die
 * The specific snippet of code:
 *              die "Kernel not configured; no .config found in ${KV_OUT_DIR}"
 * 
 * If you need support, post the output of `emerge --info '=app-emulation/virtualbox-modules-6.1.16-r1::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=app-emulation/virtualbox-modules-6.1.16-r1::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.16-r1/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.16-r1/temp/die.env'.
 * Working directory: '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.16-r1/homedir'
 * S: '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.16-r1/work'
 * 
 * The following package has failed to build, install, or execute postinst:
 * 
 *  (app-emulation/virtualbox-modules-6.1.16-r1:0/6.1::gentoo, ebuild scheduled for merge), Log file:
 *   '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.16-r1/temp/build.log'
 * 

Bug #87242 seems to be related.
Comment 2 Mike Pagano gentoo-dev 2021-09-02 19:45:53 UTC
I can emerge virtualbox-modules, can you give me more detail so I can reproduce this?
Comment 3 David Zaslavsky 2021-09-02 21:25:07 UTC
Sure. I don't know what will be most useful but here's a bunch of background info. This is the procedure I use for building my kernel:

$ eselect kernel list
$ sudo eselect kernel set ...
$ cd /usr/src/linux
$ sudo mkdir build
$ sudo chown nobody:nobody build
$ zcat /proc/config.gz | sudo -u nobody tee build/.config.old >/dev/null
$ sudo -u nobody KBUILD_OUTPUT="/usr/src/linux/build" make oldconfig
$ sudo -u nobody KBUILD_OUTPUT="/usr/src/linux/build" make -j 17
$ sudo KBUILD_OUTPUT="/usr/src/linux/build" make install modules_install
$ sudo emerge -a @module-rebuild

With this procedure, the only thing that I add to the kernel source directory (/usr/src/linux) is the subdirectory build/.

$ ls -la /usr/src/linux/
total 944
drwxr-xr-x  26 root   root     4096 Aug 22 18:40 .
drwxr-xr-x   6 root   root     4096 Aug 23 18:56 ..
drwxr-xr-x  25 root   root     4096 Aug 22 18:35 arch
drwxr-xr-x   3 root   root     4096 Aug 22 18:35 block
drwxr-xr-x  21 nobody nobody   4096 Aug 22 18:44 build
drwxr-xr-x   2 root   root     4096 Aug 22 18:35 certs
-rw-r--r--   1 root   root    17019 Jun 27 15:21 .clang-format
-rw-r--r--   1 root   root       59 Jun 27 15:21 .cocciconfig
-rw-r--r--   1 root   root      496 Jun 27 15:21 COPYING
-rw-r--r--   1 root   root   100968 Jun 27 15:21 CREDITS
drwxr-xr-x   4 root   root     4096 Aug 22 18:35 crypto
drwxr-xr-x   2 root   root     4096 Aug 22 18:36 distro
drwxr-xr-x  81 root   root     4096 Aug 22 18:36 Documentation
drwxr-xr-x 140 root   root     4096 Aug 22 18:36 drivers
drwxr-xr-x  80 root   root     4096 Aug 22 18:36 fs
-rw-r--r--   1 root   root       71 Jun 27 15:21 .get_maintainer.ignore
-rw-r--r--   1 root   root       62 Jun 27 15:21 .gitattributes
-rw-r--r--   1 root   root     1959 Jun 27 15:21 .gitignore
drwxr-xr-x  29 root   root     4096 Aug 22 18:36 include
drwxr-xr-x   2 root   root     4096 Aug 22 18:36 init
drwxr-xr-x   2 root   root     4096 Aug 22 18:36 ipc
-rw-r--r--   1 root   root     1327 Jun 27 15:21 Kbuild
-rw-r--r--   1 root   root      580 Aug 22 18:35 Kconfig
drwxr-xr-x  20 root   root     4096 Aug 22 18:36 kernel
drwxr-xr-x  21 root   root    12288 Aug 22 18:36 lib
drwxr-xr-x   6 root   root     4096 Aug 22 18:35 LICENSES
-rw-r--r--   1 root   root    20121 Jun 27 15:21 .mailmap
-rw-r--r--   1 root   root   602638 Jun 27 15:21 MAINTAINERS
-rw-r--r--   1 root   root    66542 Aug 22 18:35 Makefile
drwxr-xr-x   4 root   root     4096 Aug 22 18:36 mm
drwxr-xr-x  71 root   root     4096 Aug 22 18:36 net
-rw-r--r--   1 root   root      727 Jun 27 15:21 README
drwxr-xr-x  34 root   root     4096 Aug 22 18:36 samples
drwxr-xr-x  17 root   root     4096 Aug 22 18:36 scripts
drwxr-xr-x  14 root   root     4096 Aug 22 18:36 security
drwxr-xr-x  27 root   root     4096 Aug 22 18:36 sound
drwxr-xr-x  37 root   root     4096 Aug 22 18:36 tools
drwxr-xr-x   3 root   root     4096 Aug 22 18:36 usr
drwxr-xr-x   4 root   root     4096 Aug 22 18:36 virt

In particular, /usr/src/linux/.config doesn't exist. However I do have /proc/config.gz enabled:

$ ls -l /proc/config.gz
-r--r--r-- 1 root root 30679 Sep  2 14:18 /proc/config.gz

I normally have an environment variable override to tell Portage about the kernel build directory:

$ cat /etc/portage/env/kbuild.conf
KBUILD_OUTPUT=/usr/src/linux/build
$ cat /etc/portage/package.env/40_kbuild 
app-emulation/virtualbox-modules kbuild.conf

With that override, emerging virtualbox-modules works fine. However, if I remove that file, then I can reproduce the error:

$ sudo ebuild /usr/portage/app-emulation/virtualbox-modules/virtualbox-modules-6.1.26.ebuild compile
 * vbox-kernel-module-src-6.1.26.tar.xz BLAKE2B SHA512 size ;-) ...                                                                  [ ok ]
 * checking ebuild checksums ;-) ...                                                                                                 [ ok ]
 * checking auxfile checksums ;-) ...                                                                                                [ ok ]
 * checking miscfile checksums ;-) ...                                                                                               [ ok ]
 * Determining the location of the kernel source code
 * Found kernel source directory:
 *     /usr/src/linux
 * Found sources for kernel version:
 *     5.13.12-gentoo
 * Could not find a usable .config in the kernel source directory.
 * Please ensure that /usr/src/linux points to a configured set of Linux sources.
 * If you are using KBUILD_OUTPUT, please set the environment var so that
 * it points to the necessary object directory so that it might find .config.
 * ERROR: app-emulation/virtualbox-modules-6.1.26::gentoo failed (setup phase):
 *   Kernel not configured; no .config found in /usr/src/linux
 * 
 * Call stack:
 *                          ebuild.sh, line 127:  Called pkg_setup
 *   virtualbox-modules-6.1.26.ebuild, line  33:  Called linux-mod_pkg_setup
 *                   linux-mod.eclass, line 607:  Called linux-info_pkg_setup
 *                  linux-info.eclass, line 974:  Called check_extra_config
 *                  linux-info.eclass, line 782:  Called require_configured_kernel
 *                  linux-info.eclass, line 316:  Called die
 * The specific snippet of code:
 *              die "Kernel not configured; no .config found in ${KV_OUT_DIR}"
 * 
 * If you need support, post the output of `emerge --info '=app-emulation/virtualbox-modules-6.1.26::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=app-emulation/virtualbox-modules-6.1.26::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.26/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.26/temp/environment'.
 * Working directory: '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.26/empty'
 * S: '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.26/work'

Hopefully that helps, but let me know if there's anything else in particular that you need.

If the solution to this is just that KBUILD_OUTPUT has to be set when running Portage by putting something in /etc/portage/env like I did, I get that. It works for me since my build directory is fixed. It sounded like in Dennis's case, that wouldn't be sufficient, though.
Comment 4 Mike Pagano gentoo-dev 2021-09-07 22:31:05 UTC
(In reply to David Zaslavsky from comment #3)
> Sure. I don't know what will be most useful but here's a bunch of background
> info. This is the procedure I use for building my kernel:
> 
> $ eselect kernel list
> $ sudo eselect kernel set ...
> $ cd /usr/src/linux
> $ sudo mkdir build
> $ sudo chown nobody:nobody build
> $ zcat /proc/config.gz | sudo -u nobody tee build/.config.old >/dev/null
> $ sudo -u nobody KBUILD_OUTPUT="/usr/src/linux/build" make oldconfig
> $ sudo -u nobody KBUILD_OUTPUT="/usr/src/linux/build" make -j 17
> $ sudo KBUILD_OUTPUT="/usr/src/linux/build" make install modules_install
> $ sudo emerge -a @module-rebuild
> 
> With this procedure, the only thing that I add to the kernel source
> directory (/usr/src/linux) is the subdirectory build/.
> 
> $ ls -la /usr/src/linux/
> total 944
> drwxr-xr-x  26 root   root     4096 Aug 22 18:40 .
> drwxr-xr-x   6 root   root     4096 Aug 23 18:56 ..
> drwxr-xr-x  25 root   root     4096 Aug 22 18:35 arch
> drwxr-xr-x   3 root   root     4096 Aug 22 18:35 block
> drwxr-xr-x  21 nobody nobody   4096 Aug 22 18:44 build
> drwxr-xr-x   2 root   root     4096 Aug 22 18:35 certs
> -rw-r--r--   1 root   root    17019 Jun 27 15:21 .clang-format
> -rw-r--r--   1 root   root       59 Jun 27 15:21 .cocciconfig
> -rw-r--r--   1 root   root      496 Jun 27 15:21 COPYING
> -rw-r--r--   1 root   root   100968 Jun 27 15:21 CREDITS
> drwxr-xr-x   4 root   root     4096 Aug 22 18:35 crypto
> drwxr-xr-x   2 root   root     4096 Aug 22 18:36 distro
> drwxr-xr-x  81 root   root     4096 Aug 22 18:36 Documentation
> drwxr-xr-x 140 root   root     4096 Aug 22 18:36 drivers
> drwxr-xr-x  80 root   root     4096 Aug 22 18:36 fs
> -rw-r--r--   1 root   root       71 Jun 27 15:21 .get_maintainer.ignore
> -rw-r--r--   1 root   root       62 Jun 27 15:21 .gitattributes
> -rw-r--r--   1 root   root     1959 Jun 27 15:21 .gitignore
> drwxr-xr-x  29 root   root     4096 Aug 22 18:36 include
> drwxr-xr-x   2 root   root     4096 Aug 22 18:36 init
> drwxr-xr-x   2 root   root     4096 Aug 22 18:36 ipc
> -rw-r--r--   1 root   root     1327 Jun 27 15:21 Kbuild
> -rw-r--r--   1 root   root      580 Aug 22 18:35 Kconfig
> drwxr-xr-x  20 root   root     4096 Aug 22 18:36 kernel
> drwxr-xr-x  21 root   root    12288 Aug 22 18:36 lib
> drwxr-xr-x   6 root   root     4096 Aug 22 18:35 LICENSES
> -rw-r--r--   1 root   root    20121 Jun 27 15:21 .mailmap
> -rw-r--r--   1 root   root   602638 Jun 27 15:21 MAINTAINERS
> -rw-r--r--   1 root   root    66542 Aug 22 18:35 Makefile
> drwxr-xr-x   4 root   root     4096 Aug 22 18:36 mm
> drwxr-xr-x  71 root   root     4096 Aug 22 18:36 net
> -rw-r--r--   1 root   root      727 Jun 27 15:21 README
> drwxr-xr-x  34 root   root     4096 Aug 22 18:36 samples
> drwxr-xr-x  17 root   root     4096 Aug 22 18:36 scripts
> drwxr-xr-x  14 root   root     4096 Aug 22 18:36 security
> drwxr-xr-x  27 root   root     4096 Aug 22 18:36 sound
> drwxr-xr-x  37 root   root     4096 Aug 22 18:36 tools
> drwxr-xr-x   3 root   root     4096 Aug 22 18:36 usr
> drwxr-xr-x   4 root   root     4096 Aug 22 18:36 virt
> 
> In particular, /usr/src/linux/.config doesn't exist. However I do have
> /proc/config.gz enabled:
> 
> $ ls -l /proc/config.gz
> -r--r--r-- 1 root root 30679 Sep  2 14:18 /proc/config.gz
> 
> I normally have an environment variable override to tell Portage about the
> kernel build directory:
> 
> $ cat /etc/portage/env/kbuild.conf
> KBUILD_OUTPUT=/usr/src/linux/build
> $ cat /etc/portage/package.env/40_kbuild 
> app-emulation/virtualbox-modules kbuild.conf
> 
> With that override, emerging virtualbox-modules works fine. However, if I
> remove that file, then I can reproduce the error:
> 
> $ sudo ebuild
> /usr/portage/app-emulation/virtualbox-modules/virtualbox-modules-6.1.26.
> ebuild compile
>  * vbox-kernel-module-src-6.1.26.tar.xz BLAKE2B SHA512 size ;-) ...         
> [ ok ]
>  * checking ebuild checksums ;-) ...                                        
> [ ok ]
>  * checking auxfile checksums ;-) ...                                       
> [ ok ]
>  * checking miscfile checksums ;-) ...                                      
> [ ok ]
>  * Determining the location of the kernel source code
>  * Found kernel source directory:
>  *     /usr/src/linux
>  * Found sources for kernel version:
>  *     5.13.12-gentoo
>  * Could not find a usable .config in the kernel source directory.
>  * Please ensure that /usr/src/linux points to a configured set of Linux
> sources.
>  * If you are using KBUILD_OUTPUT, please set the environment var so that
>  * it points to the necessary object directory so that it might find .config.
>  * ERROR: app-emulation/virtualbox-modules-6.1.26::gentoo failed (setup
> phase):
>  *   Kernel not configured; no .config found in /usr/src/linux
>  * 
>  * Call stack:
>  *                          ebuild.sh, line 127:  Called pkg_setup
>  *   virtualbox-modules-6.1.26.ebuild, line  33:  Called linux-mod_pkg_setup
>  *                   linux-mod.eclass, line 607:  Called linux-info_pkg_setup
>  *                  linux-info.eclass, line 974:  Called check_extra_config
>  *                  linux-info.eclass, line 782:  Called
> require_configured_kernel
>  *                  linux-info.eclass, line 316:  Called die
>  * The specific snippet of code:
>  *              die "Kernel not configured; no .config found in
> ${KV_OUT_DIR}"
>  * 
>  * If you need support, post the output of `emerge --info
> '=app-emulation/virtualbox-modules-6.1.26::gentoo'`,
>  * the complete build log and the output of `emerge -pqv
> '=app-emulation/virtualbox-modules-6.1.26::gentoo'`.
>  * The complete build log is located at
> '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.26/temp/build.
> log'.
>  * The ebuild environment file is located at
> '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.26/temp/
> environment'.
>  * Working directory:
> '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.26/empty'
>  * S: '/var/tmp/portage/portage/app-emulation/virtualbox-modules-6.1.26/work'
> 
> Hopefully that helps, but let me know if there's anything else in particular
> that you need.
> 
> If the solution to this is just that KBUILD_OUTPUT has to be set when
> running Portage by putting something in /etc/portage/env like I did, I get
> that. It works for me since my build directory is fixed. It sounded like in
> Dennis's case, that wouldn't be sufficient, though.

For you I believe KBUILD_OUTPUT is the solution here.
Comment 5 Mike Pagano gentoo-dev 2021-09-07 22:31:42 UTC
Dennis,

Please re-open if this is still an issue today.
Comment 6 Dennis Schridde 2021-09-08 12:46:51 UTC
I use sys-kernel/gentoo-kernel with /etc/portage/savedconfig/sys-kernel/gentoo-kernel these days.

I also still have `alias emerge='env KERNEL_DIR=/usr/src/linux-$(uname -r) KBUILD_OUTPUT=/home/$ADMINUSER/build-$(uname -r) /usr/bin/emerge'` in my /root/.bashrc. I will report back if removing that has any consequence.