# Genkernel runs as root?

## awdas

Hello, I have a question concerning genkernel, does it run as root?

Is there any known way to build the kernel via portage? I'd love to use the sandbox it provides (and unprivileged user).

----------

## The Doctor

Yes, genkernel is designed to run as root. So does portage.

If you really want to build the kernel as a user you can do so. You will either have to download the sources yourself or chown the portage installed sources (at your own risk). There is no way for portage to build the kernel by itself because it has no way of knowing what features you want. Genkernel can't because it requires root privileges to install the kernel.

----------

## Jaglover

Actually portage runs as portage, although initiated by root it drops the rights for fetching and building.

----------

## mv

 *The Doctor wrote:*   

>  build the kernel as a user [...] You will either have to download the sources yourself or chown the portage installed sources (at your own risk).

 

Neither is necessary: You just have to define an output directory which belongs to portage:portage and set KBUILD_OUTPUT to that directory. Set KERNEL_DIR to /usr/src/linux.

Then you can compile as portage. There is a kernel script (can be installed over portage from the mv overlay) which does this if the above variables are set up:

It must be called as root, but will drop permissions for compilation to "portage"; then it restores root permissions for installation and setting symlinks.

It is written to match my personal kernel management, but if you prefer a different one and write patches to the script which support both, I will gladly extend the script...

----------

## awdas

 *mv wrote:*   

>  *The Doctor wrote:*    build the kernel as a user [...] You will either have to download the sources yourself or chown the portage installed sources (at your own risk). 
> 
> Neither is necessary: You just have to define an output directory which belongs to portage:portage and set KBUILD_OUTPUT to that directory. Set KERNEL_DIR to /usr/src/linux.
> 
> Then you can compile as portage. There is a kernel script (can be installed over portage from the mv overlay) which does this if the above variables are set up:
> ...

 

This is what I was looking for, thanks! I'll look at it, and might send some push request if I have time.

I also thought about making an ebuild for hardened-sources that calls portage's make functions with USE flags to determine the configuration mechanism (ex USE=menuconfig), I'll see if that feasible.

----------

## mv

 *awdas wrote:*   

> I also thought about making an ebuild for hardened-sources that calls portage's make functions with USE flags to determine the configuration mechanism (ex USE=menuconfig), I'll see if that feasible.

 

I prefer a separate script, because reconfiguring/recompiling the kernel and installing the sources are two separate things and the latter does not always have to be repeated before the former. Also note that an interactive ebuild is usually always a bad idea. Yet another argument against it: A script is somewhat distribution independent (though the mentioned kernel scripts supports many gentoo-specific features [like using the portage user by default], these features are optional).

----------

## awdas

 *mv wrote:*   

>  *awdas wrote:*   I also thought about making an ebuild for hardened-sources that calls portage's make functions with USE flags to determine the configuration mechanism (ex USE=menuconfig), I'll see if that feasible. 
> 
> I prefer a separate script, because reconfiguring/recompiling the kernel and installing the sources are two separate things and the latter does not always have to be repeated before the former. Also note that an interactive ebuild is usually always a bad idea. Yet another argument against it: A script is somewhat distribution independent (though the mentioned kernel scripts supports many gentoo-specific features [like using the portage user by default], these features are optional).

 

Hmm, I think you're right, portage doesn't even seem to support interactive ebuild.

I don't know if it's a bug, but it won't redirect your input to the config utilities, probably because of a combination of sandbox + chroot?.

Although a script is fun because it's distribution independent, a full integration of the kernel building and initramfs building into portage would be awesome.

----------

## szatox

 *Quote:*   

> portage doesn't even seem to support interactive ebuild. 

 

It does.

I recall there are some ebuilds for games that require you to copy data files into some specific location. You could probably use it to let the user know it's time for menuconfig (or set USE=savedconfig and  try building new kernel with config stored in /etc - non-interactively)

----------

