SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-02-24 10:02:23

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

How to compile the kernel from source.

Warning: Do not do this on a production machine.

If it breaks you get to keep all pieces. No support for this in the Crunchbang Forums!

It works like this:

0. Prerequisites:
   

apt-get install git build-essential

1. Get a copy of the linux-stable tree:
   

git clone -o stable \
     git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git \
     linux
    cd linux

     Or, if you already have a clone of the kernel:
   

git remote add -f stable \
    git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git \
        linux
    cd linux

2. Now for the latest version:
   

git checkout stable/linux-3.2.y

   

cp /boot/config-$(uname -r) .config;

# current configuration
   

make localmodconfig; 

# optional: minimize configuration
                  Go with the default for every question asked - just <enter>
   

make deb-pkg;

# optionally with -j<num> for parallel build
   

dpkg -i ../<name of package>

                  Do this for the kernel package and the firmware package
    reboot
                 into the new kernel

Enjoy

Last edited by xaos52 (2012-02-25 15:08:49)

Offline

Help fund CrunchBang, donate to the project!

#2 2012-02-24 14:17:45

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: How to compile the kernel from source.

thank you xaos! big_smile

Offline

#3 2012-02-25 11:39:36

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to compile the kernel from source.

Curious, How to best un-compile as well -

I have compiled Kernels with apt and want to completely remove all related files for some Kernels as no longer needed - for this I used aptitude. However, I noticed /lib/modules and /usr/share still have related files after this removal:

:~$ sudo aptitude remove linux-image-3.2.0-6.dmz.1-liquorix-686 linux-headers-3.2.0-5.dmz.1-liquorix-686

So, how does one complete a better clean-up if desired to remove all Kernel files after install?

Offline

#4 2012-02-25 14:32:06

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: How to compile the kernel from source.

As far as I know, you can not compile a kernel with apt nor aptitude. Both tools install the binary packages.

For removing a package completely use the command

sudo apt-get --purge remove <package name>

I am not sure if removing and purging a kernel removes the associated /lib/modules/kernel-version.
I would have to test if it does.
What I am sure of is that you can remove the directory manually with

sudo rm -rf /lib/modules/<kernel-version-you-want-to-remove>

hth

Offline

#5 2012-02-25 14:55:08

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to compile the kernel from source.

Both tools install the binary packages

Oh,

what is the advantage of compiling over the binary packages?

Offline

#6 2012-02-25 14:56:28

Unia
#! Octo-portal-pussy
From: The Netherlands
Registered: 2010-07-17
Posts: 4,059

Re: How to compile the kernel from source.

Xaos, how about putting all terminal commands in code tags? That would make this good guide clear to follow


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Github

I am a #! forum moderator. Feel free to send me a PM with any question you have!

Offline

#7 2012-02-25 14:57:31

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: How to compile the kernel from source.

Compiling allows you to test newer kernels that are not available as binary packages yet. Normally there is no advantage, except if you have brand new hardware that is not, or not well supported in the binary package yet.

Offline

#8 2012-02-25 16:56:07

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to compile the kernel from source.

I am not sure if removing and purging a kernel removes the associated /lib/modules/kernel-version.
I would have to test if it does.

well, getting different results:

- -purge remove....

does remove the /lib/modules/kernel-version as well as /usr/share/bug/kernel-version unless it returns this error:

