{"id":152,"date":"2017-02-12T06:42:11","date_gmt":"2017-02-12T06:42:11","guid":{"rendered":"http:\/\/blog.warbel.net\/?p=152"},"modified":"2017-02-12T06:42:11","modified_gmt":"2017-02-12T06:42:11","slug":"how-to-compile-the-linux-kernel-from-source-on-ubuntu-16-04-lts","status":"publish","type":"post","link":"https:\/\/blog.warbel.net\/index.php\/2017\/02\/12\/how-to-compile-the-linux-kernel-from-source-on-ubuntu-16-04-lts\/","title":{"rendered":"How to Compile the Linux Kernel from Source on Ubuntu 16.04 LTS"},"content":{"rendered":"<h1>Background\/Problem:<\/h1>\n<p>My KVM host, after a recent upgrade (see posts below) cannot start with the kernel option iommu=on enabled. Technically it can, however the system will not start due to a driver\/bug issue with an additional SATA card I have installed:<br \/>\n:$ lspci<br \/>\n&#8230;<strong><br \/>\n02:00.0 SATA controller: Marvell Technology Group Ltd. 88SE9230 PCIe SATA 6Gb\/s Controller (rev 11)<\/strong><\/p>\n<p>Disks simply do not register when using iommu. The Bugzilla report can be found <a href=\"https:\/\/bugzilla.kernel.org\/show_bug.cgi?id=42679\">here<\/a>\u00a0and more information can be had <a href=\"http:\/\/lime-technology.com\/forum\/index.php?topic=40683\">here.<\/a>\u00a0The references are old, so my hope is that it has been patched in the latest kernel images.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-153\" src=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/linux-300x224.jpg\" alt=\"\" width=\"300\" height=\"224\" srcset=\"https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/linux-300x224.jpg 300w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/linux-402x300.jpg 402w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/linux.jpg 500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Furthermore, I need the latest kernel to use the Quad tuner PCI-E card I have:<br \/>\n:$ lspci<br \/>\n&#8230;<br \/>\n<strong>05:00.0 Multimedia video controller: Conexant Systems, Inc. CX23887\/8 PCIe Broadcast Audio and Video Decoder with 3D Comb (rev 04)<\/strong><\/p>\n<p>The quad tuner needs kernel 4.8 to run. More information <a href=\"https:\/\/www.linuxtv.org\/wiki\/index.php\/Hauppauge_WinTV-quadHD_(DVB-T\/T2\/C)\">here<\/a>.\u00a0So fundamentally, I need to compile the latest stable kernel image to get the full use of my system and then pass the PCIE tuner card through to my Media VM.<\/p>\n<h1>The Process:<\/h1>\n<p>I recommend doing this I have done, inside a reasonably powered Virtual machine. I&#8217;ve gone back through things and corrected my instructions when I&#8217;ve run into problems. This process will generate a Debian package that you can install on any Debian based OS (such as Ubuntu).<\/p>\n<h2>Problems:<\/h2>\n<ol>\n<li>Not giving enough RAM, CPU and disk space to the VM to compile (at all) or in a timely manner.\n<ol>\n<li>I&#8217;ve given my VM 4 cores, 4GB RAM and an &#8216;external&#8217; hard drive of 30GB to use to compile the kernel.<\/li>\n<\/ol>\n<\/li>\n<li><a href=\"https:\/\/itbusters.wordpress.com\/2013\/02\/07\/how-to-build-debian-kernel-using-multiple-cores\/\">Utilize all the cores<\/a>. add the line:\u00a0CONCURRENCY_LEVEL= 4 to \/etc\/kernel-pkg.conf to use all 4 cores when compiling (once the package is installed, see below)<\/li>\n<li>Not having some essential packages installed that caused the process to stop. such as libssl-dev.<\/li>\n<\/ol>\n<div id=\"attachment_154\" style=\"width: 970px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-154\" class=\"size-full wp-image-154\" src=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/allthecores.jpg\" alt=\"\" width=\"960\" height=\"194\" srcset=\"https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/allthecores.jpg 960w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/allthecores-300x61.jpg 300w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/allthecores-768x155.jpg 768w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/allthecores-500x101.jpg 500w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><p id=\"caption-attachment-154\" class=\"wp-caption-text\">Using all the cores makes it go much faster!<\/p><\/div>\n<h2>Steps:<\/h2>\n<p>At the command prompt, install all the packages you need to compile the kernel:<br \/>\n:$ <strong>sudo apt-get install fakeroot kernel-package gcc build-essential libncurses5-dev qt5-default\u00a0libssl-dev<\/strong><\/p>\n<p>Download, to a disk that has ~20GB free, the latest stable kernel version. At the time of writing this was 4.9.9. Extract it and cd into the directory<br \/>\n:$ <strong>wget https:\/\/cdn.kernel.org\/pub\/linux\/kernel\/v4.x\/linux-4.9.9.tar.xz<br \/>\n<\/strong>:$ <strong>tar -xf linux-4.9.9.tar.xz<\/strong><br \/>\n:$<strong> cd linux.-4.9.9<\/strong><\/p>\n<p>Assuming you&#8217;re running this in a desktop Linux environment, run make xconfig, alternatively, if you&#8217;re using a terminal server, make menuconfig will do.<\/p>\n<div id=\"attachment_156\" style=\"width: 385px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-156\" class=\"wp-image-156 size-full\" src=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/xconfig.jpg\" width=\"375\" height=\"492\" srcset=\"https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/xconfig.jpg 375w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/xconfig-229x300.jpg 229w\" sizes=\"auto, (max-width: 375px) 100vw, 375px\" \/><p id=\"caption-attachment-156\" class=\"wp-caption-text\">The default settings should do in most instances.<\/p><\/div>\n<p>Save and close the configuration. Make the build environment clean, then begin the compile process:<br \/>\n:$ <strong>make-kpkg clean<\/strong><br \/>\n:$ <strong>fakeroot make-kpkg \u2013initrd \u2013revision=4.9.9.linux kernel_image kernel_headers<\/strong><\/p>\n<div id=\"attachment_158\" style=\"width: 581px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-158\" class=\"wp-image-158 size-full\" src=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/compiling.jpg\" width=\"571\" height=\"188\" srcset=\"https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/compiling.jpg 571w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/compiling-300x99.jpg 300w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/compiling-500x165.jpg 500w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><p id=\"caption-attachment-158\" class=\"wp-caption-text\">You can save time by compiling a kernel with only the hardware that you have installed. Do this by deselecting them in the xconfig\/menuconfig. The downside is that if you add new hardware, you&#8217;ll need to recompile the kernel.<\/p><\/div>\n<p>For an explanation on the above fakeroot command, please see this <a href=\"https:\/\/www.debian.org\/releases\/jessie\/i386\/ch08s06.html.en\">Debian manual page<\/a>. You should now have a custom kernel image compiling.<\/p>\n<p>Once it&#8217;s completed, cd to the upper directory, and install the kernel:<br \/>\n:$ <strong>cd ..<\/strong><br \/>\n:$ <strong>sudo dpkg -i linux-image-4.9.9_4.9.9.linux_amd64.deb linux-headers-4.9.9.9_4.9.9.9.linux_amd64.deb<\/strong><br \/>\n:$ <strong>sudo shutdown -hr now<\/strong><\/p>\n<p>After restarting the VM, you can check the currently running version of the kernel by typing at the command prompt:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-161\" src=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/uname-r.jpg\" alt=\"\" width=\"354\" height=\"117\" srcset=\"https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/uname-r.jpg 354w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/02\/uname-r-300x99.jpg 300w\" sizes=\"auto, (max-width: 354px) 100vw, 354px\" \/><\/p>\n<h2>Additional extra step:<\/h2>\n<p>Prove to yourself that you&#8217;ve created a usable package by spinning up a shiny new VM, sftp the debian package to it, then install and reboot.<\/p>\n<h2>Further reading:<\/h2>\n<p><a href=\"https:\/\/www.cyberciti.biz\/faq\/debian-ubuntu-building-installing-a-custom-linux-kernel\/\">https:\/\/www.cyberciti.biz\/faq\/debian-ubuntu-building-installing-a-custom-linux-kernel\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background\/Problem: My KVM host, after a recent upgrade (see posts below) cannot start with the kernel option iommu=on enabled. Technically it can, however the system will not start due to a driver\/bug issue with an additional SATA card I have &hellip; <a href=\"https:\/\/blog.warbel.net\/index.php\/2017\/02\/12\/how-to-compile-the-linux-kernel-from-source-on-ubuntu-16-04-lts\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":6,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}