如何在 Ubuntu 上不编译新内核的情况下禁用 vmwgfx 驱动程序?

How to disable vmwgfx driver without compiling a new kernel on Ubuntu?

我知道我可以通过编译新内核来禁用它,而无需在 config 文件中设置 CONFIG_DRM_VMWGFX。但是我不想构建新内核,可以通过修改一些配置来实现吗?

我尝试从 lib/modules/XXX/kernel/driver 目录中删除 vmwgfx.ko,然后重新启动,但驱动程序在 Ubuntu 16.04 上运行良好。为什么?文件在别处吗?

我也试过 rmmod,但是不行。

[root@ubuntu:] lsmod |grep vmwgfx
vmwgfx                235405  4 
drm_kms_helper        159169  1 vmwgfx
ttm                    99345  1 vmwgfx
drm                   370825  7 ttm,drm_kms_helper,vmwgfx
[root@ubuntu:] rmmod -f vmwgfx
rmmod: ERROR: ../libkmod/libkmod-module.c:793 kmod_module_remove_module()
could not remove 'vmwgfx': Resource temporarily unavailable
[root@ubuntu:] modprobe -r vmwgfx
modprobe: FATAL: Module vmwgfx is in use.

终于知道怎么做了

造成我这种情况的原因是驱动的文件存放在initramfs-xxx.img中。所以我们需要重建一个initramfs-xxx.img.

  1. 找到文件路径:modinfo vmwgfx
filename:       /lib/modules/4.4.0-21-generic/kernel/drivers/gpu/drm/vmwgfx/vmwgfx.ko
version:        2.9.0.0
license:        GPL and additional rights
description:    Standalone drm driver for the VMware SVGA device
author:         VMware Inc. and others
srcversion:     AC179B70460E5C5D32AC416
alias:          pci:v000015ADd00000405sv*sd*bc*sc*i*
depends:        ttm,drm,drm_kms_helper
intree:         Y
vermagic:       4.4.0-21-generic SMP mod_unload modversions 
parm:           enable_fbdev:Enable vmwgfx fbdev (int)
parm:           force_dma_api:Force using the DMA API for TTM pages (int)
parm:           restrict_iommu:Try to limit IOMMU usage for TTM pages (int)
parm:           force_coherent:Force coherent TTM pages (int)
parm:           restrict_dma_mask:Restrict DMA mask to 44 bits with IOMMU (int)
  1. 删除驱动文件mv /lib/modules/$(uname -r)/kernel/driver/gpu/drm/vmwgfx/vmwgfx.ko /home/$(whoami)/.

  2. 备份你的启动img:mv /boot/initrd.img-`uname -r` /home/`whoami`/

  3. 重新启动 img: mkinitrd -f /boot/initrd.img-`uname -r` `uname -r`

  4. 重启

如果你想删除其他build-in驱动文件,这个方法很有效。 如果你的虚拟机是centos,选择正确的文件路径和启动img名称即可。