Custom Kernel: Difference between revisions

From Alpine Linux
m (Categorized: Kernel)
(Add content)
Line 1: Line 1:
{{Draft}}
{{Draft}}


This process of building a custom configured kernel is assuming you are running on Alpine Linux utilizing abuild & aports.
This process of building a '''custom configured kernel''' assumes you are running on Alpine Linux utilizing abuild & aports.


== Alpine Build System ==
== But why? ==
* [[Creating an Alpine package]]
** [[Creating_an_Alpine_package#Setup_your_system_and_account|Setup your system and account for building packages]]


== Aports ==
You want to build a custom kernel to enable experimental hardware or features or outdated hardware, to reduce bloat further, to tune the kernel to the hardware.


== Configuring Kernel ==
== Setting up the Alpine Build System ==
 
First, you need to follow the steps in [[Creating_an_Alpine_package#Setup_your_system_and_account|Setup your system and account for building packages]].  You also need to configure your /etc/apk/repositories so that they search locally for your apks.  See [[Creating_an_Alpine_package#Testing_the_package_locally|Testing the package locally]] for details.
 
== Working with aports ==
 
There are several ways to maintain a kernel.  The first option is to create a new kernel package.  The other option is to just use the existing vanilla kernel just tweaking the configure-vanilla.ARCH file.
 
=== Switching to the proper release version ===
 
You need to switch to the proper branch that matches the release so that the kernel compiles against the dependencies properly.
 
{| cellpadding="5" border="1" class="wikitable"
|-
! Friendly name
! Remote branch
|-
| Edge
| master
|-
| 3.7
| 3.7-stable
|-
|}
 
The following is required to get access to the APKBUILD released for that version of Alpine and which you will create a commit for.
 
If you are on 3.7 do:
 
  git checkout -b 3.7-stable origin/3.7-stable
 
If you are on Edge do:
 
  git checkout master
 
=== Creating a new kernel package ===
 
Use this option only if you want to want to be a kernel package maintainer or have custom patches.
 
What you need to do is copy ''main/linux-vanilla'' folder to ''testing/linux-NAME'', where NAME could be anything but usually initials or a project name to a special kernel patch or patchset.  Just use your last name if you don't know what to put.  Rename all files from vanilla to NAME.  Rename everything in APKBUILD with vanilla to NAME.
 
Next step is to edit the inside of the kernel to change the value of _flavor to NAME.
 
=== Vanilla with native settings and minimal edits ===
 
Most users will want to use this option.
 
You can use linux-vanilla but what you should do is create a local branch by doing:
 
For Alpine Edge:
 
  git checkout -b my-custom-kernel
 
For Alpine 3.7
 
  git checkout -b my-custom-kernel origin/3.7-stable
 
Doing it this way, you do less work in maintaining.  All you need to do is keep ''master'' or ''3.7-stable'' in sync[https://help.github.com/articles/syncing-a-fork/][https://help.github.com/articles/configuring-a-remote-for-a-fork/] and merge any conflicts. 
 
First switch to the branch by doing <code>git checkout my-custom-kernel</code>. When you are done with your edits either by editing directly the APKBUILD config-vanilla.ARCH or copying the .config overriding the config-vanilla.ARCH generated by <code>make menuconfig</code> (discussed below in the ''Configuring kernel'' section) do <code>git add APKBUILD config-vanilla.ARCH</code> where ARCH is whatever architecture (x86, x86_64, ...) you use.  Then, you need to do <code>git commit APKBUILD</code>.  You do this so that git can keep your code separate from Alpine's and so your changes float forward between kernel updates.
 
== Custom patches ==
 
Custom patches should be added to ''sources=''.
 
After you added the URL, you need to produce a checksum by doing <code>abuild checksum</code>.
 
== Configuring kernel ==
 
Attempt to build the kernel first.  To do that, you do abuild -rK to install most of the dependencies.  If it complains about a dependency like elfutils-dev use -rKd.  Then, when it prompts for values for new found config options just hold enter till it starts compiling the kernel.  Just Ctrl+C out of it.  Then you go into the src/build-NAME and edit the config file.  Copy the .config file overriding the config-NAME in the srcdir.
 
The alternative is to use the kernel configuration menu.  To use it you need <code>ncurses-dev</code>
 
After you are done using the menu, you want to remove <code>ncurses-dev</code>.
 
The options in the kernel config are typically defaults.  If your device is old, it may be set to n by default.


== Building ==
== Building ==


== Testing ==
You should then do a abuild -r to attempt to build it.


== Installing ==
== Installing ==
To install it you do a <code>sudo apk add linux-NAME</code>
== Bootloader ==
You need to configure your bootloader to use the kernel.


[[Category:Kernel]]
[[Category:Kernel]]

Revision as of 06:18, 4 March 2018

This material is work-in-progress ...

Do not follow instructions here until this notice is removed.
(Last edited by Orson Teodoro on 4 Mar 2018.)

This process of building a custom configured kernel assumes you are running on Alpine Linux utilizing abuild & aports.

But why?

You want to build a custom kernel to enable experimental hardware or features or outdated hardware, to reduce bloat further, to tune the kernel to the hardware.

Setting up the Alpine Build System

First, you need to follow the steps in Setup your system and account for building packages. You also need to configure your /etc/apk/repositories so that they search locally for your apks. See Testing the package locally for details.

Working with aports

There are several ways to maintain a kernel. The first option is to create a new kernel package. The other option is to just use the existing vanilla kernel just tweaking the configure-vanilla.ARCH file.

Switching to the proper release version

You need to switch to the proper branch that matches the release so that the kernel compiles against the dependencies properly.

Friendly name Remote branch
Edge master
3.7 3.7-stable

The following is required to get access to the APKBUILD released for that version of Alpine and which you will create a commit for.

If you are on 3.7 do:

 git checkout -b 3.7-stable origin/3.7-stable

If you are on Edge do:

 git checkout master

Creating a new kernel package

Use this option only if you want to want to be a kernel package maintainer or have custom patches.

What you need to do is copy main/linux-vanilla folder to testing/linux-NAME, where NAME could be anything but usually initials or a project name to a special kernel patch or patchset. Just use your last name if you don't know what to put. Rename all files from vanilla to NAME. Rename everything in APKBUILD with vanilla to NAME.

Next step is to edit the inside of the kernel to change the value of _flavor to NAME.

Vanilla with native settings and minimal edits

Most users will want to use this option.

You can use linux-vanilla but what you should do is create a local branch by doing:

For Alpine Edge:

 git checkout -b my-custom-kernel

For Alpine 3.7

 git checkout -b my-custom-kernel origin/3.7-stable

Doing it this way, you do less work in maintaining. All you need to do is keep master or 3.7-stable in sync[1][2] and merge any conflicts.

First switch to the branch by doing git checkout my-custom-kernel. When you are done with your edits either by editing directly the APKBUILD config-vanilla.ARCH or copying the .config overriding the config-vanilla.ARCH generated by make menuconfig (discussed below in the Configuring kernel section) do git add APKBUILD config-vanilla.ARCH where ARCH is whatever architecture (x86, x86_64, ...) you use. Then, you need to do git commit APKBUILD. You do this so that git can keep your code separate from Alpine's and so your changes float forward between kernel updates.

Custom patches

Custom patches should be added to sources=.

After you added the URL, you need to produce a checksum by doing abuild checksum.

Configuring kernel

Attempt to build the kernel first. To do that, you do abuild -rK to install most of the dependencies. If it complains about a dependency like elfutils-dev use -rKd. Then, when it prompts for values for new found config options just hold enter till it starts compiling the kernel. Just Ctrl+C out of it. Then you go into the src/build-NAME and edit the config file. Copy the .config file overriding the config-NAME in the srcdir.

The alternative is to use the kernel configuration menu. To use it you need ncurses-dev

After you are done using the menu, you want to remove ncurses-dev.

The options in the kernel config are typically defaults. If your device is old, it may be set to n by default.

Building

You should then do a abuild -r to attempt to build it.

Installing

To install it you do a sudo apk add linux-NAME

Bootloader

You need to configure your bootloader to use the kernel.