How to Disable CPU Cores to Save Power in Ubuntu 22.04

This tutorial shows how to disable certain CPU cores in Ubuntu to save power and prevent your machine from overheating.

There are a few tools to manage CPU frequency and save power in Linux today. They include power-profile-daemon (Gnome built-in power mode settings), TLP laptop battery life saving tool, auto-cpufreq, and more.

Besides limiting CPU frequency, turn off few CPU cores is another choice to cool down your PC or laptop. And, Motherboard BIOS settings page usually have a corresponding option. For choice, here’s how to do the job in Ubuntu Linux.

Option 1: Single command to disable CPU core

Ubuntu and most other Linux has a /sys/devices/system/cpu/ directory handles the CPU configurations.

1. First, press Ctrl+Alt+T on keyboard to open terminal. Then, run command to list the directory content:

ls /sys/devices/system/cpu/

In terminal output, you’ll see cpu0, cpu1, cpu2, cpu3 etc sub-folders for your CPU cores. In my case, I have 8 cores (4c/8t). They are cpu0 ~ cpu7.

2. Each sub-folder contains a ‘online‘ config file. To disable a CPU core, just set its online file content to 0.

For example, disable cpu7 by running command:

sudo sh -c "echo 0 > /sys/devices/system/cpu/cpu7/online"

By re-running last command and changing number 7, you may continue to disable more CPU cores one by one.

Or, use single command to disable multiple cores:

for file in $(ls /sys/devices/system/cpu/cpu[578]*/online); do sudo sh -c "echo 0 > $file"; done

The command above will disable CPU ids with number 5, 7, 8 (cpu5, cpu7, and cpu8 if exist).

3. After making changes, verify by either going to system ‘About’ page, or running the command below in terminal:

lscpu | grep 'CPU(s)'

Option 2: Use Kernel Parameter to set how many CPU Cores to enable on startup

The changes you made in “Option 1” will be overridden on system reboot. If you want to make it work on every boot, then there’s a maxcpus kernel parameter can do the job.

1. First, press Ctrl+Alt+T on keyboard to open terminal. When it opens, run command to edit the grub boot-loader config file:

sudo gedit /etc/default/grub

For Ubuntu 23.10, replace gedit with gnome-text-editor. For non-default GNOME desktop, replace gedit with your favorite text editor, or use nano that works in most desktops.

2. When file opens, add the maxcpus=4 (change number 4 as you want.) parameter as value to GRUB_CMDLINE_LINUX_DEFAULT. Then, save file. For nano command line text editor, press Ctrl+S to save, then Ctrl+X to exit.

3. Finally, apply the change by updating grub configuration (this command varies in different Linux Distros):

sudo update-grub

For those who have “Grub Customizer” installed, you can also open the app and navigate to “General Settings” tab to add the kernel parameter and finally click save.

In addition, the kernel parameter usually load the first 4 (or other number depends your setting) CPU cores. If you want to re-enable the left CPU cores, for example cpu7, run command:

sudo sh -c "echo 1 > /sys/devices/system/cpu/cpu7/online"

Instead of running the command above one by one with different core number, you may alternatively run single command below to re-enable all CPU cores:

for file in $(ls /sys/devices/system/cpu/cpu[0-9]*/online); do sudo sh -c "echo 1 > $file"; done

Use graphical tool to disable CPU cores

For GNOME, the default desktop environment in Ubuntu and Fedora Workstation, there’s a lightweight power management extension that can do the job.

It’s cpufreq which however supports GNOME up to version 44 so far (Ubuntu 23.04/Fedora 38 and earlier).

Ubuntu user can first search for and install “Extension Manager” from Ubuntu Software (App Center), then use the tool to search & install the cpufreq extension. While, Fedora and other Linux with GNOME can visit the extension web page then use ON/OFF toggle to install (need to install browser extension).

For non-Gnome users, there’s previously cpupower-gui tool for Ubuntu 20.04. Sadly, it lacks development for recent Ubuntu versions support.

If you know any other graphical tool to do the job, feel free to leave comment below.