Ubuntu 16.04 - Compile Custom Kernel For Ryzen
In an effort to fix stability on Ryzen, this tutorial was produced to show how to build a custom version of the latest kernel with
CONFIG_RCU_NOCB_CPU applied. This was made with a lot of help from First Last in the comments section of my Ryzen Stability post.
I have tested that the steps below work for building and installing a custom kernel. I installed the kernel this morning (5th October 2017) and haven't had a crash since.
Install the necessary packages:
sudo apt install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache -y
Create an area to work and clone the latest kernel there.
cd ~ mkdir kernelbuild cd kernelbuild git clone -b linux-4.13.y git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
Go into the source code and lets create a basic/default config to build the kernel from:
cd linux-stable cp /boot/config-`uname -r` .config yes '' | make oldconfig
Tweaking The Kernel For Ryzen
Now this is the important part where we will tweak our configuration options to try and resolve issues on the Ryzen CPUs. If you just want to compile your kernel from source, and aren't using a Ryzen CPU, then feel free to skip this part. However the info may be useful if you want to tweak the kernel in other ways.
Run the following command to open a menu for changing our .config file:
You will be shown the following screen:
/ in order to perform a search, and and enter the text
After running the search, you will see the screen below:
Press 1 to go to the option and you will see the following:
spacebar and you will then see:
spacebar again to allow advanced adjustments to RCU configuration.
Then go down to Offload RCU callback processing from boot-selected CPUs and press
Then press the right arrow several times to select Save and press enter to save over your
Then to exit out, you need to hover Exit and press return to exit. You have to do this multiple times until you are back at the normal terminal screen.
Build The Kernel
Now lets build the kernel. In this example I am going to use 16 threads because I have a Ryzen 7 1700 with 16 threads, If you have a Ryzen 3 with just 4 cores and no simultaneous multithreading, then you want to use a value of 4.
make clean NUM_THREADS=16 make -j $NUM_THREADS deb-pkg LOCALVERSION=-custom
make deb-pkg LOCALVERSION=-custom
Installing the Kernel
Now we've built the kernel, it's time to install it so that our system will use it when it boots up.
cd .. sudo dpkg -i linux-firmware-image-4.13.4-custom_4.13.4-custom-1_amd64.deb sudo dpkg -i linux-libc-dev_4.13.4-custom-1_amd64.deb sudo dpkg -i linux-headers-4.13.4-custom_4.13.4-custom-1_amd64.deb sudo dpkg -i linux-image-4.13.4-custom-dbg_4.13.4-custom-1_amd64.deb sudo dpkg -i linux-image-4.13.4-custom_4.13.4-custom-1_amd64.deb
Now reboot to boot into your new kernel, but before you do, you may wish to update grub to set a longer timeout.
Just Download Somebody Elses Kernel
If you don't want to sit around and wait for a kernel to build, First Last has built a kernel and made it available online. You can download the relevant files here, but it's probably a lot more secure to build your own than trusting strangers.
sudo dpkg -i linux-firmware-image-4.13.4-customrcu_4.13.4-customrcu-3_amd64.deb sudo dpkg -i linux-libc-dev_4.13.4-customrcu-3_amd64.deb sudo dpkg -i linux-headers-4.13.4-customrcu_4.13.4-customrcu-3_amd64.deb sudo dpkg -i linux-image-4.13.4-customrcu-dbg_4.13.4-customrcu-3_amd64.deb sudo dpkg -i linux-image-4.13.4-customrcu_4.13.4-customrcu-3_amd64.deb
Then reboot to boot into your new kernel.
Adding Kernel Boot Paramater
sudo vim /etc/default/grub
Find the line that states
GRUB_CMDLINE_LINUX_DEFAULT= and add the contents:
rcu_nocbs=0-15 like so:
... GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="rcu_nocbs=0-15" GRUB_CMDLINE_LINUX="" ...
Now apply that change by running:
Then reboot to boot into your kernel with the new options set.
- Massive thanks to First Last (also known as tgui) in the comments section of: Programster's Blog - Stabilizing Ubuntu 16.04 on Ryzen
- maketecheasier.com - How to Build a Custom Kernel on Ubuntu
- bugs.launchpad.com - Ryzen 1800X freeze - rcu_sched detected stalls on CPUs/tasks
- STH - AMD Ryzen with Ubuntu – Here is what you have to do to fix constant crashes!
- Hard Forum - How to Stabilize Your AMD Ryzen Memory and CPU Overclocking Attempts
- bugs.launchpad.com - Ryzen 1800X freeze - rcu_sched detected stalls on CPUs/tasks Edit
- Level1Techs.com - [Solved] Linux is unstable ever since I upgraded to Ryzen
- Level1Techs.com - Custom Ubuntu Distro For Ryzen Installations
First published: 16th August 2018