使用bbswitch禁用nvidia独显

本文介绍了如何使用bbswitch模块来控制Optimus笔记本电脑上的独立显卡的开关状态。主要内容包括检查显卡状态、安装bbswitch模块、手动设置显卡状态、设置模块参数以及配置开机自加载等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0.查看显卡状态:

lspci|grep VGA

1.下载bbswitch源代码,编译并安装:

make&&make install

2.加载模块:

modprobe bbswitch

3.(可选)手动设置显卡状态

tee /proc/acpi/bbswitch <<<OFF #关闭独立显卡

tee /proc/acpi/bbswitch <<<ON #开启独立显卡

4. 设置bbswitch模块参数:

echo 'options bbswitch load_state=0'> /etc/modprobe.d/bbswitch.conf

5.开机自加载:

echo 'modprobe bbswitch'>>/etc/rc.local


参考:bbswitch官方文档——

bbswitch is a kernel module which automatically detects the required ACPI callsfor two kinds of Optimus laptops. It has been verified to work with "real"Optimus and "legacy" Optimus laptops (at least, that is how I call them). Themachines on which these tests has performed are:

  • Clevo B7130 - GT 425M ("real" Optimus, Lekensteyns laptop)
  • Dell Vostro 3500 - GT 310M ("legacy" Optimus, Samsagax' laptop)

(note: there is no need to add more supported laptops here as the universalcalls should work for every laptop model supporting either Optimus calls)

It's preferred over manually hacking with the acpi_call module because it candetect the correct handle preceding _DSM and has some built-in safeguards:

  • You're not allowed to disable a card if a driver (nouveau, nvidia) is loaded.
  • Before suspend, the card is automatically enabled. When resuming, it'sdisabled again if that was the case before suspending. Hibernation shouldwork, but it not tested.

Build

Build the module (kernel headers are required):

make

Then load it (requires root privileges, i.e. sudo):

make load

If your card is supported, there should be no error. Otherwise, you get a "Nosuch device" (ENODEV) error. Check your kernel log (dmesg) for moreinformation.

DKMS support

If you have DKMS installed, you can install bbswitch in such a way that itsurvives kernel upgrades. It is recommended to remove older versions of bbswitchby runningdkms remove -m bbswitch -v OLDVERSION --all as root. To installthe new version, simply run:

# make -f Makefile.dkms

To uninstall it, run:

# make -f Makefile.dkms uninstall

Usage

bbswitch has three commands to check the card status and switching (# means "run with root privileges, i.e. run it prefixed withsudo):

Get the status:

# cat /proc/acpi/bbswitch  
0000:01:00.0 ON

Turn the card off, respectively on:

# tee /proc/acpi/bbswitch <<<OFF
# tee /proc/acpi/bbswitch <<<ON

If the card stays on when trying to disable it, you've probably forgotten tounload the driver,

$ dmesg |tail -1
bbswitch: device 0000:01:00.0 is in use by driver 'nouveau', refusing OFF

Do not attempt to load a driver while the card is off or the card won't beusable until the PCI configuration space has been recovered (for example, afterwriting the contents manually or rebooting).

Module options

The module has some options that control the behavior on loading and unloading:load_state andunload_state. Valid values are -1, 0 and 1 meaning "donot change the card state", "turn the card off" and "turn the card on"respectively. For example, if you want to havebbswitch disable the cardimmediately when loading the module while enabling the card on unload, load themodule with:

# modprobe bbswitch load_state=0 unload_state=1

The unload_state value can be changed on runtime, the above command yields thesame behavior as:

# modprobe bbswitch load_state=0
# echo 1 | tee /sys/module/bbswitch/parameters/unload_state

If not explictly set, the default behavior is not to change the power state ofthe discrete video card which equals toload_state=-1 unload_state=-1.

Disable card on boot

These options can be useful to disable the card on boot time. Depending on yourdistribution,/etc/modules, /etc/modules.conf or some other file can be usedto load modules on boot time. Adding the below line to the file makes the cardget disabled on boot:

bbswitch load_state=0

You have to update your initial ramdisk (initrd) for the changes propagate tothe boot process. On Debian and Ubuntu, this can performed by runningupdate-initramfs -u as root.


### 如何配置和使用 NVIDIA 独立显卡 #### 安装 NVIDIA 显卡驱动程序 为了使 NVIDIA 独立显卡能够正常工作,首先需要安装适合的 NVIDIA 驱动程序。可以通过以下命令来查找并安装最新的稳定版驱动: ```bash sudo ubuntu-drivers autoinstall ``` 如果系统未自动检测到合适的驱动版本,则可以手动指定版本号进行安装[^1]。 #### 禁用 Nouveau 开源驱动 默认情况下,Linux 系统可能会加载 Nouveau 开源驱动,这可能与 NVIDIA 的专有驱动冲突。因此,在安装 NVIDIA 驱动之前,应先禁用 Nouveau 驱动。编辑 `/etc/modprobe.d/blacklist.conf` 文件并将以下两行添加至文件末尾: ```plaintext blacklist nouveau options nouveau modeset=0 ``` 随后更新 initramfs 并重启计算机以应用更改: ```bash sudo update-initramfs -u sudo reboot ``` 完成上述操作后再继续安装 NVIDIA 驱动[^2]。 #### 使用 `prime-select` 切换显卡模式 对于支持 Optimus 技术的笔记本电脑来说,可以在 Intel 核心显卡(iGPU)和 NVIDIA 独立显卡之间切换。通过执行如下命令可以选择不同的 GPU 工作状态: - **启用 NVIDIA 独立显卡** ```bash sudo prime-select nvidia ``` - **恢复到 Intel 核显** ```bash sudo prime-select intel ``` 每次切换之后都需要重新启动图形界面服务或者整个机器才能生效[^3]。 #### 调整 PyTorch 环境适配 CUDA 支持 当确认硬件层面已成功启用了 NVIDIA 显卡后,还需要确保软件开发环境中也充分利用到了该设备资源。比如构建一个基于 Conda 的 Python 虚拟环境,并在此基础上部署带有 CUDA 加速功能的深度学习框架——PyTorch: 1. 创建一个新的虚拟环境; ```bash conda create -n python397 python=3.9.7 ``` 2. 启用新创建好的虚拟环境; ```bash conda activate python397 ``` 3. 按照官方文档指引下载对应版本的 PyTorch 包含 CUDA 插件的支持包[^4]。 --- #### 注意事项 某些特殊场景下可能出现无法顺利切换回独显的情况,此时建议查阅具体错误日志分析原因所在,必要时尝试降级或升级相关组件直至兼容为止。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值