如何禁用内置摄像头?

我想禁用我的笔记本电脑上运行的Ubuntu 13.10的内置摄像头。如此处所建议,我已经通过将其列入黑名单来禁用相关的内核模块。但是在重新启动后,这些模块仍然被加载。我该怎么做才能摆脱这些模块呢?
我的模块黑名单位于/etc/modprobe.d/blacklist-webcam.conf,内容如下:
blacklist videodev
blacklist videobuf2_core
blacklist videobuf2_memops
blacklist videobuf2_vmalloc
blacklist uvcvideo

但是在重启后,lsmod给我返回的结果是:
Module                  Size  Used by
uvcvideo               80885  0 
videobuf2_vmalloc      13216  1 uvcvideo
videobuf2_memops       13362  1 videobuf2_vmalloc
videobuf2_core         40499  1 uvcvideo
videodev              133509  2 uvcvideo,videobuf2_core

编辑:
当我执行sudo modprobe -r uvcvideo时,模块就会消失。所以我可以编写一个脚本来做这个。但是我不认为这是一个干净的解决方案;-)

当您键入sudo modprobe -r uvcvideo时,您会得到什么结果? - jobin
1你把黑名单文件保存在哪里了? - Braiam
@Braiam:黑名单位于/etc/modprobe.d目录下。它还包含用于屏蔽蓝牙模块的条目。这样设置是有效的,所以该文件会被解释执行。 - Marc Hauptmann
你禁用摄像头的需求背后的原因是什么?我是认真的,不是在捣乱。如果你想释放kmodules等所使用的资源,那太棒了。如果你希望摄像头不拍摄图像/视频,并且不在意几KB或内存,也许这就是你需要的?http://pbs.twimg.com/media/BTWPnR_CYAA2pfM.jpg 在这里可以找到它们:https://www.eff.org/deeplinks/2013/04/how-protect-against-laptop-webcam-hacking - 0xSheepdog
我认为它们是通过udev规则在后期启用的。我不确定你如何禁用它们。 - Braiam
@Sneetsher,我在问题中添加了我的黑名单位置。 - Marc Hauptmann
@Sneetsher,一切都好。我刚刚弄清楚为什么模块被加载了。谢谢你的帮助! - Marc Hauptmann
5个回答

在您的blacklist.conf文件中,将blacklist videodev改为install videodev /bin/false。 执行update-initramfs -u命令。 重新启动计算机。 更多详细信息请参考Arch Wiki上的内核模块黑名单设置

Blacklisting

Blacklisting, in the context of kernel modules, is a mechanism to prevent the kernel module from loading. This could be useful if, for example, the associated hardware is not needed, or if loading that module causes problems: for instance there may be two kernel modules that try to control the same piece of hardware, and loading them together would result in a conflict.

Some modules are loaded as part of the initramfs. mkinitcpio -M will print out all automatically detected modules: to prevent the initramfs from loading some of those modules, blacklist them in /etc/modprobe.d/modprobe.conf. Running mkinitcpio -v will list all modules pulled in by the various hooks (e.g. filesystems hook, block hook, etc.). Remember to add that .conf file to the FILES section in /etc/mkinitcpio.conf, if you have not done so already, and rebuild the initramfs once you have blacklisted the modules, and reboot afterwards.

Using files in /etc/modprobe.d/

Create a .conf file inside /etc/modprobe.d/ and append a line for each module you want to blacklist, using the blacklist keyword. If for example you want to prevent the pcspkr module from loading:

/etc/modprobe.d/nobeep.conf

# Do not load the 'pcspkr' module on boot.
blacklist pcspkr

Note: The blacklist command will blacklist a module so that it will not be loaded automatically, but the module may be loaded if another non-blacklisted module depends on it or if it is loaded manually.

However, there is a workaround for this behaviour; the install command instructs modprobe to run a custom command instead of inserting the module in the kernel as normal, so you can force the module to always fail loading with:

/etc/modprobe.d/blacklist.conf

...
install module_name /bin/false
...

This will effectively blacklist that module and any other that depends on it.


只需将模块列表放在/etc/modprobe.d/blacklist.uvcdrver.conf中即可。文件名可以是任何名称,只需确保格式和权限正确即可。

非常感谢大家的帮助!在尝试bain's solution时,我找到了问题的源头。他的解决方案很有效。重新启动后,模块确实消失了。但是有一个缺点:如果我想重新启用网络摄像头,就无法通过modprobe uvcvideo加载模块。
为了找出为什么会加载uvcvideo模块,我在系统中进行了一番搜索,最终使用grep -r uvcvideo /etc/命令,然后发现了一个位于/etc/pm/power.d目录下的脚本。当插入电源时,该脚本会执行modprobe uvcvideo命令。我之前编写了这个脚本以优化功耗。我注释掉了与网络摄像头模块相关的代码行,之后黑名单生效了!

我建议你运行。
sudo update-initramfs -u

修改黑名单后,这将更新您的初始RAM磁盘。

不,那个没有起作用。 - Marc Hauptmann

如果你想要一条命令行指令来解决问题的话,这可能会有所帮助(基于这个答案):
要在重启前禁用摄像头,请使用以下命令:
sudo modprobe -r uvcvideo

输入密码,如果终端没有显示任何错误,则意味着您的网络摄像头已被禁用。如果您收到以下错误信息:modprobe: FATAL: Module uvcvideo is in use,您可以尝试使用以下命令强制移除它:
sudo rmmod -f uvcvideo

要重新启用您的网络摄像头,请在shell中键入以下内容:
sudo modprobe uvcvideo