I encountered the following error while upgrading my Ubuntu 12.04 server. Now apt-get is unable to install or removed any package.

Unpacking linux-headers-3.13.0-62 (from .../linux-headers-3.13.0-62_3.13.0-62.102~precise1_all.deb) ...
dpkg: error processing /var/cache/apt/archives/linux-headers-3.13.0-62_3.13.0-62.102~precise1_all.deb (--unpack):
 unable to create `/usr/src/linux-headers-3.13.0-62/arch/arm/include/asm/ptrace.h.dpkg-new' 
(while processing `./usr/src/linux-headers-3.13.0-62/arch/arm/include/asm/ptrace.h'): 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)
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

Though I am not really out of disk space,

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       6.8G  4.7G  1.8G  69% /  

Anyhow my inodes are full,

# df -i
Filesystem     Inodes   IUsed  IFree IUse% Mounted on
/dev/sda1      458752  455214   3538  100% /

I have more than ten old kernels but I am unable to remove those as my apt-get itself is lame. So I am unable to follow this post which reports similar problem.

The only option seems to delete a few older kernels manually. Will it cause any problem?

Is there any better way out? Can I use reserved space for root for the time being and remove older kernels?

  • 1
    Indeed I manually removed couple of older kernels from /usr/src to get rid of the situation. Luckily everything went well and apt started working again. But I will request you to take back up before doing such thing on a production machine. I did it on a virtual machine which had complete backup.
    – sourav c.
    Sep 10, 2015 at 13:00
  • It works! I did the same here (ubutu 14.04.1) to update to kernel 4.4.0-51-generic. I'm just not sure if it will cause any problem in the future. Thanks.
    – Moreno
    Dec 4, 2016 at 22:05

2 Answers 2


I know this post is a bit old, but I found an answer here for anybody that may stumble upon this post: https://help.ubuntu.com/community/RemoveOldKernels

In case that link is broken, here is the relevant snippet:

Safely Removing Old Kernels

For users of LVM systems, encrypted systems or limited-storage systems, the most frequent problem is that the /boot partition is simply full. The package manager cannot install a pending upgrade due to lack of space. Besides, apt-get can not remove a package due to broken dependency.

This problem can be fixed quickly and easily from the shell. Simply identify one or two old kernels to remove manually, which will provide the package manager enough space to install the queued upgrade.

$ sudo rm -rv ${TMPDIR:-/var/tmp}/mkinitramfs-*  
                                  ## In Ubuntu 16.04 and earlier there may be leftover temporary
                                  ## files to delete.
                                  ## See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=814345

$ uname -r                        ## This command identifies the currently-running kernel
4.2.0-21-generic                  ## This is the current kernel.
                                  ## DO NOT REMOVE it!

$ dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r)
                                  ## This command lists all the kernels excluding the booted
                                  ## kernel in the package database, and their status.
rc  linux-image-4.2.0-14-generic  ## The oldest kernel in the database
                                  ## Status 'rc' means it's already been removed
ii  linux-image-4.2.0-15-generic  ## The oldest installed kernel. Eligible for removal.
                                  ## Status 'ii' means Installed.
ii  linux-image-4.2.0-16-generic  ## Another old installed kernel. Eligible for removal
ii  linux-image-4.2.0-18-generic  ## Another old installed kernel. Eligible for removal
ii  linux-image-4.2.0-19-generic  ## The previous good kernel. Keep
iU  linux-image-4.2.0-22-generic  ## DO NOT REMOVE. Status 'iU' means it's not installed,
                                  ## but queued for install in apt.
                                  ## This is the package we want apt to install.

                                  ## Purge the oldest kernel package using dpkg instead of apt.
                                  ## First you need to remove the image initrd.img file manually
                                  ## due to Bug #1678187.
$ sudo update-initramfs -d -k 4.2.0-15-generic
$ sudo dpkg --purge linux-image-4.2.0-15-generic linux-image-extra-4.2.0-15-generic
                                  ## If the previous command fails, some installed package
                                  ## depends on the kernel. The output of dpkg tells the name
                                  ## of the package. Purge it first.

                                  ## Also purge the respective header package.
$ sudo dpkg --purge linux-headers-4.2.0-15-generic
                                  ## Try also purging the common header package.
$ sudo dpkg --purge linux-headers-4.2.0-15
                                  ## Do not worry, if the previous command fails.

$ sudo apt-get -f install         ## Try to fix the broken dependency.

I followed this with:

sudo apt-get autoremove --purge
  • What if the current kernel version (found with uname -r) is older than the one currently installed? I.e. I find that the current version is 5.4.0-71-generic, but the ones installed are ...-74-generic and ...-77-generic` (and the iU version is ...-80-generic). Jul 21, 2021 at 16:03

I found now way out from the situation and removed couple of older kernels from /usr/src to get rid of the situation. Fortunately everything went well and apt started working again.

It is highly recommended to take back up before removing older kernels on a production machine.

  • Any better solution is still welcome. I post this comment as answer as it may help someone.
    – sourav c.
    Dec 26, 2016 at 7:17
  • 1
    After removed some old kernels and ran apt-get autoremove and installed some dependacies apt-get -f install fixed my issues Sep 21, 2017 at 10:14
  • THANK YOU. I removed all of the linux-* under /boot but didn't use dkpg so there were still the *-header files in /usr/src Apr 16, 2018 at 2:26

You must log in to answer this question.

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