![DKMS 创建的内核模块显示“Exec 格式错误”(更新至 Ubuntu 21.04 后)](https://linux22.com/image/1182005/DKMS%20%E5%88%9B%E5%BB%BA%E7%9A%84%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E6%98%BE%E7%A4%BA%E2%80%9CExec%20%E6%A0%BC%E5%BC%8F%E9%94%99%E8%AF%AF%E2%80%9D%EF%BC%88%E6%9B%B4%E6%96%B0%E8%87%B3%20Ubuntu%2021.04%20%E5%90%8E%EF%BC%89.png)
嗨,我的情况很奇怪。Hirsute 的更新似乎一切正常,直到我将扩展坞插入笔记本电脑后才发现无法使用外接显示器。缩小原因范围后,我发现 DKMS 无法为我的内核生成模块,而且 NVidia 驱动程序和 VirtualBox 也不再可用。
我发现系统上的 GCC 和 BinUtils 应该与用于创建内核的版本相匹配。
因此 dmesg 输出包含:
sudo dmesg
Linux version 5.11.0-18-generic (buildd@lgw01-amd64-049) (gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0, GNU ld (GNU Binutils for Ubuntu) 2.36.1) #19-Ubuntu SMP Fri May 7 14:22:03 UTC 2021 (Ubuntu 5.11.0-18.19-generic 5.11.17)
GCC 版本是:
gcc --version
gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0
binutils 是:
sudo apt show binutils
Version: 2.36.1-6ubuntu1
因此一切似乎都很好,即使重新安装例如 virtualbox-dkms:
sudo apt install virtualbox-dkms
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libcg libcggl libnvidia-decode-460:i386 libnvidia-encode-460:i386 libnvidia-fbc1-460:i386 libnvidia-gl-460:i386 libnvidia-ifr1-460:i386 libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib libxnvctrl0
nvidia-prime nvidia-settings nvidia-utils-460 python-is-python2 python2 python2-minimal python2.7 python2.7-minimal screen-resolution-extra xserver-xorg-video-nvidia-460
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
dkms
Suggested packages:
menu
The following NEW packages will be installed:
dkms virtualbox-dkms
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 761 kB of archives.
After this operation, 5.983 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://de.archive.ubuntu.com/ubuntu hirsute/main amd64 dkms all 2.8.4-4 [68,3 kB]
Get:2 http://de.archive.ubuntu.com/ubuntu hirsute/multiverse amd64 virtualbox-dkms amd64 6.1.18-dfsg-5 [692 kB]
Fetched 761 kB in 0s (2.382 kB/s)
Selecting previously unselected package dkms.
(Reading database ... 237715 files and directories currently installed.)
Preparing to unpack .../archives/dkms_2.8.4-4_all.deb ...
Unpacking dkms (2.8.4-4) ...
Selecting previously unselected package virtualbox-dkms.
Preparing to unpack .../virtualbox-dkms_6.1.18-dfsg-5_amd64.deb ...
Unpacking virtualbox-dkms (6.1.18-dfsg-5) ...
Setting up dkms (2.8.4-4) ...
Setting up virtualbox-dkms (6.1.18-dfsg-5) ...
Loading new virtualbox-6.1.18 DKMS files...
Building for 5.11.0-18-generic
Building initial module for 5.11.0-18-generic
Secure Boot not enabled on this system.
Done.
vboxdrv.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.11.0-18-generic/updates/dkms/
vboxnetadp.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.11.0-18-generic/updates/dkms/
vboxnetflt.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.11.0-18-generic/updates/dkms/
depmod....
DKMS: install completed.
但是现在我发现 virtualbox.service 没有运行:
systemctl status virtualbox.service
● virtualbox.service - LSB: VirtualBox Linux kernel module
Loaded: loaded (/etc/init.d/virtualbox; generated)
Active: failed (Result: exit-code) since Sat 2021-06-12 20:05:44 CEST; 5min ago
Docs: man:systemd-sysv-generator(8)
Process: 2331 ExecStart=/etc/init.d/virtualbox start (code=exited, status=1/FAILURE)
Jun 12 20:05:43 icy systemd[1]: Starting LSB: VirtualBox Linux kernel module...
Jun 12 20:05:43 icy virtualbox[2331]: * Loading VirtualBox kernel modules...
Jun 12 20:05:44 icy virtualbox[2331]: * No suitable module for running kernel found
Jun 12 20:05:44 icy virtualbox[2331]: ...fail!
Jun 12 20:05:44 icy systemd[1]: virtualbox.service: Control process exited, code=exited, status=1/FAILURE
Jun 12 20:05:44 icy systemd[1]: virtualbox.service: Failed with result 'exit-code'.
Jun 12 20:05:44 icy systemd[1]: Failed to start LSB: VirtualBox Linux kernel module.
原因似乎出在模块本身:
sudo modprobe vboxdrv
modprobe: ERROR: could not insert 'vboxdrv': Exec format error
所以最后的问题是我该怎么做才能让 DKMS 模块再次运行?
更新 1
根据此处的要求,modinfo 的输出也是:
modinfo vboxdrv
filename: /lib/modules/5.11.0-18-generic/updates/dkms/vboxdrv.ko
version: 6.1.18_Ubuntu r142142 (0x00300000)
license: GPL
description: Oracle VM VirtualBox Support Driver
author: Oracle Corporation
srcversion: 5EB879B583F3535AB3CD593
depends:
retpoline: Y
name: vboxdrv
vermagic: 5.11.0-18-generic SMP mod_unload modversions
sig_id: PKCS#7
signer: icy Secure Boot Module Signature key
sig_key: 23:63:30:57:34:DB:4B:33:E5:70:6F:95:8E:AD:BC:C3:58:DA:A9:35
sig_hashalgo: sha512
signature: 52:41:92:C6:00:84:D2:AC:7C:CB:B2:18:72:35:91:2D:49:AE:5C:CB:
B4:E6:48:00:63:B2:E9:30:3A:68:D8:EC:CA:58:B4:14:0F:4D:4A:C2:
83:BA:70:3A:6E:B8:F2:07:7D:8A:5B:F0:03:C8:83:61:FF:F9:1B:0D:
ED:53:85:FF:6E:4F:C2:8A:1B:B5:4C:DC:79:13:00:D9:F8:87:58:19:
3E:F6:C4:BC:93:5D:9F:6C:60:42:B0:55:8E:A1:B5:9E:50:EB:0C:BB:
92:42:82:BE:F1:24:89:C3:5C:CB:3E:2B:51:66:57:00:62:55:63:2E:
D6:4A:10:47:66:4D:33:F6:0F:DF:02:A3:17:1E:34:7D:BF:64:99:88:
E3:D2:18:DA:B9:39:13:BC:19:28:E3:6A:F4:51:94:41:35:E5:F0:C5:
5E:61:A2:11:C3:1C:D4:4B:7C:09:64:41:C9:A1:D6:73:A2:5C:E9:FF:
21:E4:A3:B7:85:5C:17:AE:75:1A:06:41:3F:63:3A:69:36:2F:3C:C9:
4B:8B:65:FF:92:1B:00:67:43:37:32:91:9A:9E:A6:C9:42:EB:1A:18:
A4:47:89:B2:E0:02:B8:C6:6F:DE:B4:D8:40:34:30:70:84:85:4F:C1:
1D:B2:BA:BE:4A:15:73:6C:C0:99:DE:06:8C:E6:89:74
parm: force_async_tsc:force the asynchronous TSC mode (int)
更新 2
软件包:
dpkg -l *virtualbox*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============================-=========================-============-============================================================
ii virtualbox 6.1.18-dfsg-5 amd64 x86 virtualization solution - base binaries
un virtualbox-2.0 <none> <none> (no description available)
un virtualbox-2.1 <none> <none> (no description available)
un virtualbox-2.2 <none> <none> (no description available)
un virtualbox-3.0 <none> <none> (no description available)
un virtualbox-3.1 <none> <none> (no description available)
un virtualbox-3.2 <none> <none> (no description available)
un virtualbox-4.0 <none> <none> (no description available)
un virtualbox-4.1 <none> <none> (no description available)
un virtualbox-4.2 <none> <none> (no description available)
un virtualbox-4.3 <none> <none> (no description available)
un virtualbox-5.0 <none> <none> (no description available)
un virtualbox-5.1 <none> <none> (no description available)
un virtualbox-5.2 <none> <none> (no description available)
un virtualbox-6.0 <none> <none> (no description available)
rc virtualbox-6.1 6.1.22-144080~Ubuntu~eoan amd64 Oracle VM VirtualBox
ii virtualbox-dkms 6.1.18-dfsg-5 amd64 x86 virtualization solution - kernel module sources for dkms
un virtualbox-guest-additions-iso <none> <none> (no description available)
un virtualbox-guest-dkms <none> <none> (no description available)
un virtualbox-guest-modules <none> <none> (no description available)
un virtualbox-modules <none> <none> (no description available)
un virtualbox-ose <none> <none> (no description available)
ii virtualbox-qt 6.1.18-dfsg-5 amd64 x86 virtualization solution - Qt based user interface
ii virtualbox-source 6.1.18-dfsg-5 amd64 x86 virtualization solution - kernel module source
usr/src:
ls -al /usr/src/
total 900
drwxr-xr-x 29 root root 4096 Jun 12 20:34 .
drwxr-xr-x 14 root root 4096 Apr 23 2020 ..
drwx------ 2 nm-openvpn pulse 4096 Jun 18 2019 evdi-5.2.14
drwxr-xr-x 3 root root 4096 Mai 14 2020 libdvd-pkg
drwxr-xr-x 24 root root 4096 Jun 5 13:55 linux-headers-5.11.0-18
drwxr-xr-x 7 root root 4096 Jun 5 14:13 linux-headers-5.11.0-18-generic
drwxr-xr-x 20 root root 4096 Jun 5 2020 linux-headers-5.4.0-29
drwxr-xr-x 4 root root 4096 Jun 5 2020 linux-headers-5.4.0-29-generic
drwxr-xr-x 3 root root 4096 Jun 16 2020 linux-headers-5.4.0-31
drwxr-xr-x 20 root root 4096 Jul 6 2020 linux-headers-5.4.0-33
drwxr-xr-x 4 root root 4096 Jul 6 2020 linux-headers-5.4.0-33-generic
drwxr-xr-x 20 root root 4096 Jul 6 2020 linux-headers-5.4.0-37
drwxr-xr-x 4 root root 4096 Jul 6 2020 linux-headers-5.4.0-37-generic
drwxr-xr-x 20 root root 4096 Aug 1 2020 linux-headers-5.4.0-39
drwxr-xr-x 4 root root 4096 Aug 1 2020 linux-headers-5.4.0-39-generic
drwxr-xr-x 20 root root 4096 Sep 11 2020 linux-headers-5.4.0-40
drwxr-xr-x 4 root root 4096 Sep 11 2020 linux-headers-5.4.0-40-generic
drwxr-xr-x 20 root root 4096 Sep 16 2020 linux-headers-5.4.0-42
drwxr-xr-x 4 root root 4096 Sep 16 2020 linux-headers-5.4.0-42-generic
drwxr-xr-x 20 root root 4096 Sep 27 2020 linux-headers-5.4.0-45
drwxr-xr-x 4 root root 4096 Sep 27 2020 linux-headers-5.4.0-45-generic
drwxr-xr-x 20 root root 4096 Okt 25 2020 linux-headers-5.4.0-48
drwxr-xr-x 4 root root 4096 Okt 25 2020 linux-headers-5.4.0-48-generic
drwxr-xr-x 20 root root 4096 Nov 3 2020 linux-headers-5.4.0-51
drwxr-xr-x 4 root root 4096 Nov 3 2020 linux-headers-5.4.0-51-generic
drwxr-xr-x 20 root root 4096 Nov 3 2020 linux-headers-5.4.0-52
drwxr-xr-x 4 root root 4096 Nov 3 2020 linux-headers-5.4.0-52-generic
drwxr-xr-x 7 root root 4096 Jun 12 19:57 nvidia-460.80
drwxr-xr-x 11 root root 4096 Jun 12 20:34 virtualbox-6.1.18
-rw-r--r-- 1 root root 802665 Apr 8 20:43 virtualbox.tar.bz2
模块:
ls -al /lib/modules/$(uname -r)/updates/dkms
total 680
drwxr-xr-x 2 root root 4096 Jun 12 20:34 .
drwxr-xr-x 3 root root 4096 Jun 12 20:34 ..
-rw-r--r-- 1 root root 620706 Jun 12 20:34 vboxdrv.ko
-rw-r--r-- 1 root root 17474 Jun 12 20:34 vboxnetadp.ko
-rw-r--r-- 1 root root 44378 Jun 12 20:34 vboxnetflt.ko
dkms 状态:
dkms status
virtualbox, 6.1.18, 5.11.0-18-generic, x86_64: installed
更新 3
以下命令未显示任何结果:
grep -i virtualbox /etc/apt/sources.list
在 sources.list.d 中:
grep -i virtualbox /etc/apt/sources.list.d/*.list
/etc/apt/sources.list.d/virtualbox.list:deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian hirsute contrib
好吧,我会删除这个文件,因为无论如何安装 virtualbox-6.1 都行不通。但我认为根本原因仍然是 DKMS,因为我在从 synaptics.com 的 DisplayLink 驱动程序安装时遇到了同样的问题,例如 evdi.ko。
Synaptics 只显示virtualbox
和virtualbox-6.1
。删除后/etc/apt/sources.list.d/virtualbox.list
只剩virtualbox
下 。
重新安装了 dkms 和 virtualbox。问题依然存在。
更新 4
事实证明,没有 dkms 我甚至无法构建内核模块,所以事情真的很糟糕。
尝试过本教程编写一个简单的 Linux 内核模块
以下是我得到的结果:
user@icy:~/src/lkm-example$ make
make -C /lib/modules/5.11.0-18-generic/build M=/home/user/src/lkm-example modules
make[1]: Entering directory '/usr/src/linux-headers-5.11.0-18-generic'
CC [M] /home/user/src/lkm-example/lkm-example/lkm_example.o
MODPOST /home/user/src/lkm-example/lkm-example/Module.symvers
CC [M] /home/user/src/lkm-example/lkm-example/lkm_example.mod.o
LD [M] /home/user/src/lkm-example/lkm-example/lkm_example.ko
make[1]: Leaving directory '/usr/src/linux-headers-5.11.0-18-generic'
user@icy:~/src/lkm-example$ sudo insmod lkm_example.ko
[sudo] password for user:
insmod: ERROR: could not insert module lkm_example.ko: Invalid module format
user@icy:~/src/lkm-example$ modinfo lkm_example.ko
filename: /home/user/src/lkm-example/lkm_example.ko
version: 0.01
description: A simple example Linux module.
author: Robert W. Oliver II
license: GPL
srcversion: 0EC24E04A8469A9DB84342D
依赖:
retpoline:Y 名称:lkm_example vermagic:5.11.0-18-generic SMP mod_unload modversions
更新 5 - 当前状态
用户@icy:~$ modinfo vboxdrv
filename: /lib/modules/5.11.0-18-generic/updates/dkms/vboxdrv.ko
version: 6.1.18_Ubuntu r142142 (0x00300000)
license: GPL
description: Oracle VM VirtualBox Support Driver
author: Oracle Corporation
srcversion: 5EB879B583F3535AB3CD593
depends:
retpoline: Y
name: vboxdrv
vermagic: 5.11.0-18-generic SMP mod_unload modversions
sig_id: PKCS#7
signer: icy Secure Boot Module Signature key
sig_key: 23:63:30:57:34:DB:4B:33:E5:70:6F:95:8E:AD:BC:C3:58:DA:A9:35
sig_hashalgo: sha512
signature: 52:41:92:C6:00:84:D2:AC:7C:CB:B2:18:72:35:91:2D:49:AE:5C:CB:
B4:E6:48:00:63:B2:E9:30:3A:68:D8:EC:CA:58:B4:14:0F:4D:4A:C2:
83:BA:70:3A:6E:B8:F2:07:7D:8A:5B:F0:03:C8:83:61:FF:F9:1B:0D:
ED:53:85:FF:6E:4F:C2:8A:1B:B5:4C:DC:79:13:00:D9:F8:87:58:19:
3E:F6:C4:BC:93:5D:9F:6C:60:42:B0:55:8E:A1:B5:9E:50:EB:0C:BB:
92:42:82:BE:F1:24:89:C3:5C:CB:3E:2B:51:66:57:00:62:55:63:2E:
D6:4A:10:47:66:4D:33:F6:0F:DF:02:A3:17:1E:34:7D:BF:64:99:88:
E3:D2:18:DA:B9:39:13:BC:19:28:E3:6A:F4:51:94:41:35:E5:F0:C5:
5E:61:A2:11:C3:1C:D4:4B:7C:09:64:41:C9:A1:D6:73:A2:5C:E9:FF:
21:E4:A3:B7:85:5C:17:AE:75:1A:06:41:3F:63:3A:69:36:2F:3C:C9:
4B:8B:65:FF:92:1B:00:67:43:37:32:91:9A:9E:A6:C9:42:EB:1A:18:
A4:47:89:B2:E0:02:B8:C6:6F:DE:B4:D8:40:34:30:70:84:85:4F:C1:
1D:B2:BA:BE:4A:15:73:6C:C0:99:DE:06:8C:E6:89:74
parm: force_async_tsc:force the asynchronous TSC mode (int)
用户@icy:~$ dpkg -l *virtualbox*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============================-=============-============-==========================================>
ii virtualbox 6.1.18-dfsg-5 amd64 x86 virtualization solution - base binaries
un virtualbox-2.0 <none> <none> (no description available)
un virtualbox-2.1 <none> <none> (no description available)
un virtualbox-2.2 <none> <none> (no description available)
un virtualbox-3.0 <none> <none> (no description available)
un virtualbox-3.1 <none> <none> (no description available)
un virtualbox-3.2 <none> <none> (no description available)
un virtualbox-4.0 <none> <none> (no description available)
un virtualbox-4.1 <none> <none> (no description available)
un virtualbox-4.2 <none> <none> (no description available)
un virtualbox-4.3 <none> <none> (no description available)
un virtualbox-5.0 <none> <none> (no description available)
un virtualbox-5.1 <none> <none> (no description available)
un virtualbox-5.2 <none> <none> (no description available)
un virtualbox-6.0 <none> <none> (no description available)
un virtualbox-6.1 <none> <none> (no description available)
ii virtualbox-dkms 6.1.18-dfsg-5 amd64 x86 virtualization solution - kernel modul>
un virtualbox-guest-additions-iso <none> <none> (no description available)
un virtualbox-guest-dkms <none> <none> (no description available)
un virtualbox-guest-modules <none> <none> (no description available)
un virtualbox-modules <none> <none> (no description available)
ii virtualbox-qt 6.1.18-dfsg-5 amd64 x86 virtualization solution - Qt based use>
un virtualbox-source <none> <none> (no description available)
用户@icy:~$ ls -al /usr/src/
total 24
drwxr-xr-x 6 root root 4096 Jun 13 10:51 .
drwxr-xr-x 14 root root 4096 Apr 23 2020 ..
drwxr-xr-x 3 root root 4096 Mai 14 2020 libdvd-pkg
drwxr-xr-x 24 root root 4096 Jun 5 13:55 linux-headers-5.11.0-18
drwxr-xr-x 7 root root 4096 Jun 5 14:13 linux-headers-5.11.0-18-generic
drwxr-xr-x 11 root root 4096 Jun 13 10:51 virtualbox-6.1.18
用户@icy:~$ ls -al /lib/modules/$(uname -r)/updates/dkms
total 680
drwxr-xr-x 2 root root 4096 Jun 13 10:52 .
drwxr-xr-x 3 root root 4096 Jun 13 10:52 ..
-rw-r--r-- 1 root root 620706 Jun 13 10:52 vboxdrv.ko
-rw-r--r-- 1 root root 17474 Jun 13 10:52 vboxnetadp.ko
-rw-r--r-- 1 root root 44378 Jun 13 10:52 vboxnetflt.ko
用户@icy:~$ dkms 状态
virtualbox, 6.1.18, 5.11.0-18-generic, x86_64: installed
用户@icy:~$ grep -i virtualbox /etc/apt/sources.list
<No output here>
用户@icy:~$ grep -i virtualbox /etc/apt/sources.list.d/*.list
<No output here>
答案1
从 20.10 升级到 21.04 后,我遇到了同样的问题,并通过卸载与模块构建相关的所有内容解决了该问题,而无需完全重新安装:
- 我删除了所有版本的 build-essential、gcc、clang、binutils、libtool、autoconf、flex 和 bison。
- 我删除了所有名为 linux-headers-* 的软件包并删除了 /usr/src 中的相应目录。
- 我删除并清除了 dkms 包,并手动删除了 /var/lib/dkms 中的剩余文件。
然后我重新安装了 flex 和 bison(linux-headers 需要,但不会自动安装)和 dkms。
答案2
在执行了各种 Ubuntu 发行版升级后,现在安装 21.04 时会遇到问题。多次发行版升级会导致系统不完整,这并不罕见。
启动到 Ubuntu Live 21.04 USB/DVD 证明问题出在您当前的安装上。
请全新重新安装 Ubuntu 21.04。