How To Fix A Full /boot Partition on Linux

How To Fix A Full /boot Partition on Linux

Get Social!

full-boot-mountUtilities such as apt-get generally install kernel updates by adding the new kernel to the Linux boot list and set it as the default. This means that the next time the system boots, the new kernel will be loaded. The problem is that the old kernel is still there (just incase the new one doesn’t work, you’ve got a fall back!), and the kernel before that, and the kernel before that…

The current 3.x kernel for Ubuntu is around 20MB so it doesn’t take long for the kernel updates to fill a tiny 200-or-so-Mb boot partition where they are stored.

The good news is that it’s easy to clear out the old updates, but it’s important to not remove the latest one that you’re using.

Which Kernel am I Running?

It’s quick and easy to see which kernel version you are running. Use the uname command with the -a switch and pay attention to the version numbers reported.

uname -a
3.19.0-47-generic

This shows that you’re using version 3.19.0-47.

List Currently Installed Kernels

Next you’ll need to list the kernel packages that are currently installed so that you can remove any outdated ones to free up the space on the /boot partition.

Run the below dpkg command to list the installed kernel packages and their versions.

dpkg --list 'linux-image*'

dpkg-kernel-package-listThe above output shows several versions of kernel that are all taking up space on the /boot partition however we only really need the current running version given by the above uname -a command. It’s a good idea to keep the last 2 kernels just incase you notice an issue down the line, but the above list is quite excessive.

Remove Unused Kernel Packages to Free Space on /boot

Once you’ve identified your current kernel and the kernel packages you have installed it’s time to remove the ones you don’t need.

Using apt-get enter the package names of the kernel packages to remove.

apt-get remove linux-image-3.19.0-25-generic

If you get an error running this command then see the next section.

note: the above screenshot of the installed packages cropped the full version name – it’s missing the generic part. You can use tab completion with the apt-get command, or use an asterisk after the version number to remove the required package. 

Errors Removing Packages

If you get an error warning about dependencies similar to the below then you may need to manually remove a few kernel packages to free up some space.

[root@server:~] $apt-get remove linux-image-extra-3.19.0-25-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-generic-lts-vivid : Depends: linux-image-3.19.0-49-generic but it is not going to be installed
                                 Depends: linux-image-extra-3.19.0-49-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).

The problem here is that the original update failed to install the latest version of the kernel (version 3.19.0-49-generic in this case) and apt-get doesn’t like doing anything else until that problem has been resolved.

First we need to free up some space. Carefully delete 2 of the older kernel packages with a command similar to the below, but with old version numbers from your system returned by the above section List Currently Installed Kernels.

