How to: Compile the latest kernels (Classic Mint & LMDE)

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
User avatar
Acid_1
Level 5
Level 5
Posts: 796
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

How to: Compile the latest kernels (Classic Mint & LMDE)

Post by Acid_1 »

How to compile your own kernel.

I've personally tested it on:
Linux Mint 14, Cinnamon
Linux Mint Debian Edition, Cinnamon

I made a video of it, so you can see what a proper build should look like. http://www.youtube.com/watch?v=_uWjGagIQcs

The first thing we need to do is install what is needed to compile the kernel. These are the essentials:

Code: Select all

sudo apt-get install build-essential kernel-package libncurses5-dev fakeroot wget bzip2
The next line you can omit if you are comfortable with using the terminal for all your kernel options. Otherwise, if you want a GUI with point and click for your options, install the QT4 base.

Code: Select all

sudo apt-get install qt4-designer qt4-dev-tools qt4-doc qt4-linguist-tools qt4-qmake
Now we need to set up our environment variables... So, in a terminal:

Code: Select all

export CONCURRENCY_LEVEL=2 
export CHOST="x86_64-pc-Linux-gnu" 
export CFLAGS="-march=native -O2 -pipe" 
export CXXFLAGS="$CFLAGS" 
If you're running a 32bit pc, use the "x86-pc-Linux-gnu" option instead. Then we need to make a directory to contain all our building:

Code: Select all

mkdir kernel-build 
cd kernel-build 
Now we need a kernel to build. You have a few options with the kernels, but I like to get mine from kernel.org. You can pick the Mainline, Stable, or Linux-next. The differences are:

Mainline
  • The most recent kernel, released by Torvalds, with latest features, not necessarily stable
Latest Stable
  • The latest stable kernel, with updates that are only bug fixes, no new features
Linux-next
  • Not actually a version number. Hundreds of devs add to this tree daily, and there is no record of previous days kernels of this tree. It can change drastically over 24 hours, and is not recommended for production or home use
While I am personally using the 3.9 RC7 right now, I will recommend that a user compile the stable tree, so I will use that for the tutorial.

Code: Select all

wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.8.7.tar.xz
tar -Jxf linux-3.8.7.tar.xz
cd linux-3.8.7

Next we want to copy our old kernel configs to the new kernel, reducing the work we need to do for selecting options for the kernel. You can answer these to the best of your ability or you can simply press enter (return) to use the default options.

Code: Select all

cp /boot/config-`uname -r` ./.config
make oldconfig
If you chose to do the QT4 install, then use make xconfig, if not use make menuconfig.

Code: Select all

make xconfig
OR

Code: Select all

make menuconfig
Finally, we will compile the kernel and install it like any other .deb file for Mint/Ubuntu. For custom name on this kernel, I would put -mint-14-x86-64-15-04-13, so the following code would look like this:

Code: Select all

fakeroot make-kpkg --initrd --append-to-version=-customname kernel_image kernel_headers
The --append-to-version option lets you identify the kernel as your own unique kernel. Now all you do is wait a couple hours for it to compile your kernel. It will automatically be turned into a .deb for easy installation. Then simply install it with:

Code: Select all

cd ..
sudo dpkg -i linux-image-*.deb linux-headers-*.deb
sudo update-grub
Where -* is the rest of the kernel name. (You could type "sudo dpkg -i linux-image" and then press
for the terminal to finish the name for you.


Now you have your own custom kernel, congratulations. Feel free to remove the folder holding all the source code, as it's likely over 10Gb now. Keep the .debs if you have the space (they're about 55Mb combined), and have fun.

For nvidia driver users who blacklisted nouveau, you have one more step, due to a recently introduced change with nvidia drivers. Reboot into the new kernel via recovery mode. As root, run:

Code: Select all

update-initramfs -k 'uname -r'
Now run your nvidia driver .run that you have. Afterwards use:

Code: Select all

shutdown -r now
And reboot into your new kernel normally. Congratulations, you're finished!

---------

EDIT:
Lethe wrote:What you can also do is starting with a generic kernel (i.e. the standard Mint/Debian kernel) is to plug in all your devices (USB stick, USB printer etc.) so that the modules get loaded, then run in your unpacked 'linux kernel' directory:

Code: Select all

make localmodconfig
What this will do it automatically tune your config to only use the modules required on your system, and turn all the other off. A lot quicker than trying to do it manually.

Nick
-- For a leaner kernel
Last edited by Acid_1 on Sun Dec 29, 2013 12:30 pm, edited 8 times in total.
CptCrunch

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by CptCrunch »

