Skip to content

Commit 709cc1b

Browse files
authored
Merge pull request #1 from enix/feat/zfs
feat: add ZFS sysext (modules and tools build)
2 parents b0b0027 + f13c3a3 commit 709cc1b

46 files changed

Lines changed: 5814 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

create_zfs_sysext.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
export ARCH="${ARCH-amd64}"
5+
SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")"
6+
7+
if [ $# -lt 3 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
8+
echo "Usage: $0 VERSION SYSEXTNAME FLATCARVERSION"
9+
echo "The script will build ZFS modules and tooling and create a sysext squashfs image with the name SYSEXTNAME.raw in the current folder."
10+
echo "A temporary directory named SYSEXTNAME in the current folder will be created and deleted again."
11+
echo "All files in the sysext image will be owned by root."
12+
echo "To use arm64 pass 'ARCH=arm64' as environment variable (current value is '${ARCH}')."
13+
"${SCRIPTFOLDER}"/bake.sh --help
14+
exit 1
15+
fi
16+
17+
VERSION="$1"
18+
SYSEXTNAME="$2"
19+
FLATCARVERSION="$3"
20+
if [ "${ARCH}" = aarch64 ]; then
21+
ARCH=arm64
22+
fi
23+
rm -f ${SYSEXTNAME}
24+
25+
# base
26+
echo "========== Prepare base"
27+
emerge-gitclone
28+
echo 'FEATURES="-network-sandbox -pid-sandbox -ipc-sandbox -usersandbox -sandbox"' >>/etc/portage/make.conf
29+
cp files/zfs/repos.conf /etc/portage/repos.conf/zfs.conf
30+
cp -r files/zfs/${FLATCARVERSION}/overlay/ /var/lib/portage/zfs-overlay/
31+
32+
# build zfs
33+
echo "========== Build ZFS"
34+
kernel=$(ls /lib/modules) && KBUILD_OUTPUT=/lib/modules/${kernel}/build KERNEL_DIR=/lib/modules/${kernel}/source emerge -j$(nproc) --getbinpkg --onlydeps zfs
35+
emerge -j$(nproc) --getbinpkg --buildpkgonly zfs squashfs-tools
36+
37+
# install deps
38+
echo "========== Install deps"
39+
emerge --getbinpkg --usepkg squashfs-tools
40+
41+
# flatcar layout compat
42+
echo "========== Create Flatcar layout"
43+
mkdir -p ${SYSEXTNAME} ; for dir in lib lib64 bin sbin; do mkdir -p ${SYSEXTNAME}/usr/$dir; ln -s usr/$dir ${SYSEXTNAME}/$dir; done
44+
echo "========== Copy kernel modules to workdir"
45+
mkdir -p ${SYSEXTNAME}/lib/modules
46+
rsync -a /lib/modules/${kernel} ${SYSEXTNAME}/lib/modules/
47+
echo "========== Emerge packages"
48+
pkgs=$(emerge 2>/dev/null --usepkgonly --pretend zfs| awk -F'] ' '/binary/{ print $ 2 }' | awk '{ print "="$1 }'); emerge --usepkgonly --root=${SYSEXTNAME} --nodeps $pkgs
49+
echo "========== Create sysext metadata file"
50+
mkdir -p ${SYSEXTNAME}/usr/lib/extension-release.d && echo -e 'ID=flatcar\nSYSEXT_LEVEL=1.0' >${SYSEXTNAME}/usr/lib/extension-release.d/extension-release.zfs
51+
mv ${SYSEXTNAME}/etc ${SYSEXTNAME}/usr/etc
52+
echo "========== Copy static files (systemd) to workdir"
53+
rsync -a files/zfs/usr/ ${SYSEXTNAME}/usr/
54+
55+
# clean uneeded files
56+
echo "========== Cleaning"
57+
rm -rf ${SYSEXTNAME}/var/db
58+
rm -rf ${SYSEXTNAME}/var/cache
59+
rm -rf ${SYSEXTNAME}/usr/share
60+
rm -rf ${SYSEXTNAME}/usr/src
61+
rm -rf ${SYSEXTNAME}/usr/include
62+
63+
64+
65+
"${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}"
66+
rm -rf "${SYSEXTNAME}"
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Copyright 2020-2023 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
# @ECLASS: dist-kernel-utils.eclass
5+
# @MAINTAINER:
6+
# Distribution Kernel Project <dist-kernel@gentoo.org>
7+
# @AUTHOR:
8+
# Michał Górny <mgorny@gentoo.org>
9+
# @SUPPORTED_EAPIS: 7 8
10+
# @BLURB: Utility functions related to Distribution Kernels
11+
# @DESCRIPTION:
12+
# This eclass provides various utility functions related to Distribution
13+
# Kernels.
14+
15+
# @ECLASS_VARIABLE: KERNEL_IUSE_SECUREBOOT
16+
# @PRE_INHERIT
17+
# @DEFAULT_UNSET
18+
# @DESCRIPTION:
19+
# If set to a non-null value, inherits secureboot.eclass
20+
# and allows signing of generated kernel images.
21+
22+
if [[ ! ${_DIST_KERNEL_UTILS} ]]; then
23+
24+
case ${EAPI} in
25+
7|8) ;;
26+
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
27+
esac
28+
29+
if [[ ${KERNEL_IUSE_SECUREBOOT} ]]; then
30+
inherit secureboot
31+
fi
32+
33+
# @FUNCTION: dist-kernel_build_initramfs
34+
# @USAGE: <output> <version>
35+
# @DESCRIPTION:
36+
# Build an initramfs for the kernel. <output> specifies the absolute
37+
# path where initramfs will be created, while <version> specifies
38+
# the kernel version, used to find modules.
39+
#
40+
# Note: while this function uses dracut at the moment, other initramfs
41+
# variants may be supported in the future.
42+
dist-kernel_build_initramfs() {
43+
debug-print-function ${FUNCNAME} "${@}"
44+
45+
[[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
46+
local output=${1}
47+
local version=${2}
48+
49+
local rel_image_path=$(dist-kernel_get_image_path)
50+
local image=${output%/*}/${rel_image_path##*/}
51+
52+
local args=(
53+
--force
54+
# if uefi=yes is used, dracut needs to locate the kernel image
55+
--kernel-image "${image}"
56+
57+
# positional arguments
58+
"${output}" "${version}"
59+
)
60+
61+
ebegin "Building initramfs via dracut"
62+
dracut "${args[@]}"
63+
eend ${?} || die -n "Building initramfs failed"
64+
}
65+
66+
# @FUNCTION: dist-kernel_get_image_path
67+
# @DESCRIPTION:
68+
# Get relative kernel image path specific to the current ${ARCH}.
69+
dist-kernel_get_image_path() {
70+
case ${ARCH} in
71+
amd64|x86)
72+
echo arch/x86/boot/bzImage
73+
;;
74+
arm64)
75+
echo arch/arm64/boot/Image.gz
76+
;;
77+
arm)
78+
echo arch/arm/boot/zImage
79+
;;
80+
hppa|ppc|ppc64|sparc)
81+
# https://www.kernel.org/doc/html/latest/powerpc/bootwrapper.html
82+
# ./ is required because of ${image_path%/*}
83+
# substitutions in the code
84+
echo ./vmlinux
85+
;;
86+
riscv)
87+
echo arch/riscv/boot/Image.gz
88+
;;
89+
*)
90+
die "${FUNCNAME}: unsupported ARCH=${ARCH}"
91+
;;
92+
esac
93+
}
94+
95+
# @FUNCTION: dist-kernel_install_kernel
96+
# @USAGE: <version> <image> <system.map>
97+
# @DESCRIPTION:
98+
# Install kernel using installkernel tool. <version> specifies
99+
# the kernel version, <image> full path to the image, <system.map>
100+
# full path to System.map.
101+
dist-kernel_install_kernel() {
102+
debug-print-function ${FUNCNAME} "${@}"
103+
104+
[[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments"
105+
local version=${1}
106+
local image=${2}
107+
local map=${3}
108+
109+
# if dracut is used in uefi=yes mode, initrd will actually
110+
# be a combined kernel+initramfs UEFI executable. we can easily
111+
# recognize it by PE magic (vs cpio for a regular initramfs)
112+
local initrd=${image%/*}/initrd
113+
local magic
114+
[[ -s ${initrd} ]] && read -n 2 magic < "${initrd}"
115+
if [[ ${magic} == MZ ]]; then
116+
einfo "Combined UEFI kernel+initramfs executable found"
117+
# install the combined executable in place of kernel
118+
image=${initrd%/*}/uki.efi
119+
mv "${initrd}" "${image}" || die
120+
# We moved the generated initrd, prevent dracut from running again
121+
# https://github.com/dracutdevs/dracut/pull/2405
122+
shopt -s nullglob
123+
local plugins=()
124+
for file in "${EROOT}"/etc/kernel/install.d/*.install; do
125+
plugins+=( "${file}" )
126+
done
127+
for file in "${EROOT}"/usr/lib/kernel/install.d/*.install; do
128+
if ! has "${file##*/}" 50-dracut.install 51-dracut-rescue.install "${plugins[@]##*/}"; then
129+
plugins+=( "${file}" )
130+
fi
131+
done
132+
shopt -u nullglob
133+
export KERNEL_INSTALL_PLUGINS="${KERNEL_INSTALL_PLUGINS} ${plugins[@]}"
134+
fi
135+
136+
if [[ ${KERNEL_IUSE_SECUREBOOT} ]]; then
137+
# Kernel-install requires uki's are named uki.efi, sign in-place
138+
secureboot_sign_efi_file "${image}" "${image}"
139+
fi
140+
141+
ebegin "Installing the kernel via installkernel"
142+
# note: .config is taken relatively to System.map;
143+
# initrd relatively to bzImage
144+
installkernel "${version}" "${image}" "${map}"
145+
eend ${?} || die -n "Installing the kernel failed"
146+
}
147+
148+
# @FUNCTION: dist-kernel_reinstall_initramfs
149+
# @USAGE: <kv-dir> <kv-full>
150+
# @DESCRIPTION:
151+
# Rebuild and install initramfs for the specified dist-kernel.
152+
# <kv-dir> is the kernel source directory (${KV_DIR} from linux-info),
153+
# while <kv-full> is the full kernel version (${KV_FULL}).
154+
# The function will determine whether <kernel-dir> is actually
155+
# a dist-kernel, and whether initramfs was used.
156+
#
157+
# This function is to be used in pkg_postinst() of ebuilds installing
158+
# kernel modules that are included in the initramfs.
159+
dist-kernel_reinstall_initramfs() {
160+
debug-print-function ${FUNCNAME} "${@}"
161+
162+
[[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
163+
local kernel_dir=${1}
164+
local ver=${2}
165+
166+
local image_path=${kernel_dir}/$(dist-kernel_get_image_path)
167+
local initramfs_path=${image_path%/*}/initrd
168+
if [[ ! -f ${image_path} ]]; then
169+
eerror "Kernel install missing, image not found:"
170+
eerror " ${image_path}"
171+
eerror "Initramfs will not be updated. Please reinstall your kernel."
172+
return
173+
fi
174+
if [[ ! -f ${initramfs_path} && ! -f ${initramfs_path%/*}/uki.efi ]]; then
175+
einfo "No initramfs or uki found at ${image_path}"
176+
return
177+
fi
178+
179+
dist-kernel_build_initramfs "${initramfs_path}" "${ver}"
180+
dist-kernel_install_kernel "${ver}" "${image_path}" \
181+
"${kernel_dir}/System.map"
182+
}
183+
184+
# @FUNCTION: dist-kernel_PV_to_KV
185+
# @USAGE: <pv>
186+
# @DESCRIPTION:
187+
# Convert a Gentoo-style ebuild version to kernel "x.y.z[-rcN]" version.
188+
dist-kernel_PV_to_KV() {
189+
debug-print-function ${FUNCNAME} "${@}"
190+
191+
[[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments"
192+
local pv=${1}
193+
194+
local kv=${pv%%_*}
195+
[[ -z $(ver_cut 3- "${kv}") ]] && kv+=".0"
196+
[[ ${pv} == *_* ]] && kv+=-${pv#*_}
197+
echo "${kv}"
198+
}
199+
200+
_DIST_KERNEL_UTILS=1
201+
fi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
masters = portage-stable
2+
thin-manifests = true
3+
sign-commits = false
4+
sign-manifests = false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zfs-overlay
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DIST udev-init-scripts-34.tar.gz 3660 BLAKE2B 954b003c78b31649fef69213a5424098f40e17e7ed11f4ec1443247950ea60db8536f37ca603caa06e5c9f8bab07b5ac3cb8c9435144532a97ff04836c24da49 SHA512 ed48bcd0815e235b2b3fa38f857cd97f164aac7c6ea805be87890eb06a0d52064bd733da240c6e2a34c8c73e10fd047b5e53096de06f17bc81d8266d70c0cc9d
2+
DIST udev-init-scripts-35.tar.gz 3666 BLAKE2B fddae466428605ea930519e8a47e0ea91f89f9eacc1fd97c137d175142125b12c3d045aec68db35a463de444ac6d8c037cca55f9628f10576c968259d566a9e4 SHA512 da9d2093149967e2e1b9bc7190ddfd55a87c9ae2177e3216f7cb2694fc9b64037eb6f2599ad8a4b7594ef32ced88fbb319c92904bc72a81ea5404945f8a8378a
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
3+
<pkgmetadata>
4+
<maintainer type="project">
5+
<email>systemd@gentoo.org</email>
6+
</maintainer>
7+
</pkgmetadata>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 1999-2021 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=7
5+
OLD_PN=udev-gentoo-scripts
6+
OLD_P=${OLD_PN}-${PV}
7+
8+
if [ "${PV}" = "9999" ]; then
9+
EGIT_REPO_URI="git://anongit.gentoo.org/proj/${OLD_PN}.git"
10+
inherit git-r3
11+
else
12+
SRC_URI="https://gitweb.gentoo.org/proj/${OLD_PN}.git/snapshot/${OLD_P}.tar.gz -> ${P}.tar.gz"
13+
S="${WORKDIR}/${OLD_P}"
14+
KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86"
15+
fi
16+
17+
DESCRIPTION="udev startup scripts for openrc"
18+
HOMEPAGE="https://wiki.gentoo.org/wiki/No_homepage"
19+
20+
LICENSE="GPL-2"
21+
SLOT="0"
22+
23+
RESTRICT="test"
24+
25+
RDEPEND=">=virtual/udev-217
26+
!<sys-apps/openrc-0.14"
27+
28+
src_install() {
29+
local -x SYSCONFDIR="${EPREFIX}/etc"
30+
default
31+
}
32+
33+
pkg_postinst() {
34+
# Add udev and udev-trigger to the sysinit runlevel automatically.
35+
for f in udev udev-trigger; do
36+
if [[ -x "${EROOT}/etc/init.d/${f}" &&
37+
-d "${EROOT}/etc/runlevels/sysinit" &&
38+
! -L "${EROOT}/etc/runlevels/sysinit/${f}" ]]; then
39+
ln -snf "${EPREFIX}/etc/init.d/${f}" "${EROOT}/etc/runlevels/sysinit/${f}"
40+
ewarn "Adding ${f} to the sysinit runlevel"
41+
fi
42+
done
43+
44+
if ! has_version "sys-fs/eudev[rule-generator]" && \
45+
[[ -x $(type -P rc-update) ]] && rc-update show | grep udev-postmount | grep -qs 'boot\|default\|sysinit'; then
46+
ewarn "The udev-postmount service has been removed because the reasons for"
47+
ewarn "its existance have been removed upstream."
48+
ewarn "Please remove it from your runlevels."
49+
fi
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 1999-2021 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=8
5+
OLD_PN=udev-gentoo-scripts
6+
OLD_P=${OLD_PN}-${PV}
7+
8+
if [ "${PV}" = "9999" ]; then
9+
EGIT_REPO_URI="https://anongit.gentoo.org/proj/${OLD_PN}.git"
10+
inherit git-r3
11+
else
12+
SRC_URI="https://gitweb.gentoo.org/proj/${OLD_PN}.git/snapshot/${OLD_P}.tar.gz -> ${P}.tar.gz"
13+
S="${WORKDIR}/${OLD_P}"
14+
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
15+
fi
16+
17+
DESCRIPTION="udev startup scripts for openrc"
18+
HOMEPAGE="https://wiki.gentoo.org/wiki/No_homepage"
19+
20+
LICENSE="GPL-2"
21+
SLOT="0"
22+
23+
RESTRICT="test"
24+
25+
RDEPEND=">=virtual/udev-217
26+
!<sys-apps/openrc-0.14"
27+
28+
src_install() {
29+
local -x SYSCONFDIR="${EPREFIX}/etc"
30+
default
31+
}
32+
33+
pkg_postinst() {
34+
# Add udev and udev-trigger to the sysinit runlevel automatically.
35+
for f in udev udev-trigger; do
36+
if [[ -x "${EROOT}/etc/init.d/${f}" &&
37+
-d "${EROOT}/etc/runlevels/sysinit" &&
38+
! -L "${EROOT}/etc/runlevels/sysinit/${f}" ]]; then
39+
ln -snf "${EPREFIX}/etc/init.d/${f}" "${EROOT}/etc/runlevels/sysinit/${f}"
40+
ewarn "Adding ${f} to the sysinit runlevel"
41+
fi
42+
done
43+
44+
if ! has_version "sys-fs/eudev[rule-generator]" && \
45+
[[ -x $(type -P rc-update) ]] && rc-update show | grep udev-postmount | grep -qs 'boot\|default\|sysinit'; then
46+
ewarn "The udev-postmount service has been removed because the reasons for"
47+
ewarn "its existance have been removed upstream."
48+
ewarn "Please remove it from your runlevels."
49+
fi
50+
}

0 commit comments

Comments
 (0)