6

I'm running Ubuntu 14.04.4 LTS, and I'm trying to install a new package using apt-get. Unfortunately, whenever I try I get messages like:

The following packages have unmet dependencies:
 linux-image-extra-3.16.0-70-generic : Depends: linux-image-3.16.0-70-generic but it is not going to be installed
 linux-image-generic-lts-utopic : Depends: linux-image-3.16.0-70-generic but it is not going to be installed
 linux-signed-image-3.16.0-70-generic : Depends: linux-image-3.16.0-70-generic (= 3.16.0-70.90~14.04.1) but it is not going to be installed

Doing some googling, I found that this can be caused by lack of space on the boot partition (and sure enough, df shows /boot at 100%). However, any time I try running the apt-get commands in the accepted answer there, I get the same errors as above.

Looking for another solution that didn't use apt-get, I came across this post, which recommends using things like sudo dpkg --purge linux-image-4.2.0-15-generic on old, unused kernels.

dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r) (from the afore-mentioned post) shows that I have several old kernels in the pi state (desired purged, state is installed according to this)

uname -r tells me the kernel I'm running is 3.16.0-62-generic, so I thought I should be safe to remove these old kernels. However, trying to do so with things like sudo dpkg --purge linux-image-3.16.0-49-generic results in:

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

Garrg! I'm at my wit's end, and out of my depth (don't really know much about dpkg or apt-get), so I need some help.

Questions:

  1. Why can't I uninstall the old kernels with dpkg?

  2. If that question can't be directly solved, I guess ultimately I want to know: What do I need to do to get into a state where I can install new packages again?


Other things I have tried:

  • sudo apt-get autoremove : results in the original error about unmet dependencies
  • sudo apt-get -f autoremove : results in:
Unpacking linux-image-3.16.0-70-generic (3.16.0-70.90~14.04.1) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-3.16.0-70-generic_3.16.0-70.90~14.04.1_amd64.deb (--unpack):
 cannot copy extracted data for './boot/vmlinuz-3.16.0-70-generic' to '/boot/vmlinuz-3.16.0-70-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
                                                                              dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.16.0-70-generic /boot/vmlinuz-3.16.0-70-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.16.0-70-generic /boot/vmlinuz-3.16.0-70-generic
Errors were encountered while processing:
 /var/cache/apt/archives/linux-image-3.16.0-70-generic_3.16.0-70.90~14.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Note: I've migrated this question from "Unix & Linux Stack Exchange"

0

1 Answer 1

4

Use uname -r to show your currently running kernel. DO NOT DELETE anything with this version number.

You can find which packages the kernels in /boot belong to:

for i in /boot/vmlinuz* ; do 
    dpkg -S $i| egrep -v $(uname -r)
done

You can remove these packages with sudo apt-get purge packagename ....

You can find more packages related to the kernels to be deleted by looking for other packages with the same version number:

To extract the version numbers:

for i in /boot/vmlinuz* ; do 
    dpkg -S $i | egrep -v $(uname -r)
done |cut -d- -f3-4  

To find other packages with the same version numbers:

for j in $(
    for i in /boot/vmlinuz* ; do 
        dpkg -S $i| egrep -v $(uname -r)
    done |cut -d- -f3-4 ) ; 
do 
     dpkg -l "*$j*" | egrep '^ii|^rc'
done  

To automate deleting all kernels other than the current kernel, and all packages whose versions match the deleted kernels (Danger, Wil Robinson):

Simply append

| awk '{print $2}' | xargs sudo apt-get --dry-run purge

to the previous code fragment. WHen you're sure it does what you want, remove --dry-run.

If your /boot is so full that you cannot delete packages, you can make some space on /boot by removing the oldest /boot/initrd.img* file,

4
  • 1
    The key was "If your /boot is so full that you cannot delete packages, you can make some space on /boot by removing the oldest /boot/initrd.img* file". After that I did a sudo apt-get -f install, then running sudo apt-get remove -f linux-image-3.16.0-<various old versions>-generic worked for me.
    – augray
    May 14, 2016 at 17:46
  • 1
    Doing the sudo apt-get -f install after you have freed a tiny percentage of the space on /boot risks filling /boot mid-install. It would have been safer to do the whole cleanup first. When I used it, I manually preserved more versions by inserting | egrep -v '3.19.0-56|3.19.0-58' just after the awk command. YMMV.
    – waltinator
    May 14, 2016 at 18:30
  • I should mention that I cleaned out all of the initrd.img files except the one for the current kernel, which left me with 40% in boot. I'll try to keep boot from filling up again, but if it does, next time I'll clean out more before the apt-get -f install.
    – augray
    May 14, 2016 at 19:24
  • 1
    By deleting all but the latest initrd.img files, you broke all the other kernels. Reasonableness calls for keeping a spare version or two.
    – waltinator
    May 15, 2016 at 3:11

Not the answer you're looking for? Browse other questions tagged .