Skip to content

Commit

Permalink
Merge pull request #10 from enix/zfs-20240219
Browse files Browse the repository at this point in the history
20240219
  • Loading branch information
donch authored Feb 19, 2024
2 parents 03c2584 + 054aeda commit 27d5efe
Show file tree
Hide file tree
Showing 50 changed files with 7,060 additions and 18 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ jobs:
"teleport-9.3.26"
"teleport-10.3.16"
"teleport-11.3.27"
"teleport-12.4.30"
"teleport-13.4.11"
"teleport-12.4.34"
"teleport-13.4.16"
"teleport-14.2.3"
"teleport-14.3.0"
"teleport-14.3.6"
"teleport-15.0.2"
)
for image in ${images[@]}; do
Expand Down Expand Up @@ -100,7 +101,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
flatcarversion: ["3602.2.0", "3602.2.1", "3602.2.2", "3602.2.3"]
flatcarversion: ["3510.2.7", "3602.2.3", "3760.2.0", "3815.2.0"]
permissions:
# allow the action to create a release
contents: write
Expand Down Expand Up @@ -147,16 +148,16 @@ jobs:
set -euo pipefail
images=(
"zfs-2.1.12-${{ matrix.flatcarversion }}"
"zfs-${{ matrix.flatcarversion }}"
)
for image in ${images[@]}; do
component="${image%%-*}"
flatcarversion="${image##*-}"
temp="${image#*-}"
version="${temp%-*}"
"./create_${component}_sysext.sh" "${version}" "${component}" "${flatcarversion}"
mv "${component}.raw" "${image}.raw"
component="${image%-*}"
flatcarversion="${image#*-}"
"./create_${component}_sysext.sh" "${component}" "${flatcarversion}"
baked_component=$(ls ${component}-*.raw)
sysext_name="${baked_component%.raw}-${flatcarversion}.raw"
mv "$baked_component" "$sysext_name"
done
sha256sum *.raw >> SHA256SUMS
Expand Down
15 changes: 8 additions & 7 deletions create_zfs_sysext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail
export ARCH="${ARCH-amd64}"
SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")"

if [ $# -lt 3 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 VERSION SYSEXTNAME FLATCARVERSION"
echo "The script will build ZFS modules and tooling and create a sysext squashfs image with the name SYSEXTNAME.raw in the current folder."
echo "A temporary directory named SYSEXTNAME in the current folder will be created and deleted again."
Expand All @@ -14,9 +14,8 @@ if [ $# -lt 3 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
exit 1
fi

VERSION="$1"
SYSEXTNAME="$2"
FLATCARVERSION="$3"
SYSEXTNAME="$1"
FLATCARVERSION="$2"
if [ "${ARCH}" = aarch64 ]; then
ARCH=arm64
fi
Expand All @@ -28,9 +27,12 @@ emerge-gitclone
echo 'FEATURES="-network-sandbox -pid-sandbox -ipc-sandbox -usersandbox -sandbox"' >>/etc/portage/make.conf
cp files/zfs/repos.conf /etc/portage/repos.conf/zfs.conf
cp -r files/zfs/${FLATCARVERSION}/overlay/ /var/lib/portage/zfs-overlay/
# fixme starting with 3760. Incorrect permission on some headers
chmod -R +r /usr/lib/gcc/x86_64-cros-linux-gnu/

# build zfs
echo "========== Build ZFS"
VERSION=$(emerge --search sys-fs/zfs$ | grep "Latest version available" | awk '{print $NF}')
echo "========== Build ZFS $VERSION"
kernel=$(ls /lib/modules) && KBUILD_OUTPUT=/lib/modules/${kernel}/build KERNEL_DIR=/lib/modules/${kernel}/source emerge -j$(nproc) --getbinpkg --onlydeps zfs
emerge -j$(nproc) --getbinpkg --buildpkgonly zfs squashfs-tools

Expand Down Expand Up @@ -58,7 +60,6 @@ rm -rf ${SYSEXTNAME}/usr/share
rm -rf ${SYSEXTNAME}/usr/src
rm -rf ${SYSEXTNAME}/usr/include



"${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}" "${FLATCARVERSION}"
mv "${SYSEXTNAME}.raw" "${SYSEXTNAME}-${VERSION}.raw"
rm -rf "${SYSEXTNAME}"
201 changes: 201 additions & 0 deletions files/zfs/3760.2.0/overlay/eclass/dist-kernel-utils.eclass
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# Copyright 2020-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: dist-kernel-utils.eclass
# @MAINTAINER:
# Distribution Kernel Project <dist-kernel@gentoo.org>
# @AUTHOR:
# Michał Górny <mgorny@gentoo.org>
# @SUPPORTED_EAPIS: 7 8
# @BLURB: Utility functions related to Distribution Kernels
# @DESCRIPTION:
# This eclass provides various utility functions related to Distribution
# Kernels.

# @ECLASS_VARIABLE: KERNEL_IUSE_SECUREBOOT
# @PRE_INHERIT
# @DEFAULT_UNSET
# @DESCRIPTION:
# If set to a non-null value, inherits secureboot.eclass
# and allows signing of generated kernel images.

if [[ ! ${_DIST_KERNEL_UTILS} ]]; then

case ${EAPI} in
7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac

if [[ ${KERNEL_IUSE_SECUREBOOT} ]]; then
inherit secureboot
fi

# @FUNCTION: dist-kernel_build_initramfs
# @USAGE: <output> <version>
# @DESCRIPTION:
# Build an initramfs for the kernel. <output> specifies the absolute
# path where initramfs will be created, while <version> specifies
# the kernel version, used to find modules.
#
# Note: while this function uses dracut at the moment, other initramfs
# variants may be supported in the future.
dist-kernel_build_initramfs() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
local output=${1}
local version=${2}

local rel_image_path=$(dist-kernel_get_image_path)
local image=${output%/*}/${rel_image_path##*/}

local args=(
--force
# if uefi=yes is used, dracut needs to locate the kernel image
--kernel-image "${image}"

# positional arguments
"${output}" "${version}"
)

ebegin "Building initramfs via dracut"
dracut "${args[@]}"
eend ${?} || die -n "Building initramfs failed"
}

# @FUNCTION: dist-kernel_get_image_path
# @DESCRIPTION:
# Get relative kernel image path specific to the current ${ARCH}.
dist-kernel_get_image_path() {
case ${ARCH} in
amd64|x86)
echo arch/x86/boot/bzImage
;;
arm64)
echo arch/arm64/boot/Image.gz
;;
arm)
echo arch/arm/boot/zImage
;;
hppa|ppc|ppc64|sparc)
# https://www.kernel.org/doc/html/latest/powerpc/bootwrapper.html
# ./ is required because of ${image_path%/*}
# substitutions in the code
echo ./vmlinux
;;
riscv)
echo arch/riscv/boot/Image.gz
;;
*)
die "${FUNCNAME}: unsupported ARCH=${ARCH}"
;;
esac
}

