How to compile the mainline Kernel the Manjaro way

This sounds a little bit wrong. Because the kernel you downloaded and extracted will not be used. It doesn't matter if it is there, so it is not really wrong but unnecessary.

Just create a folder, put all files form the Gitlab page in there (or just do a git clone) and edit all files you want to change. For example the PKGBUILD file if you don't want all the Manjaro patches or change the config.x86_64 if you want a diffrent config for a x86_64 Kernel. Then run updpkgsums and makepkg with the appropriate options, for example makepkg -sri
The makepkg will download, extract, patch and then build the Kernel, with the -i option also install. There is no reason for you to manually download and extract the Kernel.


Xabbu, that is where I am now. Thank you for the clarification. Things seem to go well but when I attempt to boot it says "loading initram" and nothing. Just stops there. I've had this before but I could always find the problem using make xconfig. Here, nothing seems to work. I copied and pasted into the CONFIG file my working .config. I will have to try again tomorrow.

I don't think you can use a straight debian "working" config in a Manjaro kernel. Unless your system didn't boot with the Manjaro liveUSB, try just building a standard Manjaro kernel first. You need validate your build environment. There are a few details that need to be right and hardly anybody remembers all of them once their system has been building kernels for awhile!

Once you can build a working standard kernel, then you can start experimenting.

I think that's what I was using. The .config is what I created using make xconfig. Otherwise, it was all Manjaro. :frowning:

Humor me. Start with the stock Manjaro config (no modifications). Build a standard Manjaro kernel and see if it boots. I seem to recall that you have a fast AMD with a ton of cores. It should take under 10-15 minutes. Once that works, then you'll only have to worry about your config edits (or your patches) if your modified kernel doesn't boot.

1 Like

Yes exactly. Small steps in the beginning, don't change too much at once.

Here's a simple (and simplified) procedure if you want to start rolling your own kernels, including git for version control:

  1. git clone an existing kernel, in this example let's use Manjaro 4.17:
    git clone

  2. before you start to do anything, create a local git branch for your development:
    cd linux417
    git checkout -b development (replace development with any name you like)

  3. [optional] give your kernel a different name so it can be easily installed alongside existing ones.
    For that, you have to replace every instance of -MANJARO with a name of your choice, this in every file, not only in PKGBUILD!
    You could use a simple 'find and replace' in your text editor, or use the sed command, e.g. sed -i -e "s|-MANJARO|-CUSTOM|" PKGBUILD.
    You also have to edit various other names, like

pkgname=('linux417' 'linux417-headers')

should become

pkgname=('linux417-custom' 'linux417-headers-custom')

You also have to adapt the package() functions accordingly. Check again if you really got everything, it's quite important.

  1. Now you can edit PKGBUILD, insert patches, remove the comment before one of the make *config lines to launch the configuration.

  2. run updpkgsums

  3. Then you can try launching makepkg. In kernel config, don't forget to save your config.
    Copy over your config from the build directory (e.g. /tmp/makepkg) to your git folder and name it something like config.custom. We will add that config later to the PKGBUILD

  4. When the build process finishes, you will have a kernel and a header package, ideally with your custom name. Install with pacman -U, reboot and if it works, continue to next step

  5. Edit your PKGBUILD again, this time replace the default config with the one you saved previously. Don't forget to run updpkgsums again.

  6. Now you can add the modified/added files to your git branch. First check status with git status, then add modified files with git add [Note: you can also do this before the build].
    Once done, commit your changes with git commit.

  7. For any extramodules, the procedure is more or less the same. Again, don't forget to change the names in the files if you use a custom one, for example extramodules-4.17-MANJARO becomes extramodules-4.17-CUSTOM etc.

  8. Since we used git, we can always switch back to original Manjaro with git checkout master, and you can update that branch easily with git pull. You can even go further and merge a new updated Manjaro branch into your own with git merge, but that's out of scope and doesn't always work without intervention.


I did what you said last night. Same results. I regressed a bit and it won't load the init ram step. Let me redo this process using Torvic's easy step-by-step process and I'll see if that works!

I'm trying the kernel re-name instructions. They got me started. There were a couple more minor details, but I'm building as I type. I know the standard mainline 4.16 runs on my target system, but I hadn't built it in Manjaro before. I didn't want to disturb my working kernel projects (4.14, 4.17), so a different kernel seemed best to test.

Update: Everything looked good until I tried to actually boot 4.16.18-T100MJ. I got "Kernel panic - not syncing: VFS: unable to mount fs on unknown-block(0,0)". Re-checking things now... Freshly installed Manjaro 4.9.111 works as expected except for backlight control. Customized (not renamed) 4.14 and 4.17 also work properly.

My case is a known good build environment, a clean copy of linux416 (32 bit kernel) with only a kernel name change attempted. I must have missed something.

Edit 2: I was able to build & boot a plain 4.16.18 without changing the kernel name. So I know the project files, the config and the build environment are OK...

