Create Kernel Snap based on deb packages


#1

I am trying to make a kernel snap to use the generic on an amd64 architecture. There are existing compiled generic files for kernel v4.15. Is it possible to repackage these debian files into a kernel snap? If yes, what would that look like? The goal is to not have to compile the entire kernel if a precompiled version is already available.

If not, where would be the best example to create a generic Linux kernel v4.15 amd64 snap with the source being hosted on a git server and not locally?

NOTE: I was using the pc-kernel snap (based on v4.4.0), however I encountered a kernel bug, which has been resolved in v4.15.


#2

It is possible to build a kernel snap from the deb packages, however, I hightly advise against it.
We have snapcraft.yaml in the root tree of our kernels past 4.4.0. You can do the following for the 4.15 kernel:

git clone git://kernel.ubuntu.com/ubuntu/ubuntu-bionic.git
cd ubuntu-bionic
snapcraft snap

This will build the pc-kernel snap for the current bionic (4.15) kernel. If you need specific versions, you can branch and checkout the tree you need.

You can see the snapcraft.yaml here [1].

Thanks!

[1] http://kernel.ubuntu.com/git/ubuntu/ubuntu-bionic.git/tree/snapcraft.yaml


#3

Great! I will check it out! Is there a github mirror I can use? I can only clone over http/https on my company network unfortunately.

Can this kernel snap be created in ubuntu 16.04, and what are the package dependencies?


#4

Sure.

git clone https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic

  • Luke

#5

Hi @wililupy, I can successfully clone the repo thanks! I am however running into a build issue on my Ubuntu 16.04 Server.

I clone the repository then checkout the Ubuntu-4.15.0-9.10 tag with a clean git repository.

I execute sudo snapcraft snap --target-arch amd64. The build fails and shows the following error:
make: *** No rule to make target 'firmware_install'. Stop.

If I am not mistaken, checking out on this tag, and creating the build should just work?


#6

It should just work. Let me try to run it on my test system and I’ll let you know what I find.
One thing I noticed is that you are building using sudo which is not required to run snapcraft.
I also have never used the --target-arch amd64 flag when building

I’ll let you know what I discover.

Thanks,
Luke


#7

Interesting. I tried to build on my xenial box and it failed, but at a different point. I got the following error:

Failed to run 'make -j8 CONFIG_PREFIX=/root/ubuntu-bionic/parts/kernel/install modules_install INSTALL_MOD_PATH=/root/ubuntu-bionic/parts/kernel/install firmware_install INSTALL_FW_PATH=/root/ubuntu-bionic/parts/kernel/install/lib/firmware' for 'kernel': Exited with code 2.
Verify that the part is using the correct parameters and try again.

I’m going to try to build on a clean system (LXC) and see what happens.

  • Luke

#8

This looks like the same error message, I am receiving the same error message as well. You can see that it attempted to run firmware_install as well. Did you happen to pipe/redirect this to a build log? If so, did you redirect stderr to stdout?

Perhaps the tag I am on Ubuntu-4.15.0-9.10 may have issues? The only location this is being called is from the file bionic/debian/scripts/misc/find-obsolete-firmware.


#9

I was able to run snapcraft in debug mode trying to build the kernel and this is the output from the last few lines:

  mkdir -p /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/ubuntu/xr-usb-serial ; cp ubuntu/xr-usb-serial/xr_usb_serial_common.ko /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/ubuntu/xr-usb-serial ; true /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/ubuntu/xr-usb-serial/xr_usb_serial_common.ko ; if (echo "/home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/ubuntu/xr-usb-serial/xr_usb_serial_common.ko" | egrep -q "\/drivers\/staging\/") && [ -f ./drivers/staging/signature-inclusion ] && (! egrep -x "xr_usb_serial_common.ko" ./drivers/staging/signature-inclusion) ; then echo Not signing "/home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/ubuntu/xr-usb-serial/xr_usb_serial_common.ko"; else scripts/sign-file "sha512" "certs/signing_key.pem" certs/signing_key.x509 /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/ubuntu/xr-usb-serial/xr_usb_serial_common.ko  && true /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/ubuntu/xr-usb-serial/xr_usb_serial_common.ko; fi
  mkdir -p /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/virt/lib ; cp virt/lib/irqbypass.ko /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/virt/lib ; true /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/virt/lib/irqbypass.ko ; if (echo "/home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/virt/lib/irqbypass.ko" | egrep -q "\/drivers\/staging\/") && [ -f ./drivers/staging/signature-inclusion ] && (! egrep -x "irqbypass.ko" ./drivers/staging/signature-inclusion) ; then echo Not signing "/home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/virt/lib/irqbypass.ko"; else scripts/sign-file "sha512" "certs/signing_key.pem" certs/signing_key.x509 /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/virt/lib/irqbypass.ko  && true /home/wililupy/bionic/parts/kernel/install/lib/modules/4.15.2+/kernel/virt/lib/irqbypass.ko; fi

