1

How to uninstall unused packages when disk is full? I am trying to install an unmet dependency linux-headers-4.4.0-108 and update the kernel.

I have tried to use sudo apt-get autoremove but it fails with a disk full error.

Versions:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:    16.04
Codename:   xenial

Filesystem:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M   46M  350M  12% /run
/dev/xvda1      7.8G  5.0G  2.4G  69% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           396M     0  396M   0% /run/user/1000

I receive the same error when trying to run sudo apt-get -f install

$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  linux-headers-4.4.0-108
The following NEW packages will be installed:
linux-headers-4.4.0-108
0 upgraded, 1 newly installed, 0 to remove and 160 not upgraded.
7 not fully installed or removed.
Need to get 0 B/9927 kB of archives.
After this operation, 70.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
  LANGUAGE = (unset),
  LC_ALL = (unset),
  LC_CTYPE = "UTF-8",
  LANG = "en_US.UTF-8"
  are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
(Reading database ... 501671 files and directories currently installed.)
Preparing to unpack .../linux-headers-4.4.0-108_4.4.0-108.131_all.deb ...
Unpacking linux-headers-4.4.0-108 (4.4.0-108.131) ...
dpkg: error processing archive /var/cache/apt/archives/linux-headers-
4.4.0-108_4.4.0-108.131_all.deb (--unpack):
  error creating directory './usr/src/linux-headers-4.4.0-
108/arch/powerpc/platforms/pasemi': 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:
  /var/cache/apt/archives/linux-headers-4.4.0-108_4.4.0-108.131_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I also found that there are many unused kernels installed which can be removed to create more space but I'm not sure exactly the best method as I usually use sudo apt-get autoremove

Current:

$ uname -r
4.4.0-93-generic

Unused:

$ dpkg --list | grep linux-image

ii  linux-image-4.4.0-101-generic    4.4.0-101.124 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-103-generic    4.4.0-103.126 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-104-generic    4.4.0-104.127 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
iU  linux-image-4.4.0-108-generic    4.4.0-108.131 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-31-generic     4.4.0-31.50 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-4.4.0-79-generic     4.4.0-79.100 amd64  Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-81-generic     4.4.0-81.104 amd64  Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-83-generic     4.4.0-83.106 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-87-generic     4.4.0-87.110 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-89-generic     4.4.0-89.112 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-91-generic     4.4.0-91.114 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-92-generic     4.4.0-92.115 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-93-generic     4.4.0-93.116 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-96-generic     4.4.0-96.119 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-97-generic     4.4.0-97.120 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-98-generic     4.4.0-98.121 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
iU  linux-image-virtual              4.4.0.108.113 amd64 This package will always depend on the latest minimal generic kernel image.

I have also just tried to manually remove a kernel however I receive the following error.

$ sudo apt-get purge linux-image-4.4.0-78
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'linux-image-4.4.0-78-generic' for regex 'linux-image-4.4.0-78'
Note, selecting 'linux-image-4.4.0-78-lowlatency' for regex 'linux-image-4.4.0-78'
Package 'linux-image-4.4.0-78-lowlatency' is not installed, so not removed
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
  linux-headers-4.4.0-108-generic : Depends: linux-headers-4.4.0-108 but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

inode stats:

$ df -iH
Filesystem     Inodes IUsed IFree IUse% Mounted on
udev             504k   360  504k    1% /dev
tmpfs            506k   495  506k    1% /run
/dev/xvda1       525k  514k   11k   98% /
tmpfs            506k     1  506k    1% /dev/shm
tmpfs            506k     4  506k    1% /run/lock
tmpfs            506k    16  506k    1% /sys/fs/cgroup
tmpfs            506k     4  506k    1% /run/user/1000
4

3 Answers 3

2

Check your kernel headers, too

You have 16 kernel images installed, and the failure occurred while installing kernel headers.

  • Kernel images don't consume a lot of inodes, but kernel headers do.
  • If you have 16 kernel images installed, check to see if you also have 16 sets of kernel headers installed.
  • Kernel headers may prevent kernel images from being autoremoved.

See how the whole problem packs together into one tight ball?

If you do indeed have 16 sets of kernel images AND kernel headers installed, use dpkg to remove one package, usually freeing enough headroom for apt to remove the rest.

2

Your inode status shows that your server consists of large no of files. Inodes are basically the files that store information about the files. Hence your inodes have possibly become used up due to large creation/storage/improper handling of files.

Do you have websites running in your server? If yes, then please check the no of session files created that are not handled nicely or there might be some scripts that is generating files at a larger scale.

You can find the number of files in each of the directories using the script:

for i in /*; do echo "$i"; find "$i" |wc -l; done

You can also type the above command in shell.

7
  • The server is running some docker containers. Jan 11, 2018 at 12:03
  • use this command to find out where are most of the files located: '''for i in /*; do echo $i; find $i |wc -l; done''' Jan 11, 2018 at 13:04
  • You should edit your answer to include additional info :)
    – Zanna
    Jan 11, 2018 at 14:52
  • @Zanna see the updated answer Jan 12, 2018 at 6:31
  • theres only one pipe, the one you are mentioning is wc -l Jan 12, 2018 at 12:36
0

Hey - There's another Charles Green!

So, your disk is not full of files, but your inode count is almost full. This would indicate that there are lots and lots of little files on your disk somewhere.

To find all of these little files, try the following:

cd /
sudo du -a -d 1 --inodes . | sort -nr | head -20

The first command changes to the root directory, and the second command produces a list of the 20 largest inode consuming directories on your computer. In my computer, for example, "/proc" uses 266672 inodes...

Follow the trail of large consumers of inodes, and see if you find a directory full of 0 byte files or lots and lots of very small files. This will be where your problem is.


There is some information about inodes at https://unix.stackexchange.com/questions/117093/find-where-inodes-are-being-used and also at Running out of inodes

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