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…


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
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)


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-CUSTOM kernel

pkgname=('linux512-cus' 'linux512-cus-headers')
        # the main kernel config files
        'config' 'config.anbox'
        # ARCH Patches
        # Temp Fixes
        # CUSTOM Patches
        # Lenovo + AMD
        # other patches
        # Bootsplash

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 = *.patch ]] || continue
      msg2 "Applying patch: $src..."
      patch -Np1 < "../$src"

  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

  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')

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


  # 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')

  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}"

  # 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 ;;
    /usr/bin/strip ${_strip} "${_binary}"
  done < <(find "${_builddir}/scripts" -type f -perm -u+w -print0 2>/dev/null)
1 Like