Dynamically detect and install the correct headers for the currently active kernel

I’ve been testing a new project called Linksy (an alternative to KDE Connect), and I’m trying to help the developer fix their camera setup script so it works out of the box for Manjaro users.

The app uses v4l2loopback-dkms to use a mobile phone as a webcam. Right now, their setup script simply runs:pacman -S linux-headers

On vanilla Arch, this works fine. But on Manjaro, because we support multiple side-by-side kernels, this generic package often just defaults to the first provider or an LTS header package (like linux618-headers). As a result, DKMS fails to build the .ko module for the currently running kernel.

I am currently running the Linux 7.3 kernel on the Unstable branch. My questions are:

  1. Is the header package strictly named linux73-headers for the 7.3 series?
    I think I remember it being installed when I ran sudo mhwd-kernel -i linux73, but haven’t seen it in updates since then.

  2. What is the cleanest, most Manjaro-approved bash command to dynamically detect and install the correct headers for the currently active kernel (uname -r)?

I want to pass this information directly back to the Linksy dev so they can patch their script. That way, the “Mobile as Camera” feature will just work automatically for Manjaro and multi-kernel Arch users without requiring manual pacman intervention.


More info : (only visible to forum members)

https://forum.manjaro.org/t/meet-linksy-a-kde-connect-alternative-with-more-features/190769

Yes

$ mbn info linux73-headers -q
Branch         : unstable
Name           : linux73-headers
Version        : 7.3.0-1
Repository     : core
Build Date     : Mon 19 Oct 2026 06:46:15 
Packager       : Manjaro Build Server <build@manjaro.org>
Branch         : testing
Name           : linux73-headers
Version        : 7.3.0rc6-1
Repository     : core
Build Date     : Mon 05 Oct 2026 01:15:36 
Packager       : Manjaro Build Server <build@manjaro.org>
Branch         : stable
Name           : linux73-headers
Version        : 7.3.0rc6-1
Repository     : core
Build Date     : Mon 05 Oct 2026 01:15:36 
Packager       : Manjaro Build Server <build@manjaro.org>
sudo pacman -S linux73-headers

or

pamac install linux73-headers

Thanks.

sudo pacman -S linux73-headers Automatically installed v4l2loopback/0.15.4
And I messaged the dev about this, so hopefully they update their script and it works on manjaro out-of-the-box.


I don’t understand one thing though. when I installed sudo mhwd-kernel -i linux73, why wasn’t the linux73-headers automatically installed as like a dependency?
Do I need to make sure to install respective headers manually when I install new kernel?

I have never had a problem with mhwd-kernel automatically installing the relevant linux*-headers package with a new kernel, but I have never used a DKMS kernel module

Archwiki - Dynamic Kernel Module Support - Upgrades

Though the rebuild of the DKMS modules is usually seamless during a kernel upgrade, it may still happen that the rebuild fails. You should pay extra attention to the pacman output. This applies in particular if the system relies on the DKMS module to boot successfully and/or if you use DKMS with a custom kernel not in the official repositories.

The headers are in theory optional. I guess if one only sticks to the repo not needed. Me personally i always install them explicit. If you have them on the current kernel and install a new one they are pulled automatically for the new kernel too. At least with mhwd, no idea if pacman does it.

I guess they have to be hard dependency for dkms, but i am on the phone and cannot check.

The best approach would be to check if installed. pull the kernel version with uname, clean the output with awk sed grep whatever and put it in variable and theck if linux$(ver)-headers is installed.

That explains it why I only had linux618-headers, this system started with linux 6.12 series, so maybe the Manjaro Settings manager (the GUI app) installed the headers for 6.18, and maybe evcn the linux 7.0/7.1 series kernels…
But then I started using terminal way to install kernels from linux 7.2 - 7.3 series, and since then I have not seen those respective headers being updated, probably not installed in the first place.

That would be confirmed by checking if linux72-headers is on my system (as I still have linux618 linux72 and linux73 installed), If they are then it was installed by the sudo mhwd-kernel -i linux72, if they aren’t then system was using linux618-headers since I removed linux612.


So does that mean I have linux71-headers still on my system because I just did sudo mhwd-kernel -r linux71.

ArchLinux Developer Manual - DKMS package guidelines - Dependencies

Do not include linux-headers – or any other Linux header package – to the PKGBUILD. These headers are already listed as optional dependencies of dkms and each kernel package has its own header package, so including header package dependency in the -dkms package is both unnecessarily redundant and restricting.

$ pamac info dkms
Name                  : dkms
Version               : 3.4.4-1
Description           : Dynamic Kernel Modules System
URL                   : https://github.com/dkms-project/dkms
Licences              : GPL-2.0-or-later
Repository            : extra
Installed Size        : 171.2 kB
Groups                : --
Depends On            : bash coreutils gawk gcc kmod make patch sed
Optional Dependencies : linux-headers: build modules against the kernel [Installed]
Provides              : --
Replaces              : --
Conflicts With        : --
Packager              : Mark Wagie <mark@manjaro.org>
Build Date            : Wed 07 Oct 2026 15:01:24 BST
Validated By          : MD5 Sum  SHA-256 Sum  Signature

mhwd-kernel -r will also remove the matching header (just tested it)

To check whether it’s already installed and to install it if necessary, you can follow a similar approach to the one used by mhwd-kernel.

#! /bin/bash
IFS=. read -r major minor _ <<< "$(uname -r)"
current="linux$major$minor"
[[ -z $(pacman -Qs "($current)-headers") ]] && echo "sudo pacman -S  '($current)-headers'"

(without the echo :wink:)