Can't sudo apt install anything!

trying to sudo apt install something output:

Removing linux-image-5.10.0-21-arm64 (5.10.162-1) …
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.10.0-21-arm64
/etc/kernel/postrm.d/z50-raspi-firmware:
cp: error writing ‘/boot/firmware/initrd.img-6.1.0-0.deb11.6-arm64’: No space left on device

df -h /boot provides 217G available space.

tested with few different available packages.

please help

Is /boot/firmware in the partition of /boot (No specific partition for /boot/firmware)? What file system type do you use? Also check “df -i” in case.

1 Like

On the Raspberry Pi, we are creating a separate firmware partition. On 64bit images, we have set the size to 256MiB. But for 32bit images, the size is still 64MiB unfortunately. See if moving files temporarily from that partition to another directory outside of /boot/firmware fixes that issue (don’t reboot until you have restored the files, take backups before trying this). If it is a possibility, use the 64bit images. for Raspberry Pi 3 and 4.

First figure out if your system has booted with / mounted read-only. If it is mounted read-write this may help.
Log in to a shell and try touch new-file.txt. If you don’t get an error you are mounted read-write. You should be able to see a new file in this directory named, “new-file.txt,” which will be empty. That being the case you can proceed on. If you get an error, read it carefully, you may be mounted read-only which will happen in cases of severe system distress. My freedombox ran for weeks as a router in read-only mode, so you will not necessarily lose all functionality if mounted read-only, but that’s an indicator you need to fix something serious. Go all the way to the bottom if your system is mounted read-only.

I think I’ve had this problem before, and for me the issue was the accumulation of old kernel packages. When I ls /boot I see this today:
13M grub
30M initrd.img-5.10.0-22-amd64
30M initrd.img-5.10.0-23-amd64
4.0K System.map-5.10.0-22-amd64
4.0K System.map-5.10.0-23-amd64
6.8M vmlinuz-5.10.0-22-amd64
6.8M vmlinuz-5.10.0-23-amd64

When I had the problem I would have seen something like:

30M initrd.img-5.10.0-19-amd64
30M initrd.img-5.10.0-20-amd64
30M initrd.img-5.10.0-21-amd64
30M initrd.img-5.10.0-22-amd64
30M initrd.img-5.10.0-23-amd64

You can see 150MB of initial ramdisk images for various kernel versions. I want to have the current version (5.10.0-23), and one older version (5.10-0-22). For me the older ones can go.

  1. find your oldest kernel version: initrd.img-5.10.0-19-amd64
  2. do a dpkg-query -l and find the name of the associated package:
    rc linux-image-5.10.0-19-amd64 5.10.149-2
  3. try to remove that sigle, very old version kernel package “the right way,” using apt tools. Read the manual page first if you need to: man apt or do an internet search for apt manpage, apt-get manpage, dpkg manpage, etc.
  4. if step #3 fails, and it may if you are critically low on storage, you could manually delete the initrd image which will win you 30MB of free space. Note that the initrd images are not installed with the package, but created by package scripts after the fact. A point of fine distinction. It must not be the only initrd image you have. rm /boot/initrd.img-5.10.0-19.amd64
  5. Now with some free space you should be able to remove that old kernel version the right way using apt tools. Make sure you complete this step so as not to leave some inconsistent boot options in your grub menu. apt remove linux-image-5.10.0-19-amd64
  6. If you get to here successfully you have also removed the old kernel firmware tree which may also have been occupying valuable storage.
  7. If you have enough space now try do do a couple more things to liberate disk space:
    1.1 apt-get autoremove to get rid of packages which satisfied obsolete dependencies - I recall this getting rid of my unwanted old kernel files in the past.
    1.2 apt-get autoclean to remove obsolete downloaded package files
    1.3 apt-get clean to remove cached package files downloaded from your Debian mirror
    1.4 apt-get install --fix-broken will find broken packages in states of partial install and remove them
    1.5 At this point you may find you have more /boot space, and using the package management tools means that your system is likely in a rebootable and runnable state.
    1.6 I would still try to apt update and apt upgrade before rebooting at this point.

If your system is mounted read-only

I don’t know the complete instructions from memory, search out the specifics here.

  1. You need your root password for this. I hope you have it?
  2. Boot in single-user mode. Search the internet for how to do this with Grub. You will modify the grub command at the grub prompt to make linux start in single-user maintenance mode
  3. The system boots and you are prompted for the root password.
  4. The system mounts in single-user (perhaps in read-only mode).
  5. You may need to mount your root file system read-write at this point.
  6. Then go and delete one old initrd.image file (not the current one!)
  7. say a quick prayer and reboot
  8. When the system comes back up, try the instructions at the top for when you are rebooted with / mounted read-write