This quick guide would help you to fix the “VirtualBox Kernel Headers Not Found” error.
Reason for the error
The primary reason is the difference in Kernel versions between the guest and the host system.
For example, if your host system has Linux Kernel 5.19 for example and you are installing any distribution with a different version, say 5.14, then you may run into this error while running the setup script for the virtual box guest additions.
The VirtualBox guest addition set-up requires the necessary Kernel modules to be built inside the guest system. Then it checks whether the Kernel modules match; otherwise, it throws this error.
Fix the Kernel Headers Not found error in VirtualBox
To solve this, open a terminal inside the guest system.
And install the necessary Kernel packages as mentioned below.
sudo dnf install kernel-headers kernel-devel
And then reboot.
After reboot, try to re-run the VirtualBox guest addition installation script. And the error should be fixed.
If not, drop a note below.
Note: Although its mentioned that only for Fedora and related distros. But the same applies to Ubuntu and related distros as well. The idea is the same to install the necessary packages in the guest system.