0
uname -r

5.15.0-60-generic

My apt upgrade is failing with:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
  mc libmagickcore-6.q16-6-extra node-hosted-git-info imagemagick libzmq5
  python2.7-minimal libmagickwand-6.q16-6 python2.7 python3-rsa mc-data
  node-tar imagemagick-6.q16 libeditorconfig0 libjs-jquery-ui libopenexr24
  libsdl2-2.0-0 libmysofa1 libmagickcore-6.q16-6 glances libpython2.7-minimal
  libpython2.7-stdlib imagemagick-6-common
Learn more about Ubuntu Pro at https://ubuntu.com/pro
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
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-firmware (1.187.36) ...
update-initramfs: Generating /boot/initrd.img-5.15.0-60-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.15.0-60-generic with 1.
dpkg: error processing package linux-firmware (--configure):
 installed linux-firmware package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-firmware
E: Sub-process /usr/bin/dpkg returned an error code (1)

  1. First of all, I'm a little confused by this. I seem to be ON 5.15.0-60-generic already, why is it trying to
update-initramfs: failed for /boot/initrd.img-5.15.0-60-generic with 1.

?

  1. I presume this is due to low disk space:
df -H

Filesystem                 Size  Used Avail Use% Mounted on
udev                       135G     0  135G   0% /dev
tmpfs                       28G  3.0M   28G   1% /run
/dev/mapper/vgubuntu-root  982G  838G   94G  90% /
tmpfs                      136G  296M  135G   1% /dev/shm
tmpfs                      5.3M  4.1k  5.3M   1% /run/lock
tmpfs                      136G     0  136G   0% /sys/fs/cgroup
/dev/nvme0n1p2             738M  588M   97M  86% /boot
/dev/nvme0n1p1             536M  6.4M  530M   2% /boot/efi
/dev/sda2                  7.0T  1.5T  5.2T  23% /mnt/usb-8tb
tmpfs                       28G   25k   28G   1% /run/user/125
tmpfs                       28G   70k   28G   1% /run/user/1000

So I'm trying to remove old linux kernels, which seems to be taking space:

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n  | grep linux-image
20      linux-image-generic-hwe-20.04
9520    linux-image-5.8.0-43-generic
9927    linux-image-5.11.0-36-generic
9928    linux-image-5.11.0-37-generic
9933    linux-image-5.11.0-38-generic
9956    linux-image-5.13.0-25-generic
9956    linux-image-5.13.0-27-generic
9965    linux-image-5.13.0-28-generic
9965    linux-image-5.13.0-30-generic
9965    linux-image-5.13.0-35-generic
9968    linux-image-5.13.0-37-generic
9968    linux-image-5.13.0-39-generic
9971    linux-image-5.13.0-40-generic
9971    linux-image-5.13.0-41-generic
9971    linux-image-5.13.0-44-generic
9972    linux-image-5.13.0-48-generic
9973    linux-image-5.13.0-51-generic
9973    linux-image-5.13.0-52-generic
10775   linux-image-5.15.0-41-generic
10778   linux-image-5.15.0-43-generic
11196   linux-image-5.15.0-46-generic
11207   linux-image-5.15.0-52-generic
11208   linux-image-5.15.0-50-generic
11209   linux-image-5.15.0-48-generic
11210   linux-image-5.15.0-53-generic
11212   linux-image-5.15.0-56-generic
11214   linux-image-5.15.0-57-generic
11215   linux-image-5.15.0-58-generic
11223   linux-image-5.15.0-60-generic
11499   linux-image-5.11.0-40-generic
11502   linux-image-5.11.0-41-generic
11502   linux-image-5.11.0-43-generic
11504   linux-image-5.11.0-44-generic
11504   linux-image-5.11.0-46-generic
  1. But when trying to remove any of the older ones, it says it will only free up 0 bytes.

Appreciate some guidance here on those questions - many thanks.

Nik
  • 437
  • 7
  • 16
  • 1
    Regardless of whether removing many of them releases 0bytes, having that many installed seems ludicrous. – Bib Feb 19 '23 at 11:30
  • 1
    Have you tried to `fsck` the disk? (example [link](https://phoenixnap.com/kb/fsck-command-linux)) – harrymc Feb 19 '23 at 11:35
  • @harrymc I have not no. Is it safe to unmount the boot partition to do so? (I guess /dev/nvme0n1p2 in my case?) Actually, from the output above, it's not quite clear to me what's failing. Does it write to (encrypted) swap (/dev/mapper/vgubuntu-swap_1) as a temporary step, and that is what is failing? – Nik Feb 19 '23 at 12:06
  • The only time when `/boot` needs to be mounted is when you are updating the kernel. Completely possible to unmount at any time or even to set it to `noauto` in database. You can ignore the zero byte message and remove anyway. Maybe the fsck first but possibly the message is wrong. – doneal24 Feb 19 '23 at 13:50
  • 2
    Just nuke (eg: `: > somefile`) older initramfs files in /boot to free some space for the upgrade for your current kernel's initramfs to succeed. Then remove older kernels packages. – A.B Feb 19 '23 at 16:05
  • 1
    See https://markmcb.com/2013/02/04/cleanup-unused-linux-kernels-in-ubuntu/ Also: *Edit the file '/etc/dnf/dnf.conf', changing the numeric value in **installonly_limit=3** to a number of your choosing.* See https://superuser.com/questions/1423559/how-can-i-change-the-number-of-kernels-retained-when-updating-in-fedora – DrMoishe Pippik Feb 19 '23 at 16:57
  • dnf <- for Ubuntu? Really? I'd expect to see `apt` in there. – Hannu Feb 19 '23 at 18:08
  • google "unattended upgrade ubuntu" – Hannu Feb 19 '23 at 18:15

1 Answers1

0

Assumption: fsck is ok, i.e. not complaining.

Now,

Leave linux-image-generic-hwe-20.04 in place as that is a meta-package that is used for coming updates of your ubuntu.

The other ones are just taking up space, except the one printed by uname -r and maybe one prior to it (as a backup, for safety in case of malfunction in the latest).

These other-ones SHOULD be removable with e.g.
sudo apt purge linux-image-5.8.0-43-generic (for the first in your list (above)
you may also add more of them after the first one, just make sure there is at least one space in between each of them.

... or even do
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | grep linux-image >~/kernels

Then make sure there is just names of ones to remove in that file...
(edit with e.g. nano ~/kernels, leave only packages to remove in there, save the file)
then do:

sudo apt purge $(cat ~/kernels)
... or similar.

Hannu
  • 8,740
  • 3
  • 21
  • 39
  • Thanks for this. I'm a little nervous to nuke things without understanding this bit: " I seem to be ON 5.15.0-60-generic already, why is it trying to update-initramfs: failed for /boot/initrd.img-5.15.0-60-generic" - any ideas? – Nik Feb 19 '23 at 18:45
  • `initramfs` is a "linux" running for a few moments while the main Linux is about to boot. And the reason for the update failure is most likely "Space too low" - the update cannot create what it needs. So: One way to free up some is to "nuke some old file" - as A.B. put it. e.g. `sudo echo >/boot/initrd.img-x.xx.x-xx-generic` for an OLD version of initrd. – Hannu Feb 20 '23 at 22:07
  • so at this point initramfs is running an old kernel (NOT 5.15.0-60), while my main system is running the latest? (5.15.0-60)...? – Nik Feb 21 '23 at 09:27
  • Seems likely as installation failed. – Hannu Feb 21 '23 at 17:07