├── .dockerignore ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── Vagrantfile ├── ansible ├── ansible.cfg ├── playbook.yml └── roles │ └── docker │ └── tasks │ └── main.yml ├── patches └── macbook-11-screen-flickering.patch └── scripts └── kernel-build /.dockerignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | .git 3 | 4 | Vagrantfile 5 | 6 | ansible 7 | target 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | 3 | target 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | MAINTAINER Naftuli Kay 4 | 5 | RUN apt-get update >/dev/null 6 | 7 | ENV KERNEL_MAJOR=4.4.0 8 | 9 | # get the latest kernel in the given major release 10 | RUN apt-cache search linux-image-$KERNEL_MAJOR- | \ 11 | grep -ioP "(?<=linux-image-)$KERNEL_MAJOR-\d+(?=-generic)" | sort -r | head -1 > /tmp/kernel-release 12 | 13 | RUN apt-get build-dep -y linux-image-$(cat /tmp/kernel-release)-generic >/dev/null && \ 14 | apt-get install -y fakeroot >/dev/null && \ 15 | apt-get clean >/dev/null 16 | 17 | RUN install --directory -m 0755 /data && \ 18 | install --directory -m 0755 /patches 19 | 20 | ADD scripts/kernel-build /usr/local/bin/kernel-build 21 | RUN chmod 0755 /usr/local/bin/kernel-build 22 | 23 | WORKDIR /data 24 | 25 | VOLUME /data 26 | VOLUME /patches 27 | 28 | # we have to run as root so that we can apt-get update 29 | ENTRYPOINT ["/usr/local/bin/kernel-build"] 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Naftuli Kay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ubuntu-kernel-build 2 | 3 | A Docker container for building an Ubuntu kernel with arbitrary patches, config flags, and a tag. 4 | 5 | ## Example 6 | 7 | A simple kernel build can be run like so: 8 | 9 | ``` 10 | sudo install --directory -o 1000 -g 1000 ~/kbuild 11 | sudo docker run -it --rm -v ~/kbuild:/data \ 12 | naftulikay/ubuntu-kernel-build 13 | ``` 14 | 15 | The end result will be a series of Debian kernel packages in the `~/kbuild` directory. 16 | 17 | A more advanced build with patches and building `lowlatency`, `cloud`, and `generic` kernel packages: 18 | 19 | ``` 20 | sudo docker run -it --rm -v ~/kbuild:/data -v ~/patches:/patches \ 21 | -e BUILD_TYPE=full naftulikay/ubuntu-kernel-build 22 | ``` 23 | 24 | ## Environment Variables 25 | 26 | ### `KERNEL_MAJOR` 27 | 28 | The major kernel version to build, by default `4.4.0`. 29 | 30 | ### `BUILD_TAG` 31 | 32 | The tag appended to the package version to make the package unique, defaults to `hardcore` for obvious reasons. 33 | 34 | ### `BUILD_TYPE` 35 | 36 | The type of kernel build to run, either `fast` (default), `full`, or `custom`. 37 | 38 | If `custom`, `BUILD_CMD` must be specified. 39 | 40 | ### `BUILD_CMD` 41 | 42 | If `BUILD_TYPE` is set to `custom`, this must be specified as arguments to `fakeroot debian/rules`. 43 | 44 | ## Volumes 45 | 46 | ### `/data` 47 | 48 | This will be the directory where the kernel is built. It should be owned by a user with a UID of 1000. 49 | 50 | ### `/patches` 51 | 52 | This is a directory containing patch files to apply against the kernel sources before building. 53 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | require 'etc' 5 | require 'shellwords' 6 | 7 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 8 | VAGRANTFILE_API_VERSION = "2" 9 | 10 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 11 | # Every Vagrant virtual environment requires a box to build off of. 12 | config.vm.box = "bento/centos-7.3" 13 | config.vm.hostname = "devel" 14 | 15 | # Create a private network, which allows host-only access to the machine 16 | # using a specific IP. 17 | config.vm.network "private_network", type: "dhcp" 18 | 19 | # Tweak the VMs configuration. 20 | config.vm.provider "virtualbox" do |vb| 21 | vb.cpus = Etc.nprocessors 22 | vb.memory = 2048 23 | vb.linked_clone = true 24 | end 25 | 26 | # configure ssh to pass through certain AWS environment variables for auth 27 | config.ssh.forward_env = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"] 28 | 29 | # Configure the VM using Ansible 30 | config.vm.provision "ansible_local" do |ansible| 31 | # allow passing ansible args from environment variable 32 | ansible.raw_arguments = Shellwords::shellwords(ENV.fetch("ANSIBLE_ARGS", "")) 33 | 34 | ansible.provisioning_path = "/vagrant/ansible/" 35 | ansible.playbook = "playbook.yml" 36 | 37 | # ansible.galaxy_role_file = "requirements.yml" 38 | # ansible.galaxy_roles_path = "galaxy_roles" 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /ansible/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | retry_files_enabled = false 3 | -------------------------------------------------------------------------------- /ansible/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | become: yes 4 | roles: 5 | - role: docker 6 | 7 | tasks: 8 | - name: setenforce 1 9 | selinux: policy=targeted state=enforcing 10 | -------------------------------------------------------------------------------- /ansible/roles/docker/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install docker repo 3 | yum_repository: 4 | name: docker 5 | description: Docker Repository 6 | enabled: yes 7 | baseurl: https://yum.dockerproject.org/repo/main/centos/7/ 8 | gpgcheck: yes 9 | gpgkey: https://yum.dockerproject.org/gpg 10 | 11 | - name: install docker 12 | package: name=docker-engine state=present 13 | 14 | - name: start docker 15 | service: name=docker state=started enabled=yes 16 | -------------------------------------------------------------------------------- /patches/macbook-11-screen-flickering.patch: -------------------------------------------------------------------------------- 1 | diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c 2 | index 10191b9..8409dea 100644 3 | --- a/drivers/gpu/drm/radeon/si_dpm.c 4 | +++ b/drivers/gpu/drm/radeon/si_dpm.c 5 | @@ -3010,16 +3010,18 @@ static void si_apply_state_adjust_rules(struct radeon_device *rdev, 6 | max_mclk = 120000; 7 | } else if (rdev->family == CHIP_VERDE) { 8 | if ((rdev->pdev->revision == 0x81) || 9 | - (rdev->pdev->revision == 0x83) || 10 | (rdev->pdev->revision == 0x87) || 11 | (rdev->pdev->device == 0x6820) || 12 | - (rdev->pdev->device == 0x6821) || 13 | (rdev->pdev->device == 0x6822) || 14 | (rdev->pdev->device == 0x6823) || 15 | (rdev->pdev->device == 0x682A) || 16 | (rdev->pdev->device == 0x682B)) { 17 | max_sclk = 75000; 18 | max_mclk = 80000; 19 | + } else if (rdev->pdev->device == 0x6821 && 20 | + rdev->pdev->revision == 0x83) { 21 | + max_sclk = 80000; 22 | + max_mclk = 112500; 23 | } 24 | } else if (rdev->family == CHIP_OLAND) { 25 | if ((rdev->pdev->revision == 0xC7) || 26 | -------------------------------------------------------------------------------- /scripts/kernel-build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | KERNEL_MAJOR="${KERNEL_MAJOR:-4.4.0}" 6 | BUILD_TYPE="${BUILD_TYPE:-fast}" 7 | BUILD_CLEAN="${BUILD_CLEAN:-n}" 8 | BUILD_TAG="${BUILD_TAG:-hardcore}" 9 | 10 | 11 | function get-latest-kernel-version() { 12 | # find the latest kernel in the given line 13 | apt-cache search linux-image-${KERNEL_MAJOR}- | grep -ioP "(?<=linux-image-)${KERNEL_MAJOR}-\d+(?=-generic)" | sort -r | head -1 14 | } 15 | 16 | function install-kernel-source() { 17 | # source the kernel 18 | apt-get update >/dev/null 19 | apt-get source linux-image-$(get-latest-kernel-version)-generic 20 | } 21 | 22 | function patch-kernel() { 23 | ( 24 | cd linux-${KERNEL_MAJOR} 25 | find /patches -type f -iname '*.patch' | sort -n | while read patch_file ; do 26 | # patch files 27 | patch -p1 -N < $patch_file || rc=$? 28 | # if the patch returned non-zero, it could just have been skipped as already applied 29 | if [ $rc -gt 1 ]; then 30 | echo "Patch: $patch_file failed." >&2 31 | exit $rc 32 | fi 33 | done 34 | ) 35 | } 36 | 37 | function configure-kernel() { 38 | ( 39 | # so in debian.master/config/amd64/config.* are defined kernel config lines. 40 | # to allow custom config entries, get the value of env and grep for all 41 | # CONFIG_* entries. 42 | # for each of these, see if there is an uncommented line in those files 43 | echo 44 | ) 45 | } 46 | 47 | function update-kernel-version() { 48 | ( 49 | cd linux-${KERNEL_MAJOR} 50 | 51 | local latest_kernel=$(head -n 1 debian.master/changelog | grep -oP '(?<=\()[^)]+(?=\))') 52 | local latest_kernel_tag="$(echo $latest_kernel | grep -oP "(?<=\+)${build_tag}$")" 53 | 54 | if [ "$latest_kernel_tag" != "$build_tag" ]; then 55 | # tag it up 56 | local line="$(head -n 1 debian.master/changelog)" 57 | local before="$(echo "$line" | grep -oP '^.*\(')" 58 | local after="$(echo "$line" | grep -oP '\).*$')" 59 | 60 | sed -i "1 s|^.*$|${before}${latest_kernel}+${build_tag}${after}|" debian.master/changelog 61 | fi 62 | ) 63 | 64 | return 0 65 | } 66 | 67 | function build-kernel() { 68 | ( 69 | cd linux-${KERNEL_MAJOR} 70 | 71 | local build_clean="$BUILD_CLEAN" 72 | local build_type="$BUILD_TYPE" 73 | local build_tag="$BUILD_TAG" 74 | local build_cmd="$BUILD_CMD" 75 | 76 | # unset these so they don't propagate into the build 77 | unset BUILD_CLEAN BUILD_TYPE BUILD_TAG BUILD_CMD 78 | 79 | if [[ "${build_clean}" != "n" ]]; then 80 | fakeroot debian/rules clean 81 | fi 82 | 83 | if [[ "${build_type}" == "full" ]]; then 84 | fakeroot debian/rules binary 85 | elif [[ "${build_type}" == "fast" ]]; then 86 | fakeroot debian/rules binary-headers binary-generic binary-perarch 87 | else 88 | fakeroot debian/rules ${build_cmd} 89 | fi 90 | ) 91 | } 92 | 93 | function main() { 94 | # validate build type 95 | case ${BUILD_TYPE} in 96 | full) 97 | ;; 98 | fast) 99 | ;; 100 | custom) 101 | ;; 102 | *) 103 | echo "Unknown BUILD_TYPE: should be either full, fast, or custom." >&2 104 | exit 1 105 | ;; 106 | esac 107 | 108 | if [ "$BUILD_TYPE" == "custom" -a -z "$BUILD_CMD" ]; then 109 | # if build type is custom and build command is empty 110 | echo "Custom build types need to specify BUILD_CMD." >&2 111 | exit 1 112 | fi 113 | 114 | # do the thing 115 | install-kernel-source 116 | 117 | # patch and configure the kernel sources 118 | patch-kernel 119 | configure-kernel 120 | 121 | # append a tag to the kernel package 122 | update-kernel-version 123 | 124 | # build it 125 | build-kernel 126 | } 127 | 128 | if [[ ${BASH_SOURCE[0]} == $0 ]]; then 129 | main 130 | fi 131 | --------------------------------------------------------------------------------