1

The other day I was cleaning some disk space. I deleted some directories with the Linux Kernel headers. Now I see a lot of errors complaining about missing Linux headers. I tried to reinstall them but, can't find them.

I've already researched many commands but, none of them work. This is what I have tried so far:

linux@linux:~$ sudo apt-get install uswsusp
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libx86-1
The following NEW packages will be installed:
  libx86-1 uswsusp
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 220 kB of archives.
After this operation, 977 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirror.ufscar.br/ubuntu bionic/universe amd64 libx86-1 amd64 1.1+ds1-10.2 [75,2 kB]
Get:2 http://mirror.ufscar.br/ubuntu bionic/universe amd64 uswsusp amd64 1.0+20120915-6.1build1 [145 kB]
Fetched 220 kB in 1s (297 kB/s)  
Preconfiguring packages ...
Selecting previously unselected package libx86-1:amd64.
(Reading database ... 385946 files and directories currently installed.)
Preparing to unpack .../libx86-1_1.1+ds1-10.2_amd64.deb ...
Unpacking libx86-1:amd64 (1.1+ds1-10.2) ...
Selecting previously unselected package uswsusp.
Preparing to unpack .../uswsusp_1.0+20120915-6.1build1_amd64.deb ...
Unpacking uswsusp (1.0+20120915-6.1build1) ...
Setting up libx86-1:amd64 (1.1+ds1-10.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up uswsusp (1.0+20120915-6.1build1) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools (0.130ubuntu3.7) ...
update-initramfs: Generating /boot/initrd.img-4.15.0-46-generic
WARNING: missing /lib/modules/4.15.0-46-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
0depmod: WARNING: could not open /var/tmp/mkinitramfs_x156QB/lib/modules/4.15.0-46-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_x156QB/lib/modules/4.15.0-46-generic/modules.builtin: No such file or directory

linux@linux:~$ sudo dpkg-reconfigure uswsusp
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools (0.130ubuntu3.7) ...
update-initramfs: Generating /boot/initrd.img-4.15.0-46-generic
WARNING: missing /lib/modules/4.15.0-46-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_PgcUvV/lib/modules/4.15.0-46-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_PgcUvV/lib/modules/4.15.0-46-generic/modules.builtin: No such file or directory

linux@linux:~$ sudo apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
linux-headers-4.15.0-46-generic is already the newest version (4.15.0-46.49).
linux-headers-4.15.0-46-generic set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 32 not upgraded.

linux@linux:~$ sudo apt-get update && sudo apt-get upgrade
Ign:1 http://mirror.ufscar.br/mint-archive tessa InRelease
Hit:2 http://mirror.ufscar.br/ubuntu bionic InRelease                                                                                                                                                                
Hit:3 http://mirror.ufscar.br/ubuntu bionic-updates InRelease                                                                                                                                                                               
Hit:4 http://mirror.ufscar.br/ubuntu bionic-backports InRelease                                                                                                                                                                             
Hit:5 http://mirror.ufscar.br/mint-archive tessa Release                                                                                                                                                                                    
Hit:6 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                                                                                                                
Hit:7 http://archive.canonical.com/ubuntu bionic InRelease                                                                                                                       
Hit:8 http://ppa.launchpad.net/hluk/copyq/ubuntu bionic InRelease                                                                
Hit:9 https://download.sublimetext.com apt/stable/ InRelease                                               
Hit:11 http://ppa.launchpad.net/kubuntu-ppa/backports/ubuntu bionic InRelease                       
Reading package lists... Done                      
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  libnss-myhostname libnss-systemd libpam-systemd libpoppler-glib8 libpoppler-qt5-1 libpoppler73 libseccomp2 libsystemd0 libudev1 libxcb-composite0 libxcb-damage0 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-randr0
  libxcb-record0 libxcb-render0 libxcb-res0 libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb-xinerama0 libxcb-xkb1 libxcb-xv0 libxcb1 libxcb1-dev poppler-utils systemd systemd-sysv udev
32 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 6.053 kB of archives.
After this operation, 16,4 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libnss-systemd amd64 237-3ubuntu10.15 [105 kB]
0% [1 libnss-systemd 13,9 kB/105 kB 13%]
Get:2 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libsystemd0 amd64 237-3ubuntu10.15 [205 kB]
Get:3 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 systemd amd64 237-3ubuntu10.15 [2.899 kB]
Get:4 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libpam-systemd amd64 237-3ubuntu10.15 [108 kB]
Get:5 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libnss-myhostname amd64 237-3ubuntu10.15 [34,4 kB]
Get:6 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 udev amd64 237-3ubuntu10.15 [1.100 kB]
Get:7 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libudev1 amd64 237-3ubuntu10.15 [54,2 kB]
Get:8 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 systemd-sysv amd64 237-3ubuntu10.15 [12,0 kB]
Get:9 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libseccomp2 amd64 2.3.1-2.1ubuntu4.1 [39,1 kB]
Get:10 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb1-dev amd64 1.13-2~ubuntu18.04 [80,0 kB]
Get:11 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb1 amd64 1.13-2~ubuntu18.04 [45,5 kB]
Get:12 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-render0 amd64 1.13-2~ubuntu18.04 [14,7 kB]
Get:13 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-shm0 amd64 1.13-2~ubuntu18.04 [5.600 B]
Get:14 http://mirror.ufscar.br/ubuntu bionic-updates/universe amd64 libpoppler-qt5-1 amd64 0.62.0-2ubuntu2.8 [140 kB]
Get:15 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 poppler-utils amd64 0.62.0-2ubuntu2.8 [154 kB]
Get:16 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libpoppler-glib8 amd64 0.62.0-2ubuntu2.8 [108 kB]
Get:17 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libpoppler73 amd64 0.62.0-2ubuntu2.8 [799 kB]
Get:18 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-composite0 amd64 1.13-2~ubuntu18.04 [5.184 B]
Get:19 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-damage0 amd64 1.13-2~ubuntu18.04 [4.872 B]
Get:20 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-dri2-0 amd64 1.13-2~ubuntu18.04 [6.920 B]
Get:21 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-dri3-0 amd64 1.13-2~ubuntu18.04 [6.568 B]
Get:22 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-glx0 amd64 1.13-2~ubuntu18.04 [22,1 kB]
Get:23 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-present0 amd64 1.13-2~ubuntu18.04 [5.552 B]
Get:24 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-randr0 amd64 1.13-2~ubuntu18.04 [16,4 kB]
Get:25 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-record0 amd64 1.13-2~ubuntu18.04 [7.064 B]
Get:26 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-res0 amd64 1.13-2~ubuntu18.04 [6.392 B]
Get:27 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-shape0 amd64 1.13-2~ubuntu18.04 [5.972 B]
Get:28 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-sync1 amd64 1.13-2~ubuntu18.04 [8.808 B]
Get:29 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-xfixes0 amd64 1.13-2~ubuntu18.04 [9.352 B]
Get:30 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-xinerama0 amd64 1.13-2~ubuntu18.04 [5.264 B]
Get:31 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-xkb1 amd64 1.13-2~ubuntu18.04 [30,1 kB]
Get:32 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 libxcb-xv0 amd64 1.13-2~ubuntu18.04 [9.168 B]
Fetched 6.053 kB in 3s (2.331 kB/s)    
Extracting templates from packages: 100%
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../libnss-systemd_237-3ubuntu10.15_amd64.deb ...
Unpacking libnss-systemd:amd64 (237-3ubuntu10.15) over (237-3ubuntu10.13) ...
Preparing to unpack .../libsystemd0_237-3ubuntu10.15_amd64.deb ...
Unpacking libsystemd0:amd64 (237-3ubuntu10.15) over (237-3ubuntu10.13) ...
Setting up libsystemd0:amd64 (237-3ubuntu10.15) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../systemd_237-3ubuntu10.15_amd64.deb ...
Unpacking systemd (237-3ubuntu10.15) over (237-3ubuntu10.13) ...
Setting up systemd (237-3ubuntu10.15) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../libpam-systemd_237-3ubuntu10.15_amd64.deb ...
Unpacking libpam-systemd:amd64 (237-3ubuntu10.15) over (237-3ubuntu10.13) ...
Setting up libpam-systemd:amd64 (237-3ubuntu10.15) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../libnss-myhostname_237-3ubuntu10.15_amd64.deb ...
Unpacking libnss-myhostname:amd64 (237-3ubuntu10.15) over (237-3ubuntu10.13) ...
Preparing to unpack .../udev_237-3ubuntu10.15_amd64.deb ...
Unpacking udev (237-3ubuntu10.15) over (237-3ubuntu10.13) ...
Preparing to unpack .../libudev1_237-3ubuntu10.15_amd64.deb ...
Unpacking libudev1:amd64 (237-3ubuntu10.15) over (237-3ubuntu10.13) ...
Setting up libudev1:amd64 (237-3ubuntu10.15) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../systemd-sysv_237-3ubuntu10.15_amd64.deb ...
Unpacking systemd-sysv (237-3ubuntu10.15) over (237-3ubuntu10.13) ...
Setting up systemd-sysv (237-3ubuntu10.15) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../libseccomp2_2.3.1-2.1ubuntu4.1_amd64.deb ...
Unpacking libseccomp2:amd64 (2.3.1-2.1ubuntu4.1) over (2.3.1-2.1ubuntu4) ...
Setting up libseccomp2:amd64 (2.3.1-2.1ubuntu4.1) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../libxcb1-dev_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb1-dev:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../libxcb1_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb1:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Setting up libxcb1:amd64 (1.13-2~ubuntu18.04) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../libxcb-render0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-render0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Setting up libxcb-render0:amd64 (1.13-2~ubuntu18.04) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../libxcb-shm0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-shm0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Setting up libxcb-shm0:amd64 (1.13-2~ubuntu18.04) ...
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../00-libpoppler-qt5-1_0.62.0-2ubuntu2.8_amd64.deb ...
Unpacking libpoppler-qt5-1:amd64 (0.62.0-2ubuntu2.8) over (0.62.0-2ubuntu2.7) ...
Preparing to unpack .../01-poppler-utils_0.62.0-2ubuntu2.8_amd64.deb ...
Unpacking poppler-utils (0.62.0-2ubuntu2.8) over (0.62.0-2ubuntu2.7) ...
Preparing to unpack .../02-libpoppler-glib8_0.62.0-2ubuntu2.8_amd64.deb ...
Unpacking libpoppler-glib8:amd64 (0.62.0-2ubuntu2.8) over (0.62.0-2ubuntu2.7) ...
Preparing to unpack .../03-libpoppler73_0.62.0-2ubuntu2.8_amd64.deb ...
Unpacking libpoppler73:amd64 (0.62.0-2ubuntu2.8) over (0.62.0-2ubuntu2.7) ...
Preparing to unpack .../04-libxcb-composite0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-composite0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../05-libxcb-damage0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-damage0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../06-libxcb-dri2-0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-dri2-0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../07-libxcb-dri3-0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-dri3-0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../08-libxcb-glx0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-glx0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../09-libxcb-present0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-present0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../10-libxcb-randr0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-randr0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../11-libxcb-record0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-record0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../12-libxcb-res0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-res0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../13-libxcb-shape0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-shape0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../14-libxcb-sync1_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-sync1:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../15-libxcb-xfixes0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-xfixes0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../16-libxcb-xinerama0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-xinerama0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../17-libxcb-xkb1_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-xkb1:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Preparing to unpack .../18-libxcb-xv0_1.13-2~ubuntu18.04_amd64.deb ...
Unpacking libxcb-xv0:amd64 (1.13-2~ubuntu18.04) over (1.13-1) ...
Setting up libxcb-xinerama0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-present0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libnss-systemd:amd64 (237-3ubuntu10.15) ...
Setting up libxcb-composite0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-dri2-0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-dri3-0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-glx0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-randr0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-xfixes0:amd64 (1.13-2~ubuntu18.04) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up libnss-myhostname:amd64 (237-3ubuntu10.15) ...
Setting up libxcb-res0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-record0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-damage0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb-sync1:amd64 (1.13-2~ubuntu18.04) ...
Setting up libpoppler73:amd64 (0.62.0-2ubuntu2.8) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up udev (237-3ubuntu10.15) ...
update-initramfs: deferring update (trigger activated)
Setting up libxcb-xv0:amd64 (1.13-2~ubuntu18.04) ...
Processing triggers for systemd (237-3ubuntu10.15) ...
Setting up libxcb-shape0:amd64 (1.13-2~ubuntu18.04) ...
Setting up libxcb1-dev:amd64 (1.13-2~ubuntu18.04) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for dbus (1.12.2-1ubuntu1) ...
Setting up libxcb-xkb1:amd64 (1.13-2~ubuntu18.04) ...
Setting up libpoppler-glib8:amd64 (0.62.0-2ubuntu2.8) ...
Setting up poppler-utils (0.62.0-2ubuntu2.8) ...
Setting up libpoppler-qt5-1:amd64 (0.62.0-2ubuntu2.8) ...
Processing triggers for initramfs-tools (0.130ubuntu3.7) ...
update-initramfs: Generating /boot/initrd.img-4.15.0-46-generic
WARNING: missing /lib/modules/4.15.0-46-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_TKdkq1/lib/modules/4.15.0-46-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_TKdkq1/lib/modules/4.15.0-46-generic/modules.builtin: No such file or directory
Processing triggers for libc-bin (2.27-3ubuntu1) ...

linux@linux:~$ sudo apt install linux-image-4.15.0-46-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
linux-image-4.15.0-46-generic is already the newest version (4.15.0-46.49).
linux-image-4.15.0-46-generic set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

linux@linux:~$ sudo apt install linux-image-4.15.0-46-generic --reinstall
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 7.904 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 linux-image-4.15.0-46-generic amd64 4.15.0-46.49 [7.904 kB]
Fetched 7.904 kB in 3s (3.111 kB/s)                        
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../linux-image-4.15.0-46-generic_4.15.0-46.49_amd64.deb ...
Unpacking linux-image-4.15.0-46-generic (4.15.0-46.49) over (4.15.0-46.49) ...
Setting up linux-image-4.15.0-46-generic (4.15.0-46.49) ...
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
dpkg: error processing package linux-image-4.15.0-46-generic (--configure):
 installed linux-image-4.15.0-46-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-46-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

linux@linux:~$ sudo dpkg --purge linux-image-4.15.0-46-generic
dpkg: dependency problems prevent removal of linux-image-4.15.0-46-generic:
 linux-image-generic depends on linux-image-4.15.0-46-generic.
 linux-modules-extra-4.15.0-46-generic depends on linux-image-4.15.0-46-generic | linux-image-unsigned-4.15.0-46-generic; however:
  Package linux-image-4.15.0-46-generic is to be removed.
  Package linux-image-unsigned-4.15.0-46-generic is not installed.

dpkg: error processing package linux-image-4.15.0-46-generic (--purge):
 dependency problems - not removing
Errors were encountered while processing:
 linux-image-4.15.0-46-generic

linux@linux:~$ sudo apt-get install linux-image-4.15.0-46-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
linux-image-4.15.0-46-generic is already the newest version (4.15.0-46.49).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up linux-image-4.15.0-46-generic (4.15.0-46.49) ...
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
dpkg: error processing package linux-image-4.15.0-46-generic (--configure):
 installed linux-image-4.15.0-46-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-46-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

linux@linux:~$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 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.15.0-46-generic (4.15.0-46.49) ...
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
dpkg: error processing package linux-image-4.15.0-46-generic (--configure):
 installed linux-image-4.15.0-46-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-46-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

linux@linux:~$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 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.15.0-46-generic (4.15.0-46.49) ...
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
dpkg: error processing package linux-image-4.15.0-46-generic (--configure):
 installed linux-image-4.15.0-46-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-46-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

linux@linux:~$ sudo apt upgrade --fix-missing
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up linux-image-4.15.0-46-generic (4.15.0-46.49) ...
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
dpkg: error processing package linux-image-4.15.0-46-generic (--configure):
 installed linux-image-4.15.0-46-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-46-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

linux@linux:~$ sudo apt install --reinstall linux-headers-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 2.376 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://mirror.ufscar.br/ubuntu bionic-updates/main amd64 linux-headers-generic amd64 4.15.0.46.48 [2.376 B]
Fetched 2.376 B in 0s (10,5 kB/s)                 
(Reading database ... 385977 files and directories currently installed.)
Preparing to unpack .../linux-headers-generic_4.15.0.46.48_amd64.deb ...
Unpacking linux-headers-generic (4.15.0.46.48) over (4.15.0.46.48) ...
Setting up linux-image-4.15.0-46-generic (4.15.0-46.49) ...
depmod: ERROR: could not open directory /lib/modules/4.15.0-46-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
dpkg: error processing package linux-image-4.15.0-46-generic (--configure):
 installed linux-image-4.15.0-46-generic package post-installation script subprocess returned error exit status 1
Setting up linux-headers-generic (4.15.0.46.48) ...
Errors were encountered while processing:
 linux-image-4.15.0-46-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
  • If the header packages are still marked as installed in apt, you might have to "uninstall" them with and then install them again. – Gerowen Mar 12 '19 at 1:58
3

From: How to install Linux Kernel headers on Debian or Ubuntu

sudo apt-get install --reinstall linux-headers-$(uname -r)

Then:

sudo apt-get update && sudo apt-get upgrade
|improve this answer|||||
  • I already ran this command, if you look into the log output I presented, and you will notice the problem persists on the next commands which come after. – user Mar 12 '19 at 1:53
  • @user I added --reinstall option to force complete installation. – WinEunuuchs2Unix Mar 12 '19 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.