Skip to content

Instantly share code, notes, and snippets.

@vbatts
Created June 16, 2020 15:28
Show Gist options
  • Save vbatts/9af92a341611751dc3a157f204a84973 to your computer and use it in GitHub Desktop.
Save vbatts/9af92a341611751dc3a157f204a84973 to your computer and use it in GitHub Desktop.
building kernel module on flatcar
#!/bin/bash
# more information on building kernel modules https://docs.flatcar-linux.org/os/kernel-modules/
set -ue
. /etc/os-release
. /etc/flatcar/update.conf
rm -f flatcar_developer_container.bin.bz2.DIGESTS ||:
wget "https://${GROUP}.release.flatcar-linux.net/${FLATCAR_BOARD}/${VERSION}/flatcar_developer_container.bin.bz2.DIGESTS"
set +e
sha512sum -c flatcar_developer_container.bin.bz2.DIGESTS
ret="$?"
set -e
if [ "${ret}" -eq 0 ] ; then
rm -f \
flatcar_developer_container.bin.bz2 \
flatcar_developer_container_contents.txt \
flatcar_developer_container_packages.txt \
flatcar_developer_container_licenses.json
fi
if [ ! -f flatcar_developer_container.bin.bz2 ] ; then
echo "fetching developer image: https://${GROUP}.release.flatcar-linux.net/${FLATCAR_BOARD}/${VERSION}/flatcar_developer_container.bin.bz2"
wget \
"https://${GROUP}.release.flatcar-linux.net/${FLATCAR_BOARD}/${VERSION}/flatcar_developer_container.bin.bz2" \
"https://${GROUP}.release.flatcar-linux.net/${FLATCAR_BOARD}/${VERSION}/flatcar_developer_container_contents.txt" \
"https://${GROUP}.release.flatcar-linux.net/${FLATCAR_BOARD}/${VERSION}/flatcar_developer_container_packages.txt" \
"https://${GROUP}.release.flatcar-linux.net/${FLATCAR_BOARD}/${VERSION}/flatcar_developer_container_licenses.json"
sha512sum -c flatcar_developer_container.bin.bz2.DIGESTS
fi
if [ ! -f flatcar_developer_container.bin ] ; then
echo "extracting developer image"
bzcat flatcar_developer_container.bin.bz2 > flatcar_developer_container.bin
fi
dev() {
systemd-nspawn -q -i ./flatcar_developer_container.bin --bind=/usr/lib64/modules --bind=/:/hostfs ${@}
}
dev -- passwd -d root
dev -- grep ^VERSION= /etc/os-release | cut -d = -f 2
dev -- grep ^GROUP= /etc/flatcar/update.conf | cut -d = -f 2
## /etc/portage/make.conf needs
# PORTAGE_BINHOST="https://storage.googleapis.com/flatcar-jenkins/boards/amd64-usr/2345.3.1/pkgs/
# https://storage.googleapis.com/flatcar-jenkins/boards/amd64-usr/2345.3.1/toolchain/"
dev -- emerge-gitclone
dev -- emerge -gKv coreos-sources ||:
dev -- emerge -gKv sys-fs/squashfs-tools || :
dev -- sh -c 'zcat /proc/config.gz | dd of=/usr/src/linux/.config' || :
dev -- make -C /usr/src/linux modules_prepare || :
if [ ! -d wireguard-linux-compat ] ; then
git clone https://git.zx2c4.com/wireguard-linux-compat
else
pushd wireguard-linux-compat
git pull -r --autostash
popd
fi
dev --chdir=/hostfs/root/wireguard-linux-compat/src -- make clean
dev --chdir=/hostfs/root/wireguard-linux-compat/src -- make -j$(nproc)
dev --chdir=/hostfs/root/wireguard-linux-compat/src -- make install
if [ ! -d /opt/modules ] ; then
mkdir -p /opt/modules
fi
systemctl unmask usr-lib64-modules.mount
cat > /etc/systemd/system/usr-lib64-modules.mount <<EOF
# DO NOT EDIT
[Unit]
Description=Custom Kernel Modules
Before=local-fs.target
ConditionPathExists=/opt/modules
[Mount]
Type=overlay
What=overlay
Where=/usr/lib64/modules
Options=lowerdir=/usr/lib64/modules,upperdir=/opt/modules,workdir=/opt/modules.wd
[Install]
WantedBy=local-fs.target
EOF
systemctl enable --now usr-lib64-modules.mount
if [ ! -d wireguard-tools ] ; then
git clone --recursive https://git.zx2c4.com/wireguard-tools
else
pushd wireguard-tools
git pull -r --autostash
popd
fi
dev --chdir=/hostfs/root/wireguard-tools/src -- make clean
dev --chdir=/hostfs/root/wireguard-tools/src -- make -j$(nproc)
dev --chdir=/hostfs/root/wireguard-tools/src -- make install DESTDIR=/hostfs/opt/
# vim:set sts=2 sw=2 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment