Unable to build a patched kernel and make it available on grub side to side with the unpatched one

In an effort to enable audio on a 2-in-1, I am trying to apply patches I’ve received to the Manjaro 5.12 kernel and build linux512-custom and linux512-custom-headers from that.

I am trying to follow the instructions in: How to compile the mainline Kernel the Manjaro way - Newbie Corner - Manjaro Linux Forum and particularly in

but I am utterly confused about the naming of things. I can build my packages and install them with pacman -U. However, at this point the standard 512 kernel and mine appear to be both installed, but they are not both available. In grub I see only a single 512 kernel named as the standard one, but that in fact from /proc/version appears to be my custom kernel… so where is the standard 512 and why my kernel does not get the -custom name?

Can you elaborate a bit on what you’re doing exactly as you’re asking us where you went wrong but you’re not providing the exact steps you did…

:thinking:

Sure, here it is:

  1. I have clone an existing kernel, that is Manjaro 5.12.8 git clone https://gitlab.manjaro.org/packages/core/linux512.git and created a local branch to do development in.
  2. I have given (in fact tried to give) the kernel a different name. Specifically, I have replace every instance of -MANJARO with -CUSTOM in PKGBUILD. Furthermore, I have edited pkgbase and pkgname into
pkgbase=linux512-cll
pkgname=('linux512-cll' 'linux512-cll-headers-')
  1. I have introduced a couple extra patches, taken from Add GLK/Chuwi Hi10x support by plbossart · Pull Request #2962 · thesofproject/linux · GitHub where work is ongoing to support audio on a tablet. I am in a bit of trouble here, because the developers have a testing tree and flow that expect a debian/ubuntu target, and I have manjaro right now on it (since a rolling distro provides a better DE experience on a tablet). For this reasons I had to adapt the patches a bit, but they seem reasonable and I have checked that they do apply cleanly.

  2. I have wondered whether I had to remove linux and linux-headers from the provides arrays of the packages expected to be built in PKGBUILD. All the \arch linux guides say that this is to be done for custom kernels, but I see no mention of it on the Manjaro forum. In the end I have not removed them.

  3. I have run updpkgsums

  4. I have built the kernel and headers packages using makepkg -s. Compilation and packages ended nicely (there was in fact a single warning from the headers packages saying that $srcdir was mentioned in the package or something like that… did not seem critical.

  5. I have copied over the two packages to the target device and installed them there with pacman -U. They installed cleanly.

  6. I have booted the target device and it boots.

However, the boot dir is a mess and the grub menus too…

I was expecting to find a vmlinuz-5.12-cll-x86_64 side to side with the standard vmlinuz-5.12-x86_64, an initramfs-5.12-cll-x86_64 side to side with the standard initramfs-5.12-x86_64 and a linux512-cll-x86_64.kver side to side with the standard linux512-cll-x86_64.kver. Furthermore, I was expecting grub to offer me the option to boot either linux512 or linux512-cll.

Conversely: i do not see any vmlinuz-5.12-cll-x86_64 or initramfs-5.12-cll-x86_64 (even if I do see linux512-cll-x86_64.kver. The vmlinuz-5.12-x86_64 is not anymore the kernel in the standard linux512 package (even if that appears to be installed alongside mine). In fact, it appears that my kernel has overwritten it. Similarly, initramfs-5.12-x86_64 is not anymore the initram corresponding to the standard kernel, as mine seems to have overwritten it. Finally, grub only offers me a single linux512 kernel.

So I have the following questions:

  • What should I do to make a linux512-cll and a linux512-cll-headers packages that can get installed in parallel with the standard linux512 and linux512-headers packages with the option to boot either linux512 or linux512-cll?

  • What should I have to do and how should I name things the day I’ll need to make a kernel (and kernel-headers package based on the kernel tree from https://github.com/plbossart/sound/tree/fix/glk-chuwi-Hi10x rather than using the Manjaro 512 kernel as a base?

  • How about the provides arrays mentioned at point 4? Is there any action required on them?

  • Is there anything like Debian Linux Kernel Handbook for Manjaro? Or even a much more synthetic wiki page. Instructions for kernel packaging on the forum, notwithstanding the excellent quality of some answers, tend to be a bit dispersive since every answer focuses just on the specific question being asked (so that bits must be collected from multiple answers) and actual instructions get interleaved with other comments and questions that are not always to the point…

@philm I would normally have called in CSCS or Linux-aarhus but as they’re on hiatus, do you know who to call in? (I’ve only ever compiled a kernel once and that was back on Ubuntu and didn’t have any of these problems)

:scream:

You’ll have to fix this line as well:

echo "${_basekernel}-${CARCH}" ...echo "${_basekernel}-cll-${CARCH}" ...

It shouldn’t harm. You can have multiple packages installed that have the same items in the provides list.

Here a working PKGBUILD file for an additional kernel “CUSTOM”

linux512-cus
# linux512-CUSTOM kernel

pkgbase=linux512-cus
pkgname=('linux512-cus' 'linux512-cus-headers')
_kernelname=-CUSTOM
_basekernel=5.12
_basever=512
pkgver=5.12.9
pkgrel=1
arch=('x86_64')
url="http://www.kernel.org/"
license=('GPL2')
makedepends=('bc'
    'docbook-xsl'
    'elfutils'
    'git'
    'inetutils'
    'kmod'
    'xmlto'
    'cpio'
    'perl'
    'tar'
    'xz')
options=('!strip')
source=("https://www.kernel.org/pub/linux/kernel/v5.x/linux-${_basekernel}.tar.xz"
        "https://www.kernel.org/pub/linux/kernel/v5.x/patch-${pkgver}.xz"
        # the main kernel config files
        'config' 'config.anbox'
        # ARCH Patches
        '0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-CLONE_NEWUSER.patch'
        '0002-HID-quirks-Add-Apple-Magic-Trackpad-2-to-hid_have_special_driver-list.patch'
        '0003-revert-bus-mhi-core-Process-execution-environment-changes-serially.patch'
        # Temp Fixes
        # CUSTOM Patches
        '0101-i2c-nuvoton-nc677x-hwmon-driver.patch'
        '0102-iomap-iomap_bmap-should-accept-unwritten-maps.patch'
        '0103-futex.patch'
        '0104-revert-xhci-Add-support-for-Renesas-controller-with-memory.patch'
        '0107-quirk-kernel-org-bug-210681-firmware_rome_error.patch'
        # Lenovo + AMD
        '0302-lenovo-wmi2.patch'
        # other patches
        # Bootsplash
        '0401-revert-fbcon-remove-now-unusued-softback_lines-cursor-argument.patch'        
        '0402-revert-fbcon-remove-no-op-fbcon_set_origin.patch'
        '0403-revert-fbcon-remove-soft-scrollback-code.patch'
        '0501-bootsplash.patch'
        '0502-bootsplash.patch'
        '0503-bootsplash.patch'
        '0504-bootsplash.patch'
        '0505-bootsplash.patch'
        '0506-bootsplash.patch'
        '0507-bootsplash.patch'
        '0508-bootsplash.patch'
        '0509-bootsplash.patch'
        '0510-bootsplash.patch'
        '0511-bootsplash.patch'
        '0512-bootsplash.patch'
        '0513-bootsplash.gitpatch'
        )
sha256sums=('7d0df6f2bf2384d68d0bd8e1fe3e071d64364dcdc6002e7b5c87c92d48fac366'
            'b844ec7be25f915578e322838b03c2780c4b1185fbab5e84a8d52db7341804e8'
            '9f34dda90e87fd953a5db34b59866cf1d65a6f8f9b0ed83728d03b7ab7419778'
            'fc896e5b00fad732d937bfb7b0db41922ecdb3a488bc1c1b91b201e028eed866'
            '986f8d802f37b72a54256f0ab84da83cb229388d58c0b6750f7c770818a18421'
            'df5843818f1571841e1a8bdbe38d7f853d841f38de46d6a6a5765de089495578'
            'a237fbb5fe40b93163e99528cfb62312f2f2c33d5f97a8d9c0a1b074b5c9df42'
            '7823d7488f42bc4ed7dfae6d1014dbde679d8b862c9a3697a39ba0dae5918978'
            '95745075edd597caa92b369cfbcd11a04c9e3c88c0c987c70114924e1e01df5c'
            'b302ba6c5bbe8ed19b20207505d513208fae1e678cf4d8e7ac0b154e5fe3f456'
            '83b5684223309809393bdffc5122924cb9940403d682a887b0aa6524015df973'
            '5e804e1f241ce542f3f0e83d274ede6aa4b0539e510fb9376f8106e8732ce69b'
            '1d58ef2991c625f6f0eb33b4cb8303932f53f1c4694e42bae24c9cd36d2ad013'
            '2b11905b63b05b25807dd64757c779da74dd4c37e36d3f7a46485b1ee5a9d326'
            '94a8538251ad148f1025cc3de446ce64f73dc32b01815426fb159c722e8fa5bc'
            '1f18c5c10a3c63e41ecd05ad34cd9f6653ba96e9f1049ce2b7bb6da2578ae710'
            '59202940d4f12bad23c194a530edc900e066866c9945e39748484a6545af96de'
            'e096b127a5208f56d368d2cb938933454d7200d70c86b763aa22c38e0ddb8717'
            '8c1c880f2caa9c7ae43281a35410203887ea8eae750fe8d360d0c8bf80fcc6e0'
            '1144d51e5eb980fceeec16004f3645ed04a60fac9e0c7cf88a15c5c1e7a4b89e'
            'dd4b69def2efacf4a6c442202ad5cb93d492c03886d7c61de87696e5a83e2846'
            '028b07f0c954f70ca37237b62e04103e81f7c658bb8bd65d7d3c2ace301297dc'
            'a0c548c5703d25ae34b57931f1162de8b18937e676e5791a0f039922090881e7'
            '8dbb5ab3cb99e48d97d4e2f2e3df5d0de66f3721b4f7fd94a708089f53245c77'
            'a7aefeacf22c600fafd9e040a985a913643095db7272c296b77a0a651c6a140a'
            'e9f22cbb542591087d2d66dc6dc912b1434330ba3cd13d2df741d869a2c31e89'
            '27471eee564ca3149dd271b0817719b5565a9594dc4d884fe3dc51a5f03832bc'
            '60e295601e4fb33d9bf65f198c54c7eb07c0d1e91e2ad1e0dd6cd6e142cb266d'
            '035ea4b2a7621054f4560471f45336b981538a40172d8f17285910d4e0e0b3ef')


prepare() {
  cd "${srcdir}/linux-${_basekernel}"

  # add upstream patch
  msg "add upstream patch"
  patch -p1 -i "${srcdir}/patch-${pkgver}"

  local src
  for src in "${source[@]}"; do
      src="${src%%::*}"
      src="${src##*/}"
      [[ $src = *.patch ]] || continue
      msg2 "Applying patch: $src..."
      patch -Np1 < "../$src"
  done

  msg2 "0513-bootsplash"
  git apply -p1 < "${srcdir}/0513-bootsplash.gitpatch"  

  msg2 "add config.anbox to config"
  cat "${srcdir}/config" > ./.config
  cat "${srcdir}/config.anbox" >> ./.config

  if [ "${_kernelname}" != "" ]; then
    sed -i "s|CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"${_kernelname}\"|g" ./.config
    sed -i "s|CONFIG_LOCALVERSION_AUTO=.*|CONFIG_LOCALVERSION_AUTO=n|" ./.config
  fi

  msg "set extraversion to pkgrel"
  sed -ri "s|^(EXTRAVERSION =).*|\1 -${pkgrel}|" Makefile

  msg "don't run depmod on 'make install'"
  # We'll do this ourselves in packaging
  sed -i '2iexit 0' scripts/depmod.sh

  msg "get kernel version"
  make prepare

  # load configuration
  # Configure the kernel. Replace the line below with one of your choice.
  #make menuconfig # CLI menu for configuration
  #make nconfig # new CLI menu for configuration
  #make xconfig # X-based configuration
  #make oldconfig # using old config from previous kernel version
  # ... or manually edit .config

  msg "rewrite configuration"
  yes "" | make config >/dev/null
}

build() {
  cd "${srcdir}/linux-${_basekernel}"

  msg "build"
  make ${MAKEFLAGS} LOCALVERSION= bzImage modules
}

package_linux512-cus() {
  pkgdesc="The ${pkgbase/linux/Linux} kernel and modules"
  depends=('coreutils' 'linux-firmware' 'kmod' 'mkinitcpio>=27')
  optdepends=('crda: to set the correct wireless channels of your country')
  provides=("linux=${pkgver}" VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE)

  cd "${srcdir}/linux-${_basekernel}"

  KARCH=x86

  # get kernel version
  _kernver="$(make LOCALVERSION= kernelrelease)"

  mkdir -p "${pkgdir}"/{boot,usr/lib/modules}
  make LOCALVERSION= INSTALL_MOD_PATH="${pkgdir}/usr" INSTALL_MOD_STRIP=1 modules_install

  # systemd expects to find the kernel here to allow hibernation
  # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
  cp arch/$KARCH/boot/bzImage "${pkgdir}/usr/lib/modules/${_kernver}/vmlinuz"

  # Used by mkinitcpio to name the kernel
  echo "${pkgbase}" | install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modules/${_kernver}/pkgbase"
  echo "${_basekernel}-cus-${CARCH}" | install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modules/${_kernver}/kernelbase"

  # add kernel version
  echo "${pkgver}-${pkgrel}-CUSTOM x64" > "${pkgdir}/boot/${pkgbase}-${CARCH}.kver"

  # make room for external modules
  local _extramodules="extramodules-${_basekernel}${_kernelname:--CUSTOM}"
  ln -s "../${_extramodules}" "${pkgdir}/usr/lib/modules/${_kernver}/extramodules"

  # add real version for building modules and running depmod from hook
  echo "${_kernver}" |
    install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modules/${_extramodules}/version"

  # remove build and source links
  rm "${pkgdir}"/usr/lib/modules/${_kernver}/{source,build}

  # now we call depmod...
  depmod -b "${pkgdir}/usr" -F System.map "${_kernver}"

  # add vmlinux
  install -Dt "${pkgdir}/usr/lib/modules/${_kernver}/build" -m644 vmlinux
}

package_linux512-cus-headers() {
  pkgdesc="Header files and scripts for building modules for ${pkgbase/linux/Linux} kernel"
  depends=('gawk' 'python' 'libelf')
  provides=("linux-headers=$pkgver")

  cd "${srcdir}/linux-${_basekernel}"
  local _builddir="${pkgdir}/usr/lib/modules/${_kernver}/build"

  install -Dt "${_builddir}" -m644 Makefile .config Module.symvers
  install -Dt "${_builddir}/kernel" -m644 kernel/Makefile

  mkdir "${_builddir}/.tmp_versions"

  cp -t "${_builddir}" -a include scripts

  install -Dt "${_builddir}/arch/${KARCH}" -m644 "arch/${KARCH}/Makefile"
  install -Dt "${_builddir}/arch/${KARCH}/kernel" -m644 "arch/${KARCH}/kernel/asm-offsets.s"
  #install -Dt "${_builddir}/arch/${KARCH}/kernel" -m644 "arch/${KARCH}/kernel/macros.s"

  cp -t "${_builddir}/arch/${KARCH}" -a "arch/${KARCH}/include"

  install -Dt "${_builddir}/drivers/md" -m644 drivers/md/*.h
  install -Dt "${_builddir}/net/mac80211" -m644 net/mac80211/*.h

  # http://bugs.archlinux.org/task/13146
  install -Dt "${_builddir}/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h

  # http://bugs.archlinux.org/task/20402
  install -Dt "${_builddir}/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
  install -Dt "${_builddir}/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
  install -Dt "${_builddir}/drivers/media/tuners" -m644 drivers/media/tuners/*.h

  # add xfs and shmem for aufs building
  mkdir -p "${_builddir}"/{fs/xfs,mm}

  # copy in Kconfig files
  find . -name Kconfig\* -exec install -Dm644 {} "${_builddir}/{}" \;

  # add objtool for external module building and enabled VALIDATION_STACK option
  install -Dt "${_builddir}/tools/objtool" tools/objtool/objtool

  # remove unneeded architectures
  local _arch
  for _arch in "${_builddir}"/arch/*/; do
    [[ ${_arch} == */x86/ ]] && continue
    rm -r "${_arch}"
  done

  # remove files already in linux-docs package
  rm -r "${_builddir}/Documentation"

  # Fix permissions
  chmod -R u=rwX,go=rX "${_builddir}"

  # strip scripts directory
  local _binary _strip
  while read -rd '' _binary; do
    case "$(file -bi "${_binary}")" in
      *application/x-sharedlib*)  _strip="${STRIP_SHARED}"   ;; # Libraries (.so)
      *application/x-archive*)    _strip="${STRIP_STATIC}"   ;; # Libraries (.a)
      *application/x-executable*) _strip="${STRIP_BINARIES}" ;; # Binaries
      *) continue ;;
    esac
    /usr/bin/strip ${_strip} "${_binary}"
  done < <(find "${_builddir}/scripts" -type f -perm -u+w -print0 2>/dev/null)
}
1 Like