Ubuntu/Fedora下修改CPU调频设置重启后失效的问题咨询
Ubuntu/Fedora下修改CPU调频设置重启后失效的问题咨询
Hey there! I see you're having trouble keeping your CPU frequency settings after rebooting Ubuntu or Fedora—let's figure this out together.
First, let's clear up why your current changes don't stick:
- The
sudo cpupower frequency-set -g balancedcommand and direct edits to/sys/devices/system/cpu/cpufreq/*are temporary runtime changes. The/sysfilesystem is a virtual in-memory filesystem that gets reinitialized every time your system boots, so any edits there won't survive a restart. That's totally normal behavior, not a bug!
Now, let's go over how to make these settings permanent, plus address your questions about tools like Nano, Vim, and tee:
持久化CPU调频设置的方法
针对Ubuntu
- 使用cpupower服务(最简方案)
- 用你习惯的编辑器打开cpupower配置文件(Nano、Vim、Gedit都可以):
sudo nano /etc/default/cpupower - 找到
GOVERNOR=开头的行,修改为:GOVERNOR="balanced" - 保存文件后,启用并启动服务,让设置立即生效且开机自动加载:
sudo systemctl enable --now cpupower
- 用你习惯的编辑器打开cpupower配置文件(Nano、Vim、Gedit都可以):
- 通过rc.local自定义脚本(适合进阶调整)
- 如果需要设置特定频率限制(不止是调度器),创建或编辑
/etc/rc.local文件(不存在的话直接创建即可):sudo nano /etc/rc.local - 在
exit 0行之前添加你的命令,比如:cpupower frequency-set -g balanced # 示例:给所有CPU设置最低800MHz频率 echo 800000 | tee /sys/devices/system/cpu/cpufreq/policy*/scaling_min_freq - 给文件添加执行权限:
sudo chmod +x /etc/rc.local
- 如果需要设置特定频率限制(不止是调度器),创建或编辑
针对Fedora
- 使用cpupower服务
- 编辑cpupower配置文件:
sudo nano /etc/sysconfig/cpupower - 将调度器行修改为:
GOVERNOR="balanced" - 启用并启动服务:
sudo systemctl enable --now cpupower
- 编辑cpupower配置文件:
- 自定义systemd服务(适合复杂配置)
- 创建一个自定义systemd服务文件:
sudo nano /etc/systemd/system/cpu-freq-set.service - 粘贴以下内容(如果需要额外调整,可修改
ExecStart行):[Unit] Description=开机时设置CPU调频策略 [Service] Type=oneshot ExecStart=/usr/bin/cpupower frequency-set -g balanced # 取消注释下面的行可设置自定义最低频率 # ExecStart=/bin/bash -c 'echo 800000 | tee /sys/devices/system/cpu/cpufreq/policy*/scaling_min_freq' [Install] WantedBy=multi-user.target - 保存文件后,重载systemd并启用服务:
sudo systemctl daemon-reload sudo systemctl enable cpu-freq-set.service
- 创建一个自定义systemd服务文件:
关于你提到的工具的疑问
- Nano/Gedit/Vim: 这些都是文本编辑器,用来编辑上面提到的配置文件完全没问题。选你用着顺手的就行:Nano是终端里的入门友好型工具,Vim适合有经验的用户高效操作,Gedit则是桌面环境下的图形化编辑器。
tee: 这个命令很适合安全地写入sysfs文件(因为可以配合sudo使用,不像直接echo重定向需要先切换到root)。比如:
但要注意——这仍然是临时修改,想要开机保留的话,需要把这个命令加入到开机脚本或systemd服务里,就像前面介绍的那样。echo "balanced" | sudo tee /sys/devices/system/cpu/cpufreq/policy*/scaling_governor
备注:内容来源于stack exchange,提问作者nickvlandoskyCA




