LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 03-30-2012, 02:24 AM   #1
Alkin
LQ Newbie
 
Registered: Sep 2006
Location: Bulgaria
Distribution: Slackware
Posts: 24

Rep: Reputation: 2
Building kernel from source at /usr/src as user


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?

Cheers

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.
Old 03-30-2012, 02:32 AM   #2
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 5,953

Rep: Reputation: 496Reputation: 496Reputation: 496Reputation: 496Reputation: 496
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.
 
Old 03-30-2012, 06:50 AM   #3
GazL
Senior Member
 
Registered: May 2008
Posts: 3,231

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
I wrote this for my own use but you're welcome to take a look/use it if you wish. It's a little unconventional.

It works best if you have set LOCALVERSION in your config files. I use "-generic" and "-custom" for mine, depending on whether it's based on Pat's .config file or my own..

Last edited by GazL; 04-21-2012 at 05:38 AM.
 
1 members found this post helpful.
Old 03-30-2012, 07:15 AM   #4
Alkin
LQ Newbie
 
Registered: Sep 2006
Location: Bulgaria
Distribution: Slackware
Posts: 24

Original Poster
Rep: Reputation: 2
Interesting and useful. Many thanks for sharing!
 
Old 03-30-2012, 08:59 AM   #5
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,238

Rep: Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299
This is the definitive guide to building a new kernel on Slackware.

http://alien.slackbook.org/dokuwiki/...kernelbuilding
 
Old 03-30-2012, 09:17 AM   #6
hf2046
Member
 
Registered: Mar 2011
Distribution: Slack64
Posts: 108

Rep: Reputation: 20
Quote:
Originally Posted by Alkin View Post
Does anybody has a clue what would be the safest (without using another machine) and elegant way to build and install new kernels?
And this is the definitive guide to building Linux kernels, written by a kernel maintainer. He gives an example why you shouldn't build as root.

http://www.kroah.com/lkn/
 
3 members found this post helpful.
Old 03-31-2012, 02:09 AM   #7
Alkin
LQ Newbie
 
Registered: Sep 2006
Location: Bulgaria
Distribution: Slackware
Posts: 24

Original Poster
Rep: Reputation: 2
The paragraph

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-2.6.17.11
$ make O=~/linux/linux-2.6.17.11
All of the build files will be created in the ~/linux/linux-2.6.17.11/ 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.
 
Old 03-31-2012, 02:39 AM   #8
GazL
Senior Member
 
Registered: May 2008
Posts: 3,231

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
Quote:
Originally Posted by Alkin View Post
The paragraph
...snip...

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.
 
1 members found this post helpful.
Old 03-31-2012, 03:46 AM   #9
Alkin
LQ Newbie
 
Registered: Sep 2006
Location: Bulgaria
Distribution: Slackware
Posts: 24

Original Poster
Rep: Reputation: 2
I see... "O=" is something new for me, thanks. I can mark this thread as solved, thanks to everyone.

Last edited by Alkin; 03-31-2012 at 03:58 AM. Reason: post -> thread
 
Old 03-31-2012, 09:22 PM   #10
tmmukunn
Member
 
Registered: Nov 2007
Distribution: Slackware
Posts: 34

Rep: Reputation: 5
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.
 
Old 04-01-2012, 06:03 AM   #11
GazL
Senior Member
 
Registered: May 2008
Posts: 3,231

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
Quote:
Originally Posted by tmmukunn View Post
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.
 
Old 04-01-2012, 11:22 AM   #12
Alkin
LQ Newbie
 
Registered: Sep 2006
Location: Bulgaria
Distribution: Slackware
Posts: 24

Original Poster
Rep: Reputation: 2
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?
 
Old 04-01-2012, 12:08 PM   #13
GazL
Senior Member
 
Registered: May 2008
Posts: 3,231

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
They won't be slackware specific. And it's always a good idea to do make mrproper or make distclean before you build from the source.
 
Old 04-01-2012, 12:22 PM   #14
Alkin
LQ Newbie
 
Registered: Sep 2006
Location: Bulgaria
Distribution: Slackware
Posts: 24

Original Poster
Rep: Reputation: 2
Ah I see, but then it requires su permissions...
 
Old 04-02-2012, 04:45 PM   #15
GazL
Senior Member
 
Registered: May 2008
Posts: 3,231

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
I just updated to 3.2.14 and thought you might be interested in seeing my approach in action.
.
Code:
build@slackbox:~$ dmesg | head -1
Linux version 3.2.14-custom (build@slackbox) (gcc version 4.7.0 (GCC) ) #1 SMP Mon Apr 2 20:47:56 BST 2012
As you can see the new kernel was built by 'build' and not root.


And this is how I got there.

History of my 'build' user
Code:
  491  cd /local/mirrors/linux-stable/
  492  git fetch --all
  493  git pull
  494  git clean -d -f
  495  su root -c "mkdir /usr/src/linux-3.2.14 && cp -r * /usr/src/linux-3.2.14"
  496  cd
  497  ./kernel.SlackBuild -s /usr/src/linux-3.2.14
(I prefer to keep my git tree separate to the source I build from, but I could have built from the git tree if I had wanted to and avoided an additional step and a 'su' .)


And then as root:
Code:
  494  installpkg kernel-3.2.14_custom-x86_64-1_gazl.txz 
  495  cd ../nvidia/
  496  ./NVIDIA-Linux-x86_64-295.33-no-compat32.run -s -K -k 3.2.14-custom
  497  cd
  498  VERSION=3.2.14-custom ./maint/initrd_build.sh 
  499  vi /etc/lilo.conf
  500  /sbin/lilo
(Don't worry too much about the initrd_build script: it is just a front end to mkinitrd - nothing much of interest in there.)

... and job done... reboot to shiny new kernel.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can anyone tell me where is the source files of /usr/src/kernel/../usb/storage amwjatyvh Red Hat 2 08-02-2011 05:41 AM
FreeBSD 6.2, no /usr/src/tools and /usr/src/usr.bin, failed to build world. Mr_Shameless *BSD 4 05-16-2008 08:43 AM
keeping compiling kernel source in /usr/src after compile ph0t0n1st Linux - Hardware 2 03-26-2008 06:48 AM
Why build a kernel outside the traditional /usr/src area? ssenuta Linux - General 4 08-26-2006 11:32 AM
rpmbuild doesn't produce the source code in /usr/src/redhat/BUILD Niceman2005 Linux - Software 2 11-29-2004 05:58 PM


All times are GMT -5. The time now is 09:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration