[SOLVED] Building kernel from source at /usr/src as user
SlackwareThis Forum is for the discussion of Slackware Linux.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Up until recently I've been building my kernels as a root. Today I had some free time and decided to read the whole README file accompanying the latest kernel-source (3.2.13, Slackware). The author of this file (Linus Torvalds?) clearly states the we should avoid building the kernel as root. Does anybody know why? If that is the case why slackpkg preserves root:root ownership during kernel-source installation? I am aware that this is a Slackware related issue, since one can download the vanilla source in his home directory and build it without su permission.
There are some opinions that one can change the ownership of /usr/src to root:xxx granting write access to user from the group xxx, but after installing a new kernel-source the ownership is reverted back to root:root and I need to change to ownership of the directory every time I install a new kernel-source.
Does anybody has a clue what would be the safest (without using another machine) and elegant way to build and install new kernels?
Last edited by Alkin; 03-30-2012 at 03:17 AM.
Reason: Changed the title
Click here to see the post LQ members have rated as the most helpful post in this thread.
Install the kernel in ~/ - that's the safest way. You need most of a gig in home to do that, but whatever blows up, it will stay as a luser.
BTW I take these discussions with a grain of salt, because a kernel compile is the most tried & tested build system anywhere. Heads debate how safe is safe; It's really _you_ is the danger. The scripts work, but what are you going to type.
Sometimes it is easier to have the source code for the kernel tree in a read-only
location (such as on a CD-ROM, or in a source code control system), and place
the output of the kernel build elsewhere, so that you do not disturb the original
source tree. The kernel build system handles this easily, by requiring only the
single argument O= to tell it where to place the output of the build. For example, if
the kernel source is located on a CD-ROM mounted on /mnt/cdrom/ and you wish
to place the built files in your local directory, enter:
$ cd /mnt/cdrom/linux-220.127.116.11
$ make O=~/linux/linux-18.104.22.168
All of the build files will be created in the ~/linux/linux-22.214.171.124/ directory.
Please note that this O= option should also be passed to the configuration options
of the build so that the configuration is correctly placed in the output directory
and not in the directory containing the source code.
from the book, Linux Kernel in a Nutshell, by Greg Kroah-Hartman, published by O'Reilly have helped me figure out an elegant way of building the Linux kernel as user. Still not very clear why I shouldn't build it as root though...
@hf2046 Thanks for the link, very helpful.
from the book, Linux Kernel in a Nutshell, by Greg Kroah-Hartman, published by O'Reilly have helped me figure out an elegant way of building the Linux kernel as user.
... which is exactly the approach my build script above takes, only my script has a bit added onto the end that packages it up.
The "don't build as root" thing is simply a "We might make a mistake in the Makefile and if we do and it's running as root anything can happen" sort of deal. Its more likely a consideration with the development kernels or release candidates though. By the time it gets to a release tarball these sorts of problems ought to have been discovered and shouldn't be an issue.
Even those who say "Don't build as root" generally tell you the 'make modules_install' has to be done as root, and if that has to be done as root then I really don't see much advantage from not doing the rest of it as root.
Generally I like the idea of staying away from root as much as possible . Only because I might be careless enough to leave myself in root and accidently bringing up an application that probably shouldn't be run as root.
Sometimes we have to protect us from ourselves .
Anyways, my point in regards to this thread is that I haven't seen any issues at all in compiling the linux kernel as the user. As Gazl points out though, you can't get away w/ running make modules_install w/o running as root. And most likely to update your boot location, and also lilo, you'd have to run as root as well, but these don't take any time at all to do compared to compiling the kernel.
In the end, do what you got to do to get the job done with whatever security works for you.
As Gazl points out though, you can't get away w/ running make modules_install w/o running as root.
Strictly speaking you can, but you'll need root at some point to make it possible (even if it's only a little chowning before and after). It all depends on how many hoops you're prepared to jump through to avoid it and whether it's worth the effort.
Well it turns out that the method with outputting the build to another directory (O=) requires preliminary use of "make mrproper" which wants to remove "./kernel/bounds.s" and "./arch/x86/kernel/asm-offsets.s" files from the source directory. Is it save to remove these files? Are they unnecessary? I presume these are Slackaware specific?