Score:2

Why does my Linux Kernel have missing directories / files that are crucial for ip_tables to run?

in flag

as mentioned in the header - my Linux Kernel seems to be missing files / directories that are crucial for iptables to run properly. I'm able to temporarily resolve this by reinstalling my kernel, but it's not a permanent resolve as after a reboot I'm back to where I started.

When I run iptables -L I receive an error saying, "Perhaps iptables or your kernel needs to be upgraded." I've found I'm able to resolve this error by running sudo apt-get install --reinstall linux-modules-5.8.0-59-generic. I've noticed that after the reinstall I have additional files and directories in my /lib/modules/5.8.0-59-generic directory, which leads me to believe that my kernel by default is missing these and disabling iptables from functioning properly. After a reboot it goes back to missing these said files/directories and iptables not working.

Is it possible to reinstall the kernel module permanently, so I don't have to reinstall after every reboot to get iptables to work?

I'm running Ubuntu 20.04.2, and as mentioned above my kernel is 5.8.0-59-generic. I appreciate any assistance I can get!

edit:

The output I get from ls /boot/vmlinuz* is: [vmlinuz output]: https://i.stack.imgur.com/dDroe.png OR as text:

/boot/vmlinuz /boot/vmlinuz-5.4.0-77-generic /boot/vmlinuz-5.8.0-48-generic /boot/vmlinuz-5.8.0-55-generic /boot/vmlinuz-5.8.0-59-generic /boot/vmlinuz.old

And the ouput I get from apt-cache policy linux-image-generic is: [apt-cache output]: https://i.stack.imgur.com/OY9Cj.png OR as text:

linux-image-generic: Installed: 5.4.0.77.80 Candidate: 5.4.0.77.80 Version table: *** 5.4.0.77.80 500 500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages 500 http://archive.ubuntu.com/ubuntu focal-security/main amd64 Packages 100 /var/lib/dpkg/status 5.4.0.26.32 500 500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages

The computer that is running is a Dell Optiplex 3020 with specs of:

  • CPU: Quad Core Intel(R) Core(TM) i5-4570 CPU @ 3.20 GHz
  • RAM: 8Gb ram

edit: I'm unsure how the output from these commands will help me, and I'd really appreciate further guidance as I'm still no closer to getting this resolved!

vidarlo avatar
ar flag
Please [edit] your post to include the output of `ls /boot/vmlinuz*` and `apt-cache policy linux-image-generic`.
Michael Hampton avatar
cz flag
Please describe the computer on which you are running Ubuntu.
Landon Miller avatar
in flag
Thanks for your replies, @vidarlo and Michael Hampton! I updated my post, so hopefully you guys can assist more!
vidarlo avatar
ar flag
@LandonMiller Please don't paste text as images, paste it as text and format it with the `{}`-button.
Landon Miller avatar
in flag
I edited my post to include the output as text @vidarlo. I really appreciate your assistance!
mm flag
I have the same problem as @LandonMiller, on 20.04.4 LTS (focal)
Landon Miller avatar
in flag
@Titou I posted what I had to do to resolve the issue. Maybe try that and see if it works?
Score:1
no flag

The kernel that you are booting with is not the one that you've installed. In short, the modules that you installed is for another - possibly older or newer kernel, as selected by the bootloader, which was likely not updated.

You can verify this with cat /proc/version. This will show the currently running kernel. apt install --reinstall linux-modules-`cut -d\ -f3 /proc/version` should install the correct version.

You can use dpkg -l|grep linux- to see what is installed.

As for getting the bootloader to stop rebooting into the same old version, sudo update-grub might resolve that. Alternatively you can view /boot/grub/grub.cfg for more information, or hold Shift or press ESC when booting and select the appropriate kernel. (See https://askubuntu.com/questions/281119/how-do-you-run-update-grub for more troubleshooting)

Even though Linux follows a "monolithic" design where most functionality can be built into the kernel itself, there is so much functionality available nowadays that it makes more sense to move as much of that functionality - such as iptables - out into "loadable kernel modules". It has a great feature where it "autoloads" these modules as needed - but these modules are usually very specific to the kernel version - and it not finding those - see ls /usr/lib/modules/* - is what gave you the error message.

You can view what modules are currently loaded with lsmod. You can also load modules with insmod and unload them with rmmod. (See man insmod and so on.)

Computers have changed so much in the last 30 years, that instead of just storing the modules on the main partition, they need to be stored in a temporary RAM disk initrd because sometimes those modules are needed to access the actual hard drive or filesystem. update-grub takes care of storing copies of the required modules in the relevant initrd for the relevant Linux kernels.

Generally, as long as a kernel can read your root filesystem somehow, you can boot any Linux root filesystem using any kernel. So you can usually easily repair - or backup your system by booting from a live bootable Linux, then mounting your main filesystem. (To find it see lsblk and mount) To work on your actual system even though you booted from another, see chroot. For example, if you live boot, and your hard drive shows up as /dev/sdb1 then you can fsck /dev/sdb and then mount /dev/sdb1 /mnt, and then sudo mount -t proc - /mnt/sdb1/proc; sudo mount -o bind /dev /mnt/sdb1/dev; sudo chroot /mnt/sdb1 and then you can run apt install or update-grub and exit and sudo reboot.)

Files can get corrupted or missing due to many factors - low disk space, loose cables, damaged hardware, power outages, EMF, cosmic rays. Modern software is good at working around much of this. The great thing about Linux as opposed to other systems, is that it gives you much more of an opportunity to repair it, as opposed to just reinstalling - and learning more about how it works in the process.

mm flag
Great answer. I agree with the fact that repairing should come up with additional knowledge.
Score:0
in flag

For @Titou... I think I was having this error because of a corrupted kernel?? I resolved the issue by backing up and re-installing Ubuntu OS. After doing this, I haven't had an issue since.

no flag
Corrupted - or missing - "kernel modules". As for backing up, you should only need to backup if you're reformatting - which is not a bad idea if you have a corrupted filesystem and `fsck` can't fix it. If you do backup, the nice thing about Linux is that you only have to backup `/home`. Unless you're hosting websites and databases, in which case the configuration is in `/etc` and the data in `/var`. If you've got docker images, best to export them because just backing up `/var/lib/docker` will end up using many times as much space as the actual images, as the deduplication might not be kept.
mm flag
Thanks for the solution !
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.