rmdir: failed to remove `/lib/modules/2.6.33.7.2-rt30-1-686': Directory not empty
dpkg: warning: while removing linux-image-2.6.33.7.2-rt30-1-686, directory '/lib/modules/2.6.33.7.2-rt30-1-686' not empty so not removed.

Offline

#9 2012-02-25 17:08:06

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: How to compile the kernel from source.

I do not know if this is a bug or if it is a safety measure to prevent you from removing the modules inadvertently.

If you are sure you want these removed, then do:

sudo rm -rf /lib/modules/2.6.33.7.2-rt30...
sudo apt-get --purge remove ....

hth

Offline

#10 2012-02-25 17:50:12

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to compile the kernel from source.

using for example

~$ sudo rm -rf /lib/modules/2.6.33.7.2-rt30-1-686/

cleaned up well


With your git method installed, how would one remove a compiled Kernel?

Offline

#11 2012-02-25 17:56:35

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: How to compile the kernel from source.

In 2 steps:

1. If you installed the new kernel, then remove it like you would with any other kernel. Itwas installed with dpkg -i , so it follows the rules as if it was installed with apt.

2. if you want to get rid of all sources:
    remove the top level linux directory:

    cd to the directory where you executed the git command

sudo rm -rf linux
sudo rm -rf .git

Last edited by xaos52 (2012-02-25 17:57:54)

Offline

#12 2012-02-25 18:07:36

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to compile the kernel from source.

curious, could one use this compile method to get a 3.2 liquorix i686 Kernel working by changing the source in step 1 of install?

Offline

#13 2012-02-25 18:42:45

mynis01
#! Die Hard
From: 127.0.0.1
Registered: 2010-07-02
Posts: 1,965

Re: How to compile the kernel from source.

There are all ready pre-compiled debian packages of the latest liquorix kernels available that always work well for me. You could download the vanilla 3.2.7-1 kernel and then apply the liquorix patch before you compile it, the patch can be found here: http://liquorix.net/sources/3.2.7-1.patch.gz. Alternatively, you could apply the ZEN, SMP, and PREEMPT patches yourself and you would have a kernel that is pretty close to liquorix. There's also some other cool patches you could try out, like the BFS scheduler, that optimize your machine for desktop use.

Offline

#14 2012-02-25 19:00:33

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to compile the kernel from source.

OK, so..- the 3.2.7-1 Kernel - for i686/32-bit will work with the liquorix patch? or any corresponding set of Kernel version and liquorix patch?

Offline

#15 2012-02-25 19:16:41

kd5ob
#! CrunchBanger
From: Oklahoma
Registered: 2012-02-02
Posts: 208

Re: How to compile the kernel from source.

This is a good lesson.  But, I find it funny that we could compile kernel modules using aptitude such as the Broadcom in the past yet, they have no aptitude .deb setup which would invoke automatically as you've suggested.  Break for menu and so on.....

Maybe Debian wouldn't do this but, perhaps in the future Crunch Bang could.  It could be one of their MARKS.

Offline

#16 2012-02-26 17:51:47

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to compile the kernel from source.

I ended up adding apt source for Kernels: (running 3.2.0-0.bpo.1-486)

## Liquorix Kernel by damentz http://www.liquorix.net/ .
# Secure Apt: apt-get install '^liquorix-([^-]+-)?keyring.?'
# Latest "stable" kernel
deb http://liquorix.net/debian/ sid main
# RC/Beta kernels
#deb http://liquorix.net/debian/ sid main future

applied the keyring - updated

and installed:

3.2.0-7.dmz.1-liquorix-686

so far so good

Offline

#17 2012-03-22 16:29:55

Marceau
#! CrunchBanger
Registered: 2012-01-09
Posts: 103

Re: How to compile the kernel from source.

Pretty awesome! I've now rolled my own kernel and am using it as we speak. smile

I did follow a slightly different procedure though, as git was unbearably slow for me (20-30KB/s).

I downloaded the most recent mainline 3.3 from kernel.org, unzipped it in a folder, put a terminal in that folder and then followed the commands you wrote

cp /boot/config-$(uname -r) .config

make localmodconfig

make -j4 deb-pkg

I just installed the deb packages by double-clicking them. A habit from the old days, I guess.

I wonder though, if you don't mind my asking, what does "cp /boot/config-$(uname -r) .config" actually do? Am I right in guessing it just copies the config of the currently installed kernel to the source directory? How does its presence/absence influence the make process?

Offline

#18 2012-03-22 16:40:57

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: How to compile the kernel from source.

Your guess is correct.
It influences the localmodconfig: Only questions that are not answered in the current config are asked.

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo