= Compile Linux kernel for Ubuntu
= Compiling Linux kernel for Ubuntu
{synonym}
This section describes our attempts at compiling the <Linux kernel> for <Ubuntu> so as to use the exact patches and build configuration as used for a given <Ubuntu release>. The same toolchain would also be ideal, but perhaps this would require a <Linux distribution buildable from source>.
https://canonical-kteam-docs.readthedocs-hosted.com/en/public/how-to/build-kernel.html seems promising it says that for <Ubuntu 24.04> and above you should do the following which was tested on <Ubuntu 24.10>:
``
sudo cp /etc/apt/sources.list /etc/apt/sources.list~
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt-get update
sudo apt build-dep -y linux linux-image-unsigned-$(uname -r)
sudo apt install -y fakeroot llvm libncurses-dev dwarves
apt source linux-image-unsigned-$(uname -r)
~/tmp/ubuntu/linux-6.11.0
cd linux-6.11.0
chmod a+x debian/rules
chmod a+x debian/scripts/*
chmod a+x debian/scripts/misc/*
fakeroot debian/rules clean
fakeroot debian/rules binary
``
The build is extremely slow compared to a build of a more embedded and specifically targeted minimal kernel, and took about 2 hours on <Ciro Santilli's hardware/P14s>. Their philosophy is likely to enable as many drivers as possible so that a single download will work for everyone. Which makes sense, fair enough. It would be cute though if there was a smarter way. Oh well.
After it finally finishes the build including our <vmlinux> is present at:
``
linux-6.11.0/debian/build/build-generic
``
Back to article page