Wednesday, July 16th, 2014 - 12:20 PM

Ubuntu 12.04 initramfs dependency nonsense

In managing Linux servers, and I’ve encountered the following situation many times:

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
initramfs-tools : Depends: initramfs-tools-bin (< 0.99ubuntu13.1~) but 0.99ubuntu13.5 is installed libc6-dev : Depends: libc6 (= 2.15-0ubuntu10.5) but 2.15-0ubuntu10.4 is installed plymouth : Depends: libplymouth2 (= 0.8.2-2ubuntu31) but 0.8.2-2ubuntu31.1 is installed E: Unmet dependencies. Try using -f.

It’s usually caused by /boot filling up with old kernels, which will eventually happen if you used default partitioning and configured Ubuntu to automatically install security updates. As a result, updates stop getting applied, which could potentially leave the system vulnerable.

I keep thinking I’m finished fixing this problem, but then I end up using another server that has this issue. I always manage to fix it, but each time I find myself figuring out or tracking down a solution. (There are many ways to address it.)

The first step is to free up space. You can probably do that by removing the accumulated kernels you’re not using.
This command (borrowed from a post on askubuntu) should do it (by listing the installed kernels, stripping out the running kernel, then uninstalling the remaining set):

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

After that, the following commands (borrowed from a link on stackexchange) should get things back into a sane state:

sudo dpkg --configure -a --force-depends
sudo apt-get install -f
sudo apt-get dist-upgrade

Now I’ll remember where to find the solution next time I encounter this… and hopefully someone else will benefit.

Leave a Reply