12

I've been having an error when updating or running any apt command for a week or so. Upgrading to LTS 18.04 hasn't resolved it, nor has removing all old kernels. Space isn't an issue either.

Attempting to reinstall initramfs doesn't work. Error I get is:

   Reading package lists...
Building dependency tree...
Reading state information...
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up linux-image-4.15.0-47-generic (4.15.0-47.50) ...
Setting up initramfs-tools (0.130ubuntu3.7) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for linux-image-4.15.0-47-generic (4.15.0-47.50) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.15.0-47-generic
E: /usr/share/initramfs-tools/hooks/fsck failed with return 1.
update-initramfs: failed for /boot/initrd.img-4.15.0-47-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-4.15.0-47-generic (--configure):
 installed linux-image-4.15.0-47-generic package post-installation script subprocess returned error exit status 1
Processing triggers for initramfs-tools (0.130ubuntu3.7) ...
update-initramfs: Generating /boot/initrd.img-4.15.0-47-generic
E: /usr/share/initramfs-tools/hooks/fsck failed with return 1.
update-initramfs: failed for /boot/initrd.img-4.15.0-47-generic with 1.
dpkg: error processing package initramfs-tools (--configure):
 installed initramfs-tools package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-47-generic
 initramfs-tools

Anyone got any ideas as to what I can do?

Thanks.

11 Answers 11

14

Running auto-remove and clean worked for my situation.

apt-get auto-remove && apt-get clean && apt-get update && apt-get upgrade

2
  • this did it for me Nov 26 '19 at 12:57
  • Thanks, you saved me a few hours of headache trying to reinstall the old version of Nvidia drivers to restore my display setup
    – Moha
    Oct 16 '20 at 18:01
12

For me, it was an issue with the initramfs-tools package

I just did:

# apt remove initramfs-tools

# apt clean

# apt install initramfs-tools

Then I no longer received the error

2
  • 1
    This one works for me Jun 7 at 7:21
  • This works for me too. thx
    – nthack
    Jul 31 at 22:34
5

I had this error since more than a year. Now I found a solution.

cd ~
mkdir initramfs
cd initramfs
cp -r /boot .
cd boot
sudo update-initramfs -ut -b .
sudo cp -r * /boot
sudo apt-get autoremove

Explanation: /boot is on a different partition with insufficient space to perform the operation. Solution: do the update on a drive where there is sufficient space and copy back the results.

1
  • 2
    This is fantastic! I tried the other solutions, but none of them made a difference. This was exactly my problem. I have /boot on a different partition on a USB drive with encryption. For me, your solution didn't actually work, but the explanation gave me what I needed: cd /boot and rm all the old versions of what was in there, then sudo apt update (Adding an answer specific for this for visibility) Jun 26 '20 at 2:29
3

As pointed out by Harald, the problem was insufficient space on the /boot partition.

His solution didn't work for me, but led me directly to what did:

cd /boot, then ls to look at the versions of the files already there. Then rm each of the files that have multiple versions, making sure to delete all but the newest, then sudo apt update

2

A similar question has this solution:

sudo apt-get autoclean
sudo apt-get clean
sudo apt-get update 
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get -f install
sudo dpkg --configure -a

Additionally ensure this command:

ll /usr/share/initramfs-tools/hooks/fsck

returns this output:

-rwxr-xr-x 1 root root 2468 Sep 18  2018 /usr/share/initramfs-tools/hooks/fsck*
2
  • Thanks for your reply, done all that and the problem persists sudo dpkg --configure -a .. update-initramfs: Generating /boot/initrd.img-4.15.0-47-generic E: /usr/share/initramfs-tools/hooks/fsck failed with return 1. update-initramfs: failed for /boot/initrd.img-4.15.0-47-generic with 1. run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1 dpkg: error processing package linux-image-4.15.0-47-generic (--configure): Errors ..processing: linux-image-4.15.0-47-generic initramfs-tools linux-image-4.15.0-48-generic the ll command returns the expected output.
    – adieb
    Apr 25 '19 at 8:23
  • I also did sudo apt autoremove Dec 8 '19 at 11:23
2
sudo apt remove initramfs-tools
sudo apt clean
sudo apt install initramfs-tools
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get clean
sudo apt-get update 
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get -f install
sudo dpkg --configure -a

This was the solution for me.

