How to build and install a vanilla kernel on a Linux computer.
- How to build and install a vanilla kernel on a Linux computer.
- Getting the source code.
- Preparing to build the source.
- Compiling the kernel
- Installing the kernel.
This posting will explain how to build a vanilla kernel from kernel.org and properly install it to your Linux machine.
Getting the source code.
Firstly; download a vanilla tarball from http://www.kernel.org. I chose the 3.12-rc6 kernel tarball.
Type this command to unpack the tar.xz file:
tar xpvf linux-3.12-rc6.tar.xz |
Then enter the source directory.
cd linux-3.12-rc6/ |
Preparing to build the source.
Ensure that the source tree is clean:
make mrproper |
Then copy the default configuration from the existing kernel:
cat /boot/config-`uname -r` > .config |
After that, you may then run this command to begin configuring the kernel.
make menuconfig |
If you get an error you would need to install the ncurses-devel package.
The above screenshot shows the menuconfig window I am using to set up the Linux kernel on Debian Wheezy 7.1.
Once you are finished configuring the kernel; exit menuconfig and save your changes.
Compiling the kernel
Now you may begin compiling the kernel:
make -j4 && make modules |
This will use all 4 CPU cores to build the Linux kernel faster. And it will then build all required kernel modules as well. This might take quite a while, but wait a while and you will have a brand new kernel image ready to be installed.
Installing the kernel.
Once the compilation has completed install the kernel modules thusly:
sudo make modules_install |
That will install all of the kernel modules under a directory in /lib/modules/3.12-rc6 and perform other tasks to ensure that the modules are properly registered.
After that install the kernel image and System.map file to the /boot directory with this command:
make install |
. Not all Linux distributions implement this properly, but this is how I install a new kernel bzImage image on Fedora 19 and Debian 7.1. Any Linux distro that does not allow you to install the kernel in the traditional fashion is not worth bothering with in my opinion.
homer@neo:/media/86c5852a-4c79-4224-b766-dd0d54eaa483/linux-work/linux-3.12-rc6$ sudo make install sh /media/86c5852a-4c79-4224-b766-dd0d54eaa483/linux-work/linux-3.12-rc6/arch/x86/boot/install.sh 3.12.0-rc6 arch/x86/boot/bzImage \ System.map "/boot" run-parts: executing /etc/kernel/postinst.d/dkms 3.12.0-rc6 /boot/vmlinuz-3.12.0-rc6 Error! Bad return status for module build on kernel: 3.12.0-rc6 (x86_64) Consult /var/lib/dkms/virtualbox/4.1.18/build/make.log for more information. run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.12.0-rc6 /boot/vmlinuz-3.12.0-rc6 update-initramfs: Generating /boot/initrd.img-3.12.0-rc6 run-parts: executing /etc/kernel/postinst.d/pm-utils 3.12.0-rc6 /boot/vmlinuz-3.12.0-rc6 run-parts: executing /etc/kernel/postinst.d/zz-extlinux 3.12.0-rc6 /boot/vmlinuz-3.12.0-rc6 P: Checking for EXTLINUX directory... found. P: Writing config for /boot/vmlinuz-3.9-0.bpo.1-amd64... P: Writing config for /boot/vmlinuz-3.2.0-4-amd64... P: Writing config for /boot/vmlinuz-3.12.0-rc6... P: Updating /boot/extlinux/linux.cfg... P: Writing config for Windows 8 (loader) on /dev/sda2... P: Installing debian theme... done. run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.12.0-rc6 /boot/vmlinuz-3.12.0-rc6 Generating grub.cfg ... Found background image: /usr/share/images/desktop-base/desktop-grub.png Found linux image: /boot/vmlinuz-3.12.0-rc6 Found initrd image: /boot/initrd.img-3.12.0-rc6 Found linux image: /boot/vmlinuz-3.9-0.bpo.1-amd64 Found linux image: /boot/vmlinuz-3.2.0-4-amd64 Found initrd image: /boot/initrd.img-3.2.0-4-amd64 Found memtest86+ image: /boot/memtest86+.bin Found memtest86+ multiboot image: /boot/memtest86+_multiboot.bin Found Windows 8 (loader) on /dev/sda2 done |
After this; re-boot your machine and boot into your new kernel!