A few Errors from above:
sudo dpkg -i linus-headers-*.deb
Should be:
sudo dpkg -i linux-headers-*.deb
And
fakeroot make-kpkg --initrd --append-to-version=-mint-14-x86_64-15-04-13 kernel_image kernel_headers
Should be:
fakeroot make-kpkg --initrd --append-to-version=-mint-14-x86-64-15-04-13 kernel_image kernel_headers
Other than that, great howto! Probably the best ive seen on kernel upgrades on the net!
Lethe

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by Lethe »

What you can also do is starting with a generic kernel (i.e. the standard Mint/Debian kernel) is to plug in all your devices (USB stick, USB printer etc.) so that the modules get loaded, then run in your unpacked 'linux kernel' directory:

Code: Select all

make localmodconfig
What this will do it automatically tune your config to only use the modules required on your system, and turn all the other off. A lot quicker than trying to do it manually.

Nick
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by catweazel »

Acid_1 wrote:

Code: Select all

export CONCURRENCY_LEVEL=2 
export CHOST="x86_64-pc-Linux-gnu" 
export CFLAGS="-march=native -O2 -pipe"
Some notes on optimising. I know you said this is standard ubuntu, however:

Code: Select all

export CONCURRENCY_LEVEL=2
That the number of jobs and is the same as make's -j option. This can be set much higher on machines with more than one core. I use 16.

Code: Select all

export CHOST="x86_64-pc-Linux-gnu"
That tells the compiler to build a dumbed down kernel and isn't optimal for high-end machines. It's the stock ubuntu setting. "i686-pc-linux-gnu" is more appropriate for later cpus, eg core2, i5, i7.

Code: Select all

export CFLAGS="-march=native -O2 -pipe" 
That too is suboptimal for later processors. march can be set to "corei7 -O2 -pipe", for example.

CHOST and CFLAGS can also be set using make menuconfig.

Cheers.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
Acid_1
Level 5
Level 5
Posts: 796
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by Acid_1 »

catweazel wrote: 1) That the number of jobs and is the same as make's -j option. This can be set much higher on machines with more than one core. I use 16.

Code: Select all

export CHOST="x86_64-pc-Linux-gnu"
2) That tells the compiler to build a dumbed down kernel and isn't optimal for high-end machines. It's the stock ubuntu setting. "i686-pc-linux-gnu" is more appropriate for later cpus, eg core2, i5, i7.

Code: Select all

export CFLAGS="-march=native -O2 -pipe" 
3) That too is suboptimal for later processors. march can be set to "corei7 -O2 -pipe", for example.

4) CHOST and CFLAGS can also be set using make menuconfig.

Cheers.
1) I was unaware of this, but thanks and I will try it next time.
2/3) That's beyond the scope of this tutorial. It's simply for those who want to have a more recent kernel on their distro. I don't have the know-how to list this in the tutorial for others, let alone all the possible architectures that are out there, and simply don't have the time, or even the will, to look that up. If the user wants these optimisations, they are more than welcome to use Google for different CFLAGS options.
4) Perhaps, but why wait until later when setting a variable, when you could just as easily forget.

Lethe wrote:What you can also do is starting with a generic kernel (i.e. the standard Mint/Debian kernel) is to plug in all your devices (USB stick, USB printer etc.) so that the modules get loaded, then run in your unpacked 'linux kernel' directory:

Code: Select all

make localmodconfig
What this will do it automatically tune your config to only use the modules required on your system, and turn all the other off. A lot quicker than trying to do it manually.

Nick
I do like this feature, and I wasn't aware of it (Thanks Nick!). However, I don't know if I'd even want to use it. What if I buy more hardware? I have to recompile it in order to have features from it work, or even the hardware's base function? What if I switch out a drive, or a mobo, or some RAM? Will I still be able to boot without a LiveCD handy or internet?

Not all these are applicable to me necessarily, but just some shortcomings I see if I were to use it myself, for others, or even some people using this guide. However, I will keep that in mind. TY.

CptCrunch wrote:A few Errors from above:
sudo dpkg -i linus-headers-*.deb
Should be:
sudo dpkg -i linux-headers-*.deb
And
fakeroot make-kpkg --initrd --append-to-version=-mint-14-x86_64-15-04-13 kernel_image kernel_headers
Should be:
fakeroot make-kpkg --initrd --append-to-version=-mint-14-x86-64-15-04-13 kernel_image kernel_headers
Other than that, great howto! Probably the best ive seen on kernel upgrades on the net!

Thansk :D And I'll make sure to fix those typos! Cheers!
teil89

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by teil89 »

I tried following the steps with your kernel as well as 10.2 and it compiles for about 20 minutes and then it stops. Only 1 .deb file is created though. It is 9.1mb. It looks like it is creating the linux image but not linux headers .deb. I should note I'm already on a different kernel from xorg-edgers. 3.7.0.7-generic. Any ideas on what I can do to fix it? I've ran it about 4 different times now.
User avatar
Acid_1
Level 5
Level 5
Posts: 796
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by Acid_1 »