# @FUNCTION: dist-kernel_install_kernel
# @USAGE: <version> <image> <system.map>
# @DESCRIPTION:
# Install kernel using installkernel tool. <version> specifies
# the kernel version, <image> full path to the image, <system.map>
# full path to System.map.
dist-kernel_install_kernel() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments"
local version=${1}
local image=${2}
local map=${3}

# if dracut is used in uefi=yes mode, initrd will actually
# be a combined kernel+initramfs UEFI executable. we can easily
# recognize it by PE magic (vs cpio for a regular initramfs)
local initrd=${image%/*}/initrd
local magic
[[ -s ${initrd} ]] && read -n 2 magic < "${initrd}"
if [[ ${magic} == MZ ]]; then
einfo "Combined UEFI kernel+initramfs executable found"
# install the combined executable in place of kernel
image=${initrd%/*}/uki.efi
mv "${initrd}" "${image}" || die
# We moved the generated initrd, prevent dracut from running again
# https://github.com/dracutdevs/dracut/pull/2405
shopt -s nullglob
local plugins=()
for file in "${EROOT}"/etc/kernel/install.d/*.install; do
plugins+=( "${file}" )
done
for file in "${EROOT}"/usr/lib/kernel/install.d/*.install; do
if ! has "${file##*/}" 50-dracut.install 51-dracut-rescue.install "${plugins[@]##*/}"; then
plugins+=( "${file}" )
fi
done
shopt -u nullglob
export KERNEL_INSTALL_PLUGINS="${KERNEL_INSTALL_PLUGINS} ${plugins[@]}"
fi

if [[ ${KERNEL_IUSE_SECUREBOOT} ]]; then
# Kernel-install requires uki's are named uki.efi, sign in-place
secureboot_sign_efi_file "${image}" "${image}"
fi

ebegin "Installing the kernel via installkernel"
# note: .config is taken relatively to System.map;
# initrd relatively to bzImage
installkernel "${version}" "${image}" "${map}"
eend ${?} || die -n "Installing the kernel failed"
}

# @FUNCTION: dist-kernel_reinstall_initramfs
# @USAGE: <kv-dir> <kv-full>
# @DESCRIPTION:
# Rebuild and install initramfs for the specified dist-kernel.
# <kv-dir> is the kernel source directory (${KV_DIR} from linux-info),
# while <kv-full> is the full kernel version (${KV_FULL}).
# The function will determine whether <kernel-dir> is actually
# a dist-kernel, and whether initramfs was used.
#
# This function is to be used in pkg_postinst() of ebuilds installing
# kernel modules that are included in the initramfs.
dist-kernel_reinstall_initramfs() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
local kernel_dir=${1}
local ver=${2}

local image_path=${kernel_dir}/$(dist-kernel_get_image_path)
local initramfs_path=${image_path%/*}/initrd
if [[ ! -f ${image_path} ]]; then
eerror "Kernel install missing, image not found:"
eerror " ${image_path}"
eerror "Initramfs will not be updated. Please reinstall your kernel."
return
fi
if [[ ! -f ${initramfs_path} && ! -f ${initramfs_path%/*}/uki.efi ]]; then
einfo "No initramfs or uki found at ${image_path}"
return
fi

dist-kernel_build_initramfs "${initramfs_path}" "${ver}"
dist-kernel_install_kernel "${ver}" "${image_path}" \
"${kernel_dir}/System.map"
}

# @FUNCTION: dist-kernel_PV_to_KV
# @USAGE: <pv>
# @DESCRIPTION:
# Convert a Gentoo-style ebuild version to kernel "x.y.z[-rcN]" version.
dist-kernel_PV_to_KV() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments"
local pv=${1}

local kv=${pv%%_*}
[[ -z $(ver_cut 3- "${kv}") ]] && kv+=".0"
[[ ${pv} == *_* ]] && kv+=-${pv#*_}
echo "${kv}"
}

_DIST_KERNEL_UTILS=1
fi
Loading

0 comments on commit 27d5efe

Please sign in to comment.