When the build process finishes, you will have a kernel and a header package, ideally with your custom name. Install with pacman -U, reboot and if it works, continue to next step

This part did not work. I had been using makepkg -sri. Two things I don't know how to do:

  1. clean the build- like, just from the parts that compiled to binary. Clean build directory but don't erase config.
  2. Installing from the .xz packages.

I'm sorry to report, it did not work. :frowning: It crashes hard at loading initial ramdisk. I am using the ramdisk settings that I always use though. I have a known working config too. It is very unhappy about something. :wink: Maybe I ought to go back to 4.16.x and see if that works?

If you look in the filesystem under /tmp you should see /makepkg/ Under there you should find your project working directory
open a terminal down there (linux-4.17) and you can use some of the standard kernel .org build commands like
make clean
you can go back to the linux417 directory and use terminal to rebuild with
makepkg -ef
To install the .xz packages use
sudo pacman -U linux417*.xz

Finally, I got the name changed kernel to boot. I had to change all the things in the instructions, plus add [-custom] name to the files linux416.preset and linux416.install. I also had to edit PKGBUILD where it invokes mkinitcpio to add [-custom] to linux416. Since linux416 works pretty well, I'll look at adding my patches and changing .config tomorrow.

My final "stock" linux416 PKGBUILD with name change "T100MJ" and pseudo custom .config follows

# Based on the file created for Arch Linux by:
# Tobias Powalowski <>
# Thomas Baechler <>

# Maintainer: Philip Müller <>
# Maintainer: Guinux <>
# Maintainer: Rob McCathie <>

pkgname=('linux416-T100MJ' 'linux416-headers-T100MJ')
arch=('i686' 'x86_64')
makedepends=('xmlto' 'docbook-xsl' 'kmod' 'inetutils' 'bc' 'elfutils' 'git')
        # the main kernel config files
        'config.x86_64' 'config-T100MJ' 'config.aufs'
        "${pkgbase}.preset" # standard config files for mkinitcpio ramdisk
        '60-linux.hook'     # pacman hook for depmod
        '90-linux.hook'     # pacman hook for initramfs regeneration
        # ARCH Patches
        # MANJARO Patches
        # Bootsplash