teil89 wrote:I tried following the steps with your kernel as well as 10.2 and it compiles for about 20 minutes and then it stops. Only 1 .deb file is created though. It is 9.1mb. It looks like it is creating the linux image but not linux headers .deb. I should note I'm already on a different kernel from xorg-edgers. 3.7.0.7-generic. Any ideas on what I can do to fix it? I've ran it about 4 different times now.
How much free space do you have where you're compiling? It takes nearly 8.5Gb once it's done. Most of it you can delete but it's still massive.
User avatar
Acid_1
Level 5
Level 5
Posts: 796
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by Acid_1 »

Double post. Sorry.
Last edited by Acid_1 on Wed Jul 24, 2013 4:52 pm, edited 1 time in total.
teil89

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by teil89 »

I have about 200Gb in my home folder available.
teil89

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by teil89 »

This is what it's showing me.
User avatar
Acid_1
Level 5
Level 5
Posts: 796
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by Acid_1 »

I guess more importantly can you give me the last 10 or 20 lines from the output of the terminal?

Also, when you post it, make sure to use the . Thanks :)
teil89

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by teil89 »

I have a question, when running make oldconfig I just hold down enter till I get a command prompt to accept all defaults. With make menucofnig or make xconfig I just try to hit save to generate a default as well. Is this the correct way?
User avatar
Acid_1
Level 5
Level 5
Posts: 796
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by Acid_1 »

teil89 wrote:I have a question, when running make oldconfig I just hold down enter till I get a command prompt to accept all defaults. With make menucofnig or make xconfig I just try to hit save to generate a default as well. Is this the correct way?
Yup that's the same way I do it.
teil89

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by teil89 »

I misread this

Code: Select all

fakeroot make-kpkg --initrd --append-to-version=-customname kernel_image kernel_headers


and somehow have been putting it in without "kernel_image" :? Sorry about that. Thanks for your help and a great tutorial!
maxarsys

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by maxarsys »

Hi, I followed your tutorial wich is well done, but I m having trouble with xorg when I m loading the new kernel. It doesnt want to work. It says that i915 drivers is not found.

I m using a Intel HD graphic card 3000.
teil89

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by teil89 »

I had success with installing xorg-edgers ppa and then doing ctrl-alt-f1 to log out and from there logging in and doing sudo apt-get update and sudo apt-get upgrade. It should see your graphics processor and try to reinstall and configure the drivers which is all you need. Alternatively you can try to install an updated driver from synaptic but that doesn't always configure for me after a restart. Also depending on if you used the latest stable kernel, your graphics processor might not be properly supported. I know my Nvidia card didn't want to work with 3.10.2 right away so I ended up using 3.9.8. Hope this helps. If not I will respond quickly since I just woke up.
User avatar
Acid_1
Level 5
Level 5
Posts: 796
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by Acid_1 »

teil89 wrote:I had success with installing xorg-edgers ppa and then doing ctrl-alt-f1 to log out and from there logging in and doing sudo apt-get update and sudo apt-get upgrade. It should see your graphics processor and try to reinstall and configure the drivers which is all you need. Alternatively you can try to install an updated driver from synaptic but that doesn't always configure for me after a restart. Also depending on if you used the latest stable kernel, your graphics processor might not be properly supported. I know my Nvidia card didn't want to work with 3.10.2 right away so I ended up using 3.9.8. Hope this helps. If not I will respond quickly since I just woke up.
This may be of interest to you.

http://www.phoronix.com/scan.php?page=news_item&px=MTM1NTI
Previous1

Re: How to--compile the latest kernel(s) the Mint/Ubuntu way

Post by Previous1 »

While this guide doesn't suggest it, I'm going to add it as a warning. Unless you have a compelling reason not to, avoid linux-source or the mainline patches from ubuntu. They're terribly bloated, with an A64 it took me well over 12 hours to compile it, a regular kernel about 2 hours.
User avatar
Acid_1
Level 5
Level 5
Posts: 796
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

Re: How to: Compile the latest kernels (Classic Mint & LMDE)

Post by Acid_1 »

This works on LMDE too. Compiled yesterday in about 55 minutes. Kernel 3.12.6. Considering a repository to distribute latest kernels.
grml4d

Re: How to: Compile the latest kernels (Classic Mint & LMDE)

Post by grml4d »

how should i do to add the intel network driver to the kernel ?
http://sourceforge.net/projects/e1000/f ... ble/3.0.4/

edit : to compile kernel and this driver at once
Last edited by grml4d on Tue Jun 17, 2014 1:24 am, edited 1 time in total.
Post Reply

Return to “Tutorials”