{"id":6,"date":"2016-04-29T01:31:06","date_gmt":"2016-04-29T01:31:06","guid":{"rendered":"http:\/\/10.1.10.6\/?p=6"},"modified":"2016-05-04T17:52:59","modified_gmt":"2016-05-04T17:52:59","slug":"success-in-building-a-kernel-snap-in-snapcraft-2-8-4","status":"publish","type":"post","link":"https:\/\/www.lucaswilliams.net\/index.php\/2016\/04\/29\/success-in-building-a-kernel-snap-in-snapcraft-2-8-4\/","title":{"rendered":"Success in building a Kernel Snap in snapcraft 2.8.4"},"content":{"rendered":"<p>Wow! Talk about a crazy week. And it couldn&#8217;t have been better. After many days trying to get a working kernel in Snappy Ubuntu Core with customized Kernel Modules built against the kernel into a single snap bundle was easy is like saying giving a cat a bath is easy (I did that today as well, waiting for the kernel to finish building&#8230;)<\/p>\n<p>Anyways, this blog post is about how I managed to get it working using snapcraft 2.8.4, running on Ubuntu 16.04, with kernel 4.4.0-21-generic from the Ubuntu kernel repository, and building the modules and then depmod&#8217;ing them and making sure they get put into the final snap.<\/p>\n<p>First thing I did, download snapcraft. Easy to do now that it is in the main repository for Ubuntu 16.04. All you do is <code>sudo apt update<\/code> then <code>sudo apt install snapcraft -y<\/code>. Once that is complete, then you can run <code>snapcraft init<\/code> and you have a blank snapcraft.yaml file waiting for you to tell it what you are going to build. Below is an example that I used for my kernel snap:<\/p>\n<pre><code>name: custom-kernel<\/code><code>\r\n version: 4.4.6\r\n summary: \u00a0custom kernel\r\n description: \u00a0custom kernel for Snappy\r\n type: kernel\r\n parts:\r\n    kernel:\r\n      plugin: kernel\r\n      source: .\r\n      kconfigfile: 4.4-config\r\n      kconfigs:\r\n        - CONFIG_SQUASHFS=m\r\n      kernel-initrd-modules:\r\n        - squashfs\r\n        - ahci<\/code><\/pre>\n<p>I then ran <code>sudo apt source linux-image-`uname -r`<\/code> to get the latest kernel source that is running on Xenial. After that, I copied my snapcraft.yaml file to the location I downloaded the kernel source files to and copied the default kernel config file from \/boot\/config-4.4.0-21-generic to the kernel source directory and renamed it to 4.4-config. I then ran <code>snapcraft build<\/code>\u00a0and after two hours, and giving my cat a bath, it was done. I was then able to build my custom kernel modules against these headers so that I knew they would have the same symbols for it. All I did was modify my makefile so that instead of it looking in \/lib\/modules\/`uname -r`\/build for my modules, I pointed it to \/home\/wililupy\/linux-4.4.0\/parts\/kernel\/build and modified the kernel version to 4.4.6. I then ran <code>make all<\/code> and it built my *.ko files I needed.<\/p>\n<p>I then copied the *ko files to \/home\/wililupy\/linux-4.4.0\/parts\/install\/lib\/4.4.6\/extra (I had to create the extra directory <code>mkdir -p extra<\/code>) and then ran <code>depmod -b ~wililupy\/linux-4.4.0\/parts\/install 4.4.6<\/code>\u00a0to update the modules symbols for the compiled kernel. I then ran\u00a0\u00a0<code>snapcraft snap<\/code>. It then built my kernel.snap file. I then ran ubuntu-device-flash, which you will need to download from <a href=\"http:\/\/people.canonical.com\/~mvo\/all-snaps\/ubuntu-device-flash\">here<\/a>. Run <code>sudo .\/ubuntu-device-flash core 16 --channel=edge --kernel=custom-kernel_4.4.6_amd64.snap --gadget=canonical-pc --os=ubuntu-core -o custom-snappy.img<\/code>and you will have your custom image that you are now ready to install on your device.<\/p>\n<p>Since I work heavily in the Whitebox switching area, I use <a href=\"http:\/\/onie.org\">ONIE<\/a>\u00a0to install my software on whitebox switches. Read up on how this works from their Github or if you want, ask me in the comments below.<\/p>\n<p>Happy Hacking!!<\/p>\n<p>[ayssocial_buttons id=&#8221;2&#8243;]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wow! Talk about a crazy week. And it couldn&rsquo;t have been better. After many days trying to get a working kernel in Snappy Ubuntu Core with customized Kernel Modules built against the kernel into a single snap bundle was easy is like saying giving a cat a bath is easy (I did that today as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":9,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":20,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/posts\/6\/revisions\/20"}],"wp:attachment":[{"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}