# Where to put and compile a kernel?

## Yamakuzure

Hi everybody!

We have a discussion in the german part of the forums about where to put the kernel sources and where (and by whom!) to build them. (Original discussion / Google translated)

One side says: "The kernel README says you do not need to be root to compile, so you shouldn't. And kernel sources must not be placed into /usr/src/linux anyway."

The other side says: "I have always compiled my kernel in /usr/src/linux being root, and there was no harm done by it ever."

However, I found this Linux Gazette article from 2001 where kernel devs already voted against /usr/src/linux as a source and build directory (or symlink).

The questions are whether using /usr/src/linux can really be harmful, and if it can, why gentoo portage (and the handbook, of course) still wants this link to be used.

Personally I guess the said directory was banned (or tried to be banned) ten years ago, when the kernel headers didn't have their own place in /usr/include/linux which had symlinks into /usr/src/linux/include in it. This situation really could mess things up. But nowadays /usr/include/linux is free of symlinks into /usr/src/linux/include so it shouldn't matter anymore, should it?

----------

## aCOSwt

As far as I run a Linux system, I do as Linus advises and this is what he was advising about 5 months ago about linux 3 (so I believe it is not obsolete yet):

 *Linus Torvald wrote:*   

>  Linux kernel release 3.x <http://kernel.org/>
> 
> ...
> 
> These are the release notes for Linux version 3.....
> ...

 

Now of course, as you wrote it, wherever the /usr/src/linux is a symlink, there is formally no /usr/src/linux area.

So, as Gentoo does it (another dir under /usr/src), there is no real problem at all apart from the fact that /usr/src is writable by root only.

Then I would say that if it does make sense to be able to build a kernel as non-root, it also makes sense that only root can install it.

=> Download / Patch / Build your kernel at home as non-root and then leave root put the results in their appropriate locations & appropriate perms.

----------

## John5788

I've always compiled my linux sources in /usr/src/linux as root as per the official documentation. Even when you `USE=symlink emerge gentoo-sources`, the symlink generated will be pointing to a directory in /usr/src

----------

## Ant P.

That readme isn't really relevant to Gentoo. Anything that needs linux headers builds against the version installed in /usr/include/linux.

Common sense would suggest "make nconfig && make && su -c 'make modules_install install'" as the right way to compile a kernel, but most people don't do it for some reason.

----------

## Hu

The location of the source does not affect its safety, so it is fine to let the package manager unpack the source into /usr/src/linux and use that as your kernel source tree.  You can still build as an unprivileged user in this case, by setting the output environment variables correctly.  This gets you the best of all worlds:central location of source, possibly patched by the package maintainersone copy of source for N copies of built kernel, each with their own .configkernel build runs unprivileged

----------

## NeddySeagoon

folklore has it that there was once a bug in the kernel build system so it did rm -rf / which is clearly a very bad thing to do as root.

Its not very clever as a user either.

If you don't know what it does - don't test it.

I have always built may kernels as me in my ~/ and only used root to install.

/usr/src/linux points into my ~/ so that the nvidia binary blob can find a configured kernel to build against.

----------

## eccerr0r

I think this might be the lore:

The problem is that /usr/include/{linux,asm, amongst others} in glibcs of past sometimes linked to /usr/src/linux/include/ because the kernel and libc are so very tightly integrated with each other.  If you change the stuff in /usr/src/linux, you change your system /usr/include files, and sometimes may build something unrelated to the kernel wrong.

That being said I think Gentoo skirts the problem by hardcoding /usr/include links in the sys-kernel/linux-headers package so no links go to /usr/src/linux.  So really, at least on Gentoo, it should be safe to compile in /usr/src/linux....

That is, if you don't care about your /lib/modules/$VERSION/{build, source} links too ...

----------

