From 2117073e165cbe50a87d2863d393591fcf7a999f Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Feb 28 2019 19:44:28 +0000 Subject: Support akmods in rpm-ostree When running in rpm-ostree systems (like silverblue) the %post scripts run in a limited sandbox which produce a static image that will be used as-is. This causes some issues for akmods. First of all, we can't install the built kmod rpms or even modify /usr at any time past the %post script. Secondly, the sandbox puts some limits on what we can do in %post. For example we can't use any users other than root (due to /usr being a fuse mount), and /var is not available for either the rpm db or /var/cache. So, as a result, when layering akmods on rpm-ostree we build the kmod from the directly from the %post of the akmod rpm and extract it as part of the final ostree image. Note, this requires some changes to kmodtools to generate the call to akmods-ostree-post in the akmod rpm. --- diff --git a/akmods-ostree-post b/akmods-ostree-post new file mode 100644 index 0000000..ebb22dd --- /dev/null +++ b/akmods-ostree-post @@ -0,0 +1,102 @@ +#!/bin/bash - +############################################################################ +# +# akmods - Rebuilds and install akmod RPMs +# Copyright (c) 2007, 2008 Thorsten Leemhuis +# Copyright (c) 2018 Nicolas Chauvet +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +############################################################################ + +myprog="akmods-post" +tmpdir= + +# Only do %post builds in ostree +if ! grep -q OSTREE_VERSION= /etc/os-release && ! test -f /run/ostree-booted; then + exit 0 +fi + +kmodname=$1 +srpm=$2 + + +finally() +{ + # remove tmpfiles + remove_tmpdir + + exit ${1:-128} +} + +# Make sure finally() is run regardless of reason for exiting. +trap "finally" ABRT HUP INT QUIT + +create_tmpdir() +{ + if ! tmpdir="$(mktemp -d -p /tmp ${myprog}.XXXXXXXX)/" ; then + echo "ERROR: failed to create tmpdir." >&2 + finally 1 + fi + if ! mkdir "${tmpdir}"results ; then + echo "ERROR: failed to create result tmpdir." >&2 + finally 1 + fi +} + +remove_tmpdir() +{ + # remove tmpfiles + if [[ "${tmpdir}" ]] && [[ -d "${tmpdir}" ]]; then + rm -rf "${tmpdir}" + fi +} + +# This is an ostree build, so do build for all +# deployed kernels in the %post +kernels="$(ls /lib/modules)" + +create_tmpdir + +for kernel in ${kernels} ; do + echo "Building ${srpm} for kernel ${kernel}" + # Note: This builds as root, but this is pretty safe because its happening in the ostree %post sandbox. + # In fact, given that /usr is a rofiles-fuse mount no other user can access /usr in this sandbox anyway. + akmodsbuild --quiet --kernels ${kernel} --outputdir ${tmpdir}results --logfile "${tmpdir}/akmodsbuild.log" "${srpm}" 2>&1 + returncode=$? + if (( ! ${returncode} == 0 )); then + finally 1 + fi +done + +for f in $(find "${tmpdir}results" -type f -name '*.rpm' | grep -v debuginfo) ; do + rpm2cpio $f | cpio --quiet -D / -id + returncode=$? + if (( ! ${returncode} == 0 )); then + echo "Extracting $f failed:" 2>&1 + finally 1 + fi +done + +for kernel in ${kernels} ; do + depmod -v ${kernel} 2>&1 +done + +finally 0 diff --git a/akmods.spec b/akmods.spec index 50a694e..b9c6491 100644 --- a/akmods.spec +++ b/akmods.spec @@ -19,6 +19,7 @@ Source8: akmods-shutdown.service Source9: README Source10: LICENSE Source11: akmods@.service +Source12: akmods-ostree-post BuildArch: noarch @@ -93,6 +94,7 @@ mkdir -p %{buildroot}%{_usrsrc}/akmods \ install -pm 0755 %{SOURCE1} %{buildroot}%{_sbindir}/ install -pm 0755 %{SOURCE2} %{buildroot}%{_sbindir}/ +install -pm 0755 %{SOURCE12} %{buildroot}%{_sbindir}/ install -pm 0755 %{SOURCE5} %{buildroot}%{_sysconfdir}/kernel/postinst.d/ %if 0%{?fedora} || 0%{?rhel} > 6 @@ -164,6 +166,7 @@ fi %endif %{_sbindir}/akmodsbuild %{_sbindir}/akmods +%{_sbindir}/akmods-ostree-post %{_sysconfdir}/kernel/postinst.d/akmodsposttrans %if 0%{?fedora} || 0%{?rhel} > 6 %{_unitdir}/akmods.service @@ -185,7 +188,10 @@ fi %changelog -* Thu Feb 28 2019 Hans de Goede - 0.5.6-19 +* Thu Feb 28 2019 Alexander Larsson - 0.5.6-19 +- Support ostree/silverblue builds - rhbz#1667014 + +* Thu Feb 28 2019 Hans de Goede - Do not fail when the old initscripts pkg is not installed - rhbz#1680121 * Thu Jan 31 2019 Fedora Release Engineering - 0.5.6-18