More complete (slightly) instructions for compiling a custom kernel

The kernel instructions to compile your own kernel at Managing qube kernels | Qubes OS seem incomplete, so I’m making a slightly more complete version here:

  1. do:
sudo qubes-dom0-update qubes-kernel-vm-support kernel-devel
  1. Find a valid version (which will eventually be used as a parameter for qubes-prepare-vm-kernel) by doing:
    ls /usr/src/kernels/
    
    each subdirectory name should be a valid version, and will be a valid parameter for qubes-prepare-vm-kernel.
  2. Pick a subdirectory / version and enter that subdirectory. Example:
    cd 5.10.61-1.fc32.qubes.x86_64
    
  3. Configure the kernel by editing the .config file in that directory
    (note, you cannot use “make menuconfig” or “make config”, unless you install the special dependencies for those)
    (Also note, there are a lot of options, so it may take a while)
  4. build it with qubes-prepare-vm-kernel {name of exact subdirectory you chose}. Example:
    sudo qubes-prepare-vm-kernel 5.10.61-1.fc32.qubes.x86_64
    

This should succeed in placing a new copy of the kernel in /var/lib/qubes/vm-kernels/{version of what you just configured}

However, the compilation process runs way too fast, so it is obviously not compiling the kernel. Possibly just managing modules?

Confirmed: typing make all or make zImage returns “flex: command not found”, so it is not capable of recompiling it as it would require packages to do the actual build that are not on your system

Conjectured procedure:
So, i suspect you are supposed to create a development qube. And I’ll conjecture that it’s supposed to be a fedora qube (to match dom0). I’m not familiar with the fedoa build dependancies, but I’m guessing it should be something like:

qvm-create --template fedora32 --label red kernel-compile
cd /
tar -cvzf ~/kernel-to-transfer.tgz /usr/src/kernels/{kernel version}/
qvm-copy-to-vm kernel-compile ~/kernel-to-transfer.tgz
qvm-run kernel-compile 'sudo dnf install kernel-devel'   ### to install the fedora build dependancies
qvm-run kernel-compile 'tar -xvzf /home/user/QubesIncoming/dom0/kernel-to-transfer.tgz'   ## (this would need to be done from /)
##then log into kernel-compile
cd /usr/src/kernels/{version you just copied over ending in .qubes.x86_64}  
make menuconfig
make all
tar -cvzf /home/user/back-to-dom0.tgz /usr/src/kernels/{version you just copied over ending in .qubes.x86_64}
###go back to dom0
qvm-run --pass-io kernel-compile 'cat /home/user/back-to-dom0.tgz' > /home/user/back-to-dom0.tgz
cd /
tar -xvzf /home/usr/back-to-dom0.tgz

Then use the sudo qubes-prepare-vm-kernel 5.10.61-1.fc32.qubes.x86_64 (or whatever your version name was) command to install it

1 Like

I have added a new procedure to the top post that conjectures how your supposed to do it. For those that access the forums via email a copy is here:

Summary of new conjectured procedure

Conjectured procedure:
So, i suspect you are supposed to create a development qube. And I’ll conjecture that it’s supposed to be a fedora qube (to match dom0). I’m not familiar with the fedoa build dependancies, but I’m guessing it should be something like:

qvm-create --template fedora32 --label red kernel-compile
cd /
tar -cvzf ~/kernel-to-transfer.tgz /usr/src/kernels/{kernel version}/
qvm-copy-to-vm kernel-compile ~/kernel-to-transfer.tgz
qvm-run kernel-compile 'dnf install kernel-compile'   ### to install the fedora build dependancies
qvm-run kernel-compile 'tar -xvzf /home/user/QubesIncoming/dom0/kernel-to-transfer.tgz'   ## (this would need to be done from /)
##then log into kernel-compile
cd /usr/src/kernels/{version you just copied over ending in .qubes.x86_64}  
make menuconfig
make all
tar -cvzf /home/user/back-to-dom0.tgz /usr/src/kernels/{version you just copied over ending in .qubes.x86_64}
###go back to dom0
qvm-run --pass-io kernel-compile 'cat /home/user/back-to-dom0.tgz' > /home/user/back-to-dom0.tgz
cd /
tar -xvzf /home/usr/back-to-dom0.tgz

Then use the sudo qubes-prepare-vm-kernel 5.10.61-1.fc32.qubes.x86_64 (or whatever your version name was) command to install it

Thanks again for the help. I’m having a few problems (of course, how could I not? :slight_smile:).

For some reason in /usr/src/kernels I have only 5.4.143-1.fc25 even after sudo qubes-dom0-update. Are you on the Beta or something? On another Qubes machine there’s nothing in /usr/src/kernels, but perhaps that’s because I didn’t install qubes-kernel-vm-support kernel-devel there.

I made the kernel-compile AppVM. I’m trying to build a kernel first without modifying anything just to make sure I can.

qvm-run kernel-compile 'dnf install kernel-compile'   ### to install the fedora build dependancies

I don’t understand why I have to do this from dom0. And “kernel-compile” is the name of the AppVM, not of any package, so I’m not sure what to install in the kernel-compile AppVM.

Also, in the make menuconfig step I got permission denied for making a bunch of .tmp_6114 and other .tmp_XXXX directories, so I used sudo make menuconfig, even though I read that compiling a kernel shouldn’t need sudo.

With sudo make menuconfig I got a Kconfig:34: can't open file "Documentation/Kconfig. According to this Bugzilla RedHat comment I tried to find the 5.4.143 kernel in the provided link, but couldn’t find it. I couldn’t get the search bar to work so I ordered the list of kernels and on page 121 I see kernel-5.4.14, but no kernel-5.4.143. I cloned the git repo from kernel.org,

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
cd linux-stable/
git checkout v5.4.143 # to get the exact files for this version of the kernel
wormhole send Documentation/ # to send to another machine that does make menuconfig

. This fixed it and the menuconfig program started.

You are correct, it should have been dnf install kernel-devel. (changed in OP) I think that it needs sudo too.

Also, you dont have to the above install command from dom0. You are free to type the “sudo dnf install kernel-devel” into the kernel-compile qube itself. I just talked about it as a qvm-run command because I was originally intending to not have the then log into kernel-compile step.

1 Like

Yes. The “reference machine” I used to try installing packages on to get that info was my scratch system that probably had qubes 4.1 on it at that moment.