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

Write tutorials and howtos in here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

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

Postby Acid_1 on Tue Apr 16, 2013 3:55 pm

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 [TAB] 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.
Website: Forkwhilefork
User avatar
Acid_1
Level 5
Level 5
 
Posts: 817
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

Linux Mint is funded by ads and donations.
 

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

Postby CptCrunch on Wed May 29, 2013 7:19 pm

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!
CptCrunch
Level 1
Level 1
 
Posts: 19
Joined: Tue May 28, 2013 9:07 am
Location: Jacksonville, FL

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

Postby Lethe on Tue Jun 11, 2013 5:28 am

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
Lethe
Level 1
Level 1
 
Posts: 3
Joined: Mon May 13, 2013 6:18 am

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

Postby catweazel on Tue Jun 11, 2013 5:34 am

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.
Mint Testing Team & Mint Donor #3606
KDE 4.12.0, custom preemptive kernel 3.12.5,
Intel i7 4770K @ 4.7GHz, 16GB 2666MHz XMP,
4 Samsung 840 PRO 512GB SSDs in RAID0,
6TB HW RAID10, dual 24" Acer X243H,
Gigabyte nVidia GTX 680 Super Overclock
User avatar
catweazel
Level 7
Level 7
 
Posts: 1656
Joined: Fri Oct 12, 2012 9:44 pm

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

Postby Acid_1 on Mon Jul 01, 2013 4:35 pm

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!
Website: Forkwhilefork
User avatar
Acid_1
Level 5
Level 5
 
Posts: 817
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

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

Postby teil89 on Tue Jul 23, 2013 12:26 am

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.
teil89
Level 1
Level 1
 
Posts: 6
Joined: Tue Jul 23, 2013 12:18 am

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

Postby Acid_1 on Tue Jul 23, 2013 11:31 pm

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.
Website: Forkwhilefork
User avatar
Acid_1
Level 5
Level 5
 
Posts: 817
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

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

Postby Acid_1 on Tue Jul 23, 2013 11:32 pm

Double post. Sorry.
Last edited by Acid_1 on Wed Jul 24, 2013 4:52 pm, edited 1 time in total.
Website: Forkwhilefork
User avatar
Acid_1
Level 5
Level 5
 
Posts: 817
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

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

Postby teil89 on Wed Jul 24, 2013 2:05 am

I have about 200Gb in my home folder available.
teil89
Level 1
Level 1
 
Posts: 6
Joined: Tue Jul 23, 2013 12:18 am

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

Postby teil89 on Wed Jul 24, 2013 12:32 pm

This is what it's showing me.
Attachments
Screenshot-Disk Usage Analyzer.png
Disk Usage.
teil89
Level 1
Level 1
 
Posts: 6
Joined: Tue Jul 23, 2013 12:18 am

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

Postby Acid_1 on Wed Jul 24, 2013 4:53 pm

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 [code][/code]. Thanks :)
Website: Forkwhilefork
User avatar
Acid_1
Level 5
Level 5
 
Posts: 817
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

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

Postby teil89 on Wed Jul 24, 2013 11:18 pm

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?
teil89
Level 1
Level 1
 
Posts: 6
Joined: Tue Jul 23, 2013 12:18 am

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

Postby Acid_1 on Thu Jul 25, 2013 8:39 pm

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.
Website: Forkwhilefork
User avatar
Acid_1
Level 5
Level 5
 
Posts: 817
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

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

Postby teil89 on Fri Jul 26, 2013 7:30 pm

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!
teil89
Level 1
Level 1
 
Posts: 6
Joined: Tue Jul 23, 2013 12:18 am

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

Postby maxarsys on Sat Aug 03, 2013 10:08 am

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.
maxarsys
Level 1
Level 1
 
Posts: 23
Joined: Mon Nov 05, 2012 3:00 am

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

Postby teil89 on Sat Aug 03, 2013 10:19 am

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.
teil89
Level 1
Level 1
 
Posts: 6
Joined: Tue Jul 23, 2013 12:18 am

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

Postby Acid_1 on Sat Aug 03, 2013 5:21 pm

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=n ... px=MTM1NTI
Website: Forkwhilefork
User avatar
Acid_1
Level 5
Level 5
 
Posts: 817
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

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

Postby Previous1 on Sat Dec 14, 2013 3:21 pm

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.
Image
Tutorials | cynicaltux
Arch Linux i3wm, 64bit
User avatar
Previous1
Level 4
Level 4
 
Posts: 367
Joined: Sun Dec 01, 2013 11:48 am

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

Postby Acid_1 on Sun Dec 29, 2013 12:10 pm

This works on LMDE too. Compiled yesterday in about 55 minutes. Kernel 3.12.6. Considering a repository to distribute latest kernels.
Website: Forkwhilefork
User avatar
Acid_1
Level 5
Level 5
 
Posts: 817
Joined: Thu Nov 01, 2007 11:12 pm
Location: Saskatchewan, Canada

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

Postby grml4d on Mon Jun 09, 2014 3:12 am

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.
grml4d
Level 1
Level 1
 
Posts: 28
Joined: Sat Jun 02, 2012 7:58 pm

Linux Mint is funded by ads and donations.
 
Next

Return to Tutorials / Howtos

Who is online

Users browsing this forum: Jim Hauser and 6 guests