build and install linux kernel

If you want to alter some feature of the kernel, then you will have to change the source or configure of linux kernel before compiling it. Here is some steps to do this. I will take linux-4.3 as an example.

Get a distribution of linux kernel source code.

You can get any version from github. Then here's some software you'll have to install.

$sudo apt-get update
$sudo apt-get install git fakeroot build-essential  ncurses-dev xz-utils libssl-dev bc
$cd linux-4.3

Configuring and Compiling

There is an easy way to do the configure, which is to copy your own configure to the directory.

$cp  /boot/config-*(uname -r) .config
$make menuconfig
$sudo make -j 4
$sudo make modules_install -j 4 && sudo make install -j 4

If your host system is 64bit, then it is fine to do just `make menuconfig`, and you will compile a 64bit kernel finally. When you need to compile a 64bit on a 32bit system, then it is necessary to do `make ARCH=x86_64 menuconfig`

Final steps

After the compile and install, we should choose to use the new kernel the next time we boot up.

$update-initramfs -c -k 4.3

And then use the following command to look for the kernels present in the boot folder. And update grub file

$update-grub

And then restart your system,and choose which kernel you use before start linux, use uname -r to show which kernel you are using

choose which kernel to boot

This operation is optional, if you can't choose the kernel when you are booting.

First change the file /etc/default/grub, and then uncomment the line GRUB_HIDDEN_TIMEOUT=0

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_THEME=/boot/grub/themes/Vimix/theme.txt


GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)

and then update grub, then boot to choose the advanced option.

sudo update-grub

Last updated