Skip to content

Commit

Permalink
feat: provide an easy way to manage kernel configuration
Browse files Browse the repository at this point in the history
This automates the kernel configuration generation process described in
`kernel/README.md` and wraps it as easy to use `make` targets, e.g.:

* `make kernel-olddefconfig` updates kernel config for the new kernel
version
* `make kernel-menuconfig` launches interactive kernel configuration

List of architectures can be updated via `PLATFORM=` variable override.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Aug 5, 2020
1 parent f0e2bdb commit db45e19
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 113 deletions.
11 changes: 11 additions & 0 deletions Makefile
Expand Up @@ -13,6 +13,10 @@ COMMON_ARGS := --file=Pkgfile
COMMON_ARGS += --progress=$(PROGRESS)
COMMON_ARGS += --platform=$(PLATFORM)

, := ,
space :=
space +=

TARGETS = ca-certificates cni containerd dosfstools eudev fhs grub ipmitool iptables kernel kmod libaio libressl libseccomp linux-firmware lvm2 musl open-iscsi open-isns runc socat syslinux util-linux xfsprogs

all: $(TARGETS) ## Builds all known pkgs.
Expand All @@ -37,3 +41,10 @@ $(TARGETS):
.PHONY: deps.png
deps.png:
bldr graph | dot -Tpng > deps.png

kernel-%: ## Updates the kernel configs: e.g. make kernel-olddefconfig; make kernel-menuconfig; etc.
for platform in $(subst $(,),$(space),$(PLATFORM)); do \
arch=`basename $$platform` ; \
$(MAKE) docker-kernel-prepare PLATFORM=$$platform TARGET_ARGS="--tag=$(REGISTRY)/$(USERNAME)/kernel:$(TAG)-$$arch --load"; \
docker run --rm -it --entrypoint=/toolchain/bin/bash -e PATH=/toolchain/bin:/bin -w /src -v $$PWD/kernel/kernel/config-$$arch:/src/.hostconfig $(REGISTRY)/$(USERNAME)/kernel:$(TAG)-$$arch -c 'cp .hostconfig .config && make $* && cp .config .hostconfig'; \
done
36 changes: 16 additions & 20 deletions kernel/README.md
@@ -1,32 +1,28 @@
# Kernel

## Customizing the kernel
## Updating kernel config

When updating kernel to the new version, import proper defaults with:

High-level notes:
```sh
make kernel-olddefconfig
```

- In pkg.yaml, comment out the `build` and `install` steps
- At the bottom of pkg.yaml, change the finalize step from
If you want to update for a specific architecture only, use:

```yaml
finalize:
- from: /rootfs
to: /
```sh
make kernel-olddefconfig PLATFORM=linux/arm64
```

to
## Customizing the kernel

Run another target to get into `menuconfig`:

```yaml
finalize:
- from: /
to: /
```sh
make kernel-menuconfig
```

- Create a local image with `docker buildx build -t kernel --target kernel -f Pkgfile --load .`
- Run the kernel image we created: `docker run --rm -it --entrypoint=/toolchain/bin/bash kernel`
- Set path: `export PATH=/toolchain/bin:/bin`
- Change to build dir: `cd /tmp/build/0`
- Make changes to kernel settings with `make menuconfig` and save upon exiting
- With the container still running, copy the config out to local disk: `docker cp $CONTAINER_ID:/tmp/build/0/.config config-amd64`
- Revert your changes to pkg.yaml
## Testing

- Build and push a test image with `make USERNAME=rsmitty PUSH=true kernel`
- PR upstream (when ready) and profit
57 changes: 57 additions & 0 deletions kernel/kernel-prepare/pkg.yaml
@@ -0,0 +1,57 @@
name: kernel-prepare
variant: scratch
shell: /toolchain/bin/bash
dependencies:
- image: '{{ .TOOLS_IMAGE }}'
steps:
- sources:
- url: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.7.7.tar.xz
destination: linux.tar.xz
sha256: f840b9679283343c165516585c3070ebb277528721c890e9410a58e9d071ee7f
sha512: 49db85a1ce14e00411215d5d5bfda6db3d24ed2e0f2bd8e6603c18b3226614f45040856b21b4d6b525c44bb4463ab08fb594a06de6deca109d512588389cc3fd
env:
ARCH: {{ if eq .ARCH "aarch64"}}arm64{{ else if eq .ARCH "x86_64" }}x86_64{{ else }}unsupported{{ end }}
prepare:
- |
tar -xJf linux.tar.xz --strip-components=1
rm linux.tar.xz
mkdir /bin
ln -sv /toolchain/bin/bash /bin/bash
ln -sv /toolchain/bin/bash /bin/sh
ln -sv /toolchain/lib /lib
mkdir -p /usr/bin \
&& ln -sf /toolchain/bin/env /usr/bin/env \
&& ln -sf /toolchain/bin/true /bin/true \
&& ln -sf /toolchain/bin/false /bin/false \
&& ln -sf /toolchain/bin/pwd /bin/pwd
# Ensure that `make menuconfig` works.
ln -s /toolchain/bin/awk /usr/bin/awk
mkdir -p /usr/lib/pkgconfig
ln -s /toolchain/include /usr/include
for lib in ncurses form panel menu ; do
rm -vf /lib/lib${lib}.so
echo "INPUT(-l${lib}w)" > /lib/lib${lib}.so
ln -sfv ${lib}w.pc /lib/pkgconfig/${lib}.pc
done
make mrproper
install:
- |
mkdir -p /src
cp -a . /src/
finalize:
- from: /src
to: /src
- from: /toolchain
to: /toolchain
- from: /usr
to: /usr
- from: /bin
to: /bin
- from: /lib
to: /lib
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions kernel/kernel/pkg.yaml
@@ -0,0 +1,44 @@
name: kernel
variant: scratch
shell: /toolchain/bin/bash
dependencies:
- stage: kernel-prepare
steps:
- env:
ARCH: {{ if eq .ARCH "aarch64"}}arm64{{ else if eq .ARCH "x86_64" }}x86_64{{ else }}unsupported{{ end }}
CARCH: {{ if eq .ARCH "aarch64"}}arm64{{ else if eq .ARCH "x86_64" }}amd64{{ else }}unsupported{{ end }}
prepare:
- |
cp -a /src/. .
cp -v /pkg/config-${CARCH} .config
build:
- |
make -j $(nproc)
make -j $(nproc) modules
install:
- |
mkdir -p /rootfs/boot
case $ARCH in
x86_64)
mv arch/x86/boot/bzImage /rootfs/boot/vmlinuz
mv vmlinux /rootfs/boot/vmlinux
;;
arm64)
mv arch/arm64/boot/Image.gz /rootfs/boot/vmlinuz
mv vmlinux /rootfs/boot/vmlinux
;;
*)
echo "unsupported arch ${ARCH}"
exit 1
;;
esac
export KERNELRELEASE=$(cat include/config/kernel.release)
make -j $(nproc) modules_install DEPMOD=/toolchain/bin/depmod INSTALL_MOD_PATH=/rootfs
depmod -b /rootfs $KERNELRELEASE
unlink /rootfs/lib/modules/$KERNELRELEASE/build
unlink /rootfs/lib/modules/$KERNELRELEASE/source
finalize:
- from: /rootfs
to: /
93 changes: 0 additions & 93 deletions kernel/pkg.yaml

This file was deleted.

0 comments on commit db45e19

Please sign in to comment.