overview
In some cases, you may need to disable or enable CPU cores in the Ubuntu operating system. Disabling CPU cores can help you reduce power consumption, improve performance or resolve some hardware and software compatibility related issues. This article will explain how to disable and enable CPU cores in Ubuntu.
Method 1: Use GRUB configuration
GRUB is Ubuntu's boot loader, and you can disable or enable CPU cores by editing the GRUB configuration file.
-
Open a terminal and enter the following command to edit the GRUB configuration file:
sudo nano /etc/default/grub
2. In the opened file, find GRUB_CMDLINE_LINUX_DEFAULT
the line named . This line contains information about system startup parameters.
3. If you want to disable CPU cores, add the following parameters inside the quotes of the line:
nohz=off
This will disable uncore clock events.
4. If you want to enable CPU cores, make sure there are no parameters added within the quotes on the line nohz=off
.
5. Save and close the file, then run the following command to update the GRUB configuration:
sudo update-grub
6. Restart the computer for the changes to take effect.
Method 2: Use the system configuration tool
Ubuntu provides a cpufrequtils
tool called to disable or enable CPU cores by changing the CPU frequency.
1. Open a terminal and enter the following command to install cpufrequtils
:
sudo apt-get install cpufrequtils
2. After the installation is complete, enter the following command to view the information of the current CPU core:
cpufreq-info
You'll see details about your CPU frequency and current settings.
3. To disable a CPU core, enter the following command:
sudo cpufreq-set -c <core_number> -g powersave
will be <core_number>
replaced with the number of the CPU core to disable. For example, if you want to disable the second CPU core, modify the command to:
sudo cpufreq-set -c 1 -g powersave
4. To enable a disabled CPU core, enter the following command:
sudo cpufreq-set -c <core_number> -g performance
Again, <core_number>
replace with the number of the CPU core to enable.
5. Rerun cpufreq-info
the command to ensure the changes have taken effect.
Method 3: Use kernel boot parameters
Ubuntu allows you to disable or enable CPU cores via kernel boot parameters.
-
Open a terminal and enter the following command to edit the GRUB configuration file:
sudo nano /etc/default/grub
-
In the opened file, find
GRUB_CMDLINE_LINUX_DEFAULT
the line named . -
If you want to disable CPU cores, add the following parameters inside the quotes on the line:
nr_cpus=<number_of_cpus>
will <number_of_cpus>
be replaced by the number of CPU cores to enable minus one. For example, if you want to disable one CPU core, modify the command to:
nr_cpus=1
This will tell the kernel to only use the specified number of CPU cores.
4. Save and close the file, then run the following command to update the GRUB configuration:
sudo update-grub
5. Restart the computer for the changes to take effect.
Method 4: Use the kernel parameter configuration file
Ubuntu also allows you to disable or enable CPU cores using kernel parameter configuration files.
1. Open a terminal and enter the following command to create a new kernel parameter configuration file:
sudo nano /etc/sysctl.d/99-cpu-cores.conf
2. In the opened file, add the following:
kernel.sched_core_disabled=<core_number>
will be <core_number>
replaced with the number of the CPU core to disable. For example, if you want to disable the second CPU core, modify the content to:
kernel.sched_core_disabled=1
3. Save and close the file.
4. Run the following command for the changes to take effect:
sudo sysctl --system
Alternatively, you can restart your computer.
Summarize
Disabling and enabling CPU cores can have an impact on performance, power consumption and compatibility in some cases. In this article, we covered four ways to disable and enable CPU cores in Ubuntu: using GRUB configuration, using system configuration tools, using kernel boot parameters, and using kernel parameter configuration files. Choose the method that works for you based on your specific needs and system environment, and be sure to back up important data before making any changes. By properly configuring the CPU cores, you can optimize your system's performance and resource utilization to suit your needs.
Welcome to like, collect and forward, thank you! !