Home Ubuntu How to Disable/Enable CPU Cores in Ubuntu

How to Disable/Enable CPU Cores in Ubuntu

CPU cores are essential for effectively processing data and carrying out computations in the world of computers. Disabling CPU cores may be useful in some circumstances, though.

This page attempts to instruct Ubuntu users on the proper usage of CPU core disablement. We’ll talk about why cores should be disabled, how to do it either temporarily or permanently, and how to check the system thereafter.

Check CPU Cores in Ubuntu

Knowing how many cores your Ubuntu system has is crucial before beginning the procedure of CPU core disablement. Various command-line tools and graphical applications that offer thorough CPU monitoring can be used for this. You’ll be better able to decide whether to disable cores by understanding the CPU configuration of your machine.

To check how many cores are available in our system we will use the lscpu command line utility, which provides complete information about the CPU like CPU vendor details, the number of CPUs or cores, etc.

To install lscpu on Ubuntu, use the apt command:

$ sudo apt-get install util-linux

Run the lscpu command to display the information:

$ lscpu
View CPU Cores in Ubuntu
View CPU Cores in Ubuntu

As we can clearly see in the “CPU(s)” field there are 12 CPU cores available.

Why Disable CPU Cores in Ubuntu?

There are many reasons why a user may want to disable their Ubuntu’s system CPU cores. The two most significant reasons are energy efficiency and power consumption.

By disabling CPU cores, you can reduce power usage and promote energy conservation. On top of that disabling CPU cores can improve system stability and minimize heat generation. Which will result in a cooler system just like you.

It is a good idea to disable the cores that are causing problems to narrow down any hardware issues.

Method 1: Disable CPU Cores Temporarily in Ubuntu

We can disable CPU cores in Ubuntu by modifying “online” files present in “/sys/devices/system/cpu/cpuN” where N represents each CPU core number. Each core has its dedicated folder.

Let us see the list of core folders:

$ ls /sys/devices/system/cpu
List CPU Core Directory
List CPU Core Directory

NOTE: While the system is operating, CPU0, sometimes referred to as the main core or boot processor, cannot be turned off. This core is in charge of processing crucial activities that are crucial for the system’s functioning as well as initializing the system during the boot process. The system would become unusable if CPU0 were disabled.

The primary core, commonly designated as CPU0, is where the operating system and other crucial activities are initially loaded. It controls system resources and organizes the operation of other cores. The system would lose control and be unable to function as planned if CPU0 were disabled.

Even though you might be able to update the “online” file for CPU0, the modifications won’t do anything. The system will continue to rely on the core for appropriate operation while it is still operational. Therefore, attempting to deactivate CPU0 is not advised.

Let’s say I want to disable core 12 of my CPU. I will first navigate to that core directory.

cd /sys/devices/system/cpu/cpu11

NOTE: In computer science and programming, a convention is followed to start indexing or counting from 0.

There is a file called “online” which contains “0” or “1”. Where 0 represents that the core is disabled and 1 represents whether the core is online or active.

Let’s display the file’s content:

$ cat online
Check CPU Core Status
Check CPU Core Status

It say’s “1”, therefore the core is online.

To disable the core we just need to modify the “online” file and change the “0” to “1”.

$ echo 0 | sudo tee online

The core will now be disabled we can again verify it.

$ cat online
Disable CPU Core in Ubuntu
Disable CPU Core in Ubuntu

Another way to verify is using the lscpu command again which will provide detailed information.

$ lscpu
Verify CPU Cores in Ubuntu
Verify CPU Cores in Ubuntu

In the CPU(s) section we can clearly see that 11 cores are currently enabled and 1 core is disabled.

To enable that core again to follow the same above procedure just change “0” to “1”:

$ echo 1 | sudo tee online
$ cat online
Enable CPU Core in Ubuntu
Enable CPU Core in Ubuntu

This approach is very helpful when you need to assess system performance fast or address core-specific problems. Keep in mind that until the subsequent system reboot or manual re-enabling, this technique only temporarily disables the CPU core.

Consider utilizing the techniques that we will be discussing further in the article if you wish to deactivate CPU cores permanently.

Method 1: Disable CPU Cores Permanently in Ubuntu

To disable cores permanently, which means the cores remain disabled even after the system is rebooted we just need to tweak the grub configuration file.

$ sudo nano /etc/default/grub

Search for this line:

GRUB_CMDLINE_LINUX_DEFAULT

Add the “quiet splash” to the line. For me, the existing values are something like.

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Change the value by adding the number of CPUs you want the Ubuntu system to use. Do not remove the existing values just add your content by separating it with a space character.

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash maxcpus=6"

The “maxcpus=6” for using only 6 cores.

Disable CPU Core Permanently on Ubuntu
Disable CPU Core Permanently on Ubuntu

Now, system to take effect we need to update grub.

$ sudo update-grub
Update Grub Configuration in Ubuntu
Update Grub Configuration in Ubuntu

When you reboot your system only 6 cores will be used by the Ubuntu system.

Conclusion

On Ubuntu disabling cores can be beneficial to optimize power consumption and troubleshoot hardware issues. It’s up to you to go for the temporary to the permanent approach but monitor your Ubuntu’s performance and check that the disabled CPU cores are functioning as intended.

By following the steps in this article you can now confidently enable or disable cores on your Ubuntu system by customizing the system performance according to your need.

Chinmay Sonawane
Final year student in computer science with working experience across the web and Python development. Investigate new technologies and write about them. Organized and Innovative technical writer. Looking to continue developing my skills and abilities.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

4 thoughts on “How to Disable/Enable CPU Cores in Ubuntu”

  1. Excellent article. I have a question.

    Nowadays we use computers only for YouTube viewing. I think it doesn’t require much processing power. So will it be helpful?

    Reply
    • Thank you for your feedback! Disabling CPU cores can help reduce power consumption and heat generation, which can be beneficial for overall system efficiency.

      While YouTube viewing may not require much processing power, disabling cores can still contribute to a cooler system and potentially optimize performance.

      Reply
      • Thank you for this blog!

        As an alternative, you can also use the command “chcpu“.

        Disable CPUs:

        # chcpu -d 1,4
        

        Enable CPUs:

        # chcpu -e 2-4
        
        Reply
        • Thank you for your feedback and for sharing an alternative method using the “chcpu” command to disable and enable CPUs.

          It’s great to have multiple options for achieving the same result. Your suggestion provides another useful approach for managing CPU cores in Ubuntu systems.

          Reply

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.