/boot is 100% full, apt-get purge linux-image-x.x.x.x-generic won't work

5,941

Solution 1

Removing old kernels to free space in /boot partition

If your system is running using an old kernel (usually the newest kernel boots by default) you should boot from the newest kernel installed, which seems to be linux-image-4.4.0-72-generic in your case.

Select it from the GRUB menu (hold or repeatedly press Shift during boot if GRUB doesn't show at all).

When you have booted from your newest kernel, first run sudo apt-get -f install, trying to fix the unmet dependencies issues, if it works go on with any of the first two method below; if it fails jump to manual package purge.

The apt way

Try to correctly manage the space issue with apt:

  • Run sudo apt autoclean && sudo apt autoremove, apt should correctly manage removing all old-kernels and related packages if you haven't messed too much with it.

Using purge_old_kernels from byobu package

If the apt way doesn't work or it doesn't remove enough space:

  • Install byobu running sudo apt install byobu.
  • Then run sudo purge-old-kernels, which should remove old kernels in a cleaner way than directly purging packages.

Manual package purge

If any oh the above worked:

  • Purge the oldest (not running) kernel with sudo apt-get purge linux-image-4.4.0-21-generic && sudo update-grub.
  • Reboot and boot from the newest kernel available.
  • Run sudo apt-get -f install.
  • Run sudo apt update && sudo apt full-upgrade.
  • Reboot using your newest kernel.
  • Clean older kernels, via The apt way and/or _purge_old_kernels_.

The dpkg way

As a last resort, you can try to do it in the dpkg way which isn't the safest.

  • Run from your terminal (running from your newest installed kernel):

    echo $(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs sudo apt-get -y purge
    

    Borrowed from this response.

  • Reboot your system and run sudo apt-get -f install

  • Do a full upgrade with sudo apt update && sudo apt full-upgrade.
  • Reboot if needed (new kernel¿?) and go with the apt way: sudo apt autoclean && sudo apt autoremove.
  • Run sudo purge_old_kernels, command from byoby package if still remains any old kernel version (in addition to the current and previous version which are always kept as a safety precaution).

Solution 2

If /boot is so full that apt remove doesn't work (No space left on device), just rm some files (vmlinuz or initrd.img) belonging to the kernels you want to remove to free up enough space so you can then properly apt remove the packages. Of couse, as always when running rm as root, be extra careful for typos, etc., but even if you accidentally rm a file from a kernel you didn't want to remove, a simple apt install --reinstall will fix it.

Contrary to a common misconception, there is absolutely no problem with doing that, as anybody could see if they actually tried it instead of just repeating things they have heard. (In particular, I often read that doing so would result in "broken packages". No, that's not what broken packages means.)

Share:
5,941

Related videos on Youtube

Manny
Author by

Manny

Updated on September 18, 2022

Comments

  • Manny
    Manny over 1 year

    I have a /boot overload. Tried to follow /dev/sda1 /boot is full, but got stuck.

    History:

    df
    Filesystem            1K-blocks    Used Available Use% Mounted on
    udev                     485360       0    485360   0% /dev
    tmpfs                    100744   10824     89920  11% /run
    /dev/mapper/vg00-lv01  49011528 7513836  39300100  17% /
    tmpfs                    503716       0    503716   0% /dev/shm
    tmpfs                      5120       0      5120   0% /run/lock
    tmpfs                    503716       0    503716   0% /sys/fs/cgroup
    /dev/sda1                474730  466955         0 100% /boot
    
    dpkg --list | grep linux-image
    
    ii  linux-image-4.4.0-21-generic       4.4.0-21.37                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-59-generic       4.4.0-59.80                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-62-generic       4.4.0-62.83                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-63-generic       4.4.0-63.84                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-64-generic       4.4.0-64.85                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-66-generic       4.4.0-66.87                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-67-generic       4.4.0-67.88                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-70-generic       4.4.0-70.91                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-71-generic       4.4.0-71.92                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-4.4.0-72-generic       4.4.0-72.93                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-21-generic 4.4.0-21.37                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-59-generic 4.4.0-59.80                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-62-generic 4.4.0-62.83                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-63-generic 4.4.0-63.84                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-64-generic 4.4.0-64.85                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-66-generic 4.4.0-66.87                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-67-generic 4.4.0-67.88                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-70-generic 4.4.0-70.91                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    ii  linux-image-extra-4.4.0-71-generic 4.4.0-71.92                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    iF  linux-image-extra-4.4.0-72-generic 4.4.0-72.93                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    iU  linux-image-extra-4.4.0-75-generic 4.4.0-75.96                                amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
    iU  linux-image-generic                4.4.0.75.81                                amd64        Generic Linux kernel image
    

    !!! wow, so much, how could this happen ?

    And then:

    uname -r
    4.4.0-21-generic
    

    Trials to purge unused images:

    apt-get purge linux-image-4.4.0-59-generic
    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:
     linux-image-extra-4.4.0-59-generic : Depends: linux-image-4.4.0-59-generic but it is not going to be installed
     linux-image-extra-4.4.0-75-generic : Depends: linux-image-4.4.0-75-generic but it is not going to be installed
     linux-image-generic : Depends: linux-image-4.4.0-75-generic but it is not going to be installed
                           Recommends: thermald but it is not going to be installed
    E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
    

    Anyone got an idea?

    • user535733
      user535733 about 7 years
      apt queues actions, which requires space to work. Use dpkg to remove a kernel or two, freeing the overhead apt needs. Then use apt to clean up.
    • Charles Green
      Charles Green about 7 years
      Please note that the output of 'uname -r' indicates that you are running on an older version of the kernel (4.4.0-21). After you have freed a little space on '/boot', you should boot into a newer kernel and use 'sudo apt autoclean && sudo apt autoremove'
  • Manny
    Manny about 7 years
    Hey, wow, many thanks for your advice, all of you!
  • Manny
    Manny about 7 years
    I am trying: apt autoclean && sudo apt autoremove It gives: link and /boot is still 100% Boyu won't install : link I stop moving from here, so that I avoid putting too much mess and you guys may suggest the next moves. Thanks
  • dgonzalez
    dgonzalez about 7 years
    @Manny I updated my answer with some dirtier alternatives. Be careful and always remember to keep a backup of your important data.
  • Manny
    Manny about 7 years
    Tks. First command gives : pastebin.com/pL01FGDd Looks like bad news (?)
  • dgonzalez
    dgonzalez about 7 years
    @Manny What's your sudo apt-get -f install output¿?
  • Manny
    Manny about 7 years
    Here it is : pastebin.com/1Msx9Qq2
  • dgonzalez
    dgonzalez about 7 years
    I think you are still booting from your older kernel version 4.4.0-21, try to boot from a newer kernel first, maybe 4.4.0-72 and try to start from there, if you have no luck, it may be worth doing a fresh install...
  • Manny
    Manny about 7 years
    Editing /boot/grub/grub.cfg ? File starts with '### BEGIN /etc/grub.d/00_header ### if [ -s $prefix/grubenv ]; then set have_grubenv=true load_env fi if [ "${next_entry}" ] ; then set default="${next_entry}" set next_entry= save_env next_entry set boot_once=true else set default="0" fi' I'm sorry but I do not see where to edit and how :/
  • Manny
    Manny about 7 years
  • Manny
    Manny about 7 years
    Ok I've tried removing mannualy one image in /boot and gor 96% space. Tks @user535733 Then I tried back dgonzalez approach, still failing but a bit better. pastebin.com/aD6EdRfK I'm using a console form my laptop, with ssh connexion, holding shift to choose the image from grub display does not work : no grub display appears...
  • Manny
    Manny about 7 years
    Got it ! I was most reluctant to removing content in /boot But you can (and in that case must) remove images that are not booted on. When this is done apt-get -f install and apt autoclean && apt autoremove perfectly do the job. Thanks again for helping, folks.
  • dgonzalez
    dgonzalez about 7 years
    @Manny I'm glad to read that you could avoid doing a fresh install! Keep on rocking!
  • Manny
    Manny about 7 years
    Many many thanks, really. Precious are words when you are alone face to a machine :)