[Ubuntu 14.04] Building Linux Kernel

Standard

Procedure)

1. Download kernel source of current version

apt-get source linux-image-$(uname -r)
bsw@bsw-P5K:~$ apt-get source linux-image-$(uname -r)

Reading package lists... Done
Building dependency tree
Reading state information... Done
Picking 'linux' as source package instead of 'linux-image-3.13.0-44-generic'
NOTICE: 'linux' packaging is maintained in the 'Git' version control system at:
http://kernel.ubuntu.com/git-repos/ubuntu/ubuntu-trusty.git
Need to get 125 MB of source archives.
Get:1 http://kr.archive.ubuntu.com/ubuntu/ trusty-updates/main linux 3.13.0-55.92 (dsc) [11.8 kB]
Get:2 http://kr.archive.ubuntu.com/ubuntu/ trusty-updates/main linux 3.13.0-55.92 (tar) [116 MB]
Get:3 http://kr.archive.ubuntu.com/ubuntu/ trusty-updates/main linux 3.13.0-55.92 (diff) [8752 kB]
Fetched 125 MB in 23min 56s (87.1 kB/s)
...
 linux-3.13.0/virt/kvm/async_pf.c
 linux-3.13.0/virt/kvm/coalesced_mmio.c
 linux-3.13.0/virt/kvm/ioapic.c
 linux-3.13.0/virt/kvm/iommu.c
 linux-3.13.0/virt/kvm/kvm_main.c

2. Configure build environment (one-time)

sudo apt-get build-dep linux-image-$(uname -r)
sudo apt-get update
sudo apt-get install curses-dev
bsw@bsw-P5K:~$ sudo apt-get build-dep linux-image-$(uname -r)
[sudo] password for bsw:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Picking 'linux' as source package instead of 'linux-image-3.13.0-44-generic'
The following NEW packages will be installed:
  asciidoc docbook-dsssl docbook-utils docbook-xml docbook-xsl gawk jadetex
  kernel-wedge libaudit-dev libdw-dev libdw1 libelf-dev libiberty-dev
  libnewt-dev libosp5 libostyle1c2 libsgmls-perl libslang2-dev libsp1c2
  libunwind8 libunwind8-dev lynx lynx-cur makedumpfile openjade sgml-data
  sgmlspl sp transfig xmlto xsltproc
0 upgraded, 31 newly installed, 0 to remove and 3 not upgraded.
Need to get 11.1 MB of archives.
After this operation, 51.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://kr.archive.ubuntu.com/ubuntu/ trusty/main gawk amd64 1:4.0.1+dfsg-2.1ubuntu2 [781 kB]
...
Setting up xmlto (0.0.25-2) ...
Setting up docbook-dsssl (1.79-7ubuntu1) ...
Processing triggers for sgml-base (1.26+nmu4ubuntu1) ...
Setting up docbook-utils (0.6.14-3ubuntu1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...

3. Confirm the location of kernel source (/linux-3.13.0)

Screen Shot 2015-06-16 at 10.34.18 PM

4. Example of kernel modification (keep settings) (in linux-3.13.0 directory)
cf) If you have things to modify, do that instead of this.
cf) If you don’t have things to change or just want to test kernel compile, then go to next step (step 5)

This takes the current configuration for each architecture/flavour supported and calls menuconfig to edit its config file. The chmod is needed because the way the source package is created, it loses the executable bits on the scripts.
(from https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel)

chmod a+x debian/scripts/*
chmod a+x debian/scripts/misc/*
fakeroot debian/rules clean
fakeroot debian/rules editconfigs

5. Build the kernel (might take awhile…) (in linux-3.13.0 directory)

fakeroot debian/rules clean
fakeroot debian/rules binary-headers binary-generic

6. Deb packages are created after successful build

cd ..
ls *.deb

Screen Shot 2015-06-17 at 12.16.00 AM

7. Before install deb packages, install linux-tools for right version (one-time)
(3.13.0-55 should be replaced to your kernel version)
(You might see errors when installing linux-tools, but that’s okay)

sudo apt-get install linux-tools-3.13.0-55
sudo apt-get install -f

8. Install these package to test new kernel (3.13.0-55.92 should be replaced to your kernel version, the string after generic_ and before _amd64)

sudo dpkg -i linux*3.13.0-55.92*.deb

When install deb packages, you should see messages like below (no errors)

...
Generating grub configuration file ...
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found linux image: /boot/vmlinuz-3.13.0-55-generic
Found initrd image: /boot/initrd.img-3.13.0-55-generic
Found linux image: /boot/vmlinuz-3.13.0-44-generic
Found initrd image: /boot/initrd.img-3.13.0-44-generic
Found linux image: /boot/vmlinuz-3.13.0-32-generic
Found initrd image: /boot/initrd.img-3.13.0-32-generic
Found Windows Recovery Environment (loader) on /dev/sda1
Found linux image: /boot/vmlinuz-3.13.0-55-generic
Found initrd image: /boot/initrd.img-3.13.0-55-generic
Found linux image: /boot/vmlinuz-3.13.0-44-generic
Found initrd image: /boot/initrd.img-3.13.0-44-generic
Found linux image: /boot/vmlinuz-3.13.0-32-generic
Found initrd image: /boot/initrd.img-3.13.0-32-generic
done
Setting up linux-tools-3.13.0-55-generic (3.13.0-55.92) ...

To confirm the deb packages are correctly installed (=you are ready to boot using the new kernel), type cat /boot/grub/grub.cfg | grep menuentry
You can see “Ubuntu with Linux 3.13.0-55-generic”, the version of compiled kernel.

Screen Shot 2015-06-17 at 12.56.52 AM

9. Reboot and print current kernel version

sudo reboot

After reboot, print current kernel version.

bsw@bsw-P5K:~$ uname -r
3.13.0-55-generic

Reference)
https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel
http://askubuntu.com/questions/270381/how-do-i-install-ncurses-header-files

Leave a Reply

Your email address will not be published. Required fields are marked *