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. We will do this on a single thread for debugging
make clean make -j `getconf _NPROCESSORS_ONLN` 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.
- 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