Traceback (most recent call last):
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/common.py", line 67, in _run
    return runner(['/bin/sh'], stdin=run_file, **kwargs)
  File "/snap/snapcraft/1594/usr/lib/python3.5/subprocess.py", line 581, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/bin/sh']' returned non-zero exit status 2

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/_baseplugin.py", line 204, in run
    return common.run(cmd, cwd=cwd, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/common.py", line 75, in run
    _run(cmd, subprocess.check_call, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/common.py", line 71, in _run
    call_error=call_error) from call_error
snapcraft.internal.errors.SnapcraftCommandError: Failed to run 'make -j4 V=1 CONFIG_PREFIX=/home/wililupy/bionic/parts/kernel/install modules_install INSTALL_MOD_PATH=/home/wililupy/bionic/parts/kernel/install firmware_install INSTALL_FW_PATH=/home/wililupy/bionic/parts/kernel/install/lib/firmware': Exited with code 2.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/snap/snapcraft/1594/bin/snapcraft", line 11, in 
    load_entry_point('snapcraft==2.42.1', 'console_scripts', 'snapcraft')()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 1043, in invoke
    return Command.invoke(self, ctx)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/cli/_runner.py", line 79, in run
    ctx.forward(lifecyclecli.commands['snap'])
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 553, in forward
    return self.invoke(cmd, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py", line 135, in snap
    project_options, directory=directory, output=output)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_packer.py", line 46, in snap
    execute('prime', project_options)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 79, in execute
    _Executor(config, project_options).run(step, part_names)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 191, in run
    self._run_step(step, part, part_names)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 236, in _run_step
    getattr(part, step)()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 438, in build
    self._runner.build()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 97, in build
    self._builddir)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 160, in _run_scriptlet
    scriptlet_name, function_call.strip())))
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 208, in _handle_builtin_function
    function(**function_args)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/plugins/kbuild.py", line 258, in build
    self.do_install()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/plugins/kernel.py", line 462, in do_install
    super().do_install()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/plugins/kbuild.py", line 250, in do_install
    self.make_install_targets)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/_baseplugin.py", line 208, in run
    exit_code=process_error.returncode) from process_error
snapcraft.internal.errors.SnapcraftPluginCommandError: Failed to run 'make -j4 V=1 CONFIG_PREFIX=/home/wililupy/bionic/parts/kernel/install modules_install INSTALL_MOD_PATH=/home/wililupy/bionic/parts/kernel/install firmware_install INSTALL_FW_PATH=/home/wililupy/bionic/parts/kernel/install/lib/firmware' for 'kernel': Exited with code 2.
Verify that the part is using the correct parameters and try again.

I have tried building a kernel snap in LXC, in a clean KVM, on my local machine, and even with snapcraft cleanbuild and they all fail at this same spot. I have also tried using snapcraft from all the different channels (Edge, Beta, Stable and Candidate) to no avail.
If I build the kernel straight up, no snapcraft, the kernel builds, so it makes me think that we may have a bug in the kernel plugin unless anyone else reading this thread has had success, then I am all ears as to what has changed and what I am doing wrong.
I can include the entire Debug dump from trying to build the kernel snap. Uncompressed it is 44M and 58,000+ lines in size, but as tgz it is 946k.

-Luke


#10

Hi @wililupy, Is it possible to do an override build in the snapcraft.yaml definition, instead of using the kernel plugin?


#11

I have never tried it.


#12

Ok, so I was able to successfully build a kernel snap from the stock snapcraft.yaml in the xenial git repo, so it must be someway that the bionic kernel is being built by the plugin. I will ask the maintainers if they have any insight on this.

  • Luke

#13

Hi Wililupy, Great sounds good! I have also created a question on the launchpad: https://answers.launchpad.net/ubuntu/+source/linux-signed/+question/670902.

It would seem like getting the kernel snap to build would be a crucial part of advancing to Ubuntu Core 18, if I am not mistaken.

Thanks for the help! Please keep me up to date.


#14

Apply these two patches:

https://lists.ubuntu.com/archives/kernel-team/2018-July/093905.html

and

https://lists.ubuntu.com/archives/kernel-team/2018-July/093908.html

to fix the build.

I’ve submitted both for inclusion in the next cycle.


#15

Great thanks @ppisati. I will try this out. Also, what tag were you compiling against and what are the required apt packages should be installed to compile the kernel?


#16

Hi all, thank you all very much on resolving this issue for me! I can successfully create the kernel snap with the patches suggested. I did encounter another problem but is outside the scope of this issue.


#17

Hey ppisati,

Where do you apply these patches and what is the command to do so? Haven’t done much with patching.

Thanks


#18

to the snapcraft,yaml in the kernel tree that @wililupy pointed to in post #2