Fix Broken /lib/modules/ and APT Issues

aptbootdiskupdates

I have a machine that went neglected for some time, and ended up with a full disk and full boot partition .. At that point any apt command would not work, because no space.

Before we start, this server runs a minimal MySQL DB — and /var/log/ was at 14MB and /var/mail/ was at 18kb. I also tried to run apt clean and apt autoclean — Disk was still full .. After Googling and Googling .. And EVERY post saying just run apt clean (of course) I decided to attempt to take matters into my own hand and I FAFO.

So I ran uname -r and it cam out

4.4.0-119-generic

So I went into the boot drive and removed anything not 4.4.0-119-generic. This has always been what I would try in the past and it usually clears up enough for me to run a apt install -f and apt autoremove then update-grub — Usually all is gtg after that.

My issue is that there was not enough space on the hard disk to run any apt install or apt autoremove — So I did the same in /usr/src/ and in lib/modules/

RECAP I cleared the usr/src and lib/modules of "unused" kernels.

I believe this is where I messed up. Now when I try to run apt install -f I get

Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 158 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up linux-image-4.4.0-208-generic (4.4.0-208.240) ...
depmod: ERROR: could not open directory /lib/modules/4.4.0-208-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
dpkg: error processing package linux-image-4.4.0-208-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 linux-image-4.4.0-208-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

I see the source of the error (which alerted me to my mistake)

depmod: ERROR: could not open directory /lib/modules/4.4.0-208-generic: No such file or directory

I tried to run sudo apt --fix-broken install as well — Same error — No avail.

What can I do to fix this seemingly monstrous conundrum I have cornered myself into?

Best Answer

Give the package manager what it wants for the purges: If it complains about a missing file, use touch and create the file, make missing directories. Package manager is too stupid to realize missing files should be OK when you're trying to remove them anyway, but it really doesn't care if they are empty substitutes.

Related Question