Compilar Kernel
Compilar Kernel
≡ MENU
nixCraft
Linux and Unix tutorials for new and seasoned sysadmin.
In order to create a custom kernel configuration file and build a custom kernel, the
full Linux kernel source tree must first be downloaded and installed. The latest
Linux kernel stable version is 4.5. In this tutorial, you will learn how to compile
the Linux kernel version 4.5 on a Debian and Ubuntu Linux operating system
and build .deb file.
1 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
Note: The following instructions were tested on both Debian Linux v8.x and
Ubuntu Linux v14.04.4 LTS.
Prerequisites
git : Fast, scalable, distributed revision control system. You can grab the
latest source code using the git command.
fakeroot : Tool for simulating superuser privileges. Useful to build .deb files.
build-essential : Tools for building the Linux kernel such as GCC compiler
and related tools on a Debian or Ubuntu Linux based system.
ncurses-dev : Developer’s libraries for ncurses. This is used by menuconfig
while configuring the kernel options.
kernel-package : Utility for building Linux kernel related Debian packages.
xz-utils : XZ-format compression utilities to decompress the Linux kernel tar
ball.
2 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
Open the terminal application. Type the following apt-get command to install the
required packages for building the Linux kernel:
Sample outputs:
3 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
OR
Sample outputs:
$ wget https://cdn.kernel.org/pub/linux/kernel
/v4.x/linux-4.5.tar.xz
4 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
Sample outputs:
Fig.03: Use the wget to grab the latest source code from kernel.org
$ unxz linux-4.5.tar.xz
$ gpg --verify linux-4.5.tar.sign
Sample outputs:
Get the public key from the PGP keyserver in order to verify the signature i.e.
RSA key ID 00411886 (from the above outputs):
Sample outputs:
5 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
Sample outputs:
If you do not “BAD signature” output from “gpg --verify” command, untar the
Linux kernel tar ball using the tar command enter:
Sample outputs
linux-4.5/
linux-4.5/.get_maintainer.ignore
linux-4.5/.gitignore
linux-4.5/.mailmap
6 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
linux-4.5/COPYING
linux-4.5/CREDITS
linux-4.5/Documentation/
linux-4.5/Documentation/00-INDEX
linux-4.5/Documentation/ABI/
linux-4.5/Documentation/ABI/README
linux-4.5/Documentation/ABI/obsolete/
linux-4.5/Documentation/ABI/obsolete/proc-sys-vm-nr_pdflush_threads
....
...
linux-4.5/virt/kvm/async_pf.h
linux-4.5/virt/kvm/coalesced_mmio.c
linux-4.5/virt/kvm/coalesced_mmio.h
linux-4.5/virt/kvm/eventfd.c
linux-4.5/virt/kvm/irqchip.c
linux-4.5/virt/kvm/kvm_main.c
linux-4.5/virt/kvm/vfio.c
linux-4.5/virt/kvm/vfio.h
linux-4.5/virt/lib/
linux-4.5/virt/lib/Kconfig
linux-4.5/virt/lib/Makefile
linux-4.5/virt/lib/irqbypass.c
linux-4.5
7 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
$ cd linux-4.5
$ cp /boot/config-$(uname -r) .config
$ make menuconfig
Sample outputs:
WARNING: It is easy to remove support for a device driver or option and end
up with a broken kernel. For example, if the ext4 driver is removed from the
8 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
kernel configuration file, a system may not boot. When in doubt, just leave
support in the kernel.
Make sure you save the changes before exit from menuconfig.
You need to clean the source tree and reset the kernel-package parameters, type:
$ make-kpkg clean
Sample outputs:
To speed up the compile process pass the -j option (-j 16 means you are using
all 16 cores to compile the Linux kernel):
9 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
kernel_image kernel_headers -j 16
Sample outputs:
Please note that kernel compilation may take quite a while, depending on the
power of your machine. On my shared 4 CORE CPU and 4GB ram it took 60
10 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
mins to build the Linux kernel. In the end you should see something as follows on
screen:
$ ls ../*.deb
../linux-headers-4.5.0_1.0.NAS_amd64.deb ../linux-image-4.5.0_1.0.NAS
Type the following dpkg command to install a custom kernel on your system:
Sample outputs:
11 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
Done.
Unpacking linux-image-4.5.0 (1.0.NAS) ...
Setting up linux-image-4.5.0 (1.0.NAS) ...
Running depmod.
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.5.0 /boot/vmlinuz-4.5.0
run-parts: executing /etc/kernel/postinst.d/dkms 4.5.0 /boot/vmlinuz-4.5.0
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.5.0 /boot/vmlinuz-4.5.0
update-initramfs: Generating /boot/initrd.img-4.5.0
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.5.0 /boot/vmlinuz-4.5.0
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.5.0
Found initrd image: /boot/initrd.img-4.5.0
Found linux image: /boot/vmlinuz-4.4.4
Found initrd image: /boot/initrd.img-4.4.4
Found linux image: /boot/vmlinuz-4.4.2
Found initrd image: /boot/initrd.img-4.4.2
Found linux image: /boot/vmlinuz-4.4.0
Found initrd image: /boot/initrd.img-4.4.0
Found linux image: /boot/vmlinuz-4.3.0
Found initrd image: /boot/initrd.img-4.3.0
Found linux image: /boot/vmlinuz-4.2.5
Found initrd image: /boot/initrd.img-4.2.5
Found linux image: /boot/vmlinuz-4.2.0
Found initrd image: /boot/initrd.img-4.2.0
done
$ reboot
OR
$ shutdown -r now
12 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
Type the following command to verify your new kernel and everything is working
fine:
$ uname -a
$ uname -r
$ uname -mrs
$ dmesg | more
$ dmesg | egrep -i --color 'error|critical|failed'
Sample outputs:
And, there you have it, the Linux kernel version 4.4.4 installed and working
correctly.
See also
13 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
About the author: Vivek Gite is a seasoned sysadmin and a trainer for the Linux/Unix
& shell scripting. Follow him on Twitter. OR read more like this:
CentOS Linux install kernel headers to build vmware / 3rd party modules
How do I upgrade the kernel in Linux without compiling from source code?
You need to have the Linux kernel source installed for this driver
New kernels will automatically come with newer updates/distro, but the
learning experience of compiling kernel is priceless.
14 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
REPLY LINK
REPLY LINK
4.2 is stable. Ubuntu built packages are behind the schedule and
most likely built when 4.2 was in beta. Also, some propitiatory NVIDIA/ATI &
others driver may not work on the latest version 4.2. YMMV.
REPLY LINK
Hi Vivik,
Thanks for the tutorial. I followed the same steps you mentioned but I found one
file ( abi ) is missing on my macbook (parallels + ubuntu 14.04) , here is /boot
folder. Do you know which step is wrong ?
15 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
parallels@ubuntu:/boot$ ls -al
total 115040
drwxr-xr-x 3 root root 4096 Sep 22 16:42 .
drwxr-xr-x 23 root root 4096 Sep 21 19:25 ..
-rw-r--r-- 1 root root 1158016 May 3 2014 abi-3.13.0-24-generic
-rw-r--r-- 1 root root 1162712 Aug 14 2014 abi-3.13.0-34-generic
-rw-r--r-- 1 root root 1165204 Aug 15 07:07 abi-3.13.0-63-generic
-rw-r--r-- 1 root root 165510 May 3 2014 config-3.13.0-24-generic
-rw-r--r-- 1 root root 165611 Aug 14 2014 config-3.13.0-34-generic
-rw-r--r-- 1 root root 165763 Aug 15 07:07 config-3.13.0-63-generic
-rw-r--r-- 1 root root 182704 Sep 22 16:35 config-4.2.0-hell-kernel
-rw-r--r-- 1 root root 182704 Sep 22 15:23 config-4.2.0-hell-kernel.o
drwxr-xr-x 5 root root 4096 Sep 22 16:42 grub
-rw-r--r-- 1 root root 19096859 Aug 18 2014 initrd.img-3.13.0-24-gener
-rw-r--r-- 1 root root 19145542 Sep 8 10:29 initrd.img-3.13.0-34-gener
-rw-r--r-- 1 root root 19219306 Sep 18 00:24 initrd.img-3.13.0-63-gener
-rw-r--r-- 1 root root 18069958 Sep 22 16:42 initrd.img-4.2.0-hell-kern
-rw-r--r-- 1 root root 176500 Mar 12 2014 memtest86+.bin
-rw-r--r-- 1 root root 178176 Mar 12 2014 memtest86+.elf
-rw-r--r-- 1 root root 178680 Mar 12 2014 memtest86+_multiboot.bin
-rw------- 1 root root 3372643 May 3 2014 System.map-3.13.0-24-gener
-rw------- 1 root root 3381262 Aug 14 2014 System.map-3.13.0-34-gener
-rw------- 1 root root 3392068 Aug 15 07:07 System.map-3.13.0-63-gener
-rw-r--r-- 1 root root 3663717 Sep 22 16:35 System.map-4.2.0-hell-kern
-rw------- 1 root root 5776416 May 3 2014 vmlinuz-3.13.0-24-generic
-rw------- 1 root root 5797728 Aug 14 2014 vmlinuz-3.13.0-34-generic
-rw------- 1 root root 5821152 Aug 15 07:07 vmlinuz-3.13.0-63-generic
-rw-r--r-- 1 root root 6118160 Sep 22 16:35 vmlinuz-4.2.0-hell-kernel
REPLY LINK
If you want to only compile the loaded modules with the current kernel
16 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
use ‘make localmodconfig’. This will make the compile time shorter and include all
of the currently loaded modules of you current kernel.
REPLY LINK
Great information.
Thanks!
REPLY LINK
REPLY LINK
17 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
REPLY LINK
great tute, though with the unpacking “Installing custom kernel” .deb
part, had to do image first then headers.. naturally.. thanx…
REPLY LINK
it’s showing:
“scripts/sign-file.c:23:30: fatal error: openssl/opensslv.h: No such file or directory
compilation terminated.
scripts/Makefile.host:91: recipe for target ‘scripts/sign-file’ failed
make[2]: *** [scripts/sign-file] Error 1
Makefile:545: recipe for target ‘scripts’ failed
make[1]: *** [scripts] Error 2
make[1]: Leaving directory ‘/home/x/linux-4.4’
debian/ruleset/targets/common.mk:295: recipe for target ‘debian/stamp/build
/kernel’ failed
make: *** [debian/stamp/build/kernel] Error 2”
18 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
REPLY LINK
REPLY LINK
REPLY LINK
After I type :
19 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
ls ../*.deb
REPLY LINK
cd to .. and try:
OR
REPLY LINK
20 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
(nothing works).
REPLY LINK
REPLY LINK
REPLY LINK
Your article needs updating. All of the required packages do not exist in
the cache. If someone comes to this site hoping for a guide to properly compiling
and installing a new Linux kernel – not having the packages prior to coming here
– they will spend quite some time trying to track down a fistful of packages that no
longer exist, have been updated and/or replaced.
REPLY LINK
Can you provide your Linux distro name and other info like what
packages are missing? I tested this on Debian 8 and Ubuntu Linux 14.04.3
LTS only. Everything worked perfectly.
21 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
Debian 8.1
REPLY LINK
REPLY LINK
linux-kernel-utilities
REPLY LINK
22 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
Thanks for the thought but your install script causes dkms errors
due to elaborate versioning. I get some extremely long build and version
numbers which makes it useless. You need to allow for the user to enter
EXPLICIT kernel versions and not do some crazy automate based on
date/time etc……
REPLY LINK
I would suggest a prompt that shows the user WHAT you will be
calling the kernel version and deb files, and allow the user to modify it at this
point.
REPLY LINK
tnx a lot:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
REPLY LINK
After I select Linux kernel config options and drivers to build and I click
on save and then exit, it says to “make” in the terminal but your tutorial says that I
should “make-kpkg clean” so which one should I do first after I save and exit the
menuconfig?
REPLY LINK
23 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
should I do next?
REPLY LINK
REPLY LINK
REPLY LINK
24 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
Can anyone help me? The last lines of the following are the error information.
objcopy –add-gnu-debuglink=/home/daweili/linux-4.4.4/debian/linux-image-
4.4.4/usr/lib/debug/lib/modules/4.4.4/kernel/virt/lib/irqbypass.ko /home/daweili
/linux-4.4.4/debian/linux-image-4.4.4/lib/modules/4.4.4/kernel/virt/lib/irqbypass.ko
rm -rf /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/usr/lib/debug
test ! -f tools/lguest/lguest || \
install -p -o root -g root -m 644 tools/lguest/lguest /home/daweili/linux-
4.4.4/debian/linux-image-4.4.4/lib/modules/4.4.4/lguest
test ! -f /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib/modules/4.4.4
/lguest || \
chmod 755 /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib/modules/4.4.4
/lguest
test ! -e /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib/modules/4.4.4
/source || \
mv /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib/modules/4.4.4/source
./debian/source-link
25 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
test ! -e /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib/modules/4.4.4/build
|| \
mv /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib/modules/4.4.4/build
./debian/build-link
test ! -e ./debian/source-link || \
mv ./debian/source-link /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib
/modules/4.4.4/source
test ! -e ./debian/build-link || \
mv ./debian/build-link /home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib
/modules/4.4.4/build
/sbin/depmod -q -FSystem.map -b /home/daweili/linux-4.4.4/debian/linux-
image-4.4.4 4.4.4;
restore_upstream_debianization
test ! -f scripts/package/builddeb.kpkg-dist || mv -f scripts/package
/builddeb.kpkg-dist scripts/package/builddeb
test ! -f scripts/package/Makefile.kpkg-dist || mv -f scripts/package
/Makefile.kpkg-dist scripts/package/Makefile
/usr/bin/make INSTALL_MOD_PATH=/home/daweili/linux-4.4.4/debian/linux-
image-4.4.4 \
INSTALL_FW_PATH=/home/daweili/linux-4.4.4/debian/linux-image-4.4.4/lib
/firmware/4.4.4 \
INSTALL_PATH=/home/daweili/linux-4.4.4/debian/linux-image-4.4.4//boot install
make[2]: Entering directory `/home/daweili/linux-4.4.4′
scripts/kconfig/conf –silentoldconfig Kconfig
make[2]: Leaving directory `/home/daweili/linux-4.4.4′
make[2]: Entering directory `/home/daweili/linux-4.4.4′
sh ./arch/x86/boot/install.sh 4.4.4 arch/x86/boot/bzImage \
System.map “/home/daweili/linux-4.4.4/debian/linux-image-4.4.4//boot”
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.4 /home/daweili
/linux-4.4.4/debian/linux-image-4.4.4//boot/vmlinuz-4.4.4
/etc/kernel/postinst.d/apt-auto-removal: 84: /etc/kernel/postinst.d/apt-auto-
removal: cannot create /etc/apt/apt.conf.d//01autoremove-kernels.dpkg-new:
Permission denied
run-parts: /etc/kernel/postinst.d/apt-auto-removal exited with return code 2
make[3]: *** [install] Error 1
26 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
REPLY LINK
Yes.
REPLY LINK
Hi,
This worked for me. A further question: the needed hardware config selections /
modules were not compiled into the kernel, so I did this a second time with a
different revision, enabling the relevant options in menuconfig, but grub (nor
uname, proc/release) does not show different revisions, only the kernel version,
so not sure which I am using… is there a way to tell? The hardware (touchpad)
does not work- it is not identified by the system either. Is it possible to compile it
separately as a module?
Anyway, the guide worked as described, even if it did not accomplish what I
27 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
Hello
fede@fede-Lenovo-YOGA-900-13ISK:~/linux-4.5$ ls ../*.deb
ls: cannot access ../*.deb: No such file or directory
fede@fede-Lenovo-YOGA-900-13ISK:~/linux-4.5$
REPLY LINK
28 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
I use Asus ux305 on the which I installed Ubuntu 15.10 with default
kernetl 4.2. This kernel not supports Intel M Core the same did not work my
TouchPad. Thanks to this guide I installed kernel 4.5 and all works fine. Thanks
alot.
REPLY LINK
REPLY LINK
29 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
which I need to select in Fig.05, which is rightest for install kernel. you
not clear, I don’t understand anything.
REPLY LINK
REPLY LINK
30 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
particular
.config file taken from http://kernel.ubuntu.com/~kernel-ppa/mainline/
Steps on Development machine
Copy the config file inside the kernel source directory as .config
yes ” | make oldconfig
make -j4 deb-pkg LOCALVERSION=-my_kernel
Steps on target machine
sudo dpkg -i linux-headers-x.xx…_amd64.deb
sudo dpkg -i linux-image-x.xx…_amd64.deb
After this even if I have to do a minor modification in kernel source (like add some
new printk statements) then also I had to repeat the above steps which takes lot
of time (as everything is done from scratch, nothing is reused from previous
compilation)
How can I expedite the subsequent compilation of kernel ?
On debian package installation, I see the following files inside the /boot directory
on the target machine
/boot/vmlinuz*KERNEL-VERSION*
/boot/initrd*KERNEL-VERSION*
/boot/System-map*KERNEL-VERSION*
/boot/config-*KERNEL-VERSION*
For modules, I can use a shortcut, like for example for i915 module, I follow these
2 steps.
make DRM_MODULES=”i915″ -j4
cp drivers/gpu/drm/i915/i915.ko to /lib/modules/VERSION/kernel/drivers/gpu/drm
/i915/ on the target.
REPLY LINK
31 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
REPLY LINK
Leave a Comment
Name
Comment
Submit
You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a
href="" title="">
32 de 33 23/11/2016 14:20
How to Compile and Install Linux Kernel v4.5 S... https://www.cyberciti.biz/faq/debian-ubuntu-buil...
©2000-2016 nixCraft. All rights reserved. Privacy - Terms of Service - Questions or Comments
33 de 33 23/11/2016 14:20