File kernel-obs-build.spec of Package kernel-source.6396

# spec file for package kernel-obs-build
# Copyright (c) 2018 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via
# needsrootforbuild

#!BuildIgnore: post-build-checks

%define patchversion 3.12.61
%define variant %{nil}

%include %_sourcedir/kernel-spec-macros

Name:           kernel-obs-build
BuildRequires:  coreutils
BuildRequires:  device-mapper
BuildRequires:  util-linux

%if 0%{?suse_version}
BuildRequires:  kernel-default
%define kernel_flavor -default

%if 0%{?rhel_version}
BuildRequires:  kernel
%define kernel_flavor ""

%ifarch %ix86 x86_64
BuildRequires:  kernel-xen
ExclusiveArch:  aarch64 ppc64le s390x x86_64
%if 0%{?suse_version} < 1315
# For SLE 11 
BuildRequires:  mkinitrd
BuildRequires:  perl-Bootloader
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  dracut
Summary:        package kernel and initrd for OBS VM builds
License:        GPL-2.0
Group:          SLES
Version:        3.12.61
%if 0%{?is_kotd}
Release:        <RELEASE>.g75215ba
Release:        0

This package is repackaging already compiled kernels to make them usable
inside of Open Build Service (OBS) VM builds. An initrd with some basic
kernel modules is generated as well, but further kernel modules can be 
loaded during build when installing the kernel package.


mkdir -p /usr/lib/dracut/modules.d/80obs
cat > /usr/lib/dracut/modules.d/80obs/ <<EOF

# called by dracut
check() {
    return 0

# called by dracut
installkernel() {
    hostonly='' instmods obs

# called by dracut
install() {
    inst_hook pre-udev 10 "\$moddir"/
chmod a+rx /usr/lib/dracut/modules.d/80obs/
cat > /usr/lib/dracut/modules.d/80obs/ <<EOF
info "Loading kernel modules for OBS"
info "  Loop..."
modprobe loop max_loop=64 lbs=0 || modprobe loop max_loop=64
info "  binfmt misc..."
modprobe binfmt_misc
chmod a+rx /usr/lib/dracut/modules.d/80obs/

# a longer list to have them also available for qemu cross builds where x86_64 kernel runs in eg. arm env.
# this list of modules where available on build workers of, so we stay compatible.
export KERNEL_MODULES="loop dm-mod dm-snapshot binfmt-misc fuse kqemu squashfs ext2 ext3 ext4 reiserfs btrfs nf_conntrack_ipv6 binfmt_misc virtio_pci virtio_mmio virtio_blk virtio_rng fat vfat nls_cp437 nls_iso8859-1 ibmvscsi sd_mod"

# manually load all modules to make sure they're available
for i in $KERNEL_MODULES; do
  echo "info '  $i'"
  echo "modprobe $i"
) >> /usr/lib/dracut/modules.d/80obs/

[ -e "/dev/vda" ] && ROOT="-d /dev/vda"
[ -e /dev/hda1 ] && ROOT="-d /dev/hda1" # for xen builds
%define kernel_name vmlinu?
%ifarch s390 s390x
%define kernel_name image
%ifarch %arm
%define kernel_name zImage
%ifarch aarch64
%define kernel_name Image

%if 0%{?suse_version} && 0%{?suse_version} < 1315
# For SLE 11 
/sbin/mkinitrd $ROOT \
               -m "$KERNEL_MODULES" \
               -k /boot/%{kernel_name}-*-default -M /boot/*-default -i /tmp/initrd.kvm -B
%ifarch %ix86 x86_64
/sbin/mkinitrd $ROOT \
               -m "$KERNEL_MODULES" \
               -k /boot/vmlinuz-xen -M /boot/*-xen -i /tmp/initrd.xen
dracut --host-only --drivers="$KERNEL_MODULES" --force /tmp/initrd.kvm `echo /boot/%{kernel_name}-*%{kernel_flavor} | sed -n -e 's,[^-]*-\(.*'%{kernel_flavor}'\),\1,p'`
%ifarch %ix86 x86_64
dracut --host-only --drivers="$KERNEL_MODULES xenblk" --force /tmp/initrd.xen `echo /boot/%{kernel_name}-*-xen | sed -n -e 's,[^-]*-\(.*-xen\),\1,p'`

rm -rf /usr/lib/dracut/modules.d/80obs

install -d -m 0755 $RPM_BUILD_ROOT
cp -v /boot/%{kernel_name}-*%{kernel_flavor} $RPM_BUILD_ROOT/.build.kernel.kvm
cp -v /tmp/initrd.kvm $RPM_BUILD_ROOT/.build.initrd.kvm
%ifarch %ix86 x86_64
cp -v /boot/%{kernel_name}-*-xen $RPM_BUILD_ROOT/.build.kernel.xen
cp -v /tmp/initrd.xen $RPM_BUILD_ROOT/.build.initrd.xen

#inform worker about arch
#see obs-build commit e47399d738e51
uname -m > $RPM_BUILD_ROOT/.build.hostarch.kvm


openSUSE Build Service is sponsored by