错误:无法打开目录 /lib/modules/4.2.0-25-generic:没有此文件或目录

错误:无法打开目录 /lib/modules/4.2.0-25-generic:没有此文件或目录

我将 Ubuntu 15.10 升级到16.04我的麻烦一定在某个地方发生了。

当我想做的时候,我第一次意识到自己的麻烦sudo iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT。我得到了:

modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.2.0-25-generic/modules.dep.bin'
modprobe: FATAL: Module ip_tables not found in directory /lib/modules/4.2.0-25-generic
iptables v1.6.0: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

好的,那么存在一个问题/lib/modules/4.2.0-25-generic......

然后我尝试用 进行修复sudo depmod。但我得到了:

depmod: ERROR: could not open directory /lib/modules/4.2.0-25-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory

现在我想用 重建内核sudo apt-get install --reinstall linux-...,这里有一些版本,例如:

linux-image-3.13.0-24-generic             
linux-image-3.4.0-4-goldfish              
linux-image-4.4.0-21-generic              
linux-image-4.4.0-21-lowlatency           
linux-image-4.4.0-22-generic              
linux-image-4.4.0-22-lowlatency  

但没有linux-image-4.2.0-25-generic。奇怪的是。所以通过升级Linux,不知何故设置了旧的和错误的内核版本。

现在我想查看此版本保存在哪里。我在uname -r命令中找到了它。因此apt-get install linux-image-'uname -r'-dbgsym,就像:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-image-4.2.0-25-generic-dbgsym
E: Couldn't find any package by glob 'linux-image-4.2.0-25-generic-dbgsym'
E: Couldn't find any package by regex 'linux-image-4.2.0-25-generic-dbgsym'

但我不知道如何手动更改uname -r。我也不知道为什么我得到了这个错误的版本。最重要的是,更改是否是个好主意uname

顺便说一句,我使用 Digitalocean 并通过 升级do-release-upgrade

编辑#1

我只是想看看我当前的内核。它实际上是 4.4.0-22:

sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-22-generic
Found initrd image: /boot/initrd.img-4.4.0-22-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done

但 uname 仍然说:

uname -r
4.2.0-25-generic

有人能向我解释一下可能发生了什么以及如何解决吗?

答案1

您无法在 VPS 上安装自己的内核或内核模块。如果您确实需要某些内核模块,则应咨询您的主机。

我认为这个filter模块肯定应该包括在内。

答案2

我只是需要核心在 Digitalocean 中。现在我有了正确的内核 (4.4.0.22),并且 iptables 也正常工作了。 在此处输入图片描述

相关内容