rm /boot/*-3.19.0-25*
rm /boot/*-3.19.0-33*

Check and double check this command because there’s no going back once it’s ran! It’s perfectly safe to do as long as you are using old version numbers that you’re no longer using.

You can now run apt-get to complete the original upgrade now that it has the space. This will remove the error when trying to remove the unused kernel packages in the above section.

apt-get install -f

Now go back to the above section and remove the old kernel packages that you no longer need.


13 Comments

raul

30-May-2017 at 11:46 am

Hi, this is kind of urgent for me

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-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
pi 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
in linux-image-4.4.0-75-generic amd64 (no description available)
in linux-image-4.4.0-78-generic amd64 (no description available)
ii linux-image-extra-4.4.0-66-g 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-70-g 4.4.0-70.91 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rH linux-image-extra-4.4.0-71-g 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-g 4.4.0-72.93 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rH linux-image-extra-4.4.0-75-g 4.4.0-75.96 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
pH linux-image-extra-4.4.0-78-g 4.4.0-78.99 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rU linux-image-generic 4.4.0.78.84 amd64 Generic Linux kernel image

and uname returns 4.4.0-66-generic #87-Ubuntu SMP Fri Mar 3 15:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

/boot is 100% used

Can i delete newer versions of the kernel?

    James Coyle

    30-May-2017 at 11:52 am

    You can delete any versions you want to. I’d recommend, however, keeping the latest one or two.

    The above post is only an example of version numbers – of course the version numbers change over time.

      raul

      31-May-2017 at 11:48 am

      Thanks for the quick reply.

      I’ve manually removed all the files from /boot containing 4.4.0-70 and 4.4.0-71 from the above list

      I was left with

      /dev/sda1 193242 98662 80317 56% /boot

      Running sudo apt-get install -f outputted this large mess (basically it tried to recreate an install the missing files)

      ———-output———

      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      Correcting dependencies… Done
      The following packages were automatically installed and are no longer required:
      linux-headers-4.4.0-72 linux-headers-4.4.0-72-generic linux-image-4.4.0-72-generic linux-image-extra-4.4.0-72-generic
      Use ‘sudo apt autoremove’ to remove them.
      The following additional packages will be installed:
      linux-image-4.4.0-75-generic linux-image-4.4.0-78-generic
      Suggested packages:
      fdutils linux-doc-4.4.0 | linux-source-4.4.0 linux-tools
      The following packages will be REMOVED:
      linux-image-extra-4.4.0-71-generic
      The following NEW packages will be installed:
      linux-image-4.4.0-75-generic linux-image-4.4.0-78-generic
      0 upgraded, 2 newly installed, 1 to remove and 85 not upgraded.
      7 not fully installed or removed.
      Need to get 0 B/116 MB of archives.
      After this operation, 18.9 MB disk space will be freed.
      Do you want to continue? [Y/n] Y
      (Reading database … 223420 files and directories currently installed.)
      Removing linux-image-extra-4.4.0-71-generic (4.4.0-71.92) …
      depmod: FATAL: could not load /boot/System.map-4.4.0-71-generic: No such file or directory
      run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-71-generic /boot/vmlinuz-4.4.0-71-generic
      run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-71-generic /boot/vmlinuz-4.4.0-71-generic
      update-initramfs: Generating /boot/initrd.img-4.4.0-71-generic
      run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-71-generic /boot/vmlinuz-4.4.0-71-generic
      run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-71-generic /boot/vmlinuz-4.4.0-71-generic
      Generating grub configuration file …
      Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
      Found linux image: /boot/vmlinuz-4.4.0-72-generic
      Found initrd image: /boot/initrd.img-4.4.0-72-generic
      Found linux image: /boot/vmlinuz-4.4.0-66-generic
      Found initrd image: /boot/initrd.img-4.4.0-66-generic
      done
      (Reading database … 223420 files and directories currently installed.)
      Preparing to unpack …/linux-image-4.4.0-78-generic_4.4.0-78.99_amd64.deb …
      Done.
      Unpacking linux-image-4.4.0-78-generic (4.4.0-78.99) …
      Preparing to unpack …/linux-image-4.4.0-75-generic_4.4.0-75.96_amd64.deb …
      Done.
      Unpacking linux-image-4.4.0-75-generic (4.4.0-75.96) …
      Setting up linux-firmware (1.157.10) …
      update-initramfs: Generating /boot/initrd.img-4.4.0-72-generic
      update-initramfs: Generating /boot/initrd.img-4.4.0-71-generic
      update-initramfs: Generating /boot/initrd.img-4.4.0-70-generic
      update-initramfs: Generating /boot/initrd.img-4.4.0-66-generic

      gzip: stdout: No space left on device
      E: mkinitramfs failure cpio 141 gzip 1
      update-initramfs: failed for /boot/initrd.img-4.4.0-66-generic with 1.
      dpkg: error processing package linux-firmware (–configure):
      subprocess installed post-installation script returned error exit status 1
      Setting up linux-image-4.4.0-78-generic (4.4.0-78.99) …
      Running depmod.
      update-initramfs: deferring update (hook will be called later)
      Examining /etc/kernel/postinst.d.
      run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-78-generic /boot/vmlinuz-4.4.0-78-generic
      run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-78-generic /boot/vmlinuz-4.4.0-78-generic
      update-initramfs: Generating /boot/initrd.img-4.4.0-78-generic
      run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-78-generic /boot/vmlinuz-4.4.0-78-generic
      run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-78-generic /boot/vmlinuz-4.4.0-78-generic
      Generating grub configuration file …
      Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
      Found linux image: /boot/vmlinuz-4.4.0-78-generic
      Found initrd image: /boot/initrd.img-4.4.0-78-generic
      Found linux image: /boot/vmlinuz-4.4.0-75-generic
      Found linux image: /boot/vmlinuz-4.4.0-72-generic
      Found initrd image: /boot/initrd.img-4.4.0-72-generic
      Found linux image: /boot/vmlinuz-4.4.0-66-generic
      Found initrd image: /boot/initrd.img-4.4.0-66-generic
      done
      dpkg: error processing package linux-image-extra-4.4.0-78-generic (–configure):
      package linux-image-extra-4.4.0-78-generic is not ready for configuration
      cannot configure (current status ‘half-installed’)
      dpkg: dependency problems prevent configuration of linux-image-generic:
      linux-image-generic depends on linux-image-extra-4.4.0-78-generic; however:
      Package linux-image-extra-4.4.0-78-generic is not installed.
      linux-image-generic depends on linux-firmware; however:
      Package linux-firmware is not configured yet.

      dpkg: error processing package linux-image-generic (–configure):
      dependency problems – leaving unconfigured
      dpkg: dependency problems prevent configuration of linux-generic:
      linux-generic depends on linux-image-generic (= 4.4.0.78.84); however:
      Package linux-image-generic is not configured yet.

      dpkg: error processing package linux-generic (–configure):
      dependency problems – leaving unconfigured
      Setting up linux-image-extra-4.4.0-72-generic (4.4.0-72.93) …
      run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
      run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
      update-initramfs: Generating /boot/initrd.img-4.4.0-72-generic

      gzip: stdout: No space left on device
      E: mkinitramfs failure find 141 cpio 141 gzip 1
      update-initramfs: failed for /boot/initrd.img-4.4.0-72-generic with 1.
      run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
      dpkg: error processing package linux-image-extra-4.4.0-72-generic (–configure):
      subprocess installed post-installation script returned error exit status 1
      Setting up linux-image-4.4.0-75-generic (4.4.0-75.96) …
      Running depmod.
      update-initramfs: deferring update (hook will be called later)
      Examining /etc/kernel/postinst.d.
      run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-75-generic /boot/vmlinuz-4.4.0-75-generic
      run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-75-generic /boot/vmlinuz-4.4.0-75-generic
      update-initramfs: Generating /boot/initrd.img-4.4.0-75-generic

      gzip: stdout: No space left on device
      E: mkinitramfs failure cpio 141 gzip 1
      update-initramfs: failed for /boot/initrd.img-4.4.0-75-generic with 1.
      run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
      Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-4.4.0-75-generic.postinst line 1052.
      dpkg: error processing package linux-image-4.4.0-75-generic (–configure):
      subprocess installed post-installation script returned error exit status 2
      dpkg: error processing package linux-image-extra-4.4.0-75-generic (–configure):
      package linux-image-extra-4.4.0-75-generic is not ready for configuration
      cannot configure (current status ‘half-installed’)
      Errors were encountered while processing:
      linux-firmware
      linux-image-extra-4.4.0-78-generic
      linux-image-generic
      linux-generic
      linux-image-extra-4.4.0-72-generic
      linux-image-4.4.0-75-generic
      linux-image-extra-4.4.0-75-generic
      E: Sub-process /usr/bin/dpkg returned an error code (1)

      ————————-

      Another manual removal of files from /boot and then tried cmd sudo apt autoremove

      ———-output——-
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      The following packages will be REMOVED:
      linux-headers-4.4.0-71 linux-headers-4.4.0-71-generic linux-image-4.4.0-71-generic
      0 upgraded, 0 newly installed, 3 to remove and 85 not upgraded.
      1 not fully installed or removed.
      After this operation, 144 MB disk space will be freed.
      Do you want to continue? [Y/n] Y
      (Reading database … 225798 files and directories currently installed.)
      Removing linux-headers-4.4.0-71-generic (4.4.0-71.92) …
      Removing linux-headers-4.4.0-71 (4.4.0-71.92) …
      Removing linux-image-4.4.0-71-generic (4.4.0-71.92) …
      Examining /etc/kernel/postrm.d .
      run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-71-generic /boot/vmlinuz-4.4.0-71-generic
      update-initramfs: Deleting /boot/initrd.img-4.4.0-71-generic
      run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-71-generic /boot/vmlinuz-4.4.0-71-generic
      Generating grub configuration file …
      Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
      Found linux image: /boot/vmlinuz-4.4.0-78-generic
      Found initrd image: /boot/initrd.img-4.4.0-78-generic
      Found linux image: /boot/vmlinuz-4.4.0-75-generic
      Found initrd image: /boot/initrd.img-4.4.0-75-generic
      done
      Setting up linux-image-extra-4.4.0-72-generic (4.4.0-72.93) …
      depmod: FATAL: could not load /boot/System.map-4.4.0-72-generic: No such file or directory
      run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
      run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
      update-initramfs: Generating /boot/initrd.img-4.4.0-72-generic
      run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
      run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
      Generating grub configuration file …
      Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
      Found linux image: /boot/vmlinuz-4.4.0-78-generic
      Found initrd image: /boot/initrd.img-4.4.0-78-generic
      Found linux image: /boot/vmlinuz-4.4.0-75-generic
      Found initrd image: /boot/initrd.img-4.4.0-75-generic
      done
      ———————-

      Then sudo apt-get install -f
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      0 upgraded, 0 newly installed, 0 to remove and 85 not upgraded.

      Now I’m left with

      /dev/sda1 193242 90540 88439 51% /boot

      /boot$ ls -la
      ———————————————————–
      total 82095
      drwxr-xr-x 4 root root 1024 May 31 10:07 .
      drwxr-xr-x 23 root root 4096 May 31 10:01 ..
      -rw-r–r– 1 root root 1246246 Apr 20 12:02 abi-4.4.0-75-generic
      -rw-r–r– 1 root root 1246312 Apr 27 18:24 abi-4.4.0-78-generic
      -rw-r–r– 1 root root 190214 Apr 20 12:02 config-4.4.0-75-generic
      -rw-r–r– 1 root root 190355 Apr 27 18:24 config-4.4.0-78-generic
      drwxr-xr-x 5 root root 1024 May 31 10:07 grub
      -rw-r–r– 1 root root 34109495 May 31 10:07 initrd.img-4.4.0-72-generic
      -rw-r–r– 1 root root 12559250 May 31 10:04 initrd.img-4.4.0-75-generic
      -rw-r–r– 1 root root 12559493 May 31 10:04 initrd.img-4.4.0-78-generic
      drwx—— 2 root root 12288 Mar 16 19:35 lost+found
      -rw——- 1 root root 3883390 Apr 20 12:02 System.map-4.4.0-75-generic
      -rw——- 1 root root 3882872 Apr 27 18:24 System.map-4.4.0-78-generic
      -rw——- 1 root root 7081872 Apr 20 12:02 vmlinuz-4.4.0-75-generic
      -rw——- 1 root root 7089552 Apr 27 18:24 vmlinuz-4.4.0-78-generic
      —————————————————–

      uname -a
      Linux LindaBoxPro 4.4.0-66-generic #87-Ubuntu SMP Fri Mar 3 15:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      The current kernel is 4.4.0-66 and there is not anymore in the /boot folder

      dpkg –list ‘linux-image*’
      —————————————————————
      Desired=Unknown/Install/Remove/Purge/Hold
      | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
      |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
      ||/ Name Version Architecture Description
      +++-==============================================================-====================================-====================================-=================================================================================================================================
      un linux-image (no description available)
      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-70-generic 4.4.0-70.91 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
      rc 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
      pi 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-4.4.0-75-generic 4.4.0-75.96 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
      ii linux-image-4.4.0-78-generic 4.4.0-78.99 amd64 Linux kernel image 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-70-generic 4.4.0-70.91 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
      rc 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
      ii 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
      rc 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
      rc linux-image-extra-4.4.0-78-generic 4.4.0-78.99 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
      ————————————————————-

      And there are other kernels in the dpkg
      I didn’t rebooted the machine because is in production, hope with apt-get upgrade and a reboot all of this will go away.
      I’m just asking if it unsafe or the machine will not boot at all if the kernel files from /boot are not in sync with the dpkg list or even if the current kernel version isn’t present in the boot folder?

        James Coyle

        31-May-2017 at 11:56 am

        You need to run apt-get install -f to resolve the dependencies, and ensure that at least one kernel is installed. You don’t need to have the current running kernel installed, but you do need to have at least one available.

          raul

          31-May-2017 at 12:21 pm

          sudo apt-get install -f
          Reading package lists… Done
          Building dependency tree
          Reading state information… Done
          0 upgraded, 0 newly installed, 0 to remove and 104 not upgraded.

          So in this case I’ll backup all the things and reboot the machine at a low traffic hour and hope it reboots. There are some worrying discrepancies between /boot folder contents, dpkg listing and current uname -a.

          Thanks a lot and hope it helps others too…

          James Coyle

          31-May-2017 at 1:19 pm

          Good luck!

Sandeep

1-Jun-2017 at 11:25 am

I was randomly googling the issue I faced on boot disk full and stumbled upon your website. It was spot on. Your steps solved my issue in 5 minutes. Thank you so much.

Huw Edwards

29-Jun-2017 at 6:06 pm

Thank you James – worked perfectly and nice, clear instructions.
Huw

jhice

4-Feb-2018 at 8:50 pm

Thanks for the tip ! It works.

Dan

14-Dec-2018 at 7:19 pm

Thanks for the help. It worked.

Jac

16-Dec-2018 at 2:39 am

Thank you man! After trying 6 other useless commands and solutions, This is the cleanest written solution to this problem that was easy to comprehend and implement.. and it worked! Thank you so much, Im finally able to upgrade this f*ing box.

Simo

29-May-2019 at 6:04 pm

It worked ! Thank you !

Frank

20-Oct-2021 at 8:53 am

Hi, command apt autoremove (on Debian based systems) is elegant enough, removing old kernels and boot partition shall be free of old, unused kernels images.

Leave a Reply

Visit our advertisers

Quick Poll

Are you using Docker.io?

Visit our advertisers