Success in building a Kernel Snap in snapcraft 2.8.4

Wow! Talk about a crazy week. And it couldn’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…)

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’ing them and making sure they get put into the final snap.

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 sudo apt update then sudo apt install snapcraft -y. Once that is complete, then you can run snapcraft init 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:

name: custom-kernel
 version: 4.4.6
 summary:  custom kernel
 description:  custom kernel for Snappy
 type: kernel
 parts:
    kernel:
      plugin: kernel
      source: .
      kconfigfile: 4.4-config
      kconfigs:
        - CONFIG_SQUASHFS=m
      kernel-initrd-modules:
        - squashfs
        - ahci

I then ran sudo apt source linux-image-`uname -r` 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 snapcraft build and 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 make all and it built my *.ko files I needed.

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 mkdir -p extra) and then ran depmod -b ~wililupy/linux-4.4.0/parts/install 4.4.6 to update the modules symbols for the compiled kernel. I then ran  snapcraft snap. It then built my kernel.snap file. I then ran ubuntu-device-flash, which you will need to download from here. Run 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.imgand you will have your custom image that you are now ready to install on your device.

Since I work heavily in the Whitebox switching area, I use ONIE to 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.

Happy Hacking!!

[ayssocial_buttons id=”2″]

Comments

7 responses to “Success in building a Kernel Snap in snapcraft 2.8.4”

  1. ds emulators for android Avatar

    whoah this blog is great i love reading your posts. Keep up the good work!
    You know, many persons are searching round for this information, you can help
    them greatly.

  2. jump roblox} Avatar

    I like, will read more. Cheers!

  3. easyworship 6.7.5 crack Avatar

    Intresting, will come back here more often.

  4. poker indonesia online Avatar

    You made some good points there. I checked on the web for more
    information about the issue and found most individuals will
    go along with your views on this web site.

  5. bit heroes hack Avatar

    Great, this is what I was looking for in google

  6. https://2captcha.com Avatar

    I got this website fгom my friend ԝho informed
    mе abbout this web site аnd at thе momernt
    tһіs time I am browsing tһis site and reading very informative content hеre.

  7. تور مشهد تعطیلات عید نوروز 97 Avatar

    I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more enjoyable for
    me to come here and visit more often. Did you hire out a developer to create your theme?
    Superb work!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.