2
  • The first line (sudo apt remove initramfs-tools) helped me; none of the others did. Sep 30 at 5:23
  • (-1) this removes cryptsetup which if you have your disk encrypted (like me) will not allow you to boot into your system. Do NOT do this
    – pzivich
    Oct 18 at 12:34
1

I've just had a very similar issue when I did an sudo apt autoremove and it failed attempting to install kernel files for a kernel I don't have. My uname -a shows I'm using kernel version 5.0.0-20 and running ls -al /boot shows only this and the 5.0.0-17 kernel are installed. However, apt suddenly turned up errors and attempted to install files in my /boot for old kernels including 5.0.0-15, 4.18.0-17, 4.13.0-45. Which is weird.

So I figure that somehow they've altered the logic for dkms (or something related to initramfs) and it checks some other locations to see if kernels might be installed and then does updates on those kernels and replaces missing files.

I'm not sure exactly what fixed it but I did:

sudo apt purge *5.0.0-15* *4.18.0-17* *4.13.0-45* 
#check carefully that it's not removing anything you need though, this is a hammer to crack a nut

ls -al /lib/modules 
# which revealed lots of old module folders that I removed with ...
sudo rm -rf /lib/modules/4.* 
# and similarly for the 5.0.0-15 modules

Then I did:

ls -al /usr/src/ 
# which again showed old source trees that I pruned with
sudo rm -rf sudo rm -rf /usr/src/linux-headers-4.*

Then I did:

locate -e 4.13.0 
# which found old kernel files in
ls -al /var/lib/initramfs-tools/ 
# so I removed with
sudo rm -rf /var/lib/initramfs-tools/4*

I have problems with a very tight /boot folder for historical reasons and so removed old kernel files with:

sudo rm -i /boot/**4* 
# and similar for all but my current and next oldest kernels
# -i is interactive mode so you have to answer 'y' to remove
# that's a really useful safety check, 'sudo rm' is a dangerous tool!

Finally I ran:

sudo apt -f install

Which finished as expected and returned the system to the expected state without attempting to install extraneous kernels. I did not test as I went along so can not guarantee which part fixed it, but it was not harmful to clear those old files out AFAICT.

Aside, checking my /var/log/apt/history.log file, this appears to be the beginning of this particular error:

Start-Date: 2019-07-01  17:59:10
Commandline: /usr/bin/unattended-upgrade
Upgrade: linux-tools-common:amd64 (4.15.0-52.56, 4.15.0-54.58)
End-Date: 2019-07-01  17:59:16

Start-Date: 2019-07-01  17:59:22
Commandline: /usr/bin/unattended-upgrade
Install: linux-image-5.0.0-20-generic:amd64 (5.0.0-20.21~18.04.1, automatic), linux-modules-extra-5.0.0-20-generic:amd64 (5.0.0-20.21~18.04.1, automatic), linux-modules-5.0.0-20-generic:amd64 (5.0.0-20.21~18.04.1, automatic)
Upgrade: linux-image-generic-hwe-18.04-edge:amd64 (5.0.0.17.73, 5.0.0.20.76), linux-image-extra-virtual-hwe-18.04-edge:amd64 (5.0.0.17.73, 5.0.0.20.76)
Error: Sub-process /usr/bin/dpkg returned an error code (1)
End-Date: 2019-07-01  18:00:10

But this may be a false flag as for me the limited /boot space can be the cause of the error code (1).

0

I had this issue on two separate machines today after doing an apt update and apt upgrade except mine was for linux-image-4.15.0-48-generic. (Ubuntu 18.04.2)

My fix was this (reproduced on both machines):

sudo rm /var/lib/dpkg/info/linux-image-4.15.0-48-generic.postinst
sudo dpkg --configure -a
sudo apt-get update

Then reinstall the package:

sudo apt install linux-image-4.15.0-48-generic

This will set the package to manually installed and will replace the *.postinst file.

0

Try purging unused kernels. If problem persists then remove all 'initrd' images with

sudo rm /boot/initrd.img*

then generate new 'initrd' images for all current existing kernels

sudo update-initramfs -c -k all
0

This was happening to me. Ended up being that /boot was full.

Check boot partition space with df -h

Then free up some space with: How do I free up more space in /boot?

0

I followed all the advice here and nothing worked. I fixed it by making sure that the boot/efi partition was mounted, which in my case it wasn't. /etc/fstab was not configured correctly due to the partuuid/uuid/lable not matching. Then I updated and upgraded with no errors, followed by updating grub and a reboot.

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.