prepare() {
  #mv "${srcdir}/linux-${_git}" "${srcdir}/linux-${_basekernel}"
  #mv "${srcdir}/linux-${_basekernel}-${_rc}" "${srcdir}/linux-${_basekernel}"
  cd "${srcdir}/linux-${_basekernel}"

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

  # add latest fixes from stable queue, if needed
  # enable only if you have "" executed before
  #patch -Np1 -i "${srcdir}/prepatch-${_basekernel}`date +%Y%m%d`"

  # disable USER_NS for non-root users by default
  patch -Np1 -i ../0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch

  # Nvidia driver
  patch -Np1 -i ../0002-Partially-revert-swiotlb-remove-various-exports.patch

  patch -Np1 -i ../0001-drm-i915-edp-Only-use-the-alternate-fixed-mode-if-it.patch

  patch -Np1 -i ../0002-Bluetooth-btusb-Apply-QCQ_ROME-setup-for-BTUSB_ATH30.patch

  # iwlwifi: add killer cards for 9000 series
  patch -Np1 -i "${srcdir}/0001-iwlwifi-killer-ac-1550.patch"

  # Add bootsplash -
  patch -Np1 -i "${srcdir}/0001-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0002-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0003-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0004-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0005-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0006-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0007-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0008-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0009-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0010-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0011-bootsplash.patch"
  patch -Np1 -i "${srcdir}/0012-bootsplash.patch"
  # use git-apply to add binary files
  git apply -p1 < "${srcdir}/0013-bootsplash.patch"

  # add aufs4 support
  patch -Np1 -i "${srcdir}/aufs4.16-${_aufs}.patch"
  patch -Np1 -i "${srcdir}/aufs4-base.patch"
  patch -Np1 -i "${srcdir}/aufs4-kbuild.patch"
  patch -Np1 -i "${srcdir}/aufs4-loopback.patch"
  patch -Np1 -i "${srcdir}/aufs4-mmap.patch"
  patch -Np1 -i "${srcdir}/aufs4-standalone.patch"
  patch -Np1 -i "${srcdir}/tmpfs-idr.patch"
  patch -Np1 -i "${srcdir}/vfs-ino.patch"

  # add BFQ scheduler
  msg "Fix naming schema in BFQ-MQ patch"
  sed -i -e "s|SUBLEVEL = 0|SUBLEVEL = ${_sub}|g" \
  patch -Np1 -i "${srcdir}/0001-BFQ-${_bfq}-${_bfqdate}.patch"

  if [ "${CARCH}" = "x86_64" ]; then
    cat "${srcdir}/config.x86_64" > ./.config
    cat "${srcdir}/config-T100MJ" > ./.config

  # cat "${srcdir}/config.aufs" >> ./.config

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

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

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

  # 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

  # rewrite configuration
  yes "" | make config >/dev/null

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

  # build!
  make ${MAKEFLAGS} LOCALVERSION= bzImage modules

package_linux416-T100MJ() {
  pkgdesc="The ${pkgbase/linux/Linux} kernel and modules"
  depends=('coreutils' 'linux-firmware' 'kmod' 'mkinitcpio>=0.7')
  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" modules_install
  cp arch/$KARCH/boot/bzImage "${pkgdir}/boot/vmlinuz-${_basekernel}-${CARCH}"

  # add kernel version
  if [ "${CARCH}" = "x86_64" ]; then
     echo "${pkgver}-${pkgrel}-T100MJ x64" > "${pkgdir}/boot/${pkgbase}-${CARCH}.kver"
     echo "${pkgver}-${pkgrel}-T100MJ x32" > "${pkgdir}/boot/${pkgbase}-${CARCH}.kver"

  # make room for external modules
  local _extramodules="extramodules-${_basekernel}${_kernelname:--T100MJ}"
  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 "${_kernver}"

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

  # sed expression for following substitutions
  local _subst="

  # hack to allow specifying an initially nonexisting install file
  sed "${_subst}" "${startdir}/${install}" > "${startdir}/${install}.pkg"
  true && install=${install}.pkg

  # install mkinitcpio preset file
  sed "${_subst}" ${srcdir}/linux416-T100MJ.preset |
    install -Dm644 /dev/stdin "${pkgdir}/etc/mkinitcpio.d/${pkgbase}.preset"

  # install pacman hooks
  sed "${_subst}" ${srcdir}/60-linux.hook |
    install -Dm644 /dev/stdin "${pkgdir}/usr/share/libalpm/hooks/60-${pkgbase}.hook"
  sed "${_subst}" ${srcdir}/90-linux.hook |
    install -Dm644 /dev/stdin "${pkgdir}/usr/share/libalpm/hooks/90-${pkgbase}.hook"

package_linux416-headers-T100MJ() {
  pkgdesc="Header files and scripts for building modules for ${pkgbase/linux/Linux} kernel"

  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"

  if [ "${CARCH}" = "i686" ]; then
    install -Dt "${_builddir}/arch/${KARCH}" -m644 "arch/${KARCH}/Makefile_32.cpu"

  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

  install -Dt "${_builddir}/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h

  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}/{}" \;

  if [ "${CARCH}" = "x86_64" ]; then
    # 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)

So the above instructions were incomplete? Do we have a -complete- guide that works and is verifiable?

Only a couple of details were missing for changing the kernel name and there were warnings posted in the instructions. Like I said before, no one remembers all the details of setting up the build environment. If you search my PKGBUILD for T100MJ, you can see all the places I had to make edits. torvic got most of them. Anyway, this is one of the more complete guides I've seen. All I would add is a list of build tools. The problem with many Linux guides is that they are obsolete within a few weeks...

If you can't boot an unmodified kernel that you've built, then we need to debug the build environment. I'm guessing that you've got the needed build tools or you would not be able to finish the makepkg. So it might be worth looking at your /etc/makepkg.conf. I'm not an expert, but I have built unmodified bootable kernels. If you post your makepkg.conf, I can compare yours against mine.

This could take a while, we seem to be in different timezones and it's getting late here.

1 Like

It's taking a while because I have to work and I'm remodeling the house. I'm fine with our timeframe here, thank you. I'm trying to debug the whole thing now. There was an update from Manjaro for the 4.17 Kernel but guess what? It too didn't boot! I think the stupid Nvidia drivers are fouling it up. I'm going to try to switch to AMD as soon as I can because their GPU driver is open source. I think that could save me a lot of headaches.

1 Like

Yeah, if the standard kernel won't boot, I wouldn't expect a home built kernel to boot either - unless you added a patch to fix the standard kernel. :smirk:

The Manjaro 4.17 gets pretty far. It almost boots to the desktop but just stops. I'm almost sure that's stupid Nvidia.

That seems like a reasonable conclusion. Maybe at the grub menu, remove splash and add 3 to the end of the kernel arguments. That should take you to a tty login instead of the GUI desktop. You could also adjust the _sub in the PKGBUILD to the last known 4.17.x that did boot. But the problem could be a graphic driver update, not the kernel...

1 Like

Update: From the command line I could add the Nvidia driver, get online, remove the driver, etc. I think from here I could begin again to test out the mainline Kernel. I'll report later when I get something working but that may be a day or two.

Yes, the 4.17.x Kernel from Manjaro didn't have network support on my system. I couldn't believe it either. It's fine, the 4.16.x Kernel is now working, network working, and Nvidia driver working. I can refocus again on compiling the Kernel.

Forum kindly sponsored by